Added hook to unit test when build: darwin.
authorThuyen Tran <thuyen.c.tran@intel.com>
Tue, 14 Apr 2015 21:57:14 +0000 (14:57 -0700)
committerErich Keane <erich.keane@intel.com>
Wed, 15 Apr 2015 17:41:46 +0000 (17:41 +0000)
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 <thuyen.c.tran@intel.com>
Signed-off-by: Erich Keane <erich.keane@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/707
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
.gitignore
extlibs/gtest/SConscript
resource/SConscript
resource/csdk/connectivity/test/SConscript
resource/csdk/stack/test/SConscript
resource/unit_tests.scons

index 1c4ddab..d242a39 100644 (file)
@@ -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
index e9f1f23..6007302 100644 (file)
@@ -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')
index 58540c9..cacd5d4 100644 (file)
@@ -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')
-
index e6971fc..42ae757 100644 (file)
@@ -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');
index 64d2aac..7cd80fd 100644 (file)
@@ -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');
index bea8c7e..7624233 100644 (file)
@@ -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')