From 81770872710a2c2395ec8ba8e4dcf24e3753a4ee Mon Sep 17 00:00:00 2001 From: Eldar Akchurin Date: Fri, 30 Oct 2015 13:15:30 +0000 Subject: [PATCH] Skeleton of the boost unit test project --- CNTK.sln | 20 ++- Tests/UnitTests/MathTests/CPUMatrix.cpp | 87 ++++++++++++ Tests/UnitTests/MathTests/MathTests.vcxproj | 149 ++++++++++++++++++++ Tests/UnitTests/MathTests/stdafx.cpp | 7 + Tests/UnitTests/MathTests/stdafx.h | 13 ++ Tests/UnitTests/MathTests/targetver.h | 12 ++ 6 files changed, 283 insertions(+), 5 deletions(-) create mode 100644 Tests/UnitTests/MathTests/CPUMatrix.cpp create mode 100644 Tests/UnitTests/MathTests/MathTests.vcxproj create mode 100644 Tests/UnitTests/MathTests/stdafx.cpp create mode 100644 Tests/UnitTests/MathTests/stdafx.h create mode 100644 Tests/UnitTests/MathTests/targetver.h diff --git a/CNTK.sln b/CNTK.sln index 7c83ce25f087..d30e5b6ef2f4 100644 --- a/CNTK.sln +++ b/CNTK.sln @@ -401,6 +401,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ndl", "ndl", "{09B8623A-BF5 Tests\Speech\Data\ndl\macros.txt = Tests\Speech\Data\ndl\macros.txt EndProjectSection EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "UnitTests", "UnitTests", "{6F19321A-65E7-4829-B00C-3886CD6C6EDE}" +EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MathTests", "Tests\UnitTests\MathTests\MathTests.vcxproj", "{4701E678-5E6F-470D-B348-9CD1A2C095D1}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|x64 = Debug|x64 @@ -472,6 +476,10 @@ Global {7C4E77C9-6B17-4B02-82C1-DB62EEE2635B}.Debug|x64.Build.0 = Debug|x64 {7C4E77C9-6B17-4B02-82C1-DB62EEE2635B}.Release|x64.ActiveCfg = Release|x64 {7C4E77C9-6B17-4B02-82C1-DB62EEE2635B}.Release|x64.Build.0 = Release|x64 + {9BD0A746-0BBD-45B6-B81C-053F03C26CFB}.Debug|x64.ActiveCfg = Debug|x64 + {9BD0A746-0BBD-45B6-B81C-053F03C26CFB}.Debug|x64.Build.0 = Debug|x64 + {9BD0A746-0BBD-45B6-B81C-053F03C26CFB}.Release|x64.ActiveCfg = Release|x64 + {9BD0A746-0BBD-45B6-B81C-053F03C26CFB}.Release|x64.Build.0 = Release|x64 {928ABD1B-4D3B-4017-AEF1-0FA1B4467513}.Debug|x64.ActiveCfg = Debug|x64 {928ABD1B-4D3B-4017-AEF1-0FA1B4467513}.Debug|x64.Build.0 = Debug|x64 {928ABD1B-4D3B-4017-AEF1-0FA1B4467513}.Release|x64.ActiveCfg = Release|x64 @@ -484,10 +492,10 @@ Global {EAD17188-072C-4726-B840-A769C36DAD1B}.Debug|x64.Build.0 = Debug|x64 {EAD17188-072C-4726-B840-A769C36DAD1B}.Release|x64.ActiveCfg = Release|x64 {EAD17188-072C-4726-B840-A769C36DAD1B}.Release|x64.Build.0 = Release|x64 - {9BD0A746-0BBD-45B6-B81C-053F03C26CFB}.Debug|x64.ActiveCfg = Debug|x64 - {9BD0A746-0BBD-45B6-B81C-053F03C26CFB}.Debug|x64.Build.0 = Debug|x64 - {9BD0A746-0BBD-45B6-B81C-053F03C26CFB}.Release|x64.ActiveCfg = Release|x64 - {9BD0A746-0BBD-45B6-B81C-053F03C26CFB}.Release|x64.Build.0 = Release|x64 + {4701E678-5E6F-470D-B348-9CD1A2C095D1}.Debug|x64.ActiveCfg = Debug|x64 + {4701E678-5E6F-470D-B348-9CD1A2C095D1}.Debug|x64.Build.0 = Debug|x64 + {4701E678-5E6F-470D-B348-9CD1A2C095D1}.Release|x64.ActiveCfg = Release|x64 + {4701E678-5E6F-470D-B348-9CD1A2C095D1}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -522,6 +530,7 @@ Global {5F733BBA-FE83-4668-8F83-8B0E78A36619} = {C47CDAA5-6D6C-429E-BC89-7CA0F868FDC8} {19EE975B-232D-49F0-94C7-6F1C6424FB53} = {C47CDAA5-6D6C-429E-BC89-7CA0F868FDC8} {7C4E77C9-6B17-4B02-82C1-DB62EEE2635B} = {D45DF403-6781-444E-B654-A96868C5BE68} + {9BD0A746-0BBD-45B6-B81C-053F03C26CFB} = {33EBFE78-A1A8-4961-8938-92A271941F94} {928ABD1B-4D3B-4017-AEF1-0FA1B4467513} = {DD043083-71A4-409A-AA91-F9C548DCF7EC} {DE3C54E5-D7D0-47AF-A783-DFDCE59E7937} = {DD043083-71A4-409A-AA91-F9C548DCF7EC} {5E666C53-2D82-49C9-9127-3FDDC321C741} = {D45DF403-6781-444E-B654-A96868C5BE68} @@ -529,7 +538,6 @@ Global {B6725C9F-A6D2-4269-9B74-7888A90F7884} = {5E666C53-2D82-49C9-9127-3FDDC321C741} {B27DD434-EECD-4EE0-A03B-1150EB87258E} = {B6725C9F-A6D2-4269-9B74-7888A90F7884} {A4884465-CFBB-4A64-A9DE-690E1A63EF7E} = {B6725C9F-A6D2-4269-9B74-7888A90F7884} - {9BD0A746-0BBD-45B6-B81C-053F03C26CFB} = {33EBFE78-A1A8-4961-8938-92A271941F94} {3E9C89B1-C045-4F42-92B2-F9FFFFC2DBD4} = {39E42C4B-A078-4CA4-9D92-B883D8129601} {C70E1572-20FF-496C-A0A9-10AA6755A07C} = {39E42C4B-A078-4CA4-9D92-B883D8129601} {EAD17188-072C-4726-B840-A769C36DAD1B} = {DD043083-71A4-409A-AA91-F9C548DCF7EC} @@ -540,5 +548,7 @@ Global {40F93928-5CA2-433A-A48C-C8E9A35D7079} = {6994C86D-A672-4254-824A-51F4DFEB807F} {39B9BB97-D0E8-439A-8A1B-8DB8E7CF73C3} = {6994C86D-A672-4254-824A-51F4DFEB807F} {09B8623A-BF5D-4499-B3B3-A9EFEA4C4B68} = {5F733BBA-FE83-4668-8F83-8B0E78A36619} + {6F19321A-65E7-4829-B00C-3886CD6C6EDE} = {D45DF403-6781-444E-B654-A96868C5BE68} + {4701E678-5E6F-470D-B348-9CD1A2C095D1} = {6F19321A-65E7-4829-B00C-3886CD6C6EDE} EndGlobalSection EndGlobal diff --git a/Tests/UnitTests/MathTests/CPUMatrix.cpp b/Tests/UnitTests/MathTests/CPUMatrix.cpp new file mode 100644 index 000000000000..fb6bbbad7f0f --- /dev/null +++ b/Tests/UnitTests/MathTests/CPUMatrix.cpp @@ -0,0 +1,87 @@ +// +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// +#include "stdafx.h" +#include "..\..\..\Math\Math\CPUMatrix.h" + +#include + +#define BOOST_TEST_MODULE MathTests +#define BOOST_TEST_MAIN +#include + +using namespace Microsoft::MSR::CNTK; + +namespace Microsoft +{ + namespace MSR + { + namespace CNTK + { + namespace Test + { + typedef CPUDoubleMatrix DMatrix; + typedef CPUSingleMatrix SMatrix; + + BOOST_AUTO_TEST_SUITE(CpuMatrixSuite) + + BOOST_AUTO_TEST_CASE(CPUMatrixConstructorNoFlags) + { + DMatrix m; + BOOST_CHECK(m.IsEmpty()); + + m.Resize(2, 3); + BOOST_CHECK(!m.IsEmpty()); + + BOOST_CHECK_EQUAL(m.GetNumRows(), 2); + BOOST_CHECK_EQUAL(m.GetNumCols(), 3); + BOOST_CHECK_EQUAL(m.GetNumElements(), 6); + + m(0, 0) = 1; + m(1, 2) = 2; + BOOST_CHECK_EQUAL(m(0, 0), 1); + BOOST_CHECK_EQUAL(m(1, 2), 2); + + DMatrix m1(m); + BOOST_CHECK(m1.IsEqualTo(m)); + } + + BOOST_AUTO_TEST_CASE(CPUMatrixConstructorFlagNormal) + { + std::array tmp = { 1, 2, 3, 4, 5, 6 }; + + float* array = new float[6]; + std::copy(tmp.begin(), tmp.end(), array); + + SMatrix m(2, 3, array, matrixFlagNormal); + BOOST_CHECK_EQUAL(m(0, 0), 1); + BOOST_CHECK_EQUAL(m(0, 1), 3); + BOOST_CHECK_EQUAL(m(0, 2), 5); + BOOST_CHECK_EQUAL(m(1, 0), 2); + BOOST_CHECK_EQUAL(m(1, 1), 4); + BOOST_CHECK_EQUAL(m(1, 2), 6); + } + + BOOST_AUTO_TEST_CASE(CPUMatrixConstructorFormatRowMajor) + { + std::array tmp = { 7, 8, 9, 10, 11, 12 }; + + double *array = new double[6]; + std::copy(tmp.begin(), tmp.end(), array); + + DMatrix m(2, 3, array, matrixFormatRowMajor); + BOOST_CHECK_EQUAL(m(0, 0), 7); + BOOST_CHECK_EQUAL(m(0, 1), 8); + BOOST_CHECK_EQUAL(m(0, 2), 9); + BOOST_CHECK_EQUAL(m(1, 0), 10); + BOOST_CHECK_EQUAL(m(1, 1), 11); + BOOST_CHECK_EQUAL(m(1, 2), 12); + } + + BOOST_AUTO_TEST_SUITE_END() + } + } + } +} \ No newline at end of file diff --git a/Tests/UnitTests/MathTests/MathTests.vcxproj b/Tests/UnitTests/MathTests/MathTests.vcxproj new file mode 100644 index 000000000000..28ea5cc8c6e8 --- /dev/null +++ b/Tests/UnitTests/MathTests/MathTests.vcxproj @@ -0,0 +1,149 @@ + + + + + Debug + x64 + + + Release + x64 + + + + {4701E678-5E6F-470D-B348-9CD1A2C095D1} + Win32Proj + MathTests + + + + Application + true + v120 + Unicode + false + + + + + true + + + + + false + + + + + Application + false + v120 + true + Unicode + false + + + + + + + + + + + + + + true + $(IncludePath) + $(Platform)\$(Configuration)\$(ProjectName)\ + $(LibraryPath) + $(SolutionDir)$(Platform)\$(Configuration)\UnitTests\ + + + true + $(IncludePath);$(VCInstallDir)include;$(VCInstallDir)atlmfc\include;$(WindowsSDK_IncludePath); + $(Platform)\$(Configuration)\$(ProjectName)\ + $(SolutionDir)$(Platform)\$(Configuration)\UnitTests\ + + + + NotUsing + Level4 + Disabled + $(BOOST_INCLUDE_PATH);..\..\..\common\include\;%(AdditionalIncludeDirectories) + WIN32;_DEBUG;%(PreprocessorDefinitions) + true + true + true + + + Console + true + $(BOOST_LIB_PATH);%(AdditionalLibraryDirectories) + + + 64 + compute_20,sm_20;compute_30,sm_30;%(CodeGeneration) + + + xcopy /Y $(SolutionDir)$(Platform)\$(Configuration)\*.dll $(OutDir) + + + + + Level4 + Use + MaxSpeed + true + true + $(BOOST_INCLUDE_PATH);..\..\..\common\include;%(AdditionalIncludeDirectories) + WIN32;NDEBUG;%(PreprocessorDefinitions) + true + true + true + false + /d2Zi+ %(AdditionalOptions) + + + Console + true + true + true + $(BOOST_LIB_PATH);%(AdditionalLibraryDirectories) + + + xcopy /Y $(SolutionDir)$(Platform)\$(Configuration)\*.dll $(OutDir) + + + + + + + + + Create + Create + + + + + + {60bdb847-d0c4-4fd3-a947-0c15c08bcdb5} + true + true + false + true + false + + + + + + + + + + + \ No newline at end of file diff --git a/Tests/UnitTests/MathTests/stdafx.cpp b/Tests/UnitTests/MathTests/stdafx.cpp new file mode 100644 index 000000000000..9fa3b7d3471e --- /dev/null +++ b/Tests/UnitTests/MathTests/stdafx.cpp @@ -0,0 +1,7 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// +// stdafx.cpp : source file that includes just the standard includes + +#include "stdafx.h" \ No newline at end of file diff --git a/Tests/UnitTests/MathTests/stdafx.h b/Tests/UnitTests/MathTests/stdafx.h new file mode 100644 index 000000000000..b14c6f389474 --- /dev/null +++ b/Tests/UnitTests/MathTests/stdafx.h @@ -0,0 +1,13 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// +// +// stdafx.h : include file for standard system include files, +// or project specific include files that are used frequently, but +// are changed infrequently + +#pragma once + +#define _CRT_SECURE_NO_WARNINGS // "secure" CRT not available on all platforms +#define _SCL_SECURE_NO_WARNINGS // current API of matrix does not allow safe invokations. TODO: change api to proper one. +#include "targetver.h" \ No newline at end of file diff --git a/Tests/UnitTests/MathTests/targetver.h b/Tests/UnitTests/MathTests/targetver.h new file mode 100644 index 000000000000..d27646b3e455 --- /dev/null +++ b/Tests/UnitTests/MathTests/targetver.h @@ -0,0 +1,12 @@ +// +// Copyright (c) Microsoft Corporation. All rights reserved. +// + +#pragma once + +// Including SDKDDKVer.h defines the highest available Windows platform. + +// If you wish to build your application for a previous Windows platform, include WinSDKVer.h and +// set the _WIN32_WINNT macro to the platform you wish to support before including SDKDDKVer.h. + +#include