Skip to content

Commit 3e98a43

Browse files
rbbrnsChromeos LUCI
authored andcommitted
panic: Add nesting support to crash console command
Add support for nesting to `crash` console command. Calling the crash console command with multiple crash arguments will result in nested crashes in the order specified. This is useful for testing complex panic scenarios. BUG=b:333916658 TEST=Nested crashes tested on volteer, zork and skyrim. TEST=Twister test drivers/drivers.panic_output TEST=Twister test drivers/drivers.console_cmd_crash Change-Id: I65ff48c0a977f3451cbde6c1787bde74d11d7a83 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/5454818 Reviewed-by: Forest Mittelberg <[email protected]> Code-Coverage: Zoss <[email protected]> Tested-by: Rob Barnes <[email protected]> Commit-Queue: Rob Barnes <[email protected]> Reviewed-by: Jeremy Bettis <[email protected]>
1 parent a19779e commit 3e98a43

File tree

18 files changed

+314
-16
lines changed

18 files changed

+314
-16
lines changed

baseboard/kukui/baseboard.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@
309309
#undef CONFIG_CMD_APTHROTTLE
310310
#undef CONFIG_CMD_CHARGE_SUPPLIER_INFO
311311
#undef CONFIG_CMD_CRASH
312+
#undef CONFIG_CMD_CRASH_NESTED
312313
#undef CONFIG_CMD_HCDEBUG
313314
#undef CONFIG_CMD_IDLE_STATS
314315
#undef CONFIG_CMD_KEYBOARD

board/pdeval-stm32f072/board.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
#undef CONFIG_CONSOLE_HISTORY
8282
#undef CONFIG_HIBERNATE
8383
#undef CONFIG_CMD_CRASH
84+
#undef CONFIG_CMD_CRASH_NESTED
8485

8586
/*
8687
* Allow dangerous commands all the time, since we don't have a write protect

board/servo_v4/board.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@
9191
#undef CONFIG_CONSOLE_CMDHELP
9292
#undef CONFIG_CONSOLE_HISTORY
9393
#undef CONFIG_CMD_CRASH
94+
#undef CONFIG_CMD_CRASH_NESTED
9495
#undef CONFIG_CMD_ACCELSPOOF
9596
#undef CONFIG_CMD_FASTCHARGE
9697
#undef CONFIG_CMD_FLASHINFO

board/servo_v4p1/board.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@
168168
#undef CONFIG_CONSOLE_CMDHELP
169169
#undef CONFIG_CONSOLE_HISTORY
170170
#undef CONFIG_CMD_CRASH
171+
#undef CONFIG_CMD_CRASH_NESTED
171172
#undef CONFIG_CMD_ACCELSPOOF
172173
#undef CONFIG_CMD_FASTCHARGE
173174
#undef CONFIG_CMD_FLASHINFO

board/volteer/board.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,7 @@
166166
#undef CONFIG_CMD_CHARGER
167167
#undef CONFIG_CMD_CHARGE_SUPPLIER_INFO
168168
#undef CONFIG_CMD_CRASH
169+
#undef CONFIG_CMD_CRASH_NESTED
169170
#undef CONFIG_CMD_DEVICE_EVENT
170171
#undef CONFIG_CMD_FLASH_WP
171172
#undef CONFIG_CMD_HASH

common/panic_output.c

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "sysjump.h"
1616
#include "system.h"
1717
#include "task.h"
18+
#include "test_util.h"
1819
#include "timer.h"
1920
#include "uart.h"
2021
#include "usb_console.h"
@@ -366,13 +367,56 @@ ENABLE_CLANG_WARNING("-Winfinite-recursion")
366367
ENABLE_GCC_WARNING("-Winfinite-recursion")
367368
#endif
368369

370+
#ifdef CONFIG_CMD_CRASH_NESTED
371+
static bool command_crash_nested_enabled;
372+
static int command_crash_nested_argc;
373+
static const char **command_crash_nested_argv;
374+
test_mockable_static void command_crash_nested_enable(int argc,
375+
const char **argv)
376+
{
377+
command_crash_nested_argc = argc;
378+
command_crash_nested_argv = argv;
379+
command_crash_nested_enabled = true;
380+
}
381+
test_mockable_static void command_crash_nested_disable(void)
382+
{
383+
command_crash_nested_enabled = false;
384+
}
385+
/* Forward declare command_crash so it can be referenced in
386+
* command_crash_nested_handler.
387+
*/
388+
static int command_crash(int argc, const char **argv);
389+
/*
390+
* Called from the panic handler.
391+
* Triggers a nested crash when enabled.
392+
*/
393+
int command_crash_nested_handler(void)
394+
{
395+
if (!command_crash_nested_enabled)
396+
return EC_SUCCESS;
397+
/* Must be re-enabled after each run */
398+
command_crash_nested_enabled = false;
399+
/* Decrement argc and shift argv */
400+
return command_crash(command_crash_nested_argc - 1,
401+
command_crash_nested_argv + 1);
402+
}
403+
#endif /* CONFIG_CMD_CRASH_NESTED */
404+
369405
/*****************************************************************************/
370406
/* Console commands */
371407
static int command_crash(int argc, const char **argv)
372408
{
373409
if (argc < 2)
374410
return EC_ERROR_PARAM1;
375411

412+
if (argc > 2) {
413+
if (IS_ENABLED(CONFIG_CMD_CRASH_NESTED)) {
414+
command_crash_nested_enable(argc, argv);
415+
} else {
416+
return EC_ERROR_PARAM_COUNT;
417+
}
418+
}
419+
376420
if (!strcasecmp(argv[1], "assert")) {
377421
ASSERT(0);
378422
} else if (!strcasecmp(argv[1], "divzero")) {
@@ -417,17 +461,28 @@ static int command_crash(int argc, const char **argv)
417461
cflush();
418462
ccprintf("%08x\n", *(volatile unsigned int *)null_ptr);
419463
} else {
464+
/* Disable nested crash on error */
465+
if (IS_ENABLED(CONFIG_CMD_CRASH_NESTED))
466+
command_crash_nested_disable();
420467
return EC_ERROR_PARAM1;
421468
}
422469

470+
/* Disable nested crash on error */
471+
if (IS_ENABLED(CONFIG_CMD_CRASH_NESTED))
472+
command_crash_nested_disable();
473+
423474
/* Everything crashes, so shouldn't get back here */
424475
return EC_ERROR_UNKNOWN;
425476
}
426477

