def WaitForDevicePm(self, wait_time=120):
    """Waits for targeted device's package manager to be up.

    Args:
      wait_time: time in seconds to wait

    Raises:
      WaitForResponseTimedOutError if wait_time elapses and pm still does not
      respond.
    """
    logger.Log("Waiting for device package manager...")
    self.SendCommand("wait-for-device")
    # Now the device is there, but may not be running.
    # Query the package manager with a basic command
    try:
      self._WaitForShellCommandContents("pm path android", "package:",
                                        wait_time)
    except errors.WaitForResponseTimedOutError:
      raise errors.WaitForResponseTimedOutError(
          "Package manager did not respond after %s seconds" % wait_time)
示例#2
0
def GetProductOut():
    """Returns the full pathname to the target/product directory.

  Typically the value of the env variable $ANDROID_PRODUCT_OUT.

  Assumes build environment has been properly configured by envsetup &
  lunch/choosecombo.

  Returns:
    The absolute file path of the Android product directory.

  Raises:
    AbortError: if Android product directory could not be found.
  """
    path = os.getenv("ANDROID_PRODUCT_OUT")
    if path is None:
        logger.Log(
            "Error: ANDROID_PRODUCT_OUT not defined. Please run envsetup.sh")
        raise errors.AbortError
    return path
示例#3
0
    def StartInstrumentationNoResults(self,
                                      package_name,
                                      runner_name,
                                      no_window_animation=False,
                                      raw_mode=False,
                                      instrumentation_args={}):
        """Runs instrumentation and dumps output to stdout.

    Equivalent to StartInstrumentation, but will dump instrumentation
    'normal' output to stdout, instead of parsing return results. Command will
    never timeout.
    """
        adb_command_string = self.PreviewInstrumentationCommand(
            package_name,
            runner_name,
            no_window_animation=no_window_animation,
            raw_mode=raw_mode,
            instrumentation_args=instrumentation_args)
        logger.Log(adb_command_string)
        run_command.RunCommand(adb_command_string, return_output=False)
示例#4
0
def GetHostBin():
    """Compute the full pathname to the host binary directory.

  Typically $ANDROID_BUILD_TOP/out/host/linux-x86/bin.

  Assumes build environment has been properly configured by envsetup &
  lunch/choosecombo.

  Returns:
    The absolute file path of the Android host binary directory.

  Raises:
    AbortError: if Android host binary directory could not be found.
  """
    (_, _, os_arch) = GetHostOsArch()
    path = os.path.join(GetTop(), "out", "host", os_arch, "bin")
    if not os.path.exists(path):
        logger.Log("Error: Host bin path could not be found %s" % path)
        raise errors.AbortError
    return path
示例#5
0
def GetHostLibraryPath():
    """Returns the full pathname to the host java library output directory.

  Typically $ANDROID_BUILD_TOP/out/host/<host_os>/framework.

  Assumes build environment has been properly configured by envsetup &
  lunch/choosecombo.

  Returns:
    The absolute file path of the Android host java library directory.

  Raises:
    AbortError: if Android host java library directory could not be found.
  """
    (_, _, os_arch) = GetHostOsArch()
    path = os.path.join(GetTop(), "out", "host", os_arch, "framework")
    if not os.path.exists(path):
        logger.Log("Error: Host library path could not be found %s" % path)
        raise errors.AbortError
    return path
示例#6
0
def launch():
    try:
        gc.disable()

        log_main: logger.Log = logger.Log()
        log_main.to_stderr = launcher.DEBUG
        log_main.info(f"Starting TF2 Rich Presence {launcher.VERSION}")

        app: TF2RichPresense = TF2RichPresense(log_main)
        app.run()
    except SystemExit:
        raise
    except Exception:
        try:
            gc.enable()
            log_main.critical(traceback.format_exc())
        except NameError:
            pass  # the crash happened in logger.Log().__init__() and so log_main is unassigned

        raise
示例#7
0
    def Pull(self, src, dest):
        """Pulls the file src on the device onto dest on the host.

    Args:
      src: absolute file path of file on device to pull
      dest: destination file path on host

    Returns:
      True if success and False otherwise.
    """
        # Create the base dir if it doesn't exist already
        if not os.path.exists(os.path.dirname(dest)):
            os.makedirs(os.path.dirname(dest))

        if self.DoesFileExist(src):
            self.SendCommand("pull %s %s" % (src, dest), timeout_time=60)
            return True
        else:
            logger.Log("ADB Pull Failed: Source file %s does not exist." % src)
            return False
示例#8
0
    def __init__(self,
                 log: Optional[logger.Log] = None,
                 loc: Optional[localization.Localizer] = None):
        self.in_menus: bool = True
        self.tf2_map: str = ''  # these have "tf2_" to avoid conflicting with reserved keywords
        self.tf2_class: str = "unselected"
        self.map_fancy: str = ''
        self.server_address: str = ''
        self.queued_state: str = "Not queued"
        self.hosting: bool = False
        self.server_name: str = ''
        self.player_count: str = ''
        self.kills: str = ''
        self.gamemode: str = ''
        self.gamemode_fancy: str = ''
        self.custom_map: bool = False
        self.game_start_time: int = int(time.time())
        self.map_change_time: int = int(time.time())
        self.map_line: str = ''

        self.update_rpc: bool = True
        # don't track whether the GUI needs to be updated, main just always calls its updates and lets it handle whether or not it needs to set elements
        self.last_server_request_time: float = 0.0
        self.last_server_request_data: Dict[str, str] = {}
        self.last_server_request_address: str = ''
        self.updated_server_state: bool = False
        self.force_zero_map_time: bool = False

        if log:
            self.log: logger.Log = log
        else:
            self.log = logger.Log()
            self.log.error(
                f"Initialized GameState without a log, defaulting to one at {self.log.filename}"
            )

        if loc:
            self.loc: localization.Localizer = loc
        else:
            self.loc = localization.Localizer()
            self.log.error("Initialized GameState without a localizer")
