Skip to content

Commit 3bf5225

Browse files
committed
[nrf fromlist] 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. Upstream PR #: 86568 Signed-off-by: Sebastian Głąb <[email protected]>
1 parent 10eb60b commit 3bf5225

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-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: 54 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,47 @@ 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("k_sys_fatal_error_handler(%d)", 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, sizeof(cpu_lockup_status));
343+
__ASSERT(0, "Intentionally failed assertion");
344+
} else {
345+
/* Reset due to CPU Lockup was done */
346+
LOG_INF("TEST that RESET_CPU_LOCKUP was detected");
347+
if (cause & RESET_CPU_LOCKUP) {
348+
LOG_INF("PASS: RESET_CPU_LOCKUP detected");
349+
print_bar();
350+
/* Check RESET_SOFTWARE can be cleared */
351+
test_clear_reset_cause();
352+
} else {
353+
LOG_ERR("FAIL: RESET_CPU_LOCKUP not set");
354+
print_bar();
355+
}
356+
/* Cleanup */
357+
cpu_lockup_status = 0;
358+
sys_cache_data_flush_range((void *) &cpu_lockup_status, sizeof(cpu_lockup_status));
359+
}
360+
}
361+
}
362+
319363
int main(void)
320364
{
321365
uint32_t cause;
@@ -327,6 +371,9 @@ int main(void)
327371
if (reboot_status == REBOOT_WAS_DONE) {
328372
LOG_INF("This boot is due to expected software reset");
329373
}
374+
if (cpu_lockup_status == CPU_LOCKUP_WAS_DONE) {
375+
LOG_INF("This boot is due to expected cpu lockup reset");
376+
}
330377
print_bar();
331378

332379
/* Test relies on REST_PIN to correctly start. */
@@ -340,12 +387,14 @@ int main(void)
340387
machine_state = 0;
341388
reboot_status = 0;
342389
wdt_status = 0;
390+
cpu_lockup_status = 0;
343391
}
344392

345393
while (machine_state <= LAST_STATE) {
346394
LOG_DBG("machine_state = %u", machine_state);
347395
LOG_DBG("reboot_status = %u", reboot_status);
348396
LOG_DBG("wdt_status = %u", wdt_status);
397+
LOG_DBG("cpu_lockup_status = %u", cpu_lockup_status);
349398

350399
switch (machine_state) {
351400
case 0: /* Print (an store) which reset causes are supported. */
@@ -358,6 +407,9 @@ int main(void)
358407
case 2: /* Test RESET_WATCHDOG. */
359408
test_reset_watchdog(cause);
360409
machine_state++;
410+
case 3: /* Test CPU_LOCKUP. */
411+
test_reset_cpu_lockup(cause);
412+
machine_state++;
361413
}
362414
}
363415

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)