summaryrefslogtreecommitdiff
path: root/zephyr/test/system_safe_mode/src/system_safe_mode.c
diff options
context:
space:
mode:
Diffstat (limited to 'zephyr/test/system_safe_mode/src/system_safe_mode.c')
-rw-r--r--zephyr/test/system_safe_mode/src/system_safe_mode.c56
1 files changed, 56 insertions, 0 deletions
diff --git a/zephyr/test/system_safe_mode/src/system_safe_mode.c b/zephyr/test/system_safe_mode/src/system_safe_mode.c
index 68c6dc4797..f75a27ec84 100644
--- a/zephyr/test/system_safe_mode/src/system_safe_mode.c
+++ b/zephyr/test/system_safe_mode/src/system_safe_mode.c
@@ -3,6 +3,7 @@
* found in the LICENSE file.
*/
+#include "console.h"
#include "ec_commands.h"
#include "ec_tasks.h"
#include "host_command.h"
@@ -10,11 +11,14 @@
#include "system.h"
#include "system_fake.h"
#include "system_safe_mode.h"
+#include "uart.h"
#include <zephyr/fff.h>
#include <zephyr/kernel.h>
#include <zephyr/ztest.h>
+#include <regex.h>
+
FAKE_VOID_FUNC(system_reset, int);
static void system_before(void *data)
@@ -23,6 +27,7 @@ static void system_before(void *data)
set_system_safe_mode(false);
get_panic_data_write()->flags = 0;
system_set_shrspi_image_copy(EC_IMAGE_RW);
+ shell_start(get_ec_shell());
}
static void enter_safe_mode_cb(struct k_timer *unused)
@@ -155,4 +160,55 @@ ZTEST_USER(system_safe_mode, test_panic_event_notify)
zassert_true(host_is_event_set(EC_HOST_EVENT_PANIC));
}
+static uint32_t fake_stack[] = {
+ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
+ 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
+ 0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f,
+};
+
+uint32_t get_panic_stack_pointer(const struct panic_data *pdata)
+{
+ return (uint32_t)fake_stack;
+}
+
+ZTEST_USER(system_safe_mode, test_print_stack_contents)
+{
+ char buffer[1024];
+ uint16_t write_count;
+ regex_t regex;
+
+ char *regex_str = "========== Stack Contents ===========\n"
+ "[0-9a-f]{8}: 00000000 00000001 00000002 00000003\n"
+ "[0-9a-f]{8}: 00000004 00000005 00000006 00000007\n"
+ "[0-9a-f]{8}: 00000008 00000009 0000000a 0000000b\n"
+ "[0-9a-f]{8}: 0000000c 0000000d 0000000e 0000000f\n"
+ "[0-9a-f]{8}: 00000010 00000011 00000012 00000013\n"
+ "[0-9a-f]{8}: 00000014 00000015 00000016 00000017\n"
+ "[0-9a-f]{8}: 00000018 00000019 0000001a 0000001b\n"
+ "[0-9a-f]{8}: 0000001c 0000001d 0000001e 0000001f\n";
+
+ zassert_ok(regcomp(&regex, regex_str, REG_EXTENDED));
+
+ /* Snapshot console before panic */
+ zassert_ok(uart_console_read_buffer_init(), NULL);
+
+ k_sys_fatal_error_handler(K_ERR_CPU_EXCEPTION, NULL);
+ /* Short sleep to allow hook task to run */
+ k_msleep(1);
+ zassert_true(system_is_in_safe_mode());
+
+ /* Snapshot console after panic */
+ zassert_ok(uart_console_read_buffer_init(), NULL);
+
+ zassert_ok(uart_console_read_buffer(CONSOLE_READ_RECENT, buffer,
+ sizeof(buffer), &write_count),
+ NULL);
+ /* Need at least 405 bytes for match */
+ zassert_true(write_count >= 405);
+
+ /* Check for expected stack print in console buffer */
+ zassert_ok(regexec(&regex, buffer, 0, NULL, 0));
+ regfree(&regex);
+}
+
ZTEST_SUITE(system_safe_mode, NULL, NULL, system_before, NULL, NULL);