示例#9
0
 def Run():
     if return_output:
         output_dest = subprocess.PIPE
     else:
         # None means direct to stdout
         output_dest = None
     pipe = subprocess.Popen(cmd,
                             executable='/bin/bash',
                             stdout=output_dest,
                             stderr=subprocess.STDOUT,
                             shell=True)
     pid.append(pipe.pid)
     try:
         output = pipe.communicate()[0]
         if output is not None and len(output) > 0:
             so.append(output)
     except OSError, e:
         logger.SilentLog("failed to retrieve stdout from: %s" % cmd)
         logger.Log(e)
         so.append("ERROR")
         error_occurred = True
    def generate_predictions_with_id(self, path, examples):
        if (self.completed == True):
            best_path = os.path.join(FIXED_PARAMETERS["ckpt_path"], modname) + ".ckpt_best"
            self.sess = tf.Session()
            self.sess.run(self.init)
            self.saver.restore(self.sess, best_path)
            logger.Log("Model restored from file: %s" % best_path)

        total_batch = int(len(examples) / self.batch_size)
        pred_size = 3
        logits = np.empty(pred_size)
        costs = 0
        IDs = np.empty(1)
        for i in tqdm(range(total_batch + 1), ascii = True):
            if i != total_batch:
                #make batch here
                r, premise, hypothesis, premise_def, hypothesis_def ,labels, mask_p, mask_h, mask_p_def, mask_h_def = self.batch_matrix(examples, i * self.batch_size, (i+1) * self.batch_size)
            else:
                #make batch here with boundary 
                r, premise, hypothesis, premise_def, hypothesis_def ,labels, mask_p, mask_h, mask_p_def, mask_h_def = self.batch_matrix(examples, i * self.batch_size, len(examples))

            feed_dict = {self.model.r_matrix : r,
                            self.model.premise_x : premise,
                            self.model.hypothesis_x : hypothesis,
                            self.model.mask_p : mask_p,
                            self.model.mask_h : mask_h,
                            self.model.premise_def : premise_def,
                            self.model.hypothesis_def : hypothesis_def,
                            self.model.mask_p_def : mask_p_def,
                            self.model.mask_h_def : mask_h_def,
                            self.model.y : labels,
                            self.model.keep_rate_ph: 1.0,
                            self.model.is_train: True
                            }
            logit = self.sess.run(self.model.logits, feed_dict)
            IDs = np.concatenate([IDs, pairIDs])
            logits = np.vstack([logits, logit])
        IDs = IDs[1:]
        logits = np.argmax(logits[1:], axis=1)
        save_submission(path, IDs, logits[1:])
示例#11
0
    def Parse(self, element):
        """Populates common suite attributes from given suite xml element.

    Args:
      element: xml node to parse
    Raises:
      ParseError if a required attribute is missing.
    Returns:
      parsed test suite or None
    """
        parser = None
        if element.nodeName == InstrumentationParser.TAG_NAME:
            parser = InstrumentationParser()
        elif element.nodeName == NativeParser.TAG_NAME:
            parser = NativeParser()
        elif element.nodeName == HostParser.TAG_NAME:
            parser = HostParser()
        else:
            logger.Log('Unrecognized tag %s found' % element.nodeName)
            return None
        test_suite = parser.Parse(element)
        return test_suite
示例#12
0
    def testLevel(self):
        """A test setting the debug level up."""

        import logger

        logfilename = 'xyzzy2.log'

        # start logging at WARN, write some test logs, close log
        log = logger.Log(logfilename, logger.Log.WARN)
        log('test')
        log.debug('DEBUG: test')
        log.info('INFO: test')
        log.warn('WARN: test')
        log.error('ERROR: test')
        log.critical('CRITICAL: test')
        del log

        # check contents of the logfile
        with open(logfilename, 'r') as fd:
            lines = fd.readlines()

        # get last field of each line (ignore first 3 lines)
        last_field = []
        for l in lines[3:]:
            end_field = l.split('|')[-1]
            last_field.append(end_field)

        # build the expected output
        expected = [
            'Logging level set to 30 (WARN)\n', 'test\n', 'WARN: test\n',
            'ERROR: test\n', 'CRITICAL: test\n'
        ]

        msg = ('Got error comparing last fields, expected:\n%s\ngot:\n%s' %
               (''.join(expected), ''.join(last_field)))

        self.assertEqual(expected, last_field, msg)

        os.remove(logfilename)
示例#13
0
def GetHostOsArch():
    """Identify the host os and arch.

  Returns:
    The triple (HOST_OS, HOST_ARCH, HOST_OS-HOST_ARCH).

  Raises:
    AbortError: If the os and/or arch could not be found.
  """
    command = ("CALLED_FROM_SETUP=true BUILD_SYSTEM=build/core "
               "make --no-print-directory -C \"%s\" -f build/core/config.mk "
               "dumpvar-report_config") % GetTop()

    # Use the shell b/c we set some env variables before the make command.
    config = subprocess.Popen(command, stdout=subprocess.PIPE,
                              shell=True).communicate()[0]
    host_os = re.search("HOST_OS=(\w+)", config).group(1)
    host_arch = re.search("HOST_ARCH=(\w+)", config).group(1)
    if not (host_os and host_arch):
        logger.Log("Error: Could not get host's OS and/or ARCH")
        raise errors.AbortError
    return (host_os, host_arch, "%s-%s" % (host_os, host_arch))
示例#14
0
    def __init__(self):
        # model initialization
        self.model = model.ExpliLEModel(
            vectors,
            PARAMETERS["mlp_lay"],
            activation=tf.nn.tanh,
            scope="exp_le",
            asym_fact=PARAMETERS["asym_fact"],
            margin_le=PARAMETERS["hinge_margin"],
            reg_factor_hyp=PARAMETERS["reg_factor_hyp"],
            reg_factor_sym=PARAMETERS["reg_factor_sym"],
            learning_rate=PARAMETERS["learning_rate"],
            margin_sym=PARAMETERS["margin_sym"])
        self.asym_fact = PARAMETERS["asym_fact"]
        self.batch_size = PARAMETERS["batch_size"]
        self.keep_rate = PARAMETERS["dropout"]
        self.eval_steps = PARAMETERS["eval_steps"]

        logger.Log("Initializing variables")
        self.init = tf.global_variables_initializer()
        self.sess = None
        self.saver = tf.train.Saver()
