1# Copyright 2016 The Chromium OS Authors. All rights reserved.
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import logging
6import time
7from autotest_lib.client.common_lib.cros import arc
8from autotest_lib.client.common_lib.cros import chrome
9from autotest_lib.client.bin import test
10
11
12class cheets_CTSHelper(test.test):
13    """Helper to run Android's CTS on autotest.
14
15    Android CTS needs a running Android, which depends on a logged in ChromeOS
16    user. This helper class logs in to ChromeOS and waits for Android boot
17    complete.
18
19    We do not log out, and the machine will be rebooted after test.
20    """
21    version = 1
22
23    def run_once(self, count=None):
24        if count:
25            # Run stress test by logging in and starting ARC several times.
26            # Each iteration is about 15s on Samus.
27            for i in range(count):
28                logging.info('cheets_CTSHelper iteration %d', i)
29                with chrome.Chrome(
30                        arc_mode=arc.arc_common.ARC_MODE_ENABLED) as _:
31                    time.sleep(2)
32        else:
33            # Utility used by server tests to login. We do not log out, and
34            # ensure the machine will be rebooted after test.
35            try:
36                self.chrome = chrome.Chrome(
37                            arc_mode=arc.arc_common.ARC_MODE_ENABLED,
38                            init_network_controller=False)
39            except:
40                # We are going to paper over some failures here. Notice these
41                # should still be detected by regularly running
42                # cheets_CTSHelper.stress.
43                logging.error('Could not start Chrome. Retrying soon...')
44                # Give system a chance to calm down.
45                time.sleep(20)
46                self.chrome = chrome.Chrome(
47                            arc_mode=arc.arc_common.ARC_MODE_ENABLED,
48                            num_tries=3,
49                            init_network_controller=False)
50