diff options
Diffstat (limited to 'zephyr/test/ap_power/src')
-rw-r--r-- | zephyr/test/ap_power/src/ap_pwrseq.c | 141 | ||||
-rw-r--r-- | zephyr/test/ap_power/src/board.c | 29 | ||||
-rw-r--r-- | zephyr/test/ap_power/src/console_command.c | 6 | ||||
-rw-r--r-- | zephyr/test/ap_power/src/events.c | 15 | ||||
-rw-r--r-- | zephyr/test/ap_power/src/hibdelay.c | 37 | ||||
-rw-r--r-- | zephyr/test/ap_power/src/hibernate.c | 39 | ||||
-rw-r--r-- | zephyr/test/ap_power/src/host_command.c | 28 | ||||
-rw-r--r-- | zephyr/test/ap_power/src/main.c | 5 | ||||
-rw-r--r-- | zephyr/test/ap_power/src/signals.c | 20 | ||||
-rw-r--r-- | zephyr/test/ap_power/src/test_mocks.c | 30 |
10 files changed, 31 insertions, 319 deletions
diff --git a/zephyr/test/ap_power/src/ap_pwrseq.c b/zephyr/test/ap_power/src/ap_pwrseq.c deleted file mode 100644 index 6c2fd4fd7f..0000000000 --- a/zephyr/test/ap_power/src/ap_pwrseq.c +++ /dev/null @@ -1,141 +0,0 @@ -/* Copyright 2022 The ChromiumOS Authors - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "ap_power/ap_power.h" -#include "ap_power/ap_power_interface.h" -#include "chipset.h" -#include "emul/emul_power_signals.h" -#include "test_state.h" - -#include <zephyr/drivers/espi.h> -#include <zephyr/drivers/espi_emul.h> -#include <zephyr/drivers/gpio/gpio_emul.h> -#include <zephyr/kernel.h> -#include <zephyr/logging/log.h> -#include <zephyr/ztest.h> - -#include <ap_power/ap_pwrseq.h> - -static struct ap_power_ev_callback test_cb; -static int power_resume_count; -static int power_start_up_count; -static int power_hard_off_count; -static int power_shutdown_count; -static int power_shutdown_complete_count; -static int power_suspend_count; - -static void emul_ev_handler(struct ap_power_ev_callback *callback, - struct ap_power_ev_data data) -{ - switch (data.event) { - case AP_POWER_RESUME: - power_resume_count++; - break; - - case AP_POWER_STARTUP: - power_start_up_count++; - break; - - case AP_POWER_HARD_OFF: - power_hard_off_count++; - break; - - case AP_POWER_SHUTDOWN: - power_shutdown_count++; - break; - - case AP_POWER_SHUTDOWN_COMPLETE: - power_shutdown_complete_count++; - break; - - case AP_POWER_SUSPEND: - power_suspend_count++; - break; - default: - break; - }; -} - -ZTEST(ap_pwrseq, test_ap_pwrseq_0) -{ - zassert_equal(0, - power_signal_emul_load( - EMUL_POWER_SIGNAL_TEST_PLATFORM(tp_sys_g3_to_s0)), - "Unable to load test platfform `tp_sys_g3_to_s0`"); - - k_msleep(500); - - zassert_equal(1, power_start_up_count, - "AP_POWER_STARTUP event not generated"); - zassert_equal(1, power_resume_count, - "AP_POWER_RESUME event not generated"); -} - -ZTEST(ap_pwrseq, test_ap_pwrseq_1) -{ - zassert_equal(0, - power_signal_emul_load(EMUL_POWER_SIGNAL_TEST_PLATFORM( - tp_sys_s0_power_fail)), - "Unable to load test platfform `tp_sys_s0_power_fail`"); - - /* - * Once emulated power signals are loaded, we need to wake AP power - * Sequence thread up to start executing new set of power signals - */ - ap_pwrseq_wake(); - k_msleep(500); - zassert_equal(1, power_shutdown_count, - "AP_POWER_SHUTDOWN event not generated"); - zassert_equal(1, power_shutdown_complete_count, - "AP_POWER_SHUTDOWN_COMPLETE event not generated"); - zassert_equal(0, power_suspend_count, - "AP_POWER_SUSPEND event generated"); -} - -ZTEST(ap_pwrseq, test_ap_pwrseq_2) -{ - zassert_equal( - 0, - power_signal_emul_load(EMUL_POWER_SIGNAL_TEST_PLATFORM( - tp_sys_g3_to_s0_power_down)), - "Unable to load test platfform `tp_sys_g3_to_s0_power_down`"); - - ap_power_exit_hardoff(); - k_msleep(2000); - zassert_equal(3, power_shutdown_count, - "AP_POWER_SHUTDOWN event not generated"); - zassert_equal(3, power_shutdown_complete_count, - "AP_POWER_SHUTDOWN_COMPLETE event not generated"); - zassert_equal(1, power_suspend_count, - "AP_POWER_SUSPEND event generated"); - zassert_equal(1, power_hard_off_count, - "AP_POWER_HARD_OFF event generated"); -} - -void ap_pwrseq_after_test(void *data) -{ - power_signal_emul_unload(); -} - -void *ap_pwrseq_setup_suite(void) -{ - ap_power_ev_init_callback(&test_cb, emul_ev_handler, - AP_POWER_RESUME | AP_POWER_STARTUP | - AP_POWER_HARD_OFF | AP_POWER_SUSPEND | - AP_POWER_SHUTDOWN | - AP_POWER_SHUTDOWN_COMPLETE); - - ap_power_ev_add_callback(&test_cb); - - return NULL; -} - -void ap_pwrseq_teardown_suite(void *data) -{ - ap_power_ev_remove_callback(&test_cb); -} - -ZTEST_SUITE(ap_pwrseq, ap_power_predicate_post_main, ap_pwrseq_setup_suite, - NULL, ap_pwrseq_after_test, NULL); diff --git a/zephyr/test/ap_power/src/board.c b/zephyr/test/ap_power/src/board.c index f08ccf9ef7..26c9448396 100644 --- a/zephyr/test/ap_power/src/board.c +++ b/zephyr/test/ap_power/src/board.c @@ -6,11 +6,9 @@ #include <zephyr/kernel.h> #include <zephyr/ztest.h> -#include <ap_power/ap_power_interface.h> #include <ap_power_override_functions.h> +#include <ap_power/ap_power_interface.h> #include <power_signals.h> -#include <timer.h> -#include <x86_power_signals.h> static bool signal_PWR_ALL_SYS_PWRGD; static bool signal_PWR_DSW_PWROK; @@ -61,29 +59,11 @@ void board_ap_power_force_shutdown(void) int board_ap_power_assert_pch_power_ok(void) { - power_signal_set(PWR_PCH_PWROK, 1); return 0; } -static void generate_ec_soc_dsw_pwrok_handler(void) -{ - int in_sig_val = power_signal_get(PWR_DSW_PWROK); - - if (in_sig_val != power_signal_get(PWR_EC_SOC_DSW_PWROK)) { - power_signal_set(PWR_EC_SOC_DSW_PWROK, 1); - } -} - void board_ap_power_action_g3_s5(void) { - power_signal_enable(PWR_DSW_PWROK); - - power_signal_set(PWR_EN_PP3300_A, 1); - power_signal_set(PWR_EN_PP5000_A, 1); - - power_wait_signals_timeout(IN_PGOOD_ALL_CORE, 100 * MSEC); - - generate_ec_soc_dsw_pwrok_handler(); } void board_ap_power_action_s3_s0(void) @@ -100,5 +80,10 @@ void board_ap_power_action_s0(void) bool board_ap_power_check_power_rails_enabled(void) { - return true; + return false; +} + +int extpower_is_present(void) +{ + return 0; } diff --git a/zephyr/test/ap_power/src/console_command.c b/zephyr/test/ap_power/src/console_command.c index 7789a13919..9d38e773c7 100644 --- a/zephyr/test/ap_power/src/console_command.c +++ b/zephyr/test/ap_power/src/console_command.c @@ -3,13 +3,13 @@ * found in the LICENSE file. */ +#include <zephyr/shell/shell.h> +#include <zephyr/ztest.h> + #include "console.h" #include "ec_commands.h" #include "test_state.h" -#include <zephyr/shell/shell.h> -#include <zephyr/ztest.h> - ZTEST_USER(console_cmd_debug_mode, test_debug_mode_default) { zassert_ok(shell_execute_cmd(get_ec_shell(), "debug_mode"), diff --git a/zephyr/test/ap_power/src/events.c b/zephyr/test/ap_power/src/events.c index 2528d356f6..ae7d2b870f 100644 --- a/zephyr/test/ap_power/src/events.c +++ b/zephyr/test/ap_power/src/events.c @@ -8,18 +8,20 @@ * @brief Unit Tests for AP power events */ -#include "ap_power/ap_power.h" -#include "ap_power/ap_power_events.h" -#include "hooks.h" -#include "test_state.h" - #include <zephyr/device.h> + #include <zephyr/drivers/espi.h> #include <zephyr/drivers/espi_emul.h> -#include <zephyr/kernel.h> #include <zephyr/logging/log.h> +#include <zephyr/kernel.h> #include <zephyr/ztest.h> +#include "ap_power/ap_power.h" +#include "ap_power/ap_power_events.h" + +#include "hooks.h" +#include "test_state.h" + /* * Structure passed to event listeners. */ @@ -171,7 +173,6 @@ DECLARE_HOOK(HOOK_CHIPSET_STARTUP, hook_startup, HOOK_PRIO_DEFAULT); */ ZTEST(events, test_hooks) { - count_hook_startup = count_hook_shutdown = 0; ap_power_ev_send_callbacks(AP_POWER_STARTUP); zassert_equal(0, count_hook_shutdown, "shutdown hook called"); zassert_equal(1, count_hook_startup, "startup hook not called"); diff --git a/zephyr/test/ap_power/src/hibdelay.c b/zephyr/test/ap_power/src/hibdelay.c deleted file mode 100644 index 11fac953ea..0000000000 --- a/zephyr/test/ap_power/src/hibdelay.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Copyright 2022 The ChromiumOS Authors - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "console.h" -#include "ec_commands.h" -#include "test_state.h" - -#include <zephyr/shell/shell.h> -#include <zephyr/ztest.h> - -ZTEST_SUITE(console_cmd_hibdelay, ap_power_predicate_post_main, NULL, NULL, - NULL, NULL); - -ZTEST_USER(console_cmd_hibdelay, test_too_many_args) -{ - zassert_ok(shell_execute_cmd(get_ec_shell(), "hibdelay 1 2"), NULL); -} - -ZTEST_USER(console_cmd_hibdelay, test_no_args) -{ - zassert_ok(shell_execute_cmd(get_ec_shell(), "hibdelay"), NULL); -} - -ZTEST_USER(console_cmd_hibdelay, test_invalid_arg) -{ - int rv = shell_execute_cmd(get_ec_shell(), "hibdelay 3.4"); - - zassert_equal(rv, EC_ERROR_PARAM1, "Expected %d, but got %d", - EC_ERROR_PARAM1, rv); -} - -ZTEST_USER(console_cmd_hibdelay, test_valid_args) -{ - zassert_ok(shell_execute_cmd(get_ec_shell(), "hibdelay 5"), NULL); -} diff --git a/zephyr/test/ap_power/src/hibernate.c b/zephyr/test/ap_power/src/hibernate.c deleted file mode 100644 index 23030bdcb3..0000000000 --- a/zephyr/test/ap_power/src/hibernate.c +++ /dev/null @@ -1,39 +0,0 @@ -/* Copyright 2022 The ChromiumOS Authors - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "hooks.h" -#include "test_mocks.h" -#include "test_state.h" - -#include <zephyr/device.h> -#include <zephyr/kernel.h> -#include <zephyr/logging/log.h> -#include <zephyr/ztest.h> - -#include <ap_power/ap_power.h> -#include <ap_power/ap_power_events.h> -#include <ap_power/ap_power_interface.h> - -ZTEST(hibernate, test_g3_hibernate) -{ - extpower_is_present_fake.return_val = 0; - ap_power_ev_send_callbacks(AP_POWER_HARD_OFF); - k_sleep(K_SECONDS(30)); - zassert_equal(1, system_hibernate_fake.call_count); -} - -ZTEST(hibernate, test_ac_changed) -{ - extpower_is_present_fake.return_val = 1; - hook_notify(HOOK_AC_CHANGE); - k_sleep(K_SECONDS(30)); - zassert_equal(0, system_hibernate_fake.call_count); - extpower_is_present_fake.return_val = 0; - hook_notify(HOOK_AC_CHANGE); - k_sleep(K_SECONDS(30)); - zassert_equal(1, system_hibernate_fake.call_count); -} - -ZTEST_SUITE(hibernate, ap_power_predicate_post_main, NULL, NULL, NULL, NULL); diff --git a/zephyr/test/ap_power/src/host_command.c b/zephyr/test/ap_power/src/host_command.c deleted file mode 100644 index f0b3b0d732..0000000000 --- a/zephyr/test/ap_power/src/host_command.c +++ /dev/null @@ -1,28 +0,0 @@ -/* Copyright 2022 The ChromiumOS Authors - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "ec_commands.h" -#include "host_command.h" -#include "test_state.h" - -#include <zephyr/ztest.h> - -ZTEST(host_cmd, test_hibernate_get) -{ - struct ec_response_hibernation_delay response; - struct ec_params_hibernation_delay params = { - .seconds = 0, - }; - - struct host_cmd_handler_args args = BUILD_HOST_COMMAND( - EC_CMD_HIBERNATION_DELAY, 0, response, params); - - zassert_ok(host_command_process(&args)); - params.seconds = 123; - zassert_ok(host_command_process(&args)); - zassert_equal(123, response.hibernate_delay, NULL); -} - -ZTEST_SUITE(host_cmd, ap_power_predicate_post_main, NULL, NULL, NULL, NULL); diff --git a/zephyr/test/ap_power/src/main.c b/zephyr/test/ap_power/src/main.c index 9ed34eee4a..d653b51164 100644 --- a/zephyr/test/ap_power/src/main.c +++ b/zephyr/test/ap_power/src/main.c @@ -3,11 +3,10 @@ * found in the LICENSE file. */ -#include "ec_app_main.h" -#include "test_state.h" - #include <zephyr/kernel.h> #include <zephyr/ztest.h> +#include "ec_app_main.h" +#include "test_state.h" bool ap_power_predicate_pre_main(const void *state) { diff --git a/zephyr/test/ap_power/src/signals.c b/zephyr/test/ap_power/src/signals.c index 4eae187564..e8bc6e426c 100644 --- a/zephyr/test/ap_power/src/signals.c +++ b/zephyr/test/ap_power/src/signals.c @@ -8,22 +8,24 @@ * @brief Unit Tests for power signals API */ -#include "ec_tasks.h" -#include "emul/emul_stub_device.h" -#include "gpio.h" -#include "gpio/gpio.h" -#include "gpio/gpio_int.h" -#include "power_signals.h" -#include "test_state.h" - #include <zephyr/device.h> + #include <zephyr/drivers/espi.h> #include <zephyr/drivers/espi_emul.h> #include <zephyr/drivers/gpio/gpio_emul.h> -#include <zephyr/kernel.h> #include <zephyr/logging/log.h> +#include <zephyr/kernel.h> #include <zephyr/ztest.h> +#include "power_signals.h" + +#include "ec_tasks.h" +#include "emul/emul_stub_device.h" +#include "gpio.h" +#include "gpio/gpio.h" +#include "gpio/gpio_int.h" +#include "test_state.h" + extern bool gpio_test_interrupt_triggered; static const struct device *emul_port; diff --git a/zephyr/test/ap_power/src/test_mocks.c b/zephyr/test/ap_power/src/test_mocks.c deleted file mode 100644 index 9eb8834ff5..0000000000 --- a/zephyr/test/ap_power/src/test_mocks.c +++ /dev/null @@ -1,30 +0,0 @@ -/* Copyright 2022 The ChromiumOS Authors - * Use of this source code is governed by a BSD-style license that can be - * found in the LICENSE file. - */ - -#include "test_mocks.h" - -#include <zephyr/fff.h> -#include <zephyr/ztest.h> - -/* Mocks for common/extpower_gpio.c */ -DEFINE_FAKE_VALUE_FUNC(int, extpower_is_present); - -/* Mocks for common/system.c */ -DEFINE_FAKE_VOID_FUNC(system_hibernate, uint32_t, uint32_t); - -/** - * @brief Reset all the fakes before each test. - */ -static void fff_reset_rule_before(const struct ztest_unit_test *test, - void *data) -{ - ARG_UNUSED(test); - ARG_UNUSED(data); - - RESET_FAKE(extpower_is_present); - RESET_FAKE(system_hibernate); -} - -ZTEST_RULE(fff_reset_rule, fff_reset_rule_before, NULL); |