Add VBUS current check for type-C charging test
1. add poll_pd_state for plankton class. The state transition (between
sink and source) will take a short time. If we want to make sure test
checking in stable state, we should poll it.
2. add VBUS current check (same as the metric of factory test). Check
current is around 3A in charging 5V, and others current is over 0A.
3. make plankton object as local since it is only used inside run_once.
BUG=chrome-os-partner:33362
TEST=manual
test_that --fast -b typec_host_board due_ip_address \
firmware_TypeCCharging
Change-Id: I9a544b3a0e96a35df916069619895172612333e5
Reviewed-on: https://chromium-review.googlesource.com/262536
Reviewed-by: Wai-Hong Tam <waihong@chromium.org>
Commit-Queue: Pin-chih Lin <johnylin@chromium.org>
Tested-by: Pin-chih Lin <johnylin@chromium.org>
diff --git a/server/cros/servo/plankton.py b/server/cros/servo/plankton.py
index 482e42b..8154f34 100644
--- a/server/cros/servo/plankton.py
+++ b/server/cros/servo/plankton.py
@@ -7,6 +7,8 @@
import time
import xmlrpclib
+from autotest_lib.client.bin import utils
+
class PlanktonError(Exception):
pass
@@ -38,6 +40,11 @@
VBUS_VOLTAGE_MV = 'vbus_voltage'
VBUS_CURRENT_MA = 'vbus_current'
VBUS_POWER_MW = 'vbus_power'
+ # USBC PD states.
+ USBC_PD_STATES = {
+ 'sink': 'SNK_READY',
+ 'source': 'SRC_READY'}
+ POLL_STATE_SECS = 2
def __init__(self, args_dict=None):
@@ -125,3 +132,19 @@
return 0
raise PlanktonError('Invalid USBC role: %s' % usbc_role)
+
+
+ def poll_pd_state(self, state):
+ """Polls until Plankton pd goes to the specific state.
+
+ @param state: Specified pd state name.
+ """
+ if state not in self.USBC_PD_STATES:
+ raise PlanktonError('Invalid state name: %s' % state)
+ utils.poll_for_condition(
+ lambda: self.get('pd_state') == self.USBC_PD_STATES[state],
+ exception=utils.TimeoutError('Plankton not in %s state '
+ 'after %s seconds.' %
+ (self.USBC_PD_STATES[state],
+ self.POLL_STATE_SECS)),
+ timeout=self.POLL_STATE_SECS)