blob: bb10717265c7c7985c277f19aa941d3985ebc55a [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.
"""Checks and updates touch device firmware."""
import glob
import logging
import os
import unittest
import factory_common # pylint: disable=unused-import
from cros.factory.test import session
from cros.factory.utils.arg_utils import Arg
from cros.factory.utils import process_utils
FIRMWARE_UPDATER = '/opt/google/touch/scripts/'
CONFIG_UPDATER = '/opt/google/touch/scripts/'
class UpdateTouchDeviceFWTest(unittest.TestCase):
ARGS = [
Arg('device_name', str, 'Name of the touch device as in'
Arg('fw_name', str, 'Expected firmware file name (in /lib/firmware)'),
Arg('fw_version', str, 'Expected firmware version'),
def run_updater_command(self, command):'Running: %s', command)
updater = process_utils.Spawn(command,
log=True, read_stdout=True, shell=True)
if updater.returncode != 0:
error_message = 'Touch device %s update failed.' % self.args.device_name
logging.error(' stdout: %s', updater.stdout_data)
logging.error(' stderr: %s', updater.stderr_data)
raise ValueError(error_message)
def runTest(self):
# Find the appropriate device sysfs file.
devices = [x for x in glob.glob('/sys/bus/i2c/devices/*/name')
if open(x).read().strip() == self.args.device_name]
1, len(devices),
'Expected to find one device but found %s' % devices)
device_path = os.path.dirname(devices[0])
expected_ver = getattr(self.args, 'fw_version')
actual_ver = open(os.path.join(device_path, 'fw_version')).read().strip()
if expected_ver != actual_ver:'Updating firmware from version %s to version %s',
actual_ver, expected_ver)
firmware_updater_cmd = '%s -f -d %s -n %s' % (
FIRMWARE_UPDATER, self.args.device_name, self.args.fw_name)
# Always force-update the device configuration'Updating device configuration.')
config_updater_cmd = '%s -f -d %s' % (CONFIG_UPDATER, self.args.device_name)