Refactor duplicated SCons/Python test run code.
authorOssama Othman <ossama.othman@intel.com>
Wed, 15 Jul 2015 21:23:41 +0000 (14:23 -0700)
committerErich Keane <erich.keane@intel.com>
Fri, 17 Jul 2015 01:46:30 +0000 (01:46 +0000)
Moved duplicated code test run code to a Python module under
tools/scons.  Support for Valgrind suppressions was also added.

Change-Id: I31d0bf7879116a358439e387dcd5fd87bbbecc9d
Signed-off-by: Ossama Othman <ossama.othman@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/1678
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: Jon A. Cruz <jonc@osg.samsung.com>
Reviewed-by: Caiwen Zhang <caiwen.zhang@intel.com>
Reviewed-by: Erich Keane <erich.keane@intel.com>
resource/c_common/oic_malloc/test/SConscript
resource/c_common/oic_string/test/SConscript
resource/csdk/connectivity/test/SConscript
resource/csdk/ocrandom/test/SConscript
resource/csdk/stack/test/SConscript
resource/unittests/SConscript
tools/__init__.py [new file with mode: 0644]
tools/scons/RunTest.py [new file with mode: 0644]
tools/scons/__init__.py [new file with mode: 0644]
tools/valgrind/iotivity.supp [new file with mode: 0644]

index 0443928..0b702ec 100644 (file)
@@ -29,8 +29,7 @@ src_dir = malloctest_env.get('SRC_DIR')
 ######################################################################
 malloctest_env.PrependUnique(CPPPATH = [
         '../include',
-               '../../../../extlibs/gtest/gtest-1.7.0/include'
-        ])
+        '#extlibs/gtest/gtest-1.7.0/include' ])
 
 malloctest_env.AppendUnique(LIBPATH = [os.path.join(env.get('BUILD_DIR'), 'resource/c_common')])
 malloctest_env.AppendUnique(LIBPATH = [src_dir + '/extlibs/gtest/gtest-1.7.0/lib/.libs'])
@@ -50,12 +49,7 @@ env.AppendTarget('test')
 if env.get('TEST') == '1':
        target_os = env.get('TARGET_OS')
        if target_os == 'linux':
-               out_dir = env.get('BUILD_DIR')
-               result_dir = env.get('BUILD_DIR') + '/test_out/'
-               if not os.path.isdir(result_dir):
-                       os.makedirs(result_dir)
-               malloctest_env.AppendENVPath('GTEST_OUTPUT', ['xml:'+ result_dir])
-               malloctest_env.AppendENVPath('LD_LIBRARY_PATH', [out_dir])
-               malloctest_env.AppendENVPath('LD_LIBRARY_PATH', ['./extlibs/gtest/gtest-1.7.0/lib/.libs'])
-               ut = malloctest_env.Command ('ut', None, 'valgrind -q --leak-check=full --xml=yes --xml-file=resource_ccommon_malloc_test.memcheck ' + out_dir + 'resource/c_common/oic_malloc/test/malloctests')
-               AlwaysBuild ('ut')
+                from tools.scons.RunTest import *
+                run_test(malloctest_env,
+                         'resource_ccommon_malloc_test.memcheck',
+                         'resource/c_common/oic_malloc/test/malloctests')
index 9aacebc..9d30251 100644 (file)
@@ -29,8 +29,7 @@ src_dir = stringtest_env.get('SRC_DIR')
 ######################################################################
 stringtest_env.PrependUnique(CPPPATH = [
         '../include',
-               '../../../../extlibs/gtest/gtest-1.7.0/include'
-        ])
+        '#extlibs/gtest/gtest-1.7.0/include' ])
 
 stringtest_env.AppendUnique(LIBPATH = [os.path.join(env.get('BUILD_DIR'), 'resource/c_common')])
 stringtest_env.AppendUnique(LIBPATH = [src_dir + '/extlibs/gtest/gtest-1.7.0/lib/.libs'])
