msvc: get UnitTests compiling

Choose it from VS or pass /p:RunUnitTests=true to msbuild
This commit is contained in:
Shawn Hoffman 2014-08-31 05:52:21 -07:00
parent 0625b5defb
commit 839cace5ff
10 changed files with 146 additions and 7 deletions

View File

@ -161,6 +161,12 @@ extern "C"
__declspec(dllimport) void __stdcall DebugBreak(void); __declspec(dllimport) void __stdcall DebugBreak(void);
} }
#define Crash() {DebugBreak();} #define Crash() {DebugBreak();}
#if (_MSC_VER > 1800)
#error alignof compat can be removed
#else
#define alignof(x) __alignof(x)
#endif
#endif // WIN32 ndef #endif // WIN32 ndef
// Generic function to get last error message. // Generic function to get last error message.

View File

@ -209,7 +209,7 @@
</ImportGroup> </ImportGroup>
<!--Copy Exe, Data directory and DLLs which should be located in the executable directory--> <!--Copy Exe, Data directory and DLLs which should be located in the executable directory-->
<ItemGroup> <ItemGroup>
<DataDirFiles Include="$(SolutionDir)..\Data\**\*.*" /> <DataDirFiles Include="$(DolphinRootDir)Data\**\*.*" />
<ExternalDlls Include="$(ExternalsDir)OpenAL\$(PlatformName)\*.dll;$(ExternalsDir)msvcrt\$(PlatformName)\*.dll" /> <ExternalDlls Include="$(ExternalsDir)OpenAL\$(PlatformName)\*.dll;$(ExternalsDir)msvcrt\$(PlatformName)\*.dll" />
<BinaryFiles Include="$(TargetPath)" /> <BinaryFiles Include="$(TargetPath)" />
<AllInputFiles Include="@(DataDirFiles);@(ExternalDlls);@(BinaryFiles)" /> <AllInputFiles Include="@(DataDirFiles);@(ExternalDlls);@(BinaryFiles)" />

View File

@ -139,7 +139,8 @@ TEST(BitField, Alignment)
GC_ALIGNED16(OddlyAlignedTestStruct test_struct); GC_ALIGNED16(OddlyAlignedTestStruct test_struct);
TestUnion& object = test_struct.obj; TestUnion& object = test_struct.obj;
static_assert(alignof(test_struct.obj.signed_1bit) == 1, "Incorrect variable alignment"); static_assert(alignof(decltype(test_struct.obj.signed_1bit)) == 1,
"Incorrect variable alignment");
for (u64 val : table) for (u64 val : table)
{ {

View File

@ -13,6 +13,9 @@ TEST(CommonFuncs, ArraySizeMacro)
EXPECT_EQ(4u, ArraySize(test)); EXPECT_EQ(4u, ArraySize(test));
EXPECT_EQ(42u, ArraySize(test2)); EXPECT_EQ(42u, ArraySize(test2));
(void)test;
(void)test2;
} }
TEST(CommonFuncs, RoundUpPow2Macro) TEST(CommonFuncs, RoundUpPow2Macro)

View File

