def _DoFullBuild(self, tests): """If necessary, run a full 'make' command for the tests that need it.""" extra_args_set = Set() # hack to build cts dependencies # TODO: remove this when cts dependencies are removed is_cts = self._IsCtsTests(tests) if is_cts: # need to use make since these fail building with ONE_SHOT_MAKEFILE extra_args_set.add('CtsTestStubs') extra_args_set.add('android.core.tests.runner') for test in tests: if test.IsFullMake(): if test.GetExtraBuildArgs(): # extra args contains the args to pass to 'make' extra_args_set.add(test.GetExtraBuildArgs()) else: logger.Log( "Warning: test %s needs a full build but does not specify" " extra_build_args" % test.GetName()) # check if there is actually any tests that required a full build if extra_args_set: cmd = ('make -j%s %s' % (self._options.make_jobs, ' '.join(list(extra_args_set)))) logger.Log(cmd) if not self._options.preview: old_dir = os.getcwd() os.chdir(self._root_path) output = run_command.RunCommand(cmd, return_output=True) logger.SilentLog(output) os.chdir(old_dir) self._DoInstall(output) if is_cts: # hack! hardcode install of CtsTestStubs out = android_build.GetTestAppPath() abs_install_path = os.path.join(out, "CtsTestStubs.apk") logger.Log("adb install -r %s" % abs_install_path) logger.Log(self._adb.Install(abs_install_path))
def _ProcessOptions(self): """Processes command-line options.""" # TODO error messages on once-only or mutually-exclusive options. user_test_default = os.path.join(os.environ.get("HOME"), ".android", self._TEST_FILE_NAME) parser = optparse.OptionParser(usage=self._RUNTEST_USAGE) parser.add_option("-l", "--list-tests", dest="only_list_tests", default=False, action="store_true", help="To view the list of tests") parser.add_option("-b", "--skip-build", dest="skip_build", default=False, action="store_true", help="Skip build - just launch") parser.add_option("-j", "--jobs", dest="make_jobs", metavar="X", default=self._DEFAULT_JOBS, help="Number of make jobs to use when building") parser.add_option("-n", "--skip_execute", dest="preview", default=False, action="store_true", help="Do not execute, just preview commands") parser.add_option( "-i", "--build-install-only", dest="build_install_only", default=False, action="store_true", help="Do not execute, build tests and install to device only") parser.add_option("-r", "--raw-mode", dest="raw_mode", default=False, action="store_true", help="Raw mode (for output to other tools)") parser.add_option("-a", "--suite-assign", dest="suite_assign_mode", default=False, action="store_true", help="Suite assignment (for details & usage see " "InstrumentationTestRunner)") parser.add_option("-v", "--verbose", dest="verbose", default=False, action="store_true", help="Increase verbosity of %s" % sys.argv[0]) parser.add_option("-w", "--wait-for-debugger", dest="wait_for_debugger", default=False, action="store_true", help="Wait for debugger before launching tests") parser.add_option("-c", "--test-class", dest="test_class", help="Restrict test to a specific class") parser.add_option("-m", "--test-method", dest="test_method", help="Restrict test to a specific method") parser.add_option("-p", "--test-package", dest="test_package", help="Restrict test to a specific java package") parser.add_option("-z", "--size", dest="test_size", help="Restrict test to a specific test size") parser.add_option( "--annotation", dest="test_annotation", help="Include only those tests tagged with a specific" " annotation") parser.add_option("--not-annotation", dest="test_not_annotation", help="Exclude any tests tagged with a specific" " annotation") parser.add_option("-u", "--user-tests-file", dest="user_tests_file", metavar="FILE", default=user_test_default, help="Alternate source of user test definitions") parser.add_option("-o", "--coverage", dest="coverage", default=False, action="store_true", help="Generate code coverage metrics for test(s)") parser.add_option( "--coverage-target", dest="coverage_target_path", default=None, help="Path to app to collect code coverage target data for.") parser.add_option( "-k", "--skip-permissions", dest="skip_permissions", default=False, action="store_true", help="Do not grant runtime permissions during test package" " installation.") parser.add_option("-x", "--path", dest="test_path", help="Run test(s) at given file system path") parser.add_option("-t", "--all-tests", dest="all_tests", default=False, action="store_true", help="Run all defined tests") parser.add_option( "--continuous", dest="continuous_tests", default=False, action="store_true", help="Run all tests defined as part of the continuous " "test set") parser.add_option( "--timeout", dest="timeout", default=300, help="Set a timeout limit (in sec) for " "running native tests on a device (default: 300 secs)") parser.add_option("--suite", dest="suite", help="Run all tests defined as part of the " "the given test suite") group = optparse.OptionGroup( parser, "Targets", "Use these options to direct tests to a specific " "Android target") group.add_option("-e", "--emulator", dest="emulator", default=False, action="store_true", help="use emulator") group.add_option("-d", "--device", dest="device", default=False, action="store_true", help="use device") group.add_option("-s", "--serial", dest="serial", help="use specific serial") parser.add_option_group(group) self._options, self._test_args = parser.parse_args() if (not self._options.only_list_tests and not self._options.all_tests and not self._options.continuous_tests and not self._options.suite and not self._options.test_path and len(self._test_args) < 1): parser.print_help() logger.SilentLog("at least one test name must be specified") raise errors.AbortError self._adb = adb_interface.AdbInterface() if self._options.emulator: self._adb.SetEmulatorTarget() elif self._options.device: self._adb.SetDeviceTarget() elif self._options.serial is not None: self._adb.SetTargetSerial(self._options.serial) if self._options.verbose: logger.SetVerbose(True) if self._options.coverage_target_path: self._options.coverage = True self._known_tests = self._ReadTests() self._options.host_lib_path = android_build.GetHostLibraryPath() self._options.test_data_path = android_build.GetTestAppPath()