@@ -50,12 +49,7 @@ env.AppendTarget('test')
 if env.get('TEST') == '1':
        target_os = env.get('TARGET_OS')
        if target_os == 'linux':
-               out_dir = env.get('BUILD_DIR')
-               result_dir = env.get('BUILD_DIR') + '/test_out/'
-               if not os.path.isdir(result_dir):
-                       os.makedirs(result_dir)
-               stringtest_env.AppendENVPath('GTEST_OUTPUT', ['xml:'+ result_dir])
-               stringtest_env.AppendENVPath('LD_LIBRARY_PATH', [out_dir])
-               stringtest_env.AppendENVPath('LD_LIBRARY_PATH', ['./extlibs/gtest/gtest-1.7.0/lib/.libs'])
-               ut = stringtest_env.Command ('ut', None, 'valgrind -q --leak-check=full --xml=yes --xml-file=resource_ccommon_string_test.memcheck ' + out_dir + 'resource/c_common/oic_string/test/stringtests')
-               AlwaysBuild ('ut')
+                from tools.scons.RunTest import *
+                run_test(stringtest_env,
+                         'resource_ccommon_string_test.memcheck',
+                         'resource/c_common/oic_string/test/stringtests')
index 24f2bdc..b66a223 100644 (file)
@@ -82,12 +82,7 @@ env.AppendTarget('test')
 if env.get('TEST') == '1':
         target_os = env.get('TARGET_OS')
         if target_os == 'linux':
-                out_dir = env.get('BUILD_DIR')
-                result_dir = env.get('BUILD_DIR') + '/test_out/'
-                if not os.path.isdir(result_dir):
-                        os.makedirs(result_dir)
-                catest_env.AppendENVPath('GTEST_OUTPUT', ['xml:'+ result_dir])
-                catest_env.AppendENVPath('LD_LIBRARY_PATH', [out_dir])
-                catest_env.AppendENVPath('LD_LIBRARY_PATH', ['./extlibs/gtest/gtest-1.7.0/lib/.libs'])
-                ut = catest_env.Command ('ut', None, 'valgrind -q --leak-check=full --xml=yes --xml-file=resource_csdk_connectivity_test.memcheck ' + out_dir + 'resource/csdk/connectivity/test/catests')
-                AlwaysBuild ('ut')
+                from tools.scons.RunTest import *
+                run_test(catest_env,
+                         'resource_csdk_connectivity_test.memcheck',
+                         'resource/csdk/connectivity/test/catests')
index eeb858a..2e7bc52 100644 (file)
@@ -60,12 +60,7 @@ env.AppendTarget('test')
 if env.get('TEST') == '1':
        target_os = env.get('TARGET_OS')
        if target_os == 'linux':
-               out_dir = env.get('BUILD_DIR')
-               result_dir = env.get('BUILD_DIR') + '/test_out/'
-               if not os.path.isdir(result_dir):
-                       os.makedirs(result_dir)
-               randomtest_env.AppendENVPath('GTEST_OUTPUT', ['xml:'+ result_dir])
-               randomtest_env.AppendENVPath('LD_LIBRARY_PATH', [out_dir])
-               randomtest_env.AppendENVPath('LD_LIBRARY_PATH', ['./extlibs/gtest/gtest-1.7.0/lib/.libs'])
-               ut = randomtest_env.Command ('ut', None, 'valgrind -q --leak-check=full --xml=yes --xml-file=resource_csdk_random_test.memcheck ' + out_dir + 'resource/csdk/ocrandom/test/randomtests')
-               AlwaysBuild ('ut')
+                from tools.scons.RunTest import *
+                run_test(randomtest_env,
+                         'resource_csdk_random_test.memcheck',
+                         'resource/csdk/ocrandom/test/randomtests')
index 27f9905..ade8f3f 100644 (file)
@@ -39,7 +39,7 @@ stacktest_env.PrependUnique(CPPPATH = [
                '../../connectivity/external/inc',
                '../../extlibs/cjson',
                '../../../oc_logger/include',
-               '../../../../extlibs/gtest/gtest-1.7.0/include'
+               '#extlibs/gtest/gtest-1.7.0/include'
                ])
 
 stacktest_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
