blob: 98cea7cf5e5ef962c9b58e0c25422a46c44f70b3 [file] [log] [blame]
# Copyright (c) 2014 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 time
from autotest_lib.client.common_lib import error
from autotest_lib.server import test
class platform_ServoPowerStateController(test.test):
"""Test servo can power on and off DUT in recovery and non-recovery mode."""
version = 1
def initialize(self, host):
"""Initialize DUT for testing."""
def cleanup(self):
"""Clean up DUT after servo actions."""
if not
# Power off, then power on DUT from internal storage.
def assert_dut_on(self, rec_on=False):
"""Confirm DUT is powered on, claim test failure if DUT is off.
@param rec_on: True if DUT should boot from external USB stick as in
recovery mode.
@raise TestFail: If DUT is off or DUT boot from wrong source.
if not
raise error.TestFail('power_state:%s did not turn DUT on.' %
('rec' if rec_on else 'on'))
# Check boot source. Raise TestFail if DUT boot from wrong source.
boot_from_usb =
if boot_from_usb != rec_on:
boot_source = ('USB' if boot_from_usb else
'non-removable storage')
raise error.TestFail('power_state:%s booted from %s.' %
('rec' if rec_on else 'on', boot_source))
def assert_dut_off(self, error_message):
"""Confirm DUT is off and does not turn back on after 30 seconds.
@param error_message: Error message to raise if DUT stays on.
@raise TestFail: If DUT stays on.
if not
raise error.TestFail(error_message)
raise error.TestFail('%s. %s' % (error_message, 'DUT turns back on'
' after it is turned off.'))
def test_with_usb_plugged_in(self):
"""Run test when USB stick is plugged in to servo."""'Power off DUT')
self.assert_dut_off('power_state:off did not turn DUT off.')'Power DUT on in recovery mode, DUT shall boot from USB.')'off')
self.assert_dut_off('power_state:rec didn\'t stay at recovery screen.')'dut')
self.assert_dut_on(rec_on=True)'Power off DUT which is up in recovery mode.')
self.assert_dut_off('power_state:off failed after boot from external '
'USB stick.')'Power DUT off in recovery mode without booting.')'off')
self.assert_dut_off('power_state:off failed at recovery screen ')
# Power DUT on in non-recovery mode with USB stick plugged in.
# DUT shall boot from internal storage.'Power on DUT in non-recovery mode.')'dut')
def test_with_usb_unplugged(self):
"""Run test when USB stick is not plugged in servo."""
# Power off DUT regardless its current status.'Power off DUT.')
self.assert_dut_off('power_state:off did not turn DUT off.')
# Try to power off the DUT again, make sure the DUT stays off.'Power off DUT which is already off.')
self.assert_dut_off('power_state:off turned DUT on.')
# USB stick should be unplugged before the test.'off')'Power on in non-recovery mode.')
self.assert_dut_on(rec_on=False)'Power DUT off and on without delay. DUT should be '
'on after power_on is completed.')
self.assert_dut_on(rec_on=False)'Power off DUT which is up in non-recovery mode.')
self.assert_dut_off('power_state:off failed after boot from '
'internal storage.')'Power DUT off and reset. DUT should be on after '
'reset is completed.')
self.assert_dut_on(rec_on=False)'Reset DUT when it\'s on. DUT should be on after '
'reset is completed.')
boot_id =
new_boot_id =
if not new_boot_id or boot_id == new_boot_id:
raise error.TestFail('power_state:reset failed to reboot DUT.')
def run_once(self, host, usb_available=True):
"""Run the test.
@param host: host object of tested DUT.
@param usb_plugged_in: True if USB stick is plugged in servo.
""" = host
self.controller = host.servo.get_power_state_controller()
if usb_available: