Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(553)

Unified Diff: build/android/run_all_tests.py

Issue 15942016: Creates a new test running script test_runner.py (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: A few more updates from code review Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « build/android/pylib/utils/test_options_parser.py ('k') | build/android/run_browser_tests.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: build/android/run_all_tests.py
diff --git a/build/android/run_all_tests.py b/build/android/run_all_tests.py
new file mode 100755
index 0000000000000000000000000000000000000000..c96859d82f22a0cb6c06f5bb36c388b4528fdf4c
--- /dev/null
+++ b/build/android/run_all_tests.py
@@ -0,0 +1,447 @@
+#!/usr/bin/env python
+#
+# Copyright (c) 2013 The Chromium Authors. All rights reserved.
+# Use of this source code is governed by a BSD-style license that can be
+# found in the LICENSE file.
+
+"""Runs all types of tests from one unified interface.
+
+Types of tests supported:
+1. GTest native unit tests (gtests)
+ Example: ./run_all_tests.py gtests -s android_webview_unittests
+2. ContentBrowser unit tests (content_browsertests)
+ Example: ./run_all_tests.py content_browsertests
+3. Instrumentation tests (instrumentation): Both Python host-driven and
+ Java instrumentation tests are run by default. Use --python_only or
+ --java_only to select one or the other.
+ Example: ./run_all_tests.py instrumentation -I
+ --test-apk=ChromiumTestShellTest
+4. UIAutomator tests (uiautomator): Both Python host-driven and Java
+ UIAutomator tests are run by default. Use --python_only or --java_only to
+ select one or the other.
+ Example: ./run_all_tests.py uiautomator
+ --test-jar=chromium_testshell_uiautomator_tests
+ --package-name=org.chromium.chrome.testshell
+
+TODO(gkanwar):
+* Add options to run Monkey tests.
+"""
+
+import optparse
+import os
+import sys
+
+from pylib import cmd_helper
+from pylib import constants
+from pylib import ports
+from pylib.browsertests import dispatch as browsertests_dispatch
+from pylib.gtest import dispatch as gtest_dispatch
+from pylib.host_driven import run_python_tests as python_dispatch
+from pylib.instrumentation import dispatch as instrumentation_dispatch
+from pylib.uiautomator import dispatch as uiautomator_dispatch
+from pylib.utils import emulator
+from pylib.utils import run_tests_helper
+
+_SDK_OUT_DIR = os.path.join(constants.DIR_SOURCE_ROOT, 'out')
+VALID_TEST_TYPES = ['gtests', 'content_browsertests', 'instrumentation',
+ 'uiautomator']
+
+
+def ProcessTestTypeArg(options, args, errorf):
+ """Processes that the first arg is a valid test type keyword."""
+ if len(args) < 2:
+ errorf('You must specify a test type. Options are: ' +
craigdh 2013/06/17 22:37:05 Let's stick a newline in here before "Options". Th
gkanwar 2013/06/20 20:48:47 Done.
+ ', '.join(VALID_TEST_TYPES))
+ if args[1] not in VALID_TEST_TYPES:
+ errorf('Invalid test type. The test type must be one of: ' +
craigdh 2013/06/17 22:37:05 ditto
gkanwar 2013/06/20 20:48:47 Done.
+ ', '.join(VALID_TEST_TYPES))
+ options.test_type = args[1]
+
+
+def AddBuildTypeOption(option_container):
+ """Adds the build type option to the OptionContainer."""
+ default_build_type = 'Debug'
+ if 'BUILDTYPE' in os.environ:
+ default_build_type = os.environ['BUILDTYPE']
+ option_container.add_option('--debug', action='store_const', const='Debug',
+ dest='build_type', default=default_build_type,
+ help=('If set, run test suites under out/Debug. '
+ 'Default is env var BUILDTYPE or Debug.'))
+ option_container.add_option('--release', action='store_const',
+ const='Release', dest='build_type',
+ help=('If set, run test suites under out/Release.'
+ ' Default is env var BUILDTYPE or Debug.'))
+
+
+def AddDeviceOptions(option_container):
+ """Adds all device-related options to the OptionContainer."""
+
+ option_container.add_option('-d', '--device', dest='test_device',
+ help=('Target device for the test suite '
+ 'to run on.'))
+ option_container.add_option('-e', '--emulator', dest='use_emulator',
+ action='store_true',
+ help='Run tests in a new instance of emulator.')
+ option_container.add_option('-n', '--emulator-count',
+ type='int', default=1,
+ help=('Number of emulators to launch for '
+ 'running the tests.'))
+ option_container.add_option('--abi', default='armeabi-v7a',
+ help='Platform of emulators to launch.')
+
+
+def ProcessDeviceOptions(options):
+ """Processes emulator and device options."""
+ if options.use_emulator:
+ emulator.DeleteAllTempAVDs()
+
+
+def AddCommonOptions(option_parser, default_timeout=60):
+ """Adds all common options to option_parser."""
+
+ option_group = optparse.OptionGroup(option_parser, 'Common Options',
craigdh 2013/06/17 22:37:05 Also print the list of valid test_type first thing
gkanwar 2013/06/20 20:48:47 Done.
+ 'Options that apply to all test types.')
+
+ AddBuildTypeOption(option_group)
+
+ # --gtest_filter is DEPRECATED. Added for backwards compatibility
+ # with the syntax of the old run_tests.py script.
+ option_group.add_option('-f', '--test_filter', '--gtest_filter',
+ dest='test_filter',
+ help=('Test filter (if not fully qualified, '
+ 'will run all matches).'))
+ option_group.add_option('--out-directory', dest='out_directory',
+ help=('Path to the out/ directory, irrespective of '
+ 'the build type. Only for non-Chromium uses.'))
+ option_group.add_option('-t', dest='timeout',
craigdh 2013/06/17 22:37:05 Does this actually work for all test types?
gkanwar 2013/06/20 20:48:47 Ah, you're right, this only works for gtests at th
+ help='Timeout to wait for each test',
+ type='int',
+ default=default_timeout)
+ option_group.add_option('-c', dest='cleanup_test_files',
+ help='Cleanup test files on the device after run',
+ action='store_true')
+ option_group.add_option('--num_retries', dest='num_retries', type='int',
craigdh 2013/06/17 22:37:05 Does this actually work for all test types?
gkanwar 2013/06/20 20:48:47 This was used by all test types except UIAutomator
+ default=2,
+ help=('Number of retries for a test before '
+ 'giving up.'))
+ option_group.add_option('-v',
+ '--verbose',
+ dest='verbose_count',
+ default=0,
+ action='count',
+ help='Verbose level (multiple times for more)')
+ profilers = ['devicestatsmonitor', 'chrometrace', 'dumpheap', 'smaps',
+ 'traceview']
+ option_group.add_option('--profiler', dest='profilers', action='append',
+ choices=profilers,
+ help=('Profiling tool to run during test. Pass '
+ 'multiple times to run multiple profilers. '
+ 'Available profilers: %s' % profilers))
+ option_group.add_option('--tool',
craigdh 2013/06/17 22:37:05 Let's come up with a list of options we'd like to
gkanwar 2013/06/20 20:48:47 Done for most options. I'm still waiting on Peter
+ dest='tool',
+ help=('Run the test under a tool '
+ '(use --tool help to list them)'))
+ option_group.add_option('--flakiness-dashboard-server',
+ dest='flakiness_dashboard_server',
+ help=('Address of the server that is hosting the '
+ 'Chrome for Android flakiness dashboard.'))
+ option_group.add_option('--skip-deps-push', dest='push_deps',
+ action='store_false', default=True,
+ help=('Do not push dependencies to the device. '
+ 'Use this at own risk for speeding up test '
+ 'execution on local machine.'))
+ option_group.add_option('--exit-code', action='store_true',
+ help=('If set, the exit code will be total number '
+ 'of failures.'))
+ option_group.add_option('--buildbot-step-failure',
+ action='store_true',
+ help=('If present, will set the buildbot status '
+ 'as STEP_FAILURE, otherwise as STEP_WARNINGS '
+ 'when test(s) fail.'))
+ option_parser.add_option_group(option_group)
+
+
+def ProcessCommonOptions(options):
+ """Processes and handles all common options."""
+ if options.out_directory:
+ cmd_helper.OutDirectory.set(options.out_directory)
+ run_tests_helper.SetLogLevel(options.verbose_count)
+
+
+def AddContentBrowserOptions(option_parser):
+ """Adds an option group to option_parser for Content Browser tests.
+
+ There are currently no options to be added for Content Browser tests, but we
+ create an option group anyway so that we can add an example for Content
+ Browser tests.
+ """
+
+ option_group = optparse.OptionGroup(
+ option_parser, 'Content Browser Test Options', 'There are no Content '
+ 'Browser specific options currently! Example usage: ./run_all_tests.py '
craigdh 2013/06/17 22:37:05 No !
gkanwar 2013/06/20 20:48:47 Done.
+ 'content_browsertests')
+ option_parser.add_option_group(option_group)
+
+
+def AddGTestOptions(option_parser):
+ """Adds gtest options to option_parser."""
+
+ option_group = optparse.OptionGroup(
+ option_parser, 'GTest Options', 'Use these options to choose which '
+ 'test suites to run and how. Example usage: ./run_all_tests.py gtests -s '
+ 'android_webview_unittests')
+
+ option_group.add_option('-s', '--suite', dest='test_suite',
+ help=('Executable name of the test suite to run '
+ '(use -s help to list them).'))
+ option_group.add_option('-a', '--test_arguments', dest='test_arguments',
+ help='Additional arguments to pass to the test.')
+ option_group.add_option('-x', '--xvfb', dest='use_xvfb',
craigdh 2013/06/17 22:37:05 Do these also work for content_browsertests?
gkanwar 2013/06/20 20:48:47 Most of these do (--suite, --test_arguments, --web
+ action='store_true',
+ help='Use Xvfb around tests (ignored if not Linux).')
+ option_group.add_option('--webkit', action='store_true',
+ help='Run the tests from a WebKit checkout.')
+ option_group.add_option('--exe', action='store_true',
+ help='If set, use the exe test runner instead of '
+ 'the APK.')
+
+ # TODO(gkanwar): Move these to Common Options once we have the plumbing
+ # in our other test types to handle these commands
+ AddDeviceOptions(option_group)
+
+ option_parser.add_option_group(option_group)
+
+
+def AddJavaTestOptions(option_parser):
+ """Adds the Java test options to option_parser."""
+
+ option_group = optparse.OptionGroup(option_parser,
+ 'Java Test Options',
+ 'These options are shared between both '
+ 'Instrumentation and UIAutomator tests. '
+ 'See the specific options for one or the '
craigdh 2013/06/17 22:37:05 Try to use as few words as possible. People tend t
gkanwar 2013/06/20 20:48:47 Done.
+ 'other for an example of how to run each '
+ 'type of test.')
+ option_group.add_option(
+ '-A', '--annotation', dest='annotation_str',
+ help=('Comma-separated list of annotations. Run only tests with any of '
+ 'the given annotations. An annotation can be either a key or a '
+ 'key-values pair. A test that has no annotation is considered '
+ '"SmallTest".'))
+ option_group.add_option(
+ '-E', '--exclude-annotation', dest='exclude_annotation_str',
+ help=('Comma-separated list of annotations. Exclude tests with these '
+ 'annotations.'))
+ option_group.add_option('-j', '--java_only', action='store_true',
+ default=False, help='Run only the Java tests.')
+ option_group.add_option('-p', '--python_only', action='store_true',
+ default=False, help='Run only the host-driven tests.')
+ option_group.add_option('--screenshot', dest='screenshot_failures',
+ action='store_true',
+ help='Capture screenshots of test failures')
+ option_group.add_option('--save-perf-json', action='store_true',
+ help='Saves the JSON file for each UI Perf test.')
+ # TODO(gkanwar): Remove this option. It is not used anywhere.
+ option_group.add_option('--shard_retries', type=int, default=1,
craigdh 2013/06/17 22:37:05 What's the difference between this and the common
gkanwar 2013/06/20 20:48:47 This option is currently only used in host_driven
+ help=('Number of times to retry each failure when '
+ 'sharding.'))
+ option_group.add_option('--official-build', help='Run official build tests.')
+ option_group.add_option('--python_test_root',
+ help='Root of the host-driven tests.')
+ option_group.add_option('--keep_test_server_ports',
+ action='store_true',
+ help=('Indicates the test server ports must be '
+ 'kept. When this is run via a sharder '
+ 'the test server ports should be kept and '
+ 'should not be reset.'))
+ option_group.add_option('--disable_assertions', action='store_true',
+ help='Run with java assertions disabled.')
+ option_group.add_option('--test_data', action='append', default=[],
+ help=('Each instance defines a directory of test '
+ 'data that should be copied to the target(s) '
+ 'before running the tests. The argument '
+ 'should be of the form <target>:<source>, '
+ '<target> is relative to the device data'
+ 'directory, and <source> is relative to the '
+ 'chromium build directory.'))
+
+ option_parser.add_option_group(option_group)
+
+
+def ProcessJavaTestOptions(options, errorf):
+ """Processes options/arguments and populates options with defaults."""
+
+ if options.java_only and options.python_only:
+ errorf('Options java_only (-j) and python_only (-p) '
+ 'are mutually exclusive.')
+ options.run_java_tests = True
+ options.run_python_tests = True
+ if options.java_only:
+ options.run_python_tests = False
+ elif options.python_only:
+ options.run_java_tests = False
+
+ if not options.python_test_root:
+ options.run_python_tests = False
+
+ if options.annotation_str:
+ options.annotations = options.annotation_str.split(',')
+ elif options.test_filter:
+ options.annotations = []
+ else:
+ options.annotations = ['Smoke', 'SmallTest', 'MediumTest', 'LargeTest']
+
+ if options.exclude_annotation_str:
+ options.exclude_annotations = options.exclude_annotation_str.split(',')
+ else:
+ options.exclude_annotations = []
+
+ if not options.keep_test_server_ports:
+ if not ports.ResetTestServerPortAllocation():
+ raise Exception('Failed to reset test server port.')
+
+
+def AddInstrumentationOptions(option_parser):
+ """Adds Instrumentation test options to option_parser."""
+ option_group = optparse.OptionGroup(
+ option_parser, 'Instrumentation Test Options',
+ 'Options specific to Instrumentation Tests. Example usage: '
craigdh 2013/06/17 22:37:05 Clarify here that these are in addition to the jav
gkanwar 2013/06/20 20:48:47 Done.
+ './run_all_tests.py instrumentation -I --test-apk=ChromiumTestShellTest')
+
+ option_group.add_option('-w', '--wait_debugger', dest='wait_for_debugger',
+ action='store_true',
+ help='(Instrumentation only) Wait for debugger.')
+ option_group.add_option('-I', dest='install_apk', action='store_true',
+ help='(Instrumentation only) Install test APK.')
+ option_group.add_option(
+ '--test-apk', dest='test_apk',
+ help=('(Instrumentation only) The name of the apk containing the tests '
+ '(without the .apk extension; e.g. "ContentShellTest"). '
+ 'Alternatively, this can be a full path to the apk.'))
+ option_parser.add_option_group(option_group)
+
+
+def ProcessInstrumentationOptions(options, errorf):
+ """Processes options/arguments and populate options with defaults."""
+
+ ProcessJavaTestOptions(options, errorf)
+
+ if not options.test_apk:
+ errorf('--test-apk must be specified.')
+
+ if os.path.exists(options.test_apk):
+ # The APK is fully qualified, assume the JAR lives along side.
+ options.test_apk_path = options.test_apk
+ options.test_apk_jar_path = (os.path.splitext(options.test_apk_path)[0] +
+ '.jar')
+ else:
+ options.test_apk_path = os.path.join(_SDK_OUT_DIR,
+ options.build_type,
+ constants.SDK_BUILD_APKS_DIR,
+ '%s.apk' % options.test_apk)
+ options.test_apk_jar_path = os.path.join(
+ _SDK_OUT_DIR, options.build_type, constants.SDK_BUILD_TEST_JAVALIB_DIR,
+ '%s.jar' % options.test_apk)
+
+
+def AddUIAutomatorOptions(option_parser):
+ """Adds UI Automator test options to option_parser."""
+ option_group = optparse.OptionGroup(
+ option_parser, 'UIAutomator Test Options',
+ 'Options specific to UIAutomator tests. Example usage: ./run_all_tests.py'
craigdh 2013/06/17 22:37:05 ditto
gkanwar 2013/06/20 20:48:47 Done.
+ ' uiautomator --test-jar=chromium_testshell_uiautomator_tests '
+ '--package-name=org.chromium.chrome.testshell')
+ option_group.add_option(
+ '--package-name',
+ help=('(UIAutomator only) The package name used by the apk '
craigdh 2013/06/17 22:37:05 No longer need all the "UIAutomator only" and "Ins
gkanwar 2013/06/20 20:48:47 Done.
+ 'containing the application.'))
+ option_group.add_option(
+ '--test-jar', dest='test_jar',
+ help=('(UIAutomator only) The name of the dexed jar containing the tests '
+ '(without the .dex.jar extension). Alternatively, this can be a '
+ 'full path to the jar.'))
+ option_parser.add_option_group(option_group)
+
+
+def ProcessUIAutomatorOptions(options, errorf):
+ """Processes UIAutomator options/arguments."""
+
+ ProcessJavaTestOptions(options, errorf)
+
+ if not options.package_name:
+ errorf('--package-name must be specified.')
+
+ if not options.test_jar:
+ errorf('--test-jar must be specified.')
+
+ if os.path.exists(options.test_jar):
+ # The dexed JAR is fully qualified, assume the info JAR lives along side.
+ options.uiautomator_jar = options.test_jar
+ else:
+ options.uiautomator_jar = os.path.join(
+ _SDK_OUT_DIR, options.build_type, constants.SDK_BUILD_JAVALIB_DIR,
+ '%s.dex.jar' % options.test_jar)
+ options.uiautomator_info_jar = (
+ options.uiautomator_jar[:options.uiautomator_jar.find('.dex.jar')] +
+ '_java.jar')
+
+
+def RunTests(options, option_parser):
+ """Checks test type and dispatches to the appropriate function."""
+
+ total_failed = 0
+ if options.test_type == 'gtests':
+ # TODO(gkanwar): Once we move Device Options to Common, this should get
+ # moved out into main.
+ ProcessDeviceOptions(options)
+ total_failed = gtest_dispatch.Dispatch(options)
+ elif options.test_type == 'content_browsertests':
+ total_failed = browsertests_dispatch.Dispatch(options)
+ elif options.test_type == 'instrumentation':
+ ProcessInstrumentationOptions(options, option_parser.error)
+ if options.run_java_tests:
+ total_failed += instrumentation_dispatch.Dispatch(options)
+ if options.run_python_tests:
+ total_failed += python_dispatch.Dispatch(options)
+ elif options.test_type == 'uiautomator':
+ ProcessUIAutomatorOptions(options, option_parser.error)
+ if options.run_java_tests:
+ total_failed += uiautomator_dispatch.Dispatch(options)
+ if options.run_python_tests:
+ total_failed += python_dispatch.Dispatch(options)
+ else:
+ raise Exception('Unknown test type state')
+
+ return total_failed
+
+
+def main(argv):
+ option_parser = optparse.OptionParser(
+ usage='Usage: %prog test_type [options]')
+ AddCommonOptions(option_parser)
+ AddContentBrowserOptions(option_parser)
+ AddGTestOptions(option_parser)
+ AddJavaTestOptions(option_parser)
+ AddInstrumentationOptions(option_parser)
+ AddUIAutomatorOptions(option_parser)
+ options, args = option_parser.parse_args(argv)
+
+ ProcessTestTypeArg(options, args, option_parser.error)
+ ProcessCommonOptions(options)
+
+ failed_tests_count = RunTests(options, option_parser)
+
+ # Failures of individual test suites are communicated by printing a
+ # STEP_FAILURE message.
+ # Returning a success exit status also prevents the buildbot from incorrectly
+ # marking the last suite as failed if there were failures in other suites in
+ # the batch (this happens because the exit status is a sum of all failures
+ # from all suites, but the buildbot associates the exit status only with the
+ # most recent step).
+ if options.exit_code:
+ return failed_tests_count
+ return 0
+
+
+if __name__ == '__main__':
+ sys.exit(main(sys.argv))
« no previous file with comments | « build/android/pylib/utils/test_options_parser.py ('k') | build/android/run_browser_tests.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698