Imported Upstream version 0.9.2
[platform/upstream/iotivity.git] / tools / scons / RunTest.py
1 # ------------------------------------------------------------------------
2 # Copyright 2015 Intel Corporation
3 #
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
7 #
8 #      http://www.apache.org/licenses/LICENSE-2.0
9 #
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 # ------------------------------------------------------------------------
16
17 import os
18
19 def run_test(env, xml_file, test):
20     """
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
24     parameter.
25
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.
29     """
30
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)
35
36     # Dump test report in XML format to the results directory.
37     env.AppendENVPath('GTEST_OUTPUT', ['xml:' + result_dir])
38
39     # Make sure the Google Test libraries are in the dynamic
40     # linker/loader path.
41     env.AppendENVPath('LD_LIBRARY_PATH', [build_dir])
42     env.AppendENVPath('LD_LIBRARY_PATH', ['./extlibs/gtest/gtest-1.7.0/lib/.libs'])
43
44     test_cmd = os.path.join(build_dir, test)
45
46     if xml_file:
47         # Environment variables to be made available during the
48         # Valgrind run.
49         valgrind_environment = ''
50
51         # Valgrind suppressions file.
52         suppression_file = env.File('#tools/valgrind/iotivity.supp').srcnode().path
53
54         # Set up to run the test under Valgrind.
55         test_cmd = '%s valgrind --leak-check=full --suppressions=%s --xml=yes --xml-file=%s %s' % (valgrind_environment, suppression_file, xml_file, test_cmd)
56
57     ut = env.Command('ut', None, test_cmd)
58     env.AlwaysBuild('ut')