Skip to content

Commit

Permalink
StaticCrt test fixed for VS2008-2012
Browse files Browse the repository at this point in the history
  • Loading branch information
KindDragon committed Nov 6, 2015
1 parent 03aa5cb commit b6bef88
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 20 deletions.
4 changes: 3 additions & 1 deletion src/callstack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -594,12 +594,14 @@ bool CallStack::isCrtStartupModule( const PWSTR filename ) const
endWith(filename, len, L"\\crt\\crtw32\\startup\\stdenvp.c") ||
endWith(filename, len, L"\\crt\\crtw32\\startup\\tidtable.c") ||
endWith(filename, len, L"\\crt\\crtw32\\mbstring\\mbctype.c") ||
// VS2010
// VS2012 and bellow
endWith(filename, len, L"\\crt\\src\\crt0dat.c") || //_cinit()
endWith(filename, len, L"\\crt\\src\\onexit.c") || //__onexitinit()
endWith(filename, len, L"\\crt\\src\\stdargv.c") || //_wsetargv()
endWith(filename, len, L"\\crt\\src\\stdenvp.c") || //_wsetenvp()
endWith(filename, len, L"\\crt\\src\\ioinit.c") || //_ioinit()
endWith(filename, len, L"\\crt\\src\\tidtable.c") || //_mtinit()
endWith(filename, len, L"\\crt\\src\\mbctype.c") || //__initmbctable()
// default
(false);
}
Expand Down
16 changes: 16 additions & 0 deletions src/tests/suite/testsuite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,17 @@ enum action_e {
// Name of the debug C Runtime Library DLL on this system
#ifdef _DEBUG
#if _MSC_VER == 1400 // VS 2005
#ifdef _DLL
#define CRTDLLNAME _T("msvcr80d.dll")
#else
#define CRTDLLNAME _T("msvcrt.dll")
#endif
#elif _MSC_VER == 1500 // VS 2008
#ifdef _DLL
#define CRTDLLNAME _T("msvcr90d.dll")
#else
#define CRTDLLNAME _T("msvcrt.dll")
#endif
#elif _MSC_VER == 1600 // VS 2010
#define CRTDLLNAME _T("msvcr100d.dll")
#elif _MSC_VER == 1700 // VS 2012
Expand All @@ -68,9 +76,17 @@ enum action_e {
#endif
#else
#if _MSC_VER == 1400 // VS 2005
#ifdef _DLL
#define CRTDLLNAME _T("msvcr80.dll")
#else
#define CRTDLLNAME _T("msvcrt.dll")
#endif
#elif _MSC_VER == 1500 // VS 2008
#ifdef _DLL
#define CRTDLLNAME _T("msvcr90.dll")
#else
#define CRTDLLNAME _T("msvcrt.dll")
#endif
#elif _MSC_VER == 1600 // VS 2010
#define CRTDLLNAME _T("msvcr100.dll")
#elif _MSC_VER == 1700 // VS 2012
Expand Down
40 changes: 21 additions & 19 deletions src/tests/vld_unload/vld_unload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,57 +46,59 @@ TEST(TestUnloadDlls, Sequence1)
ASSERT_EQ(NULL, GetModuleHandle(sVld_dll));
HMODULE hModule1 = ::LoadLibrary(_T("vld_dll1.dll"));
int w = VLDGetLeaksCount(); // vld is loaded and counts 1 memory leak
EXPECT_EQ(1, w);
::FreeLibrary(hModule1); // vld is unloaded here and reports the memory leak
int x = VLDGetLeaksCount(); // vld is unloaded and cannot count any memory leaks
EXPECT_EQ(-1, x);

HMODULE hModule2 = ::LoadLibrary(_T("vld_dll2.dll"));
int y = VLDGetLeaksCount(); // vld is loaded and counts 1 memory leak
EXPECT_EQ(1, y);
::FreeLibrary(hModule2); // vld is unloaded here and reports the memory leak
int z = VLDGetLeaksCount(); // vld is unloaded and cannot count any memory leaks

assert(w == 1 && x == -1 && y == 1 && z == -1);
ASSERT_EQ(1, w);
ASSERT_EQ(-1, x);
ASSERT_EQ(1, y);
ASSERT_EQ(-1, z);
EXPECT_EQ(-1, z);
}

TEST(TestUnloadDlls, Sequence2)
{
ASSERT_EQ(NULL, GetModuleHandle(sVld_dll));
HMODULE hModule3 = ::LoadLibrary(_T("vld_dll1.dll"));
int w = VLDGetLeaksCount(); // vld is loaded and counts 1 memory leak
EXPECT_EQ(1, w);
HMODULE hModule4 = ::LoadLibrary(_T("vld_dll2.dll"));
int x = VLDGetLeaksCount(); // vld is still loaded and counts 2 memory leaks
EXPECT_EQ(2, x);
::FreeLibrary(hModule4); // vld is *not* unloaded here
int y = VLDGetLeaksCount(); // vld is still loaded and counts 2 memory leaks
int y = VLDGetLeaksCount();
#if _MSC_VER <= 1600 && !defined(_DLL) // VS 2010 and bellow
EXPECT_EQ(1, y); // vld is still loaded and counts 1 memory leaks

This comment has been minimized.

Copy link
@ioannis-e

ioannis-e Nov 6, 2015

@KindDragon Maybe add a comment here so we know why the test behaves differently in these versions

The reason for reporting 1 leak at this point is that the vld_dll1 module build with <VS2013 calls internally
HeapDestroy when it unloads and the leak is either
 - reported automatically by VLD when the Heap is destroyed if VLD_OPT_SKIP_HEAPFREE_LEAKS was specified or
 - ignored since the destroyed Heap was removed from VLD heap map.

Ideally for me we should save the HeapDetroy leaks and report them together with all other leaks so the test would be consistent. The only difference would be that these leaks will not have a memory dump as it is unavailable at this point.

#else
EXPECT_EQ(2, y); // vld is still loaded and counts 2 memory leaks
#endif
::FreeLibrary(hModule3); // vld is unloaded here and reports 2 memory leaks
int z = VLDGetLeaksCount(); // vld is unloaded and cannot count any memory leaks

assert(w == 1 && x == 2 && y == 2 && z == -1);
ASSERT_EQ(1, w);
ASSERT_EQ(2, x);
ASSERT_EQ(2, y);
ASSERT_EQ(-1, z);
EXPECT_EQ(-1, z);
}

TEST(TestUnloadDlls, Sequence3)
{
ASSERT_EQ(NULL, GetModuleHandle(sVld_dll));
HMODULE hModule5 = ::LoadLibrary(_T("vld_dll1.dll"));
int w = VLDGetLeaksCount(); // vld is loaded and counts 1 memory leak
EXPECT_EQ(1, w);
HMODULE hModule6 = ::LoadLibrary(_T("vld_dll2.dll"));
int x = VLDGetLeaksCount(); // vld is still loaded and counts 2 memory leaks
EXPECT_EQ(2, x);
::FreeLibrary(hModule5); // vld is *not* unloaded here
int y = VLDGetLeaksCount(); // vld is still loaded and counts 2 memory leaks
#if _MSC_VER <= 1600 && !defined(_DLL) // VS 2010 and bellow
EXPECT_EQ(1, y); // vld is still loaded and counts 1 memory leaks

This comment has been minimized.

Copy link
@ioannis-e

ioannis-e Nov 6, 2015

Same as above

#else
EXPECT_EQ(2, y); // vld is still loaded and counts 2 memory leaks
#endif
::FreeLibrary(hModule6); // vld is unloaded here and reports 2 memory leaks
int z = VLDGetLeaksCount(); // vld is unloaded and cannot count any memory leaks

assert(w == 1 && x == 2 && y == 2 && z == -1);
ASSERT_EQ(1, w);
ASSERT_EQ(2, x);
ASSERT_EQ(2, y);
ASSERT_EQ(-1, z);
EXPECT_EQ(-1, z);
}

TEST(TestUnloadDlls, Sequence4)
Expand Down

0 comments on commit b6bef88

Please sign in to comment.