def __init__(self, args, unknown_args): self._additional_args = unknown_args self._path_to_outdir = args.path_to_outdir self._test_launcher_summary_output = args.test_launcher_summary_output self._logs_dir = args.logs_dir self._use_vm = args.use_vm self._rdb_client = result_sink.TryInitClient() self._retries = 0 self._timeout = None # The location on disk of a shell script that can be optionally used to # invoke the test on the device. If it's not set, we assume self._test_cmd # contains the test invocation. self._on_device_script = None self._test_cmd = [ CROS_RUN_TEST_PATH, '--board', args.board, '--cache-dir', args.cros_cache, ] if args.use_vm: self._test_cmd += [ '--start', # Don't persist any filesystem changes after the VM shutsdown. '--copy-on-write', ] else: self._test_cmd += [ '--device', args.device if args.device else LAB_DUT_HOSTNAME ] if args.logs_dir: for log in SYSTEM_LOG_LOCATIONS: self._test_cmd += ['--results-src', log] self._test_cmd += [ '--results-dest-dir', os.path.join(args.logs_dir, 'system_logs') ] if args.flash: self._test_cmd += ['--flash'] if args.public_image: self._test_cmd += ['--public-image'] # This environment variable is set for tests that have been instrumented # for code coverage. Its incoming value is expected to be a location # inside a subdirectory of result_dir above. This is converted to an # absolute path that the vm is able to write to, and passed in the # --results-src flag to cros_run_vm_test for copying out of the vm before # its termination. self._llvm_profile_var = None if os.environ.get('LLVM_PROFILE_FILE'): _, llvm_profile_file = os.path.split(os.environ['LLVM_PROFILE_FILE']) self._llvm_profile_var = '/tmp/profraw/%s' % llvm_profile_file # This should make the vm test runner exfil the profiling data. self._test_cmd += ['--results-src', '/tmp/profraw'] self._test_env = setup_env()
def main(): signal.signal(signal.SIGUSR1, DumpThreadStacks) parser = argparse.ArgumentParser() command_parsers = parser.add_subparsers( title='test types', dest='command') subp = command_parsers.add_parser( 'gtest', help='googletest-based C++ tests') AddCommonOptions(subp) AddDeviceOptions(subp) AddEmulatorOptions(subp) AddGTestOptions(subp) AddTracingOptions(subp) AddCommandLineOptions(subp) subp = command_parsers.add_parser( 'instrumentation', help='InstrumentationTestCase-based Java tests') AddCommonOptions(subp) AddDeviceOptions(subp) AddEmulatorOptions(subp) AddInstrumentationTestOptions(subp) AddSkiaGoldTestOptions(subp) AddTracingOptions(subp) AddCommandLineOptions(subp) subp = command_parsers.add_parser( 'junit', help='JUnit4-based Java tests') AddCommonOptions(subp) AddJUnitTestOptions(subp) subp = command_parsers.add_parser( 'linker', help='linker tests') AddCommonOptions(subp) AddDeviceOptions(subp) AddEmulatorOptions(subp) AddLinkerTestOptions(subp) subp = command_parsers.add_parser( 'monkey', help="tests based on Android's monkey command") AddCommonOptions(subp) AddDeviceOptions(subp) AddEmulatorOptions(subp) AddMonkeyTestOptions(subp) subp = command_parsers.add_parser( 'python', help='python tests based on unittest.TestCase') AddCommonOptions(subp) AddPythonTestOptions(subp) args, unknown_args = parser.parse_known_args() if unknown_args: if hasattr(args, 'allow_unknown') and args.allow_unknown: args.command_line_flags = unknown_args else: parser.error('unrecognized arguments: %s' % ' '.join(unknown_args)) # --replace-system-package has the potential to cause issues if # --enable-concurrent-adb is set, so disallow that combination if (hasattr(args, 'replace_system_package') and hasattr(args, 'enable_concurrent_adb') and args.replace_system_package and args.enable_concurrent_adb): parser.error('--replace-system-package and --enable-concurrent-adb cannot ' 'be used together') # --use-webview-provider has the potential to cause issues if # --enable-concurrent-adb is set, so disallow that combination if (hasattr(args, 'use_webview_provider') and hasattr(args, 'enable_concurrent_adb') and args.use_webview_provider and args.enable_concurrent_adb): parser.error('--use-webview-provider and --enable-concurrent-adb cannot ' 'be used together') if (getattr(args, 'coverage_on_the_fly', False) and not getattr(args, 'coverage_dir', '')): parser.error('--coverage-on-the-fly requires --coverage-dir') if (hasattr(args, 'debug_socket') or (hasattr(args, 'wait_for_java_debugger') and args.wait_for_java_debugger)): args.num_retries = 0 # Result-sink may not exist in the environment if rdb stream is not enabled. result_sink_client = result_sink.TryInitClient() try: return RunTestsCommand(args, result_sink_client) except base_error.BaseError as e: logging.exception('Error occurred.') if e.is_infra_error: return constants.INFRA_EXIT_CODE return constants.ERROR_EXIT_CODE except: # pylint: disable=W0702 logging.exception('Unrecognized error occurred.') return constants.ERROR_EXIT_CODE