1a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor# Copyright (c) 2010 The Chromium OS Authors. All rights reserved. 2a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor# Use of this source code is governed by a BSD-style license that can be 3a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor# found in the LICENSE file. 4a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor 5fa61689967461297dc51565a51f4061312cb0f7dKen Mixterimport os 6e7c4cab13a8576a4f9de41b2dc1fb8c45c97424cEric Lifrom datetime import datetime 7e7c4cab13a8576a4f9de41b2dc1fb8c45c97424cEric Lifrom autotest_lib.client.bin import boottool, utils 8fa61689967461297dc51565a51f4061312cb0f7dKen Mixterfrom autotest_lib.client.bin.job import base_client_job 91904d00cebc4212cf929ce6900197407b1990ca8Thieu Lefrom autotest_lib.client.common_lib import error 10e7c4cab13a8576a4f9de41b2dc1fb8c45c97424cEric Lifrom autotest_lib.client.cros import cros_logging 11e7c4cab13a8576a4f9de41b2dc1fb8c45c97424cEric Li 12a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor 13a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'ConnorLAST_BOOT_TAG = object() 14a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor 15a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connorclass site_job(base_client_job): 16e7c4cab13a8576a4f9de41b2dc1fb8c45c97424cEric Li 17e7c4cab13a8576a4f9de41b2dc1fb8c45c97424cEric Li 18a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor def __init__(self, *args, **kwargs): 19a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor base_client_job.__init__(self, *args, **kwargs) 20a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor 21e7c4cab13a8576a4f9de41b2dc1fb8c45c97424cEric Li 22d656d56473f50b9c1a9f5e2b2f5a9472181ee342Eric Li def _runtest(self, url, timeout, tag, args, dargs): 23e4e5344028f4738079ad29b2e9703ffdc9ce3ab2Hung-Te Lin # this replaced base_client_job._runtest, which is called by 24e4e5344028f4738079ad29b2e9703ffdc9ce3ab2Hung-Te Lin # base_client_job.runtest.group_func (see job.py) 25e4e5344028f4738079ad29b2e9703ffdc9ce3ab2Hung-Te Lin try: 26e4e5344028f4738079ad29b2e9703ffdc9ce3ab2Hung-Te Lin self.last_error = None 27d656d56473f50b9c1a9f5e2b2f5a9472181ee342Eric Li base_client_job._runtest(self, url, timeout,tag, args, dargs) 28e4e5344028f4738079ad29b2e9703ffdc9ce3ab2Hung-Te Lin except error.TestBaseException, detail: 29e4e5344028f4738079ad29b2e9703ffdc9ce3ab2Hung-Te Lin self.last_error = detail 30e4e5344028f4738079ad29b2e9703ffdc9ce3ab2Hung-Te Lin raise 31a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor 32e7c4cab13a8576a4f9de41b2dc1fb8c45c97424cEric Li 33fa61689967461297dc51565a51f4061312cb0f7dKen Mixter def run_test(self, url, *args, **dargs): 34e7c4cab13a8576a4f9de41b2dc1fb8c45c97424cEric Li log_pauser = cros_logging.LogRotationPauser() 35f8fc31a1686d7aace0b4b07156d4d6fcb210cf27Hung-Te Lin passed = False 36fa61689967461297dc51565a51f4061312cb0f7dKen Mixter try: 37fa61689967461297dc51565a51f4061312cb0f7dKen Mixter log_pauser.begin() 381904d00cebc4212cf929ce6900197407b1990ca8Thieu Le passed = base_client_job.run_test(self, url, *args, **dargs) 391904d00cebc4212cf929ce6900197407b1990ca8Thieu Le if not passed: 401904d00cebc4212cf929ce6900197407b1990ca8Thieu Le # Save the VM state immediately after the test failure. 411904d00cebc4212cf929ce6900197407b1990ca8Thieu Le # This is a NOOP if the the test isn't running in a VM or 421904d00cebc4212cf929ce6900197407b1990ca8Thieu Le # if the VM is not properly configured to save state. 431904d00cebc4212cf929ce6900197407b1990ca8Thieu Le group, testname = self.pkgmgr.get_package_name(url, 'test') 441904d00cebc4212cf929ce6900197407b1990ca8Thieu Le now = datetime.now().strftime('%I:%M:%S.%f') 451904d00cebc4212cf929ce6900197407b1990ca8Thieu Le checkpoint_name = '%s-%s' % (testname, now) 461904d00cebc4212cf929ce6900197407b1990ca8Thieu Le utils.save_vm_state(checkpoint_name) 47fa61689967461297dc51565a51f4061312cb0f7dKen Mixter finally: 48fa61689967461297dc51565a51f4061312cb0f7dKen Mixter log_pauser.end() 49f8fc31a1686d7aace0b4b07156d4d6fcb210cf27Hung-Te Lin return passed 50fa61689967461297dc51565a51f4061312cb0f7dKen Mixter 51fa61689967461297dc51565a51f4061312cb0f7dKen Mixter 52a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor def reboot(self, tag=LAST_BOOT_TAG): 53a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor if tag == LAST_BOOT_TAG: 54a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor tag = self.last_boot_tag 55a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor else: 56a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor self.last_boot_tag = tag 57a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor 58a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor self.reboot_setup() 59a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor self.harness.run_reboot() 60a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor 61a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor # sync first, so that a sync during shutdown doesn't time out 62f4d43ff1254ac68ebc54442da8ad2821bd16d6cbChris Sosa utils.system('sync; sync', ignore_status=True) 63a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor 64f4d43ff1254ac68ebc54442da8ad2821bd16d6cbChris Sosa utils.system('reboot </dev/null >/dev/null 2>&1 &') 65a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor self.quit() 66a2394f25cc3dea7848f90270cb1dfa830f8b4482Sean O'Connor 67a11a045e56301bea09f54581c5ec5e08d328d03eEric Li 68a11a045e56301bea09f54581c5ec5e08d328d03eEric Li def require_gcc(self): 69a11a045e56301bea09f54581c5ec5e08d328d03eEric Li return False 70