From eecedc6980a2bd91539e06fb15419ce4b324114d Mon Sep 17 00:00:00 2001 From: Ossama Othman Date: Wed, 15 Jul 2015 14:23:41 -0700 Subject: [PATCH] Refactor duplicated SCons/Python test run code. 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 Reviewed-on: https://gerrit.iotivity.org/gerrit/1678 Tested-by: jenkins-iotivity Reviewed-by: Jon A. Cruz Reviewed-by: Caiwen Zhang Reviewed-by: Erich Keane --- resource/c_common/oic_malloc/test/SConscript | 16 +++----- resource/c_common/oic_string/test/SConscript | 16 +++----- resource/csdk/connectivity/test/SConscript | 13 ++----- resource/csdk/ocrandom/test/SConscript | 13 ++----- resource/csdk/stack/test/SConscript | 15 +++---- resource/unittests/SConscript | 30 +++++++------- tools/__init__.py | 17 ++++++++ tools/scons/RunTest.py | 58 ++++++++++++++++++++++++++++ tools/scons/__init__.py | 17 ++++++++ tools/valgrind/iotivity.supp | 20 ++++++++++ 10 files changed, 148 insertions(+), 67 deletions(-) create mode 100644 tools/__init__.py create mode 100644 tools/scons/RunTest.py create mode 100644 tools/scons/__init__.py create mode 100644 tools/valgrind/iotivity.supp diff --git a/resource/c_common/oic_malloc/test/SConscript b/resource/c_common/oic_malloc/test/SConscript index 0443928..0b702ec 100644 --- a/resource/c_common/oic_malloc/test/SConscript +++ b/resource/c_common/oic_malloc/test/SConscript @@ -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') diff --git a/resource/c_common/oic_string/test/SConscript b/resource/c_common/oic_string/test/SConscript index 9aacebc..9d30251 100644 --- a/resource/c_common/oic_string/test/SConscript +++ b/resource/c_common/oic_string/test/SConscript @@ -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') diff --git a/resource/csdk/connectivity/test/SConscript b/resource/csdk/connectivity/test/SConscript index 24f2bdc..b66a223 100644 --- a/resource/csdk/connectivity/test/SConscript +++ b/resource/csdk/connectivity/test/SConscript @@ -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') diff --git a/resource/csdk/ocrandom/test/SConscript b/resource/csdk/ocrandom/test/SConscript index eeb858a..2e7bc52 100644 --- a/resource/csdk/ocrandom/test/SConscript +++ b/resource/csdk/ocrandom/test/SConscript @@ -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') diff --git a/resource/csdk/stack/test/SConscript b/resource/csdk/stack/test/SConscript index 27f9905..ade8f3f 100644 --- a/resource/csdk/stack/test/SConscript +++ b/resource/csdk/stack/test/SConscript @@ -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') diff --git a/resource/unittests/SConscript b/resource/unittests/SConscript index 45c152d..4264736 100644 --- a/resource/unittests/SConscript +++ b/resource/unittests/SConscript @@ -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 index 0000000..05bfb69 --- /dev/null +++ b/tools/__init__.py @@ -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 index 0000000..0d9f023 --- /dev/null +++ b/tools/scons/RunTest.py @@ -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 index 0000000..9c7eea5 --- /dev/null +++ b/tools/scons/__init__.py @@ -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 index 0000000..bc2289e --- /dev/null +++ b/tools/valgrind/iotivity.supp @@ -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. -- 2.7.4