示例#15
0
    def Run(self, options, adb_interface):
        """Runs the host test.

    Results will be displayed on stdout. Assumes 'java' is on system path.

    Args:
      options: command line options for running host tests. Expected member
        fields:
        host_lib_path: path to directory that contains host library files
        test_data_path: path to directory that contains test data files
        preview: if true, do not execute, display commands only
      adb_interface: reference to device under test

    Raises:
      errors.AbortError: if fatal error occurs
    """
        # get the serial number of the device under test, so it can be passed to
        # hosttestlib.
        serial_number = adb_interface.GetSerialNumber()
        self._lib_names.append(self.GetJarName())
        # gather all the host jars that are needed to run tests
        full_lib_paths = []
        for lib in self._lib_names:
            path = os.path.join(options.host_lib_path, lib)
            # make sure jar file exists on host
            if not os.path.exists(path):
                raise errors.AbortError(msg="Could not find jar %s" % path)
            full_lib_paths.append(path)

        # java -cp <libs> <runner class> <test suite class> -s <device serial>
        # -p <test data path>
        cmd = "java -cp %s %s %s -s %s -p %s" % (
            ":".join(full_lib_paths), self._TEST_RUNNER, self.GetClassName(),
            serial_number, options.test_data_path)
        logger.Log(cmd)
        if not options.preview:
            run_command.RunOnce(cmd, return_output=False)
示例#16
0
    def __init__(self, config, msg_queue):
        threading.Thread.__init__(self)
        conf.verb = 0

        self.__init_variable()

        self.name = config['name']
        self.mac = config['mac']
        self.iface = config['iface']
        self.config = config

        self.msg = message.Message(msg_queue)
        self.msg.user = self.name
        self.msg.msg_templete['attacker'] = 'Unknown'
        self.msg.msg_templete['victim'] = self.name
        self.msg.msg_templete['victim_mac'] = self.mac

        log_file = "./log/%s.log" % self.name
        self.log = logger.Log(log_file)
        self.log.set_print_level(3)

        self.iface_id = in6_mactoifaceid(self.mac).lower()
        self.link_local_addr = "fe80::" + self.iface_id
        self.link_local_addr = in6_ptop(self.link_local_addr)

        #FF02:0:0:0:0:1:FFXX:XXXX
        self.solicited_node_addr = inet_ntop6(
            in6_getnsma(inet_pton6(self.link_local_addr)))

        # When sending packets, it will select one of these addresses as src_addr.
        self.src_addrs.append(self.link_local_addr)
        self.src_addrs.append(self.unspecified_addr)

        # Packets with these dst_addr will destinate to the honeypot.
        self.dst_addrs.append(self.link_local_addr)
        self.dst_addrs.append(self.solicited_node_addr)
        self.dst_addrs.append(self.all_nodes_addr)
  def _GetTestsToRun(self):
    """Get a list of TestSuite objects to run, based on command line args."""
    if self._tests_to_run:
      return self._tests_to_run

    self._tests_to_run = []
    if self._options.all_tests:
      self._tests_to_run = self._known_tests.GetTests()
    elif self._options.continuous_tests:
      self._tests_to_run = self._known_tests.GetContinuousTests()
    elif self._options.cts_tests:
      self._tests_to_run = self._known_tests.GetCtsTests()
    elif self._options.test_path:
      walker = test_walker.TestWalker()
      self._tests_to_run = walker.FindTests(self._options.test_path)

    for name in self._test_args:
      test = self._known_tests.GetTest(name)
      if test is None:
        logger.Log("Error: Could not find test %s" % name)
        self._DumpTests()
        raise errors.AbortError
      self._tests_to_run.append(test)
    return self._tests_to_run
示例#18
0
    def _TurnOffVerifier(self, test_list):
        """Turn off the dalvik verifier if needed by given tests.

    If one or more tests needs dalvik verifier off, and it is not already off,
    turns off verifier and reboots device to allow change to take effect.
    """
        # hack to check if these are frameworks/base tests. If so, turn off verifier
        # to allow framework tests to access package-private framework api
        framework_test = False
        for test in test_list:
            if os.path.commonprefix([test.GetBuildPath(), "frameworks/base"]):
                framework_test = True
        if framework_test:
            # check if verifier is off already - to avoid the reboot if not
            # necessary
            output = self._adb.SendShellCommand("cat /data/local.prop")
            if not self._DALVIK_VERIFIER_OFF_PROP in output:
                if self._options.preview:
                    logger.Log("adb shell \"echo %s >> /data/local.prop\"" %
                               self._DALVIK_VERIFIER_OFF_PROP)
                    logger.Log("adb shell chmod 644 /data/local.prop")
                    logger.Log("adb reboot")
                    logger.Log("adb wait-for-device")
                else:
                    logger.Log("Turning off dalvik verifier and rebooting")
                    self._adb.SendShellCommand(
                        "\"echo %s >> /data/local.prop\"" %
                        self._DALVIK_VERIFIER_OFF_PROP)

                    self._ChmodReboot()
            elif not self._options.preview:
                # check the permissions on the file
                permout = self._adb.SendShellCommand("ls -l /data/local.prop")
                if not "-rw-r--r--" in permout:
                    logger.Log(
                        "Fixing permissions on /data/local.prop and rebooting")
                    self._ChmodReboot()
示例#19
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import logger
import requests
import parsel

base_url = 'http://yhxz521.com'
log = logger.Log()


def get_classify_list():
    log.debug("***********开始爬取***********")
    pase = send_requests(base_url)
    href_list = pase.xpath(
        '//div[@class="nav"]/ul/li/a/@href').extract()  # 分类list
    log.debug("分类list为:%s" % href_list)
    return href_list


def send_requests(url):
    response = requests.get(url)
    log.debug("请求地址:%s" % url)
    response.encoding = response.apparent_encoding
    log.debug("编码为:%s" % response.encoding)
    html = response.text  # response的html
    parse = parsel.Selector(html)
    return parse


