1 # ------------------------------------------------------------------------
2 # Copyright 2015 Intel Corporation
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
8 # http://www.apache.org/licenses/LICENSE-2.0
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 # ------------------------------------------------------------------------
19 def run_test(env, xml_file, test):
21 Run test with the given SCons Environment, dumping Valgrind
22 results to the given XML file. If no Valgrind run is desired
23 simply pass in an empty string or None for the xml_file
26 Note that the test path should not include the build directory
27 where binaries are placed. The build directory will be prepended
28 to the test path automatically.
31 build_dir = env.get('BUILD_DIR')
32 result_dir = os.path.join(build_dir, 'test_out/')
33 if not os.path.isdir(result_dir):
34 os.makedirs(result_dir)
36 # Dump test report in XML format to the results directory.
37 env.AppendENVPath('GTEST_OUTPUT', ['xml:' + result_dir])
39 # Make sure the Google Test libraries are in the dynamic
41 env.AppendENVPath('LD_LIBRARY_PATH', [build_dir])
42 env.AppendENVPath('LD_LIBRARY_PATH', ['./extlibs/gtest/gtest-1.7.0/lib/.libs'])
44 test_cmd = os.path.join(build_dir, test)
47 # Environment variables to be made available during the
49 valgrind_environment = ''
51 # GLib uses a custom memory allocation scheme that can
52 # sometimes confuse Valgrind. Configure GLib to be Valgrind
54 valgrind_environment += 'G_DEBUG=gc-friendly G_SLICE=always-malloc'
56 # Valgrind suppressions file.
57 suppression_file = env.File('#tools/valgrind/iotivity.supp').srcnode().path
59 # Set up to run the test under Valgrind.
60 test_cmd = '%s valgrind --leak-check=full --suppressions=%s --xml=yes --xml-file=%s %s' % (valgrind_environment, suppression_file, xml_file, test_cmd)
62 ut = env.Command('ut', None, test_cmd)