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 3 # found in the LICENSE file. 4 5 import os 6 from datetime import datetime 7 from autotest_lib.client.bin import boottool, utils 8 from autotest_lib.client.bin.job import base_client_job 9 from autotest_lib.client.common_lib import error 10 from autotest_lib.client.cros import cros_logging 11 12 13 LAST_BOOT_TAG = object() 14 15 class site_job(base_client_job): 16 17 18 def __init__(self, *args, **kwargs): 19 base_client_job.__init__(self, *args, **kwargs) 20 21 22 def _runtest(self, url, timeout, tag, args, dargs): 23 # this replaced base_client_job._runtest, which is called by 24 # base_client_job.runtest.group_func (see job.py) 25 try: 26 self.last_error = None 27 base_client_job._runtest(self, url, timeout,tag, args, dargs) 28 except error.TestBaseException, detail: 29 self.last_error = detail 30 raise 31 32 33 def run_test(self, url, *args, **dargs): 34 log_pauser = cros_logging.LogRotationPauser() 35 passed = False 36 try: 37 log_pauser.begin() 38 passed = base_client_job.run_test(self, url, *args, **dargs) 39 if not passed: 40 # Save the VM state immediately after the test failure. 41 # This is a NOOP if the the test isn't running in a VM or 42 # if the VM is not properly configured to save state. 43 group, testname = self.pkgmgr.get_package_name(url, 'test') 44 now = datetime.now().strftime('%I:%M:%S.%f') 45 checkpoint_name = '%s-%s' % (testname, now) 46 utils.save_vm_state(checkpoint_name) 47 finally: 48 log_pauser.end() 49 return passed 50 51 52 def reboot(self, tag=LAST_BOOT_TAG): 53 if tag == LAST_BOOT_TAG: 54 tag = self.last_boot_tag 55 else: 56 self.last_boot_tag = tag 57 58 self.reboot_setup() 59 self.harness.run_reboot() 60 61 # sync first, so that a sync during shutdown doesn't time out 62 utils.system('sync; sync', ignore_status=True) 63 64 utils.system('reboot </dev/null >/dev/null 2>&1 &') 65 self.quit() 66 67 68 def require_gcc(self): 69 return False 70