Enable more unit tests on Windows
authorDavid Antler <david.a.antler@intel.com>
Fri, 26 Aug 2016 17:31:47 +0000 (10:31 -0700)
committerDave Thaler <dthaler@microsoft.com>
Sat, 17 Sep 2016 18:25:56 +0000 (18:25 +0000)
* Enable resource/c_common unit tests
* Enable resource/unittests binary (partially)
* Fix small unit test bugs related to MSVC
* Consolidate flags for gtest binaries on Windows

Change-Id: Iead5e4494f3cc0e597ccee4bd83e6d9978141972
Signed-off-by: David Antler <david.a.antler@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/11609
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Soemin Tjong <stjong@microsoft.com>
Reviewed-by: Phil Coval <philippe.coval@osg.samsung.com>
Reviewed-by: Dave Thaler <dthaler@microsoft.com>
19 files changed:
extlibs/gtest/SConscript
extlibs/hippomocks.scons
resource/c_common/ocrandom/test/SConscript
resource/c_common/oic_malloc/test/SConscript
resource/c_common/oic_malloc/test/linux/oic_malloc_tests.cpp
resource/c_common/oic_string/test/SConscript
resource/c_common/oic_string/test/linux/oic_string_tests.cpp
resource/c_common/oic_time/test/SConscript
resource/csdk/connectivity/test/SConscript
resource/csdk/octbstack_product.def
resource/csdk/security/provisioning/unittest/SConscript
resource/csdk/security/unittest/SConscript
resource/csdk/stack/test/SConscript
resource/src/OCApi.cpp
resource/unit_tests.scons
resource/unittests/OCRepresentationTest.cpp
resource/unittests/OCResourceResponseTest.cpp
resource/unittests/SConscript
run.bat

index ecb392a..d127ccf 100644 (file)
@@ -124,5 +124,7 @@ if target_os in targets_need_gtest:
                        gtest_env.AppendUnique(CXXFLAGS = ['-pthread'])
                        gtest_env.PrependUnique(LIBS = ['pthread'])
        gtest_env.PrependUnique(LIBS = ['gtest', 'gtest_main'])
+       if target_os in ['windows']:
+               gtest_env.AppendUnique(LINKFLAGS = ['/subsystem:CONSOLE'])
 
 Return('gtest_env')
index 5832177..0826f97 100644 (file)
@@ -31,8 +31,7 @@ Import('env')
 target_os = env.get('TARGET_OS')
 src_dir = env.get('SRC_DIR')
 
-# Only verify/install on linux
-if target_os in ['linux']:
+if target_os in ['linux', 'windows']:
        print '*** Checking for installation of hippomocks ***'
 
        hippomocks_sha      = '8e210c5808d490b26fff69151c801fa28d291fcb'
index 2f80752..632f22c 100644 (file)
@@ -59,7 +59,7 @@ Alias("test", [randomtests])
 
 randomtest_env.AppendTarget('test')
 if randomtest_env.get('TEST') == '1':
