Skip to content

Commit 2ec7254

Browse files
RICCIARDI-Adrienanangl
authored andcommitted
[nrf fromtree] tests: fs: nvs: Add a test scenario for data CRC
Adapt the test_nvs_gc_corrupt_close_ate test to forge the data CRC. Signed-off-by: Adrien Ricciardi <[email protected]> (cherry picked from commit e13840c) Signed-off-by: Andrzej Głąbek <[email protected]>
1 parent c1add2c commit 2ec7254

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

tests/subsys/fs/nvs/src/main.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,8 @@ ZTEST_F(nvs, test_nvs_full_sector)
560560
len);
561561
} else {
562562
zassert_true(len == sizeof(data_read),
563-
"nvs_read failed: %d", i, len);
563+
"nvs_read #%d failed: len is %zd instead of %zu",
564+
i, len, sizeof(data_read));
564565
zassert_equal(data_read, i,
565566
"read unexpected data: %d instead of %d",
566567
data_read, i);
@@ -639,6 +640,9 @@ ZTEST_F(nvs, test_nvs_gc_corrupt_close_ate)
639640
uint32_t data;
640641
ssize_t len;
641642
int err;
643+
#ifdef CONFIG_NVS_DATA_CRC
644+
uint32_t data_crc;
645+
#endif
642646

643647
close_ate.id = 0xffff;
644648
close_ate.offset = fixture->fs.sector_size - sizeof(struct nvs_ate) * 5;
@@ -648,6 +652,9 @@ ZTEST_F(nvs, test_nvs_gc_corrupt_close_ate)
648652
ate.id = 0x1;
649653
ate.offset = 0;
650654
ate.len = sizeof(data);
655+
#ifdef CONFIG_NVS_DATA_CRC
656+
ate.len += sizeof(data_crc);
657+
#endif
651658
ate.crc8 = crc8_ccitt(0xff, &ate,
652659
offsetof(struct nvs_ate, crc8));
653660

@@ -666,6 +673,12 @@ ZTEST_F(nvs, test_nvs_gc_corrupt_close_ate)
666673
data = 0xaa55aa55;
667674
err = flash_write(fixture->fs.flash_device, fixture->fs.offset, &data, sizeof(data));
668675
zassert_true(err == 0, "flash_write failed: %d", err);
676+
#ifdef CONFIG_NVS_DATA_CRC
677+
data_crc = crc32_ieee((const uint8_t *) &data, sizeof(data));
678+
err = flash_write(fixture->fs.flash_device, fixture->fs.offset + sizeof(data), &data_crc,
679+
sizeof(data_crc));
680+
zassert_true(err == 0, "flash_write for data CRC failed: %d", err);
681+
#endif
669682

670683
/* Mark sector 1 as closed */
671684
err = flash_write(fixture->fs.flash_device,

tests/subsys/fs/nvs/testcase.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,15 @@ tests:
1111
- CONFIG_NVS_LOOKUP_CACHE=y
1212
- CONFIG_NVS_LOOKUP_CACHE_SIZE=64
1313
platform_allow: native_sim
14+
filesystem.nvs.data_crc:
15+
extra_args:
16+
- CONFIG_NVS_DATA_CRC=y
17+
platform_allow:
18+
- native_sim
19+
- qemu_x86
20+
filesystem.nvs.data_crc_cache:
21+
extra_args:
22+
- CONFIG_NVS_DATA_CRC=y
23+
- CONFIG_NVS_LOOKUP_CACHE=y
24+
- CONFIG_NVS_LOOKUP_CACHE_SIZE=64
25+
platform_allow: native_sim

0 commit comments

Comments
 (0)