Skip to content

Commit

Permalink
tests/subsys/fs/nvs: Fix flakiness due to not init'ed data
Browse files Browse the repository at this point in the history
This test has been seen failing at random (though not often).
A valgrind check showed the nvs_ate structures were being
CRC'ed with not-initialized data, and checked later (assuming
the CRC would be different than a constant).
This maybe have been the cause of the test failures, so let's
initialize the whole structure to prevent the CRC value
from depending on random memory/stack content.

Signed-off-by: Alberto Escolar Piedras <alberto.escolar.piedras@nordicsemi.no>
  • Loading branch information
aescolar authored and fabiobaltieri committed Feb 27, 2025
1 parent 63bb55e commit 414996f
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions tests/subsys/fs/nvs/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ ZTEST_F(nvs, test_nvs_gc_corrupt_close_ate)
close_ate.id = 0xffff;
close_ate.offset = fixture->fs.sector_size - sizeof(struct nvs_ate) * 5;
close_ate.len = 0;
close_ate.part = 0xff;
close_ate.crc8 = 0xff; /* Incorrect crc8 */

ate.id = 0x1;
Expand All @@ -667,6 +668,7 @@ ZTEST_F(nvs, test_nvs_gc_corrupt_close_ate)
#ifdef CONFIG_NVS_DATA_CRC
ate.len += sizeof(data_crc);
#endif
ate.part = 0xff;
ate.crc8 = crc8_ccitt(0xff, &ate,
offsetof(struct nvs_ate, crc8));

Expand Down Expand Up @@ -722,12 +724,14 @@ ZTEST_F(nvs, test_nvs_gc_corrupt_ate)
close_ate.id = 0xffff;
close_ate.offset = fixture->fs.sector_size / 2;
close_ate.len = 0;
close_ate.part = 0xff;
close_ate.crc8 = crc8_ccitt(0xff, &close_ate,
offsetof(struct nvs_ate, crc8));

corrupt_ate.id = 0xdead;
corrupt_ate.offset = 0;
corrupt_ate.len = 20;
corrupt_ate.part = 0xff;
corrupt_ate.crc8 = 0xff; /* Incorrect crc8 */

/* Mark sector 0 as closed */
Expand Down

0 comments on commit 414996f

Please sign in to comment.