Skip to content

Commit 28d2a81

Browse files
travis3630carlescufi
authored andcommitted
tests: zephyr: add nrf7120 flash testcases
Add zephyr flash common and flash negative tests testcases, negative tests is added in new folder as it modified negative_test/src/main.c Signed-off-by: Travis Lam <[email protected]>
1 parent 2ae642f commit 28d2a81

File tree

8 files changed

+290
-0
lines changed

8 files changed

+290
-0
lines changed

CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,7 @@
943943
/tests/zephyr/drivers/counter/ @nrfconnect/ncs-low-level-test
944944
/tests/zephyr/drivers/flash/common/ @nrfconnect/ncs-low-level-test @nrfconnect/ncs-ll-ursus
945945
/tests/zephyr/drivers/flash/negative_tests/ @nrfconnect/ncs-low-level-test
946+
/tests/zephyr/drivers/flash/negative_tests_nrf7120/ @nrfconnect/ncs-code-owners @rob-robinson-14 @Hi-Im-David @travis3630
946947
/tests/zephyr/drivers/gpio/ @nrfconnect/ncs-low-level-test
947948
/tests/zephyr/drivers/i2c/i2c_bme688/ @nrfconnect/ncs-low-level-test
948949
/tests/zephyr/drivers/i2c/i2c_target_api/ @nrfconnect/ncs-low-level-test

