Home | History | Annotate | Download | only in hardware_DiskFirmwareUpgrade
      1 # Copyright (c) 2013 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, os.path, re
      6 from autotest_lib.client.common_lib import error
      7 from autotest_lib.server import autotest, test
      8 
      9 class hardware_DiskFirmwareUpgrade(test.test):
     10     """
     11     Integrity stress test for storage device
     12     """
     13     version = 1
     14 
     15     TEST_NAME='hardware_DiskFirmwareUpgrade'
     16     TEST_SCRIPT='/usr/sbin/chromeos-disk-firmware-update.sh'
     17     DEFAULT_LOCATION='/opt/google/disk/firmware'
     18 
     19     _client_install_path = None
     20 
     21 
     22     def _exists_on_client(self, f):
     23         return self._client.run('ls "%s"' % f,
     24                                ignore_status=True).exit_status == 0
     25 
     26     def _get_model_name(self):
     27         """ Return the name of an ATA/SCSI device. """
     28         return self._client.run(
     29             'cat /sys/block/$(basename $(rootdev -s -d))/device/model').stdout
     30 
     31     def _get_device_name(self):
     32         """ Return the name of an eMMC device, using cid data."""
     33         return self._client.run(
     34             'cat /sys/block/$(basename $(rootdev -s -d))/device/cid | cut -c 7-18').stdout
     35 
     36     def run_once(self, host, disk_fw_packages):
     37         """
     38         For every firmware package in disk_fw_packages, we launch the sibbling
     39         client test if:
     40         - the script to install the package is present
     41         - the model of the device present matches the defined model regex.
     42         We launch the slibbing client test a second time to put the machine
     43         in a well-known state.
     44 
     45         @param host:     machine to use.
     46         @param disk_fw_packages: directory of firmare to use and
     47                          expected return code. See control for details.
     48         """
     49 
     50         self._client = host
     51         self._client_at = autotest.Autotest(self._client)
     52         # First, check if the machine image contains the
     53         # upgrade script.
     54         if not self._exists_on_client(self.TEST_SCRIPT):
     55             raise error.TestNAError('Firmware upgrade not supported')
     56 
     57         # Retrieve model name.
     58         try:
     59             model = self._get_model_name()
     60         except error.AutoservRunError:
     61             model = self._get_device_name()
     62 
     63         i = 0
     64         for model_re, package_desc in disk_fw_packages.iteritems():
     65             if not re.match(model_re, model):
     66                 continue
     67             for p, results in package_desc.iteritems():
     68                 result_dir = '-'.join([self.TEST_NAME, str(i), p])
     69                 if p.startswith('test_'):
     70                     self._client_at.run_test(
     71                             self.TEST_NAME,
     72                             results_dir=result_dir,
     73                             disk_firmware_package=self.DEFAULT_LOCATION + '-test',
     74                             expected_result=results[0],
     75                             upgrade_required=results[1])
     76                 else:
     77                     # We are not expecting downloads.
     78                     self._tmpdir = self._client.get_tmp_dir()
     79                     self._client.send_file(os.path.join(self.bindir, p),
     80                                            self._tmpdir)
     81                     self._client_at.run_test(
     82                             self.TEST_NAME,
     83                             results_dir=result_dir,
     84                             disk_firmware_package=os.path.join(self._tmpdir, p),
     85                             expected_result=results[0],
     86                             upgrade_required=results[1])
     87                 result_dir = '-'.join([self.TEST_NAME, str(i), '~base'])
     88                 self._client_at.run_test(
     89                         self.TEST_NAME,
     90                         results_dir=result_dir,
     91                         disk_firmware_package=self.DEFAULT_LOCATION,
     92                         upgrade_required=results[1])
     93                 i += 1
     94 
     95