if __name__ == "__main__":
示例#20
0
class TestRunner(object):
    """Command line utility class for running pre-defined Android test(s)."""

    _TEST_FILE_NAME = "test_defs.xml"

    # file path to android core platform tests, relative to android build root
    # TODO move these test data files to another directory
    _CORE_TEST_PATH = os.path.join("development", "testrunner",
                                   _TEST_FILE_NAME)

    # vendor glob file path patterns to tests, relative to android
    # build root
    _VENDOR_TEST_PATH = os.path.join("vendor", "*", "tests", "testinfo",
                                     _TEST_FILE_NAME)

    _RUNTEST_USAGE = (
        "usage: runtest.py [options] short-test-name[s]\n\n"
        "The runtest script works in two ways.  You can query it "
        "for a list of tests, or you can launch one or more tests.")

    # default value for make -jX
    _DEFAULT_JOBS = 16

    _DALVIK_VERIFIER_PROP = "dalvik.vm.dexopt-flags"
    _DALVIK_VERIFIER_OFF_VALUE = "v=n"
    _DALVIK_VERIFIER_OFF_PROP = "%s = %s" % (_DALVIK_VERIFIER_PROP,
                                             _DALVIK_VERIFIER_OFF_VALUE)

    # regular expression to match path to artifacts to install in make output
    _RE_MAKE_INSTALL = re.compile(r'INSTALL-PATH:\s([^\s]+)\s(.*)$')

    def __init__(self):
        # disable logging of timestamp
        self._root_path = android_build.GetTop()
        out_base_name = os.path.basename(android_build.GetOutDir())
        # regular expression to find remote device path from a file path relative
        # to build root
        pattern = r'' + out_base_name + r'\/target\/product\/\w+\/(.+)$'
        self._re_make_install_path = re.compile(pattern)
        logger.SetTimestampLogging(False)
        self._adb = None
        self._known_tests = None
        self._options = None
        self._test_args = None
        self._tests_to_run = None

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

    def _ReadTests(self):
        """Parses the set of test definition data.

    Returns:
      A TestDefinitions object that contains the set of parsed tests.
    Raises:
      AbortError: If a fatal error occurred when parsing the tests.
    """
        try:
            known_tests = test_defs.TestDefinitions()
            # only read tests when not in path mode
            if not self._options.test_path:
                core_test_path = os.path.join(self._root_path,
                                              self._CORE_TEST_PATH)
                if os.path.isfile(core_test_path):
                    known_tests.Parse(core_test_path)
                # read all <android root>/vendor/*/tests/testinfo/test_defs.xml paths
                vendor_tests_pattern = os.path.join(self._root_path,
                                                    self._VENDOR_TEST_PATH)
                test_file_paths = glob.glob(vendor_tests_pattern)
                for test_file_path in test_file_paths:
                    known_tests.Parse(test_file_path)
                if os.path.isfile(self._options.user_tests_file):
                    known_tests.Parse(self._options.user_tests_file)
            return known_tests
        except errors.ParseError:
            raise errors.AbortError

    def _DumpTests(self):
        """Prints out set of defined tests."""
        print "The following tests are currently defined:\n"
        print "%-25s %-40s %s" % ("name", "build path", "description")
        print "-" * 80
        for test in self._known_tests:
            print "%-25s %-40s %s" % (test.GetName(), test.GetBuildPath(),
                                      test.GetDescription())
        print "\nSee %s for more information" % self._TEST_FILE_NAME

    def _DoBuild(self):
        logger.SilentLog("Building tests...")
        tests = self._GetTestsToRun()

        # Build and install tests that do not get granted permissions
        self._DoPermissionAwareBuild(tests, False)

        # Build and install tests that require granted permissions
        self._DoPermissionAwareBuild(tests, True)

    def _DoPermissionAwareBuild(self, tests, test_requires_permissions):
        # turn off dalvik verifier if necessary
        # TODO: skip turning off verifier for now, since it puts device in bad
        # state b/14088982
        #self._TurnOffVerifier(tests)
        self._DoFullBuild(tests, test_requires_permissions)

        target_tree = make_tree.MakeTree()

        extra_args_set = []
        for test_suite in tests:
            if test_suite.IsGrantedPermissions() == test_requires_permissions:
                self._AddBuildTarget(test_suite, target_tree, extra_args_set)

        if not self._options.preview:
            self._adb.EnableAdbRoot()
        else:
            logger.Log("adb root")

        if not target_tree.IsEmpty():
            if self._options.coverage:
                coverage.EnableCoverageBuild()
                target_tree.AddPath("external/emma")

            target_list = target_tree.GetPrunedMakeList()
            target_dir_list = [
                re.sub(r'Android[.]mk$', r'', i) for i in target_list
            ]
            target_build_string = " ".join(target_list)
            target_dir_build_string = " ".join(target_dir_list)
            extra_args_string = " ".join(extra_args_set)

            install_path_goals = []
            mmma_goals = []
            for d in target_dir_list:
                if d.startswith("./"):
                    d = d[2:]
                if d.endswith("/"):
                    d = d[:-1]
                install_path_goals.append("GET-INSTALL-PATH-IN-" +
                                          d.replace("/", "-"))
                mmma_goals.append("MODULES-IN-" + d.replace("/", "-"))
            # mmm cannot be used from python, so perform a similar operation using
            # ONE_SHOT_MAKEFILE
            cmd = 'ONE_SHOT_MAKEFILE="%s" make -j%s -C "%s" %s %s %s' % (
                target_build_string, self._options.make_jobs, self._root_path,
                " ".join(install_path_goals), " ".join(mmma_goals),
                extra_args_string)
            # mmma cannot be used from python, so perform a similar operation
            alt_cmd = 'make -j%s -C "%s" -f build/core/main.mk %s %s' % (
                self._options.make_jobs, self._root_path, extra_args_string,
                " ".join(mmma_goals))

            logger.Log(cmd)
            if not self._options.preview:
                run_command.SetAbortOnError()
                try:
                    output = run_command.RunCommand(cmd,
                                                    return_output=True,
                                                    timeout_time=600)
                    ## Chances are this failed because it didn't build the dependencies
                except errors.AbortError:
                    logger.Log(
                        "make failed. Trying to rebuild all dependencies.")
                    logger.Log(
                        "mmma -j%s %s" %
                        (self._options.make_jobs, target_dir_build_string))
                    # Try again with mma equivalent, which will build the dependencies
                    run_command.RunCommand(alt_cmd,
                                           return_output=False,
                                           timeout_time=600)
                    # Run mmm again to get the install paths only
                    output = run_command.RunCommand(cmd,
                                                    return_output=True,
                                                    timeout_time=600)
                run_command.SetAbortOnError(False)
                logger.SilentLog(output)
                self._DoInstall(output, test_requires_permissions)

    def _DoInstall(self, make_output, test_requires_permissions):
        """Install artifacts from build onto device.

    Looks for 'install:' text from make output to find artifacts to install.

    Files with the .apk extension get 'adb install'ed, all other files
    get 'adb push'ed onto the device.

    Args:
      make_output: stdout from make command
    """
        for line in make_output.split("\n"):
            m = self._RE_MAKE_INSTALL.match(line)
            if m:
                # strip the 'INSTALL: <name>' from the left hand side
                # the remaining string is a space-separated list of build-generated files
                install_paths = m.group(2)
                for install_path in re.split(r'\s+', install_paths):
                    if install_path.endswith(".apk"):
                        abs_install_path = os.path.join(
                            self._root_path, install_path)
                        extra_flags = ""
                        if test_requires_permissions and not self._options.skip_permissions:
                            extra_flags = "-g"
                        logger.Log("adb install -r %s %s" %
                                   (extra_flags, abs_install_path))
                        logger.Log(
                            self._adb.Install(abs_install_path, extra_flags))
                    else:
                        self._PushInstallFileToDevice(install_path)

    def _PushInstallFileToDevice(self, install_path):
        m = self._re_make_install_path.match(install_path)
        if m:
            remote_path = m.group(1)
            remote_dir = os.path.dirname(remote_path)
            logger.Log("adb shell mkdir -p %s" % remote_dir)
            self._adb.SendShellCommand("mkdir -p %s" % remote_dir)
            abs_install_path = os.path.join(self._root_path, install_path)
            logger.Log("adb push %s %s" % (abs_install_path, remote_path))
            self._adb.Push(abs_install_path, remote_path)
        else:
            logger.Log(
                "Error: Failed to recognize path of file to install %s" %
                install_path)

    def _DoFullBuild(self, tests, test_requires_permissions):
        """If necessary, run a full 'make' command for the tests that need it."""
        extra_args_set = Set()

        for test in tests:
            if test.IsFullMake() and test.IsGrantedPermissions(
            ) == test_requires_permissions:
                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, test_requires_permissions)

    def _AddBuildTarget(self, test_suite, target_tree, extra_args_set):
        if not test_suite.IsFullMake():
            build_dir = test_suite.GetBuildPath()
            if self._AddBuildTargetPath(build_dir, target_tree):
                extra_args_set.append(test_suite.GetExtraBuildArgs())
            for path in test_suite.GetBuildDependencies(self._options):
                self._AddBuildTargetPath(path, target_tree)

    def _AddBuildTargetPath(self, build_dir, target_tree):
        if build_dir is not None:
            target_tree.AddPath(build_dir)
            return True
        return False

    def _GetTestsToRun(self):
        """Get a list of TestSuite objects to run, based on command line args."""
        if self._tests_to_run:
            return self._tests_to_run

        self._tests_to_run = []
        if self._options.all_tests:
            self._tests_to_run = self._known_tests.GetTests()
        elif self._options.continuous_tests:
            self._tests_to_run = self._known_tests.GetContinuousTests()
        elif self._options.suite:
            self._tests_to_run = \
                self._known_tests.GetTestsInSuite(self._options.suite)
        elif self._options.test_path:
            walker = test_walker.TestWalker()
            self._tests_to_run = walker.FindTests(self._options.test_path)

        for name in self._test_args:
            test = self._known_tests.GetTest(name)
            if test is None:
                logger.Log("Error: Could not find test %s" % name)
                self._DumpTests()
                raise errors.AbortError
            self._tests_to_run.append(test)
        return self._tests_to_run

    def _IsCtsTests(self, test_list):
        """Check if any cts tests are included in given list of tests to run."""
        for test in test_list:
            if test.GetSuite() == 'cts':
                return True
        return False

    def _TurnOffVerifier(self, test_list):
        """Turn off the dalvik verifier if needed by given tests.

    If one or more tests needs dalvik verifier off, and it is not already off,
    turns off verifier and reboots device to allow change to take effect.
    """
        # hack to check if these are frameworks/base tests. If so, turn off verifier
        # to allow framework tests to access private/protected/package-private framework api
        framework_test = False
        for test in test_list:
            if os.path.commonprefix([test.GetBuildPath(), "frameworks/base"]):
                framework_test = True
        if framework_test:
            # check if verifier is off already - to avoid the reboot if not
            # necessary
            output = self._adb.SendShellCommand("cat /data/local.prop")
            if not self._DALVIK_VERIFIER_OFF_PROP in output:

                # Read the existing dalvik verifier flags.
                old_prop_value = self._adb.SendShellCommand("getprop %s" \
                    %(self._DALVIK_VERIFIER_PROP))
                old_prop_value = old_prop_value.strip(
                ) if old_prop_value else ""

                # Append our verifier flags to existing flags
                new_prop_value = "%s %s" % (self._DALVIK_VERIFIER_OFF_VALUE,
                                            old_prop_value)

                # Update property now, as /data/local.prop is not read until reboot
                logger.Log("adb shell setprop %s '%s'" \
                    %(self._DALVIK_VERIFIER_PROP, new_prop_value))
                if not self._options.preview:
                    self._adb.SendShellCommand("setprop %s '%s'" \
                      %(self._DALVIK_VERIFIER_PROP, new_prop_value))

                # Write prop to /data/local.prop
                # Every time device is booted, it will pick up this value
                new_prop_assignment = "%s = %s" % (self._DALVIK_VERIFIER_PROP,
                                                   new_prop_value)
                if self._options.preview:
                    logger.Log("adb shell \"echo %s >> /data/local.prop\"" %
                               new_prop_assignment)
                    logger.Log("adb shell chmod 644 /data/local.prop")
                else:
                    logger.Log("Turning off dalvik verifier and rebooting")
                    self._adb.SendShellCommand(
                        "\"echo %s >> /data/local.prop\"" %
                        new_prop_assignment)

                # Reset runtime so that dalvik picks up new verifier flags from prop
                self._ChmodRuntimeReset()
            elif not self._options.preview:
                # check the permissions on the file
                permout = self._adb.SendShellCommand("ls -l /data/local.prop")
                if not "-rw-r--r--" in permout:
                    logger.Log(
                        "Fixing permissions on /data/local.prop and rebooting")
                    self._ChmodRuntimeReset()

    def _ChmodRuntimeReset(self):
        """Perform a chmod of /data/local.prop and reset the runtime.
    """
        logger.Log("adb shell chmod 644 /data/local.prop ## u+w,a+r")
        if not self._options.preview:
            self._adb.SendShellCommand("chmod 644 /data/local.prop")

        self._adb.RuntimeReset(preview_only=self._options.preview)

        if not self._options.preview:
            self._adb.EnableAdbRoot()

    def RunTests(self):
        """Main entry method - executes the tests according to command line args."""
        try:
            run_command.SetAbortOnError()
            self._ProcessOptions()
            if self._options.only_list_tests:
                self._DumpTests()
                return

            if not self._options.skip_build:
                self._DoBuild()

            if self._options.build_install_only:
                logger.Log(
                    "Skipping test execution (due to --build-install-only flag)"
                )
                return

            for test_suite in self._GetTestsToRun():
                try:
                    test_suite.Run(self._options, self._adb)
                except errors.WaitForResponseTimedOutError:
                    logger.Log("Timed out waiting for response")

        except KeyboardInterrupt:
            logger.Log("Exiting...")
        except errors.AbortError, error:
            logger.Log(error.msg)
            logger.SilentLog("Exiting due to AbortError...")
        except errors.WaitForResponseTimedOutError:
            logger.Log("Timed out waiting for response")
