This is an automated email from the ASF dual-hosted git repository. marko pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mynewt-core.git
commit 22f5f1a6ffa3f0f1a02da218d25ab532a69b01c3 Author: Marko Kiiskila <ma...@apache.org> AuthorDate: Thu Aug 29 12:55:02 2019 +0300 sys/log; enable bookmarks with FCB2. --- sys/log/full/pkg.yml | 3 ++ sys/log/full/selftest/fcb2_bookmarks/pkg.yml | 30 +++++++++++++++ .../fcb2_bookmarks/src/log_test_fcb_bookmarks.c | 39 +++++++++++++++++++ .../fcb2_bookmarks/src/log_test_fcb_bookmarks.h | 44 ++++++++++++++++++++++ .../src/log_test_fcb_bookmarks_util.c | 43 ++++++++------------- .../fcb2_bookmarks/src/testcases/s0_l1_b0_p100.c | 32 ++++++++++++++++ .../fcb2_bookmarks/src/testcases/s0_l1_b1_p100.c | 32 ++++++++++++++++ .../src/testcases/s100_l500_b10_p2000.c | 32 ++++++++++++++++ .../src/testcases/s10_l100_b10_p2000.c | 32 ++++++++++++++++ .../src/testcases/s10_l100_b1_p200.c | 32 ++++++++++++++++ sys/log/full/selftest/fcb2_bookmarks/syscfg.yml | 23 +++++++++++ .../src/log_test_fcb_bookmarks_util.c | 2 +- sys/log/full/src/log_fcb2.c | 7 +++- sys/log/full/syscfg.yml | 2 +- 14 files changed, 323 insertions(+), 30 deletions(-) diff --git a/sys/log/full/pkg.yml b/sys/log/full/pkg.yml index 5c4ecde..4e618cb 100644 --- a/sys/log/full/pkg.yml +++ b/sys/log/full/pkg.yml @@ -52,6 +52,9 @@ pkg.deps.LOG_STORAGE_WATERMARK: pkg.apis: - log +pkg.req_apis.LOG_STATS: + - stats + pkg.init: log_init: 'MYNEWT_VAL(LOG_SYSINIT_STAGE_MAIN)' diff --git a/sys/log/full/selftest/fcb2_bookmarks/pkg.yml b/sys/log/full/selftest/fcb2_bookmarks/pkg.yml new file mode 100644 index 0000000..7b9a2f0 --- /dev/null +++ b/sys/log/full/selftest/fcb2_bookmarks/pkg.yml @@ -0,0 +1,30 @@ +# 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. +# +pkg.name: sys/log/full/selftest/fcb2_bookmarks +pkg.type: unittest +pkg.description: "Log unit tests; bookmarks with FCB2." +pkg.author: "Apache Mynewt <d...@mynewt.apache.org>" +pkg.homepage: "http://mynewt.apache.org/" +pkg.keywords: + +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/sys/stats/full" + - "@apache-mynewt-core/test/testutil" diff --git a/sys/log/full/selftest/fcb2_bookmarks/src/log_test_fcb_bookmarks.c b/sys/log/full/selftest/fcb2_bookmarks/src/log_test_fcb_bookmarks.c new file mode 100644 index 0000000..85b8391 --- /dev/null +++ b/sys/log/full/selftest/fcb2_bookmarks/src/log_test_fcb_bookmarks.c @@ -0,0 +1,39 @@ +/* + * 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 "os/mynewt.h" +#include "log_test_util/log_test_util.h" +#include "log_test_fcb_bookmarks.h" + +TEST_SUITE(log_test_suite_fcb_bookmarks) +{ + log_test_case_fcb_bookmarks_s0_l1_b0_p100(); + log_test_case_fcb_bookmarks_s0_l1_b1_p100(); + log_test_case_fcb_bookmarks_s10_l100_b1_p200(); + log_test_case_fcb_bookmarks_s10_l100_b10_p2000(); + log_test_case_fcb_bookmarks_s100_l500_b10_p2000(); +} + +int +main(int argc, char **argv) +{ + log_test_suite_fcb_bookmarks(); + + return tu_any_failed; +} diff --git a/sys/log/full/selftest/fcb2_bookmarks/src/log_test_fcb_bookmarks.h b/sys/log/full/selftest/fcb2_bookmarks/src/log_test_fcb_bookmarks.h new file mode 100644 index 0000000..e7d58f5 --- /dev/null +++ b/sys/log/full/selftest/fcb2_bookmarks/src/log_test_fcb_bookmarks.h @@ -0,0 +1,44 @@ +/* + * 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. + */ + +#ifndef H_LOG_TEST_FCB_BOOKMARKS_ +#define H_LOG_TEST_FCB_BOOKMARKS_ + +#include "os/mynewt.h" +#include "testutil/testutil.h" + +struct ltfbu_cfg { + int skip_mod; + int body_len; + int bmark_count; + int pop_count; +}; + +void ltfbu_populate_log(int count); +void ltfbu_verify_log(uint32_t start_idx); +void ltfbu_init(const struct ltfbu_cfg *cfg); +void ltfbu_test_once(const struct ltfbu_cfg *cfg); + +TEST_CASE_DECL(log_test_case_fcb_bookmarks_s0_l1_b0_p100); +TEST_CASE_DECL(log_test_case_fcb_bookmarks_s0_l1_b1_p100); +TEST_CASE_DECL(log_test_case_fcb_bookmarks_s10_l100_b1_p200); +TEST_CASE_DECL(log_test_case_fcb_bookmarks_s10_l100_b10_p2000); +TEST_CASE_DECL(log_test_case_fcb_bookmarks_s100_l500_b10_p2000); + +#endif diff --git a/sys/log/full/selftest/fcb_bookmarks/src/log_test_fcb_bookmarks_util.c b/sys/log/full/selftest/fcb2_bookmarks/src/log_test_fcb_bookmarks_util.c similarity index 87% copy from sys/log/full/selftest/fcb_bookmarks/src/log_test_fcb_bookmarks_util.c copy to sys/log/full/selftest/fcb2_bookmarks/src/log_test_fcb_bookmarks_util.c index 25a8b36..76421ba 100644 --- a/sys/log/full/selftest/fcb_bookmarks/src/log_test_fcb_bookmarks_util.c +++ b/sys/log/full/selftest/fcb2_bookmarks/src/log_test_fcb_bookmarks_util.c @@ -40,15 +40,14 @@ static struct log ltfbu_log; static struct fcb_log_bmark ltfbu_bmarks[LTFBU_MAX_BMARKS]; -static struct flash_area ltfbu_fcb_areas[] = { - [0] = { +static struct flash_sector_range ltfbu_fcb_range = { + .fsr_flash_area = { .fa_off = 0 * LTFBU_SECTOR_SIZE, - .fa_size = LTFBU_SECTOR_SIZE, + .fa_size = 2 * LTFBU_SECTOR_SIZE }, - [1] = { - .fa_off = 1 * LTFBU_SECTOR_SIZE, - .fa_size = LTFBU_SECTOR_SIZE, - } + .fsr_sector_count = 2, + .fsr_sector_size = LTFBU_SECTOR_SIZE, + .fsr_align = MYNEWT_VAL(MCU_FLASH_MIN_WRITE_SIZE) }; static int @@ -56,19 +55,10 @@ ltfbu_max_entries(void) { int entry_space; int entry_size; - int len_size; - int crc_size; - if (ltfbu_cfg.body_len > 127) { - len_size = 2; - } else { - len_size = 1; - } - crc_size = 1; - - /* "+ 1" for CRC. */ + /* "+ 2" for CRC. */ entry_size = LOG_BASE_ENTRY_HDR_SIZE + ltfbu_cfg.body_len + - len_size + crc_size; + FCB_ENTRY_SIZE + 2; entry_space = LTFBU_SECTOR_SIZE - 8; return entry_space / entry_size; @@ -99,7 +89,7 @@ ltfbu_expected_idxs(uint32_t start_idx) first++; count--; } - + return (struct ltfbu_slice) { .idxs = <fbu_entry_idxs[first], .count = count, @@ -206,7 +196,6 @@ void ltfbu_init(const struct ltfbu_cfg *cfg) { int rc; - int i; /* Ensure tests are repeatable. */ srand(0); @@ -216,17 +205,17 @@ ltfbu_init(const struct ltfbu_cfg *cfg) ltfbu_fcb_log = (struct fcb_log) { .fl_fcb.f_scratch_cnt = 1, - .fl_fcb.f_sectors = ltfbu_fcb_areas, - .fl_fcb.f_sector_cnt = sizeof(ltfbu_fcb_areas) / sizeof(ltfbu_fcb_areas[0]), + .fl_fcb.f_range_cnt = 1, + .fl_fcb.f_sector_cnt = ltfbu_fcb_range.fsr_sector_count, + .fl_fcb.f_ranges = <fbu_fcb_range, .fl_fcb.f_magic = 0x7EADBADF, .fl_fcb.f_version = 0, }; - for (i = 0; i < ltfbu_fcb_log.fl_fcb.f_sector_cnt; i++) { - rc = flash_area_erase(<fbu_fcb_areas[i], 0, - ltfbu_fcb_areas[i].fa_size); - TEST_ASSERT_FATAL(rc == 0); - } + rc = flash_area_erase(<fbu_fcb_range.fsr_flash_area, 0, + ltfbu_fcb_range.fsr_flash_area.fa_size); + TEST_ASSERT_FATAL(rc == 0); + rc = fcb_init(<fbu_fcb_log.fl_fcb); TEST_ASSERT_FATAL(rc == 0); diff --git a/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s0_l1_b0_p100.c b/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s0_l1_b0_p100.c new file mode 100644 index 0000000..d211264 --- /dev/null +++ b/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s0_l1_b0_p100.c @@ -0,0 +1,32 @@ +/* + * 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" +#include "log_test_fcb_bookmarks.h" + +TEST_CASE_SELF(log_test_case_fcb_bookmarks_s0_l1_b0_p100) +{ + struct ltfbu_cfg cfg = { + .skip_mod = 0, + .body_len = 10, + .bmark_count = 0, + .pop_count = 100, + }; + ltfbu_test_once(&cfg); +} diff --git a/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s0_l1_b1_p100.c b/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s0_l1_b1_p100.c new file mode 100644 index 0000000..ee7718b --- /dev/null +++ b/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s0_l1_b1_p100.c @@ -0,0 +1,32 @@ +/* + * 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" +#include "log_test_fcb_bookmarks.h" + +TEST_CASE_SELF(log_test_case_fcb_bookmarks_s0_l1_b1_p100) +{ + struct ltfbu_cfg cfg = { + .skip_mod = 0, + .body_len = 10, + .bmark_count = 1, + .pop_count = 100, + }; + ltfbu_test_once(&cfg); +} diff --git a/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s100_l500_b10_p2000.c b/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s100_l500_b10_p2000.c new file mode 100644 index 0000000..e86964c --- /dev/null +++ b/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s100_l500_b10_p2000.c @@ -0,0 +1,32 @@ +/* + * 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" +#include "log_test_fcb_bookmarks.h" + +TEST_CASE_SELF(log_test_case_fcb_bookmarks_s100_l500_b10_p2000) +{ + struct ltfbu_cfg cfg = { + .skip_mod = 100, + .body_len = 500, + .bmark_count = 10, + .pop_count = 2000, + }; + ltfbu_test_once(&cfg); +} diff --git a/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s10_l100_b10_p2000.c b/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s10_l100_b10_p2000.c new file mode 100644 index 0000000..ac48042 --- /dev/null +++ b/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s10_l100_b10_p2000.c @@ -0,0 +1,32 @@ +/* + * 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" +#include "log_test_fcb_bookmarks.h" + +TEST_CASE_SELF(log_test_case_fcb_bookmarks_s10_l100_b10_p2000) +{ + struct ltfbu_cfg cfg = { + .skip_mod = 10, + .body_len = 100, + .bmark_count = 10, + .pop_count = 2000, + }; + ltfbu_test_once(&cfg); +} diff --git a/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s10_l100_b1_p200.c b/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s10_l100_b1_p200.c new file mode 100644 index 0000000..ac81aef --- /dev/null +++ b/sys/log/full/selftest/fcb2_bookmarks/src/testcases/s10_l100_b1_p200.c @@ -0,0 +1,32 @@ +/* + * 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" +#include "log_test_fcb_bookmarks.h" + +TEST_CASE_SELF(log_test_case_fcb_bookmarks_s10_l100_b1_p200) +{ + struct ltfbu_cfg cfg = { + .skip_mod = 10, + .body_len = 100, + .bmark_count = 1, + .pop_count = 200, + }; + ltfbu_test_once(&cfg); +} diff --git a/sys/log/full/selftest/fcb2_bookmarks/syscfg.yml b/sys/log/full/selftest/fcb2_bookmarks/syscfg.yml new file mode 100644 index 0000000..fda1a78 --- /dev/null +++ b/sys/log/full/selftest/fcb2_bookmarks/syscfg.yml @@ -0,0 +1,23 @@ +# 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. +# + +syscfg.vals: + LOG_VERSION: 3 + LOG_FCB2: 1 + LOG_FCB_BOOKMARKS: 1 + LOG_STATS: 1 diff --git a/sys/log/full/selftest/fcb_bookmarks/src/log_test_fcb_bookmarks_util.c b/sys/log/full/selftest/fcb_bookmarks/src/log_test_fcb_bookmarks_util.c index 25a8b36..dca71d1 100644 --- a/sys/log/full/selftest/fcb_bookmarks/src/log_test_fcb_bookmarks_util.c +++ b/sys/log/full/selftest/fcb_bookmarks/src/log_test_fcb_bookmarks_util.c @@ -99,7 +99,7 @@ ltfbu_expected_idxs(uint32_t start_idx) first++; count--; } - + return (struct ltfbu_slice) { .idxs = <fbu_entry_idxs[first], .count = count, diff --git a/sys/log/full/src/log_fcb2.c b/sys/log/full/src/log_fcb2.c index 9e5c4d1..38b0619 100644 --- a/sys/log/full/src/log_fcb2.c +++ b/sys/log/full/src/log_fcb2.c @@ -24,8 +24,8 @@ #include <string.h> #include "flash_map/flash_map.h" -#include "fcb/fcb.h" #include "log/log.h" +#include "fcb/fcb.h" /* Assume the flash alignment requirement is no stricter than 8. */ #define LOG_FCB2_MAX_ALIGN 8 @@ -164,7 +164,12 @@ log_fcb2_start_append(struct log *log, int len, struct fcb_entry *loc) #endif #if MYNEWT_VAL(LOG_STATS) +#if MYNEWT_VAL(LOG_FCB) rc = fcb_area_info(fcb, NULL, &cnt, NULL); +#endif +#if MYNEWT_VAL(LOG_FCB2) + rc = fcb_area_info(fcb, FCB_SECTOR_OLDEST, &cnt, NULL); +#endif if (rc == 0) { LOG_STATS_INCN(log, lost, cnt); } diff --git a/sys/log/full/syscfg.yml b/sys/log/full/syscfg.yml index b49ccd8..5e8982b 100644 --- a/sys/log/full/syscfg.yml +++ b/sys/log/full/syscfg.yml @@ -68,7 +68,7 @@ syscfg.defs: bookmark storage at runtime. value: 0 restrictions: - - LOG_FCB + - (LOG_FCB || LOG_FCB2) LOG_CONSOLE: description: 'Support logging to console.'