Home | History | Annotate | Download | only in firmware_PDResetSoft
      1 # Copyright 2016 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 
      7 from autotest_lib.client.common_lib import error
      8 from autotest_lib.server.cros.faft.firmware_test import FirmwareTest
      9 from autotest_lib.server.cros.servo import pd_device
     10 
     11 
     12 class firmware_PDResetSoft(FirmwareTest):
     13     """
     14     Servo based USB PD soft reset test.
     15 
     16     Soft resets are issued by both ends of the connection. If the DUT
     17     is dualrole capable, then a power role swap is executed, and the
     18     test is repeated with the DUT in the opposite power role. Pass
     19     criteria is that all attempted soft resets are successful.
     20 
     21     """
     22     version = 1
     23     RESET_ITERATIONS = 5
     24 
     25 
     26     def _test_soft_reset(self, port_pair):
     27         """Tests soft reset initated by both Plankton and the DUT
     28 
     29         @param port_pair: list of 2 connected PD devices
     30         """
     31         for dev in port_pair:
     32             for _ in xrange(self.RESET_ITERATIONS):
     33                 try:
     34                     if dev.soft_reset() == False:
     35                         raise error.TestFail('Soft Reset Failed')
     36                 except NotImplementedError:
     37                     logging.warn('Device cant soft reset ... skipping')
     38                     break
     39 
     40     def initialize(self, host, cmdline_args):
     41         super(firmware_PDResetSoft, self).initialize(host, cmdline_args)
     42         # Only run in normal mode
     43         self.switcher.setup_mode('normal')
     44         # Turn off console prints, except for USBPD.
     45         self.usbpd.send_command('chan 0x08000000')
     46 
     47     def cleanup(self):
     48         self.usbpd.send_command('chan 0xffffffff')
     49         super(firmware_PDResetSoft, self).cleanup()
     50 
     51     def run_once(self):
     52         """Execute Power Role swap test.
     53 
     54         1. Verify that pd console is accessible
     55         2. Verify that DUT has a valid PD contract
     56         3. Make sure dualrole mode is enabled on both ends
     57         4. Test Soft Reset initiated by both ends of connection
     58         5. Attempt to change power roles
     59            If power role changed, then retest soft resets
     60            Else end test.
     61 
     62         """
     63         # Create list of available UART consoles
     64         consoles = [self.usbpd, self.plankton]
     65         port_partner = pd_device.PDPortPartner(consoles)
     66         # Identify a valid test port pair
     67         port_pair = port_partner.identify_pd_devices()
     68         if not port_pair:
     69             raise error.TestFail('No PD connection found!')
     70 
     71         # Test soft resets initiated by both ends
     72         self._test_soft_reset(port_pair)
     73         # Attempt to swap power roles
     74         try:
     75             if port_pair[0].pr_swap() == False:
     76                 logging.warn('Power role not swapped, ending test')
     77                 return
     78         except NotImplementedError:
     79             logging.warn('device cant send power role swap command, end test')
     80             return
     81         # Power role has been swapped, retest.
     82         self._test_soft_reset(port_pair)
     83