Skip to content

Commit ce03563

Browse files
aescolartpambor
authored andcommitted
board native_sim: Test sys_reboot and hw_info reporting the reset cause
Add a test of the CONFIG_NATIVE_SIM_REBOOT functionality together with the hw_info get_reset_cause() logic. Signed-off-by: Alberto Escolar Piedras <[email protected]>
1 parent 503bdf5 commit ce03563

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
cmake_minimum_required(VERSION 3.20.0)
5+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
6+
project(native_reset_hw_info)
7+
8+
FILE(GLOB app_sources src/*.c)
9+
target_sources(app PRIVATE ${app_sources})
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Copyright (c) 2025 Nordic Semiconductor ASA
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
CONFIG_REBOOT=y
5+
CONFIG_NATIVE_SIM_REBOOT=y
6+
CONFIG_HWINFO=y
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#include <stdio.h>
8+
#include <zephyr/drivers/hwinfo.h>
9+
#include <zephyr/sys/reboot.h>
10+
#include <nsi_main.h>
11+
12+
int main(void)
13+
{
14+
uint32_t cause;
15+
int err;
16+
17+
err = hwinfo_get_reset_cause(&cause);
18+
if (err != 0) {
19+
posix_print_error_and_exit("hwinfo_get_reset_cause() failed %i\n", err);
20+
}
21+
22+
if (cause == RESET_POR) {
23+
printf("This seems like the first start => Resetting\n");
24+
sys_reboot(SYS_REBOOT_WARM);
25+
} else if (cause == RESET_SOFTWARE) {
26+
printf("Booted after SOFTWARE reset => we are done\n");
27+
}
28+
nsi_exit(0);
29+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
tests:
2+
boards.native_sim.reset_hw_info:
3+
platform_allow:
4+
- native_sim
5+
- native_sim/native/64
6+
integration_platforms:
7+
- native_sim
8+
harness: console
9+
harness_config:
10+
type: multi_line
11+
ordered: true
12+
regex:
13+
- "(.*)Booting Zephyr OS build(.*)"
14+
- "This seems like the first start => Resetting"
15+
- "(.*)Booting Zephyr OS build(.*)"
16+
- "Booted after SOFTWARE reset => we are done"

0 commit comments

Comments
 (0)