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 datetime 6import logging 7import time 8from autotest_lib.client.common_lib.cros import arc 9from autotest_lib.client.common_lib.cros import chrome 10from autotest_lib.client.bin import test 11 12 13class cheets_StartAndroid_P(test.test): 14 """Helper to run Android's CTS on autotest. 15 16 Android CTS needs a running Android, which depends on a logged in ChromeOS 17 user. This helper class logs in to ChromeOS and waits for Android boot 18 complete. 19 20 We do not log out, and the machine will be rebooted after test. 21 """ 22 version = 1 23 24 def cleanup(self): 25 if hasattr(self, '_run_times'): 26 logging.debug("Times to start Chrome and Android: %s", 27 self._run_times) 28 # Report the first, second and last start times to perf dashboard. 29 for index in [0, 1, len(self._run_times) - 1]: 30 if index >= len(self._run_times): 31 continue 32 self.output_perf_value( 33 description='Time_to_Start_Chrome_and_Android-%d' % ( 34 index + 1), 35 value=self._run_times[index], 36 units='seconds', 37 higher_is_better=False, 38 replace_existing_values=True, 39 graph="Time_to_start_Chrome_and_Android" 40 ) 41 42 def run_once(self, count=None, dont_override_profile=False): 43 if count: 44 # Run stress test by logging in and starting ARC several times. 45 # Each iteration is about 15s on Samus. 46 self._run_times = [] 47 for i in range(count): 48 logging.info('cheets_StartAndroid iteration %d', i) 49 50 start = datetime.datetime.utcnow() 51 chrome_obj = chrome.Chrome( 52 arc_mode = arc.arc_common.ARC_MODE_ENABLED, 53 dont_override_profile=dont_override_profile) 54 elapsed_time = (datetime.datetime.utcnow() - start 55 ).total_seconds() 56 57 # 2 seconds for chrome to settle down before logging out 58 time.sleep(2) 59 chrome_obj.close() 60 61 self._run_times.append(elapsed_time) 62 else: 63 # Utility used by server tests to login. We do not log out, and 64 # ensure the machine will be rebooted after test. 65 try: 66 self.chrome = chrome.Chrome( 67 dont_override_profile=dont_override_profile, 68 arc_mode=arc.arc_common.ARC_MODE_ENABLED) 69 except: 70 # We are going to paper over some failures here. Notice these 71 # should still be detected by regularly running 72 # cheets_StartAndroid.stress. 73 logging.error('Could not start Chrome. Retrying soon...') 74 # Give system a chance to calm down. 75 time.sleep(20) 76 self.chrome = chrome.Chrome( 77 dont_override_profile=dont_override_profile, 78 arc_mode=arc.arc_common.ARC_MODE_ENABLED, 79 num_tries=3) 80