blob: d5a79eb27ee52374920adf99f73ebcade681d30f [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
21 valgrind/tsan/suppressions.txt
22 valgrind/tsan/suppressions_mac.txt
23 valgrind/tsan/suppressions_win32.txt
24Since they're referenced from the chrome_tests.py script, we have similar files
25below the directory of this script. When executing, this script will setup both
26Chrome's suppression files and our own, so we can easily maintain WebRTC
27specific suppressions in our own files.
kjellander@webrtc.org8f138102013-01-10 08:13:52 +000028"""
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +000029
kjellander@webrtc.org8f138102013-01-10 08:13:52 +000030import logging
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +000031import optparse
kjellander@webrtc.orgb6e4cc72012-05-27 20:59:35 +000032import os
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +000033import sys
34
35import logging_utils
kjellander@webrtc.orgb6e4cc72012-05-27 20:59:35 +000036import path_utils
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +000037
38import chrome_tests
39
kjellander@webrtc.org8f138102013-01-10 08:13:52 +000040
41class WebRTCTest(chrome_tests.ChromeTests):
kjellander@webrtc.orgb6e4cc72012-05-27 20:59:35 +000042 """Class that handles setup of suppressions for WebRTC.
43
44 Everything else is inherited from chrome_tests.ChromeTests.
45 """
46
kjellander@webrtc.org6d6d95e2013-06-11 06:03:32 +000047 def __init__(self, test_name, options, args, test_in_chrome_tests):
48 """Create a WebRTC test.
49 Args:
50 test_name: Short name for the test executable (no path).
51 options: options to pass to ChromeTests.
52 args: args to pass to ChromeTests.
53 test_in_chrome_tests: The name of the test configuration in ChromeTests.
54 """
55 self._test_name = test_name
56 chrome_tests.ChromeTests.__init__(self, options, args, test_in_chrome_tests)
57
kjellander@webrtc.orgb6e4cc72012-05-27 20:59:35 +000058 def _DefaultCommand(self, tool, exe=None, valgrind_test_args=None):
59 """Override command-building method so we can add more suppressions."""
60 cmd = chrome_tests.ChromeTests._DefaultCommand(self, tool, exe,
61 valgrind_test_args)
kjellander@webrtc.org6d6d95e2013-06-11 06:03:32 +000062
63 # Add gtest filters, if found.
64 chrome_tests.ChromeTests._AppendGtestFilter(self, tool, self._test_name,
65 cmd)
66
kjellander@webrtc.orgb6e4cc72012-05-27 20:59:35 +000067 # When ChromeTests._DefaultCommand has executed, it has setup suppression
68 # files based on what's found in the memcheck/ or tsan/ subdirectories of
69 # this script's location. If Mac or Windows is executing, additional
70 # platform specific files have also been added.
kjellander@webrtc.org6d6d95e2013-06-11 06:03:32 +000071 # Since only the ones located below this directory are added, we must also
kjellander@webrtc.orgb6e4cc72012-05-27 20:59:35 +000072 # add the ones maintained by Chrome, located in ../valgrind.
73
74 # The idea is to look for --suppression arguments in the cmd list and add a
75 # modified copy of each suppression file, for the corresponding file in
76 # ../valgrind. If we would simply replace 'valgrind-webrtc' with 'valgrind'
77 # we may produce invalid paths if other parts of the path contain that
78 # string. That's why the code below only replaces the end of the path.
kjellander@webrtc.org8f138102013-01-10 08:13:52 +000079 script_dir = path_utils.ScriptDir()
80 old_base, _ = os.path.split(script_dir)
81 new_dir = os.path.join(old_base, 'valgrind')
kjellander@webrtc.orgb6e4cc72012-05-27 20:59:35 +000082 add_suppressions = []
83 for token in cmd:
84 if '--suppressions' in token:
kjellander@webrtc.org8f138102013-01-10 08:13:52 +000085 add_suppressions.append(token.replace(script_dir, new_dir))
kjellander@webrtc.orgb6e4cc72012-05-27 20:59:35 +000086 return add_suppressions + cmd
87
88
kjellander@webrtc.org8f138102013-01-10 08:13:52 +000089def main(_):
phoglund@webrtc.org02421fc2013-08-27 14:00:10 +000090 parser = optparse.OptionParser(
91 'usage: %prog -b <dir> -t <test> -- <test args>')
kjellander@webrtc.org8f138102013-01-10 08:13:52 +000092 parser.disable_interspersed_args()
kjellander@webrtc.orgfc89ba52013-10-14 18:05:52 +000093 parser.add_option('-b', '--build-dir',
kjellander@webrtc.org8f138102013-01-10 08:13:52 +000094 help=('Location of the compiler output. Can only be used '
95 'when the test argument does not contain this path.'))
kjellander@webrtc.org09418c32013-10-14 17:34:38 +000096 parser.add_option("--target", help="Debug or Release")
kjellander@webrtc.org8f138102013-01-10 08:13:52 +000097 parser.add_option('-t', '--test', help='Test to run.')
98 parser.add_option('', '--baseline', action='store_true', default=False,
99 help='Generate baseline data instead of validating')
100 parser.add_option('', '--gtest_filter',
101 help='Additional arguments to --gtest_filter')
102 parser.add_option('', '--gtest_repeat',
103 help='Argument for --gtest_repeat')
kjellander@webrtc.org59d57052013-12-11 14:16:53 +0000104 parser.add_option("--gtest_shuffle", action="store_true", default=False,
105 help="Randomize tests' orders on every iteration.")
kjellander@webrtc.org8f138102013-01-10 08:13:52 +0000106 parser.add_option('-v', '--verbose', action='store_true', default=False,
107 help='Verbose output - enable debug log messages')
108 parser.add_option('', '--tool', dest='valgrind_tool', default='memcheck',
109 help='Specify a valgrind tool to run the tests under')
110 parser.add_option('', '--tool_flags', dest='valgrind_tool_flags', default='',
111 help='Specify custom flags for the selected valgrind tool')
112 parser.add_option('', '--keep_logs', action='store_true', default=False,
113 help=('Store memory tool logs in the <tool>.logs directory '
114 'instead of /tmp.\nThis can be useful for tool '
115 'developers/maintainers.\nPlease note that the <tool>'
116 '.logs directory will be clobbered on tool startup.'))
wjia@webrtc.org03cfde22014-01-14 17:48:34 +0000117 parser.add_option("--brave-new-test-launcher", action="store_true",
118 help="run the tests with --brave-new-test-launcher")
119 parser.add_option("--test-launcher-bot-mode", action="store_true",
120 help="run the tests with --test-launcher-bot-mode")
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +0000121 options, args = parser.parse_args()
122
123 if options.verbose:
124 logging_utils.config_root(logging.DEBUG)
125 else:
126 logging_utils.config_root()
127
128 if not options.test:
kjellander@webrtc.org8f138102013-01-10 08:13:52 +0000129 parser.error('--test not specified')
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +0000130
kjellander@webrtc.org09418c32013-10-14 17:34:38 +0000131 # Support build dir both with and without the target.
132 if (options.target and options.build_dir and
133 not options.build_dir.endswith(options.target)):
134 options.build_dir = os.path.join(options.build_dir, options.target)
135
kjellander@webrtc.org8f138102013-01-10 08:13:52 +0000136 # If --build_dir is provided, prepend it to the test executable if needed.
kjellander@webrtc.orgdc6fa022013-01-10 10:06:15 +0000137 test_executable = options.test
138 if options.build_dir and not test_executable.startswith(options.build_dir):
139 test_executable = os.path.join(options.build_dir, test_executable)
140 args = [test_executable] + args
kjellander@webrtc.orgb43f85f2012-09-11 11:22:45 +0000141
kjellander@webrtc.org6d6d95e2013-06-11 06:03:32 +0000142 test = WebRTCTest(options.test, options, args, 'cmdline')
kjellander@webrtc.org8f138102013-01-10 08:13:52 +0000143 return test.Run()
turaj@webrtc.org799980f2012-05-11 00:41:48 +0000144
kjellander@webrtc.org8f138102013-01-10 08:13:52 +0000145if __name__ == '__main__':
kjellander@webrtc.org8f138102013-01-10 08:13:52 +0000146 return_code = main(sys.argv)
147 sys.exit(return_code)