tests: flash_simulator: reboot: added
Add a test for the flash simulator preserving memory across a `sys_reboot` through the use of memory regions. Signed-off-by: Jordan Yates <jordan@embeint.com>
This commit is contained in:
parent
4bdc61132c
commit
557418ace6
5 changed files with 107 additions and 0 deletions
|
@ -0,0 +1,12 @@
|
|||
#
|
||||
# Copyright (c) 2018 Nordic Semiconductor ASA.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
|
||||
cmake_minimum_required(VERSION 3.20.0)
|
||||
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
|
||||
project(flash_simulator_reboot)
|
||||
|
||||
FILE(GLOB app_sources src/*.c)
|
||||
target_sources(app PRIVATE ${app_sources})
|
|
@ -0,0 +1,27 @@
|
|||
#include <mem.h>
|
||||
|
||||
/ {
|
||||
sram_203F0000:sram@203F0000 {
|
||||
compatible = "zephyr,memory-region", "mmio-sram";
|
||||
reg = <0x203F0000 0x10000>;
|
||||
zephyr,memory-region = "FlashSim";
|
||||
status = "okay";
|
||||
};
|
||||
|
||||
sim_flash_controller: sim_flash_controller {
|
||||
compatible = "zephyr,sim-flash";
|
||||
|
||||
#address-cells = <1>;
|
||||
#size-cells = <1>;
|
||||
erase-value = <0xff>;
|
||||
memory-region = <&sram_203F0000>;
|
||||
|
||||
flash_sim0: flash_sim@0 {
|
||||
compatible = "soc-nv-flash";
|
||||
reg = <0x00000000 0x10000>;
|
||||
|
||||
erase-block-size = <1024>;
|
||||
write-block-size = <4>;
|
||||
};
|
||||
};
|
||||
};
|
4
tests/drivers/flash_simulator/flash_sim_reboot/prj.conf
Normal file
4
tests/drivers/flash_simulator/flash_sim_reboot/prj.conf
Normal file
|
@ -0,0 +1,4 @@
|
|||
CONFIG_ZTEST=y
|
||||
CONFIG_FLASH=y
|
||||
CONFIG_FLASH_SIMULATOR=y
|
||||
CONFIG_REBOOT=y
|
54
tests/drivers/flash_simulator/flash_sim_reboot/src/main.c
Normal file
54
tests/drivers/flash_simulator/flash_sim_reboot/src/main.c
Normal file
|
@ -0,0 +1,54 @@
|
|||
/*
|
||||
* Copyright (c) 2018 Nordic Semiconductor ASA.
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
#include <zephyr/ztest.h>
|
||||
#include <zephyr/drivers/flash.h>
|
||||
#include <zephyr/device.h>
|
||||
#include <zephyr/sys/reboot.h>
|
||||
#include <zephyr/toolchain.h>
|
||||
|
||||
#define MAGIC_WORD 0xABDE2134
|
||||
|
||||
#define SOC_NV_FLASH_NODE DT_CHILD(DT_INST(0, zephyr_sim_flash), flash_sim_0)
|
||||
#define FLASH_SIMULATOR_FLASH_SIZE DT_REG_SIZE(SOC_NV_FLASH_NODE)
|
||||
|
||||
static const struct device *const flash_dev = DEVICE_DT_GET(DT_NODELABEL(sim_flash_controller));
|
||||
static uint32_t boot_count __noinit;
|
||||
|
||||
ZTEST(flash_sim_reboot, test_preserve_over_reboot)
|
||||
{
|
||||
uint32_t word = MAGIC_WORD;
|
||||
int rc;
|
||||
|
||||
if (boot_count == 0) {
|
||||
printk("First boot, erasing flash\n");
|
||||
rc = flash_erase(flash_dev, 0, FLASH_SIMULATOR_FLASH_SIZE);
|
||||
zassert_equal(0, rc, "Failed to erase flash");
|
||||
printk("Writing magic word to offset 0\n");
|
||||
rc = flash_write(flash_dev, 0, &word, sizeof(word));
|
||||
zassert_equal(0, rc, "Failed to write flash");
|
||||
printk("Rebooting device...\n");
|
||||
boot_count += 1;
|
||||
sys_reboot(SYS_REBOOT_WARM);
|
||||
zassert_unreachable("Failed to reboot");
|
||||
} else if (boot_count == 1) {
|
||||
printk("Second boot, reading magic word\n");
|
||||
rc = flash_read(flash_dev, 0, &word, sizeof(word));
|
||||
zassert_equal(0, rc, "Failed to read flash");
|
||||
zassert_equal(MAGIC_WORD, word, "Magic word not preserved");
|
||||
} else {
|
||||
zassert_unreachable("Unexpected boot_count value %d", boot_count);
|
||||
}
|
||||
}
|
||||
|
||||
void *flash_sim_setup(void)
|
||||
{
|
||||
zassert_true(device_is_ready(flash_dev), "Simulated flash device not ready");
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ZTEST_SUITE(flash_sim_reboot, NULL, flash_sim_setup, NULL, NULL, NULL);
|
10
tests/drivers/flash_simulator/flash_sim_reboot/testcase.yaml
Normal file
10
tests/drivers/flash_simulator/flash_sim_reboot/testcase.yaml
Normal file
|
@ -0,0 +1,10 @@
|
|||
common:
|
||||
tags:
|
||||
- drivers
|
||||
- flash
|
||||
tests:
|
||||
drivers.flash.flash_simulator.boot_no_erase:
|
||||
timeout: 5
|
||||
platform_allow: mps2/an385
|
||||
integration_platforms:
|
||||
- mps2/an385
|
Loading…
Add table
Add a link
Reference in a new issue