Home | History | Annotate | Download | only in firmware_Cr50USB
      1 # Copyright 2017 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 logging
      6 import time
      7 
      8 from autotest_lib.client.common_lib import error
      9 from autotest_lib.server import autotest, test
     10 
     11 
     12 class firmware_Cr50USB(test.test):
     13     """
     14     Stress the Cr50 usb connection to the DUT.
     15 
     16     This test is intended to be run with many iterations to ensure that the
     17     USB connection is not flaky.
     18 
     19     The iteration should be specified by the parameter -a "num_iterations=10".
     20 
     21     To exit on the first USB failure use  "exit_condition='immediately'".
     22     """
     23     version = 1
     24 
     25     SLEEP_DELAY = 20
     26 
     27     def run_once(self, host, num_iterations=100, exit_condition=None):
     28         self.host = host
     29 
     30         # Make sure the device is logged in so TPM activity doesn't keep it
     31         # awake
     32         self.client_at = autotest.Autotest(self.host)
     33         self.client_at.run_test('login_LoginSuccess')
     34 
     35         failed_runs = []
     36         fail_count = 0
     37         logging.info("Running Cr50 USB stress test for %d iterations",
     38                      num_iterations)
     39 
     40         for iteration in xrange(num_iterations):
     41             if iteration:
     42                 time.sleep(self.SLEEP_DELAY)
     43 
     44             i = iteration + 1
     45             logging.info("Run %d of %d%s", i, num_iterations,
     46                          " %d failures" % fail_count if fail_count else "")
     47             try:
     48                 # Run usb_updater command.
     49                 result = self.host.run("usb_updater -f")
     50             except Exception, e:
     51                 failed_runs.append(str(i))
     52                 fail_count += 1
     53                 logging.debug(e)
     54 
     55                 if exit_condition == "immediately":
     56                     raise error.TestFail("USB failure on run %d of %d" %
     57                         (i, num_iterations))
     58 
     59                 logging.info("USB failure on %d out of %d runs: %s", fail_count,
     60                     i, ', '.join(failed_runs))
     61 
     62         if fail_count:
     63             raise error.TestFail('USB failure on %d runs out of %d: %s' %
     64                     (fail_count, num_iterations, ', '.join(failed_runs)))
     65