-       if target_os in ['linux']:
+       if target_os in ['linux', 'windows']:
                 from tools.scons.RunTest import *
                 run_test(randomtest_env,
                          'resource_csdk_random_test.memcheck',
index b1d9e2a..589be23 100644 (file)
@@ -47,7 +47,7 @@ Alias("test", [malloctests])
 
 malloctest_env.AppendTarget('test')
 if malloctest_env.get('TEST') == '1':
-       if target_os in ['linux']:
+       if target_os in ['linux', 'windows']:
                 from tools.scons.RunTest import *
                 run_test(malloctest_env,
                          'resource_ccommon_malloc_test.memcheck',
index dd94aad..5a9222d 100644 (file)
@@ -18,6 +18,7 @@
 //
 //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
 
+#include "iotivity_config.h"
 
 extern "C" {
     #include "oic_malloc.h"
@@ -28,7 +29,9 @@ extern "C" {
 #include <sys/stat.h>
 #include <errno.h>
 #include <fcntl.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
+#endif
 #include <stdlib.h>
 #include <stdint.h>
 
index 94bbd2b..29fbcda 100644 (file)
@@ -46,7 +46,7 @@ Alias("test", [stringtests])
 
 stringtest_env.AppendTarget('test')
 if stringtest_env.get('TEST') == '1':
-    if target_os in ['linux']:
+    if target_os in ['linux', 'windows']:
                 from tools.scons.RunTest import *
                 run_test(stringtest_env,
                          'resource_ccommon_string_test.memcheck',
index 320d30f..9b023e7 100644 (file)
@@ -191,12 +191,15 @@ TEST(StringTests, StrcpyZeroSource)
 // tests a copy where the destination is of length 0
 TEST(StringTests, StrcpyZeroDestination)
 {
-    char target[0];
+    char target[1] = { (char)0xde };
     char source[] = "123456789";
+    char beforeValue = target[0];
 
-    char *result = OICStrcpy(target, sizeof(target), source);
+    char *result = OICStrcpy(target, 0, source);
 
+    char afterValue = target[0];
     EXPECT_EQ(target, result);
+    EXPECT_EQ(beforeValue, afterValue);
 }
 
 // tests a copy where the destination is of length 0
@@ -398,11 +401,15 @@ TEST(StringTests, StrcatZeroSource)
 // Tests a cat where the Destination is zero length
 TEST(StringTests, StrcatZeroDestination)
 {
-    char target[0];
+    char target[1] = { (char)0xde };
     char source[] = "12345";
+    char beforeValue = target[0];
 
-    char *result = OICStrcat(target, sizeof(target), source);
+    char *result = OICStrcat(target, 0, source);
+
+    char afterValue = target[0];
     EXPECT_EQ(target, result);
+    EXPECT_EQ(beforeValue, afterValue);
 }
 
 // Tests a cat where the Destination is zero length
index c4cb46b..2cca0e5 100644 (file)
@@ -34,7 +34,6 @@ timetest_env.PrependUnique(CPPPATH = [
 
 timetest_env.AppendUnique(LIBPATH = [os.path.join(timetest_env.get('BUILD_DIR'), 'resource', 'c_common')])
 timetest_env.PrependUnique(LIBS = ['c_common'])
-timetest_env.Append(LIBS = ['rt']);
 
 if timetest_env.get('LOGGING'):
     timetest_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
@@ -48,7 +47,7 @@ Alias("test", [timetests])
 
 timetest_env.AppendTarget('test')
 if timetest_env.get('TEST') == '1':
-    if target_os in ['linux']:
+    if target_os in ['linux', 'windows']:
                 from tools.scons.RunTest import *
                 run_test(timetest_env,
                          'resource_ccommon_time_test.memcheck',
index 58cb1e3..62dfaf4 100644 (file)
@@ -59,7 +59,6 @@ if catest_env.get('LOGGING'):
        catest_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
 
 if target_os in ['msys_nt', 'windows']:
-       catest_env.AppendUnique(LINKFLAGS = ['/subsystem:CONSOLE'])
        catest_env.AppendUnique(LIBS = ['ws2_32',
                                         'advapi32',
                                         'iphlpapi'])
index 84e47c7..1c81e28 100644 (file)
@@ -39,6 +39,9 @@ OCCreateOCStringLL
 OCCreateResource
 OCDeleteResource
 OCDiscoverDirectPairingDevices
+OCDiscoveryPayloadCreate
+OCDiscoveryPayloadDestroy
+OCDiscoveryPayloadGetResourceCount
 OCDoDirectPairing
 OCDoResource
 OCDoResponse
@@ -61,6 +64,8 @@ OCInit1
 OCNotifyAllObservers
 OCNotifyListOfObservers
 OCPayloadDestroy
+OCPlatformPayloadCreate
+OCPresencePayloadCreate
 OCProcess
 OCRDDelete
 OCRDDeleteWithDeviceId
index 7818df5..653df64 100644 (file)
@@ -84,7 +84,6 @@ if not sptest_env.get('RELEASE'):
        sptest_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
 
 if target_os in ['msys_nt', 'windows']:
-    sptest_env.AppendUnique(LINKFLAGS = ['/subsystem:CONSOLE'])
     sptest_env.AppendUnique(LIBS = ['ws2_32',
                                     'advapi32',
                                     'iphlpapi'])
index a2399b0..b67de92 100644 (file)
@@ -71,7 +71,6 @@ if srmtest_env.get('LOGGING') == '1':
        srmtest_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
 
 if target_os == 'windows':
-       srmtest_env.AppendUnique(LINKFLAGS = ['/subsystem:CONSOLE'])
        srmtest_env.AppendUnique(LIBS = ['advapi32', 'kernel32', 'ws2_32', 'iphlpapi'])
 else:
        # TODO: Implement feature check.
index 82e6ab3..46cc864 100644 (file)
@@ -60,7 +60,6 @@ if stacktest_env.get('LOGGING'):
        stacktest_env.AppendUnique(CPPDEFINES = ['TB_LOG'])
 
 if target_os in ['msys_nt', 'windows']:
-       stacktest_env.AppendUnique(LINKFLAGS = ['/subsystem:CONSOLE'])
        stacktest_env.AppendUnique(LIBS = ['ws2_32', 'iphlpapi', 'kernel32'])
 else:
        stacktest_env.PrependUnique(LIBS = ['m'])
index 7fdc9f5..529573f 100644 (file)
@@ -21,6 +21,9 @@
 #include "OCApi.h"
 
 #if defined(_MSC_VER)
+
+#include <iostream>
+
 namespace OC
 {
     std::ostream& oclog()
index 40b1e79..c018e28 100644 (file)
@@ -29,7 +29,7 @@ target_os = env.get('TARGET_OS')
 src_dir = env.get('SRC_DIR')
 build_dir = env.get('BUILD_DIR')
 
-if target_os in ['linux']:
+if target_os in ['linux', 'windows']:
        # Verify that 'google unit test' library is installed.  If not,
        # get it and install it
        SConscript('#extlibs/gtest/SConscript')
@@ -59,24 +59,9 @@ if target_os in ['linux']:
        # Build Provisioning API unit test
        if env.get('SECURED') == '1':
                SConscript('csdk/security/provisioning/unittest/SConscript')
-               SConscript('provisioning/unittests/SConscript')
-
-elif target_os == 'windows' and env.get('TEST') == '1':
-       # Verify that 'google unit test' library is installed.  If not,
-       # get it and install it
-       SConscript('#extlibs/gtest/SConscript')
-
-       # Build C stack's unit tests.
-       SConscript('csdk/stack/test/SConscript')
-       SConscript('csdk/connectivity/test/SConscript')
-
-       # Build Security Resource Manager unit tests
-       if env.get('SECURED') == '1':
-               SConscript('csdk/security/unittest/SConscript')
-
-       # Build Provisioning API unit test
-       if env.get('SECURED') == '1':
-               SConscript('csdk/security/provisioning/unittest/SConscript')
+               # TODO: Enable provisioning and associated unit tests for Windows
+               if target_os != 'windows':
+                       SConscript('provisioning/unittests/SConscript')
 
 elif target_os in ['darwin', 'msys_nt']:
        # Verify that 'google unit test' library is installed.  If not,
index eb4ac87..471c302 100644 (file)
@@ -547,12 +547,15 @@ namespace OCRepresentationTest
         rep[AttrName] = nullptr;
         EXPECT_TRUE(rep.isNULL(AttrName));
 
+// @todo: Re-enable this part of the unit test. MSVC can't assign to nullptr_t.
+#ifndef _MSC_VER
         std::nullptr_t repout = rep[AttrName];
         std::nullptr_t repout2;
         repout2 = rep[AttrName];
 
         EXPECT_EQ(nullptr, repout);
         EXPECT_EQ(nullptr, repout2);
+#endif
 
         double badout;
         EXPECT_FALSE(rep.getValue<double>(AttrName, badout));
index c53c83c..3968948 100644 (file)
@@ -119,7 +119,11 @@ namespace OCResourceResponseTest
         EXPECT_EQ(NULL, response.getRequestHandle());
     }
 
+#ifdef _MSC_VER
+    TEST(ResourceHandleTest, DISABLED_SetGetResourceHandleValidHandle)
+#else
     TEST(ResourceHandleTest, SetGetResourceHandleValidHandle)
+#endif
     {
         OCResourceResponse response;
         OCResourceHandle resHandle;
index dc9907f..9d2684f 100644 (file)
@@ -46,6 +46,10 @@ unittests_env.PrependUnique(CPPPATH = [
                '#extlibs/hippomocks-master/HippoMocksTest'
                ])
 
+if target_os in ['windows']:
+       unittests_env.AppendUnique(LIBS = ['ws2_32'])
+       unittests_env.AppendUnique(CPPPATH = ['#extlibs/boost/boost'])
+
 unittests_env.AppendUnique(LIBPATH = [unittests_env.get('BUILD_DIR')])
 unittests_env.PrependUnique(LIBS = [
                'oc',
@@ -81,6 +85,14 @@ unittests_src = [
                'OCHeaderOptionTest.cpp'
        ]
 
+# TODO: Fix errors in the following Windows tests.
+if target_os in ['windows']:
+       unittests_src.remove('OCPlatformTest.cpp')
+       unittests_src.remove('OCRepresentationEncodingTest.cpp')
+       if '12.0' == unittests_env['MSVC_VERSION']:
+               unittests_src.remove('OCRepresentationTest.cpp')
+               unittests_src.remove('OCResourceTest.cpp')
+
 if (('SUB' in with_mq) or ('PUB' in with_mq) or ('BROKER' in with_mq)):
        unittests_src = unittests_src + ['OCMQResourceTest.cpp']
 
@@ -93,7 +105,9 @@ Alias("unittests", [unittests])
 
 unittests_env.AppendTarget('unittests')
 if unittests_env.get('TEST') == '1':
-       if target_os in ['linux']:
+       if target_os in ['windows']:
+               unittests_env.AppendENVPath('PATH', unittests_env.get('BUILD_DIR'))
+       if target_os in ['linux', 'windows']:
                 from tools.scons.RunTest import *
                 run_test(unittests_env,
                          'resource_unittests_unittests.memcheck',
diff --git a/run.bat b/run.bat
index 1856907..a81745e 100644 (file)
--- a/run.bat
+++ b/run.bat
@@ -90,6 +90,11 @@ if "!CURRENT_ARG!"=="server" (
   %DEBUG% %BUILD_DIR%\resource\csdk\stack\test\cbortests.exe
   %DEBUG% %BUILD_DIR%\resource\csdk\security\unittest\unittest.exe
   %DEBUG% %BUILD_DIR%\resource\csdk\security\provisioning\unittest\unittest.exe
+  %DEBUG% %BUILD_DIR%\resource\c_common\ocrandom\test\randomtests.exe
+  %DEBUG% %BUILD_DIR%\resource\c_common\oic_malloc\test\malloctests.exe
+  %DEBUG% %BUILD_DIR%\resource\c_common\oic_string\test\stringtests.exe
+  %DEBUG% %BUILD_DIR%\resource\c_common\oic_time\test\timetests.exe
+  %DEBUG% %BUILD_DIR%\resource\unittests\unittests.exe
 ) else if "!CURRENT_ARG!"=="build" (
   echo Starting IoTivity build with these options:
   echo   TARGET_OS=%TARGET_OS%