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:31 UTC

[mynewt-core] branch master updated (468fe5eaf -> 63d9db228)

This is an automated email from the ASF dual-hosted git repository.

jerzy pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git


    from 468fe5eaf Add RTC DS3231
     new 62b7fc824 fcb2/selftest: Add function to init FCB without clearing flash
     new a3cc4aade fcb2/selftest: Add test that fills FCB with small writes
     new 63d9db228 fcb2: Fix moving to next location when buffer was full

The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 fs/fcb2/selftest/src/fcb_test.c                       | 19 ++++++++++++++-----
 fs/fcb2/selftest/src/fcb_test.h                       |  2 ++
 fs/fcb2/selftest/src/testcases/fcb_test_append_fill.c | 10 ++++++++++
 ...est_append_fill.c => fcb_test_append_fill_small.c} | 14 ++++++++++++--
 fs/fcb2/src/fcb_getnext.c                             | 17 +++++++++++++----
 5 files changed, 51 insertions(+), 11 deletions(-)
 copy fs/fcb2/selftest/src/testcases/{fcb_test_append_fill.c => fcb_test_append_fill_small.c} (84%)


[mynewt-core] 01/03: fcb2/selftest: Add function to init FCB without clearing flash

Posted by je...@apache.org.
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]);
 }


[mynewt-core] 03/03: fcb2: Fix moving to next location when buffer was full

Posted by je...@apache.org.
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 63d9db2288685c96d0bb1218a9a4a9432806e5bb
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Sat Apr 9 23:42:42 2022 +0200

    fcb2: Fix moving to next location when buffer was full
    
    When FCB sector was fully filled with data and there was no
    space for new entry, function fcb2_getnext_in_area() returned
    FCB2_ERR_CRC instead of FCB2_ERR_NOVAR.
    This resulted in fcb2_init() clearing everything.
---
 fs/fcb2/src/fcb_getnext.c | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/fs/fcb2/src/fcb_getnext.c b/fs/fcb2/src/fcb_getnext.c
