Home | History | Annotate | Download | only in usbpd_DisplayPortSink
      1 # Copyright (c) 2015 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.bin import test
      8 from autotest_lib.client.common_lib import error
      9 from autotest_lib.client.cros import ec as cros_ec
     10 
     11 
     12 class usbpd_DisplayPortSink(test.test):
     13     """Integration test for USB-PD DisplayPort sink."""
     14 
     15     version = 1
     16     DP_SVID = '0xff01'
     17 
     18     def _is_displayport(self, port):
     19         return port.is_amode_supported(self.DP_SVID)
     20 
     21     def _set_displayport(self, port, opos, enter):
     22         return port.set_amode(self.DP_SVID, opos, enter)
     23 
     24     def run_once(self, enter_reps=1):
     25         usbpd = cros_ec.EC_USBPD()
     26         logging.info("device has %d USB-PD ports", len(usbpd.ports))
     27 
     28         for i,port in enumerate(usbpd.ports):
     29             if not port.is_dfp():
     30                 continue
     31 
     32             logging.info("Port %d is dfp", i)
     33 
     34             if not self._is_displayport(port):
     35                 continue
     36 
     37             logging.info("Port %d supports dp", i)
     38 
     39             for _ in xrange(enter_reps):
     40                 if not self._set_displayport(port, 1, False):
     41                     raise error.TestError("Failed to exit DP mode")
     42 
     43                 if not self._set_displayport(port, 1, True):
     44                     raise error.TestError("Failed to enter DP mode")
     45