From 93fc9b9080f8a958234ac60a7fc44f8cb53f5601 Mon Sep 17 00:00:00 2001 From: Thuyen Tran Date: Tue, 14 Apr 2015 14:57:14 -0700 Subject: [PATCH] Added hook to unit test when build: darwin. Added and modified scons scripts to download, set up gtest libraries and then added hook to invoke CSDK's unit test when build darwin target. Change-Id: Ie169545fe143fd897fffcc25265c12648902f652 Signed-off-by: Thuyen Tran Signed-off-by: Erich Keane Reviewed-on: https://gerrit.iotivity.org/gerrit/707 Tested-by: jenkins-iotivity --- .gitignore | 22 +++++++++++++- extlibs/gtest/SConscript | 47 ++++++++++++++++++++++++++---- resource/SConscript | 8 +++-- resource/csdk/connectivity/test/SConscript | 5 +++- resource/csdk/stack/test/SConscript | 6 +++- resource/unit_tests.scons | 7 +++++ 6 files changed, 84 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 1c4ddab..d242a39 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,23 @@ +#****************************************************************** +# +# Copyright 2014 Intel Mobile Communications GmbH All Rights Reserved. +# +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= + # Ignore output dirs /release resource/release @@ -58,7 +78,7 @@ out/ platform # Ignore downloaded dependencies -extlibs/gtest* +extlibs/gtest/gtest-* extlibs/hippomocks-master/ extlibs/master.zip extlibs/cereal/cereal diff --git a/extlibs/gtest/SConscript b/extlibs/gtest/SConscript index e9f1f23..6007302 100644 --- a/extlibs/gtest/SConscript +++ b/extlibs/gtest/SConscript @@ -11,13 +11,13 @@ Import('env') target_os = env.get('TARGET_OS') src_dir = env.get('SRC_DIR') +targets_need_gtest = ['darwin','linux'] +gtest_dir = src_dir + '/extlibs/gtest/gtest-1.7.0' +gtest_zip_file = src_dir + '/extlibs/gtest/gtest-1.7.0.zip' +gtest_url = 'https://googletest.googlecode.com/files/gtest-1.7.0.zip' -if target_os == 'linux': - print '*** Checking for installation of google unit test 1.7.0 ***' - - gtest_dir = src_dir + '/extlibs/gtest/gtest-1.7.0' - gtest_zip_file = src_dir + '/extlibs/gtest/gtest-1.7.0.zip' - gtest_url = 'https://googletest.googlecode.com/files/gtest-1.7.0.zip' +if target_os in targets_need_gtest: + print '*** Checking for installation of google unit test 1.7.0 ***' if not os.path.exists(gtest_dir): # If the gtest zip file is not already present, download it @@ -30,6 +30,41 @@ if target_os == 'linux': print 'Unzipping google unit test' env.UnpackAll(gtest_dir, gtest_zip) + +if target_os == 'darwin': + if os.path.exists(gtest_dir): + # Build gtest and store it at a temporary directory + gtest_lib_dir = gtest_dir + '/lib' + gtest_dotlib_dir = gtest_lib_dir + '/.libs' + + if not os.path.exists(gtest_lib_dir): + print 'Create a directory' + os.mkdir(gtest_lib_dir) + + print 'Change to a directory' + os.chdir(gtest_lib_dir) + + print 'Invoke cmake command to generate appropriate make files' + env.Configure(gtest_lib_dir, 'cmake -G"Unix Makefiles" ..') + + # Run make on gtest + print 'Making google unit test' + env.Configure(gtest_lib_dir, 'make') + + print 'Create a directory' + os.mkdir(gtest_dotlib_dir) + + print 'Change to a directory' + os.chdir(gtest_dotlib_dir) + + print 'Create hard links pointing to gtest libraries' + os.link('../' + 'libgtest.a', 'libgtest.a') + os.link('../' + 'libgtest_main.a', 'libgtest_main.a') + print 'Create hard links pointing to gtest libraries - DONE' + + +elif target_os == 'linux': + if not os.path.exists(gtest_dir): # Run configure on gtest print 'Configuring google unit test' env.Configure(gtest_dir, './configure') diff --git a/resource/SConscript b/resource/SConscript index 58540c9..cacd5d4 100644 --- a/resource/SConscript +++ b/resource/SConscript @@ -59,9 +59,13 @@ if target_os == 'linux': # Build C/C++ unit tests SConscript('unit_tests.scons') + elif target_os == 'darwin': - # Build linux samples for now + # Build linux samples for now. SConscript('csdk/stack/samples/linux/SimpleClientServer/SConscript') + + # Build C stack's unit tests. + SConscript('unit_tests.scons') + elif target_os == 'arduino': SConscript('csdk/stack/samples/arduino/SimpleClientServer/ocserver/SConscript') - diff --git a/resource/csdk/connectivity/test/SConscript b/resource/csdk/connectivity/test/SConscript index e6971fc..42ae757 100644 --- a/resource/csdk/connectivity/test/SConscript +++ b/resource/csdk/connectivity/test/SConscript @@ -49,12 +49,15 @@ catest_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')]) catest_env.AppendUnique(LIBPATH = [src_dir + '/extlibs/gtest/gtest-1.7.0/lib/.libs']) catest_env.PrependUnique(LIBS = ['m', 'octbstack', - 'oc_logger', 'connectivity_abstraction', 'coap', 'gtest', 'gtest_main']) +target_os = env.get('TARGET_OS') +if target_os != 'darwin': + catest_env.PrependUnique(LIBS = ['oc_logger']) + if env.get('SECURED') == '1': catest_env.AppendUnique(LIBS = ['tinydtls']) catest_env.ParseConfig('pkg-config --libs glib-2.0'); diff --git a/resource/csdk/stack/test/SConscript b/resource/csdk/stack/test/SConscript index 64d2aac..7cd80fd 100644 --- a/resource/csdk/stack/test/SConscript +++ b/resource/csdk/stack/test/SConscript @@ -44,12 +44,16 @@ stacktest_env.AppendUnique(LIBPATH = [env.get('BUILD_DIR')]) stacktest_env.AppendUnique(LIBPATH = [src_dir + '/extlibs/gtest/gtest-1.7.0/lib/.libs']) stacktest_env.PrependUnique(LIBS = ['m', 'octbstack', - 'oc_logger', 'connectivity_abstraction', 'coap', 'gtest', 'gtest_main']) +target_os = env.get('TARGET_OS') +if target_os != 'darwin': + stacktest_env.PrependUnique(LIBS = ['oc_logger']) + + if env.get('SECURED') == '1': stacktest_env.AppendUnique(LIBS = ['tinydtls']) stacktest_env.ParseConfig('pkg-config --libs glib-2.0'); diff --git a/resource/unit_tests.scons b/resource/unit_tests.scons index bea8c7e..7624233 100644 --- a/resource/unit_tests.scons +++ b/resource/unit_tests.scons @@ -47,5 +47,12 @@ if target_os == 'linux': # Build C++ unit tests SConscript('unittests/SConscript') +elif target_os == 'darwin': + # Verify that 'google unit test' library is installed. If not, + # get it and install it + SConscript(src_dir + '/extlibs/gtest/SConscript') + # Build C stack's unit tests. + SConscript('csdk/stack/test/SConscript') + SConscript('csdk/connectivity/test/SConscript') -- 2.7.4