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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/libyuv/tools/valgrind-libyuv/libyuv_tests.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,124 @@
     1.4 +#!/usr/bin/env python
     1.5 +# Copyright (c) 2012 The LibYuv Project Authors. All rights reserved.
     1.6 +#
     1.7 +# Use of this source code is governed by a BSD-style license
     1.8 +# that can be found in the LICENSE file in the root of the source
     1.9 +# tree. An additional intellectual property rights grant can be found
    1.10 +# in the file PATENTS.  All contributing project authors may
    1.11 +# be found in the AUTHORS file in the root of the source tree.
    1.12 +
    1.13 +"""Runs various libyuv tests through valgrind_test.py.
    1.14 +
    1.15 +This script inherits the chrome_tests.py in Chrome, but allows running any test
    1.16 +instead of only the hard-coded ones. It uses the -t cmdline flag to do this, and
    1.17 +only supports specifying a single test for each run.
    1.18 +
    1.19 +Suppression files:
    1.20 +The Chrome valgrind directory we use as a DEPS dependency contains the following
    1.21 +suppression files:
    1.22 +  valgrind/memcheck/suppressions.txt
    1.23 +  valgrind/memcheck/suppressions_mac.txt
    1.24 +  valgrind/tsan/suppressions.txt
    1.25 +  valgrind/tsan/suppressions_mac.txt
    1.26 +  valgrind/tsan/suppressions_win32.txt
    1.27 +Since they're referenced from the chrome_tests.py script, we have similar files
    1.28 +below the directory of this script. When executing, this script will setup both
    1.29 +Chrome's suppression files and our own, so we can easily maintain libyuv
    1.30 +specific suppressions in our own files.
    1.31 +"""
    1.32 +
    1.33 +import logging
    1.34 +import optparse
    1.35 +import os
    1.36 +import sys
    1.37 +
    1.38 +import logging_utils
    1.39 +import path_utils
    1.40 +
    1.41 +import chrome_tests
    1.42 +
    1.43 +
    1.44 +class LibyuvTest(chrome_tests.ChromeTests):
    1.45 +  """Class that handles setup of suppressions for libyuv.
    1.46 +
    1.47 +  Everything else is inherited from chrome_tests.ChromeTests.
    1.48 +  """
    1.49 +
    1.50 +  def _DefaultCommand(self, tool, exe=None, valgrind_test_args=None):
    1.51 +    """Override command-building method so we can add more suppressions."""
    1.52 +    cmd = chrome_tests.ChromeTests._DefaultCommand(self, tool, exe,
    1.53 +                                                   valgrind_test_args)
    1.54 +    # When ChromeTests._DefaultCommand has executed, it has setup suppression
    1.55 +    # files based on what's found in the memcheck/ or tsan/ subdirectories of
    1.56 +    # this script's location. If Mac or Windows is executing, additional
    1.57 +    # platform specific files have also been added.
    1.58 +    # Since only the ones located below this directory is added, we must also
    1.59 +    # add the ones maintained by Chrome, located in ../valgrind.
    1.60 +
    1.61 +    # The idea is to look for --suppression arguments in the cmd list and add a
    1.62 +    # modified copy of each suppression file, for the corresponding file in
    1.63 +    # ../valgrind. If we would simply replace 'valgrind-libyuv' with 'valgrind'
    1.64 +    # we may produce invalid paths if other parts of the path contain that
    1.65 +    # string. That's why the code below only replaces the end of the path.
    1.66 +    script_dir = path_utils.ScriptDir()
    1.67 +    old_base, _ = os.path.split(script_dir)
    1.68 +    new_dir = os.path.join(old_base, 'valgrind')
    1.69 +    add_suppressions = []
    1.70 +    for token in cmd:
    1.71 +      if '--suppressions' in token:
    1.72 +        add_suppressions.append(token.replace(script_dir, new_dir))
    1.73 +    return add_suppressions + cmd
    1.74 +
    1.75 +
    1.76 +def main(_):
    1.77 +  parser = optparse.OptionParser('usage: %prog -b <dir> -t <test> <test args>')
    1.78 +  parser.disable_interspersed_args()
    1.79 +  parser.add_option('-b', '--build-dir',
    1.80 +                    help=('Location of the compiler output. Can only be used '
    1.81 +                          'when the test argument does not contain this path.'))
    1.82 +  parser.add_option("--target", help="Debug or Release")
    1.83 +  parser.add_option('-t', '--test', help='Test to run.')
    1.84 +  parser.add_option('', '--baseline', action='store_true', default=False,
    1.85 +                    help='Generate baseline data instead of validating')
    1.86 +  parser.add_option('', '--gtest_filter',
    1.87 +                    help='Additional arguments to --gtest_filter')
    1.88 +  parser.add_option('', '--gtest_repeat',
    1.89 +                    help='Argument for --gtest_repeat')
    1.90 +  parser.add_option('-v', '--verbose', action='store_true', default=False,
    1.91 +                    help='Verbose output - enable debug log messages')
    1.92 +  parser.add_option('', '--tool', dest='valgrind_tool', default='memcheck',
    1.93 +                    help='Specify a valgrind tool to run the tests under')
    1.94 +  parser.add_option('', '--tool_flags', dest='valgrind_tool_flags', default='',
    1.95 +                    help='Specify custom flags for the selected valgrind tool')
    1.96 +  parser.add_option('', '--keep_logs', action='store_true', default=False,
    1.97 +                    help=('Store memory tool logs in the <tool>.logs directory '
    1.98 +                          'instead of /tmp.\nThis can be useful for tool '
    1.99 +                          'developers/maintainers.\nPlease note that the <tool>'
   1.100 +                          '.logs directory will be clobbered on tool startup.'))
   1.101 +  options, args = parser.parse_args()
   1.102 +
   1.103 +  if options.verbose:
   1.104 +    logging_utils.config_root(logging.DEBUG)
   1.105 +  else:
   1.106 +    logging_utils.config_root()
   1.107 +
   1.108 +  if not options.test:
   1.109 +    parser.error('--test not specified')
   1.110 +
   1.111 +  # Support build dir both with and without the target.
   1.112 +  if (options.target and options.build_dir and
   1.113 +      not options.build_dir.endswith(options.target)):
   1.114 +    options.build_dir = os.path.join(options.build_dir, options.target)
   1.115 +
   1.116 +  # If --build_dir is provided, prepend it to the test executable if needed.
   1.117 +  test_executable = options.test
   1.118 +  if options.build_dir and not test_executable.startswith(options.build_dir):
   1.119 +    test_executable = os.path.join(options.build_dir, test_executable)
   1.120 +  args = [test_executable] + args
   1.121 +
   1.122 +  test = LibyuvTest(options, args, 'cmdline')
   1.123 +  return test.Run()
   1.124 +
   1.125 +if __name__ == '__main__':
   1.126 +  return_code = main(sys.argv)
   1.127 +  sys.exit(return_code)

mercurial