kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 1 | #!/usr/bin/env python |
turaj@webrtc.org | 799980f | 2012-05-11 00:41:48 +0000 | [diff] [blame] | 2 | # Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 3 | # |
| 4 | # Use of this source code is governed by a BSD-style license |
| 5 | # that can be found in the LICENSE file in the root of the source |
| 6 | # tree. An additional intellectual property rights grant can be found |
| 7 | # in the file PATENTS. All contributing project authors may |
| 8 | # be found in the AUTHORS file in the root of the source tree. |
| 9 | |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 +0000 | [diff] [blame] | 10 | """Runs various WebRTC tests through valgrind_test.py. |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 11 | |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 +0000 | [diff] [blame] | 12 | This script inherits the chrome_tests.py in Chrome, but allows running any test |
| 13 | instead of only the hard-coded ones. It uses the -t cmdline flag to do this, and |
| 14 | only supports specifying a single test for each run. |
kjellander@webrtc.org | b6e4cc7 | 2012-05-27 20:59:35 +0000 | [diff] [blame] | 15 | |
| 16 | Suppression files: |
| 17 | The Chrome valgrind directory we use as a DEPS dependency contains the following |
| 18 | suppression files: |
| 19 | valgrind/memcheck/suppressions.txt |
| 20 | valgrind/memcheck/suppressions_mac.txt |
| 21 | valgrind/tsan/suppressions.txt |
| 22 | valgrind/tsan/suppressions_mac.txt |
| 23 | valgrind/tsan/suppressions_win32.txt |
| 24 | Since they're referenced from the chrome_tests.py script, we have similar files |
| 25 | below the directory of this script. When executing, this script will setup both |
| 26 | Chrome's suppression files and our own, so we can easily maintain WebRTC |
| 27 | specific suppressions in our own files. |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 +0000 | [diff] [blame] | 28 | """ |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 29 | |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 +0000 | [diff] [blame] | 30 | import logging |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 31 | import optparse |
kjellander@webrtc.org | b6e4cc7 | 2012-05-27 20:59:35 +0000 | [diff] [blame] | 32 | import os |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 33 | import sys |
| 34 | |
| 35 | import logging_utils |
kjellander@webrtc.org | b6e4cc7 | 2012-05-27 20:59:35 +0000 | [diff] [blame] | 36 | import path_utils |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 37 | |
| 38 | import chrome_tests |
| 39 | |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 +0000 | [diff] [blame] | 40 | |
| 41 | class WebRTCTest(chrome_tests.ChromeTests): |
kjellander@webrtc.org | b6e4cc7 | 2012-05-27 20:59:35 +0000 | [diff] [blame] | 42 | """Class that handles setup of suppressions for WebRTC. |
| 43 | |
| 44 | Everything else is inherited from chrome_tests.ChromeTests. |
| 45 | """ |
| 46 | |
| 47 | def _DefaultCommand(self, tool, exe=None, valgrind_test_args=None): |
| 48 | """Override command-building method so we can add more suppressions.""" |
| 49 | cmd = chrome_tests.ChromeTests._DefaultCommand(self, tool, exe, |
| 50 | valgrind_test_args) |
| 51 | # When ChromeTests._DefaultCommand has executed, it has setup suppression |
| 52 | # files based on what's found in the memcheck/ or tsan/ subdirectories of |
| 53 | # this script's location. If Mac or Windows is executing, additional |
| 54 | # platform specific files have also been added. |
| 55 | # Since only the ones located below this directory is added, we must also |
| 56 | # add the ones maintained by Chrome, located in ../valgrind. |
| 57 | |
| 58 | # The idea is to look for --suppression arguments in the cmd list and add a |
| 59 | # modified copy of each suppression file, for the corresponding file in |
| 60 | # ../valgrind. If we would simply replace 'valgrind-webrtc' with 'valgrind' |
| 61 | # we may produce invalid paths if other parts of the path contain that |
| 62 | # string. That's why the code below only replaces the end of the path. |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 +0000 | [diff] [blame] | 63 | script_dir = path_utils.ScriptDir() |
| 64 | old_base, _ = os.path.split(script_dir) |
| 65 | new_dir = os.path.join(old_base, 'valgrind') |
kjellander@webrtc.org | b6e4cc7 | 2012-05-27 20:59:35 +0000 | [diff] [blame] | 66 | add_suppressions = [] |
| 67 | for token in cmd: |
| 68 | if '--suppressions' in token: |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 +0000 | [diff] [blame] | 69 | add_suppressions.append(token.replace(script_dir, new_dir)) |
kjellander@webrtc.org | b6e4cc7 | 2012-05-27 20:59:35 +0000 | [diff] [blame] | 70 | return add_suppressions + cmd |
| 71 | |
| 72 | |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 +0000 | [diff] [blame] | 73 | def main(_): |
| 74 | parser = optparse.OptionParser('usage: %prog -b <dir> -t <test> <test args>') |
| 75 | parser.disable_interspersed_args() |
| 76 | parser.add_option('-b', '--build_dir', |
| 77 | help=('Location of the compiler output. Can only be used ' |
| 78 | 'when the test argument does not contain this path.')) |
| 79 | parser.add_option('-t', '--test', help='Test to run.') |
| 80 | parser.add_option('', '--baseline', action='store_true', default=False, |
| 81 | help='Generate baseline data instead of validating') |
| 82 | parser.add_option('', '--gtest_filter', |
| 83 | help='Additional arguments to --gtest_filter') |
| 84 | parser.add_option('', '--gtest_repeat', |
| 85 | help='Argument for --gtest_repeat') |
| 86 | parser.add_option('-v', '--verbose', action='store_true', default=False, |
| 87 | help='Verbose output - enable debug log messages') |
| 88 | parser.add_option('', '--tool', dest='valgrind_tool', default='memcheck', |
| 89 | help='Specify a valgrind tool to run the tests under') |
| 90 | parser.add_option('', '--tool_flags', dest='valgrind_tool_flags', default='', |
| 91 | help='Specify custom flags for the selected valgrind tool') |
| 92 | parser.add_option('', '--keep_logs', action='store_true', default=False, |
| 93 | help=('Store memory tool logs in the <tool>.logs directory ' |
| 94 | 'instead of /tmp.\nThis can be useful for tool ' |
| 95 | 'developers/maintainers.\nPlease note that the <tool>' |
| 96 | '.logs directory will be clobbered on tool startup.')) |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 97 | options, args = parser.parse_args() |
| 98 | |
| 99 | if options.verbose: |
| 100 | logging_utils.config_root(logging.DEBUG) |
| 101 | else: |
| 102 | logging_utils.config_root() |
| 103 | |
| 104 | if not options.test: |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 +0000 | [diff] [blame] | 105 | parser.error('--test not specified') |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 106 | |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 +0000 | [diff] [blame] | 107 | # If --build_dir is provided, prepend it to the test executable if needed. |
kjellander@webrtc.org | dc6fa02 | 2013-01-10 10:06:15 +0000 | [diff] [blame^] | 108 | test_executable = options.test |
| 109 | if options.build_dir and not test_executable.startswith(options.build_dir): |
| 110 | test_executable = os.path.join(options.build_dir, test_executable) |
| 111 | args = [test_executable] + args |
kjellander@webrtc.org | b43f85f | 2012-09-11 11:22:45 +0000 | [diff] [blame] | 112 | |
kjellander@webrtc.org | dc6fa02 | 2013-01-10 10:06:15 +0000 | [diff] [blame^] | 113 | test = WebRTCTest(options, args, 'cmdline') |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 +0000 | [diff] [blame] | 114 | return test.Run() |
turaj@webrtc.org | 799980f | 2012-05-11 00:41:48 +0000 | [diff] [blame] | 115 | |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 +0000 | [diff] [blame] | 116 | if __name__ == '__main__': |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 +0000 | [diff] [blame] | 117 | return_code = main(sys.argv) |
| 118 | sys.exit(return_code) |