Skip to content

Commit 51bc52c

Browse files
committed
Adding option to TestRunner to use CRT leak detection.
1 parent e11402d commit 51bc52c

File tree

6 files changed

+24
-78
lines changed

6 files changed

+24
-78
lines changed

Build/Common.Build.settings

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,23 +15,6 @@
1515
<Platform Condition="'$(Platform)'==''">Win32</Platform>
1616
</PropertyGroup>
1717

18-
<!-- for Visual Leak Detector -->
19-
<ItemDefinitionGroup Condition="'$(CASA_ENABLE_VLD)' != ''">
20-
<ClCompile>
21-
<AdditionalOptions>/DCASA_ENABLE_VLD %(AdditionalOptions)</AdditionalOptions>
22-
</ClCompile>
23-
</ItemDefinitionGroup>
24-
<ItemDefinitionGroup Condition="'$(CASA_ENABLE_VLD)' != '' AND '$(Platform)'=='Win32'">
25-
<Link>
26-
<AdditionalLibraryDirectories>"C:\Program Files (x86)\Visual Leak Detector\lib\Win32";%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
27-
</Link>
28-
</ItemDefinitionGroup>
29-
<ItemDefinitionGroup Condition="'$(CASA_ENABLE_VLD)' != '' AND '$(Platform)'=='x64'">
30-
<Link>
31-
<AdditionalLibraryDirectories>"C:\Program Files (x86)\Visual Leak Detector\lib\Win64";%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
32-
</Link>
33-
</ItemDefinitionGroup>
34-
3518
<!-- for root paths -->
3619
<PropertyGroup>
3720
<BuildRoot>$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), build.root))</BuildRoot>

Build/Release.Tests.settings

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,6 @@
1919
<TestListenerPath>$(TestRoot)\Functional\http\utilities\testlistener</TestListenerPath>
2020
<CasablancaIncludeDir>$(BinariesDirectory)\inc;$(CasablancaIncludeDir);$(TestListenerPath)\include;</CasablancaIncludeDir>
2121
</PropertyGroup>
22-
23-
<!-- Keeping the paths for Casablanca in VS installation in one common place instead of hardcoded in each test. -->
24-
<PropertyGroup Condition="'$(BuildAgainstVSInstallation)'!=''">
25-
<CasablancaVSSdkDir>$([MSBuild]::GetRegistryValue(`HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Casablanca\120\SDK`, `InstallDir`))</CasablancaVSSdkDir>
26-
<CasablancaVSExtentionSDKDir>C:\Program Files (x86)\Microsoft SDKs\Windows\v8.1\ExtensionSDKs\CppRESTWindowsSDK\1.0</CasablancaVSExtentionSDKDir>
27-
<CasablancaIncludeDir>$(CasablancaIncludeDir);$(CasablancaVSSdkDir)\include</CasablancaIncludeDir>
28-
<CasablancaVSLibDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(CasablancaVSSdkDir)\lib\x86\Debug\</CasablancaVSLibDir>
29-
<CasablancaVSLibDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(CasablancaVSSdkDir)\lib\x86\Release\</CasablancaVSLibDir>
30-
<CasablancaVSLibDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(CasablancaVSSdkDir)\lib\x64\Debug\</CasablancaVSLibDir>
31-
<CasablancaVSLibDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(CasablancaVSSdkDir)\lib\x64\Release\</CasablancaVSLibDir>
32-
<CasablancaVSLibDir Condition="'$(Configuration)|$(Platform)'=='Debug|ARM'">$(CasablancaVSSdkDir)\lib\arm\Debug\</CasablancaVSLibDir>
33-
<CasablancaVSLibDir Condition="'$(Configuration)|$(Platform)'=='Release|ARM'">$(CasablancaVSSdkDir)\lib\arm\Release\</CasablancaVSLibDir>
34-
</PropertyGroup>
3522

3623
<!-- Target that can be used to easily strip the AppContainer requirement from a dll -->
3724
<Target Name="StripAppContainerOnProjectDll">