index 4a61dfb53..ea18be4f7 100644
--- a/fs/fcb2/src/fcb_getnext.c
+++ b/fs/fcb2/src/fcb_getnext.c
@@ -25,18 +25,27 @@ int
 fcb2_getnext_in_area(struct fcb2 *fcb, struct fcb2_entry *loc)
 {
     int rc = FCB2_ERR_CRC;
-    int off;
     int len;
+    int next_data_offset;
+    int next_entry_offset;
 
     while (rc == FCB2_ERR_CRC) {
         len = loc->fe_data_len;
-        off = loc->fe_data_off;
+        /* Next data offset in sector */
+        next_data_offset = loc->fe_data_off + fcb2_len_in_flash(loc->fe_range, len) +
+                                                 fcb2_len_in_flash(loc->fe_range, 2);
+        /* Possible entry offset for next data */
+        next_entry_offset = fcb->f_active.fe_range->fsr_sector_size -
+                            (FCB2_ENTRY_SIZE * (loc->fe_entry_num + 1));
         loc->fe_data_len = 0;
         loc->fe_entry_num++;
+        /* If there is no space for next entry just finish search */
+        if (next_data_offset >= next_entry_offset) {
+            return FCB2_ERR_NOVAR;
+        }
         rc = fcb2_elem_info(loc);
         if (len) {
-            loc->fe_data_off = off + fcb2_len_in_flash(loc->fe_range, len) +
-                fcb2_len_in_flash(loc->fe_range, 2);
+            loc->fe_data_off = next_data_offset;
         }
     }
     return rc;


[mynewt-core] 02/03: fcb2/selftest: Add test that fills FCB with small writes

Posted by je...@apache.org.
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 a3cc4aade0925a4a68195127a15d60539bc706e1
Author: Jerzy Kasenberg <je...@codecoup.pl>
AuthorDate: Sun Apr 10 10:29:25 2022 +0200

    fcb2/selftest: Add test that fills FCB with small writes
    
    When chunks of data written to FCB2 are small it triggers
    condition when amount of empty space in FCB sector is less
    than FCB2 entry size (6 bytes).
    This condition was incorrectly handled in fcb2_init
---
 fs/fcb2/selftest/src/fcb_test.c                    |  2 +
 .../src/testcases/fcb_test_append_fill_small.c     | 91 ++++++++++++++++++++++
 2 files changed, 93 insertions(+)

diff --git a/fs/fcb2/selftest/src/fcb_test.c b/fs/fcb2/selftest/src/fcb_test.c
index ad9693477..695839595 100644
--- a/fs/fcb2/selftest/src/fcb_test.c
+++ b/fs/fcb2/selftest/src/fcb_test.c
@@ -143,6 +143,7 @@ TEST_CASE_DECL(fcb_test_empty_walk)
 TEST_CASE_DECL(fcb_test_append)
 TEST_CASE_DECL(fcb_test_append_too_big)
 TEST_CASE_DECL(fcb_test_append_fill)
+TEST_CASE_DECL(fcb_test_append_fill_small)
 TEST_CASE_DECL(fcb_test_reset)
 TEST_CASE_DECL(fcb_test_rotate)
 TEST_CASE_DECL(fcb_test_multiple_scratch)
@@ -157,6 +158,7 @@ TEST_SUITE(fcb_test_all)
     fcb_test_append();
     fcb_test_append_too_big();
     fcb_test_append_fill();
+    fcb_test_append_fill_small();
     fcb_test_reset();
     fcb_test_rotate();
     fcb_test_multiple_scratch();
diff --git a/fs/fcb2/selftest/src/testcases/fcb_test_append_fill_small.c b/fs/fcb2/selftest/src/testcases/fcb_test_append_fill_small.c
new file mode 100644
index 000000000..bad9f1356
--- /dev/null
+++ b/fs/fcb2/selftest/src/testcases/fcb_test_append_fill_small.c
@@ -0,0 +1,91 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+#include "fcb_test.h"
+
+TEST_CASE_SELF(fcb_test_append_fill_small)
+{
+    struct fcb2 *fcb;
+    int rc;
+    int i;
+    struct fcb2_entry loc;
+    uint8_t test_data[1];
+    int elem_cnts[2] = {0, 0};
+    int aa_together_cnts[2];
+    struct append_arg aa_together = {
+        .elem_cnts = aa_together_cnts
+    };
+    int aa_separate_cnts[2];
+    struct append_arg aa_separate = {
+        .elem_cnts = aa_separate_cnts
+    };
+
+    fcb_tc_pretest(2);
+
+    fcb = &test_fcb;
+
+    for (i = 0; i < sizeof(test_data); i++) {
+        test_data[i] = fcb_test_append_data(sizeof(test_data), i);
+    }
+
+    while (1) {
+        rc = fcb2_append(fcb, sizeof(test_data), &loc);
+        if (rc == FCB2_ERR_NOSPACE) {
+            break;
+        }
+        if (loc.fe_sector == 0) {
+            elem_cnts[0]++;
+        } else if (loc.fe_sector == 1) {
+            elem_cnts[1]++;
+        } else {
+            TEST_ASSERT(0);
+        }
+
+        rc = fcb2_write(&loc, 0, test_data, sizeof(test_data));
+        TEST_ASSERT(rc == 0);
+
+        rc = fcb2_append_finish(&loc);
+        TEST_ASSERT(rc == 0);
+    }
+    TEST_ASSERT(elem_cnts[0] > 0);
+    TEST_ASSERT(elem_cnts[0] == elem_cnts[1]);
+
+    memset(&aa_together_cnts, 0, sizeof(aa_together_cnts));
+    rc = fcb2_walk(fcb, FCB2_SECTOR_OLDEST, fcb_test_cnt_elems_cb, &aa_together);
+    TEST_ASSERT(rc == 0);
+    TEST_ASSERT(aa_together.elem_cnts[0] == elem_cnts[0]);
+    TEST_ASSERT(aa_together.elem_cnts[1] == elem_cnts[1]);
+
+    memset(&aa_separate_cnts, 0, sizeof(aa_separate_cnts));
+    rc = fcb2_walk(fcb, 0, fcb_test_cnt_elems_cb, &aa_separate);
+    TEST_ASSERT(rc == 0);
+    rc = fcb2_walk(fcb, 1, fcb_test_cnt_elems_cb, &aa_separate);
+    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]);
+}