libyuv_tests.py 6.3 KB

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