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 | b6e4cc7 | 2012-05-27 20:59:35 +0000 | [diff] [blame] | 18 | |
| 19 | Suppression files: |
| 20 | The Chrome valgrind directory we use as a DEPS dependency contains the following |
| 21 | suppression files: |
| 22 | valgrind/memcheck/suppressions.txt |
| 23 | valgrind/memcheck/suppressions_mac.txt |
| 24 | valgrind/tsan/suppressions.txt |
| 25 | valgrind/tsan/suppressions_mac.txt |
| 26 | valgrind/tsan/suppressions_win32.txt |
| 27 | Since they're referenced from the chrome_tests.py script, we have similar files |
| 28 | below the directory of this script. When executing, this script will setup both |
| 29 | Chrome's suppression files and our own, so we can easily maintain WebRTC |
| 30 | specific suppressions in our own files. |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 31 | ''' |
| 32 | |
| 33 | import optparse |
kjellander@webrtc.org | b6e4cc7 | 2012-05-27 20:59:35 +0000 | [diff] [blame] | 34 | import os |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 35 | import sys |
| 36 | |
| 37 | import logging_utils |
kjellander@webrtc.org | b6e4cc7 | 2012-05-27 20:59:35 +0000 | [diff] [blame] | 38 | import path_utils |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 39 | |
| 40 | import chrome_tests |
| 41 | |
kjellander@webrtc.org | b6e4cc7 | 2012-05-27 20:59:35 +0000 | [diff] [blame] | 42 | class WebRTCTests(chrome_tests.ChromeTests): |
| 43 | """Class that handles setup of suppressions for WebRTC. |
| 44 | |
| 45 | Everything else is inherited from chrome_tests.ChromeTests. |
| 46 | """ |
| 47 | |
| 48 | def _DefaultCommand(self, tool, exe=None, valgrind_test_args=None): |
| 49 | """Override command-building method so we can add more suppressions.""" |
| 50 | cmd = chrome_tests.ChromeTests._DefaultCommand(self, tool, exe, |
| 51 | valgrind_test_args) |
| 52 | # When ChromeTests._DefaultCommand has executed, it has setup suppression |
| 53 | # files based on what's found in the memcheck/ or tsan/ subdirectories of |
| 54 | # this script's location. If Mac or Windows is executing, additional |
| 55 | # platform specific files have also been added. |
| 56 | # Since only the ones located below this directory is added, we must also |
| 57 | # add the ones maintained by Chrome, located in ../valgrind. |
| 58 | |
| 59 | # The idea is to look for --suppression arguments in the cmd list and add a |
| 60 | # modified copy of each suppression file, for the corresponding file in |
| 61 | # ../valgrind. If we would simply replace 'valgrind-webrtc' with 'valgrind' |
| 62 | # we may produce invalid paths if other parts of the path contain that |
| 63 | # string. That's why the code below only replaces the end of the path. |
| 64 | old_base, old_dir = _split_script_path() |
| 65 | new_dir = old_base + 'valgrind' |
| 66 | add_suppressions = [] |
| 67 | for token in cmd: |
| 68 | if '--suppressions' in token: |
| 69 | add_suppressions.append(token.replace(old_base + old_dir, new_dir)) |
| 70 | return add_suppressions + cmd |
| 71 | |
| 72 | |
| 73 | def _split_script_path(): |
| 74 | """Splits the script's path into a tuple separating the last directory. |
| 75 | |
| 76 | Returns a tuple where the first item is the whole path except the last |
| 77 | directory and the second item is the name of the last directory. |
| 78 | """ |
| 79 | script_dir = path_utils.ScriptDir() |
| 80 | last_sep_index = script_dir.rfind(os.sep) |
| 81 | return script_dir[0:last_sep_index+1], script_dir[last_sep_index+1:] |
| 82 | |
| 83 | |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 84 | def _main(_): |
| 85 | parser = optparse.OptionParser("usage: %prog -b <dir> -t <test> " |
turaj@webrtc.org | 799980f | 2012-05-11 00:41:48 +0000 | [diff] [blame] | 86 | "[-t <test> ...] <arguments to all tests>" |
| 87 | "NOTE: when passing arguments to all tests, " |
| 88 | " replace any - with +.") |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 89 | parser.add_option("-b", "--build_dir", |
| 90 | help="the location of the compiler output") |
| 91 | parser.add_option("-t", "--test", action="append", default=[], |
| 92 | help="which test to run, supports test:gtest_filter format " |
| 93 | "as well.") |
| 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") |
| 100 | parser.add_option("-v", "--verbose", action="store_true", default=False, |
| 101 | help="verbose output - enable debug log messages") |
| 102 | parser.add_option("", "--tool", dest="valgrind_tool", default="memcheck", |
| 103 | help="specify a valgrind tool to run the tests under") |
| 104 | parser.add_option("", "--tool_flags", dest="valgrind_tool_flags", default="", |
| 105 | help="specify custom flags for the selected valgrind tool") |
| 106 | parser.add_option("", "--keep_logs", action="store_true", default=False, |
| 107 | help="store memory tool logs in the <tool>.logs directory " |
| 108 | "instead of /tmp.\nThis can be useful for tool " |
| 109 | "developers/maintainers.\nPlease note that the <tool>" |
| 110 | ".logs directory will be clobbered on tool startup.") |
| 111 | options, args = parser.parse_args() |
| 112 | |
| 113 | if options.verbose: |
| 114 | logging_utils.config_root(logging.DEBUG) |
| 115 | else: |
| 116 | logging_utils.config_root() |
| 117 | |
| 118 | if not options.test: |
| 119 | parser.error("--test not specified") |
| 120 | |
| 121 | if len(options.test) != 1 and options.gtest_filter: |
| 122 | parser.error("--gtest_filter and multiple tests don't make sense together") |
| 123 | |
kjellander@webrtc.org | b43f85f | 2012-09-11 11:22:45 +0000 | [diff] [blame] | 124 | # If --build_dir is provided, prepend that path to the test name to make it a |
| 125 | # valid path when running on the build slaves using Chromium's runtest.py |
kjellander@webrtc.org | 0f4185f | 2012-11-15 15:19:28 +0000 | [diff] [blame] | 126 | if options.build_dir and 'cmdline' in options.test: |
kjellander@webrtc.org | b43f85f | 2012-09-11 11:22:45 +0000 | [diff] [blame] | 127 | args[0] = os.path.join(options.build_dir, args[0]) |
| 128 | |
turaj@webrtc.org | 799980f | 2012-05-11 00:41:48 +0000 | [diff] [blame] | 129 | # Performs the deferred-argument black magic described in the usage. |
| 130 | translated_args = map(lambda arg: arg.replace('+', '-'), args) |
| 131 | |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 132 | for t in options.test: |
kjellander@webrtc.org | b6e4cc7 | 2012-05-27 20:59:35 +0000 | [diff] [blame] | 133 | tests = WebRTCTests(options, translated_args, t) |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 134 | ret = tests.Run() |
| 135 | if ret: return ret |
| 136 | return 0 |
| 137 | |
| 138 | if __name__ == "__main__": |
turaj@webrtc.org | 799980f | 2012-05-11 00:41:48 +0000 | [diff] [blame] | 139 | # Overwrite the ChromeTests tests dictionary. The cmdline option allows the |
| 140 | # user to pass any executable as parameter to the test script, so we'll use |
| 141 | # that to get our binaries in (hackish but convenient). |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 142 | chrome_tests.ChromeTests._test_list = { |
| 143 | "cmdline": chrome_tests.ChromeTests.RunCmdLine, |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 144 | } |
turaj@webrtc.org | 799980f | 2012-05-11 00:41:48 +0000 | [diff] [blame] | 145 | |
| 146 | # We do this so the user can write -t <binary> instead of -t cmdline <binary>. |
kjellander@webrtc.org | b764d78 | 2012-09-11 09:34:51 +0000 | [diff] [blame] | 147 | if '-t' in sys.argv: |
| 148 | sys.argv.insert(sys.argv.index('-t') + 1, 'cmdline') |
| 149 | elif '--test' in sys.argv: |
| 150 | sys.argv.insert(sys.argv.index('--test') + 1, 'cmdline') |
| 151 | |
turaj@webrtc.org | 799980f | 2012-05-11 00:41:48 +0000 | [diff] [blame] | 152 | print sys.argv |
kjellander@webrtc.org | b5b155b | 2011-12-20 08:53:41 +0000 | [diff] [blame] | 153 | ret = _main(sys.argv) |
kjellander@webrtc.org | b6e4cc7 | 2012-05-27 20:59:35 +0000 | [diff] [blame] | 154 | sys.exit(ret) |