示例#21
0
    def _DoPermissionAwareBuild(self, tests, test_requires_permissions):
        # turn off dalvik verifier if necessary
        # TODO: skip turning off verifier for now, since it puts device in bad
        # state b/14088982
        #self._TurnOffVerifier(tests)
        self._DoFullBuild(tests, test_requires_permissions)

        target_tree = make_tree.MakeTree()

        extra_args_set = []
        for test_suite in tests:
            if test_suite.IsGrantedPermissions() == test_requires_permissions:
                self._AddBuildTarget(test_suite, target_tree, extra_args_set)

        if not self._options.preview:
            self._adb.EnableAdbRoot()
        else:
            logger.Log("adb root")

        if not target_tree.IsEmpty():
            if self._options.coverage:
                coverage.EnableCoverageBuild()
                target_tree.AddPath("external/emma")

            target_list = target_tree.GetPrunedMakeList()
            target_dir_list = [
                re.sub(r'Android[.]mk$', r'', i) for i in target_list
            ]
            target_build_string = " ".join(target_list)
            target_dir_build_string = " ".join(target_dir_list)
            extra_args_string = " ".join(extra_args_set)

            install_path_goals = []
            mmma_goals = []
            for d in target_dir_list:
                if d.startswith("./"):
                    d = d[2:]
                if d.endswith("/"):
                    d = d[:-1]
                install_path_goals.append("GET-INSTALL-PATH-IN-" +
                                          d.replace("/", "-"))
                mmma_goals.append("MODULES-IN-" + d.replace("/", "-"))
            # mmm cannot be used from python, so perform a similar operation using
            # ONE_SHOT_MAKEFILE
            cmd = 'ONE_SHOT_MAKEFILE="%s" make -j%s -C "%s" %s %s %s' % (
                target_build_string, self._options.make_jobs, self._root_path,
                " ".join(install_path_goals), " ".join(mmma_goals),
                extra_args_string)
            # mmma cannot be used from python, so perform a similar operation
            alt_cmd = 'make -j%s -C "%s" -f build/core/main.mk %s %s' % (
                self._options.make_jobs, self._root_path, extra_args_string,
                " ".join(mmma_goals))

            logger.Log(cmd)
            if not self._options.preview:
                run_command.SetAbortOnError()
                try:
                    output = run_command.RunCommand(cmd,
                                                    return_output=True,
                                                    timeout_time=600)
                    ## Chances are this failed because it didn't build the dependencies
                except errors.AbortError:
                    logger.Log(
                        "make failed. Trying to rebuild all dependencies.")
                    logger.Log(
                        "mmma -j%s %s" %
                        (self._options.make_jobs, target_dir_build_string))
                    # Try again with mma equivalent, which will build the dependencies
                    run_command.RunCommand(alt_cmd,
                                           return_output=False,
                                           timeout_time=600)
                    # Run mmm again to get the install paths only
                    output = run_command.RunCommand(cmd,
                                                    return_output=True,
                                                    timeout_time=600)
                run_command.SetAbortOnError(False)
                logger.SilentLog(output)
                self._DoInstall(output, test_requires_permissions)
