Skip to content

Commit ee9d6b7

Browse files
nordic-seglfabiobaltieri
authored andcommitted
tests: boards: nrf: hwinfo: Extend test with RESET_CPU_LOCKUP
Extend test code with scenario that checks if: - RESET_CPU_LOCKUP is detected; - RESET_CPU_LOCKUP can be cleared. Signed-off-by: Sebastian Głąb <sebastian.glab@nordicsemi.no>
1 parent 7249fac commit ee9d6b7

File tree

3 files changed

+63
-3
lines changed

3 files changed

+63
-3
lines changed

tests/boards/nrf/hwinfo/reset_cause/prj.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@ CONFIG_REBOOT=y
55

66
CONFIG_LOG=y
77
CONFIG_LOG_MODE_MINIMAL=y
8+
CONFIG_ASSERT=y

tests/boards/nrf/hwinfo/reset_cause/src/main.c

Lines changed: 56 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <errno.h>
1212

1313
#include <zephyr/logging/log.h>
14+
#include <zephyr/logging/log_ctrl.h>
1415
LOG_MODULE_REGISTER(resetreason, LOG_LEVEL_INF);
1516

1617
static const struct device *const my_wdt_device = DEVICE_DT_GET(DT_ALIAS(watchdog0));
@@ -22,13 +23,15 @@ volatile uint32_t machine_state __attribute__((section(NOINIT_SECTION)));
2223
volatile uint32_t supported __attribute__((section(NOINIT_SECTION)));
2324
volatile uint32_t wdt_status __attribute__((section(NOINIT_SECTION)));
2425
volatile uint32_t reboot_status __attribute__((section(NOINIT_SECTION)));
26+
volatile uint32_t cpu_lockup_status __attribute__((section(NOINIT_SECTION)));
2527

2628
/* Value used to indicate that the watchdog has fired. */
2729
#define WDT_HAS_FIRED (0x12345678U)
2830
#define REBOOT_WAS_DONE (0x87654321U)
31+
#define CPU_LOCKUP_WAS_DONE (0x19283746U)
2932

3033
/* Highest value in the switch statement in the main() */
31-
#define LAST_STATE (2)
34+
#define LAST_STATE (3)
3235

3336
static void wdt_int_cb(const struct device *wdt_dev, int channel_id)
3437
{
@@ -236,7 +239,7 @@ void test_reset_software(uint32_t cause)
236239
if (reboot_status != REBOOT_WAS_DONE) {
237240
/* If software reset hasn't happen yet, do it. */
238241
reboot_status = REBOOT_WAS_DONE;
239-
LOG_INF("Test RESET_SOFTWARE - Rebooting");
242+
LOG_INF("Test RESET_SOFTWARE");
240243

241244
/* Flush cache as reboot may invalidate all lines. */
242245
sys_cache_data_flush_range((void *) &machine_state, sizeof(machine_state));
@@ -316,6 +319,49 @@ void test_reset_watchdog(uint32_t cause)
316319
}
317320
}
318321

322+
void k_sys_fatal_error_handler(unsigned int reason, const struct arch_esf *pEsf)
323+
{
324+
LOG_INF("%s(%d)", __func__, reason);
325+
LOG_PANIC();
326+
327+
/* Assert inside Assert handler - shall result in reset due to cpu lockup. */
328+
__ASSERT(0, "Intentionally failed assert inside kernel panic");
329+
}
330+
331+
void test_reset_cpu_lockup(uint32_t cause)
332+
{
333+
/* Check that reset cause from cpu lockup is detected. */
334+
if (supported & RESET_CPU_LOCKUP) {
335+
if (cpu_lockup_status != CPU_LOCKUP_WAS_DONE) {
336+
/* If reset due to cpu lockup hasn't happen yet, do it. */
337+
cpu_lockup_status = CPU_LOCKUP_WAS_DONE;
338+
LOG_INF("Test RESET_CPU_LOCKUP");
339+
340+
/* Flush cache as reboot may invalidate all lines. */
341+
sys_cache_data_flush_range((void *) &machine_state, sizeof(machine_state));
342+
sys_cache_data_flush_range((void *) &cpu_lockup_status,
343+
sizeof(cpu_lockup_status));
344+
__ASSERT(0, "Intentionally failed assertion");
345+
} else {
346+
/* Reset due to CPU Lockup was done */
347+
LOG_INF("TEST that RESET_CPU_LOCKUP was detected");
348+
if (cause & RESET_CPU_LOCKUP) {
349+
LOG_INF("PASS: RESET_CPU_LOCKUP detected");
350+
print_bar();
351+
/* Check RESET_SOFTWARE can be cleared */
352+
test_clear_reset_cause();
353+
} else {
354+
LOG_ERR("FAIL: RESET_CPU_LOCKUP not set");
355+
print_bar();
356+
}
357+
/* Cleanup */
358+
cpu_lockup_status = 0;
359+
sys_cache_data_flush_range((void *) &cpu_lockup_status,
360+
sizeof(cpu_lockup_status));
361+
}
362+
}
363+
}
364+
319365
int main(void)
320366
{
321367
uint32_t cause;
@@ -327,6 +373,9 @@ int main(void)
327373
if (reboot_status == REBOOT_WAS_DONE) {
328374
LOG_INF("This boot is due to expected software reset");
329375
}
376+
if (cpu_lockup_status == CPU_LOCKUP_WAS_DONE) {
377+
LOG_INF("This boot is due to expected cpu lockup reset");
378+
}
330379
print_bar();
331380

332381
/* Test relies on REST_PIN to correctly start. */
@@ -340,12 +389,14 @@ int main(void)
340389
machine_state = 0;
341390
reboot_status = 0;
342391
wdt_status = 0;
392+
cpu_lockup_status = 0;
343393
}
344394

345395
while (machine_state <= LAST_STATE) {
346396
LOG_DBG("machine_state = %u", machine_state);
347397
LOG_DBG("reboot_status = %u", reboot_status);
348398
LOG_DBG("wdt_status = %u", wdt_status);
399+
LOG_DBG("cpu_lockup_status = %u", cpu_lockup_status);
349400

350401
switch (machine_state) {
351402
case 0: /* Print (an store) which reset causes are supported. */
@@ -358,6 +409,9 @@ int main(void)
358409
case 2: /* Test RESET_WATCHDOG. */
359410
test_reset_watchdog(cause);
360411
machine_state++;
412+
case 3: /* Test CPU_LOCKUP. */
413+
test_reset_cpu_lockup(cause);
414+
machine_state++;
361415
}
362416
}
363417

tests/boards/nrf/hwinfo/reset_cause/testcase.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,19 @@ tests:
2020
- "RESET_DEBUG is supported"
2121
- "RESET_LOW_POWER_WAKE is supported"
2222
- "RESET_CPU_LOCKUP is supported"
23-
- "Rebooting"
2423
- "HW Info reset reason test on"
24+
- "This boot is due to expected software reset"
2525
- "PASS: RESET_SOFTWARE detected"
2626
- "PASS: reset causes were cleared"
2727
- "Watchdog shall fire"
2828
- "HW Info reset reason test on"
29+
- "This boot is due to expected watchdog reset"
2930
- "PASS: RESET_WATCHDOG detected"
3031
- "PASS: reset causes were cleared"
32+
- "HW Info reset reason test on"
33+
- "This boot is due to expected cpu lockup reset"
34+
- "PASS: RESET_CPU_LOCKUP detected"
35+
- "PASS: reset causes were cleared"
3136
- "All tests done"
3237
platform_allow:
3338
- nrf54h20dk/nrf54h20/cpuapp

0 commit comments

Comments
 (0)