@@ -76,12 +76,7 @@ env.AppendTarget('test')
 if env.get('TEST') == '1':
        target_os = env.get('TARGET_OS')
        if target_os == 'linux':
-               out_dir = env.get('BUILD_DIR')
-               result_dir = env.get('BUILD_DIR') + '/test_out/'
-               if not os.path.isdir(result_dir):
-                       os.makedirs(result_dir)
-               stacktest_env.AppendENVPath('GTEST_OUTPUT', ['xml:'+ result_dir])
-               stacktest_env.AppendENVPath('LD_LIBRARY_PATH', [out_dir])
-               stacktest_env.AppendENVPath('LD_LIBRARY_PATH', ['./extlibs/gtest/gtest-1.7.0/lib/.libs'])
-               ut = stacktest_env.Command ('ut', None, 'valgrind -q --leak-check=full --xml=yes --xml-file=resource_csdk_stack_test.memcheck ' + out_dir + 'resource/csdk/stack/test/stacktests')
-               AlwaysBuild ('ut')
+                from tools.scons.RunTest import *
+                run_test(stacktest_env,
+                         'resource_csdk_stack_test.memcheck',
+                         'resource/csdk/stack/test/stacktests')
index 45c152d..4264736 100644 (file)
@@ -38,9 +38,9 @@ unittests_env.PrependUnique(CPPPATH = [
                '../csdk/ocsocket/include',
                '../csdk/ocrandom/include',
                '../csdk/logger/include',
-               '../../extlibs/gtest/gtest-1.7.0/include',
-               '../../extlibs/hippomocks-master/HippoMocks',
-               '../../extlibs/hippomocks-master/HippoMocksTest'
+               '#extlibs/gtest/gtest-1.7.0/include',
+               '#extlibs/hippomocks-master/HippoMocks',
+               '#extlibs/hippomocks-master/HippoMocksTest'
                ])
 
 unittests_env.AppendUnique(CXXFLAGS = ['-std=c++0x', '-Wall', '-pthread'])
@@ -80,19 +80,15 @@ env.AppendTarget('unittests')
 if env.get('TEST') == '1':
        target_os = env.get('TARGET_OS')
        if target_os == 'linux':
-               out_dir = env.get('BUILD_DIR')
-               result_dir = env.get('BUILD_DIR') + '/test_out/'
-               if not os.path.isdir(result_dir):
-                       os.makedirs(result_dir)
-               unittests_env.AppendENVPath('GTEST_OUTPUT', ['xml:'+ result_dir])
-               unittests_env.AppendENVPath('LD_LIBRARY_PATH', [out_dir])
-               unittests_env.AppendENVPath('LD_LIBRARY_PATH', ['./extlibs/gtest/gtest-1.7.0/lib/.libs'])
-               ut = unittests_env.Command ('ut', None,
-                [ 'valgrind --leak-check=full --xml=yes --xml-file=resource_unittests_unittests.memcheck ' + out_dir + 'resource/unittests/unittests'])
-               AlwaysBuild ('ut')
+                from tools.scons.RunTest import *
+                run_test(unittests_env,
+                         'resource_unittests_unittests.memcheck',
+                         'resource/unittests/unittests')
 
 src_dir = unittests_env.get('SRC_DIR')
