diff options
author | Sam Hurst <shurst@google.com> | 2022-09-29 10:48:03 -0700 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-10-14 22:35:39 +0000 |
commit | 93e717fa9b9f306b329c914b0d0e8f6114fa2d3d (patch) | |
tree | 797b89cc1c06a7940e02e622584744c629e7f352 | |
parent | 27f8b4844665d86bffa845f965c5407a553c908f (diff) | |
download | chrome-ec-93e717fa9b9f306b329c914b0d0e8f6114fa2d3d.tar.gz |
zephyr: test: ps8xxx: Add test coverage to ps8xxx
Add test coverage for ps8xxx drivers
BUG=b:246762616
TEST=./twister -T zephyr/test/drivers/
BRANCH=main
Signed-off-by: Sam Hurst <shurst@google.com>
Change-Id: Ie66d341f7e105086108b30c758e2cce9d3535776
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3929259
Reviewed-by: Keith Short <keithshort@chromium.org>
Code-Coverage: Keith Short <keithshort@chromium.org>
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Commit-Queue: Keith Short <keithshort@chromium.org>
-rw-r--r-- | zephyr/test/drivers/default/src/ps8xxx.c | 172 | ||||
-rw-r--r-- | zephyr/test/drivers/prj.conf | 2 |
2 files changed, 174 insertions, 0 deletions
diff --git a/zephyr/test/drivers/default/src/ps8xxx.c b/zephyr/test/drivers/default/src/ps8xxx.c index 1e57f62957..2aa1844c10 100644 --- a/zephyr/test/drivers/default/src/ps8xxx.c +++ b/zephyr/test/drivers/default/src/ps8xxx.c @@ -61,6 +61,11 @@ ZTEST(ps8815, test_init_fail) test_ps8xxx_init_fail(); } +ZTEST(ps8745, test_init_fail) +{ + test_ps8xxx_init_fail(); +} + /** * Test PS8805 init and indirectly ps8705_dci_disable which is * used by PS8805 @@ -127,6 +132,30 @@ ZTEST(ps8815, test_ps8815_init) zassert_equal(EC_SUCCESS, ps8xxx_tcpm_drv.init(USBC_PORT_C1)); } +/** Test PS8745 init */ +ZTEST(ps8745, test_ps8745_init) +{ + const struct emul *ps8xxx_emul = EMUL_DT_GET(PS8XXX_EMUL_NODE); + struct i2c_common_emul_data *p1_i2c_common_data = + ps8xxx_emul_get_i2c_common_data(ps8xxx_emul, + PS8XXX_EMUL_PORT_1); + + /* Set arbitrary FW reg value != 0 for this test */ + tcpci_emul_set_reg(ps8xxx_emul, PS8XXX_REG_FW_REV, 0x31); + /* Set correct power status for rest of the test */ + tcpci_emul_set_reg(ps8xxx_emul, TCPC_REG_POWER_STATUS, 0x0); + + /* Test fail on reading HW revision register */ + i2c_common_emul_set_read_fail_reg(p1_i2c_common_data, + PS8815_P1_REG_HW_REVISION); + zassert_equal(EC_ERROR_INVAL, ps8xxx_tcpm_drv.init(USBC_PORT_C1), NULL); + i2c_common_emul_set_read_fail_reg(p1_i2c_common_data, + I2C_COMMON_EMUL_NO_FAIL_REG); + + /* Test successful init */ + zassert_equal(EC_SUCCESS, ps8xxx_tcpm_drv.init(USBC_PORT_C1), NULL); +} + /** Test PS8xxx release */ static void test_ps8xxx_release(void) { @@ -616,6 +645,11 @@ ZTEST(ps8815, test_ps8815_get_chip_info) test_ps8xxx_get_chip_info(PS8815_PRODUCT_ID); } +ZTEST(ps8745, test_ps8745_get_chip_info) +{ + test_ps8xxx_get_chip_info(PS8815_PRODUCT_ID); +} + /** Test PS8805 get chip info and indirectly ps8805_make_device_id */ ZTEST(ps8805, test_ps8805_get_chip_info_fix_dev_id) { @@ -710,6 +744,100 @@ ZTEST(ps8805, test_ps8805_get_chip_info_fix_dev_id) } } +/** Test PS8745 get chip info and indirectly ps8745_make_device_id */ +ZTEST(ps8745, test_ps8745_get_chip_info_fix_dev_id) +{ + const struct emul *ps8xxx_emul = EMUL_DT_GET(PS8XXX_EMUL_NODE); + struct i2c_common_emul_data *p1_i2c_common_data = + ps8xxx_emul_get_i2c_common_data(ps8xxx_emul, + PS8XXX_EMUL_PORT_1); + struct ec_response_pd_chip_info_v1 info; + uint16_t vendor, product, device_id, fw_rev; + uint16_t hw_rev; + + struct { + uint16_t exp_dev_id; + uint16_t hw_rev; + } test_param[] = { + /* Test A0 HW revision */ + { + .exp_dev_id = 0x1, + .hw_rev = 0x0a00, + }, + /* Test A1 HW revision */ + { + .exp_dev_id = 0x2, + .hw_rev = 0x0a01, + }, + /* Test A2 HW revision */ + { + .exp_dev_id = 0x3, + .hw_rev = 0x0a02, + }, + }; + + /* Setup chip info */ + vendor = PS8XXX_VENDOR_ID; + product = PS8815_PRODUCT_ID; + /* Arbitrary revision */ + fw_rev = 0x32; + tcpci_emul_set_reg(ps8xxx_emul, TCPC_REG_VENDOR_ID, vendor); + tcpci_emul_set_reg(ps8xxx_emul, TCPC_REG_PRODUCT_ID, product); + tcpci_emul_set_reg(ps8xxx_emul, PS8XXX_REG_FW_REV, fw_rev); + + /* Set device id which requires fixing */ + device_id = 0x1; + tcpci_emul_set_reg(ps8xxx_emul, TCPC_REG_BCD_DEV, device_id); + + /* Test error on fixing device id because of fail hw revision read */ + i2c_common_emul_set_read_fail_reg(p1_i2c_common_data, + PS8815_P1_REG_HW_REVISION); + zassert_equal(EC_ERROR_INVAL, + ps8xxx_tcpm_drv.get_chip_info(USBC_PORT_C1, 1, &info), + NULL); + i2c_common_emul_set_read_fail_reg(p1_i2c_common_data, + I2C_COMMON_EMUL_NO_FAIL_REG); + + /* Set wrong hw revision */ + hw_rev = 0x32; + ps8xxx_emul_set_hw_rev(ps8xxx_emul, hw_rev); + + /* Test error on fixing device id */ + zassert_equal(EC_ERROR_UNKNOWN, + ps8xxx_tcpm_drv.get_chip_info(USBC_PORT_C1, 1, &info), + NULL); + + /* Test fixing device id for specific HW revisions */ + for (int i = 0; i < ARRAY_SIZE(test_param); i++) { + ps8xxx_emul_set_hw_rev(ps8xxx_emul, test_param[i].hw_rev); + + /* Test correct device id after fixing */ + zassert_equal( + EC_SUCCESS, + ps8xxx_tcpm_drv.get_chip_info(USBC_PORT_C1, 1, &info), + "Failed to get chip info in test case %d (hw_rev 0x%x)", + i, test_param[i].hw_rev); + zassert_equal( + vendor, info.vendor_id, + "0x%x != (vendor = 0x%x) in test case %d (hw_rev 0x%x)", + vendor, info.vendor_id, i, test_param[i].hw_rev); + zassert_equal( + product, info.product_id, + "0x%x != (product = 0x%x) in test case %d (hw_rev 0x%x)", + product, info.product_id, i, test_param[i].hw_rev); + zassert_equal( + test_param[i].exp_dev_id, info.device_id, + "0x%x != (device = 0x%x) in test case %d (hw_rev 0x%x)", + test_param[i].exp_dev_id, info.device_id, i, + test_param[i].hw_rev); + zassert_equal( + fw_rev, info.fw_version_number, + "0x%x != (FW rev = 0x%x) in test case %d (hw_rev 0x%x)", + fw_rev, info.fw_version_number, i, + test_param[i].hw_rev); + } +} + /** Test PS8815 get chip info and indirectly ps8815_make_device_id */ ZTEST(ps8815, test_ps8815_get_chip_info_fix_dev_id) { @@ -965,6 +1093,11 @@ ZTEST(ps8815, test_tcpci_init) test_ps8xxx_tcpci_init(); } +ZTEST(ps8745, test_tcpci_init) +{ + test_ps8xxx_tcpci_init(); +} + /** Test TCPCI release */ static void test_ps8xxx_tcpci_release(void) { @@ -1025,6 +1158,11 @@ ZTEST(ps8815, test_tcpci_set_cc) test_ps8xxx_tcpci_set_cc(); } +ZTEST(ps8745, test_tcpci_set_cc) +{ + test_ps8xxx_tcpci_set_cc(); +} + /** Test TCPCI set polarity */ static void test_ps8xxx_tcpci_set_polarity(void) { @@ -1105,6 +1243,11 @@ ZTEST(ps8815, test_tcpci_get_rx_message_raw) test_ps8xxx_tcpci_get_rx_message_raw(); } +ZTEST(ps8745, test_tcpci_get_rx_message_raw) +{ + test_ps8xxx_tcpci_get_rx_message_raw(); +} + /** Test TCPCI transmitting message */ static void test_ps8xxx_tcpci_transmit(void) { @@ -1290,6 +1433,7 @@ static void ps8815_before(void *state) ARG_UNUSED(state); board_set_ps8xxx_product_id(PS8815_PRODUCT_ID); + ps8xxx_emul_set_reg_id(ps8xxx_emul, PS8815_REG_ID); ps8xxx_emul_set_product_id(ps8xxx_emul, PS8815_PRODUCT_ID); setup_no_fail_all(); zassume_equal(EC_SUCCESS, ps8xxx_tcpm_drv.init(USBC_PORT_C1)); @@ -1304,8 +1448,36 @@ static void ps8815_after(void *state) tcpci_emul_set_reg(ps8xxx_emul, PS8XXX_REG_FW_REV, 0x31); } +/** + * Setup PS8xxx emulator to mimic PS8745 and setup no fail for all I2C devices + * associated with PS8xxx emulator + */ +static void ps8745_before(void *state) +{ + const struct emul *ps8xxx_emul = EMUL_DT_GET(PS8XXX_EMUL_NODE); + ARG_UNUSED(state); + + board_set_ps8xxx_product_id(PS8815_PRODUCT_ID); + ps8xxx_emul_set_product_id(ps8xxx_emul, PS8815_PRODUCT_ID); + ps8xxx_emul_set_reg_id(ps8xxx_emul, PS8745_REG_ID); + setup_no_fail_all(); + zassume_equal(EC_SUCCESS, ps8xxx_tcpm_drv.init(USBC_PORT_C1), NULL); +} + +static void ps8745_after(void *state) +{ + const struct emul *ps8xxx_emul = EMUL_DT_GET(PS8XXX_EMUL_NODE); + ARG_UNUSED(state); + + /* Set correct firmware revision */ + tcpci_emul_set_reg(ps8xxx_emul, PS8XXX_REG_FW_REV, 0x31); +} + ZTEST_SUITE(ps8805, drivers_predicate_pre_main, NULL, ps8805_before, ps8805_after, NULL); ZTEST_SUITE(ps8815, drivers_predicate_pre_main, NULL, ps8815_before, ps8815_after, NULL); + +ZTEST_SUITE(ps8745, drivers_predicate_pre_main, NULL, ps8745_before, + ps8745_after, NULL); diff --git a/zephyr/test/drivers/prj.conf b/zephyr/test/drivers/prj.conf index a106c568dd..04b9bdd820 100644 --- a/zephyr/test/drivers/prj.conf +++ b/zephyr/test/drivers/prj.conf @@ -119,6 +119,8 @@ CONFIG_PLATFORM_EC_USB_PD_TCPM_PS8805=y CONFIG_PLATFORM_EC_USB_PD_TCPM_PS8805_FORCE_DID=y CONFIG_PLATFORM_EC_USB_PD_TCPM_PS8815=y CONFIG_PLATFORM_EC_USB_PD_TCPM_PS8815_FORCE_DID=y +CONFIG_PLATFORM_EC_USB_PD_TCPM_PS8745=y +CONFIG_PLATFORM_EC_USB_PD_TCPM_PS8745_FORCE_ID=y CONFIG_PLATFORM_EC_USB_PD_TCPM_MULTI_PS8XXX=y CONFIG_PLATFORM_EC_USB_PD_VBUS_DETECT_TCPC=y CONFIG_PLATFORM_EC_USB_PD_REQUIRE_AP_MODE_ENTRY=y |