blob: 627025cd75d2413aaf688bf943c2d5dcda08af62 [file] [log] [blame]
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +00001#!/usr/bin/env python
turaj@webrtc.org799980f2012-05-11 00:41:48 +00002# Copyright (c) 2012 The WebRTC project authors. All Rights Reserved.
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +00003#
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.org8f138102013-01-10 08:13:52 +000010"""Runs various WebRTC tests through valgrind_test.py.
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +000011
kjellander@webrtc.org8f138102013-01-10 08:13:52 +000012This script inherits the chrome_tests.py in Chrome, but allows running any test
13instead of only the hard-coded ones. It uses the -t cmdline flag to do this, and
14only supports specifying a single test for each run.
kjellander@webrtc.orgb6e4cc72012-05-27 20:59:35 +000015
16Suppression files:
17The Chrome valgrind directory we use as a DEPS dependency contains the following
18suppression files:
19 valgrind/memcheck/suppressions.txt
20 valgrind/memcheck/suppressions_mac.txt
kjellander@webrtc.orgb6e4cc72012-05-27 20:59:35 +000021Since they're referenced from the chrome_tests.py script, we have similar files
22below the directory of this script. When executing, this script will setup both
23Chrome's suppression files and our own, so we can easily maintain WebRTC
24specific suppressions in our own files.
kjellander@webrtc.org8f138102013-01-10 08:13:52 +000025"""
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +000026
kjellander@webrtc.org8f138102013-01-10 08:13:52 +000027import logging
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +000028import optparse
kjellander@webrtc.orgb6e4cc72012-05-27 20:59:35 +000029import os
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +000030import sys
31
32import logging_utils
kjellander@webrtc.orgb6e4cc72012-05-27 20:59:35 +000033import path_utils
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +000034
35import chrome_tests
36
kjellander@webrtc.org8f138102013-01-10 08:13:52 +000037
38class WebRTCTest(chrome_tests.ChromeTests):
kjellander@webrtc.orgb6e4cc72012-05-27 20:59:35 +000039 """Class that handles setup of suppressions for WebRTC.
40
41 Everything else is inherited from chrome_tests.ChromeTests.
42 """
43
kjellander@webrtc.org6d6d95e2013-06-11 06:03:32 +000044 def __init__(self, test_name, options, args, test_in_chrome_tests):
45 """Create a WebRTC test.
46 Args:
47 test_name: Short name for the test executable (no path).
48 options: options to pass to ChromeTests.
49 args: args to pass to ChromeTests.
50 test_in_chrome_tests: The name of the test configuration in ChromeTests.
51 """
52 self._test_name = test_name
53 chrome_tests.ChromeTests.__init__(self, options, args, test_in_chrome_tests)
54
kjellander@webrtc.orgb6e4cc72012-05-27 20:59:35 +000055 def _DefaultCommand(self, tool, exe=None, valgrind_test_args=None):
56 """Override command-building method so we can add more suppressions."""
57 cmd = chrome_tests.ChromeTests._DefaultCommand(self, tool, exe,
58 valgrind_test_args)
kjellander@webrtc.org6d6d95e2013-06-11 06:03:32 +000059
60 # Add gtest filters, if found.
61 chrome_tests.ChromeTests._AppendGtestFilter(self, tool, self._test_name,
62 cmd)
63
kjellander@webrtc.orgb6e4cc72012-05-27 20:59:35 +000064 # When ChromeTests._DefaultCommand has executed, it has setup suppression
kjellander@webrtc.orgafede832014-10-10 09:18:34 +000065 # files based on what's found in the memcheck/ subdirectory of
kjellander@webrtc.orgb6e4cc72012-05-27 20:59:35 +000066 # this script's location. If Mac or Windows is executing, additional
67 # platform specific files have also been added.
kjellander@webrtc.org6d6d95e2013-06-11 06:03:32 +000068 # Since only the ones located below this directory are added, we must also
kjellanderafd54942016-12-17 12:21:39 -080069 # add the ones maintained by Chrome, located in ../../tools/valgrind.
kjellander@webrtc.orgb6e4cc72012-05-27 20:59:35 +000070
71 # The idea is to look for --suppression arguments in the cmd list and add a
72 # modified copy of each suppression file, for the corresponding file in
kjellanderafd54942016-12-17 12:21:39 -080073 # ../../tools/valgrind.
kjellander@webrtc.org8f138102013-01-10 08:13:52 +000074 script_dir = path_utils.ScriptDir()
kjellanderafd54942016-12-17 12:21:39 -080075 checkout_src = os.path.abspath(os.path.join(script_dir, os.pardir,
76 os.pardir))
77 new_dir = os.path.join(checkout_src, 'tools', 'valgrind')
kjellander@webrtc.orgb6e4cc72012-05-27 20:59:35 +000078 add_suppressions = []
79 for token in cmd:
80 if '--suppressions' in token:
kjellander@webrtc.org8f138102013-01-10 08:13:52 +000081 add_suppressions.append(token.replace(script_dir, new_dir))
kjellander@webrtc.orgb6e4cc72012-05-27 20:59:35 +000082 return add_suppressions + cmd
83
84
kjellander@webrtc.org8f138102013-01-10 08:13:52 +000085def main(_):
phoglund@webrtc.org02421fc2013-08-27 14:00:10 +000086 parser = optparse.OptionParser(
87 'usage: %prog -b <dir> -t <test> -- <test args>')
kjellander@webrtc.org8f138102013-01-10 08:13:52 +000088 parser.disable_interspersed_args()
kjellander@webrtc.orgfc89ba52013-10-14 18:05:52 +000089 parser.add_option('-b', '--build-dir',
kjellander@webrtc.org8f138102013-01-10 08:13:52 +000090 help=('Location of the compiler output. Can only be used '
91 'when the test argument does not contain this path.'))
kjellander@webrtc.org09418c32013-10-14 17:34:38 +000092 parser.add_option("--target", help="Debug or Release")
kjellander@webrtc.org8f138102013-01-10 08:13:52 +000093 parser.add_option('-t', '--test', help='Test to run.')
94 parser.add_option('', '--baseline', action='store_true', default=False,
95 help='Generate baseline data instead of validating')
96 parser.add_option('', '--gtest_filter',
97 help='Additional arguments to --gtest_filter')
98 parser.add_option('', '--gtest_repeat',
99 help='Argument for --gtest_repeat')
kjellander@webrtc.org59d57052013-12-11 14:16:53 +0000100 parser.add_option("--gtest_shuffle", action="store_true", default=False,
101 help="Randomize tests' orders on every iteration.")
kjellander@webrtc.org944fb572014-11-11 09:57:19 +0000102 parser.add_option("--gtest_break_on_failure", action="store_true",
103 default=False,
104 help="Drop in to debugger on assertion failure. Also "
105 "useful for forcing tests to exit with a stack dump "
106 "on the first assertion failure when running with "
107 "--gtest_repeat=-1")
kjellander@webrtc.org8f138102013-01-10 08:13:52 +0000108 parser.add_option('-v', '--verbose', action='store_true', default=False,
109 help='Verbose output - enable debug log messages')
110 parser.add_option('', '--tool', dest='valgrind_tool', default='memcheck',
111 help='Specify a valgrind tool to run the tests under')
112 parser.add_option('', '--tool_flags', dest='valgrind_tool_flags', default='',
113 help='Specify custom flags for the selected valgrind tool')
114 parser.add_option('', '--keep_logs', action='store_true', default=False,
115 help=('Store memory tool logs in the <tool>.logs directory '
116 'instead of /tmp.\nThis can be useful for tool '
117 'developers/maintainers.\nPlease note that the <tool>'
118 '.logs directory will be clobbered on tool startup.'))
wjia@webrtc.org03cfde22014-01-14 17:48:34 +0000119 parser.add_option("--test-launcher-bot-mode", action="store_true",
120 help="run the tests with --test-launcher-bot-mode")
kjellander@webrtc.orgbfdee692015-02-03 15:23:34 +0000121 parser.add_option("--test-launcher-total-shards", type=int,
122 help="run the tests with --test-launcher-total-shards")
123 parser.add_option("--test-launcher-shard-index", type=int,
124 help="run the tests with --test-launcher-shard-index")
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +0000125 options, args = parser.parse_args()
126
127 if options.verbose:
128 logging_utils.config_root(logging.DEBUG)
129 else:
130 logging_utils.config_root()
131
132 if not options.test:
kjellander@webrtc.org8f138102013-01-10 08:13:52 +0000133 parser.error('--test not specified')
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +0000134
kjellander@webrtc.org09418c32013-10-14 17:34:38 +0000135 # Support build dir both with and without the target.
136 if (options.target and options.build_dir and
137 not options.build_dir.endswith(options.target)):
138 options.build_dir = os.path.join(options.build_dir, options.target)
139
kjellander@webrtc.org8f138102013-01-10 08:13:52 +0000140 # If --build_dir is provided, prepend it to the test executable if needed.
kjellander@webrtc.orgdc6fa022013-01-10 10:06:15 +0000141 test_executable = options.test
142 if options.build_dir and not test_executable.startswith(options.build_dir):
143 test_executable = os.path.join(options.build_dir, test_executable)
144 args = [test_executable] + args
kjellander@webrtc.orgb43f85f2012-09-11 11:22:45 +0000145
kjellander@webrtc.org6d6d95e2013-06-11 06:03:32 +0000146 test = WebRTCTest(options.test, options, args, 'cmdline')
kjellander@webrtc.org8f138102013-01-10 08:13:52 +0000147 return test.Run()
turaj@webrtc.org799980f2012-05-11 00:41:48 +0000148
kjellander@webrtc.org8f138102013-01-10 08:13:52 +0000149if __name__ == '__main__':
kjellander@webrtc.org8f138102013-01-10 08:13:52 +0000150 return_code = main(sys.argv)
151 sys.exit(return_code)