Skip to content

Commit e169225

Browse files
committed
Correct unload dynamic.dll after test
1 parent 8d77ca9 commit e169225

File tree

8 files changed

+101
-44
lines changed

8 files changed

+101
-44
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ src/bin/vld.ini
1818
/src/tests/vld_ComTest/ComTest_i.h
1919
/src/tests/vld_ComTest/ComTest_p.c
2020
/src/tests/vld_ComTest/ComTest_i.c
21+
*.VC.opendb

appveyor.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ configuration:
6262
matrix:
6363
fast_finish: false
6464

65+
nuget:
66+
project_feed: true
67+
disable_publish_on_pr: true
68+
6569
notifications:
6670
- provider: Webhook
6771
url: https://webhooks.gitter.im/e/f26eac97358590c8feca

src/tests/dynamic_app/LoadTests.cpp

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -42,25 +42,32 @@ void CallDynamicMethods(HMODULE module, const CHAR* function)
4242
}
4343
}
4444

45-
HMODULE RunLoaderTests(bool resolve)
45+
HMODULE LoadDynamicTests()
4646
{
4747
HMODULE hdyn = LoadLibrary(_T("dynamic.dll"));
4848
if (hdyn)
4949
{
5050
VLDEnableModule(hdyn);
51+
}
52+
return hdyn;
53+
}
5154

52-
// Should leak 18 memory allocations in total
53-
// These requires ansi, not Unicode strings
54-
CallDynamicMethods(hdyn, "SimpleLeak_Malloc"); // leaks 6
55-
CallDynamicMethods(hdyn, "SimpleLeak_New"); // leaks 6
56-
CallDynamicMethods(hdyn, "SimpleLeak_New_Array"); // leaks 6
55+
void RunLoaderTests(HMODULE hdyn, bool resolve)
56+
{
57+
if (!hdyn)
58+
return;
59+
VLDEnableModule(hdyn);
5760

58-
if (resolve)
59-
{
60-
CallVLDExportedMethod("VLDResolveCallstacks"); // This requires ansi, not Unicode strings
61-
}
61+
// Should leak 18 memory allocations in total
62+
// These requires ansi, not Unicode strings
63+
CallDynamicMethods(hdyn, "SimpleLeak_Malloc"); // leaks 6
64+
CallDynamicMethods(hdyn, "SimpleLeak_New"); // leaks 6
65+
CallDynamicMethods(hdyn, "SimpleLeak_New_Array"); // leaks 6
66+
67+
if (resolve)
68+
{
69+
CallVLDExportedMethod("VLDResolveCallstacks"); // This requires ansi, not Unicode strings
6270
}
63-
return hdyn;
6471
}
6572

6673
void CallLibraryMethods( HMODULE hmfcLib, LPCSTR function )
@@ -80,23 +87,28 @@ void CallLibraryMethods( HMODULE hmfcLib, LPCSTR function )
8087
}
8188
}
8289

83-
84-
HMODULE RunMFCLoaderTests(bool resolve)
90+
HMODULE LoadMFCTests()
8591
{
8692
HMODULE hmfcLib = LoadLibrary(_T("test_mfc.dll"));
8793
if (hmfcLib)
8894
{
8995
VLDEnableModule(hmfcLib);
90-
// Should leak 11 memory allocations in total
91-
// This requires ansi, not Unicode strings
92-
CallLibraryMethods(hmfcLib, "MFC_LeakSimple"); // Leaks 4 x 2 = 8
93-
CallLibraryMethods(hmfcLib, "MFC_LeakArray"); // leaks 3
94-
95-
if (resolve)
96-
{
97-
CallVLDExportedMethod("VLDResolveCallstacks"); // This requires ansi, not Unicode strings
98-
}
9996
}
10097
return hmfcLib;
10198
}
10299

100+
void RunMFCLoaderTests(HMODULE hmfcLib, bool resolve)
101+
{
102+
if (!hmfcLib)
103+
return;
104+
// Should leak 11 memory allocations in total
105+
// This requires ansi, not Unicode strings
106+
CallLibraryMethods(hmfcLib, "MFC_LeakSimple"); // Leaks 4 x 2 = 8
107+
CallLibraryMethods(hmfcLib, "MFC_LeakArray"); // leaks 3
108+
109+
if (resolve)
110+
{
111+
CallVLDExportedMethod("VLDResolveCallstacks"); // This requires ansi, not Unicode strings
112+
}
113+
}
114+

