diff options
author | Al Semjonovs <asemjonovs@google.com> | 2022-08-29 14:31:19 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-08-30 17:44:42 +0000 |
commit | 2dd90b8661251c10697c9b33753ff8021b0f828b (patch) | |
tree | 826cc43a3aa902ca5de753d92eb00712699d245c | |
parent | 5513feaaba485c716c2d5e182c2d433af3636ee4 (diff) | |
download | chrome-ec-2dd90b8661251c10697c9b33753ff8021b0f828b.tar.gz |
zephyr: Add `pe` and `pdcable` console command tests
Added tests for `pe` and `pdcable` console commands
BUG=b:236074967, b:236074968
BRANCH=NONE
TEST=./twister -T zephyr/test
Signed-off-by: Al Semjonovs <asemjonovs@google.com>
Change-Id: Ie7e7ea367b12f7fc3eaa47fae9c04861ad902af7
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3863127
Reviewed-by: Abe Levkoy <alevkoy@chromium.org>
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
-rw-r--r-- | zephyr/test/drivers/default/src/console_cmd/usb_pd_console.c | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/zephyr/test/drivers/default/src/console_cmd/usb_pd_console.c b/zephyr/test/drivers/default/src/console_cmd/usb_pd_console.c index d4009e202d..96b2b701ef 100644 --- a/zephyr/test/drivers/default/src/console_cmd/usb_pd_console.c +++ b/zephyr/test/drivers/default/src/console_cmd/usb_pd_console.c @@ -256,3 +256,83 @@ ZTEST_USER(console_cmd_usb_pd, test_timer) zassert_equal(rv, EC_SUCCESS, "Expected %d, but got %d", EC_SUCCESS, rv); } + +static void set_device_vdo(int port, enum tcpci_msg_type type) +{ + union tbt_mode_resp_device device_resp; + struct pd_discovery *dev_disc; + + dev_disc = pd_get_am_discovery_and_notify_access(port, type); + dev_disc->svid_cnt = 1; + dev_disc->svids[0].svid = USB_VID_INTEL; + dev_disc->svids[0].discovery = PD_DISC_COMPLETE; + dev_disc->svids[0].mode_cnt = 1; + device_resp.tbt_alt_mode = TBT_ALTERNATE_MODE; + device_resp.tbt_adapter = TBT_ADAPTER_TBT3; + device_resp.intel_spec_b0 = VENDOR_SPECIFIC_NOT_SUPPORTED; + device_resp.vendor_spec_b0 = VENDOR_SPECIFIC_NOT_SUPPORTED; + device_resp.vendor_spec_b1 = VENDOR_SPECIFIC_NOT_SUPPORTED; + dev_disc->svids[0].mode_vdo[0] = device_resp.raw_value; +} + +static void set_active_cable_type(int port, enum tcpci_msg_type type, + enum idh_ptype ptype) +{ + struct pd_discovery *dev_disc; + + dev_disc = pd_get_am_discovery_and_notify_access(port, type); + dev_disc->identity.idh.product_type = ptype; + prl_set_rev(port, type, PD_REV30); +} + +ZTEST_USER(console_cmd_usb_pd, test_pe) +{ + int rv; + + pd_set_identity_discovery(0, TCPCI_MSG_SOP, PD_DISC_COMPLETE); + + rv = shell_execute_cmd(get_ec_shell(), "pe 0 dump"); + zassert_ok(rv, "Expected %d, but got %d", EC_SUCCESS, rv); + + set_device_vdo(0, TCPCI_MSG_SOP); + rv = shell_execute_cmd(get_ec_shell(), "pe 0 dump"); + zassert_ok(rv, "Expected %d, but got %d", EC_SUCCESS, rv); + + /* Handle error scenarios */ + rv = shell_execute_cmd(get_ec_shell(), "pe 0"); + zassert_equal(rv, EC_ERROR_PARAM_COUNT, "Expected %d, but got %d", + EC_ERROR_PARAM_COUNT, rv); + + rv = shell_execute_cmd(get_ec_shell(), "pe x dump"); + zassert_equal(rv, EC_ERROR_PARAM2, "Expected %d, but got %d", + EC_ERROR_PARAM2, rv); +} + +ZTEST_USER(console_cmd_usb_pd, test_pdcable) +{ + int rv; + + rv = shell_execute_cmd(get_ec_shell(), "pdcable 0"); + zassert_ok(rv, "Expected %d, but got %d", EC_SUCCESS, rv); + + set_device_vdo(0, TCPCI_MSG_SOP_PRIME); + + /* Set active cable type IDH_PTYPE_ACABLE */ + set_active_cable_type(0, TCPCI_MSG_SOP_PRIME, IDH_PTYPE_ACABLE); + rv = shell_execute_cmd(get_ec_shell(), "pdcable 0"); + zassert_ok(rv, "Expected %d, but got %d", EC_SUCCESS, rv); + + /* Set active cable type IDH_PTYPE_PCABLE */ + set_active_cable_type(0, TCPCI_MSG_SOP_PRIME, IDH_PTYPE_PCABLE); + rv = shell_execute_cmd(get_ec_shell(), "pdcable 0"); + zassert_ok(rv, "Expected %d, but got %d", EC_SUCCESS, rv); + + /* Handle error scenarios */ + rv = shell_execute_cmd(get_ec_shell(), "pdcable"); + zassert_equal(rv, EC_ERROR_PARAM_COUNT, "Expected %d, but got %d", + EC_ERROR_PARAM_COUNT, rv); + + rv = shell_execute_cmd(get_ec_shell(), "pdcable t"); + zassert_equal(rv, EC_ERROR_PARAM2, "Expected %d, but got %d", + EC_ERROR_PARAM2, rv); +} |