From: David Antler Date: Fri, 26 Aug 2016 17:31:47 +0000 (-0700) Subject: Enable more unit tests on Windows X-Git-Tag: 1.3.0~1057^2~138 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=effc296adcc2632850ef26f99982a619460576f0;p=platform%2Fupstream%2Fiotivity.git Enable more unit tests on Windows * 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 Reviewed-on: https://gerrit.iotivity.org/gerrit/11609 Tested-by: jenkins-iotivity Reviewed-by: Soemin Tjong Reviewed-by: Phil Coval Reviewed-by: Dave Thaler --- diff --git a/extlibs/gtest/SConscript b/extlibs/gtest/SConscript index ecb392a..d127ccf 100644 --- a/extlibs/gtest/SConscript +++ b/extlibs/gtest/SConscript @@ -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') diff --git a/extlibs/hippomocks.scons b/extlibs/hippomocks.scons index 5832177..0826f97 100644 --- a/extlibs/hippomocks.scons +++ b/extlibs/hippomocks.scons @@ -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' diff --git a/resource/c_common/ocrandom/test/SConscript b/resource/c_common/ocrandom/test/SConscript index 2f80752..632f22c 100644 --- a/resource/c_common/ocrandom/test/SConscript +++ b/resource/c_common/ocrandom/test/SConscript @@ -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', diff --git a/resource/c_common/oic_malloc/test/SConscript b/resource/c_common/oic_malloc/test/SConscript index b1d9e2a..589be23 100644 --- a/resource/c_common/oic_malloc/test/SConscript +++ b/resource/c_common/oic_malloc/test/SConscript @@ -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', diff --git a/resource/c_common/oic_malloc/test/linux/oic_malloc_tests.cpp b/resource/c_common/oic_malloc/test/linux/oic_malloc_tests.cpp index dd94aad..5a9222d 100644 --- a/resource/c_common/oic_malloc/test/linux/oic_malloc_tests.cpp +++ b/resource/c_common/oic_malloc/test/linux/oic_malloc_tests.cpp @@ -18,6 +18,7 @@ // //-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +#include "iotivity_config.h" extern "C" { #include "oic_malloc.h" @@ -28,7 +29,9 @@ extern "C" { #include #include #include +#ifdef HAVE_UNISTD_H #include +#endif #include #include diff --git a/resource/c_common/oic_string/test/SConscript b/resource/c_common/oic_string/test/SConscript index 94bbd2b..29fbcda 100644 --- a/resource/c_common/oic_string/test/SConscript +++ b/resource/c_common/oic_string/test/SConscript @@ -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', diff --git a/resource/c_common/oic_string/test/linux/oic_string_tests.cpp b/resource/c_common/oic_string/test/linux/oic_string_tests.cpp index 320d30f..9b023e7 100644 --- a/resource/c_common/oic_string/test/linux/oic_string_tests.cpp +++ b/resource/c_common/oic_string/test/linux/oic_string_tests.cpp @@ -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 diff --git a/resource/c_common/oic_time/test/SConscript b/resource/c_common/oic_time/test/SConscript index c4cb46b..2cca0e5 100644 --- a/resource/c_common/oic_time/test/SConscript +++ b/resource/c_common/oic_time/test/SConscript @@ -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', diff --git a/resource/csdk/connectivity/test/SConscript b/resource/csdk/connectivity/test/SConscript index 58cb1e3..62dfaf4 100644 --- a/resource/csdk/connectivity/test/SConscript +++ b/resource/csdk/connectivity/test/SConscript @@ -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']) diff --git a/resource/csdk/octbstack_product.def b/resource/csdk/octbstack_product.def index 84e47c7..1c81e28 100644 --- a/resource/csdk/octbstack_product.def +++ b/resource/csdk/octbstack_product.def @@ -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 diff --git a/resource/csdk/security/provisioning/unittest/SConscript b/resource/csdk/security/provisioning/unittest/SConscript index 7818df5..653df64 100644 --- a/resource/csdk/security/provisioning/unittest/SConscript +++ b/resource/csdk/security/provisioning/unittest/SConscript @@ -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']) diff --git a/resource/csdk/security/unittest/SConscript b/resource/csdk/security/unittest/SConscript index a2399b0..b67de92 100644 --- a/resource/csdk/security/unittest/SConscript +++ b/resource/csdk/security/unittest/SConscript @@ -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. diff --git a/resource/csdk/stack/test/SConscript b/resource/csdk/stack/test/SConscript index 82e6ab3..46cc864 100644 --- a/resource/csdk/stack/test/SConscript +++ b/resource/csdk/stack/test/SConscript @@ -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']) diff --git a/resource/src/OCApi.cpp b/resource/src/OCApi.cpp index 7fdc9f5..529573f 100644 --- a/resource/src/OCApi.cpp +++ b/resource/src/OCApi.cpp @@ -21,6 +21,9 @@ #include "OCApi.h" #if defined(_MSC_VER) + +#include + namespace OC { std::ostream& oclog() diff --git a/resource/unit_tests.scons b/resource/unit_tests.scons index 40b1e79..c018e28 100644 --- a/resource/unit_tests.scons +++ b/resource/unit_tests.scons @@ -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, diff --git a/resource/unittests/OCRepresentationTest.cpp b/resource/unittests/OCRepresentationTest.cpp index eb4ac87..471c302 100644 --- a/resource/unittests/OCRepresentationTest.cpp +++ b/resource/unittests/OCRepresentationTest.cpp @@ -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(AttrName, badout)); diff --git a/resource/unittests/OCResourceResponseTest.cpp b/resource/unittests/OCResourceResponseTest.cpp index c53c83c..3968948 100644 --- a/resource/unittests/OCResourceResponseTest.cpp +++ b/resource/unittests/OCResourceResponseTest.cpp @@ -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; diff --git a/resource/unittests/SConscript b/resource/unittests/SConscript index dc9907f..9d2684f 100644 --- a/resource/unittests/SConscript +++ b/resource/unittests/SConscript @@ -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 --- 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%