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