From 5949c9a39700b2645a806513a02e2eacfe85509a Mon Sep 17 00:00:00 2001 From: Abe Levkoy Date: Fri, 3 Jun 2022 11:49:56 -0600 Subject: zephyr test: Use fixture for SYV682x test Convert ZTEST to ZTEST_F. Move repeated definitions to fixture/setup function. BUG=b:234886404 TEST=zmake testall BRANCH=none Signed-off-by: Abe Levkoy Change-Id: I419c57b120ec7a17a4d70c746f75ab3d3d665225 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3689798 Reviewed-by: Wai-Hong Tam --- zephyr/test/drivers/src/ppc_syv682c.c | 297 +++++++++++++++++++--------------- 1 file changed, 166 insertions(+), 131 deletions(-) diff --git a/zephyr/test/drivers/src/ppc_syv682c.c b/zephyr/test/drivers/src/ppc_syv682c.c index 5a4a72ab4f..6bfcca1c9e 100644 --- a/zephyr/test/drivers/src/ppc_syv682c.c +++ b/zephyr/test/drivers/src/ppc_syv682c.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include #include @@ -22,7 +23,11 @@ #define SYV682X_ORD DT_DEP_ORD(DT_NODELABEL(syv682x_emul)) #define GPIO_USB_C1_FRS_EN_PATH DT_PATH(named_gpios, usb_c1_frs_en) -#define GPIO_USB_C1_FRS_EN_PORT DT_GPIO_PIN(GPIO_USB_C1_FRS_EN_PATH, gpios) +struct ppc_syv682c_fixture { + struct i2c_emul *ppc_emul; + const struct device *frs_en_gpio_port; + int frs_en_gpio_pin; +}; /* Configuration for a mock I2C access function that sometimes fails. */ struct reg_to_fail_data { @@ -32,11 +37,22 @@ struct reg_to_fail_data { static const int syv682x_port = 1; -static void syv682x_test_after(void *data) +static void *syv682c_test_setup(void) { - struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); + static struct ppc_syv682c_fixture fixture; + + fixture.ppc_emul = syv682x_emul_get(SYV682X_ORD); + fixture.frs_en_gpio_port = + DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_USB_C1_FRS_EN_PATH, gpios)); + fixture.frs_en_gpio_pin = DT_GPIO_PIN(GPIO_USB_C1_FRS_EN_PATH, gpios); - ARG_UNUSED(data); + return &fixture; +} + +static void syv682x_test_after(void *data) +{ + struct ppc_syv682c_fixture *fixture = data; + struct i2c_emul *emul = fixture->ppc_emul; syv682x_emul_set_condition(emul, SYV682X_STATUS_NONE, SYV682X_CONTROL_4_NONE); @@ -50,7 +66,10 @@ static void syv682x_test_after(void *data) i2c_common_emul_set_write_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); } -ZTEST(ppc_syv682c, test_syv682x_board_is_syv682c) +ZTEST_SUITE(ppc_syv682c, drivers_predicate_post_main, syv682c_test_setup, NULL, + syv682x_test_after, NULL); + +ZTEST_F(ppc_syv682c, test_syv682x_board_is_syv682c) { zassert_true(syv682x_board_is_syv682c(syv682x_port), NULL); } @@ -76,25 +95,23 @@ static void check_control_1_default_init(uint8_t control_1) "Default init, but 5V power path selected"); } -ZTEST(ppc_syv682c, test_syv682x_init) +ZTEST_F(ppc_syv682c, test_syv682x_init) { - struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); - const struct device *gpio_dev = - DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_USB_C1_FRS_EN_PATH, gpios)); uint8_t reg; int ilim; /* * With a dead battery, the device powers up sinking VBUS, and the - * driver should keep that going.. + * driver should keep that going. */ - zassert_ok(syv682x_emul_set_reg(emul, SYV682X_CONTROL_1_REG, + zassert_ok(syv682x_emul_set_reg(this->ppc_emul, SYV682X_CONTROL_1_REG, SYV682X_CONTROL_1_CH_SEL), NULL); - syv682x_emul_set_condition(emul, SYV682X_STATUS_VSAFE_5V, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_VSAFE_5V, SYV682X_CONTROL_4_NONE); zassert_ok(ppc_init(syv682x_port), "PPC init failed"); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_1_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_1_REG, + ®), NULL); zassert_true(reg & SYV682X_CONTROL_1_CH_SEL, "Dead battery init, but CH_SEL set to 5V power path"); @@ -105,24 +122,26 @@ ZTEST(ppc_syv682c, test_syv682x_init) "Dead battery init, but VBUS source enabled"); /* With VBUS at vSafe0V, init should set the default configuration. */ - zassert_ok(syv682x_emul_set_reg(emul, SYV682X_CONTROL_1_REG, + zassert_ok(syv682x_emul_set_reg(this->ppc_emul, SYV682X_CONTROL_1_REG, SYV682X_CONTROL_1_PWR_ENB), NULL); - syv682x_emul_set_condition(emul, SYV682X_STATUS_VSAFE_0V, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_VSAFE_0V, SYV682X_CONTROL_4_NONE); zassert_ok(ppc_init(syv682x_port), "PPC init failed"); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_1_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_1_REG, + ®), NULL); check_control_1_default_init(reg); /* With sink disabled, init should do the same thing. */ - zassert_ok(syv682x_emul_set_reg(emul, SYV682X_CONTROL_1_REG, + zassert_ok(syv682x_emul_set_reg(this->ppc_emul, SYV682X_CONTROL_1_REG, SYV682X_CONTROL_1_CH_SEL), NULL); - syv682x_emul_set_condition(emul, SYV682X_STATUS_VSAFE_0V, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_VSAFE_0V, SYV682X_CONTROL_4_NONE); zassert_ok(ppc_init(syv682x_port), "PPC init failed"); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_1_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_1_REG, + ®), NULL); check_control_1_default_init(reg); @@ -131,12 +150,14 @@ ZTEST(ppc_syv682c, test_syv682x_init) * current limit according to configuration, set over-current, over- * voltage, and discharge parameters appropriately, and enable CC lines. */ - zassert_equal(gpio_emul_output_get(gpio_dev, GPIO_USB_C1_FRS_EN_PORT), + zassert_equal(gpio_emul_output_get(this->frs_en_gpio_port, + this->frs_en_gpio_pin), 0, "FRS enabled, but FRS GPIO not asserted"); ilim = (reg & SYV682X_5V_ILIM_MASK) >> SYV682X_5V_ILIM_BIT_SHIFT; zassert_equal(ilim, CONFIG_PLATFORM_EC_USB_PD_PULLUP, "Default init, but 5V current limit set to %d", ilim); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_2_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_2_REG, + ®), NULL); zassert_equal(reg, (SYV682X_OC_DELAY_10MS << SYV682X_OC_DELAY_SHIFT) | @@ -144,32 +165,34 @@ ZTEST(ppc_syv682c, test_syv682x_init) << SYV682X_DSG_RON_SHIFT) | (SYV682X_DSG_TIME_50MS << SYV682X_DSG_TIME_SHIFT), "Default init, but CONTROL_2 is 0x%x", reg); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_3_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_3_REG, + ®), NULL); zassert_equal(reg, (SYV682X_OVP_23_7 << SYV682X_OVP_BIT_SHIFT) | SYV682X_RVS_MASK, "Default init, but CONTROL_3 is 0x%x", reg); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_4_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_4_REG, + ®), NULL); zassert_equal(reg & ~SYV682X_CONTROL_4_INT_MASK, SYV682X_CONTROL_4_CC1_BPS | SYV682X_CONTROL_4_CC2_BPS, "Default init, but CONTROL_4 is 0x%x", reg); /* Disable the power path again. */ - zassert_ok(syv682x_emul_set_reg(emul, SYV682X_CONTROL_1_REG, + zassert_ok(syv682x_emul_set_reg(this->ppc_emul, SYV682X_CONTROL_1_REG, SYV682X_CONTROL_1_PWR_ENB), NULL); - syv682x_emul_set_condition(emul, SYV682X_STATUS_NONE, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_NONE, SYV682X_CONTROL_4_NONE); } -ZTEST(ppc_syv682c, test_syv682x_vbus_enable) +ZTEST_F(ppc_syv682c, test_syv682x_vbus_enable) { - struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); uint8_t reg; - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_1_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_1_REG, + ®), "Reading CONTROL_1 failed"); zassert_not_equal(reg & SYV682X_CONTROL_1_PWR_ENB, SYV682X_CONTROL_1_PWR_ENB, "VBUS sourcing disabled"); @@ -178,7 +201,8 @@ ZTEST(ppc_syv682c, test_syv682x_vbus_enable) zassert_ok(ppc_vbus_source_enable(syv682x_port, true), "VBUS enable failed"); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_1_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_1_REG, + ®), "Reading CONTROL_1 failed"); zassert_equal(reg & SYV682X_CONTROL_1_PWR_ENB, 0, "VBUS sourcing disabled"); @@ -186,15 +210,14 @@ ZTEST(ppc_syv682c, test_syv682x_vbus_enable) "PPC is not sourcing VBUS after VBUS enabled"); } -ZTEST(ppc_syv682c, test_syv682x_interrupt) +ZTEST_F(ppc_syv682c, test_syv682x_interrupt) { - struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); uint8_t reg; zassert_ok(ppc_vbus_source_enable(syv682x_port, true), "VBUS enable failed"); /* An OC event less than 100 ms should not cause VBUS to turn off. */ - syv682x_emul_set_condition(emul, SYV682X_STATUS_OC_5V, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_OC_5V, SYV682X_CONTROL_4_NONE); msleep(50); zassert_true(ppc_is_sourcing_vbus(syv682x_port), @@ -204,7 +227,7 @@ ZTEST(ppc_syv682c, test_syv682x_interrupt) zassert_false(ppc_is_sourcing_vbus(syv682x_port), "PPC is sourcing VBUS after 100 ms OC"); - syv682x_emul_set_condition(emul, SYV682X_STATUS_NONE, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_NONE, SYV682X_CONTROL_4_NONE); /* * TODO(b/190519131): Organize the tests to be more hermetic and avoid @@ -221,23 +244,23 @@ ZTEST(ppc_syv682c, test_syv682x_interrupt) */ zassert_ok(ppc_vbus_source_enable(syv682x_port, true), "Source enable failed"); - syv682x_emul_set_condition(emul, SYV682X_STATUS_TSD, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_TSD, SYV682X_CONTROL_4_NONE); msleep(1); zassert_false(ppc_is_sourcing_vbus(syv682x_port), "PPC is sourcing power after TSD"); - syv682x_emul_set_condition(emul, SYV682X_STATUS_NONE, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_NONE, SYV682X_CONTROL_4_NONE); /* An OVP event should cause the driver to disable the source path. */ zassert_ok(ppc_vbus_source_enable(syv682x_port, true), "Source enable failed"); - syv682x_emul_set_condition(emul, SYV682X_STATUS_OVP, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_OVP, SYV682X_CONTROL_4_NONE); msleep(1); zassert_false(ppc_is_sourcing_vbus(syv682x_port), "PPC is sourcing power after OVP"); - syv682x_emul_set_condition(emul, SYV682X_STATUS_NONE, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_NONE, SYV682X_CONTROL_4_NONE); /* @@ -247,31 +270,34 @@ ZTEST(ppc_syv682c, test_syv682x_interrupt) */ zassert_ok(ppc_vbus_sink_enable(syv682x_port, true), "Sink enable failed"); - syv682x_emul_set_condition(emul, SYV682X_STATUS_OC_HV, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_OC_HV, SYV682X_CONTROL_4_NONE); msleep(1); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_1_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_1_REG, + ®), "Reading CONTROL_1 failed"); zassert_equal(reg & SYV682X_CONTROL_1_PWR_ENB, 0, "Power path disabled after HV_OC handled"); - syv682x_emul_set_condition(emul, SYV682X_STATUS_OC_HV, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_OC_HV, SYV682X_CONTROL_4_NONE); /* Alert GPIO doesn't change so wait for delayed syv682x interrupt */ msleep(15); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_1_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_1_REG, + ®), "Reading CONTROL_1 failed"); zassert_equal(reg & SYV682X_CONTROL_1_PWR_ENB, 0, "Power path disabled after HV_OC handled"); - syv682x_emul_set_condition(emul, SYV682X_STATUS_OC_HV, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_OC_HV, SYV682X_CONTROL_4_NONE); /* Alert GPIO doesn't change so wait for delayed syv682x interrupt */ msleep(15); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_1_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_1_REG, + ®), "Reading CONTROL_1 failed"); zassert_equal(reg & SYV682X_CONTROL_1_PWR_ENB, SYV682X_CONTROL_1_PWR_ENB, "Power path enabled after HV_OC handled 3 times"); - syv682x_emul_set_condition(emul, SYV682X_STATUS_NONE, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_NONE, SYV682X_CONTROL_4_NONE); /* @@ -279,16 +305,18 @@ ZTEST(ppc_syv682c, test_syv682x_interrupt) * VCONN off. */ ppc_set_vconn(syv682x_port, true); - syv682x_emul_set_condition(emul, SYV682X_STATUS_NONE, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_NONE, SYV682X_CONTROL_4_VCONN_OCP); msleep(1); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_4_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_4_REG, + ®), "Reading CONTROL_4 failed"); zassert_true(reg & (SYV682X_CONTROL_4_VCONN1 | SYV682X_CONTROL_4_VCONN2), "VCONN disabled after initial VCONN OC"); msleep(50); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_4_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_4_REG, + ®), "Reading CONTROL_4 failed"); zassert_true(reg & (SYV682X_CONTROL_4_VCONN1 | SYV682X_CONTROL_4_VCONN2), @@ -298,12 +326,13 @@ ZTEST(ppc_syv682c, test_syv682x_interrupt) * should turn VCONN off. */ msleep(60); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_4_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_4_REG, + ®), "Reading CONTROL_4 failed"); zassert_false(reg & (SYV682X_CONTROL_4_VCONN1 | SYV682X_CONTROL_4_VCONN2), "VCONN enabled after long VCONN OC"); - syv682x_emul_set_condition(emul, SYV682X_STATUS_NONE, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_NONE, SYV682X_CONTROL_4_NONE); /* @@ -313,10 +342,11 @@ ZTEST(ppc_syv682c, test_syv682x_interrupt) * driver should then run generic CC over-voltage handling. */ ppc_set_vconn(syv682x_port, true); - syv682x_emul_set_condition(emul, SYV682X_STATUS_NONE, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_NONE, SYV682X_CONTROL_4_VBAT_OVP); msleep(1); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_4_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_4_REG, + ®), "Reading CONTROL_4 failed"); zassert_true(reg & SYV682X_CONTROL_4_CC1_BPS, "CC1 disabled after handling VBAT_OVP"); @@ -330,13 +360,12 @@ ZTEST(ppc_syv682c, test_syv682x_interrupt) * to a CC over-voltage event. There is currently no easy way to test * that a Hard Reset occurred. */ - syv682x_emul_set_condition(emul, SYV682X_STATUS_NONE, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_NONE, SYV682X_CONTROL_4_NONE); } -ZTEST(ppc_syv682c, test_syv682x_frs) +ZTEST_F(ppc_syv682c, test_syv682x_frs) { - struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); const struct device *gpio_dev = DEVICE_DT_GET(DT_GPIO_CTLR(GPIO_USB_C1_FRS_EN_PATH, gpios)); uint8_t reg; @@ -350,18 +379,20 @@ ZTEST(ppc_syv682c, test_syv682x_frs) "PPC is sourcing VBUS after sink enabled"); ppc_set_polarity(syv682x_port, 0 /* CC1 */); ppc_set_frs_enable(syv682x_port, true); - zassert_equal(gpio_emul_output_get(gpio_dev, GPIO_USB_C1_FRS_EN_PORT), - 1, "FRS enabled, but FRS GPIO not asserted"); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_4_REG, ®), + zassert_equal(gpio_emul_output_get(gpio_dev, this->frs_en_gpio_pin), 1, + "FRS enabled, but FRS GPIO not asserted"); + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_4_REG, + ®), "Reading CONTROL_4 failed"); zassert_equal( reg & (SYV682X_CONTROL_4_CC1_BPS | SYV682X_CONTROL_4_CC2_BPS), SYV682X_CONTROL_4_CC1_BPS, "FRS enabled with CC1 polarity, but CONTROL_4 is 0x%x", reg); ppc_set_frs_enable(syv682x_port, false); - zassert_equal(gpio_emul_output_get(gpio_dev, GPIO_USB_C1_FRS_EN_PORT), - 0, "FRS disabled, but FRS GPIO not deasserted"); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_4_REG, ®), + zassert_equal(gpio_emul_output_get(gpio_dev, this->frs_en_gpio_pin), 0, + "FRS disabled, but FRS GPIO not deasserted"); + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_4_REG, + ®), "Reading CONTROL_4 failed"); zassert_equal( reg & (SYV682X_CONTROL_4_CC1_BPS | SYV682X_CONTROL_4_CC2_BPS), @@ -370,7 +401,8 @@ ZTEST(ppc_syv682c, test_syv682x_frs) ppc_set_polarity(syv682x_port, 1 /* CC2 */); ppc_set_frs_enable(syv682x_port, true); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_4_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_4_REG, + ®), "Reading CONTROL_4 failed"); zassert_equal( reg & (SYV682X_CONTROL_4_CC1_BPS | SYV682X_CONTROL_4_CC2_BPS), @@ -381,25 +413,25 @@ ZTEST(ppc_syv682c, test_syv682x_frs) * An FRS event when the PPC is Sink should cause the PPC to switch from * Sink to Source. */ - syv682x_emul_set_condition(emul, SYV682X_STATUS_FRS, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_FRS, SYV682X_CONTROL_4_NONE); msleep(1); zassert_true(ppc_is_sourcing_vbus(syv682x_port), "PPC is not sourcing VBUS after FRS signal handled"); - syv682x_emul_set_condition(emul, SYV682X_STATUS_NONE, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_NONE, SYV682X_CONTROL_4_NONE); } -ZTEST(ppc_syv682c, test_syv682x_source_current_limit) +ZTEST_F(ppc_syv682c, test_syv682x_source_current_limit) { - struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); uint8_t reg; int ilim_val; zassert_ok(ppc_set_vbus_source_current_limit(syv682x_port, TYPEC_RP_USB), "Could not set source current limit"); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_1_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_1_REG, + ®), "Reading CONTROL_1 failed"); ilim_val = (reg & SYV682X_5V_ILIM_MASK) >> SYV682X_5V_ILIM_BIT_SHIFT; zassert_equal(reg & SYV682X_5V_ILIM_MASK, SYV682X_5V_ILIM_1_25, @@ -408,7 +440,8 @@ ZTEST(ppc_syv682c, test_syv682x_source_current_limit) zassert_ok(ppc_set_vbus_source_current_limit(syv682x_port, TYPEC_RP_1A5), "Could not set source current limit"); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_1_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_1_REG, + ®), "Reading CONTROL_1 failed"); ilim_val = (reg & SYV682X_5V_ILIM_MASK) >> SYV682X_5V_ILIM_BIT_SHIFT; zassert_equal(ilim_val, SYV682X_5V_ILIM_1_75, @@ -417,17 +450,16 @@ ZTEST(ppc_syv682c, test_syv682x_source_current_limit) zassert_ok(ppc_set_vbus_source_current_limit(syv682x_port, TYPEC_RP_3A0), "Could not set source current limit"); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_1_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_1_REG, + ®), "Reading CONTROL_1 failed"); ilim_val = (reg & SYV682X_5V_ILIM_MASK) >> SYV682X_5V_ILIM_BIT_SHIFT; zassert_equal(ilim_val, SYV682X_5V_ILIM_3_30, "Set 3.0A Rp value, but 5V_ILIM is %d", ilim_val); } -ZTEST(ppc_syv682c, test_syv682x_write_busy) +ZTEST_F(ppc_syv682c, test_syv682x_write_busy) { - struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); - /* * Writes should fail while the BUSY bit is set, except that writes to * CONTROL_4 should succeed on the SYV682C. 1000 reads is intentionally @@ -435,7 +467,7 @@ ZTEST(ppc_syv682c, test_syv682x_write_busy) * timeout. It is not a goal of this test to verify the frequency of * polling or the exact value of the timeout. */ - syv682x_emul_set_busy_reads(emul, 1000); + syv682x_emul_set_busy_reads(this->ppc_emul, 1000); zassert_equal(ppc_set_vbus_source_current_limit(syv682x_port, TYPEC_RP_USB), EC_ERROR_TIMEOUT, "SYV682 busy, but write completed"); @@ -446,29 +478,30 @@ ZTEST(ppc_syv682c, test_syv682x_write_busy) * If the busy bit clears before the driver reaches its timeout, the * write should succeed. */ - syv682x_emul_set_busy_reads(emul, 1); + syv682x_emul_set_busy_reads(this->ppc_emul, 1); zassert_equal(ppc_set_vbus_source_current_limit(syv682x_port, TYPEC_RP_USB), 0, "SYV682 not busy, but write failed"); - syv682x_emul_set_busy_reads(emul, 0); + syv682x_emul_set_busy_reads(this->ppc_emul, 0); } -ZTEST(ppc_syv682c, test_syv682x_dev_is_connected) +ZTEST_F(ppc_syv682c, test_syv682x_dev_is_connected) { - struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); uint8_t reg; zassert_ok(ppc_dev_is_connected(syv682x_port, PPC_DEV_SRC), "Could not connect device as source"); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_2_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_2_REG, + ®), "Reading CONTROL_2 failed"); zassert_false(reg & SYV682X_CONTROL_2_FDSG, "Connected as source, but force discharge enabled"); zassert_ok(ppc_dev_is_connected(syv682x_port, PPC_DEV_DISCONNECTED), "Could not disconnect device"); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_2_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_2_REG, + ®), "Reading CONTROL_2 failed"); zassert_true(reg & SYV682X_CONTROL_2_FDSG, "Disconnected, but force discharge disabled"); @@ -477,9 +510,8 @@ ZTEST(ppc_syv682c, test_syv682x_dev_is_connected) "Could not connect device as source"); } -ZTEST(ppc_syv682c, test_syv682x_vbus_sink_enable) +ZTEST_F(ppc_syv682c, test_syv682x_vbus_sink_enable) { - struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); uint8_t reg; int ilim; @@ -500,7 +532,8 @@ ZTEST(ppc_syv682c, test_syv682x_vbus_sink_enable) "VBUS enable failed"); zassert_ok(ppc_vbus_sink_enable(syv682x_port, true), "Sink disable failed"); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_1_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_1_REG, + ®), NULL); zassert_true(reg & SYV682X_CONTROL_1_CH_SEL, "Sink enabled, but CH_SEL set to 5V power path"); @@ -514,16 +547,15 @@ ZTEST(ppc_syv682c, test_syv682x_vbus_sink_enable) zassert_ok(ppc_vbus_sink_enable(syv682x_port, false), "Sink disable failed"); - zassert_ok(syv682x_emul_get_reg(emul, SYV682X_CONTROL_1_REG, ®), + zassert_ok(syv682x_emul_get_reg(this->ppc_emul, SYV682X_CONTROL_1_REG, + ®), NULL); zassert_true(reg & SYV682X_CONTROL_1_PWR_ENB, "Sink disabled, but power path enabled"); } -ZTEST(ppc_syv682c, test_syv682x_vbus_sink_oc_limit) +ZTEST_F(ppc_syv682c, test_syv682x_vbus_sink_oc_limit) { - struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); - zassert_ok(ppc_vbus_sink_enable(syv682x_port, true), "Sink enable failed"); @@ -532,11 +564,11 @@ ZTEST(ppc_syv682c, test_syv682x_vbus_sink_oc_limit) * cleared by sink disable. */ for (int i = 0; i < 4; ++i) { - syv682x_emul_set_condition(emul, SYV682X_STATUS_OC_HV, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_OC_HV, SYV682X_CONTROL_4_NONE); msleep(15); } - syv682x_emul_set_condition(emul, SYV682X_STATUS_NONE, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_NONE, SYV682X_CONTROL_4_NONE); zassert_not_equal(ppc_vbus_sink_enable(syv682x_port, true), EC_SUCCESS, @@ -550,11 +582,9 @@ ZTEST(ppc_syv682c, test_syv682x_vbus_sink_oc_limit) "Sink disable failed"); } -ZTEST(ppc_syv682c, test_syv682x_set_vconn) +ZTEST_F(ppc_syv682c, test_syv682x_set_vconn) { - struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); - - syv682x_emul_set_condition(emul, SYV682X_STATUS_NONE, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_NONE, SYV682X_CONTROL_4_VBAT_OVP); zassert_not_equal(ppc_set_vconn(syv682x_port, true), EC_SUCCESS, "VBAT OVP, but ppc_set_vconn succeeded"); @@ -588,20 +618,18 @@ static int mock_read_intercept_reg_fail(struct i2c_emul *emul, int reg, return 1; } -ZTEST(ppc_syv682c, test_syv682x_i2c_error_status) +ZTEST_F(ppc_syv682c, test_syv682x_i2c_error_status) { - struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); - /* Failed STATUS read should cause init to fail. */ - i2c_common_emul_set_read_fail_reg(emul, SYV682X_STATUS_REG); + i2c_common_emul_set_read_fail_reg(this->ppc_emul, SYV682X_STATUS_REG); zassert_not_equal(ppc_init(syv682x_port), EC_SUCCESS, "STATUS read error, but init succeeded"); - i2c_common_emul_set_read_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); + i2c_common_emul_set_read_fail_reg(this->ppc_emul, + I2C_COMMON_EMUL_NO_FAIL_REG); } -ZTEST(ppc_syv682c, test_syv682x_i2c_error_control_1) +ZTEST_F(ppc_syv682c, test_syv682x_i2c_error_control_1) { - struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); const struct ppc_drv *drv = ppc_chips[syv682x_port].drv; struct reg_to_fail_data reg_fail = { .reg_access_to_fail = 0, @@ -609,7 +637,8 @@ ZTEST(ppc_syv682c, test_syv682x_i2c_error_control_1) }; /* Failed CONTROL_1 read */ - i2c_common_emul_set_read_fail_reg(emul, SYV682X_CONTROL_1_REG); + i2c_common_emul_set_read_fail_reg(this->ppc_emul, + SYV682X_CONTROL_1_REG); zassert_not_equal(ppc_init(syv682x_port), EC_SUCCESS, "CONTROL_1 read error, but init succeeded"); zassert_not_equal(ppc_vbus_source_enable(syv682x_port, true), @@ -626,32 +655,34 @@ ZTEST(ppc_syv682c, test_syv682x_i2c_error_control_1) "succeeded"); zassert_ok(drv->reg_dump(syv682x_port), "CONTROL_1 read error, and ppc_dump failed"); - i2c_common_emul_set_read_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); + i2c_common_emul_set_read_fail_reg(this->ppc_emul, + I2C_COMMON_EMUL_NO_FAIL_REG); /* Init reads CONTROL_1 several times. The 3rd read happens while * setting the source current limit. Check that init fails when that * read fails. */ - i2c_common_emul_set_read_func(emul, &mock_read_intercept_reg_fail, - ®_fail); + i2c_common_emul_set_read_func(this->ppc_emul, + &mock_read_intercept_reg_fail, ®_fail); reg_fail.reg_access_to_fail = SYV682X_CONTROL_1_REG; reg_fail.reg_access_fail_countdown = 3; zassert_not_equal(ppc_init(syv682x_port), EC_SUCCESS, "CONTROL_1 read error, but init succeeded"); - i2c_common_emul_set_read_func(emul, NULL, NULL); + i2c_common_emul_set_read_func(this->ppc_emul, NULL, NULL); /* Failed CONTROL_1 write */ - i2c_common_emul_set_write_fail_reg(emul, SYV682X_CONTROL_1_REG); + i2c_common_emul_set_write_fail_reg(this->ppc_emul, + SYV682X_CONTROL_1_REG); /* During init, the driver will write CONTROL_1 either to disable all * power paths (normal case) or to enable the sink path (dead battery * case). vSafe0V in STATUS is one indication of the normal case. */ - syv682x_emul_set_condition(emul, SYV682X_STATUS_VSAFE_0V, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_VSAFE_0V, SYV682X_CONTROL_4_NONE); zassert_not_equal(ppc_init(syv682x_port), EC_SUCCESS, "CONTROL_1 write error, but init succeeded"); - syv682x_emul_set_condition(emul, SYV682X_STATUS_NONE, + syv682x_emul_set_condition(this->ppc_emul, SYV682X_STATUS_NONE, SYV682X_CONTROL_4_NONE); zassert_not_equal(ppc_init(syv682x_port), EC_SUCCESS, "CONTROL_1 write error, but init succeeded"); @@ -660,61 +691,65 @@ ZTEST(ppc_syv682c, test_syv682x_i2c_error_control_1) EC_SUCCESS, "CONTROL_1 write error, but VBUS source " "enable succeeded"); - i2c_common_emul_set_write_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); + i2c_common_emul_set_write_fail_reg(this->ppc_emul, + I2C_COMMON_EMUL_NO_FAIL_REG); } -ZTEST(ppc_syv682c, test_syv682x_i2c_error_control_2) +ZTEST_F(ppc_syv682c, test_syv682x_i2c_error_control_2) { - struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); - /* Failed CONTROL_2 read */ - i2c_common_emul_set_read_fail_reg(emul, SYV682X_CONTROL_2_REG); + i2c_common_emul_set_read_fail_reg(this->ppc_emul, + SYV682X_CONTROL_2_REG); zassert_not_equal(ppc_discharge_vbus(syv682x_port, true), EC_SUCCESS, "CONTROL_2 read error, but VBUS discharge succeeded"); - i2c_common_emul_set_read_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); + i2c_common_emul_set_read_fail_reg(this->ppc_emul, + I2C_COMMON_EMUL_NO_FAIL_REG); /* Failed CONTROL_2 write */ - i2c_common_emul_set_write_fail_reg(emul, SYV682X_CONTROL_2_REG); + i2c_common_emul_set_write_fail_reg(this->ppc_emul, + SYV682X_CONTROL_2_REG); zassert_not_equal(ppc_init(syv682x_port), EC_SUCCESS, "CONTROL_2 write error, but init succeeded"); - i2c_common_emul_set_write_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); + i2c_common_emul_set_write_fail_reg(this->ppc_emul, + I2C_COMMON_EMUL_NO_FAIL_REG); } -ZTEST(ppc_syv682c, test_syv682x_i2c_error_control_3) +ZTEST_F(ppc_syv682c, test_syv682x_i2c_error_control_3) { - struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); - /* Failed CONTROL_3 read */ - i2c_common_emul_set_read_fail_reg(emul, SYV682X_CONTROL_3_REG); + i2c_common_emul_set_read_fail_reg(this->ppc_emul, + SYV682X_CONTROL_3_REG); zassert_not_equal(ppc_init(syv682x_port), EC_SUCCESS, "CONTROL_3 read error, but VBUS discharge succeeded"); - i2c_common_emul_set_read_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); + i2c_common_emul_set_read_fail_reg(this->ppc_emul, + I2C_COMMON_EMUL_NO_FAIL_REG); /* Failed CONTROL_3 write */ - i2c_common_emul_set_write_fail_reg(emul, SYV682X_CONTROL_3_REG); + i2c_common_emul_set_write_fail_reg(this->ppc_emul, + SYV682X_CONTROL_3_REG); zassert_not_equal(ppc_init(syv682x_port), EC_SUCCESS, "CONTROL_3 write error, but init succeeded"); - i2c_common_emul_set_write_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); + i2c_common_emul_set_write_fail_reg(this->ppc_emul, + I2C_COMMON_EMUL_NO_FAIL_REG); } -ZTEST(ppc_syv682c, test_syv682x_i2c_error_control_4) +ZTEST_F(ppc_syv682c, test_syv682x_i2c_error_control_4) { - struct i2c_emul *emul = syv682x_emul_get(SYV682X_ORD); - /* Failed CONTROL_4 read */ - i2c_common_emul_set_read_fail_reg(emul, SYV682X_CONTROL_4_REG); + i2c_common_emul_set_read_fail_reg(this->ppc_emul, + SYV682X_CONTROL_4_REG); zassert_not_equal(ppc_set_vconn(syv682x_port, true), EC_SUCCESS, "CONTROL_2 read error, but VCONN set succeeded"); - i2c_common_emul_set_read_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); + i2c_common_emul_set_read_fail_reg(this->ppc_emul, + I2C_COMMON_EMUL_NO_FAIL_REG); /* Failed CONTROL_4 write */ - i2c_common_emul_set_write_fail_reg(emul, SYV682X_CONTROL_4_REG); + i2c_common_emul_set_write_fail_reg(this->ppc_emul, + SYV682X_CONTROL_4_REG); zassert_not_equal(ppc_init(syv682x_port), EC_SUCCESS, "CONTROL_4 write error, but init succeeded"); zassert_not_equal(ppc_set_vconn(syv682x_port, true), EC_SUCCESS, "CONTROL_4 write error, but VCONN set succeeded"); - i2c_common_emul_set_write_fail_reg(emul, I2C_COMMON_EMUL_NO_FAIL_REG); + i2c_common_emul_set_write_fail_reg(this->ppc_emul, + I2C_COMMON_EMUL_NO_FAIL_REG); } - -ZTEST_SUITE(ppc_syv682c, drivers_predicate_post_main, NULL, NULL, - syv682x_test_after, NULL); -- cgit v1.2.1