427478
DECLARE_CONSOLE_COMMAND(crash, command_crash,
428479
"[assert | divzero | udivzero | stack"
429480
" | unaligned | watchdog | hang | null]",
430-
"Crash the system (for testing)");
481+
"Crash the system (for testing)."
482+
#ifndef CONFIG_CMD_CRASH_NESTED
483+
" Repeat argument for nested crashes."
484+
#endif /* CONFIG_CMD_CRASH_NESTED */
485+
);
431486

432487
#ifdef TEST_BUILD
433488
int test_command_crash(int argc, const char **argv)

core/cortex-m/panic.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -375,6 +375,9 @@ void __keep report_panic(void)
375375
if (IS_ENABLED(CONFIG_ARMV7M_CACHE))
376376
cpu_clean_invalidate_dcache();
377377

378+
if (IS_ENABLED(CONFIG_CMD_CRASH_NESTED))
379+
command_crash_nested_handler();
380+
378381
/* Start safe mode if possible */
379382
if (IS_ENABLED(CONFIG_SYSTEM_SAFE_MODE)) {
380383
/* Only start safe mode if panic occurred in thread context */

core/cortex-m0/panic.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,10 @@ void __keep report_panic(void)
134134
}
135135

136136
panic_data_print(pdata);
137+
138+
if (IS_ENABLED(CONFIG_CMD_CRASH_NESTED))
139+
command_crash_nested_handler();
140+
137141
panic_reboot();
138142
}
139143

core/nds32/panic.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ void report_panic(uint32_t *regs, uint32_t itype)
193193

194194
print_panic_information(regs, itype, regs[16], regs[17]);
195195

196+
if (IS_ENABLED(CONFIG_CMD_CRASH_NESTED))
197+
command_crash_nested_handler();
198+
196199
if (IS_ENABLED(CONFIG_SYSTEM_SAFE_MODE)) {
197200
if (get_interrupt_level() <= 1 &&
198201
start_system_safe_mode() == EC_SUCCESS) {

core/riscv-rv32i/panic.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ void report_panic(uint32_t *regs)
145145
pdata->riscv.regs[i] = regs[i];
146146

147147
print_panic_information(regs, mcause, mepc);
148+
149+
if (IS_ENABLED(CONFIG_CMD_CRASH_NESTED))
150+
command_crash_nested_handler();
151+
148152
panic_reboot();
149153
}
150154

0 commit comments

Comments
 (0)