Skip to content

Commit 6712608

Browse files
57300jukkar
authored andcommitted
[nrf fromlist] tests: zms: Add test coverage for ZMS_ID_64BIT
Upstream PR #: 94330 * Update the "corrupt ATE" tests to work with the new ATE format. * Add a basic test to verify support to 64 bit ZMS IDs. * Add a `testcase.yaml` entry to cover the above points and also run lookup cache tests to evaluate the 64 bit hash function. Signed-off-by: Grzegorz Swiderski <[email protected]> (cherry picked from commit d9e38a9c4521e9b4423526e2c8e91b64f15928c7) (cherry picked from commit 9311d96)
1 parent deb36a9 commit 6712608

File tree

2 files changed

+56
-6
lines changed

2 files changed

+56
-6
lines changed

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

Lines changed: 50 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -578,17 +578,19 @@ ZTEST_F(zms, test_zms_gc_corrupt_close_ate)
578578
int err;
579579

580580
Z_TEST_SKIP_IFNDEF(CONFIG_FLASH_SIMULATOR_DOUBLE_WRITES);
581-
close_ate.id = 0xffffffff;
581+
memset(&close_ate, 0xff, sizeof(struct zms_ate));
582+
close_ate.id = ZMS_HEAD_ID;
582583
close_ate.offset = fixture->fs.sector_size - sizeof(struct zms_ate) * 5;
583584
close_ate.len = 0;
584-
close_ate.metadata = 0xffffffff;
585585
close_ate.cycle_cnt = 1;
586586
close_ate.crc8 = 0xff; /* Incorrect crc8 */
587587

588-
empty_ate.id = 0xffffffff;
589-
empty_ate.offset = 0;
588+
memset(&empty_ate, 0, sizeof(struct zms_ate));
589+
empty_ate.id = ZMS_HEAD_ID;
590590
empty_ate.len = 0xffff;
591-
empty_ate.metadata = 0x4201;
591+
empty_ate.metadata = FIELD_PREP(ZMS_VERSION_MASK, ZMS_DEFAULT_VERSION) |
592+
FIELD_PREP(ZMS_MAGIC_NUMBER_MASK, ZMS_MAGIC_NUMBER) |
593+
FIELD_PREP(ZMS_ATE_FORMAT_MASK, ZMS_DEFAULT_ATE_FORMAT);
592594
empty_ate.cycle_cnt = 1;
593595
empty_ate.crc8 =
594596
crc8_ccitt(0xff, (uint8_t *)&empty_ate + SIZEOF_FIELD(struct zms_ate, crc8),
@@ -649,7 +651,7 @@ ZTEST_F(zms, test_zms_gc_corrupt_ate)
649651
struct zms_ate close_ate;
650652
int err;
651653

652-
close_ate.id = 0xffffffff;
654+
close_ate.id = ZMS_HEAD_ID;
653655
close_ate.offset = fixture->fs.sector_size / 2;
654656
close_ate.len = 0;
655657
close_ate.crc8 =
@@ -955,3 +957,45 @@ ZTEST_F(zms, test_zms_input_validation)
955957
err = zms_delete(&fixture->fs, 0);
956958
zassert_true(err == -EACCES, "zms_delete call before mount fs failure: %d", err);
957959
}
960+
961+
/*
962+
* Test 64 bit ZMS ID support.
963+
*/
964+
ZTEST_F(zms, test_zms_id_64bit)
965+
{
966+
int err;
967+
ssize_t len;
968+
uint64_t data;
969+
uint64_t filling_id = 0xdeadbeefULL;
970+
971+
Z_TEST_SKIP_IFNDEF(CONFIG_ZMS_ID_64BIT);
972+
973+
err = zms_mount(&fixture->fs);
974+
zassert_true(err == 0, "zms_mount call failure: %d", err);
975+
976+
/* Fill the first sector with writes of different IDs */
977+
978+
while (fixture->fs.data_wra + sizeof(data) + sizeof(struct zms_ate) <=
979+
fixture->fs.ate_wra) {
980+
data = filling_id;
981+
len = zms_write(&fixture->fs, (zms_id_t)filling_id, &data, sizeof(data));
982+
zassert_true(len == sizeof(data), "zms_write failed: %d", len);
983+
984+
/* Choose the next ID so that its lower 32 bits stay invariant.
985+
* The purpose is to test that ZMS doesn't mistakenly cast the
986+
* 64 bit ID to a 32 bit one somewhere.
987+
*/
988+
filling_id += BIT64(32);
989+
}
990+
991+
/* Read back the written entries and check that they're all unique */
992+
993+
for (uint64_t id = 0xdeadbeefULL; id < filling_id; id += BIT64(32)) {
994+
len = zms_read_hist(&fixture->fs, (zms_id_t)id, &data, sizeof(data), 0);
995+
zassert_true(len == sizeof(data), "zms_read_hist unexpected failure: %d", len);
996+
zassert_equal(data, id, "read unexpected data: %llx instead of %llx", data, id);
997+
998+
len = zms_read_hist(&fixture->fs, (zms_id_t)id, &data, sizeof(data), 1);
999+
zassert_true(len == -ENOENT, "zms_read_hist unexpected failure: %d", len);
1000+
}
1001+
}

tests/subsys/fs/zms/testcase.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,9 @@ tests:
2727
platform_allow:
2828
- native_sim
2929
- qemu_x86
30+
filesystem.zms.id_64bit:
31+
extra_configs:
32+
- CONFIG_ZMS_ID_64BIT=y
33+
- CONFIG_ZMS_LOOKUP_CACHE=y
34+
- CONFIG_ZMS_LOOKUP_CACHE_SIZE=64
35+
platform_allow: qemu_x86

0 commit comments

Comments
 (0)