@ -37,7 +37,7 @@ TEST(Flag, MultiThreaded)
int count = 0; int count = 0;
const int ITERATIONS_COUNT = 100000; const int ITERATIONS_COUNT = 100000;
auto setter = [&f]() { auto setter = [&]() {
for (int i = 0; i < ITERATIONS_COUNT; ++i) for (int i = 0; i < ITERATIONS_COUNT; ++i)
{ {
while (f.IsSet()); while (f.IsSet());
@ -45,7 +45,7 @@ TEST(Flag, MultiThreaded)
} }
}; };
auto clearer = [&f, &count]() { auto clearer = [&]() {
for (int i = 0; i < ITERATIONS_COUNT; ++i) for (int i = 0; i < ITERATIONS_COUNT; ++i)
{ {
while (!f.IsSet()); while (!f.IsSet());

View File

@ -19,6 +19,7 @@ void Host_UpdateDisasmDialog() {}
void Host_UpdateMainFrame() {} void Host_UpdateMainFrame() {}
void Host_GetRenderWindowSize(int&, int&, int&, int&) {} void Host_GetRenderWindowSize(int&, int&, int&, int&) {}
void Host_RequestRenderWindowSize(int, int) {} void Host_RequestRenderWindowSize(int, int) {}
void Host_RequestFullscreen(bool) {}
void Host_SetStartupDebuggingParameters() {} void Host_SetStartupDebuggingParameters() {}
bool Host_UIHasFocus() { return false; } bool Host_UIHasFocus() { return false; }
bool Host_RendererHasFocus() { return false; } bool Host_RendererHasFocus() { return false; }

View File

@ -0,0 +1,112 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectGuid>{474661E7-C73A-43A6-AFEE-EE1EC433D49E}</ProjectGuid>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<PlatformToolset>v120</PlatformToolset>
<CharacterSet>Unicode</CharacterSet>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Debug'" Label="Configuration">
<UseDebugLibraries>true</UseDebugLibraries>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'" Label="Configuration">
<UseDebugLibraries>false</UseDebugLibraries>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="..\VSProps\Base.props" />
<Import Project="..\VSProps\PCHUse.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<ItemDefinitionGroup>
<!--This project also compiles gtest-->
<ClCompile>
<AdditionalIncludeDirectories>$(ExternalsDir)gtest\include;$(ExternalsDir)gtest;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<Link>
<!--This junk is needed for JIT to function correctly-->
<BaseAddress>0x00400000</BaseAddress>
<RandomizedBaseAddress>false</RandomizedBaseAddress>
<FixedBaseAddress>true</FixedBaseAddress>
<!--
The following libs are needed since we pull in pretty much the entire
dolphin codebase.
-->
<AdditionalLibraryDirectories>$(ExternalsDir)OpenAL\$(PlatformName);%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>iphlpapi.lib;winmm.lib;setupapi.lib;vfw32.lib;opengl32.lib;glu32.lib;rpcrt4.lib;comctl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<SubSystem>Console</SubSystem>
</Link>
</ItemDefinitionGroup>
<ItemGroup>
<!--gtest is rather small, so just include it into the build here-->
<ClCompile Include="$(ExternalsDir)gtest\src\gtest-all.cc" />
<ClCompile Include="$(ExternalsDir)gtest\src\gtest_main.cc" />
<!--Lump all of the tests (and supporting code) into one binary-->
<ClCompile Include="*\*.cpp" />
</ItemGroup>
<ItemGroup>
<Text Include="CMakeLists.txt" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="$(CoreDir)Core\Core.vcxproj">
<Project>{E54CF649-140E-4255-81A5-30A673C1FB36}</Project>
</ProjectReference>
<ProjectReference Include="$(CoreDir)VideoBackends\D3D\D3D.vcxproj">
<Project>{96020103-4ba5-4fd2-b4aa-5b6d24492d4e}</Project>
</ProjectReference>
<ProjectReference Include="$(CoreDir)VideoBackends\OGL\OGL.vcxproj">
<Project>{ec1a314c-5588-4506-9c1e-2e58e5817f75}</Project>
</ProjectReference>
<ProjectReference Include="$(CoreDir)VideoBackends\Software\Software.vcxproj">
<Project>{a4c423aa-f57c-46c7-a172-d1a777017d29}</Project>
</ProjectReference>
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
<!--
This project is always built, but the outputs are conditionally executed.
The tests will either be run by VS' test runner (requires a plugin to adapt
to gtest - developers will mostly use this method), or via msbuild (the
buildbot does it this way). The gtest adapter has the restriction that it
can only scan for tests on binaries it knows about (e.g. from projects' OutDir),
and it doesn't allow changing the working directory for running the tests.
Essentially this requires all runtime dependencies to be findable from the
context of the tests running with working directory set to OutDir. So...
that was the long-winded explanation of why we copy external things to the
OutDir :)
-->
<ItemGroup>
<ExternalDlls Include="$(ExternalsDir)OpenAL\$(PlatformName)\*.dll" />
</ItemGroup>
<!--Either method of running requires the runtime deps to be copied to pwd-->
<Target Name="CopyDeps"
AfterTargets="AfterBuild"
Inputs="@(ExternalDlls)"
Outputs="@(ExternalDlls -> '$(OutDir)%(RecursiveDir)%(Filename)%(Extension)')">
<Copy SourceFiles="@(ExternalDlls)" DestinationFolder="$(OutDir)"
Condition="!Exists('$(OutDir)%(RecursiveDir)%(Filename)%(ExternalDlls.Extension)') OR $([System.DateTime]::Parse('%(ModifiedTime)').Ticks) &gt; $([System.IO.File]::GetLastWriteTime('$(OutDir)%(RecursiveDir)%(Filename)%(ExternalDlls.Extension)').Ticks)" />
</Target>
<Target Name="ExecUnitTests"
AfterTargets="AfterBuild;CopyDeps"
Condition="'$(RunUnitTests)'=='true'">
<!--This is only executed via msbuild, VS test runner automatically does this-->
<Exec Command="$(TargetPath)"/>
</Target>
</Project>

View File

@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="12.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<!--For some stupid reason this has to be in the .user file...-->
<!--This is only used to allow UnitTests to find OpenAL DLL...kinda hacky-->
<LocalDebuggerWorkingDirectory>$(BinaryOutputDir)</LocalDebuggerWorkingDirectory>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
</PropertyGroup>
</Project>

View File

@ -6,10 +6,11 @@
<TargetSuffix> <TargetSuffix>
</TargetSuffix> </TargetSuffix>
<TargetSuffix Condition="'$(Configuration)'=='Debug'">D</TargetSuffix> <TargetSuffix Condition="'$(Configuration)'=='Debug'">D</TargetSuffix>
<BuildRootDir>$(SolutionDir)..\Build\</BuildRootDir> <DolphinRootDir>$(SolutionDir)..\</DolphinRootDir>
<BinaryRootDir>$(SolutionDir)..\Binary\</BinaryRootDir> <BuildRootDir>$(DolphinRootDir)Build\</BuildRootDir>
<BinaryRootDir>$(DolphinRootDir)Binary\</BinaryRootDir>
<BinaryOutputDir>$(BinaryRootDir)$(Platform)\</BinaryOutputDir> <BinaryOutputDir>$(BinaryRootDir)$(Platform)\</BinaryOutputDir>
<ExternalsDir>$(SolutionDir)..\Externals\</ExternalsDir> <ExternalsDir>$(DolphinRootDir)Externals\</ExternalsDir>
<CoreDir>$(SolutionDir)Core\</CoreDir> <CoreDir>$(SolutionDir)Core\</CoreDir>
</PropertyGroup> </PropertyGroup>
<PropertyGroup> <PropertyGroup>

View File

@ -61,6 +61,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Video Backends", "Video Bac
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pch", "PCH\pch.vcxproj", "{76563A7F-1011-4EAD-B667-7BB18D09568E}" Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "pch", "PCH\pch.vcxproj", "{76563A7F-1011-4EAD-B667-7BB18D09568E}"
EndProject EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTests", "UnitTests\UnitTests.vcxproj", "{474661E7-C73A-43A6-AFEE-EE1EC433D49E}"
EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|x64 = Debug|x64 Debug|x64 = Debug|x64
@ -171,6 +173,10 @@ Global
{76563A7F-1011-4EAD-B667-7BB18D09568E}.Debug|x64.Build.0 = Debug|x64 {76563A7F-1011-4EAD-B667-7BB18D09568E}.Debug|x64.Build.0 = Debug|x64
{76563A7F-1011-4EAD-B667-7BB18D09568E}.Release|x64.ActiveCfg = Release|x64 {76563A7F-1011-4EAD-B667-7BB18D09568E}.Release|x64.ActiveCfg = Release|x64
{76563A7F-1011-4EAD-B667-7BB18D09568E}.Release|x64.Build.0 = Release|x64 {76563A7F-1011-4EAD-B667-7BB18D09568E}.Release|x64.Build.0 = Release|x64
{474661E7-C73A-43A6-AFEE-EE1EC433D49E}.Debug|x64.ActiveCfg = Debug|x64
{474661E7-C73A-43A6-AFEE-EE1EC433D49E}.Debug|x64.Build.0 = Debug|x64
{474661E7-C73A-43A6-AFEE-EE1EC433D49E}.Release|x64.ActiveCfg = Release|x64
{474661E7-C73A-43A6-AFEE-EE1EC433D49E}.Release|x64.Build.0 = Release|x64
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE