diff --git a/.appveyor.yml b/.appveyor.yml
index 4aed91183..ac2b4f7e9 100644
--- a/.appveyor.yml
+++ b/.appveyor.yml
@@ -10,4 +10,10 @@ clone_depth: 10
build:
project: etc/visual-studio/openthread.sln
verbosity: minimal
-test: off
\ No newline at end of file
+test_script:
+- cmd: >-
+ set Platform2=%Platform%
+
+ if %Platform2%==x86 set Platform2=Win32
+
+ vstest.console /logger:Appveyor /inIsolation /platform:%Platform% build\bin\%Platform2%\%Configuration%\dll\UnitTests.dll
\ No newline at end of file
diff --git a/etc/visual-studio/UnitTests.vcxproj b/etc/visual-studio/UnitTests.vcxproj
new file mode 100644
index 000000000..0633b875c
--- /dev/null
+++ b/etc/visual-studio/UnitTests.vcxproj
@@ -0,0 +1,194 @@
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ {FD64BF17-8D36-4578-8D13-77B123BE30D3}
+ Win32Proj
+ UnitTests
+ 8.1
+
+
+
+ DynamicLibrary
+ true
+ v140
+ Unicode
+ false
+
+
+ DynamicLibrary
+ false
+ v140
+ true
+ Unicode
+ false
+
+
+ DynamicLibrary
+ true
+ v140
+ Unicode
+ false
+
+
+ DynamicLibrary
+ false
+ v140
+ true
+ Unicode
+ false
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ ..\..\build\bin\$(Platform)\$(Configuration)\dll\
+ ..\..\build\obj\$(Platform)\$(Configuration)\$(ProjectName)\
+
+
+ true
+ ..\..\build\bin\$(Platform)\$(Configuration)\dll\
+ ..\..\build\obj\$(Platform)\$(Configuration)\$(ProjectName)\
+
+
+ false
+ ..\..\build\bin\$(Platform)\$(Configuration)\dll\
+ ..\..\build\obj\$(Platform)\$(Configuration)\$(ProjectName)\
+
+
+ false
+ ..\..\build\bin\$(Platform)\$(Configuration)\dll\
+ ..\..\build\obj\$(Platform)\$(Configuration)\$(ProjectName)\
+
+
+
+ Level3
+ Disabled
+ $(VCInstallDir)UnitTest\include;..\..\include;..\..\src;..\..\src\core;..\..\third_party\mbedtls;..\..\third_party\mbedtls\repo\include;%(AdditionalIncludeDirectories)
+ WIN32;_DEBUG;MBEDTLS_CONFIG_FILE="mbedtls-config.h";OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";%(PreprocessorDefinitions)
+ true
+
+
+ Windows
+ $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)
+ ..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread.lib;..\..\build\bin\$(Platform)\$(Configuration)\lib\mbedtls.lib;%(AdditionalDependencies)
+
+
+
+
+ Level3
+ Disabled
+ $(VCInstallDir)UnitTest\include;..\..\include;..\..\src;..\..\src\core;..\..\third_party\mbedtls;..\..\third_party\mbedtls\repo\include;%(AdditionalIncludeDirectories)
+ _DEBUG;MBEDTLS_CONFIG_FILE="mbedtls-config.h";OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";%(PreprocessorDefinitions)
+ true
+
+
+
+
+ Windows
+ $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)
+ ..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread.lib;..\..\build\bin\$(Platform)\$(Configuration)\lib\mbedtls.lib;%(AdditionalDependencies)
+
+
+
+
+ Level3
+ MaxSpeed
+ true
+ true
+ $(VCInstallDir)UnitTest\include;..\..\include;..\..\src;..\..\src\core;..\..\third_party\mbedtls;..\..\third_party\mbedtls\repo\include;%(AdditionalIncludeDirectories)
+ WIN32;NDEBUG;MBEDTLS_CONFIG_FILE="mbedtls-config.h";OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";%(PreprocessorDefinitions)
+ true
+
+
+ Windows
+ true
+ true
+ $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)
+ ..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread.lib;..\..\build\bin\$(Platform)\$(Configuration)\lib\mbedtls.lib;%(AdditionalDependencies)
+
+
+
+
+ Level3
+ MaxSpeed
+ true
+ true
+ $(VCInstallDir)UnitTest\include;..\..\include;..\..\src;..\..\src\core;..\..\third_party\mbedtls;..\..\third_party\mbedtls\repo\include;%(AdditionalIncludeDirectories)
+ NDEBUG;MBEDTLS_CONFIG_FILE="mbedtls-config.h";OPENTHREAD_CONFIG_FILE="openthread-windows-config.h";%(PreprocessorDefinitions)
+ true
+
+
+
+
+ Windows
+ true
+ true
+ $(VCInstallDir)UnitTest\lib;%(AdditionalLibraryDirectories)
+ ..\..\build\bin\$(Platform)\$(Configuration)\lib\libopenthread.lib;..\..\build\bin\$(Platform)\$(Configuration)\lib\mbedtls.lib;%(AdditionalDependencies)
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {dd5018be-54c6-4fd4-9f8d-08d52fc0cd40}
+
+
+ {4111c8bb-d354-4348-ad3c-eb6832e84831}
+
+
+
+
+
+
\ No newline at end of file
diff --git a/etc/visual-studio/UnitTests.vcxproj.filters b/etc/visual-studio/UnitTests.vcxproj.filters
new file mode 100644
index 000000000..9f59c14dc
--- /dev/null
+++ b/etc/visual-studio/UnitTests.vcxproj.filters
@@ -0,0 +1,66 @@
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hh;hpp;hxx;hm;inl;inc;xsd
+
+
+ {67DA6AB6-F800-4c08-8B7A-83BB121AAD01}
+ rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms
+
+
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+ Source Files
+
+
+
+
+ Header Files
+
+
+ Header Files
+
+
+ Header Files
+
+
+
\ No newline at end of file
diff --git a/etc/visual-studio/openthread.sln b/etc/visual-studio/openthread.sln
index e87e8e186..fd1ea5adc 100644
--- a/etc/visual-studio/openthread.sln
+++ b/etc/visual-studio/openthread.sln
@@ -3,6 +3,19 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "config files", "config files", "{53F4EEF6-B96D-4887-B9CF-CD21E8BECD15}"
+ ProjectSection(SolutionItems) = preProject
+ ..\..\.appveyor.yml = ..\..\.appveyor.yml
+ ..\..\.codecov.yml = ..\..\.codecov.yml
+ ..\..\.travis.yml = ..\..\.travis.yml
+ EndProjectSection
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{95BD0669-04C8-4EEB-B3CC-0535B03F4468}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{35F6AB71-5BD2-4D53-8A51-D75CCD4CCC3D}"
+EndProject
+Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "third_party", "third_party", "{873E9D16-2A08-41FC-B301-79C95B3A8F98}"
+EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libopenthread", "libopenthread.vcxproj", "{DD5018BE-54C6-4FD4-9F8D-08D52FC0CD40}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "libopenthread_k", "libopenthread_k.vcxproj", "{9B33C190-5D07-40BF-9536-68843DC5D7AF}"
@@ -11,16 +24,7 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mbedtls", "mbedtls.vcxproj"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mbedtls_k", "mbedtls_k.vcxproj", "{69BE8E8C-CF1E-46D6-932B-DB435F47059B}"
EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{95BD0669-04C8-4EEB-B3CC-0535B03F4468}"
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "third_party", "third_party", "{873E9D16-2A08-41FC-B301-79C95B3A8F98}"
-EndProject
-Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "config files", "config files", "{53F4EEF6-B96D-4887-B9CF-CD21E8BECD15}"
- ProjectSection(SolutionItems) = preProject
- ..\..\.appveyor.yml = ..\..\.appveyor.yml
- ..\..\.codecov.yml = ..\..\.codecov.yml
- ..\..\.travis.yml = ..\..\.travis.yml
- EndProjectSection
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "UnitTests", "UnitTests.vcxproj", "{FD64BF17-8D36-4578-8D13-77B123BE30D3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
@@ -66,6 +70,14 @@ Global
{69BE8E8C-CF1E-46D6-932B-DB435F47059B}.Release|x86.ActiveCfg = Release|Win32
{69BE8E8C-CF1E-46D6-932B-DB435F47059B}.Release|x86.Build.0 = Release|Win32
{69BE8E8C-CF1E-46D6-932B-DB435F47059B}.Release|x86.Deploy.0 = Release|Win32
+ {FD64BF17-8D36-4578-8D13-77B123BE30D3}.Debug|x64.ActiveCfg = Debug|x64
+ {FD64BF17-8D36-4578-8D13-77B123BE30D3}.Debug|x64.Build.0 = Debug|x64
+ {FD64BF17-8D36-4578-8D13-77B123BE30D3}.Debug|x86.ActiveCfg = Debug|Win32
+ {FD64BF17-8D36-4578-8D13-77B123BE30D3}.Debug|x86.Build.0 = Debug|Win32
+ {FD64BF17-8D36-4578-8D13-77B123BE30D3}.Release|x64.ActiveCfg = Release|x64
+ {FD64BF17-8D36-4578-8D13-77B123BE30D3}.Release|x64.Build.0 = Release|x64
+ {FD64BF17-8D36-4578-8D13-77B123BE30D3}.Release|x86.ActiveCfg = Release|Win32
+ {FD64BF17-8D36-4578-8D13-77B123BE30D3}.Release|x86.Build.0 = Release|Win32
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -75,5 +87,6 @@ Global
{9B33C190-5D07-40BF-9536-68843DC5D7AF} = {95BD0669-04C8-4EEB-B3CC-0535B03F4468}
{4111C8BB-D354-4348-AD3C-EB6832E84831} = {873E9D16-2A08-41FC-B301-79C95B3A8F98}
{69BE8E8C-CF1E-46D6-932B-DB435F47059B} = {873E9D16-2A08-41FC-B301-79C95B3A8F98}
+ {FD64BF17-8D36-4578-8D13-77B123BE30D3} = {35F6AB71-5BD2-4D53-8A51-D75CCD4CCC3D}
EndGlobalSection
EndGlobal
diff --git a/include/openthread-windows-config.h b/include/openthread-windows-config.h
index 61d53bc1b..c1a10abb1 100644
--- a/include/openthread-windows-config.h
+++ b/include/openthread-windows-config.h
@@ -70,6 +70,9 @@
#define snprintf sprintf_s
#endif // WINDOWS_KERNEL
+// Redefine rand to random for test code
+#define random rand
+
// Temporary !!! TODO - Remove this once we figure out the strncpy issue
#define _CRT_SECURE_NO_WARNINGS
diff --git a/tests/unit/Makefile.am b/tests/unit/Makefile.am
index 88fc2726b..77c4a676e 100644
--- a/tests/unit/Makefile.am
+++ b/tests/unit/Makefile.am
@@ -57,7 +57,6 @@ AM_CPPFLAGS = \
COMMON_LDADD = \
$(top_builddir)/src/core/libopenthread.a \
- $(top_builddir)/examples/platforms/posix/libopenthread-posix.a \
$(top_builddir)/third_party/mbedtls/libmbedcrypto.a \
-lpthread \
$(NULL)
@@ -109,31 +108,31 @@ TESTS_ENVIRONMENT = \
# Source, compiler, and linker options for test programs.
test_aes_LDADD = $(COMMON_LDADD)
-test_aes_SOURCES = test_aes.cpp
+test_aes_SOURCES = test_platform.cpp test_aes.cpp
test_hmac_sha256_LDADD = $(COMMON_LDADD)
-test_hmac_sha256_SOURCES = test_hmac_sha256.cpp
+test_hmac_sha256_SOURCES = test_platform.cpp test_hmac_sha256.cpp
test_link_quality_LDADD = $(COMMON_LDADD)
-test_link_quality_SOURCES = test_link_quality.cpp
+test_link_quality_SOURCES = test_platform.cpp test_link_quality.cpp
test_lowpan_LDADD = $(COMMON_LDADD)
-test_lowpan_SOURCES = test_lowpan.cpp test_util.cpp test_vector.c
+test_lowpan_SOURCES = test_platform.cpp test_lowpan.cpp test_util.cpp test_vector.c
test_mac_frame_LDADD = $(COMMON_LDADD)
-test_mac_frame_SOURCES = test_mac_frame.cpp
+test_mac_frame_SOURCES = test_platform.cpp test_mac_frame.cpp
test_message_LDADD = $(COMMON_LDADD)
-test_message_SOURCES = test_message.cpp
+test_message_SOURCES = test_platform.cpp test_message.cpp
test_ncp_buffer_LDADD = $(COMMON_LDADD)
-test_ncp_buffer_SOURCES = test_ncp_buffer.cpp
+test_ncp_buffer_SOURCES = test_platform.cpp test_ncp_buffer.cpp
test_timer_LDADD = $(COMMON_LDADD)
-test_timer_SOURCES = test_timer.cpp
+test_timer_SOURCES = test_platform.cpp test_timer.cpp
test_toolchain_LDADD = $(COMMON_LDADD)
-test_toolchain_SOURCES = test_toolchain.cpp
+test_toolchain_SOURCES = test_platform.cpp test_toolchain.cpp
if OPENTHREAD_ENABLE_DIAG
test_diag_LDADD = $(top_builddir)/src/diag/libopenthread-diag.a \
diff --git a/tests/unit/test_aes.cpp b/tests/unit/test_aes.cpp
index cfa927775..f2895ec3c 100644
--- a/tests/unit/test_aes.cpp
+++ b/tests/unit/test_aes.cpp
@@ -35,10 +35,6 @@
static Thread::Crypto::MbedTls mbedtls;
-extern"C" void otSignalTaskletPending(otInstance *)
-{
-}
-
/**
* Verifies test vectors from IEEE 802.15.4-2006 Annex C Section C.2.1
*/
@@ -233,6 +229,7 @@ void TestMacCommandFrame()
"TestMacCommandFrame decrypt failed\n");
}
+#ifdef ENABLE_TEST_MAIN
int main(void)
{
TestMacBeaconFrame();
@@ -241,3 +238,4 @@ int main(void)
printf("All tests passed\n");
return 0;
}
+#endif
diff --git a/tests/unit/test_diag.cpp b/tests/unit/test_diag.cpp
index 545e76bfb..269ab6409 100644
--- a/tests/unit/test_diag.cpp
+++ b/tests/unit/test_diag.cpp
@@ -165,9 +165,11 @@ void TestDiag()
}
}
+#ifdef ENABLE_TEST_MAIN
int main(void)
{
TestDiag();
printf("All tests passed\n");
return 0;
}
+#endif
diff --git a/tests/unit/test_hmac_sha256.cpp b/tests/unit/test_hmac_sha256.cpp
index 303d240d8..526d72e24 100644
--- a/tests/unit/test_hmac_sha256.cpp
+++ b/tests/unit/test_hmac_sha256.cpp
@@ -36,10 +36,6 @@
static Thread::Crypto::MbedTls mbedtls;
-extern"C" void otSignalTaskletPending(otInstance *)
-{
-}
-
void TestHmacSha256(void)
{
static const struct
@@ -80,9 +76,11 @@ void TestHmacSha256(void)
}
}
+#ifdef ENABLE_TEST_MAIN
int main(void)
{
TestHmacSha256();
printf("All tests passed\n");
return 0;
}
+#endif
diff --git a/tests/unit/test_link_quality.cpp b/tests/unit/test_link_quality.cpp
index 0e24306d8..e322618cc 100644
--- a/tests/unit/test_link_quality.cpp
+++ b/tests/unit/test_link_quality.cpp
@@ -34,10 +34,6 @@
namespace Thread {
-extern"C" void otSignalTaskletPending(otInstance *)
-{
-}
-
enum
{
kMaxRssValue = 0,
@@ -342,6 +338,7 @@ void TestLinkQualityCalculations(void)
} // namespace Thread
+#ifdef ENABLE_TEST_MAIN
int main(void)
{
Thread::TestRssAveraging();
@@ -349,3 +346,4 @@ int main(void)
printf("All tests passed\n");
return 0;
}
+#endif
diff --git a/tests/unit/test_lowpan.cpp b/tests/unit/test_lowpan.cpp
index 19f3319a0..b079bca8f 100644
--- a/tests/unit/test_lowpan.cpp
+++ b/tests/unit/test_lowpan.cpp
@@ -40,41 +40,6 @@ using namespace Thread;
namespace Thread {
-extern "C" void otSignalTaskletPending(otInstance *)
-{
-}
-
-extern "C" bool otAreTaskletsPending(otInstance *)
-{
- return false;
-}
-
-extern "C" void otPlatUartSendDone(void)
-{
-}
-
-extern "C" void otPlatUartReceived(const uint8_t *aBuf, uint16_t aBufLength)
-{
- (void)aBuf;
- (void)aBufLength;
-}
-
-extern "C" void otPlatDiagAlarmFired(otInstance *)
-{
-}
-
-extern "C" void otPlatDiagRadioTransmitDone(otInstance *, bool aRxPending, ThreadError aError)
-{
- (void)aRxPending;
- (void)aError;
-}
-
-extern "C" void otPlatDiagRadioReceiveDone(otInstance *, RadioPacket *aFrame, ThreadError aError)
-{
- (void)aFrame;
- (void)aError;
-}
-
Ip6::Ip6 sIp6;
ThreadNetif sMockThreadNetif(sIp6);
Lowpan::Lowpan sMockLowpan(sMockThreadNetif);
@@ -162,7 +127,7 @@ void TestLowpanIphc(void)
} // namespace Thread
-
+#ifdef ENABLE_TEST_MAIN
int main(void)
{
TestLowpanIphc();
@@ -170,3 +135,4 @@ int main(void)
printf("All tests passed\n");
return 0;
}
+#endif
diff --git a/tests/unit/test_mac_frame.cpp b/tests/unit/test_mac_frame.cpp
index 89f2ccdb1..45a384517 100644
--- a/tests/unit/test_mac_frame.cpp
+++ b/tests/unit/test_mac_frame.cpp
@@ -34,10 +34,6 @@
namespace Thread {
-extern"C" void otSignalTaskletPending(otInstance *)
-{
-}
-
void TestMacHeader(void)
{
static const struct
@@ -88,9 +84,11 @@ void TestMacHeader(void)
} // namespace Thread
+#ifdef ENABLE_TEST_MAIN
int main(void)
{
Thread::TestMacHeader();
printf("All tests passed\n");
return 0;
}
+#endif
diff --git a/tests/unit/test_message.cpp b/tests/unit/test_message.cpp
index de7296c14..3a9cb0d0c 100644
--- a/tests/unit/test_message.cpp
+++ b/tests/unit/test_message.cpp
@@ -32,14 +32,6 @@
#include
#include
-extern"C" void otSignalTaskletPending(otInstance *)
-{
-}
-
-extern "C" void otPlatDiagAlarmFired(otInstance *)
-{
-}
-
void TestMessage(void)
{
Thread::MessagePool messagePool;
@@ -68,9 +60,11 @@ void TestMessage(void)
"Message::Free failed\n");
}
+#ifdef ENABLE_TEST_MAIN
int main(void)
{
TestMessage();
printf("All tests passed\n");
return 0;
}
+#endif
diff --git a/tests/unit/test_ncp_buffer.cpp b/tests/unit/test_ncp_buffer.cpp
index f010b0e29..9053540d3 100644
--- a/tests/unit/test_ncp_buffer.cpp
+++ b/tests/unit/test_ncp_buffer.cpp
@@ -36,14 +36,6 @@ namespace Thread {
// This module implements unit-test for NcpFrameBuffer class.
-extern"C" void otSignalTaskletPending(otInstance *)
-{
-}
-
-extern "C" void otPlatDiagAlarmFired(otInstance *)
-{
-}
-
enum
{
kTestBufferSize = 101, // Size of backed buffer for NcpFrameBuffer.
@@ -468,9 +460,11 @@ void TestNcpFrameBuffer(void)
} // namespace Thread
+#ifdef ENABLE_TEST_MAIN
int main(void)
{
Thread::TestNcpFrameBuffer();
printf("\nAll tests passed.\n");
return 0;
}
+#endif
diff --git a/tests/unit/test_platform.cpp b/tests/unit/test_platform.cpp
new file mode 100644
index 000000000..be68167ac
--- /dev/null
+++ b/tests/unit/test_platform.cpp
@@ -0,0 +1,258 @@
+/*
+ * Copyright (c) 2016, The OpenThread Authors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#if _WIN32
+#define _CRT_SECURE_NO_WARNINGS
+#include
+#endif
+
+#include
+
+#include
+#include
+#include
+#include
+#include
+
+#include
+#include
+
+enum
+{
+ kCallCountIndexAlarmStop = 0,
+ kCallCountIndexAlarmStart,
+ kCallCountIndexTimerHandler,
+
+ kCallCountIndexMax
+};
+
+uint32_t sNow;
+uint32_t sPlatT0;
+uint32_t sPlatDt;
+bool sTimerOn;
+uint32_t sCallCount[kCallCountIndexMax];
+
+bool sDiagMode = false;
+
+extern "C" {
+
+ void otSignalTaskletPending(otInstance *)
+ {
+ }
+
+ bool otAreTaskletsPending(otInstance *)
+ {
+ return false;
+ }
+
+ //
+ // Alarm
+ //
+
+ void otPlatAlarmStop(otInstance *)
+ {
+ sTimerOn = false;
+ sCallCount[kCallCountIndexAlarmStop]++;
+ }
+
+ void otPlatAlarmStartAt(otInstance *, uint32_t aT0, uint32_t aDt)
+ {
+ sTimerOn = true;
+ sCallCount[kCallCountIndexAlarmStart]++;
+ sPlatT0 = aT0;
+ sPlatDt = aDt;
+ }
+
+ uint32_t otPlatAlarmGetNow(void)
+ {
+ return sNow;
+ }
+
+ //
+ // Radio
+ //
+
+ void otPlatRadioGetIeeeEui64(otInstance *, uint8_t *)
+ {
+ }
+
+ ThreadError otPlatRadioSetPanId(otInstance *, uint16_t)
+ {
+ return kThreadError_None;
+ }
+
+ ThreadError otPlatRadioSetExtendedAddress(otInstance *, uint8_t *)
+ {
+ return kThreadError_None;
+ }
+
+ ThreadError otPlatRadioSetShortAddress(otInstance *, uint16_t)
+ {
+ return kThreadError_None;
+ }
+
+ void otPlatRadioSetPromiscuous(otInstance *, bool)
+ {
+ }
+
+ ThreadError otPlatRadioEnable(otInstance *)
+ {
+ return kThreadError_None;
+ }
+
+ ThreadError otPlatRadioDisable(otInstance *)
+ {
+ return kThreadError_None;
+ }
+
+ ThreadError otPlatRadioSleep(otInstance *)
+ {
+ return kThreadError_None;
+ }
+
+ ThreadError otPlatRadioReceive(otInstance *, uint8_t)
+ {
+ return kThreadError_None;
+ }
+
+ ThreadError otPlatRadioTransmit(otInstance *)
+ {
+ return kThreadError_None;
+ }
+
+ RadioPacket *otPlatRadioGetTransmitBuffer(otInstance *)
+ {
+ return (RadioPacket *)0;
+ }
+
+ int8_t otPlatRadioGetRssi(otInstance *)
+ {
+ return 0;
+ }
+
+ otRadioCaps otPlatRadioGetCaps(otInstance *)
+ {
+ return kRadioCapsNone;
+ }
+
+ bool otPlatRadioGetPromiscuous(otInstance *)
+ {
+ return false;
+ }
+
+ //
+ // Random
+ //
+
+ uint32_t otPlatRandomGet(void)
+ {
+#if _WIN32
+ return (uint32_t)rand();
+#else
+ return (uint32_t)random();
+#endif
+ }
+
+ ThreadError otPlatRandomSecureGet(uint16_t aInputLength, uint8_t *aOutput, uint16_t *aOutputLength)
+ {
+ ThreadError error = kThreadError_None;
+
+ VerifyOrExit(aOutput && aOutputLength, error = kThreadError_InvalidArgs);
+
+ for (uint16_t length = 0; length < aInputLength; length++)
+ {
+ aOutput[length] = (uint8_t)otPlatRandomGet();
+ }
+
+ *aOutputLength = aInputLength;
+
+exit:
+ return error;
+ }
+
+ //
+ // Diag
+ //
+
+ void otPlatDiagProcess(int argc, char *argv[], char *aOutput)
+ {
+ // no more diagnostics features for Posix platform
+ sprintf(aOutput, "diag feature '%s' is not supported\r\n", argv[0]);
+ (void)argc;
+ }
+
+ void otPlatDiagModeSet(bool aMode)
+ {
+ sDiagMode = aMode;
+ }
+
+ bool otPlatDiagModeGet()
+ {
+ return sDiagMode;
+ }
+
+ void otPlatDiagAlarmFired(otInstance *)
+ {
+ }
+
+ void otPlatDiagRadioTransmitDone(otInstance *, bool, ThreadError)
+ {
+ }
+
+ void otPlatDiagRadioReceiveDone(otInstance *, RadioPacket *, ThreadError)
+ {
+ }
+
+ //
+ // Uart
+ //
+
+ void otPlatUartSendDone(void)
+ {
+ }
+
+ void otPlatUartReceived(const uint8_t *, uint16_t)
+ {
+ }
+
+ //
+ // Misc
+ //
+
+ void otPlatReset(otInstance *aInstance)
+ {
+ (void)aInstance;
+ }
+
+ otPlatResetReason otPlatGetResetReason(otInstance *aInstance)
+ {
+ (void)aInstance;
+ return kPlatResetReason_PowerOn;
+ }
+
+} // extern "C"
\ No newline at end of file
diff --git a/tests/unit/test_timer.cpp b/tests/unit/test_timer.cpp
index cd4966b20..5c89c49dd 100644
--- a/tests/unit/test_timer.cpp
+++ b/tests/unit/test_timer.cpp
@@ -43,34 +43,11 @@ enum
};
static Thread::TimerScheduler sTimerScheduler;
-static uint32_t sNow;
-static uint32_t sPlatT0;
-static uint32_t sPlatDt;
-static bool sTimerOn;
-static uint32_t sCallCount[kCallCountIndexMax];
-
-extern "C" {
-
- void otPlatAlarmStop(otInstance *)
- {
- sTimerOn = false;
- sCallCount[kCallCountIndexAlarmStop]++;
- }
-
- void otPlatAlarmStartAt(otInstance *, uint32_t aT0, uint32_t aDt)
- {
- sTimerOn = true;
- sCallCount[kCallCountIndexAlarmStart]++;
- sPlatT0 = aT0;
- sPlatDt = aDt;
- }
-
- uint32_t otPlatAlarmGetNow(void)
- {
- return sNow;
- }
-
-} // extern "C"
+extern uint32_t sNow;
+extern uint32_t sPlatT0;
+extern uint32_t sPlatDt;
+extern bool sTimerOn;
+extern uint32_t sCallCount[kCallCountIndexMax];
void InitCounters(void)
{
@@ -409,9 +386,11 @@ void RunTimerTests(void)
TestTenTimers();
}
+#ifdef ENABLE_TEST_MAIN
int main(void)
{
RunTimerTests();
printf("All tests passed\n");
return 0;
}
+#endif
diff --git a/tests/unit/test_toolchain.cpp b/tests/unit/test_toolchain.cpp
index 9a1b9f35f..9e0e976b2 100644
--- a/tests/unit/test_toolchain.cpp
+++ b/tests/unit/test_toolchain.cpp
@@ -34,23 +34,29 @@
void test_packed1()
{
- typedef OT_TOOL_PACKED_BEGIN struct
+ OT_TOOL_PACKED_BEGIN
+ struct packed_t
{
uint8_t mByte;
uint32_t mWord;
uint16_t mShort;
- } OT_TOOL_PACKED_END packed_t;
+ } OT_TOOL_PACKED_END;
+
+ CompileTimeAssert(sizeof(packed_t) == 7, "packed_t should be packed to 7 bytes");
VerifyOrQuit(sizeof(packed_t) == 7, "Toolchain::OT_TOOL_PACKED failed 1\n");
}
void test_packed2()
{
- typedef OT_TOOL_PACKED_BEGIN struct
+ OT_TOOL_PACKED_BEGIN
+ struct packed_t
{
uint8_t mBytes[3];
uint8_t mByte;
- } OT_TOOL_PACKED_END packed_t;
+ } OT_TOOL_PACKED_END;
+
+ CompileTimeAssert(sizeof(packed_t) == 4, "packed_t should be packed to 4 bytes");
VerifyOrQuit(sizeof(packed_t) == 4, "Toolchain::OT_TOOL_PACKED failed 2\n");
}
@@ -62,7 +68,8 @@ void test_packed_union()
uint16_t mField;
} nested_t;
- typedef OT_TOOL_PACKED_BEGIN struct
+ OT_TOOL_PACKED_BEGIN
+ struct packed_t
{
uint8_t mBytes[3];
union
@@ -70,7 +77,9 @@ void test_packed_union()
nested_t mNestedStruct;
uint8_t mByte;
} OT_TOOL_PACKED_FIELD;
- } OT_TOOL_PACKED_END packed_t;
+ } OT_TOOL_PACKED_END;
+
+ CompileTimeAssert(sizeof(packed_t) == 5, "packed_t should be packed to 5 bytes");
VerifyOrQuit(sizeof(packed_t) == 5, "Toolchain::OT_TOOL_PACKED failed 3\n");
}
@@ -92,9 +101,11 @@ void TestToolchain(void)
test_packed_enum();
}
+#ifdef ENABLE_TEST_MAIN
int main(void)
{
TestToolchain();
printf("All tests passed\n");
return 0;
}
+#endif
diff --git a/tests/unit/test_util.h b/tests/unit/test_util.h
index 4c10042b2..1e26d2aec 100644
--- a/tests/unit/test_util.h
+++ b/tests/unit/test_util.h
@@ -34,10 +34,15 @@
#include
+#ifndef _WIN32
+
#ifdef __cplusplus
extern "C" {
#endif
+// Enable main functions
+#define ENABLE_TEST_MAIN
+
#define SuccessOrQuit(ERR, MSG) \
do { \
if ((ERR) != kThreadError_None) \
@@ -58,8 +63,30 @@ extern "C" {
} \
} while (0)
+//#define CompileTimeAssert(COND, MSG) typedef char __C_ASSERT__[(COND)?1:-1]
+
+// I would use the above definition for CompileTimeAssert, but I am getting the following errors
+// when I run 'make -f examples/Makefile-posix distcheck':
+//
+// error: typedef ‘__C_ASSERT__’ locally defined but not used [-Werror=unused-local-typedefs]
+//
+#define CompileTimeAssert(COND, MSG)
+
#ifdef __cplusplus
}
#endif
+#else
+
+typedef void (*utAssertTrue)(bool condition, const wchar_t *message);
+extern utAssertTrue s_AssertTrue;
+
+#define SuccessOrQuit(ERR, MSG) s_AssertTrue((ERR) == kThreadError_None, L##MSG)
+
+#define VerifyOrQuit(ERR, MSG) s_AssertTrue(ERR, L##MSG)
+
+#define CompileTimeAssert(COND, MSG) static_assert(COND, MSG)
+
+#endif
+
#endif
diff --git a/tests/unit/test_windows.cpp b/tests/unit/test_windows.cpp
new file mode 100644
index 000000000..d374b411f
--- /dev/null
+++ b/tests/unit/test_windows.cpp
@@ -0,0 +1,126 @@
+/*
+ * Copyright (c) 2016, The OpenThread Authors.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the copyright holder nor the
+ * names of its contributors may be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include
+#include "CppUnitTest.h"
+#include "test_util.h"
+
+using namespace Microsoft::VisualStudio::CppUnitTestFramework;
+
+#pragma region Test Declarations
+
+// test_aes.cpp
+void TestMacBeaconFrame();
+void TestMacDataFrame();
+void TestMacCommandFrame();
+
+// test_hmac_sha256.cpp
+void TestHmacSha256();
+
+// test_link_quality.cpp
+namespace Thread
+{
+ void TestRssAveraging();
+ void TestLinkQualityCalculations();
+}
+
+// test_lowpan.cpp
+namespace Thread
+{
+ void TestLowpanIphc();
+}
+
+// test_mac_frame.cpp
+namespace Thread
+{
+ void TestMacHeader();
+}
+
+// test_message.cpp
+void TestMessage();
+
+// test_timer.cpp
+int TestOneTimer();
+int TestTenTimers();
+
+// test_toolchain.cpp
+void test_packed1();
+void test_packed2();
+void test_packed_union();
+void test_packed_enum();
+
+#pragma endregion
+
+utAssertTrue s_AssertTrue;
+
+namespace Thread
+{
+ TEST_CLASS(UnitTests)
+ {
+ public:
+
+ UnitTests() { s_AssertTrue = AssertTrue; }
+
+ // Helper for openthread test code to call
+ static void AssertTrue(bool condition, const wchar_t* message)
+ {
+ Assert::IsTrue(condition, message);
+ }
+
+ // test_aes.cpp
+ TEST_METHOD(TestMacBeaconFrame) { ::TestMacBeaconFrame(); }
+ TEST_METHOD(TestMacDataFrame) { ::TestMacDataFrame(); }
+ TEST_METHOD(TestMacCommandFrame) { ::TestMacCommandFrame(); }
+
+ // test_hmac_sha256.cpp
+ TEST_METHOD(TestHmacSha256) { ::TestHmacSha256(); }
+
+ // test_link_quality.cpp
+ TEST_METHOD(TestRssAveraging) { Thread::TestRssAveraging(); }
+ TEST_METHOD(TestLinkQualityCalculations) { Thread::TestLinkQualityCalculations(); }
+
+ // test_lowpan.cpp
+ TEST_METHOD(TestLowpanIphc) { Thread::TestLowpanIphc(); }
+
+ // test_mac_frame.cpp
+ TEST_METHOD(TestMacHeader) { Thread::TestMacHeader(); }
+
+ // test_message.cpp
+ TEST_METHOD(TestMessage) { ::TestMessage(); }
+
+ // test_message.cpp
+ TEST_METHOD(TestOneTimer) { ::TestOneTimer(); }
+ TEST_METHOD(TestTenTimers) { ::TestTenTimers(); }
+
+ // test_toolchain.cpp
+ TEST_METHOD(test_packed1) { ::test_packed1(); }
+ TEST_METHOD(test_packed2) { ::test_packed2(); }
+ TEST_METHOD(test_packed_union) { ::test_packed_union(); }
+ TEST_METHOD(test_packed_enum) { ::test_packed_enum(); }
+ };
+}
\ No newline at end of file