summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAl Semjonovs <asemjonovs@google.com>2022-02-18 18:45:36 +0000
committerCommit Bot <commit-bot@chromium.org>2022-03-14 17:03:24 +0000
commitda01ebeeaf8b2849fd37a80a1fc27434f362f080 (patch)
treea1101c6dbdffb6dd0a47fcb4fbf00448496b7a2c
parent8cfa663c68a198d767e27ded23a6ad5417b783da (diff)
downloadchrome-ec-da01ebeeaf8b2849fd37a80a1fc27434f362f080.tar.gz
zephyr: test: usb integration test detach permutations
Test USB detach permutations sink then source, source then sink, sink only, source only BRANCH=none BUG=b:209907799, b:209907946, b:209907950 TEST=zmake configure --test-drivers Signed-off-by: Al Semjonovs <asemjonovs@google.com> Change-Id: Iaa6ea7a875cd48e0b732e226ede28b1bd27e8688 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3474633 Reviewed-by: Yuval Peress <peress@google.com>
-rw-r--r--zephyr/test/drivers/src/integration/usbc/usb_attach_src_snk.c337
1 files changed, 292 insertions, 45 deletions
diff --git a/zephyr/test/drivers/src/integration/usbc/usb_attach_src_snk.c b/zephyr/test/drivers/src/integration/usbc/usb_attach_src_snk.c
index 140b122a96..23a17dfcb4 100644
--- a/zephyr/test/drivers/src/integration/usbc/usb_attach_src_snk.c
+++ b/zephyr/test/drivers/src/integration/usbc/usb_attach_src_snk.c
@@ -27,7 +27,7 @@
#define SRC_PORT USBC_PORT_C1
#define TCPCI_EMUL_LABEL DT_NODELABEL(tcpci_emul)
-#define TCPCI_EMUL_LABEL2 DT_NODELABEL(tcpci_ps8xxx_emul)
+#define TCPCI_PS8XXX_EMUL_LABEL DT_NODELABEL(tcpci_ps8xxx_emul)
#define DEFAULT_VBUS_MV 5000
@@ -50,35 +50,31 @@ struct emul_state {
};
struct integration_usb_attach_src_then_snk_fixture {
- struct emul_state *my_emulator_state;
+ struct emul_state my_emulator_state;
};
struct integration_usb_attach_snk_then_src_fixture {
- struct emul_state *my_emulator_state;
+ struct emul_state my_emulator_state;
};
-static void *integration_usb_src_snk_setup(void)
+static void integration_usb_setup(struct emul_state *fixture)
{
const struct emul *tcpci_emul =
emul_get_binding(DT_LABEL(TCPCI_EMUL_LABEL));
const struct emul *tcpci_emul2 =
- emul_get_binding(DT_LABEL(TCPCI_EMUL_LABEL2));
+ emul_get_binding(DT_LABEL(TCPCI_PS8XXX_EMUL_LABEL));
const struct emul *charger_emul =
emul_get_binding(DT_LABEL(DT_NODELABEL(isl923x_emul)));
- static struct emul_state emul_state;
- static struct integration_usb_attach_src_then_snk_fixture fixture_state;
-
/* Setting these are required because compiler believes these values are
* not compile time constants.
*/
/*
* TODO(b/217758708): emuls should be identified at compile-time.
*/
- emul_state.tcpci_generic_emul = tcpci_emul;
- emul_state.tcpci_ps8xxx_emul = tcpci_emul2;
- emul_state.charger_isl923x_emul = charger_emul;
- fixture_state.my_emulator_state = &emul_state;
+ fixture->tcpci_generic_emul = tcpci_emul;
+ fixture->tcpci_ps8xxx_emul = tcpci_emul2;
+ fixture->charger_isl923x_emul = charger_emul;
/*
* TODO(b/221288815): TCPCI config flags should be compile-time
@@ -90,6 +86,22 @@ static void *integration_usb_src_snk_setup(void)
~TCPC_FLAGS_TCPCI_REV2_0;
tcpc_config[SRC_PORT].flags = tcpc_config[SRC_PORT].flags &
~TCPC_FLAGS_TCPCI_REV2_0;
+}
+
+static void *integration_usb_src_snk_setup(void)
+{
+ static struct integration_usb_attach_src_then_snk_fixture fixture_state;
+
+ integration_usb_setup(&fixture_state.my_emulator_state);
+
+ return &fixture_state;
+}
+
+static void *integration_usb_snk_src_setup(void)
+{
+ static struct integration_usb_attach_snk_then_src_fixture fixture_state;
+
+ integration_usb_setup(&fixture_state.my_emulator_state);
return &fixture_state;
}
@@ -177,9 +189,8 @@ static void attach_emulated_src(struct emul_state *my_emul_state)
static void integration_usb_attach_snk_then_src_before(void *state)
{
- const struct integration_usb_attach_src_then_snk_fixture *fixture =
- state;
- struct emul_state *my_state = fixture->my_emulator_state;
+ struct integration_usb_attach_src_then_snk_fixture *fixture = state;
+ struct emul_state *my_state = &fixture->my_emulator_state;
attach_src_snk_common_before(my_state);
@@ -198,9 +209,8 @@ static void integration_usb_attach_snk_then_src_before(void *state)
static void integration_usb_attach_src_then_snk_before(void *state)
{
- const struct integration_usb_attach_src_then_snk_fixture *fixture =
- state;
- struct emul_state *my_state = fixture->my_emulator_state;
+ struct integration_usb_attach_src_then_snk_fixture *fixture = state;
+ struct emul_state *my_state = &fixture->my_emulator_state;
attach_src_snk_common_before(my_state);
@@ -219,29 +229,23 @@ static void integration_usb_attach_src_then_snk_before(void *state)
static void integration_usb_attach_src_then_snk_after(void *state)
{
- const struct integration_usb_attach_src_then_snk_fixture *fixture =
- state;
+ struct integration_usb_attach_src_then_snk_fixture *fixture = state;
- attach_src_snk_common_after(fixture->my_emulator_state);
+ attach_src_snk_common_after(&fixture->my_emulator_state);
}
static void integration_usb_attach_snk_then_src_after(void *state)
{
- const struct integration_usb_attach_snk_then_src_fixture *fixture =
- state;
+ struct integration_usb_attach_snk_then_src_fixture *fixture = state;
- attach_src_snk_common_after(fixture->my_emulator_state);
+ attach_src_snk_common_after(&fixture->my_emulator_state);
}
ZTEST_F(integration_usb_attach_src_then_snk, verify_snk_port_pd_info)
{
- struct ec_params_usb_pd_power_info params = { .port = SNK_PORT };
struct ec_response_usb_pd_power_info response;
- struct host_cmd_handler_args args = BUILD_HOST_COMMAND(
- EC_CMD_USB_PD_POWER_INFO, 0, response, params);
- /* Assume */
- zassume_ok(host_command_process(&args), "Failed to get PD power info");
+ response = host_cmd_power_info(SNK_PORT);
/* Assert */
zassert_equal(response.role, USB_PD_PORT_POWER_SINK,
@@ -277,13 +281,9 @@ ZTEST_F(integration_usb_attach_src_then_snk, verify_snk_port_pd_info)
ZTEST_F(integration_usb_attach_src_then_snk, verify_src_port_pd_info)
{
- struct ec_params_usb_pd_power_info params = { .port = SRC_PORT };
struct ec_response_usb_pd_power_info response;
- struct host_cmd_handler_args args = BUILD_HOST_COMMAND(
- EC_CMD_USB_PD_POWER_INFO, 0, response, params);
- /* Assume */
- zassume_ok(host_command_process(&args), "Failed to get PD power info");
+ response = host_cmd_power_info(SRC_PORT);
/* Assert */
zassert_equal(response.role, USB_PD_PORT_POWER_SOURCE,
@@ -312,13 +312,9 @@ ZTEST_F(integration_usb_attach_src_then_snk, verify_src_port_pd_info)
ZTEST_F(integration_usb_attach_snk_then_src, verify_snk_port_pd_info)
{
- struct ec_params_usb_pd_power_info params = { .port = SNK_PORT };
struct ec_response_usb_pd_power_info response;
- struct host_cmd_handler_args args = BUILD_HOST_COMMAND(
- EC_CMD_USB_PD_POWER_INFO, 0, response, params);
- /* Assume */
- zassume_ok(host_command_process(&args), "Failed to get PD power info");
+ response = host_cmd_power_info(SNK_PORT);
/* Assert */
zassert_equal(response.role, USB_PD_PORT_POWER_SINK,
@@ -355,13 +351,9 @@ ZTEST_F(integration_usb_attach_snk_then_src, verify_snk_port_pd_info)
ZTEST_F(integration_usb_attach_snk_then_src, verify_src_port_pd_info)
{
- struct ec_params_usb_pd_power_info params = { .port = SRC_PORT };
struct ec_response_usb_pd_power_info response;
- struct host_cmd_handler_args args = BUILD_HOST_COMMAND(
- EC_CMD_USB_PD_POWER_INFO, 0, response, params);
- /* Assume */
- zassume_ok(host_command_process(&args), "Failed to get PD power info");
+ response = host_cmd_power_info(SRC_PORT);
/* Assert */
zassert_equal(response.role, USB_PD_PORT_POWER_SOURCE,
@@ -455,6 +447,261 @@ ZTEST_SUITE(integration_usb_attach_src_then_snk, drivers_predicate_post_main,
integration_usb_attach_src_then_snk_after, NULL);
ZTEST_SUITE(integration_usb_attach_snk_then_src, drivers_predicate_post_main,
- integration_usb_src_snk_setup,
+ integration_usb_snk_src_setup,
integration_usb_attach_snk_then_src_before,
integration_usb_attach_snk_then_src_after, NULL);
+
+struct usb_detach_test_fixture {
+ struct emul_state fixture;
+};
+
+static void integration_usb_test_detach(const struct emul *e)
+{
+ zassume_ok(tcpci_emul_disconnect_partner(e), NULL);
+}
+
+static void integration_usb_test_sink_detach(struct emul_state *fixture)
+{
+ integration_usb_test_detach(fixture->tcpci_ps8xxx_emul);
+}
+
+static void integration_usb_test_source_detach(struct emul_state *fixture)
+{
+ integration_usb_test_detach(fixture->tcpci_generic_emul);
+}
+
+void *usb_detach_test_setup(void)
+{
+ static struct usb_detach_test_fixture usb_detach_fixture = { 0 };
+
+ integration_usb_setup(&usb_detach_fixture.fixture);
+
+ return &usb_detach_fixture;
+}
+
+static void usb_detach_test_before(void *state)
+{
+ struct usb_detach_test_fixture *fixture = state;
+ struct emul_state *my_state = &fixture->fixture;
+
+ attach_src_snk_common_before(my_state);
+
+ /* 1) Attach SINK */
+ attach_emulated_snk(my_state);
+
+ /* Wait for PD negotiation */
+ k_sleep(K_SECONDS(10));
+
+ /* 2) Attach SOURCE */
+ attach_emulated_src(my_state);
+
+ /* Wait for PD negotiation */
+ k_sleep(K_SECONDS(10));
+}
+
+static void usb_detach_test_after(void *state)
+{
+ struct usb_detach_test_fixture *fixture = state;
+
+ attach_src_snk_common_after(&fixture->fixture);
+}
+
+ZTEST_F(usb_detach_test, verify_detach_src_snk)
+{
+ struct emul_state *fixture = &this->fixture;
+ struct ec_response_usb_pd_power_info src_power_info = { 0 };
+ struct ec_response_usb_pd_power_info snk_power_info = { 0 };
+
+ integration_usb_test_source_detach(fixture);
+ integration_usb_test_sink_detach(fixture);
+
+ k_sleep(K_SECONDS(10));
+ isl923x_emul_set_adc_vbus(fixture->charger_isl923x_emul, 0);
+
+ snk_power_info = host_cmd_power_info(SNK_PORT);
+ src_power_info = host_cmd_power_info(SRC_PORT);
+
+ /* Validate Sink power info */
+ zassert_equal(snk_power_info.role, USB_PD_PORT_POWER_DISCONNECTED,
+ "Power role %d, but PD reports role %d",
+ USB_PD_PORT_POWER_DISCONNECTED, snk_power_info.role);
+ zassert_equal(snk_power_info.type, USB_CHG_TYPE_NONE,
+ "Charger type %d, but PD reports type %d",
+ USB_CHG_TYPE_NONE, snk_power_info.type);
+
+ zassert_equal(snk_power_info.meas.voltage_max, 0,
+ "Charging at VBUS %dmV, but PD reports %dmV", 0,
+ snk_power_info.meas.voltage_max);
+
+ zassert_within(snk_power_info.meas.voltage_now, 0, 10,
+ "Actually charging at VBUS %dmV, but PD reports %dmV", 0,
+ snk_power_info.meas.voltage_now);
+
+ zassert_equal(snk_power_info.meas.current_max, 0,
+ "Charging at VBUS max %dmA, but PD reports %dmA", 0,
+ snk_power_info.meas.current_max);
+
+ zassert_true(snk_power_info.meas.current_lim >= 0,
+ "Charging at VBUS max %dmA, but PD current limit %dmA", 0,
+ snk_power_info.meas.current_lim);
+
+ zassert_equal(snk_power_info.max_power, 0,
+ "Charging up to %duW, PD max power %duW", 0,
+ snk_power_info.max_power);
+
+ /* Validate Source power info */
+ zassert_equal(src_power_info.role, USB_PD_PORT_POWER_DISCONNECTED,
+ "Power role %d, but PD reports role %d",
+ USB_PD_PORT_POWER_DISCONNECTED, src_power_info.role);
+
+ zassert_equal(src_power_info.type, USB_CHG_TYPE_NONE,
+ "Charger type %d, but PD reports type %d",
+ USB_CHG_TYPE_NONE, src_power_info.type);
+
+ /* TODO(b/209907615): Confirm measure value requirements */
+ zassert_within(src_power_info.meas.voltage_now, 0, 10,
+ "Expected Charging at VBUS %dmV, but PD reports %dmV",
+ DEFAULT_VBUS_MV, src_power_info.meas.voltage_now);
+
+ zassume_equal(src_power_info.meas.current_max, 0,
+ "Charging at VBUS max %dmA, but PD reports %dmA", 0,
+ src_power_info.meas.current_max);
+}
+
+ZTEST_F(usb_detach_test, verify_detach_snk_src)
+{
+ struct emul_state *fixture = &this->fixture;
+ struct ec_response_usb_pd_power_info src_power_info = { 0 };
+ struct ec_response_usb_pd_power_info snk_power_info = { 0 };
+
+ integration_usb_test_sink_detach(fixture);
+ integration_usb_test_source_detach(fixture);
+
+ k_sleep(K_SECONDS(10));
+ isl923x_emul_set_adc_vbus(fixture->charger_isl923x_emul, 0);
+
+ snk_power_info = host_cmd_power_info(SNK_PORT);
+ src_power_info = host_cmd_power_info(SRC_PORT);
+
+ /* Validate Sink power info */
+ zassert_equal(snk_power_info.role, USB_PD_PORT_POWER_DISCONNECTED,
+ "Power role %d, but PD reports role %d",
+ USB_PD_PORT_POWER_DISCONNECTED, snk_power_info.role);
+ zassert_equal(snk_power_info.type, USB_CHG_TYPE_NONE,
+ "Charger type %d, but PD reports type %d",
+ USB_CHG_TYPE_NONE, snk_power_info.type);
+
+ zassert_equal(snk_power_info.meas.voltage_max, 0,
+ "Charging at VBUS %dmV, but PD reports %dmV", 0,
+ snk_power_info.meas.voltage_max);
+
+ zassert_within(snk_power_info.meas.voltage_now, 0, 10,
+ "Actually charging at VBUS %dmV, but PD reports %dmV", 0,
+ snk_power_info.meas.voltage_now);
+
+ zassert_equal(snk_power_info.meas.current_max, 0,
+ "Charging at VBUS max %dmA, but PD reports %dmA", 0,
+ snk_power_info.meas.current_max);
+
+ zassert_true(snk_power_info.meas.current_lim >= 0,
+ "Charging at VBUS max %dmA, but PD current limit %dmA", 0,
+ snk_power_info.meas.current_lim);
+
+ zassert_equal(snk_power_info.max_power, 0,
+ "Charging up to %duW, PD max power %duW", 0,
+ snk_power_info.max_power);
+
+ /* Validate Source power info */
+ zassert_equal(src_power_info.role, USB_PD_PORT_POWER_DISCONNECTED,
+ "Power role %d, but PD reports role %d",
+ USB_PD_PORT_POWER_DISCONNECTED, src_power_info.role);
+
+ zassert_equal(src_power_info.type, USB_CHG_TYPE_NONE,
+ "Charger type %d, but PD reports type %d",
+ USB_CHG_TYPE_NONE, src_power_info.type);
+
+ /* TODO(b/209907615): Confirm measure value requirements */
+ zassert_within(src_power_info.meas.voltage_now, 0, 10,
+ "Expected Charging at VBUS %dmV, but PD reports %dmV",
+ DEFAULT_VBUS_MV, src_power_info.meas.voltage_now);
+
+ zassume_equal(src_power_info.meas.current_max, 0,
+ "Charging at VBUS max %dmA, but PD reports %dmA", 0,
+ src_power_info.meas.current_max);
+}
+
+ZTEST_F(usb_detach_test, verify_detach_sink)
+{
+ struct emul_state *fixture = &this->fixture;
+ struct ec_response_usb_pd_power_info pd_power_info = { 0 };
+
+ integration_usb_test_sink_detach(fixture);
+ k_sleep(K_SECONDS(10));
+ isl923x_emul_set_adc_vbus(fixture->charger_isl923x_emul, 0);
+
+ pd_power_info = host_cmd_power_info(SNK_PORT);
+
+ /* Assert */
+ zassert_equal(pd_power_info.role, USB_PD_PORT_POWER_SINK,
+ "Power role %d, but PD reports role %d",
+ USB_PD_PORT_POWER_SINK, pd_power_info.role);
+ zassert_equal(pd_power_info.type, USB_CHG_TYPE_PD,
+ "Charger type %d, but PD reports type %d",
+ USB_CHG_TYPE_PD, pd_power_info.type);
+
+ zassert_equal(pd_power_info.meas.voltage_max, DEFAULT_VBUS_MV,
+ "Charging at VBUS %dmV, but PD reports %dmV",
+ DEFAULT_VBUS_MV, pd_power_info.meas.voltage_max);
+
+ zassert_within(pd_power_info.meas.voltage_now, 0, 10,
+ "Actually charging at VBUS %dmV, but PD reports %dmV", 0,
+ pd_power_info.meas.voltage_now);
+
+ zassert_equal(pd_power_info.meas.current_max, DEFAULT_VBUS_SNK_PORT_MA,
+ "Charging at VBUS max %dmA, but PD reports %dmA",
+ DEFAULT_VBUS_SNK_PORT_MA, pd_power_info.meas.current_max);
+
+ zassert_true(pd_power_info.meas.current_lim >= 500,
+ "Charging at VBUS max %dmA, but PD current limit %dmA",
+ 500, pd_power_info.meas.current_lim);
+
+ zassert_equal(pd_power_info.max_power,
+ DEFAULT_VBUS_MV * DEFAULT_VBUS_SNK_PORT_MA,
+ "Charging up to %duW, PD max power %duW",
+ DEFAULT_VBUS_MV * DEFAULT_VBUS_SNK_PORT_MA,
+ pd_power_info.max_power);
+}
+
+ZTEST_F(usb_detach_test, verify_detach_source)
+{
+ struct emul_state *fixture = &this->fixture;
+ struct ec_response_usb_pd_power_info pd_power_info = { 0 };
+
+ integration_usb_test_source_detach(fixture);
+ k_sleep(K_SECONDS(10));
+ isl923x_emul_set_adc_vbus(fixture->charger_isl923x_emul, 0);
+
+ pd_power_info = host_cmd_power_info(SRC_PORT);
+
+ /* Assert */
+ zassert_equal(pd_power_info.role, USB_PD_PORT_POWER_DISCONNECTED,
+ "Power role %d, but PD reports role %d",
+ USB_PD_PORT_POWER_DISCONNECTED, pd_power_info.role);
+
+ zassert_equal(pd_power_info.type, USB_CHG_TYPE_NONE,
+ "Charger type %d, but PD reports type %d",
+ USB_CHG_TYPE_NONE, pd_power_info.type);
+
+ /* TODO(b/209907615): Confirm measure value requirements */
+ zassert_within(pd_power_info.meas.voltage_now, 0, 10,
+ "Expected Charging at VBUS %dmV, but PD reports %dmV",
+ DEFAULT_VBUS_MV, pd_power_info.meas.voltage_now);
+
+ zassume_equal(pd_power_info.meas.current_max, 0,
+ "Charging at VBUS max %dmA, but PD reports %dmA", 0,
+ pd_power_info.meas.current_max);
+}
+
+ZTEST_SUITE(usb_detach_test, drivers_predicate_post_main,
+ integration_usb_src_snk_setup, usb_detach_test_before,
+ usb_detach_test_after, NULL);