You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mynewt.apache.org by vi...@apache.org on 2019/10/15 18:15:26 UTC
[mynewt-core] branch master updated: sys/log;
add syscfg knob to allow separate indexing for each log.
This is an automated email from the ASF dual-hosted git repository.
vipulrahane pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
The following commit(s) were added to refs/heads/master by this push:
new ad8f567 sys/log; add syscfg knob to allow separate indexing for each log.
new bf534f0 Merge pull request #2036 from mkiiskila/perlogidx
ad8f567 is described below
commit ad8f567631c5c18e88332c6d7925a9664dafaf10
Author: Marko Kiiskila <ma...@apache.org>
AuthorDate: Thu Oct 10 16:40:44 2019 +0300
sys/log; add syscfg knob to allow separate indexing for each log.
---
sys/log/common/include/log_common/log_common.h | 2 +
sys/log/common/syscfg.yml | 5 ++
sys/log/full/include/log/log.h | 3 +
.../syscfg.yml => full/selftest/perlogidx/pkg.yml} | 25 +++----
.../src/log_test_perlogidx.c} | 34 ++-------
.../{common => full/selftest/perlogidx}/syscfg.yml | 22 ++----
.../util/include/log_test_util/log_test_util.h | 4 +
sys/log/full/selftest/util/src/log_test.c | 3 +
sys/log/full/selftest/util/src/log_test_util.c | 35 +++++++++
.../util/src/testcases/log_test_case_2logs.c | 87 ++++++++++++++++++++++
sys/log/full/src/log.c | 19 ++++-
sys/log/full/src/log_fcb.c | 19 +++--
12 files changed, 192 insertions(+), 66 deletions(-)
diff --git a/sys/log/common/include/log_common/log_common.h b/sys/log/common/include/log_common/log_common.h
index 6aa4d89..9a42354 100644
--- a/sys/log/common/include/log_common/log_common.h
+++ b/sys/log/common/include/log_common/log_common.h
@@ -117,7 +117,9 @@ struct log;
/* Global log info */
struct log_info {
+#if MYNEWT_VAL(LOG_GLOBAL_IDX)
uint32_t li_next_index;
+#endif
uint8_t li_version;
};
diff --git a/sys/log/common/syscfg.yml b/sys/log/common/syscfg.yml
index e5df5d8..855f503 100644
--- a/sys/log/common/syscfg.yml
+++ b/sys/log/common/syscfg.yml
@@ -24,6 +24,11 @@ syscfg.defs:
DFLT_LOG_LVL:
description: 'Minimum level for the default log.'
value: 1
+ LOG_GLOBAL_IDX:
+ description: >
+ Log entries indices are coming from same number space. Otherwise
+ every log has their own indexing.
+ value: 1
syscfg.logs:
DFLT_LOG:
diff --git a/sys/log/full/include/log/log.h b/sys/log/full/include/log/log.h
index cafddab..4cf3240 100644
--- a/sys/log/full/include/log/log.h
+++ b/sys/log/full/include/log/log.h
@@ -215,6 +215,9 @@ struct log {
log_append_cb *l_append_cb;
uint8_t l_level;
uint16_t l_max_entry_len; /* Log body length; if 0 disables check. */
+#if !MYNEWT_VAL(LOG_GLOBAL_IDX)
+ uint32_t l_idx;
+#endif
#if MYNEWT_VAL(LOG_STATS)
STATS_SECT_DECL(logs) l_stats;
#endif
diff --git a/sys/log/common/syscfg.yml b/sys/log/full/selftest/perlogidx/pkg.yml
similarity index 65%
copy from sys/log/common/syscfg.yml
copy to sys/log/full/selftest/perlogidx/pkg.yml
index e5df5d8..4e26fef 100644
--- a/sys/log/common/syscfg.yml
+++ b/sys/log/full/selftest/perlogidx/pkg.yml
@@ -1,4 +1,3 @@
-#
# 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
@@ -16,17 +15,15 @@
# specific language governing permissions and limitations
# under the License.
#
+pkg.name: sys/log/full/selftest/perlogidx
+pkg.type: unittest
+pkg.description: "Log unit tests; unique index per log."
+pkg.author: "Apache Mynewt <de...@mynewt.apache.org>"
+pkg.homepage: "http://mynewt.apache.org/"
+pkg.keywords:
-syscfg.defs:
- DFLT_LOG_MOD:
- description: 'Numeric module ID to use for default log messages.'
- value: 0
- DFLT_LOG_LVL:
- description: 'Minimum level for the default log.'
- value: 1
-
-syscfg.logs:
- DFLT_LOG:
- module: MYNEWT_VAL(DFLT_LOG_MOD)
- level: MYNEWT_VAL(DFLT_LOG_LVL)
-
+pkg.deps:
+ - "@apache-mynewt-core/sys/console/stub"
+ - "@apache-mynewt-core/sys/log/full"
+ - "@apache-mynewt-core/sys/log/full/selftest/util"
+ - "@apache-mynewt-core/test/testutil"
diff --git a/sys/log/full/selftest/util/src/log_test.c b/sys/log/full/selftest/perlogidx/src/log_test_perlogidx.c
similarity index 58%
copy from sys/log/full/selftest/util/src/log_test.c
copy to sys/log/full/selftest/perlogidx/src/log_test_perlogidx.c
index 885abff..db477f3 100644
--- a/sys/log/full/selftest/util/src/log_test.c
+++ b/sys/log/full/selftest/perlogidx/src/log_test_perlogidx.c
@@ -20,34 +20,12 @@
#include "os/mynewt.h"
#include "log_test_util/log_test_util.h"
-TEST_SUITE(log_test_suite_cbmem_flat)
+int
+main(int argc, char **argv)
{
- log_test_case_cbmem_append();
- log_test_case_cbmem_append_body();
- log_test_case_cbmem_printf();
-}
-
-TEST_SUITE(log_test_suite_cbmem_mbuf)
-{
- log_test_case_cbmem_append_mbuf();
- log_test_case_cbmem_append_mbuf_body();
-}
+ log_test_suite_fcb_flat();
+ log_test_suite_fcb_mbuf();
+ log_test_suite_misc();
-TEST_SUITE(log_test_suite_fcb_flat)
-{
- log_test_case_fcb_append();
- log_test_case_fcb_append_body();
- log_test_case_fcb_printf();
-}
-
-TEST_SUITE(log_test_suite_fcb_mbuf)
-{
- log_test_case_fcb_append_mbuf();
- log_test_case_fcb_append_mbuf_body();
-}
-
-TEST_SUITE(log_test_suite_misc)
-{
- log_test_case_level();
- log_test_case_append_cb();
+ return tu_any_failed;
}
diff --git a/sys/log/common/syscfg.yml b/sys/log/full/selftest/perlogidx/syscfg.yml
similarity index 70%
copy from sys/log/common/syscfg.yml
copy to sys/log/full/selftest/perlogidx/syscfg.yml
index e5df5d8..d166a44 100644
--- a/sys/log/common/syscfg.yml
+++ b/sys/log/full/selftest/perlogidx/syscfg.yml
@@ -1,4 +1,3 @@
-#
# 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
@@ -6,7 +5,7 @@
# 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,
@@ -17,16 +16,11 @@
# under the License.
#
-syscfg.defs:
- DFLT_LOG_MOD:
- description: 'Numeric module ID to use for default log messages.'
- value: 0
- DFLT_LOG_LVL:
- description: 'Minimum level for the default log.'
- value: 1
-
-syscfg.logs:
- DFLT_LOG:
- module: MYNEWT_VAL(DFLT_LOG_MOD)
- level: MYNEWT_VAL(DFLT_LOG_LVL)
+syscfg.vals:
+ LOG_FCB: 1
+ LOG_VERSION: 3
+ MCU_FLASH_MIN_WRITE_SIZE: 1
+ LOG_GLOBAL_IDX: 0
+ # The mbuf append tests allocate lots of mbufs; ensure no exhaustion.
+ MSYS_1_BLOCK_COUNT: 1000
diff --git a/sys/log/full/selftest/util/include/log_test_util/log_test_util.h b/sys/log/full/selftest/util/include/log_test_util/log_test_util.h
index c6c78f5..90b77e4 100644
--- a/sys/log/full/selftest/util/include/log_test_util/log_test_util.h
+++ b/sys/log/full/selftest/util/include/log_test_util/log_test_util.h
@@ -45,6 +45,8 @@ extern char *ltu_str_logs[];
struct os_mbuf *ltu_flat_to_fragged_mbuf(const void *flat, int len,
int frag_sz);
void ltu_setup_fcb(struct fcb_log *fcb_log, struct log *log);
+void ltu_setup_2fcbs(struct fcb_log *fcb_log1, struct log *log1,
+ struct fcb_log *fcb_log2, struct log *log2);
void ltu_setup_cbmem(struct cbmem *cbmem, struct log *log);
void ltu_verify_contents(struct log *log);
@@ -70,6 +72,8 @@ TEST_SUITE_DECL(log_test_suite_misc);
TEST_CASE_DECL(log_test_case_level);
TEST_CASE_DECL(log_test_case_append_cb);
+TEST_CASE_DECL(log_test_case_2logs);
+
#ifdef __cplusplus
}
#endif
diff --git a/sys/log/full/selftest/util/src/log_test.c b/sys/log/full/selftest/util/src/log_test.c
index 885abff..80939d7 100644
--- a/sys/log/full/selftest/util/src/log_test.c
+++ b/sys/log/full/selftest/util/src/log_test.c
@@ -50,4 +50,7 @@ TEST_SUITE(log_test_suite_misc)
{
log_test_case_level();
log_test_case_append_cb();
+#if MYNEWT_VAL(LOG_FCB)
+ log_test_case_2logs();
+#endif
}
diff --git a/sys/log/full/selftest/util/src/log_test_util.c b/sys/log/full/selftest/util/src/log_test_util.c
index bd4e303..2447cbb 100644
--- a/sys/log/full/selftest/util/src/log_test_util.c
+++ b/sys/log/full/selftest/util/src/log_test_util.c
@@ -139,6 +139,41 @@ ltu_setup_fcb(struct fcb_log *fcb_log, struct log *log)
}
void
+ltu_setup_2fcbs(struct fcb_log *fcb_log1, struct log *log1,
+ struct fcb_log *fcb_log2, struct log *log2)
+{
+#if MYNEWT_VAL(LOG_FCB)
+ int rc;
+ int i;
+
+ for (i = 0; i < sizeof(fcb_areas) / sizeof(fcb_areas[0]); i++) {
+ rc = flash_area_erase(&fcb_areas[i], 0, fcb_areas[i].fa_size);
+ TEST_ASSERT(rc == 0);
+ }
+
+ memset(fcb_log1, 0, sizeof(struct fcb_log));
+ fcb_log1->fl_fcb.f_magic = 0x7EADBADF;
+ fcb_log1->fl_fcb.f_version = 0;
+ fcb_log1->fl_fcb.f_sectors = &fcb_areas[0];
+ fcb_log1->fl_fcb.f_sector_cnt = 1;
+ rc = fcb_init(&fcb_log1->fl_fcb);
+ TEST_ASSERT(rc == 0);
+ log_register("log1", log1, &log_fcb_handler, fcb_log1, LOG_SYSLEVEL);
+
+ memset(fcb_log2, 0, sizeof(struct fcb_log));
+ fcb_log2->fl_fcb.f_magic = 0x7EADBADF;
+ fcb_log2->fl_fcb.f_version = 0;
+ fcb_log2->fl_fcb.f_sectors = &fcb_areas[1];
+ fcb_log2->fl_fcb.f_sector_cnt = 1;
+ rc = fcb_init(&fcb_log2->fl_fcb);
+ TEST_ASSERT(rc == 0);
+ log_register("log2", log2, &log_fcb_handler, fcb_log2, LOG_SYSLEVEL);
+#else
+ TEST_ASSERT(0);
+#endif
+}
+
+void
ltu_setup_cbmem(struct cbmem *cbmem, struct log *log)
{
cbmem_init(cbmem, ltu_cbmem_buf, sizeof ltu_cbmem_buf);
diff --git a/sys/log/full/selftest/util/src/testcases/log_test_case_2logs.c b/sys/log/full/selftest/util/src/testcases/log_test_case_2logs.c
new file mode 100644
index 0000000..7e57355
--- /dev/null
+++ b/sys/log/full/selftest/util/src/testcases/log_test_case_2logs.c
@@ -0,0 +1,87 @@
+/*
+ * 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 "log_test_util/log_test_util.h"
+
+struct ltc2l_entry {
+ struct log *log;
+ uint32_t idx;
+};
+
+#define LTC2L_MAX_ENTRIES 16
+static struct ltc2l_entry ltc2l_entries[LTC2L_MAX_ENTRIES];
+static int ltc2l_num_entries;
+
+static void
+ltc2l_append_cb(struct log *log, uint32_t idx)
+{
+ struct ltc2l_entry *entry;
+
+ TEST_ASSERT_FATAL(ltc2l_num_entries < LTC2L_MAX_ENTRIES);
+
+ entry = <c2l_entries[ltc2l_num_entries++];
+ entry->log = log;
+ entry->idx = idx;
+}
+
+TEST_CASE_SELF(log_test_case_2logs)
+{
+ int rc;
+ struct fcb_log fcb_log1;
+ struct log log1;
+ struct fcb_log fcb_log2;
+ struct log log2;
+
+ ltu_setup_2fcbs(&fcb_log1, &log1, &fcb_log2, &log2);
+
+ log_set_append_cb(&log1, ltc2l_append_cb);
+ log_set_append_cb(&log2, ltc2l_append_cb);
+
+ rc = log_append_body(&log1, 0, 0, LOG_ETYPE_STRING, "0", 1);
+ TEST_ASSERT(rc == 0);
+ rc = log_append_body(&log1, 0, 0, LOG_ETYPE_STRING, "1", 1);
+ TEST_ASSERT(rc == 0);
+ rc = log_append_body(&log2, 0, 0, LOG_ETYPE_STRING, "2", 1);
+ TEST_ASSERT(rc == 0);
+ rc = log_append_body(&log2, 0, 0, LOG_ETYPE_STRING, "3", 1);
+ TEST_ASSERT(rc == 0);
+ rc = log_append_body(&log1, 0, 0, LOG_ETYPE_STRING, "4", 1);
+ TEST_ASSERT(rc == 0);
+ TEST_ASSERT(ltc2l_num_entries == 5);
+ TEST_ASSERT(ltc2l_entries[0].log == &log1);
+ TEST_ASSERT(ltc2l_entries[1].log == &log1);
+ TEST_ASSERT(ltc2l_entries[2].log == &log2);
+ TEST_ASSERT(ltc2l_entries[3].log == &log2);
+ TEST_ASSERT(ltc2l_entries[4].log == &log1);
+#if MYNEWT_VAL(LOG_GLOBAL_IDX)
+ /* global index space */
+ TEST_ASSERT(ltc2l_entries[0].idx == 0);
+ TEST_ASSERT(ltc2l_entries[1].idx == 1);
+ TEST_ASSERT(ltc2l_entries[2].idx == 2);
+ TEST_ASSERT(ltc2l_entries[3].idx == 3);
+ TEST_ASSERT(ltc2l_entries[4].idx == 4);
+#else
+ /* per-log index */
+ TEST_ASSERT(ltc2l_entries[0].idx == 0);
+ TEST_ASSERT(ltc2l_entries[1].idx == 1);
+ TEST_ASSERT(ltc2l_entries[2].idx == 0);
+ TEST_ASSERT(ltc2l_entries[3].idx == 1);
+ TEST_ASSERT(ltc2l_entries[4].idx == 2);
+#endif
+}
diff --git a/sys/log/full/src/log.c b/sys/log/full/src/log.c
index b81430e..3b992e7 100644
--- a/sys/log/full/src/log.c
+++ b/sys/log/full/src/log.c
@@ -145,8 +145,9 @@ log_init(void)
STAILQ_INIT(&g_log_list);
g_log_info.li_version = MYNEWT_VAL(LOG_VERSION);
+#if MYNEWT_VAL(LOG_GLOBAL_IDX)
g_log_info.li_next_index = 0;
-
+#endif
#if MYNEWT_VAL(LOG_CLI)
shell_cmd_register(&g_shell_log_cmd);
#if MYNEWT_VAL(LOG_FCB_SLOT1)
@@ -392,6 +393,9 @@ log_register(char *name, struct log *log, const struct log_handler *lh,
log->l_level = level;
log->l_append_cb = NULL;
log->l_max_entry_len = 0;
+#if !MYNEWT_VAL(LOG_GLOBAL_IDX)
+ log->l_idx = 0;
+#endif
if (!log_registered(log)) {
STAILQ_INSERT_TAIL(&g_log_list, log, l_next);
@@ -420,9 +424,15 @@ log_register(char *name, struct log *log, const struct log_handler *lh,
rc = log_read_last_hdr(log, &hdr);
if (rc == 0) {
OS_ENTER_CRITICAL(sr);
+#if MYNEWT_VAL(LOG_GLOBAL_IDX)
if (hdr.ue_index >= g_log_info.li_next_index) {
g_log_info.li_next_index = hdr.ue_index + 1;
}
+#else
+ if (hdr.ue_index >= log->l_idx) {
+ log->l_idx = hdr.ue_index + 1;
+ }
+#endif
OS_EXIT_CRITICAL(sr);
}
}
@@ -531,7 +541,11 @@ log_append_prepare(struct log *log, uint8_t module, uint8_t level,
}
OS_ENTER_CRITICAL(sr);
+#if MYNEWT_VAL(LOG_GLOBAL_IDX)
idx = g_log_info.li_next_index++;
+#else
+ idx = log->l_idx++;
+#endif
OS_EXIT_CRITICAL(sr);
/* Try to get UTC Time */
@@ -674,7 +688,7 @@ log_append_mbuf_typed_no_free(struct log *log, uint8_t module, uint8_t level,
* We do a pull up twice, once so that the base header is
* contiguous, so that we read the flags correctly, second
* time is so that we account for the image hash as well.
- */
+ */
om = os_mbuf_pullup(om, LOG_BASE_ENTRY_HDR_SIZE);
if (!om) {
rc = -1;
@@ -954,7 +968,6 @@ log_read_body(struct log *log, const void *dptr, void *buf, uint16_t off,
}
return log_read(log, dptr, buf, log_hdr_len(&hdr) + off, len);
-
}
int
diff --git a/sys/log/full/src/log_fcb.c b/sys/log/full/src/log_fcb.c
index ed97a1b..c2ffcef 100644
--- a/sys/log/full/src/log_fcb.c
+++ b/sys/log/full/src/log_fcb.c
@@ -213,7 +213,8 @@ static int
log_fcb_append_body(struct log *log, const struct log_entry_hdr *hdr,
const void *body, int body_len)
{
- uint8_t buf[LOG_BASE_ENTRY_HDR_SIZE + LOG_IMG_HASHLEN + LOG_FCB_MAX_ALIGN - 1];
+ uint8_t buf[LOG_BASE_ENTRY_HDR_SIZE + LOG_IMG_HASHLEN +
+ LOG_FCB_MAX_ALIGN - 1];
struct fcb *fcb;
struct fcb_entry loc;
struct fcb_log *fcb_log;
@@ -346,7 +347,8 @@ log_fcb_append_mbuf_body(struct log *log, const struct log_entry_hdr *hdr,
return rc;
}
- rc = flash_area_write(loc.fe_area, loc.fe_data_off, hdr, LOG_BASE_ENTRY_HDR_SIZE);
+ rc = flash_area_write(loc.fe_area, loc.fe_data_off, hdr,
+ LOG_BASE_ENTRY_HDR_SIZE);
if (rc != 0) {
return rc;
}
@@ -355,7 +357,8 @@ log_fcb_append_mbuf_body(struct log *log, const struct log_entry_hdr *hdr,
#if MYNEWT_VAL(LOG_VERSION) > 2
if (hdr->ue_flags & LOG_FLAGS_IMG_HASH) {
/* Write LOG_IMG_HASHLEN bytes of image hash */
- rc = flash_area_write(loc.fe_area, loc.fe_data_off, hdr->ue_imghash, LOG_IMG_HASHLEN);
+ rc = flash_area_write(loc.fe_area, loc.fe_data_off, hdr->ue_imghash,
+ LOG_IMG_HASHLEN);
if (rc != 0) {
return rc;
}
@@ -644,8 +647,8 @@ log_fcb_storage_info(struct log *log, struct log_storage_info *info)
#if MYNEWT_VAL(LOG_STORAGE_WATERMARK)
static int
-log_fcb_new_watermark_index(struct log *log, struct log_offset *log_offset, const void *dptr,
- uint16_t len)
+log_fcb_new_watermark_index(struct log *log, struct log_offset *log_offset,
+ const void *dptr, uint16_t len)
{
struct fcb_entry *loc;
struct fcb_log *fl;
@@ -662,7 +665,8 @@ log_fcb_new_watermark_index(struct log *log, struct log_offset *log_offset, cons
}
/* Set log watermark to end of this element */
if (ueh.ue_index >= log_offset->lo_index) {
- fl->fl_watermark_off = loc->fe_area->fa_off + loc->fe_data_off + loc->fe_data_len;
+ fl->fl_watermark_off = loc->fe_area->fa_off + loc->fe_data_off +
+ loc->fe_data_len;
return 1;
} else {
return 0;
@@ -716,7 +720,8 @@ log_fcb_copy_entry(struct log *log, struct fcb_entry *entry,
struct fcb *dst_fcb)
{
struct log_entry_hdr ueh;
- char data[LOG_PRINTF_MAX_ENTRY_LEN + LOG_BASE_ENTRY_HDR_SIZE + LOG_IMG_HASHLEN];
+ char data[LOG_PRINTF_MAX_ENTRY_LEN + LOG_BASE_ENTRY_HDR_SIZE +
+ LOG_IMG_HASHLEN];
uint16_t hdr_len;
int dlen;
int rc;