blob: 5e628ed35df9d43bd2a5fc72bb8d070fdb186dc1 [file] [log] [blame]
# Copyright 2012 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.
"""A test to make sure everything is set for the following test in test list.
This test checks everything is set for the following tests in the test list,
including make sure an external power supplier is presence, checking factory
software is installed, etc.
Normally, this test should be placed as the first one in a test list, to make
sure everything is set before performing any other tests.
Test Procedure
It checks several conditions as specified by the options, and ask the operator
to press a key to pass.
If argument ``require_external_power`` is set, it reads
``/sys/class/power_supply/`` to determine if an external power supply is
To initialize shared data, then ask the operator to press a key to continue,
add this in test list::
"pytest_name": "start"
To also ensure if an external power supply is connected, and check factory
toolkit is properly installed::
"pytest_name": "start",
"args": {
"check_factory_install_complete": true,
"require_external_power": true
import logging
import os
import factory_common # pylint: disable=unused-import
from cros.factory.device import device_utils
from cros.factory.test.event_log import Log
from cros.factory.test import session
from cros.factory.test.i18n import _
from cros.factory.test.i18n import arg_utils as i18n_arg_utils
from cros.factory.test import state
from cros.factory.test import test_case
from cros.factory.test import test_ui
from cros.factory.utils.arg_utils import Arg
from cros.factory.utils import log_utils
_LSB_FACTORY_PATH = '/usr/local/etc/lsb-factory'
class StartTest(test_case.TestCase):
"""The factory test to start the whole factory test process."""
ARGS = [
Arg('press_to_continue', bool, 'Need to press space to continue',
Arg('require_external_power', bool,
'Prompts and waits for external power to be applied.',
Arg('check_factory_install_complete', bool,
'Check factory install process was complete.',
'prompt', 'Message to show to the operator when prompting for input.',
default=_('Enter valid serial number:<br>')),
Arg('init_shared_data', dict, 'the shared data to initialize',
def setUp(self):
self.dut = device_utils.CreateDUTInterface()
self.ui.ToggleTemplateClass('font-large', True)
def runTest(self):
if self.args.init_shared_data:
if self.args.check_factory_install_complete:
if self.args.require_external_power:
if self.args.press_to_continue:
self.ui.SetState(_('Hit SPACE to start testing...'))
def CheckExternalPower(self):
logger = log_utils.NoisyLogger(
self.ui.SetState(_('Plug in external power to continue.'))
while True:
ac_present = self.dut.power.CheckACPresent()
logger.Log('power state: %s', ac_present)
Log('ac_present', state=ac_present)
if ac_present:
def CheckFactoryInstallComplete(self):
if not os.path.exists(_LSB_FACTORY_PATH):
session.console.error('%s is missing', _LSB_FACTORY_PATH)
'<span class="test-error">',
_('Factory install process did not complete. '
'Auto-testing stopped.<br><br>'
'Please install the factory test image using factory server<br>'
'rather than booting from a USB drive.<br>'), '</span>'
# hangs forever.
def InitializeSharedData(self):
self.ui.SetState(_('Initialize some shared data...'))
for key, value in self.args.init_shared_data.iteritems():
session.console.debug('DataShelfSetValue[%s] = "%s"', key, value)
state.DataShelfSetValue(key, value)