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 | |
turaj@webrtc.org | 799980f | 2012-05-11 00:41:48 +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 | |
turaj@webrtc.org | 799980f | 2012-05-11 00:41:48 +0000 | [diff] [blame] | 12 | This script inherits the chrome_tests.py in Chrome, replacing its tests. We do |
| 13 | this by taking chrome's faux cmdline test and making that the standard, so that |
| 14 | we effectively can pass in any binary we feel like. It's also possible to pass |
| 15 | arguments to the test, provided that the arguments do not contain dashes (these |
| 16 | can be "escaped" by passing + instead, so -a becomes +a, and --my-option becomes |
| 17 | ++my_option). |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 18 | ''' |
| 19 | |
| 20 | import optparse |
| 21 | import sys |
| 22 | |
| 23 | import logging_utils |
| 24 | |
| 25 | import chrome_tests |
| 26 | |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 27 | def _main(_): |
| 28 | parser = optparse.OptionParser("usage: %prog -b <dir> -t <test> " |
turaj@webrtc.org | 799980f | 2012-05-11 00:41:48 +0000 | [diff] [blame] | 29 | "[-t <test> ...] <arguments to all tests>" |
| 30 | "NOTE: when passing arguments to all tests, " |
| 31 | " replace any - with +.") |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 32 | 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.org | 799980f | 2012-05-11 00:41:48 +0000 | [diff] [blame] | 67 | # Performs the deferred-argument black magic described in the usage. |
| 68 | translated_args = map(lambda arg: arg.replace('+', '-'), args) |
| 69 | |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 70 | for t in options.test: |
turaj@webrtc.org | 799980f | 2012-05-11 00:41:48 +0000 | [diff] [blame] | 71 | tests = chrome_tests.ChromeTests(options, translated_args, t) |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 72 | ret = tests.Run() |
| 73 | if ret: return ret |
| 74 | return 0 |
| 75 | |
| 76 | if __name__ == "__main__": |
turaj@webrtc.org | 799980f | 2012-05-11 00:41:48 +0000 | [diff] [blame] | 77 | # 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.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 80 | chrome_tests.ChromeTests._test_list = { |
| 81 | "cmdline": chrome_tests.ChromeTests.RunCmdLine, |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 82 | } |
turaj@webrtc.org | 799980f | 2012-05-11 00:41:48 +0000 | [diff] [blame] | 83 | |
| 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.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 87 | ret = _main(sys.argv) |
turaj@webrtc.org | 799980f | 2012-05-11 00:41:48 +0000 | [diff] [blame] | 88 | sys.exit(ret) |