示例#22
0
## 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
##
## 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
##
## 3. The name of the author may not be used to endorse or promote products derived from this software without specific prior written permission from the author.
##
## 4. Products derived from this software may not be called "pyTile" nor may "pyTile" appear in their names without specific prior written permission from the author.
##
## THIS SOFTWARE IS PROVIDED BY THE AUTHOR "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

import os, sys
import pygame
import random

import logger
debug = logger.Log()

# Pre-compute often used multiples
p = 64
p2 = p / 2
p4 = p / 4
p4x3 = p4 * 3
p8 = p / 8
p16 = p / 16

#tile height difference
ph = 8


class TGrid(object):
    """Represents a tile's vertex height and can be used to modify that height"""
示例#23
0
from bs4 import BeautifulSoup
import gspread
import json
import logger
import requests
import time
import quopri
from inbox import Inbox
from oauth2client.service_account import ServiceAccountCredentials

log = logger.Log(__file__)

############ GSPREAD ############
GAPI_CREDENTIALS = "account_key.json"


class SheetsAPI():
    def __init__(self):
        # Use Google Sheets API's credentials.json to access services
        scope = [
            'https://spreadsheets.google.com/feeds',
            'https://www.googleapis.com/auth/drive'
        ]
        creds = ServiceAccountCredentials.from_json_keyfile_name(
            GAPI_CREDENTIALS, scope)
        client = gspread.authorize(creds)
        self.sheet = client.open('Finance').worksheet("PetrolSF")

    # Returns previous mileage (most recent mileage in GSheet logs)
    def get_prev_mileage(self):
        last_row = self.next_available_row() - 1
