Ejemplo n.º 1
0
def RunOnce(device, url, warmup, speculation_mode, delay_to_may_launch_url,
            delay_to_launch_url, cold, chrome_args, reset_chrome_state):
    """Runs a test on a device once.

  Args:
    device: (DeviceUtils) device to run the tests on.
    url: (str) URL to load.
    warmup: (bool) Whether to call warmup.
    speculation_mode: (str) Speculation Mode.
    delay_to_may_launch_url: (int) Delay to mayLaunchUrl() in ms.
    delay_to_launch_url: (int) Delay to launchUrl() in ms.
    cold: (bool) Whether the page cache should be dropped.
    chrome_args: ([str]) List of arguments to pass to Chrome.
    reset_chrome_state: (bool) Whether to reset the Chrome local state before
                        the run.

  Returns:
    The output line (str), like this (one line only):
    <warmup>,<prerender_mode>,<delay_to_may_launch_url>,<delay_to_launch>,
      <intent_sent_ms>,<page_load_started_ms>,<page_load_finished_ms>,
      <first_contentful_paint>
    or None on error.
  """
    if not device.HasRoot():
        device.EnableRoot()

    timeout_s = 20
    logcat_timeout = int(timeout_s + delay_to_may_launch_url / 1000. +
                         delay_to_launch_url / 1000.) + 3

    with device_setup.FlagReplacer(device, _COMMAND_LINE_PATH, chrome_args):
        launch_intent = intent.Intent(
            action='android.intent.action.MAIN',
            package=_TEST_APP_PACKAGE_NAME,
            activity='org.chromium.customtabs.test.MainActivity',
            extras={
                'url': str(url),
                'warmup': warmup,
                'speculation_mode': str(speculation_mode),
                'delay_to_may_launch_url': delay_to_may_launch_url,
                'delay_to_launch_url': delay_to_launch_url,
                'timeout': timeout_s
            })
        result_line_re = re.compile(r'CUSTOMTABSBENCH.*: (.*)')
        logcat_monitor = device.GetLogcatMonitor(clear=True)
        logcat_monitor.Start()
        device.ForceStop(_CHROME_PACKAGE)
        device.ForceStop(_TEST_APP_PACKAGE_NAME)

        if reset_chrome_state:
            ResetChromeLocalState(device)

        if cold:
            cache_control.CacheControl(device).DropRamCaches()

        device.StartActivity(launch_intent, blocking=True)

        match = None
        try:
            match = logcat_monitor.WaitFor(result_line_re,
                                           timeout=logcat_timeout)
        except device_errors.CommandTimeoutError as _:
            logging.warning('Timeout waiting for the result line')
        logcat_monitor.Stop()
        logcat_monitor.Close()
        return match.group(1) if match is not None else None
 def FlushEntireSystemCache(self):
     cache = cache_control.CacheControl(self._device)
     cache.DropRamCaches()
Ejemplo n.º 3
0
 def drop_ram_caches(self):
     """Drop ran caches on device."""
     cache = cache_control.CacheControl(self.device)
     cache.DropRamCaches()