kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 | [diff] [blame] | 1 | #!/usr/bin/env python |
turaj@webrtc.org | 799980f | 2012-05-11 00:41:48 | [diff] [blame] | 2 | # Copyright (c) 2012 The WebRTC project authors. All Rights Reserved. |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 | [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 | [diff] [blame] | 10 | """Runs various WebRTC tests through valgrind_test.py. |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 | [diff] [blame] | 11 | |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 | [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 | [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 |
kjellander@webrtc.org | b6e4cc7 | 2012-05-27 20:59:35 | [diff] [blame] | 21 | Since they're referenced from the chrome_tests.py script, we have similar files |
| 22 | below the directory of this script. When executing, this script will setup both |
| 23 | Chrome's suppression files and our own, so we can easily maintain WebRTC |
| 24 | specific suppressions in our own files. |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 | [diff] [blame] | 25 | """ |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 | [diff] [blame] | 26 | |
oprypin | 51d49b4 | 2017-08-22 17:55:47 | [diff] [blame] | 27 | import argparse |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 | [diff] [blame] | 28 | import logging |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 | [diff] [blame] | 29 | import optparse |
kjellander@webrtc.org | b6e4cc7 | 2012-05-27 20:59:35 | [diff] [blame] | 30 | import os |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 | [diff] [blame] | 31 | import sys |
| 32 | |
| 33 | import logging_utils |
kjellander@webrtc.org | b6e4cc7 | 2012-05-27 20:59:35 | [diff] [blame] | 34 | import path_utils |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 | [diff] [blame] | 35 | |
| 36 | import chrome_tests |
| 37 | |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 | [diff] [blame] | 38 | |
| 39 | class WebRTCTest(chrome_tests.ChromeTests): |
kjellander@webrtc.org | b6e4cc7 | 2012-05-27 20:59:35 | [diff] [blame] | 40 | """Class that handles setup of suppressions for WebRTC. |
| 41 | |
| 42 | Everything else is inherited from chrome_tests.ChromeTests. |
| 43 | """ |
| 44 | |
kjellander@webrtc.org | 6d6d95e | 2013-06-11 06:03:32 | [diff] [blame] | 45 | def __init__(self, test_name, options, args, test_in_chrome_tests): |
| 46 | """Create a WebRTC test. |
| 47 | Args: |
| 48 | test_name: Short name for the test executable (no path). |
| 49 | options: options to pass to ChromeTests. |
| 50 | args: args to pass to ChromeTests. |
| 51 | test_in_chrome_tests: The name of the test configuration in ChromeTests. |
| 52 | """ |
| 53 | self._test_name = test_name |
| 54 | chrome_tests.ChromeTests.__init__(self, options, args, test_in_chrome_tests) |
| 55 | |
kjellander@webrtc.org | b6e4cc7 | 2012-05-27 20:59:35 | [diff] [blame] | 56 | def _DefaultCommand(self, tool, exe=None, valgrind_test_args=None): |
| 57 | """Override command-building method so we can add more suppressions.""" |
| 58 | cmd = chrome_tests.ChromeTests._DefaultCommand(self, tool, exe, |
| 59 | valgrind_test_args) |
kjellander@webrtc.org | 6d6d95e | 2013-06-11 06:03:32 | [diff] [blame] | 60 | |
| 61 | # Add gtest filters, if found. |
| 62 | chrome_tests.ChromeTests._AppendGtestFilter(self, tool, self._test_name, |
| 63 | cmd) |
| 64 | |
kjellander@webrtc.org | b6e4cc7 | 2012-05-27 20:59:35 | [diff] [blame] | 65 | # When ChromeTests._DefaultCommand has executed, it has setup suppression |
kjellander@webrtc.org | afede83 | 2014-10-10 09:18:34 | [diff] [blame] | 66 | # files based on what's found in the memcheck/ subdirectory of |
kjellander@webrtc.org | b6e4cc7 | 2012-05-27 20:59:35 | [diff] [blame] | 67 | # this script's location. If Mac or Windows is executing, additional |
| 68 | # platform specific files have also been added. |
kjellander@webrtc.org | 6d6d95e | 2013-06-11 06:03:32 | [diff] [blame] | 69 | # Since only the ones located below this directory are added, we must also |
kjellander | afd5494 | 2016-12-17 20:21:39 | [diff] [blame] | 70 | # add the ones maintained by Chrome, located in ../../tools/valgrind. |
kjellander@webrtc.org | b6e4cc7 | 2012-05-27 20:59:35 | [diff] [blame] | 71 | |
| 72 | # The idea is to look for --suppression arguments in the cmd list and add a |
| 73 | # modified copy of each suppression file, for the corresponding file in |
kjellander | afd5494 | 2016-12-17 20:21:39 | [diff] [blame] | 74 | # ../../tools/valgrind. |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 | [diff] [blame] | 75 | script_dir = path_utils.ScriptDir() |
kjellander | afd5494 | 2016-12-17 20:21:39 | [diff] [blame] | 76 | checkout_src = os.path.abspath(os.path.join(script_dir, os.pardir, |
| 77 | os.pardir)) |
| 78 | new_dir = os.path.join(checkout_src, 'tools', 'valgrind') |
kjellander@webrtc.org | b6e4cc7 | 2012-05-27 20:59:35 | [diff] [blame] | 79 | add_suppressions = [] |
| 80 | for token in cmd: |
| 81 | if '--suppressions' in token: |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 | [diff] [blame] | 82 | add_suppressions.append(token.replace(script_dir, new_dir)) |
kjellander@webrtc.org | b6e4cc7 | 2012-05-27 20:59:35 | [diff] [blame] | 83 | return add_suppressions + cmd |
| 84 | |
| 85 | |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 | [diff] [blame] | 86 | def main(_): |
phoglund@webrtc.org | 02421fc | 2013-08-27 14:00:10 | [diff] [blame] | 87 | parser = optparse.OptionParser( |
| 88 | 'usage: %prog -b <dir> -t <test> -- <test args>') |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 | [diff] [blame] | 89 | parser.disable_interspersed_args() |
kjellander@webrtc.org | fc89ba5 | 2013-10-14 18:05:52 | [diff] [blame] | 90 | parser.add_option('-b', '--build-dir', |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 | [diff] [blame] | 91 | help=('Location of the compiler output. Can only be used ' |
| 92 | 'when the test argument does not contain this path.')) |
kjellander@webrtc.org | 09418c3 | 2013-10-14 17:34:38 | [diff] [blame] | 93 | parser.add_option("--target", help="Debug or Release") |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 | [diff] [blame] | 94 | parser.add_option('-t', '--test', help='Test to run.') |
| 95 | parser.add_option('', '--baseline', action='store_true', default=False, |
| 96 | help='Generate baseline data instead of validating') |
| 97 | parser.add_option('', '--gtest_filter', |
| 98 | help='Additional arguments to --gtest_filter') |
| 99 | parser.add_option('', '--gtest_repeat', |
| 100 | help='Argument for --gtest_repeat') |
kjellander@webrtc.org | 59d5705 | 2013-12-11 14:16:53 | [diff] [blame] | 101 | parser.add_option("--gtest_shuffle", action="store_true", default=False, |
| 102 | help="Randomize tests' orders on every iteration.") |
kjellander@webrtc.org | 944fb57 | 2014-11-11 09:57:19 | [diff] [blame] | 103 | parser.add_option("--gtest_break_on_failure", action="store_true", |
| 104 | default=False, |
| 105 | help="Drop in to debugger on assertion failure. Also " |
| 106 | "useful for forcing tests to exit with a stack dump " |
| 107 | "on the first assertion failure when running with " |
| 108 | "--gtest_repeat=-1") |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 | [diff] [blame] | 109 | parser.add_option('-v', '--verbose', action='store_true', default=False, |
| 110 | help='Verbose output - enable debug log messages') |
| 111 | parser.add_option('', '--tool', dest='valgrind_tool', default='memcheck', |
| 112 | help='Specify a valgrind tool to run the tests under') |
| 113 | parser.add_option('', '--tool_flags', dest='valgrind_tool_flags', default='', |
| 114 | help='Specify custom flags for the selected valgrind tool') |
| 115 | parser.add_option('', '--keep_logs', action='store_true', default=False, |
| 116 | help=('Store memory tool logs in the <tool>.logs directory ' |
| 117 | 'instead of /tmp.\nThis can be useful for tool ' |
| 118 | 'developers/maintainers.\nPlease note that the <tool>' |
| 119 | '.logs directory will be clobbered on tool startup.')) |
wjia@webrtc.org | 03cfde2 | 2014-01-14 17:48:34 | [diff] [blame] | 120 | parser.add_option("--test-launcher-bot-mode", action="store_true", |
| 121 | help="run the tests with --test-launcher-bot-mode") |
kjellander@webrtc.org | bfdee69 | 2015-02-03 15:23:34 | [diff] [blame] | 122 | parser.add_option("--test-launcher-total-shards", type=int, |
| 123 | help="run the tests with --test-launcher-total-shards") |
| 124 | parser.add_option("--test-launcher-shard-index", type=int, |
| 125 | help="run the tests with --test-launcher-shard-index") |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 | [diff] [blame] | 126 | options, args = parser.parse_args() |
| 127 | |
oprypin | 51d49b4 | 2017-08-22 17:55:47 | [diff] [blame] | 128 | ignore_parser = argparse.ArgumentParser() |
| 129 | # Ignore Chromium-specific flags |
| 130 | # TODO(oprypin): Remove (bugs.webrtc.org/8115) |
| 131 | ignore_parser.add_argument('--isolated-script-test-output', |
| 132 | type=str, default=None) |
ehmaldonado | c4eee32 | 2017-09-07 07:34:17 | [diff] [blame] | 133 | ignore_parser.add_argument('--isolated-script-test-perf-output', |
oprypin | 51d49b4 | 2017-08-22 17:55:47 | [diff] [blame] | 134 | type=str, default=None) |
| 135 | _, args = ignore_parser.parse_known_args(args) |
| 136 | |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 | [diff] [blame] | 137 | if options.verbose: |
| 138 | logging_utils.config_root(logging.DEBUG) |
| 139 | else: |
| 140 | logging_utils.config_root() |
| 141 | |
| 142 | if not options.test: |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 | [diff] [blame] | 143 | parser.error('--test not specified') |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 | [diff] [blame] | 144 | |
kjellander@webrtc.org | 09418c3 | 2013-10-14 17:34:38 | [diff] [blame] | 145 | # Support build dir both with and without the target. |
| 146 | if (options.target and options.build_dir and |
| 147 | not options.build_dir.endswith(options.target)): |
| 148 | options.build_dir = os.path.join(options.build_dir, options.target) |
| 149 | |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 | [diff] [blame] | 150 | # If --build_dir is provided, prepend it to the test executable if needed. |
kjellander@webrtc.org | dc6fa02 | 2013-01-10 10:06:15 | [diff] [blame] | 151 | test_executable = options.test |
| 152 | if options.build_dir and not test_executable.startswith(options.build_dir): |
| 153 | test_executable = os.path.join(options.build_dir, test_executable) |
| 154 | args = [test_executable] + args |
kjellander@webrtc.org | b43f85f | 2012-09-11 11:22:45 | [diff] [blame] | 155 | |
kjellander@webrtc.org | 6d6d95e | 2013-06-11 06:03:32 | [diff] [blame] | 156 | test = WebRTCTest(options.test, options, args, 'cmdline') |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 | [diff] [blame] | 157 | return test.Run() |
turaj@webrtc.org | 799980f | 2012-05-11 00:41:48 | [diff] [blame] | 158 | |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 | [diff] [blame] | 159 | if __name__ == '__main__': |
kjellander@webrtc.org | 8f13810 | 2013-01-10 08:13:52 | [diff] [blame] | 160 | return_code = main(sys.argv) |
| 161 | sys.exit(return_code) |