src/tests/dynamic_app/LoadTests.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#pragma once
22

3-
HMODULE RunLoaderTests( bool resolve );
4-
HMODULE RunMFCLoaderTests( bool resolve );
3+
HMODULE LoadDynamicTests();
4+
void RunLoaderTests(HMODULE hdyn, bool resolve);
5+
HMODULE LoadMFCTests();
6+
void RunMFCLoaderTests(HMODULE hmfcLib, bool resolve);

src/tests/dynamic_app/ThreadTest.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,21 @@ void RunPSApiLoaderTests()
2222
void Call_LoaderLocks(const ThreadData& threadData)
2323
{
2424
RunPSApiLoaderTests(); // will not crash
25-
HMODULE hmfcLib;
26-
if (threadData.mfc)
27-
hmfcLib = RunMFCLoaderTests(threadData.resolve); // Leaks 11 allocs
28-
else
29-
hmfcLib = RunLoaderTests(threadData.resolve); // Leaks 18 allocs
25+
HMODULE hlib;
26+
if (threadData.mfc)
27+
{
28+
hlib = LoadMFCTests();
29+
RunMFCLoaderTests(hlib, threadData.resolve); // Leaks 11 allocs
30+
}
31+
else
32+
{
33+
hlib = LoadDynamicTests();
34+
RunLoaderTests(hlib, threadData.resolve); // Leaks 18 allocs
35+
}
3036
#ifndef STATIC_CRT
31-
FreeLibrary(hmfcLib);
37+
FreeLibrary(hlib);
3238
#else
33-
UNREFERENCED_PARAMETER(hmfcLib);
39+
UNREFERENCED_PARAMETER(hlib);
3440
#endif
3541

3642
HMODULE this_app = NULL;
@@ -63,7 +69,6 @@ unsigned __stdcall Dynamic_Thread_Procedure(LPVOID foo)
6369

6470
void RunLoaderLockTests(bool resolve, bool mfc)
6571
{
66-
static const int NUMTHREADS = 64;
6772
HANDLE threads[NUMTHREADS] = {0};
6873
unsigned thread_id = NULL;
6974
ThreadData threadData;
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#pragma once
22

3-
void RunLoaderLockTests(bool, bool);
3+
static const int NUMTHREADS = 64;
44

5+
void RunLoaderLockTests(bool, bool);

src/tests/dynamic_app/dynamic_app.cpp

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -40,16 +40,26 @@ class DynamicLoader : public ::testing::TestWithParam<bool> {
4040

4141
TEST_P(DynamicLoader, LoaderTests)
4242
{
43-
HMODULE hmfcLib = RunLoaderTests(GetParam()); // leaks 18
44-
ASSERT_NE(0u, (UINT_PTR)hmfcLib);
45-
int leaks = (int)VLDGetLeaksCount();
43+
HMODULE hdynLib = LoadDynamicTests();
44+
ASSERT_NE(0u, reinterpret_cast<UINT_PTR>(hdynLib));
45+
#ifdef STATIC_CRT // Toolset <= v100 use own heap
46+
VLDMarkAllLeaksAsReported();
47+
RunLoaderTests(hdynLib, GetParam()); // leaks 18
48+
int leaks = static_cast<int>(VLDGetLeaksCount());
49+
FreeLibrary(hdynLib);
50+
#else
51+
//VLDMarkAllLeaksAsReported();
52+
RunLoaderTests(hdynLib, GetParam()); // leaks 18
53+
FreeLibrary(hdynLib);
54+
int leaks = static_cast<int>(VLDGetLeaksCount());
55+
#endif
4656
if (18 != leaks) VLDReportLeaks();
4757
ASSERT_EQ(18, leaks);
4858
}
4959

5060
TEST_P(DynamicLoader, MultithreadLoadingTests)
5161
{
52-
// Creates 64 threads that each leaks 18 allocations
62+
// Creates NUMTHREADS threads that each leaks 18 allocations
5363
DWORD start = GetTickCount();
5464
RunLoaderLockTests(GetParam(), false);
5565
DWORD duration = GetTickCount() - start;
@@ -58,23 +68,38 @@ TEST_P(DynamicLoader, MultithreadLoadingTests)
5868
int leaks = (int)VLDGetLeaksCount();
5969
duration = GetTickCount() - start;
6070
_tprintf(_T("VLDGetLeaksCount took: %u ms\n"), duration);
61-
if (64 * 18 != leaks) VLDReportLeaks();
62-
ASSERT_EQ(64 * 18, leaks);
71+
int correctLeaks = NUMTHREADS * 18;
72+
if (correctLeaks != leaks) VLDReportLeaks();
73+
#ifdef STATIC_CRT // One leak from dll static allocation
74+
HMODULE hlib = LoadDynamicTests();
75+
for (int i = 0; i < NUMTHREADS + 1; i++)
76+
FreeLibrary(hlib);
77+
#endif
78+
ASSERT_EQ(correctLeaks, leaks);
6379
}
6480

6581
TEST_P(DynamicLoader, MfcLoaderTests)
6682
{
67-
HMODULE hmfcLib = RunMFCLoaderTests(GetParam()); // leaks 11
68-
ASSERT_NE(0u, (UINT_PTR)hmfcLib);
83+
HMODULE hmfcLib = LoadMFCTests();
84+
ASSERT_NE(0u, reinterpret_cast<UINT_PTR>(hmfcLib));
85+
#ifdef STATIC_CRT // Toolset <= v100 use own heap
86+
VLDMarkAllLeaksAsReported();
87+
RunMFCLoaderTests(hmfcLib, GetParam()); // leaks 11
88+
int leaks = (int)VLDGetLeaksCount();
89+
FreeLibrary(hmfcLib);
90+
#else
91+
//VLDMarkAllLeaksAsReported();
92+
RunMFCLoaderTests(hmfcLib, GetParam()); // leaks 11
6993
FreeLibrary(hmfcLib);
7094
int leaks = (int)VLDGetLeaksCount();
95+
#endif
7196
if (11 != leaks) VLDReportLeaks();
7297
ASSERT_EQ(11, leaks);
7398
}
7499

75100
TEST_P(DynamicLoader, MfcMultithreadLoadingTests)
76101
{
77-
// Creates 64 threads that each leaks 11 allocations
102+
// Creates NUMTHREADS threads that each leaks 11 allocations
78103
DWORD start = GetTickCount();
79104
RunLoaderLockTests(GetParam(), true);
80105
DWORD duration = GetTickCount() - start;
@@ -83,8 +108,13 @@ TEST_P(DynamicLoader, MfcMultithreadLoadingTests)
83108
int leaks = (int)VLDGetLeaksCount();
84109
duration = GetTickCount() - start;
85110
_tprintf(_T("VLDGetLeaksCount took: %u ms\n"), duration);
86-
if (64 * 11 != leaks) VLDReportLeaks();
87-
ASSERT_EQ(64 * 11, leaks);
111+
if (NUMTHREADS * 11 != leaks) VLDReportLeaks();
112+
#ifdef STATIC_CRT // One leak from dll static allocation
113+
HMODULE hlib = LoadMFCTests();
114+
for (int i = 0; i < NUMTHREADS + 1; i++)
115+
FreeLibrary(hlib);
116+
#endif
117+
ASSERT_EQ(NUMTHREADS * 11, leaks);
88118
}
89119

90120
INSTANTIATE_TEST_CASE_P(ResolveVal,

src/tests/dynamic_dll/dynamic.vcxproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@
190190
<WarningLevel>Level3</WarningLevel>
191191
<Optimization>Disabled</Optimization>
192192
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;DYNAMIC_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
193+
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
193194
</ClCompile>
194195
<Link>
195196
<SubSystem>Windows</SubSystem>
@@ -239,6 +240,7 @@
239240
<WarningLevel>Level3</WarningLevel>
240241
<Optimization>Disabled</Optimization>
241242
<PreprocessorDefinitions>WIN32;_DEBUG;_WINDOWS;_USRDLL;DYNAMIC_EXPORTS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
243+
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
242244
</ClCompile>
243245
<Link>
244246
<SubSystem>Windows</SubSystem>

0 commit comments

Comments
 (0)