Example #1
0
 def __init__(self, device=None, wait_for_pm=False):
     self._adb = adb_interface.AdbInterface()
     if device:
         self._adb.SetTargetSerial(device)
     if wait_for_pm:
         self.WaitForDevicePm()
     self._logcat = None
     self._original_governor = None
     self._pushed_files = []
Example #2
0
 def __init__(self, device=None):
     self._adb = adb_interface.AdbInterface()
     if device:
         self._adb.SetTargetSerial(device)
     self._logcat = None
     self.logcat_process = None
     self._pushed_files = []
     self._device_utc_offset = self.RunShellCommand('date +%z')[0]
     self._md5sum_path = ''
     self._external_storage = ''
Example #3
0
 def __init__(self, device=None):
     self._adb = adb_interface.AdbInterface()
     if device:
         self._adb.SetTargetSerial(device)
     # So many users require root that we just always do it. This could
     # be made more fine grain if necessary.
     self._adb.EnableAdbRoot()
     self._logcat = None
     self._original_governor = None
     self._pushed_files = []
     self._device_utc_offset = self.RunShellCommand('date +%z')[0]
Example #4
0
    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()
Example #5
0
    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("-n",
                          "--skip_execute",
                          dest="preview",
                          default=False,
                          action="store_true",
                          help="Do not execute, just preview commands")
        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("-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("-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")

        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 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)

        self._root_path = android_build.GetTop()

        self._known_tests = self._ReadTests()

        self._coverage_gen = coverage.CoverageGenerator(
            android_root_path=self._root_path, adb_interface=self._adb)