Skip to content

Commit a448695

Browse files
committed
tests: drivers: flash: Add test with buffer size over the bus packet limit
Applicable to flash devices with MSPI controller Signed-off-by: Bartosz Miller <[email protected]>
1 parent e9cdd68 commit a448695

File tree

1 file changed

+42
-0
lines changed
  • tests/drivers/flash/common/src

1 file changed

+42
-0
lines changed

tests/drivers/flash/common/src/main.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,13 @@ static uint8_t __aligned(4) expected[EXPECTED_SIZE];
7777
static uint8_t erase_value;
7878
static bool ebw_required;
7979

80+
#if DT_NODE_HAS_PROP(DT_BUS(TEST_AREA_DEV_NODE), packet_data_limit)
81+
#define BUFFER_SIZE_OVER_PACKET_LIMIT DT_PROP(DT_BUS(TEST_AREA_DEV_NODE), packet_data_limit) + 1
82+
static uint8_t large_data_buf[BUFFER_SIZE_OVER_PACKET_LIMIT];
83+
#else
84+
#define BUFFER_SIZE_OVER_PACKET_LIMIT 0
85+
#endif
86+
8087
static void flash_driver_before(void *arg)
8188
{
8289
int rc;
@@ -334,6 +341,41 @@ ZTEST(flash_driver, test_flash_erase)
334341
zassert_not_equal(expected[0], erase_value, "These values shall be different");
335342
}
336343

344+
ZTEST(flash_driver, test_flash_write_read_over_the_packet_limit)
345+
{
346+
if (BUFFER_SIZE_OVER_PACKET_LIMIT == 0) {
347+
ztest_test_skip();
348+
}
349+
350+
TC_PRINT("SIZE: %u\n", BUFFER_SIZE_OVER_PACKET_LIMIT);
351+
352+
int rc;
353+
const uint8_t pattern = 0xA1;
354+
355+
/* Set every byte in the buffer to the predefined pattern */
356+
memset(large_data_buf, pattern, BUFFER_SIZE_OVER_PACKET_LIMIT);
357+
358+
/* Write flash area with buffer size over the configured packet limit */
359+
rc = flash_write(flash_dev, page_info.start_offset, large_data_buf,
360+
BUFFER_SIZE_OVER_PACKET_LIMIT);
361+
zassert_equal(rc, 0, "Cannot write flash");
362+
363+
/* Flush buffer */
364+
memset(large_data_buf, 0xFF, BUFFER_SIZE_OVER_PACKET_LIMIT);
365+
366+
/* Read flash area with buffer size over the MSPI packet limit */
367+
rc = flash_read(flash_dev, page_info.start_offset, large_data_buf,
368+
BUFFER_SIZE_OVER_PACKET_LIMIT);
369+
zassert_equal(rc, 0, "Cannot read flash");
370+
371+
/* Compare read data to the pre-defined pattern */
372+
for (int i = 0; i < BUFFER_SIZE_OVER_PACKET_LIMIT; i++) {
373+
zassert_equal(large_data_buf[i], pattern,
374+
"large_data_buf[%u]=%x read, does not match written pattern %x", i,
375+
large_data_buf[i], pattern);
376+
}
377+
}
378+
337379
ZTEST(flash_driver, test_supply_gpios_control)
338380
{
339381
if (!DT_NODE_HAS_PROP(TEST_AREA_DEV_NODE, supply_gpios)) {

0 commit comments

Comments
 (0)