Release/src/utilities/asyncrt_utils.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ using namespace boost::locale::conv;
4040
#include <CoreFoundation/CoreFoundation.h>
4141
#endif
4242

43-
// For more details see https://casablanca.codeplex.com/wikipage?title=Running%20Leak%20Detection&IsNewlyCreatedPage=true
44-
#if defined(CASA_ENABLE_VLD)
45-
#include "C:/Program Files (x86)/Visual Leak Detector/include/vld.h"
46-
#endif
47-
4843
using namespace web;
4944
using namespace utility;
5045
using namespace utility::conversions;

Release/tests/common/TestRunner/test_runner.cpp

Lines changed: 24 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
#include <iostream>
2626
#include <regex>
2727

28-
#ifdef WIN32
28+
#ifdef _WIN32
2929
#include <Windows.h>
3030
#include <conio.h>
3131
#else
@@ -45,7 +45,7 @@
4545

4646
static void print_help()
4747
{
48-
std::cout << "Usage: testrunner.exe <test_binaries> [/list] [/listproperties] [/noignore] [/breakonerror]" <<std::endl;
48+
std::cout << "Usage: testrunner.exe <test_binaries> [/list] [/listproperties] [/noignore] [/breakonerror] [/detectleaks]" <<std::endl;
4949
std::cout << " [/name:<test_name>] [/select:@key=value] [/loop:<num_times>]" << std::endl;
5050
std::cout << std::endl;
5151
std::cout << " /list List all the names of the test_binaries and their" << std::endl;
@@ -55,6 +55,7 @@ static void print_help()
5555
std::cout << " test properties." << std::endl;
5656
std::cout << std::endl;
5757
std::cout << " /breakonerror Break into the debugger when a failure is encountered." << std::endl;
58+
std::cout << " /detectleaks Turns CRT leak detection and prints any leaks, Windows only." << std::endl;
5859
std::cout << std::endl;
5960
std::cout << " /name:<test_name> Run only test cases with matching name. Can contain the" << std::endl;
6061
std::cout << " wildcard '*' character." << std::endl;
@@ -84,7 +85,7 @@ static std::vector<std::string> get_files_in_directory()
8485
{
8586
std::vector<std::string> files;
8687

87-
#ifdef WIN32
88+
#ifdef _WIN32
8889

8990
char exe_directory_buffer[MAX_PATH];
9091
GetModuleFileNameA(NULL, exe_directory_buffer, MAX_PATH);
@@ -347,7 +348,7 @@ static void handle_list_option(bool listProperties, const UnitTest::TestList &te
347348

348349
static void ChangeConsoleTextColorToRed()
349350
{
350-
#ifdef WIN32
351+
#ifdef _WIN32
351352
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0004 | 0x0008);
352353
#else
353354
std::cout << "\033[1;31m";
@@ -356,7 +357,7 @@ static void ChangeConsoleTextColorToRed()
356357

357358
static void ChangeConsoleTextColorToGreen()
358359
{
359-
#ifdef WIN32
360+
#ifdef _WIN32
360361
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), 0x0002 | 0x0008);
361362
#else
362363
std::cout << "\033[1;32m";
@@ -365,7 +366,7 @@ static void ChangeConsoleTextColorToGreen()
365366

366367
static void ChangeConsoleTextColorToGrey()
367368
{
368-
#ifdef WIN32
369+
#ifdef _WIN32
369370
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_GREEN);
370371
#else
371372
std::cout << "\033[0m";
@@ -375,7 +376,7 @@ static void ChangeConsoleTextColorToGrey()
375376
bool IsTestIgnored(UnitTest::Test *pTest)
376377
{
377378
if(pTest->m_properties.Has("Ignore")) return true;
378-
#ifdef WIN32
379+
#ifdef _WIN32
379380
if(pTest->m_properties.Has("Ignore:Windows")) return true;
380381
#elif defined(__APPLE__)
381382
if(pTest->m_properties.Has("Ignore:Apple")) return true;
@@ -387,24 +388,6 @@ bool IsTestIgnored(UnitTest::Test *pTest)
387388
return false;
388389
}
389390

390-
//
391-
// These are to handle cases where an exception or assert occurs on a thread
392-
// that isn't being waited on and the process exits. These shouldn't be happening,
393-
// but could happen if we have a bug.
394-
//
395-
#ifdef WIN32
396-
397-
int CrtReportHandler(int reportType, char *message, int *returnValue)
398-
{
399-
std::cerr << "In CRT Report Handler. ReportType:" << reportType << ", message:" << message << std::endl;
400-
401-
// Cause break into debugger.
402-
*returnValue = 1;
403-
return TRUE;
404-
}
405-
406-
#endif
407-
408391
typedef std::map<std::string, UnitTest::TestList> testlist_t;
409392

410393
void list_test_options(testlist_t& testlists)
@@ -525,7 +508,15 @@ void run_all_tests(UnitTest::TestRunner& testRunner, testlist_t& testlists)
525508

526509
int main(int argc, char* argv[])
527510
{
528-
#ifdef WIN32
511+
#ifdef _WIN32
512+
// Add standard error as output as well.
513+
_CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE | _CRTDBG_MODE_WNDW);
514+
_CrtSetReportFile(_CRT_ASSERT, _CRTDBG_FILE_STDERR);
515+
_CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE | _CRTDBG_MODE_WNDW);
516+
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
517+
_CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
518+
_CrtSetReportFile(_CRT_WARN, _CRTDBG_FILE_STDERR);
519+
529520
// The test runner built with WinRT support might be used on a pre Win8 machine.
530521
// Obviously in that case WinRT test cases can't run, but non WinRT ones should be
531522
// fine. So dynamically try to call RoInitialize/RoUninitialize.
@@ -540,7 +531,6 @@ int main(int argc, char* argv[])
540531
}
541532
}
542533