tests/zephyr/drivers/flash/common/testcase.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ tests:
2828
- nrf54l15dk/nrf54l15/cpuapp
2929
extra_args:
3030
- DTC_OVERLAY_FILE="boards/nrf54l15dk_nrf54l15_cpuapp_sqspi.overlay"
31+
nrf.extended.drivers.flash.common.mramc:
32+
platform_allow:
33+
- nrf7120pdk/nrf7120/cpuapp
34+
integration_platforms:
35+
- nrf7120pdk/nrf7120/cpuapp
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
#
6+
7+
cmake_minimum_required(VERSION 3.20.0)
8+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
9+
project(flash_negative_tests_nrf7120)
10+
11+
FILE(GLOB app_sources src/*.c)
12+
target_sources(app PRIVATE ${app_sources})
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
This sample extends the same-named Zephyr sample to verify it with Nordic development kits.
2+
3+
Source code and basic configuration files can be found in the corresponding folder structure in zephyr/tests/drivers/flash/negative_tests.
4+
5+
This test is specific to nrf7120.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CONFIG_TEST=y
2+
CONFIG_ZTEST=y
3+
CONFIG_FLASH=y
4+
CONFIG_FLASH_PAGE_LAYOUT=y
5+
CONFIG_MAIN_STACK_SIZE=2048
6+
CONFIG_SPI_NOR=n
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: LicenseRef-Nordic-5-Clause
5+
*/
6+
7+
#include <zephyr/kernel.h>
8+
#include <zephyr/ztest.h>
9+
#include <zephyr/drivers/flash.h>
10+
#include <zephyr/devicetree.h>
11+
#include <zephyr/storage/flash_map.h>
12+
13+
#if defined(CONFIG_NORDIC_QSPI_NOR)
14+
#define TEST_AREA_DEV_NODE DT_INST(0, nordic_qspi_nor)
15+
#elif defined(CONFIG_SPI_NOR)
16+
#define TEST_AREA_DEV_NODE DT_INST(0, jedec_spi_nor)
17+
#else
18+
#define TEST_AREA storage_partition
19+
#endif
20+
21+
/* TEST_AREA is only defined for configurations that rely on
22+
* fixed-partition nodes.
23+
*/
24+
#if defined(TEST_AREA)
25+
#define TEST_AREA_OFFSET FIXED_PARTITION_OFFSET(TEST_AREA)
26+
#define TEST_AREA_SIZE FIXED_PARTITION_SIZE(TEST_AREA)
27+
28+
#if defined(CONFIG_SOC_SERIES_NRF54LX)
29+
#define TEST_AREA_DEVICE FIXED_PARTITION_DEVICE(TEST_AREA)
30+
#define TEST_FLASH_START (DT_REG_ADDR(DT_MEM_FROM_FIXED_PARTITION(DT_NODELABEL(TEST_AREA))))
31+
#define TEST_FLASH_SIZE (DT_REG_SIZE(DT_MEM_FROM_FIXED_PARTITION(DT_NODELABEL(TEST_AREA))))
32+
#elif defined(CONFIG_SOC_NRF54H20)
33+
#define TEST_AREA_DEVICE FIXED_PARTITION_DEVICE(TEST_AREA)
34+
#define TEST_FLASH_START (DT_REG_ADDR(DT_PARENT(DT_PARENT(DT_NODELABEL(TEST_AREA)))))
35+
#define TEST_FLASH_SIZE (DT_REG_SIZE(DT_PARENT(DT_PARENT(DT_NODELABEL(TEST_AREA)))))
36+
#elif defined(CONFIG_SOC_NRF7120)
37+
#define DEVICE_NODE DT_PARENT(DT_PARENT(DT_PARENT(DT_NODELABEL(TEST_AREA))))
38+
#define _ADD_SIZE(node_id) + DT_REG_SIZE(node_id)
39+
#define TEST_AREA_DEVICE (DEVICE_DT_GET(DEVICE_NODE))
40+
#define TEST_FLASH_START (DT_REG_ADDR(DT_PARENT(DT_PARENT(DT_NODELABEL(TEST_AREA)))))
41+
#define TEST_FLASH_SIZE (0 DT_FOREACH_CHILD_STATUS_OKAY(DEVICE_NODE, _ADD_SIZE))
42+
#else
43+
#error "Missing definition of TEST_FLASH_START and TEST_FLASH_SIZE for this target"
44+
#endif
45+
46+
#else
47+
#error "Unsupported configuraiton"
48+
#endif
49+
50+
#define EXPECTED_SIZE 512
51+
52+
#if !defined(CONFIG_FLASH_HAS_EXPLICIT_ERASE) && !defined(CONFIG_FLASH_HAS_NO_EXPLICIT_ERASE)
53+
#error There is no flash device enabled or it is missing Kconfig options
54+
#endif
55+
56+
static const struct device *const flash_dev = TEST_AREA_DEVICE;
57+
static struct flash_pages_info page_info;
58+
static uint8_t __aligned(4) expected[EXPECTED_SIZE];
59+
60+
static void *flash_driver_setup(void)
61+
{
62+
int rc;
63+
64+
zassert_true(device_is_ready(flash_dev));
65+
66+
TC_PRINT("Test will run on device %s\n", flash_dev->name);
67+
TC_PRINT("TEST_AREA_OFFSET = 0x%lx\n", (unsigned long)TEST_AREA_OFFSET);
68+
TC_PRINT("TEST_AREA_SIZE = 0x%lx\n", (unsigned long)TEST_AREA_SIZE);
69+
TC_PRINT("TEST_FLASH_START = 0x%lx\n", (unsigned long)TEST_FLASH_START);
70+
TC_PRINT("TEST_FLASH_SIZE = 0x%lx\n", (unsigned long)TEST_FLASH_SIZE);
71+
72+
rc = flash_get_page_info_by_offs(flash_dev, TEST_AREA_OFFSET, &page_info);
73+
zassert_true(rc == 0, "flash_get_page_info_by_offs returned %d", rc);
74+
TC_PRINT("Test Page Info:\n");
75+
TC_PRINT("start_offset = 0x%lx\n", (unsigned long)page_info.start_offset);
76+
TC_PRINT("size = 0x%lx\n", (unsigned long)page_info.size);
77+
TC_PRINT("index = %d\n", page_info.index);
78+
TC_PRINT("===================================================================\n");
79+
80+
return NULL;
81+
}
82+
83+
ZTEST(flash_driver_negative, test_negative_flash_erase)
84+
{
85+
int rc;
86+
87+
#if !defined(TEST_AREA)
88+
/* Flash memory boundaries are correctly calculated
89+
* only for storage_partition.
90+
*/
91+
ztest_test_skip();
92+
#endif
93+
94+
/* Acceptable values of erase size and offset are subject to
95+
* hardware-specific multiples of page size and offset.
96+
*/
97+
98+
/* Check error returned when erasing memory at wrong address (too low) */
99+
rc = flash_erase(flash_dev, (TEST_FLASH_START - page_info.size), page_info.size);
100+
zassert_true(rc < 0, "Invalid use of flash_erase returned %d", rc);
101+
102+
/* Check error returned when erasing memory at wrong address (too high) */
103+
rc = flash_erase(flash_dev, (TEST_FLASH_START + TEST_FLASH_SIZE), page_info.size);
104+
zassert_true(rc < 0, "Invalid use of flash_erase returned %d", rc);
105+
106+
/* Check error returned when erasing unaligned memory or too large chunk of memory */
107+
rc = flash_erase(flash_dev, (TEST_AREA_OFFSET + 1), (TEST_FLASH_SIZE + 1));
108+
zassert_true(rc < 0, "Invalid use of flash_erase returned %d", rc);
109+
110+
/* Erasing 0 bytes shall succeed */
111+
rc = flash_erase(flash_dev, TEST_AREA_OFFSET, 0);
112+
zassert_true(rc == 0, "flash_erase 0 bytes returned %d", rc);
113+
}
114+
115+
ZTEST(flash_driver_negative, test_negative_flash_fill)
116+
{
117+
int rc;
118+
uint8_t fill_val = 0xA; /* Dummy value */
119+
120+
#if !defined(TEST_AREA)
121+
/* Flash memory boundaries are correctly calculated
122+
* only for storage_partition.
123+
*/
124+
ztest_test_skip();
125+
#endif
126+
127+
/* Erase page offset and size are constrains of paged, explicit erase devices,
128+
* but can be relaxed with devices without such requirement.
129+
*/
130+
131+
/* Check error returned when filling memory at wrong address (too low) */
132+
rc = flash_fill(flash_dev, fill_val, (TEST_FLASH_START - page_info.size), page_info.size);
133+
zassert_true(rc < 0, "Invalid use of flash_fill returned %d", rc);
134+
135+
/* Check error returned when filling memory at wrong address (too high) */
136+
rc = flash_fill(flash_dev, fill_val, (TEST_FLASH_START + TEST_FLASH_SIZE), page_info.size);
137+
zassert_true(rc < 0, "Invalid use of flash_fill returned %d", rc);
138+
139+
/* Check error returned when filling unaligned memory */
140+
rc = flash_fill(flash_dev, fill_val, (TEST_AREA_OFFSET + 1), page_info.size);
141+
zassert_true(rc < 0, "Invalid use of flash_fill returned %d", rc);
142+
rc = flash_fill(flash_dev, fill_val, TEST_AREA_OFFSET, (page_info.size + 1));
143+
zassert_true(rc < 0, "Invalid use of flash_fill returned %d", rc);
144+
145+
/* Filling 0 bytes shall succeed */
146+
rc = flash_fill(flash_dev, fill_val, TEST_AREA_OFFSET, 0);
147+
zassert_true(rc == 0, "flash_fill 0 bytes returned %d", rc);
148+
}
149+
150+
ZTEST(flash_driver_negative, test_negative_flash_flatten)
151+
{
152+
int rc;
153+
154+
#if !defined(TEST_AREA)
155+
/* Flash memory boundaries are correctly calculated
156+
* only for storage_partition.
157+
*/
158+
ztest_test_skip();
159+
#endif
160+
161+
/* Erase page offset and size are constrains of paged, explicit erase devices,
162+
* but can be relaxed with devices without such requirement.
163+
*/
164+
165+
/* Check error returned when flatten memory at wrong address (too low) */
166+
rc = flash_flatten(flash_dev, (TEST_FLASH_START - page_info.size), page_info.size);
167+
zassert_true(rc < 0, "Invalid use of flash_flatten returned %d", rc);
168+
169+
/* Check error returned when flatten memory at wrong address (too high) */
170+
rc = flash_flatten(flash_dev, (TEST_FLASH_START + TEST_FLASH_SIZE), page_info.size);
171+
zassert_true(rc < 0, "Invalid use of flash_flatten returned %d", rc);
172+
173+
/* Check error returned when flatten unaligned memory */
174+
rc = flash_flatten(flash_dev, (TEST_AREA_OFFSET + 1), page_info.size);
175+
zassert_true(rc < 0, "Invalid use of flash_flatten returned %d", rc);
176+
rc = flash_flatten(flash_dev, TEST_AREA_OFFSET, (page_info.size + 1));
177+
zassert_true(rc < 0, "Invalid use of flash_flatten returned %d", rc);
178+
179+
/* Flatten 0 bytes shall succeed */
180+
rc = flash_flatten(flash_dev, TEST_AREA_OFFSET, 0);
181+
zassert_true(rc == 0, "flash_flatten 0 bytes returned %d", rc);
182+
}
183+
184+
ZTEST(flash_driver_negative, test_negative_flash_read)
185+
{
186+
int rc;
187+
uint8_t read_buf[EXPECTED_SIZE];
188+
189+
#if !defined(TEST_AREA)
190+
/* Flash memory boundaries are correctly calculated
191+
* only for storage_partition.
192+
*/
193+
ztest_test_skip();
194+
#endif
195+
196+
/* All flash drivers support reads without alignment restrictions on
197+
* the read offset, the read size, or the destination address.
198+
*/
199+
200+
/* Check error returned when reading from a wrong address (too low) */
201+
rc = flash_read(flash_dev, (TEST_FLASH_START - page_info.size), read_buf, EXPECTED_SIZE);
202+
zassert_true(rc < 0, "Invalid use of flash_read returned %d", rc);
203+
204+
/* Check error returned when reading from a wrong address (too high) */
205+
rc = flash_read(flash_dev, (TEST_FLASH_START + TEST_FLASH_SIZE), read_buf, EXPECTED_SIZE);
206+
zassert_true(rc < 0, "Invalid use of flash_read returned %d", rc);
207+
208+
/* Check error returned when reading too many data */
209+
rc = flash_read(flash_dev, TEST_AREA_OFFSET, read_buf, (TEST_FLASH_SIZE + page_info.size));
210+
zassert_true(rc < 0, "Invalid use of flash_read returned %d", rc);
211+
212+
/* Reading 0 bytes shall succeed */
213+
rc = flash_read(flash_dev, TEST_AREA_OFFSET, read_buf, 0);
214+
zassert_true(rc == 0, "flash_read 0 bytes returned %d", rc);
215+
}
216+
217+
ZTEST(flash_driver_negative, test_negative_flash_write)
218+
{
219+
int rc;
220+
221+
#if !defined(TEST_AREA)
222+
/* Flash memory boundaries are correctly calculated
223+
* only for storage_partition.
224+
*/
225+
ztest_test_skip();
226+
#endif
227+
228+
/* Write size and offset must be multiples of the minimum write block size
229+
* supported by the driver.
230+
*/
231+
232+
/* Check error returned when writing to a wrong address (too low) */
233+
rc = flash_write(flash_dev, (TEST_FLASH_START - page_info.size), expected, page_info.size);
234+
zassert_true(rc < 0, "Invalid use of flash_write returned %d", rc);
235+
236+
/* Check error returned when writing to a wrong address (too high) */
237+
rc = flash_write(flash_dev, (TEST_FLASH_START + TEST_FLASH_SIZE), expected, page_info.size);
238+
zassert_true(rc < 0, "Invalid use of flash_write returned %d", rc);
239+
240+
/* Check error returned when writing at unaligned memory or too large chunk of memory */
241+
rc = flash_write(flash_dev, (TEST_AREA_OFFSET + 1), expected, (TEST_FLASH_SIZE + 1));
242+
zassert_true(rc < 0, "Invalid use of flash_write returned %d", rc);
243+
244+
/* Writing 0 bytes shall succeed */
245+
rc = flash_write(flash_dev, TEST_AREA_OFFSET, expected, 0);
246+
zassert_true(rc == 0, "flash_write 0 bytes returned %d", rc);
247+
}
248+
249+
ZTEST_SUITE(flash_driver_negative, NULL, flash_driver_setup, NULL, NULL, NULL);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
SB_CONFIG_PARTITION_MANAGER=n
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
common:
2+
tags:
3+
- drivers
4+
- flash
5+
- ci_tests_zephyr_drivers_flash_negative_tests
6+
tests:
7+
nrf.extended.drivers.flash.negative_tests_nrf7120.mramc:
8+
platform_allow:
9+
- nrf7120pdk/nrf7120/cpuapp
10+
integration_platforms:
11+
- nrf7120pdk/nrf7120/cpuapp

0 commit comments

Comments
 (0)