You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by je...@apache.org on 2022/04/11 08:43:32 UTC
[mynewt-core] 01/03: fcb2/selftest: Add function to init FCB without clearing flash
This is an automated email from the ASF dual-hosted git repository.
jerzy pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 62b7fc82497a87c0a24d5ae809855b054c205ef2
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Sun Apr 10 10:25:48 2022 +0200
fcb2/selftest: Add function to init FCB without clearing flash
fcb2_init function when executed on previously correct flash should
not fail.
fcb_tc_pretest was calling fcb2_init always on empty flash.
Now it is possible to re-run fcb2_init when flash is already filled.
---
fs/fcb2/selftest/src/fcb_test.c | 17 ++++++++++++-----
fs/fcb2/selftest/src/fcb_test.h | 2 ++
fs/fcb2/selftest/src/testcases/fcb_test_append_fill.c | 10 ++++++++++
3 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/fs/fcb2/selftest/src/fcb_test.c b/fs/fcb2/selftest/src/fcb_test.c
index c384e82a1..ad9693477 100644
--- a/fs/fcb2/selftest/src/fcb_test.c
+++ b/fs/fcb2/selftest/src/fcb_test.c
@@ -108,13 +108,11 @@ fcb_test_cnt_elems_cb(struct fcb2_entry *loc, void *arg)
return 0;
}
-void
-fcb_tc_pretest(uint8_t sector_count)
+int
+fcb_tc_init_fcb(uint8_t sector_count)
{
struct fcb2 *fcb;
- int rc = 0;
- fcb_test_wipe();
fcb = &test_fcb;
memset(fcb, 0, sizeof(*fcb));
fcb->f_sector_cnt = sector_count;
@@ -124,7 +122,16 @@ fcb_tc_pretest(uint8_t sector_count)
test_fcb_ranges[0].fsr_flash_area.fa_size =
test_fcb_ranges[0].fsr_sector_size * sector_count;
- rc = fcb2_init(fcb);
+ return fcb2_init(fcb);
+}
+
+void
+fcb_tc_pretest(uint8_t sector_count)
+{
+ int rc = 0;
+
+ fcb_test_wipe();
+ rc = fcb_tc_init_fcb(sector_count);
if (rc != 0) {
printf("fcb_tc_pretest rc == %x, %d\n", rc, rc);
TEST_ASSERT(rc == 0);
diff --git a/fs/fcb2/selftest/src/fcb_test.h b/fs/fcb2/selftest/src/fcb_test.h
index acc8242b9..397f7ccfa 100644
--- a/fs/fcb2/selftest/src/fcb_test.h
+++ b/fs/fcb2/selftest/src/fcb_test.h
@@ -46,6 +46,8 @@ uint8_t fcb_test_append_data(int msg_len, int off);
int fcb_test_data_walk_cb(struct fcb2_entry *loc, void *arg);
int fcb_test_cnt_elems_cb(struct fcb2_entry *loc, void *arg);
void fcb_tc_pretest(uint8_t sector_count);
+/* Inits fcb without wiping flash */
+int fcb_tc_init_fcb(uint8_t sector_count);
#ifdef __cplusplus
}
diff --git a/fs/fcb2/selftest/src/testcases/fcb_test_append_fill.c b/fs/fcb2/selftest/src/testcases/fcb_test_append_fill.c
index 7ca56cd6b..e64ad147f 100644
--- a/fs/fcb2/selftest/src/testcases/fcb_test_append_fill.c
+++ b/fs/fcb2/selftest/src/testcases/fcb_test_append_fill.c
@@ -78,4 +78,14 @@ TEST_CASE_SELF(fcb_test_append_fill)
TEST_ASSERT(rc == 0);
TEST_ASSERT(aa_separate.elem_cnts[0] == elem_cnts[0]);
TEST_ASSERT(aa_separate.elem_cnts[1] == elem_cnts[1]);
+
+ /* Re-init FCB without clearing flash */
+ rc = fcb_tc_init_fcb(2);
+ TEST_ASSERT(rc == 0);
+ aa_together_cnts[0] = 0;
+ aa_together_cnts[1] = 0;
+ /* Walk again, number of elements should not changed */
+ rc = fcb2_walk(fcb, FCB2_SECTOR_OLDEST, fcb_test_cnt_elems_cb, &aa_together);
+ TEST_ASSERT(aa_together_cnts[0] == elem_cnts[0]);
+ TEST_ASSERT(aa_together_cnts[1] == elem_cnts[1]);
}