diff options
author | Jeremy Bettis <jbettis@google.com> | 2022-10-18 16:32:31 -0600 |
---|---|---|
committer | Chromeos LUCI <chromeos-scoped@luci-project-accounts.iam.gserviceaccount.com> | 2022-10-19 18:06:29 +0000 |
commit | 730e8ac2ad096fc55078670fe559213524886a8d (patch) | |
tree | e4d7c5252b89b2ef39abd3b877335d9625de777b | |
parent | 6813bc21369e4045123a739c74d1990f95d3ab16 (diff) | |
download | chrome-ec-730e8ac2ad096fc55078670fe559213524886a8d.tar.gz |
zephyr: Add setup func to qcom tests
Move common setup code to get into S0 to the suite setup function.
BRANCH=None
BUG=None
TEST=twister
Signed-off-by: Jeremy Bettis <jbettis@google.com>
Change-Id: I06a5d8fc327ce581047759245a0500cf760c1f1c
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/3965277
Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Commit-Queue: Jeremy Bettis <jbettis@chromium.org>
Tested-by: Jeremy Bettis <jbettis@chromium.org>
-rw-r--r-- | zephyr/test/qcom_power/src/main.c | 110 |
1 files changed, 36 insertions, 74 deletions
diff --git a/zephyr/test/qcom_power/src/main.c b/zephyr/test/qcom_power/src/main.c index 97743c90bf..6f299119ff 100644 --- a/zephyr/test/qcom_power/src/main.c +++ b/zephyr/test/qcom_power/src/main.c @@ -45,16 +45,11 @@ static void do_chipset_ap_rst_interrupt_in_s3(int times) { static const struct device *ap_rst_dev = DEVICE_DT_GET(DT_GPIO_CTLR(AP_RST_L_NODE, gpios)); - static const struct device *power_good_dev = - DEVICE_DT_GET(DT_GPIO_CTLR(POWER_GOOD_NODE, gpios)); static const struct device *ap_suspend_dev = DEVICE_DT_GET(DT_GPIO_CTLR(AP_SUSPEND_NODE, gpios)); /* Preconditions */ power_signal_enable_interrupt(GPIO_AP_SUSPEND); - power_signal_enable_interrupt(GPIO_AP_RST_L); - zassert_ok(gpio_emul_input_set(power_good_dev, - DT_GPIO_PIN(POWER_GOOD_NODE, gpios), 1)); zassert_ok(gpio_emul_input_set(ap_suspend_dev, DT_GPIO_PIN(AP_SUSPEND_NODE, gpios), 1)); power_set_state(POWER_S3); @@ -122,22 +117,6 @@ static void do_chipset_ap_rst_interrupt_in_s0(int times) { static const struct device *ap_rst_dev = DEVICE_DT_GET(DT_GPIO_CTLR(AP_RST_L_NODE, gpios)); - static const struct device *power_good_dev = - DEVICE_DT_GET(DT_GPIO_CTLR(POWER_GOOD_NODE, gpios)); - static const struct device *ap_suspend_dev = - DEVICE_DT_GET(DT_GPIO_CTLR(AP_SUSPEND_NODE, gpios)); - - /* Preconditions */ - zassert_ok(gpio_emul_input_set(power_good_dev, - DT_GPIO_PIN(POWER_GOOD_NODE, gpios), 1)); - zassert_ok(gpio_emul_input_set(ap_suspend_dev, - DT_GPIO_PIN(AP_SUSPEND_NODE, gpios), 0)); - power_set_state(POWER_S0); - power_signal_disable_interrupt(GPIO_AP_SUSPEND); - power_signal_enable_interrupt(GPIO_AP_RST_L); - task_wake(TASK_ID_CHIPSET); - k_sleep(K_MSEC(10)); - zassert_equal(power_get_state(), POWER_S0); shell_backend_dummy_clear_output(get_ec_shell()); chipset_reset_count = 0; @@ -188,35 +167,9 @@ ZTEST(qcom_power, test_notify_chipset_reset_s0) /* Call chipset_reset, don't provide signals from AP. Verify logs. */ ZTEST(qcom_power, test_chipset_reset_timeout) { - static const struct device *ap_rst_dev = - DEVICE_DT_GET(DT_GPIO_CTLR(AP_RST_L_NODE, gpios)); - static const struct device *power_good_dev = - DEVICE_DT_GET(DT_GPIO_CTLR(POWER_GOOD_NODE, gpios)); - static const struct device *ap_suspend_dev = - DEVICE_DT_GET(DT_GPIO_CTLR(AP_SUSPEND_NODE, gpios)); - static const struct device *switchcap_pg_dev = - DEVICE_DT_GET(DT_GPIO_CTLR(SWITCHCAP_PG_NODE, gpios)); const char *buffer; size_t buffer_size; - /* Preconditions */ - power_signal_disable_interrupt(GPIO_AP_SUSPEND); - power_signal_enable_interrupt(GPIO_AP_RST_L); - zassert_ok(gpio_emul_input_set(power_good_dev, - DT_GPIO_PIN(POWER_GOOD_NODE, gpios), 1)); - zassert_ok(gpio_emul_input_set(ap_suspend_dev, - DT_GPIO_PIN(AP_SUSPEND_NODE, gpios), 0)); - zassert_ok(gpio_emul_input_set(ap_rst_dev, - DT_GPIO_PIN(AP_RST_L_NODE, gpios), 1)); - zassert_ok(gpio_emul_input_set( - switchcap_pg_dev, DT_GPIO_PIN(SWITCHCAP_PG_NODE, gpios), 1)); - power_set_state(POWER_S0); - task_wake(TASK_ID_CHIPSET); - /* Wait for timeout AP_RST_TRANSITION_TIMEOUT. */ - k_sleep(K_MSEC(500)); - zassert_equal(power_get_state(), POWER_S0); - zassert_equal(power_has_signals(POWER_SIGNAL_MASK(0)), 0); - /* Reset. The reason doesn't really matter. */ shell_backend_dummy_clear_output(get_ec_shell()); chipset_reset(CHIPSET_RESET_KB_WARM_REBOOT); @@ -258,37 +211,11 @@ ZTEST(qcom_power, test_chipset_reset_success) { static const struct device *ap_rst_dev = DEVICE_DT_GET(DT_GPIO_CTLR(AP_RST_L_NODE, gpios)); - static const struct device *power_good_dev = - DEVICE_DT_GET(DT_GPIO_CTLR(POWER_GOOD_NODE, gpios)); - static const struct device *ap_suspend_dev = - DEVICE_DT_GET(DT_GPIO_CTLR(AP_SUSPEND_NODE, gpios)); - static const struct device *switchcap_pg_dev = - DEVICE_DT_GET(DT_GPIO_CTLR(SWITCHCAP_PG_NODE, gpios)); static const struct device *pmic_resin_l_dev = DEVICE_DT_GET(DT_GPIO_CTLR(PMIC_RESIN_L_NODE, gpios)); const char *buffer; size_t buffer_size; - /* Preconditions */ - power_signal_disable_interrupt(GPIO_AP_SUSPEND); - power_signal_enable_interrupt(GPIO_AP_RST_L); - zassert_ok(gpio_emul_input_set(power_good_dev, - DT_GPIO_PIN(POWER_GOOD_NODE, gpios), 1)); - zassert_ok(gpio_emul_input_set(ap_suspend_dev, - DT_GPIO_PIN(AP_SUSPEND_NODE, gpios), 0)); - zassert_ok(gpio_emul_input_set(ap_rst_dev, - DT_GPIO_PIN(AP_RST_L_NODE, gpios), 1)); - zassert_ok(gpio_emul_input_set( - switchcap_pg_dev, DT_GPIO_PIN(SWITCHCAP_PG_NODE, gpios), 1)); - zassert_ok(gpio_pin_set(pmic_resin_l_dev, - DT_GPIO_PIN(PMIC_RESIN_L_NODE, gpios), 1)); - power_set_state(POWER_S0); - task_wake(TASK_ID_CHIPSET); - /* Wait for timeout AP_RST_TRANSITION_TIMEOUT. */ - k_sleep(K_MSEC(500)); - zassert_equal(power_get_state(), POWER_S0); - zassert_equal(power_has_signals(POWER_SIGNAL_MASK(0)), 0); - /* Setup callback. */ gpio_init_callback(&gpio_callback, warm_reset_callback, BIT(DT_GPIO_PIN(PMIC_RESIN_L_NODE, gpios))); @@ -313,6 +240,41 @@ ZTEST(qcom_power, test_chipset_reset_success) zassert_equal(power_get_state(), POWER_S0); } +void start_in_s0(void *fixture) +{ + static const struct device *ap_rst_dev = + DEVICE_DT_GET(DT_GPIO_CTLR(AP_RST_L_NODE, gpios)); + static const struct device *power_good_dev = + DEVICE_DT_GET(DT_GPIO_CTLR(POWER_GOOD_NODE, gpios)); + static const struct device *ap_suspend_dev = + DEVICE_DT_GET(DT_GPIO_CTLR(AP_SUSPEND_NODE, gpios)); + static const struct device *switchcap_pg_dev = + DEVICE_DT_GET(DT_GPIO_CTLR(SWITCHCAP_PG_NODE, gpios)); + static const struct device *pmic_resin_l_dev = + DEVICE_DT_GET(DT_GPIO_CTLR(PMIC_RESIN_L_NODE, gpios)); + + power_signal_disable_interrupt(GPIO_AP_SUSPEND); + power_signal_enable_interrupt(GPIO_AP_RST_L); + zassert_ok(gpio_emul_input_set(power_good_dev, + DT_GPIO_PIN(POWER_GOOD_NODE, gpios), 1)); + zassert_ok(gpio_emul_input_set(ap_suspend_dev, + DT_GPIO_PIN(AP_SUSPEND_NODE, gpios), 0)); + zassert_ok(gpio_emul_input_set(ap_rst_dev, + DT_GPIO_PIN(AP_RST_L_NODE, gpios), 1)); + zassert_ok(gpio_emul_input_set( + switchcap_pg_dev, DT_GPIO_PIN(SWITCHCAP_PG_NODE, gpios), 1)); + zassert_ok(gpio_pin_set(pmic_resin_l_dev, + DT_GPIO_PIN(PMIC_RESIN_L_NODE, gpios), 1)); + power_set_state(POWER_S0); + power_signal_interrupt(GPIO_AP_SUSPEND); + task_wake(TASK_ID_CHIPSET); + /* Wait for timeout AP_RST_TRANSITION_TIMEOUT. */ + k_sleep(K_MSEC(500)); + zassert_equal(power_get_state(), POWER_S0, "power_state=%d", + power_get_state()); + zassert_equal(power_has_signals(POWER_SIGNAL_MASK(0)), 0); +} + void qcom_cleanup(void *fixture) { if (gpio_callback.handler != NULL) { @@ -323,7 +285,7 @@ void qcom_cleanup(void *fixture) } } -ZTEST_SUITE(qcom_power, NULL, NULL, NULL, qcom_cleanup, NULL); +ZTEST_SUITE(qcom_power, NULL, NULL, start_in_s0, qcom_cleanup, NULL); /* Wait until battery is totally stable */ int battery_wait_for_stable(void) |