diff options
-rw-r--r-- | core/cortex-m/panic.c | 3 | ||||
-rw-r--r-- | zephyr/shim/src/panic.c | 4 | ||||
-rw-r--r-- | zephyr/test/drivers/CMakeLists.txt | 1 | ||||
-rw-r--r-- | zephyr/test/drivers/Kconfig | 3 | ||||
-rw-r--r-- | zephyr/test/drivers/panic_event/CMakeLists.txt | 6 | ||||
-rw-r--r-- | zephyr/test/drivers/panic_event/src/panic_event.c | 65 | ||||
-rw-r--r-- | zephyr/test/drivers/testcase.yaml | 3 |
7 files changed, 85 insertions, 0 deletions
diff --git a/core/cortex-m/panic.c b/core/cortex-m/panic.c index eefe068931..7d364ec2a0 100644 --- a/core/cortex-m/panic.c +++ b/core/cortex-m/panic.c @@ -364,6 +364,9 @@ void __keep report_panic(void) if (IS_ENABLED(CONFIG_ARMV7M_CACHE)) cpu_clean_invalidate_dcache(); + if (IS_ENABLED(CONFIG_HOSTCMD_EVENTS)) + host_set_single_event(EC_HOST_EVENT_PANIC); + /* Start safe mode if possible */ if (IS_ENABLED(CONFIG_SYSTEM_SAFE_MODE)) { /* TODO: check for nested exceptions */ diff --git a/zephyr/shim/src/panic.c b/zephyr/shim/src/panic.c index e7c13f746d..1a9d7478e4 100644 --- a/zephyr/shim/src/panic.c +++ b/zephyr/shim/src/panic.c @@ -4,6 +4,7 @@ */ #include "common.h" +#include "host_command.h" #include "panic.h" #include "system_safe_mode.h" @@ -150,6 +151,9 @@ void k_sys_fatal_error_handler(unsigned int reason, const z_arch_esf_t *esf) LOG_PANIC(); + if (IS_ENABLED(CONFIG_HOSTCMD_EVENTS)) + host_set_single_event(EC_HOST_EVENT_PANIC); + /* Start system safe mode if possible */ if (IS_ENABLED(CONFIG_PLATFORM_EC_SYSTEM_SAFE_MODE)) { if (reason != K_ERR_KERNEL_PANIC && diff --git a/zephyr/test/drivers/CMakeLists.txt b/zephyr/test/drivers/CMakeLists.txt index 8265082543..00328367e3 100644 --- a/zephyr/test/drivers/CMakeLists.txt +++ b/zephyr/test/drivers/CMakeLists.txt @@ -25,6 +25,7 @@ add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_I2C_CONTROLLER i2c_controller) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_KEYBOARD_SCAN keyboard_scan) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_LED_DRIVER led_driver) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_MKBP mkbp) +add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_PANIC_EVENT panic_event) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_PANIC_OUTPUT panic_output) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_POWER_HOST_SLEEP power_host_sleep) add_subdirectory_ifdef(CONFIG_LINK_TEST_SUITE_RT9490 rt9490) diff --git a/zephyr/test/drivers/Kconfig b/zephyr/test/drivers/Kconfig index 6783661866..14f3d6b513 100644 --- a/zephyr/test/drivers/Kconfig +++ b/zephyr/test/drivers/Kconfig @@ -62,6 +62,9 @@ config LINK_TEST_SUITE_LOCATE_CHIP_ALTS config LINK_TEST_SUITE_MKBP bool "Link and test the mkbp tests" +config LINK_TEST_SUITE_PANIC_EVENT + bool "Link and test the panic_event tests" + config LINK_TEST_SUITE_PANIC_OUTPUT bool "Link and test the panic_output tests" diff --git a/zephyr/test/drivers/panic_event/CMakeLists.txt b/zephyr/test/drivers/panic_event/CMakeLists.txt new file mode 100644 index 0000000000..25ea751d53 --- /dev/null +++ b/zephyr/test/drivers/panic_event/CMakeLists.txt @@ -0,0 +1,6 @@ +# 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. + +# Add source files +target_sources(app PRIVATE src/panic_event.c) diff --git a/zephyr/test/drivers/panic_event/src/panic_event.c b/zephyr/test/drivers/panic_event/src/panic_event.c new file mode 100644 index 0000000000..09796d355f --- /dev/null +++ b/zephyr/test/drivers/panic_event/src/panic_event.c @@ -0,0 +1,65 @@ +/* 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. + */ + +/** + * @file + * @brief Unit Tests for panic event. + */ + +#include "common.h" +#include "ec_tasks.h" +#include "panic.h" +#include "system.h" +#include "test/drivers/stubs.h" +#include "test/drivers/test_state.h" +#include "test/drivers/utils.h" + +#include <zephyr/device.h> +#include <zephyr/fff.h> +#include <zephyr/kernel.h> +#include <zephyr/logging/log.h> +#include <zephyr/ztest.h> + +struct host_events_ctx events_ctx; + +static void before(void *unused) +{ + ARG_UNUSED(unused); + host_events_save(&events_ctx); + host_clear_events(0xffffffff); +} + +static void after(void *unused) +{ + ARG_UNUSED(unused); + host_events_restore(&events_ctx); +} + +/** + * @brief Test Suite: Verifies panic event functionality. + */ +ZTEST_SUITE(panic_event, NULL, NULL, before, after, NULL); + +/** + * @brief TestPurpose: Verify EC_HOST_EVENT_PANIC event is asserted on panic + * + * Expected Results + * - Success + */ +ZTEST_USER(panic_event, test_panic_event_notify) +{ +#ifdef CONFIG_HOSTCMD_X86 + /* Enable the EC_HOST_EVENT_PANIC event in the lpc mask */ + host_event_t lpc_event_mask; + host_event_t mask = EC_HOST_EVENT_MASK(EC_HOST_EVENT_PANIC); + + lpc_event_mask = lpc_get_host_event_mask(LPC_HOST_EVENT_SCI); + lpc_set_host_event_mask(LPC_HOST_EVENT_SCI, lpc_event_mask | mask); +#endif + + zassert_false(host_is_event_set(EC_HOST_EVENT_PANIC)); + k_sys_fatal_error_handler(K_ERR_CPU_EXCEPTION, NULL); + zassert_true(host_is_event_set(EC_HOST_EVENT_PANIC)); +} diff --git a/zephyr/test/drivers/testcase.yaml b/zephyr/test/drivers/testcase.yaml index dfd18ac110..818a3e4515 100644 --- a/zephyr/test/drivers/testcase.yaml +++ b/zephyr/test/drivers/testcase.yaml @@ -150,6 +150,9 @@ tests: - CONFIG_LINK_TEST_SUITE_PANIC_OUTPUT=y - CONFIG_PLATFORM_EC_CONSOLE_CMD_CRASH=y - CONFIG_ZTEST_THREAD_PRIORITY=1 + drivers.panic_event: + extra_configs: + - CONFIG_LINK_TEST_SUITE_PANIC_EVENT=y drivers.power_host_sleep: extra_configs: - CONFIG_LINK_TEST_SUITE_POWER_HOST_SLEEP=y |