543-
_CrtSetReportHook2(_CRT_RPTHOOK_INSTALL, CrtReportHandler);
544534
struct console_restorer {
545535
CONSOLE_SCREEN_BUFFER_INFO m_originalConsoleInfo;
546536
console_restorer()
@@ -585,6 +575,12 @@ int main(int argc, char* argv[])
585575
listOption = true;
586576
listPropertiesOption = true;
587577
}
578+
#ifdef _WIN32
579+
if (UnitTest::GlobalSettings::Has("detectleaks"))
580+
{
581+
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
582+
}
583+
#endif
588584

589585
// Start timer.
590586
UnitTest::Timer timer;
@@ -639,7 +635,7 @@ int main(int argc, char* argv[])
639635
<< "Took " << elapsedTime << "ms" << std::endl;
640636
}
641637

642-
#ifdef WIN32
638+
#ifdef _WIN32
643639
if(hComBase != nullptr)
644640
{
645641
typedef void (WINAPI *RoUnInit)();

Release/tests/common/UnitTestpp/unittestpp.h

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,3 @@
4040
#include "src/GlobalSettings.h"
4141

4242
#endif
43-
44-
// For more details see https://casablanca.codeplex.com/wikipage?title=Running%20Leak%20Detection&IsNewlyCreatedPage=true
45-
#if defined(CASA_ENABLE_VLD)
46-
#include "C:/Program Files (x86)/Visual Leak Detector/include/vld.h"
47-
48-
// vld.h pulls in Windows.h
49-
#undef max
50-
#undef min
51-
52-
#endif

Release/tests/common/utilities/stdafx.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,3 @@
3434
#include <Windows.h>
3535

3636
#endif
37-
38-
// For more details see https://casablanca.codeplex.com/wikipage?title=Running%20Leak%20Detection&IsNewlyCreatedPage=true
39-
#if defined(CASA_ENABLE_VLD)
40-
#include "C:/Program Files (x86)/Visual Leak Detector/include/vld.h"
41-
#endif

0 commit comments

Comments
 (0)