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.

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

mercurial