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

Wed, 31 Dec 2014 13:27:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 13:27:57 +0100
branch
TOR_BUG_3246
changeset 6
8bccb770b82d
permissions
-rw-r--r--

Ignore runtime configuration files generated during quality assurance.

michael@0 1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
michael@0 2 # Use of this source code is governed by a BSD-style license that can be
michael@0 3 # found in the LICENSE file.
michael@0 4
michael@0 5 """Parses options for the instrumentation tests."""
michael@0 6
michael@0 7 import constants
michael@0 8 import optparse
michael@0 9 import os
michael@0 10 import sys
michael@0 11
michael@0 12 _SDK_OUT_DIR = os.path.join(constants.CHROME_DIR, 'out')
michael@0 13
michael@0 14
michael@0 15 def AddBuildTypeOption(option_parser):
michael@0 16 """Decorates OptionParser with build type option."""
michael@0 17 default_build_type = 'Debug'
michael@0 18 if 'BUILDTYPE' in os.environ:
michael@0 19 default_build_type = os.environ['BUILDTYPE']
michael@0 20 option_parser.add_option('--debug', action='store_const', const='Debug',
michael@0 21 dest='build_type', default=default_build_type,
michael@0 22 help='If set, run test suites under out/Debug. '
michael@0 23 'Default is env var BUILDTYPE or Debug')
michael@0 24 option_parser.add_option('--release', action='store_const', const='Release',
michael@0 25 dest='build_type',
michael@0 26 help='If set, run test suites under out/Release. '
michael@0 27 'Default is env var BUILDTYPE or Debug.')
michael@0 28
michael@0 29 def AddInstallAPKOption(option_parser):
michael@0 30 """Decorates OptionParser with apk option used to install the APK."""
michael@0 31 option_parser.add_option('--apk',
michael@0 32 help=('The name of the apk containing the '
michael@0 33 ' application (with the .apk extension).'))
michael@0 34 option_parser.add_option('--apk_package',
michael@0 35 help=('The package name used by the apk containing '
michael@0 36 'the application.'))
michael@0 37
michael@0 38 def AddTestRunnerOptions(option_parser, default_timeout=60):
michael@0 39 """Decorates OptionParser with options applicable to all tests."""
michael@0 40
michael@0 41 option_parser.add_option('-t', dest='timeout',
michael@0 42 help='Timeout to wait for each test',
michael@0 43 type='int',
michael@0 44 default=default_timeout)
michael@0 45 option_parser.add_option('-c', dest='cleanup_test_files',
michael@0 46 help='Cleanup test files on the device after run',
michael@0 47 action='store_true')
michael@0 48 option_parser.add_option('-v',
michael@0 49 '--verbose',
michael@0 50 dest='verbose_count',
michael@0 51 default=0,
michael@0 52 action='count',
michael@0 53 help='Verbose level (multiple times for more)')
michael@0 54 profilers = ['devicestatsmonitor', 'chrometrace', 'dumpheap', 'smaps',
michael@0 55 'traceview']
michael@0 56 option_parser.add_option('--profiler', dest='profilers', action='append',
michael@0 57 choices=profilers,
michael@0 58 help='Profiling tool to run during test. '
michael@0 59 'Pass multiple times to run multiple profilers. '
michael@0 60 'Available profilers: %s' % profilers)
michael@0 61 option_parser.add_option('--tool',
michael@0 62 dest='tool',
michael@0 63 help='Run the test under a tool '
michael@0 64 '(use --tool help to list them)')
michael@0 65 AddBuildTypeOption(option_parser)
michael@0 66
michael@0 67
michael@0 68 def AddInstrumentationOptions(option_parser):
michael@0 69 """Decorates OptionParser with instrumentation tests options."""
michael@0 70
michael@0 71 AddTestRunnerOptions(option_parser)
michael@0 72 option_parser.add_option('-w', '--wait_debugger', dest='wait_for_debugger',
michael@0 73 action='store_true', help='Wait for debugger.')
michael@0 74 option_parser.add_option('-I', dest='install_apk', help='Install APK.',
michael@0 75 action='store_true')
michael@0 76 option_parser.add_option('-f', '--test_filter',
michael@0 77 help='Test filter (if not fully qualified, '
michael@0 78 'will run all matches).')
michael@0 79 option_parser.add_option('-A', '--annotation', dest='annotation_str',
michael@0 80 help=('Run only tests with any of the given '
michael@0 81 'annotations. '
michael@0 82 'An annotation can be either a key or a '
michael@0 83 'key-values pair. '
michael@0 84 'A test that has no annotation is '
michael@0 85 'considered "SmallTest".'))
michael@0 86 option_parser.add_option('-j', '--java_only', action='store_true',
michael@0 87 help='Run only the Java tests.')
michael@0 88 option_parser.add_option('-p', '--python_only', action='store_true',
michael@0 89 help='Run only the Python tests.')
michael@0 90 option_parser.add_option('-n', '--run_count', type='int',
michael@0 91 dest='number_of_runs', default=1,
michael@0 92 help=('How many times to run each test, regardless '
michael@0 93 'of the result. (Default is 1)'))
michael@0 94 option_parser.add_option('--test-apk', dest='test_apk',
michael@0 95 help=('The name of the apk containing the tests '
michael@0 96 '(without the .apk extension). For SDK '
michael@0 97 'builds, the apk name without the debug '
michael@0 98 'suffix(for example, ContentShellTest).'))
michael@0 99 option_parser.add_option('--screenshot', dest='screenshot_failures',
michael@0 100 action='store_true',
michael@0 101 help='Capture screenshots of test failures')
michael@0 102 option_parser.add_option('--save-perf-json', action='store_true',
michael@0 103 help='Saves the JSON file for each UI Perf test.')
michael@0 104 option_parser.add_option('--shard_retries', type=int, default=1,
michael@0 105 help=('Number of times to retry each failure when '
michael@0 106 'sharding.'))
michael@0 107 option_parser.add_option('--official-build', help='Run official build tests.')
michael@0 108 option_parser.add_option('--device',
michael@0 109 help='Serial number of device we should use.')
michael@0 110 option_parser.add_option('--python_test_root',
michael@0 111 help='Root of the python-driven tests.')
michael@0 112
michael@0 113 def ValidateInstrumentationOptions(option_parser, options, args):
michael@0 114 """Validate options/arguments and populate options with defaults."""
michael@0 115 if len(args) > 1:
michael@0 116 option_parser.print_help(sys.stderr)
michael@0 117 option_parser.error('Unknown arguments: %s' % args[1:])
michael@0 118 if options.java_only and options.python_only:
michael@0 119 option_parser.error('Options java_only (-j) and python_only (-p) '
michael@0 120 'are mutually exclusive.')
michael@0 121
michael@0 122 options.run_java_tests = True
michael@0 123 options.run_python_tests = True
michael@0 124 if options.java_only:
michael@0 125 options.run_python_tests = False
michael@0 126 elif options.python_only:
michael@0 127 options.run_java_tests = False
michael@0 128
michael@0 129 # In case of SDK Build, the jars and apks have a -debug suffix.
michael@0 130 options.test_apk_path = os.path.join(_SDK_OUT_DIR,
michael@0 131 options.build_type,
michael@0 132 constants.SDK_BUILD_APKS_DIR,
michael@0 133 '%s-debug.apk' % options.test_apk)
michael@0 134 options.test_apk_jar_path = os.path.join(_SDK_OUT_DIR,
michael@0 135 options.build_type,
michael@0 136 constants.SDK_BUILD_TEST_JAVALIB_DIR,
michael@0 137 '%s-debug.jar' % options.test_apk)
michael@0 138 if options.annotation_str:
michael@0 139 options.annotation = options.annotation_str.split()
michael@0 140 elif options.test_filter:
michael@0 141 options.annotation = []
michael@0 142 else:
michael@0 143 options.annotation = ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest']

mercurial