示例#24
0
        if runtime_restart:
            self.SendShellCommand("setprop ro.test_harness 1",
                                  retry_count=retry_count)
            # manual rest bootcomplete flag
            self.SendShellCommand("setprop dev.bootcomplete 0",
                                  retry_count=retry_count)
            self.SendShellCommand("stop", retry_count=retry_count)

        try:
            output = self.SendCommand("sync", retry_count=retry_count)
        except errors.AbortError, e:
            error = e
            output = e.msg
        if "Read-only file system" in output:
            logger.SilentLog(output)
            logger.Log("Remounting read-only filesystem")
            self.SendCommand("remount")
            output = self.SendCommand("sync", retry_count=retry_count)
        elif "No space left on device" in output:
            logger.SilentLog(output)
            logger.Log("Restarting device runtime")
            self.SendShellCommand("stop", retry_count=retry_count)
            output = self.SendCommand("sync", retry_count=retry_count)
            self.SendShellCommand("start", retry_count=retry_count)
        elif error is not None:
            # exception occurred that cannot be recovered from
            raise error
        logger.SilentLog(output)
        if runtime_restart:
            # start runtime and wait till boot complete flag is set
            self.SendShellCommand("start", retry_count=retry_count)
示例#25
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import commands
import logger
import os
import time

log = logger.Log('INFO', os.path.split(__file__)[1])
screen_shot_path = os.path.join(os.getcwd(), 'screenshot')


def check_devices():
    cmd = commands.getstatusoutput('adb devices')
    result = cmd[1].split('\n')
    if len(result) <= 2:
        log.warn('There is no device connected currently, please check!')
        return False
    elif len(result) <= 3:
        phone_status = cmd[1].split('\n')[1].split('\t')[1]
        if phone_status != 'device':
            log.warn('Phone status is {' + phone_status +
                     '}, connection is limited!')
            log.warn(
                'Please replug the cable and confirm the notice of the phone!')
            return False
        else:
            return True
    else:
        for info in result:
            if info: log.info('    ' + info)
示例#26
0
  def Run(self, options, adb):
    """Run the provided *native* test suite.

    The test_suite must contain a build path where the native test
    files are. Subdirectories are automatically scanned as well.

    Each test's name must have a .cc or .cpp extension and match one
    of the following patterns:
      - test_*
      - *_test.[cc|cpp]
      - *_unittest.[cc|cpp]
    A successful test must return 0. Any other value will be considered
    as an error.

    Args:
      options: command line options
      adb: adb interface
    """
    # find all test files, convert unicode names to ascii, take the basename
    # and drop the .cc/.cpp  extension.
    source_list = []
    build_path = os.path.join(android_build.GetTop(), self.GetBuildPath())
    os.path.walk(build_path, self._CollectTestSources, source_list)
    logger.SilentLog("Tests source %s" % source_list)

    # Host tests are under out/host/<os>-<arch>/bin.
    host_list = self._FilterOutMissing(android_build.GetHostBin(), source_list)
    logger.SilentLog("Host tests %s" % host_list)

    # Target tests are under $ANDROID_PRODUCT_OUT/system/bin.
    target_list = self._FilterOutMissing(android_build.GetTargetSystemBin(),
                                         source_list)
    logger.SilentLog("Target tests %s" % target_list)

    # Run on the host
    logger.Log("\nRunning on host")
    for f in host_list:
      if run_command.RunHostCommand(f) != 0:
        logger.Log("%s... failed" % f)
      else:
        if run_command.HasValgrind():
          if run_command.RunHostCommand(f, valgrind=True) == 0:
            logger.Log("%s... ok\t\t[valgrind: ok]" % f)
          else:
            logger.Log("%s... ok\t\t[valgrind: failed]" % f)
        else:
          logger.Log("%s... ok\t\t[valgrind: missing]" % f)

    # Run on the device
    logger.Log("\nRunning on target")
    for f in target_list:
      full_path = os.path.join(os.sep, "system", "bin", f)

      # Single quotes are needed to prevent the shell splitting it.
      output = adb.SendShellCommand("'%s 2>&1;echo -n exit code:$?'" %
                                    "(cd /sdcard;%s)" % full_path,
                                    int(options.timeout))
      success = output.endswith("exit code:0")
      logger.Log("%s... %s" % (f, success and "ok" or "failed"))
      # Print the captured output when the test failed.
      if not success or options.verbose:
        pos = output.rfind("exit code")
        output = output[0:pos]
        logger.Log(output)

      # Cleanup
      adb.SendShellCommand("rm %s" % full_path)
    def Run(self, options, adb):
        """Run the provided test suite.

    Builds up an adb instrument command using provided input arguments.

    Args:
      options: command line options to provide to test run
      adb: adb_interface to device under test

    Raises:
      errors.AbortError: if fatal error occurs
    """

        test_class = self.GetClassName()
        if options.test_class is not None:
            test_class = options.test_class.lstrip()
            if test_class.startswith("."):
                test_class = self.GetPackageName() + test_class
        if options.test_method is not None:
            test_class = "%s#%s" % (test_class, options.test_method)

        test_package = self.GetJavaPackageFilter()
        if options.test_package:
            test_package = options.test_package

        if test_class and test_package:
            logger.Log(
                'Error: both class and java package options are specified')

        instrumentation_args = {}
        if test_class is not None:
            instrumentation_args["class"] = test_class
        if test_package:
            instrumentation_args["package"] = test_package
        if options.test_size:
            instrumentation_args["size"] = options.test_size
        if options.wait_for_debugger:
            instrumentation_args["debug"] = "true"
        if options.suite_assign_mode:
            instrumentation_args["suiteAssignment"] = "true"
        if options.coverage:
            instrumentation_args["coverage"] = "true"
        if options.test_annotation:
            instrumentation_args["annotation"] = options.test_annotation
        if options.test_not_annotation:
            instrumentation_args["notAnnotation"] = options.test_not_annotation
        if options.preview:
            adb_cmd = adb.PreviewInstrumentationCommand(
                package_name=self.GetPackageName(),
                runner_name=self.GetRunnerName(),
                raw_mode=options.raw_mode,
                instrumentation_args=instrumentation_args)
            logger.Log(adb_cmd)
        elif options.coverage:
            coverage_gen = coverage.CoverageGenerator(adb)
            if not coverage_gen.TestDeviceCoverageSupport():
                raise errors.AbortError
            adb.WaitForInstrumentation(self.GetPackageName(),
                                       self.GetRunnerName())
            # need to parse test output to determine path to coverage file
            logger.Log("Running in coverage mode, suppressing test output")
            try:
                (test_results,
                 status_map) = adb.StartInstrumentationForPackage(
                     package_name=self.GetPackageName(),
                     runner_name=self.GetRunnerName(),
                     timeout_time=60 * 60,
                     instrumentation_args=instrumentation_args)
            except errors.InstrumentationError, errors.DeviceUnresponsiveError:
                return
            self._PrintTestResults(test_results)
            device_coverage_path = status_map.get("coverageFilePath", None)
            if device_coverage_path is None:
                logger.Log("Error: could not find coverage data on device")
                return

            coverage_file = coverage_gen.ExtractReport(
                self, device_coverage_path, test_qualifier=options.test_size)
            if coverage_file is not None:
                logger.Log("Coverage report generated at %s" % coverage_file)
