media/libyuv/tools/valgrind-libyuv/libyuv_tests.py

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rwxr-xr-x

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 #!/usr/bin/env python
michael@0 2 # Copyright (c) 2012 The LibYuv Project Authors. All rights reserved.
michael@0 3 #
michael@0 4 # Use of this source code is governed by a BSD-style license
michael@0 5 # that can be found in the LICENSE file in the root of the source
michael@0 6 # tree. An additional intellectual property rights grant can be found
michael@0 7 # in the file PATENTS. All contributing project authors may
michael@0 8 # be found in the AUTHORS file in the root of the source tree.
michael@0 9
michael@0 10 """Runs various libyuv tests through valgrind_test.py.
michael@0 11
michael@0 12 This script inherits the chrome_tests.py in Chrome, but allows running any test
michael@0 13 instead of only the hard-coded ones. It uses the -t cmdline flag to do this, and
michael@0 14 only supports specifying a single test for each run.
michael@0 15
michael@0 16 Suppression files:
michael@0 17 The Chrome valgrind directory we use as a DEPS dependency contains the following
michael@0 18 suppression files:
michael@0 19 valgrind/memcheck/suppressions.txt
michael@0 20 valgrind/memcheck/suppressions_mac.txt
michael@0 21 valgrind/tsan/suppressions.txt
michael@0 22 valgrind/tsan/suppressions_mac.txt
michael@0 23 valgrind/tsan/suppressions_win32.txt
michael@0 24 Since they're referenced from the chrome_tests.py script, we have similar files
michael@0 25 below the directory of this script. When executing, this script will setup both
michael@0 26 Chrome's suppression files and our own, so we can easily maintain libyuv
michael@0 27 specific suppressions in our own files.
michael@0 28 """
michael@0 29
michael@0 30 import logging
michael@0 31 import optparse
michael@0 32 import os
michael@0 33 import sys
michael@0 34
michael@0 35 import logging_utils
michael@0 36 import path_utils
michael@0 37
michael@0 38 import chrome_tests
michael@0 39
michael@0 40
michael@0 41 class LibyuvTest(chrome_tests.ChromeTests):
michael@0 42 """Class that handles setup of suppressions for libyuv.
michael@0 43
michael@0 44 Everything else is inherited from chrome_tests.ChromeTests.
michael@0 45 """
michael@0 46
michael@0 47 def _DefaultCommand(self, tool, exe=None, valgrind_test_args=None):
michael@0 48 """Override command-building method so we can add more suppressions."""
michael@0 49 cmd = chrome_tests.ChromeTests._DefaultCommand(self, tool, exe,
michael@0 50 valgrind_test_args)
michael@0 51 # When ChromeTests._DefaultCommand has executed, it has setup suppression
michael@0 52 # files based on what's found in the memcheck/ or tsan/ subdirectories of
michael@0 53 # this script's location. If Mac or Windows is executing, additional
michael@0 54 # platform specific files have also been added.
michael@0 55 # Since only the ones located below this directory is added, we must also
michael@0 56 # add the ones maintained by Chrome, located in ../valgrind.
michael@0 57
michael@0 58 # The idea is to look for --suppression arguments in the cmd list and add a
michael@0 59 # modified copy of each suppression file, for the corresponding file in
michael@0 60 # ../valgrind. If we would simply replace 'valgrind-libyuv' with 'valgrind'
michael@0 61 # we may produce invalid paths if other parts of the path contain that
michael@0 62 # string. That's why the code below only replaces the end of the path.
michael@0 63 script_dir = path_utils.ScriptDir()
michael@0 64 old_base, _ = os.path.split(script_dir)
michael@0 65 new_dir = os.path.join(old_base, 'valgrind')
michael@0 66 add_suppressions = []
michael@0 67 for token in cmd:
michael@0 68 if '--suppressions' in token:
michael@0 69 add_suppressions.append(token.replace(script_dir, new_dir))
michael@0 70 return add_suppressions + cmd
michael@0 71
michael@0 72
michael@0 73 def main(_):
michael@0 74 parser = optparse.OptionParser('usage: %prog -b <dir> -t <test> <test args>')
michael@0 75 parser.disable_interspersed_args()
michael@0 76 parser.add_option('-b', '--build-dir',
michael@0 77 help=('Location of the compiler output. Can only be used '
michael@0 78 'when the test argument does not contain this path.'))
michael@0 79 parser.add_option("--target", help="Debug or Release")
michael@0 80 parser.add_option('-t', '--test', help='Test to run.')
michael@0 81 parser.add_option('', '--baseline', action='store_true', default=False,
michael@0 82 help='Generate baseline data instead of validating')
michael@0 83 parser.add_option('', '--gtest_filter',
michael@0 84 help='Additional arguments to --gtest_filter')
michael@0 85 parser.add_option('', '--gtest_repeat',
michael@0 86 help='Argument for --gtest_repeat')
michael@0 87 parser.add_option('-v', '--verbose', action='store_true', default=False,
michael@0 88 help='Verbose output - enable debug log messages')
michael@0 89 parser.add_option('', '--tool', dest='valgrind_tool', default='memcheck',
michael@0 90 help='Specify a valgrind tool to run the tests under')
michael@0 91 parser.add_option('', '--tool_flags', dest='valgrind_tool_flags', default='',
michael@0 92 help='Specify custom flags for the selected valgrind tool')
michael@0 93 parser.add_option('', '--keep_logs', action='store_true', default=False,
michael@0 94 help=('Store memory tool logs in the <tool>.logs directory '
michael@0 95 'instead of /tmp.\nThis can be useful for tool '
michael@0 96 'developers/maintainers.\nPlease note that the <tool>'
michael@0 97 '.logs directory will be clobbered on tool startup.'))
michael@0 98 options, args = parser.parse_args()
michael@0 99
michael@0 100 if options.verbose:
michael@0 101 logging_utils.config_root(logging.DEBUG)
michael@0 102 else:
michael@0 103 logging_utils.config_root()
michael@0 104
michael@0 105 if not options.test:
michael@0 106 parser.error('--test not specified')
michael@0 107
michael@0 108 # Support build dir both with and without the target.
michael@0 109 if (options.target and options.build_dir and
michael@0 110 not options.build_dir.endswith(options.target)):
michael@0 111 options.build_dir = os.path.join(options.build_dir, options.target)
michael@0 112
michael@0 113 # If --build_dir is provided, prepend it to the test executable if needed.
michael@0 114 test_executable = options.test
michael@0 115 if options.build_dir and not test_executable.startswith(options.build_dir):
michael@0 116 test_executable = os.path.join(options.build_dir, test_executable)
michael@0 117 args = [test_executable] + args
michael@0 118
michael@0 119 test = LibyuvTest(options, args, 'cmdline')
michael@0 120 return test.Run()
michael@0 121
michael@0 122 if __name__ == '__main__':
michael@0 123 return_code = main(sys.argv)
michael@0 124 sys.exit(return_code)

mercurial