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