blob: ed18d91a6e537bfba72b16a6e00b3bc0effc221b [file] [log] [blame]
# Copyright (c) 2009 The Chromium OS Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
import logging
import os
import shutil
import traceback
from autotest_lib.client.common_lib import error
from autotest_lib.server import test, autotest
class platform_BootPerfServer(test.test):
version = 1
def run_once(self, host=None):
self.client = host
self.client_test = 'platform_BootPerf'
# Run a login test to complete the OOBE flow, if we haven't already.
# This is so that we measure boot times for the stable state.
try:
self.client.run('ls /home/chronos/.oobe_completed')
except error.AutoservRunError:
logging.info('Taking client through OOBE.')
client_at = autotest.Autotest(self.client)
client_at.run_test('login_LoginSuccess', disable_sysinfo=True)
# Reboot the client
logging.info('BootPerfServer: reboot %s' % self.client.hostname)
try:
self.client.reboot()
except error.AutoservRebootError as e:
raise error.TestFail('%s.\nTest failed with error %s' % (
traceback.format_exc(), str(e)))
# Collect the performance metrics by running a client side test
logging.info('BootPerfServer: start client test')
client_at = autotest.Autotest(self.client)
client_at.run_test(
self.client_test, last_boot_was_reboot=True, disable_sysinfo=True)
# In the client results directory are a 'keyval' file, and
# various raw bootstat data files. First promote the client
# test 'keyval' as our own.
logging.info('BootPerfServer: gather client results')
client_results_dir = os.path.join(
self.outputdir, self.client_test, "results")
src = os.path.join(client_results_dir, "keyval")
dst = os.path.join(self.resultsdir, "keyval")
if os.path.exists(src):
client_results = open(src, "r")
server_results = open(dst, "a")
shutil.copyfileobj(client_results, server_results)
server_results.close()
client_results.close()
else:
logging.warn('Unable to locate %s' % src)
# Everything that isn't the client 'keyval' file is raw data
# from the client test: copy it to a per-iteration
# subdirectory.
if self.iteration is not None:
rawdata_dir = "rawdata.%03d" % self.iteration
else:
rawdata_dir = "rawdata"
rawdata_dir = os.path.join(self.resultsdir, rawdata_dir)
os.mkdir(rawdata_dir)
for fn in os.listdir(client_results_dir):
if fn == "keyval":
continue
shutil.copy(os.path.join(client_results_dir, fn), rawdata_dir)