| OLD | NEW |
| 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. | 1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved. |
| 2 # Use of this source code is governed by a BSD-style license that can be | 2 # Use of this source code is governed by a BSD-style license that can be |
| 3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
| 4 | 4 |
| 5 import logging, os, re, time | 5 import logging, os, re, time |
| 6 from autotest_lib.client.bin import site_login, site_ui_test, site_utils | 6 from autotest_lib.client.bin import site_login, site_ui_test, site_utils |
| 7 from autotest_lib.client.common_lib import error | 7 from autotest_lib.client.common_lib import error |
| 8 | 8 |
| 9 class desktopui_ChromeFirstRender(site_ui_test.UITest): | 9 class desktopui_ChromeFirstRender(site_ui_test.UITest): |
| 10 version = 1 | 10 version = 1 |
| 11 | 11 |
| 12 | 12 |
| 13 _LOGIN_SUCCESS_FILE = '/tmp/uptime-login-success' | 13 _LOGIN_SUCCESS_FILE = '/tmp/uptime-login-success' |
| 14 _FIRST_RENDER_FILE = '/tmp/uptime-chrome-first-render' | 14 _FIRST_RENDER_FILE = '/tmp/uptime-chrome-first-render' |
| 15 | 15 |
| 16 def __parse_uptime(self, target_file): | 16 def __parse_uptime(self, target_file): |
| 17 data = file(target_file).read() | 17 data = file(target_file).read() |
| 18 time = re.split(r' +', data.strip())[0] | 18 time = re.split(r' +', data.strip())[0] |
| 19 return float(time) | 19 return float(time) |
| 20 | 20 |
| 21 | 21 |
| 22 def run_once(self): | 22 def run_once(self): |
| 23 try: | 23 try: |
| 24 site_utils.poll_for_condition( | 24 site_utils.poll_for_condition( |
| 25 lambda: os.access(self._LOGIN_SUCCESS_FILE, os.F_OK), | 25 lambda: os.access(self._LOGIN_SUCCESS_FILE, os.F_OK), |
| 26 site_login.TimeoutError('Timed out waiting for initial login')) | 26 site_login.TimeoutError('Timed out waiting for initial login')) |
| 27 site_utils.poll_for_condition( | 27 site_utils.poll_for_condition( |
| 28 lambda: os.access(self._FIRST_RENDER_FILE, os.F_OK), | 28 lambda: os.access(self._FIRST_RENDER_FILE, os.F_OK), |
| 29 site_login.TimeoutError('Timed out waiting for initial render')) | 29 site_login.TimeoutError('Timed out waiting for initial render'), |
| 30 timeout=60) |
| 30 | 31 |
| 31 start_time = self.__parse_uptime(self._LOGIN_SUCCESS_FILE) | 32 start_time = self.__parse_uptime(self._LOGIN_SUCCESS_FILE) |
| 32 end_time = self.__parse_uptime(self._FIRST_RENDER_FILE) | 33 end_time = self.__parse_uptime(self._FIRST_RENDER_FILE) |
| 33 self.write_perf_keyval( | 34 self.write_perf_keyval( |
| 34 { 'seconds_chrome_first_tab': end_time - start_time }) | 35 { 'seconds_chrome_first_tab': end_time - start_time }) |
| 35 except IOError, e: | 36 except IOError, e: |
| 36 logging.debug(e) | 37 logging.debug(e) |
| 37 raise error.TestFail('Login information missing') | 38 raise error.TestFail('Login information missing') |
| OLD | NEW |