media/webrtc/trunk/build/android/pylib/test_options_parser.py

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/media/webrtc/trunk/build/android/pylib/test_options_parser.py	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,143 @@
     1.4 +# Copyright (c) 2012 The Chromium Authors. All rights reserved.
     1.5 +# Use of this source code is governed by a BSD-style license that can be
     1.6 +# found in the LICENSE file.
     1.7 +
     1.8 +"""Parses options for the instrumentation tests."""
     1.9 +
    1.10 +import constants
    1.11 +import optparse
    1.12 +import os
    1.13 +import sys
    1.14 +
    1.15 +_SDK_OUT_DIR = os.path.join(constants.CHROME_DIR, 'out')
    1.16 +
    1.17 +
    1.18 +def AddBuildTypeOption(option_parser):
    1.19 +  """Decorates OptionParser with build type option."""
    1.20 +  default_build_type = 'Debug'
    1.21 +  if 'BUILDTYPE' in os.environ:
    1.22 +    default_build_type = os.environ['BUILDTYPE']
    1.23 +  option_parser.add_option('--debug', action='store_const', const='Debug',
    1.24 +                           dest='build_type', default=default_build_type,
    1.25 +                           help='If set, run test suites under out/Debug. '
    1.26 +                                'Default is env var BUILDTYPE or Debug')
    1.27 +  option_parser.add_option('--release', action='store_const', const='Release',
    1.28 +                           dest='build_type',
    1.29 +                           help='If set, run test suites under out/Release. '
    1.30 +                                'Default is env var BUILDTYPE or Debug.')
    1.31 +
    1.32 +def AddInstallAPKOption(option_parser):
    1.33 +  """Decorates OptionParser with apk option used to install the APK."""
    1.34 +  option_parser.add_option('--apk',
    1.35 +                           help=('The name of the apk containing the '
    1.36 +                                 ' application (with the .apk extension).'))
    1.37 +  option_parser.add_option('--apk_package',
    1.38 +                           help=('The package name used by the apk containing '
    1.39 +                                 'the application.'))
    1.40 +
    1.41 +def AddTestRunnerOptions(option_parser, default_timeout=60):
    1.42 +  """Decorates OptionParser with options applicable to all tests."""
    1.43 +
    1.44 +  option_parser.add_option('-t', dest='timeout',
    1.45 +                           help='Timeout to wait for each test',
    1.46 +                           type='int',
    1.47 +                           default=default_timeout)
    1.48 +  option_parser.add_option('-c', dest='cleanup_test_files',
    1.49 +                           help='Cleanup test files on the device after run',
    1.50 +                           action='store_true')
    1.51 +  option_parser.add_option('-v',
    1.52 +                           '--verbose',
    1.53 +                           dest='verbose_count',
    1.54 +                           default=0,
    1.55 +                           action='count',
    1.56 +                           help='Verbose level (multiple times for more)')
    1.57 +  profilers = ['devicestatsmonitor', 'chrometrace', 'dumpheap', 'smaps',
    1.58 +               'traceview']
    1.59 +  option_parser.add_option('--profiler', dest='profilers', action='append',
    1.60 +                           choices=profilers,
    1.61 +                           help='Profiling tool to run during test. '
    1.62 +                           'Pass multiple times to run multiple profilers. '
    1.63 +                           'Available profilers: %s' % profilers)
    1.64 +  option_parser.add_option('--tool',
    1.65 +                           dest='tool',
    1.66 +                           help='Run the test under a tool '
    1.67 +                           '(use --tool help to list them)')
    1.68 +  AddBuildTypeOption(option_parser)
    1.69 +
    1.70 +
    1.71 +def AddInstrumentationOptions(option_parser):
    1.72 +  """Decorates OptionParser with instrumentation tests options."""
    1.73 +
    1.74 +  AddTestRunnerOptions(option_parser)
    1.75 +  option_parser.add_option('-w', '--wait_debugger', dest='wait_for_debugger',
    1.76 +                           action='store_true', help='Wait for debugger.')
    1.77 +  option_parser.add_option('-I', dest='install_apk', help='Install APK.',
    1.78 +                           action='store_true')
    1.79 +  option_parser.add_option('-f', '--test_filter',
    1.80 +                           help='Test filter (if not fully qualified, '
    1.81 +                           'will run all matches).')
    1.82 +  option_parser.add_option('-A', '--annotation', dest='annotation_str',
    1.83 +                           help=('Run only tests with any of the given '
    1.84 +                                 'annotations. '
    1.85 +                                 'An annotation can be either a key or a '
    1.86 +                                 'key-values pair. '
    1.87 +                                 'A test that has no annotation is '
    1.88 +                                 'considered "SmallTest".'))
    1.89 +  option_parser.add_option('-j', '--java_only', action='store_true',
    1.90 +                           help='Run only the Java tests.')
    1.91 +  option_parser.add_option('-p', '--python_only', action='store_true',
    1.92 +                           help='Run only the Python tests.')
    1.93 +  option_parser.add_option('-n', '--run_count', type='int',
    1.94 +                           dest='number_of_runs', default=1,
    1.95 +                           help=('How many times to run each test, regardless '
    1.96 +                                 'of the result. (Default is 1)'))
    1.97 +  option_parser.add_option('--test-apk', dest='test_apk',
    1.98 +                           help=('The name of the apk containing the tests '
    1.99 +                                 '(without the .apk extension). For SDK '
   1.100 +                                 'builds, the apk name without the debug '
   1.101 +                                 'suffix(for example, ContentShellTest).'))
   1.102 +  option_parser.add_option('--screenshot', dest='screenshot_failures',
   1.103 +                           action='store_true',
   1.104 +                           help='Capture screenshots of test failures')
   1.105 +  option_parser.add_option('--save-perf-json', action='store_true',
   1.106 +                           help='Saves the JSON file for each UI Perf test.')
   1.107 +  option_parser.add_option('--shard_retries', type=int, default=1,
   1.108 +                           help=('Number of times to retry each failure when '
   1.109 +                                 'sharding.'))
   1.110 +  option_parser.add_option('--official-build', help='Run official build tests.')
   1.111 +  option_parser.add_option('--device',
   1.112 +                           help='Serial number of device we should use.')
   1.113 +  option_parser.add_option('--python_test_root',
   1.114 +                           help='Root of the python-driven tests.')
   1.115 +
   1.116 +def ValidateInstrumentationOptions(option_parser, options, args):
   1.117 +  """Validate options/arguments and populate options with defaults."""
   1.118 +  if len(args) > 1:
   1.119 +    option_parser.print_help(sys.stderr)
   1.120 +    option_parser.error('Unknown arguments: %s' % args[1:])
   1.121 +  if options.java_only and options.python_only:
   1.122 +    option_parser.error('Options java_only (-j) and python_only (-p) '
   1.123 +                        'are mutually exclusive.')
   1.124 +
   1.125 +  options.run_java_tests = True
   1.126 +  options.run_python_tests = True
   1.127 +  if options.java_only:
   1.128 +    options.run_python_tests = False
   1.129 +  elif options.python_only:
   1.130 +    options.run_java_tests = False
   1.131 +
   1.132 +  # In case of SDK Build, the jars and apks have a -debug suffix.
   1.133 +  options.test_apk_path = os.path.join(_SDK_OUT_DIR,
   1.134 +                                       options.build_type,
   1.135 +                                       constants.SDK_BUILD_APKS_DIR,
   1.136 +                                       '%s-debug.apk' % options.test_apk)
   1.137 +  options.test_apk_jar_path = os.path.join(_SDK_OUT_DIR,
   1.138 +                                           options.build_type,
   1.139 +                                           constants.SDK_BUILD_TEST_JAVALIB_DIR,
   1.140 +                                           '%s-debug.jar' % options.test_apk)
   1.141 +  if options.annotation_str:
   1.142 +    options.annotation = options.annotation_str.split()
   1.143 +  elif options.test_filter:
   1.144 +    options.annotation = []
   1.145 +  else:
   1.146 +    options.annotation = ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest']

mercurial