blob: 421dc2c59b0099c6ff24c9b1838254365555ae07 [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
turaj@webrtc.org799980f2012-05-11 00:41:48 +000010'''Runs various WebRTC tests through valgrind_test.py.
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +000011
turaj@webrtc.org799980f2012-05-11 00:41:48 +000012This script inherits the chrome_tests.py in Chrome, replacing its tests. We do
13this by taking chrome's faux cmdline test and making that the standard, so that
14we effectively can pass in any binary we feel like. It's also possible to pass
15arguments to the test, provided that the arguments do not contain dashes (these
16can be "escaped" by passing + instead, so -a becomes +a, and --my-option becomes
17++my_option).
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +000018'''
19
20import optparse
21import sys
22
23import logging_utils
24
25import chrome_tests
26
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +000027def _main(_):
28 parser = optparse.OptionParser("usage: %prog -b <dir> -t <test> "
turaj@webrtc.org799980f2012-05-11 00:41:48 +000029 "[-t <test> ...] <arguments to all tests>"
30 "NOTE: when passing arguments to all tests, "
31 " replace any - with +.")
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +000032 parser.add_option("-b", "--build_dir",
33 help="the location of the compiler output")
34 parser.add_option("-t", "--test", action="append", default=[],
35 help="which test to run, supports test:gtest_filter format "
36 "as well.")
37 parser.add_option("", "--baseline", action="store_true", default=False,
38 help="generate baseline data instead of validating")
39 parser.add_option("", "--gtest_filter",
40 help="additional arguments to --gtest_filter")
41 parser.add_option("", "--gtest_repeat",
42 help="argument for --gtest_repeat")
43 parser.add_option("-v", "--verbose", action="store_true", default=False,
44 help="verbose output - enable debug log messages")
45 parser.add_option("", "--tool", dest="valgrind_tool", default="memcheck",
46 help="specify a valgrind tool to run the tests under")
47 parser.add_option("", "--tool_flags", dest="valgrind_tool_flags", default="",
48 help="specify custom flags for the selected valgrind tool")
49 parser.add_option("", "--keep_logs", action="store_true", default=False,
50 help="store memory tool logs in the <tool>.logs directory "
51 "instead of /tmp.\nThis can be useful for tool "
52 "developers/maintainers.\nPlease note that the <tool>"
53 ".logs directory will be clobbered on tool startup.")
54 options, args = parser.parse_args()
55
56 if options.verbose:
57 logging_utils.config_root(logging.DEBUG)
58 else:
59 logging_utils.config_root()
60
61 if not options.test:
62 parser.error("--test not specified")
63
64 if len(options.test) != 1 and options.gtest_filter:
65 parser.error("--gtest_filter and multiple tests don't make sense together")
66
turaj@webrtc.org799980f2012-05-11 00:41:48 +000067 # Performs the deferred-argument black magic described in the usage.
68 translated_args = map(lambda arg: arg.replace('+', '-'), args)
69
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +000070 for t in options.test:
turaj@webrtc.org799980f2012-05-11 00:41:48 +000071 tests = chrome_tests.ChromeTests(options, translated_args, t)
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +000072 ret = tests.Run()
73 if ret: return ret
74 return 0
75
76if __name__ == "__main__":
turaj@webrtc.org799980f2012-05-11 00:41:48 +000077 # Overwrite the ChromeTests tests dictionary. The cmdline option allows the
78 # user to pass any executable as parameter to the test script, so we'll use
79 # that to get our binaries in (hackish but convenient).
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +000080 chrome_tests.ChromeTests._test_list = {
81 "cmdline": chrome_tests.ChromeTests.RunCmdLine,
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +000082 }
turaj@webrtc.org799980f2012-05-11 00:41:48 +000083
84 # We do this so the user can write -t <binary> instead of -t cmdline <binary>.
85 sys.argv.insert(sys.argv.index('-t') + 1, 'cmdline')
86 print sys.argv
kjellander@webrtc.orgb5b155b2011-12-20 08:53:41 +000087 ret = _main(sys.argv)
turaj@webrtc.org799980f2012-05-11 00:41:48 +000088 sys.exit(ret)