summaryrefslogtreecommitdiff
path: root/zephyr/test/drivers
diff options
context:
space:
mode:
authorAbe Levkoy <alevkoy@chromium.org>2022-01-05 01:05:10 -0700
committerCommit Bot <commit-bot@chromium.org>2022-01-07 23:07:40 +0000
commit4d47057ad35c0f666a745c1091ce0f8bf75dc318 (patch)
treed96fbb3a3be4b904d9c4d0c5ca8c60d4b5c3e655 /zephyr/test/drivers
parent537698c1204525598328794f3b7ab4e4b35f25a2 (diff)
downloadchrome-ec-4d47057ad35c0f666a745c1091ce0f8bf75dc318.tar.gz
zephyr test: PD charger integration test skeleton
The initial outline for an integration test: Emulate attaching a PD charger. Verify that PD negotiation completes and starts charging at the negotiated power. BUG=b:209907297 TEST=zmake configure --test zephyr/test/drivers BRANCH=none Change-Id: I47fdec548a6625a850ea4578353e572e5130ed55 Signed-off-by: Abe Levkoy <alevkoy@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3359842 Reviewed-by: Jack Rosenthal <jrosenth@chromium.org> Commit-Queue: Jack Rosenthal <jrosenth@chromium.org>
Diffstat (limited to 'zephyr/test/drivers')
-rw-r--r--zephyr/test/drivers/src/integration_usb.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/zephyr/test/drivers/src/integration_usb.c b/zephyr/test/drivers/src/integration_usb.c
index 854f286c77..5a236a0df1 100644
--- a/zephyr/test/drivers/src/integration_usb.c
+++ b/zephyr/test/drivers/src/integration_usb.c
@@ -91,11 +91,77 @@ static void test_attach_compliant_charger(void)
/* TODO: Also check voltage, current, etc. */
}
+static void test_attach_pd_charger(void)
+{
+ const struct emul *tcpci_emul =
+ emul_get_binding(DT_LABEL(TCPCI_EMUL_LABEL));
+ struct i2c_emul *i2c_emul;
+ uint16_t battery_status;
+ struct tcpci_src_emul_data my_charger;
+ const struct device *gpio_dev =
+ DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_AC_OK_PATH, gpios));
+
+ /*
+ * TODO(b/209907297): Implement the steps of the test beyond USB default
+ * charging.
+ */
+
+ /* 1. Configure source PDOs of partner (probably fixed source 5V 3A
+ * and fixed source 20V 3A). Currently, the partner emulator only
+ * supports the default USB power PDO.
+ */
+
+ /* Attach emulated charger. This will send Source Capabilities. */
+ zassert_ok(gpio_emul_input_set(gpio_dev, GPIO_AC_OK_PIN, 1), NULL);
+ tcpci_src_emul_init(&my_charger);
+ zassert_ok(tcpci_src_emul_connect_to_tcpci(&my_charger, tcpci_emul),
+ NULL);
+
+ /* Wait for current ramp. */
+ k_sleep(K_SECONDS(10));
+
+ /* Verify battery charging. */
+ i2c_emul = sbat_emul_get_ptr(BATTERY_ORD);
+ zassert_ok(sbat_emul_get_word_val(i2c_emul, SB_BATTERY_STATUS,
+ &battery_status),
+ NULL);
+ zassert_equal(battery_status & STATUS_DISCHARGING, 0,
+ "Battery is discharging: %d", battery_status);
+
+ /*
+ * 2. Check charging current and voltage (should be 5V, default USB
+ * current); make sure that reports from battery and PD host commands
+ * match; check that host command reports no active PDO.
+ */
+
+ /*
+ * 3. Wait for SenderResponseTimeout. Expect TCPM to send Request.
+ * We could verify that the Request references the expected PDO, but
+ * the voltage/current/PDO checks at the end of the test should all be
+ * wrong if the requested PDO was wrong here.
+ */
+
+ /*
+ * 4. Send Accept and PS_RDY from partner with appropriate delay between
+ * them. Emulate supplying VBUS at the requested voltage/current before
+ * PS_RDY.
+ */
+
+ /*
+ * 5. Check the charging voltage and current. Cross-check the PD state,
+ * the battery/charger state, and the active PDO as reported by the PD
+ * state.
+ */
+}
+
void test_suite_integration_usb(void)
{
ztest_test_suite(integration_usb,
ztest_user_unit_test_setup_teardown(
test_attach_compliant_charger, init_tcpm,
+ remove_emulated_devices),
+ ztest_user_unit_test_setup_teardown(
+ test_attach_pd_charger, init_tcpm,
remove_emulated_devices));
ztest_run_test_suite(integration_usb);
}