-svr_db_src_dir = src_dir + '/resource/examples/'
-svr_db_build_dir = env.get('BUILD_DIR') +'/resource/unittests/'
-unittests_env.Alias("install", unittests_env.Install( svr_db_build_dir,
-                                svr_db_src_dir + 'oic_svr_db_client.json'))
+svr_db_src_dir = os.path.join(src_dir, 'resource/examples/')
+svr_db_build_dir = os.path.join(env.get('BUILD_DIR'), 'resource/unittests/')
+unittests_env.Alias("install",
+                    unittests_env.Install(svr_db_build_dir,
+                                          os.path.join(svr_db_src_dir,
+                                                       'oic_svr_db_client.json')))
diff --git a/tools/__init__.py b/tools/__init__.py
new file mode 100644 (file)
index 0000000..05bfb69
--- /dev/null
@@ -0,0 +1,17 @@
+# ------------------------------------------------------------------------
+# Copyright 2015 Intel Corporation
+#
+# 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.
+# ------------------------------------------------------------------------
+
+__all__ = [ "scons" ]
diff --git a/tools/scons/RunTest.py b/tools/scons/RunTest.py
new file mode 100644 (file)
index 0000000..0d9f023
--- /dev/null
@@ -0,0 +1,58 @@
+# ------------------------------------------------------------------------
+# Copyright 2015 Intel Corporation
+#
+# 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.
+# ------------------------------------------------------------------------
+
+import os
+
+def run_test(env, xml_file, test):
+    """
+    Run test with the given SCons Environment, dumping Valgrind
+    results to the given XML file.  If no Valgrind run is desired
+    simply pass in an empty string or None for the xml_file
+    parameter.
+
+    Note that the test path should not include the build directory
+    where binaries are placed.  The build directory will be prepended
+    to the test path automatically.
+    """
+
+    build_dir = env.get('BUILD_DIR')
+    result_dir = os.path.join(build_dir, 'test_out/')
+    if not os.path.isdir(result_dir):
+        os.makedirs(result_dir)
+
+    # Dump test report in XML format to the results directory.
+    env.AppendENVPath('GTEST_OUTPUT', ['xml:' + result_dir])
+
+    # Make sure the Google Test libraries are in the dynamic
+    # linker/loader path.
+    env.AppendENVPath('LD_LIBRARY_PATH', [build_dir])
+    env.AppendENVPath('LD_LIBRARY_PATH', ['./extlibs/gtest/gtest-1.7.0/lib/.libs'])
+
+    test_cmd = os.path.join(build_dir, test)
+
+    if xml_file:
+        # Environment variables to be made available during the
+        # Valgrind run.
+        valgrind_environment = ''
+
+        # Valgrind suppressions file.
+        suppression_file = env.File('#tools/valgrind/iotivity.supp').srcnode().path
+
+        # Set up to run the test under Valgrind.
+        test_cmd = '%s valgrind --leak-check=full --suppressions=%s --xml=yes --xml-file=%s %s' % (valgrind_environment, suppression_file, xml_file, test_cmd)
+
+    ut = env.Command('ut', None, test_cmd)
+    env.AlwaysBuild('ut')
diff --git a/tools/scons/__init__.py b/tools/scons/__init__.py
new file mode 100644 (file)
index 0000000..9c7eea5
--- /dev/null
@@ -0,0 +1,17 @@
+# ------------------------------------------------------------------------
+# Copyright 2015 Intel Corporation
+#
+# 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.
+# ------------------------------------------------------------------------
+
+__all__ = [ "RunTest" ]
diff --git a/tools/valgrind/iotivity.supp b/tools/valgrind/iotivity.supp
new file mode 100644 (file)
index 0000000..bc2289e
--- /dev/null
@@ -0,0 +1,20 @@
+# ------------------------------------------------------------------------
+# Copyright 2015 Intel Corporation
+#
+# 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.
+# ------------------------------------------------------------------------
+
+# This file contains Valgrind suppressions.  It is meant to make
+# Valgrind ignore memory violations that are out of the control of
+# IoTivity developers.  Do NOT abuse this file by adding suppressions
+# for memory violations that can be addressed in IoTivity itself.