示例#28
0
            if launcher.VERSION == newest_version:
                self.log.debug(f"Up to date ({launcher.VERSION})")
            else:  # out of date
                self.log.error(
                    f"Out of date, newest version is {newest_version} (this is {launcher.VERSION})",
                    reportable=False)

                # save available version for the launcher
                db: Dict[str, Union[bool, list, str]] = utils.access_db()
                db['available_version'] = newest_version
                utils.access_db(db)

                return newest_version, downloads_url, changelog_formatted


def format_changelog(log_text: str) -> str:
    return f'  {log_text}'.replace('## ', '').replace('\r\n', '\n').replace(
        '\n- ', '\n - ').replace('\n', '\n  ')


class RateLimitError(Exception):
    pass


if __name__ == '__main__':
    update_checker = UpdateChecker(logger.Log())
    update_checker.initiate_update_check(True, 10.0)
    while not update_checker.update_check_ready():
        time.sleep(0.2)
    print(update_checker.receive_update_check())
示例#29
0
    def StartInstrumentation(self,
                             instrumentation_path,
                             timeout_time=60 * 10,
                             no_window_animation=False,
                             profile=False,
                             instrumentation_args={}):
        """Runs an instrumentation class on the target.

    Returns a dictionary containing the key value pairs from the
    instrumentations result bundle and a list of TestResults. Also handles the
    interpreting of error output from the device and raises the necessary
    exceptions.

    Args:
      instrumentation_path: string. It should be the fully classified package
      name, and instrumentation test runner, separated by "/"
        e.g. com.android.globaltimelaunch/.GlobalTimeLaunch
      timeout_time: Timeout value for the am command.
      no_window_animation: boolean, Whether you want window animations enabled
        or disabled
      profile: If True, profiling will be turned on for the instrumentation.
      instrumentation_args: Dictionary of key value bundle arguments to pass to
      instrumentation.

    Returns:
      (test_results, inst_finished_bundle)

      test_results: a list of TestResults
      inst_finished_bundle (dict): Key/value pairs contained in the bundle that
        is passed into ActivityManager.finishInstrumentation(). Included in this
        bundle is the return code of the Instrumentation process, any error
        codes reported by the activity manager, and any results explicitly added
        by the instrumentation code.

     Raises:
       WaitForResponseTimedOutError: if timeout occurred while waiting for
         response to adb instrument command
       DeviceUnresponsiveError: if device system process is not responding
       InstrumentationError: if instrumentation failed to run
    """

        command_string = self._BuildInstrumentationCommandPath(
            instrumentation_path,
            no_window_animation=no_window_animation,
            profile=profile,
            raw_mode=True,
            instrumentation_args=instrumentation_args)
        logger.Log(command_string)
        (test_results,
         inst_finished_bundle) = (am_instrument_parser.ParseAmInstrumentOutput(
             self.SendShellCommand(command_string,
                                   timeout_time=timeout_time,
                                   retry_count=2)))

        if "code" not in inst_finished_bundle:
            raise errors.InstrumentationError(
                "no test results... device setup "
                "correctly?")

        if inst_finished_bundle["code"] == "0":
            short_msg_result = "no error message"
            if "shortMsg" in inst_finished_bundle:
                short_msg_result = inst_finished_bundle["shortMsg"]
                logger.Log("Error! Test run failed: %s" % short_msg_result)
            raise errors.InstrumentationError(short_msg_result)

        if "INSTRUMENTATION_ABORTED" in inst_finished_bundle:
            logger.Log("INSTRUMENTATION ABORTED!")
            raise errors.DeviceUnresponsiveError

        return (test_results, inst_finished_bundle)
示例#30
0
def DownloadData(count, table):  #Ranking, Members, MedalRarity
    payload = {"api_key": c.api_key, "table": table, "count": count}
    r = requests.post(c.url_down, data=payload)
    logger.Log("Download " + str(count) + " " + table + ": " + r.text[:100])
    return json.loads(r.text)