Skip to content

Commit f9683b0

Browse files
committed
sys/log/full/selftest: Add unit tests for log fcb2 image hash and num_entries
1 parent ddce678 commit f9683b0

File tree

8 files changed

+190
-5
lines changed

8 files changed

+190
-5
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
pkg.name: sys/log/full/selftest/fcb2_align1_imghash
19+
pkg.type: unittest
20+
pkg.description: "Log unit tests; FCB2 flash-alignment=1."
21+
pkg.author: "Apache Mynewt <dev@mynewt.apache.org>"
22+
pkg.homepage: "http://mynewt.apache.org/"
23+
pkg.keywords:
24+
25+
pkg.deps:
26+
- "@apache-mynewt-core/sys/console/stub"
27+
- "@apache-mynewt-core/sys/log/full"
28+
- "@apache-mynewt-core/sys/log/full/selftest/util"
29+
- "@apache-mynewt-core/test/testutil"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#include "os/mynewt.h"
21+
#include "log_test_util/log_test_util.h"
22+
23+
int
24+
main(int argc, char **argv)
25+
{
26+
log_test_suite_cbmem_flat();
27+
log_test_suite_cbmem_mbuf();
28+
log_test_suite_fcb_flat();
29+
log_test_suite_fcb_mbuf();
30+
log_test_suite_misc();
31+
32+
return tu_any_failed;
33+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
19+
syscfg.vals:
20+
LOG_FCB2: 1
21+
MCU_FLASH_MIN_WRITE_SIZE: 1
22+
LOG_FLAGS_IMAGE_HASH: 1
23+
24+
# The mbuf append tests allocate lots of mbufs; ensure no exhaustion.
25+
MSYS_1_BLOCK_COUNT: 1000
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
pkg.name: sys/log/full/selftest/fcb2_align1_imghash_num_entries
19+
pkg.type: unittest
20+
pkg.description: "Log unit tests; FCB2 flash-alignment=1."
21+
pkg.author: "Apache Mynewt <dev@mynewt.apache.org>"
22+
pkg.homepage: "http://mynewt.apache.org/"
23+
pkg.keywords:
24+
25+
pkg.deps:
26+
- "@apache-mynewt-core/sys/console/stub"
27+
- "@apache-mynewt-core/sys/log/full"
28+
- "@apache-mynewt-core/sys/log/full/selftest/util"
29+
- "@apache-mynewt-core/test/testutil"
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
#include "os/mynewt.h"
21+
#include "log_test_util/log_test_util.h"
22+
23+
int
24+
main(int argc, char **argv)
25+
{
26+
log_test_suite_cbmem_flat();
27+
log_test_suite_cbmem_mbuf();
28+
log_test_suite_fcb_flat();
29+
log_test_suite_fcb_mbuf();
30+
log_test_suite_misc();
31+
32+
return tu_any_failed;
33+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
#
18+
19+
syscfg.vals:
20+
LOG_FCB2: 1
21+
MCU_FLASH_MIN_WRITE_SIZE: 1
22+
LOG_FLAGS_IMAGE_HASH: 1
23+
LOG_FLAGS_TLV_SUPPORT: 1
24+
LOG_TLV_NUM_ENTRIES: 1
25+
26+
# The mbuf append tests allocate lots of mbufs; ensure no exhaustion.
27+
MSYS_1_BLOCK_COUNT: 1000

sys/log/full/selftest/util/src/log_test_util.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ ltu_walk_verify(struct log *log, struct log_offset *log_offset,
190190
char data[128];
191191
int dlen;
192192
uint16_t hdr_len;
193+
uint16_t trailer_len;
193194

194195
TEST_ASSERT(ltu_str_idx < ltu_str_max_idx);
195196

@@ -199,7 +200,8 @@ ltu_walk_verify(struct log *log, struct log_offset *log_offset,
199200
TEST_ASSERT(rc == LOG_BASE_ENTRY_HDR_SIZE);
200201

201202
hdr_len = log_hdr_len(&ueh);
202-
dlen = len - hdr_len;
203+
trailer_len = log_trailer_len(&ueh);
204+
dlen = len - hdr_len - trailer_len;
203205
TEST_ASSERT(dlen < sizeof(data));
204206

205207
rc = log_read(log, dptr, data, hdr_len, dlen);
@@ -218,6 +220,12 @@ ltu_walk_verify(struct log *log, struct log_offset *log_offset,
218220
rc = log_read_body(log, dptr, data, 0, dlen);
219221
TEST_ASSERT(rc == dlen);
220222

223+
#if MYNEWT_VAL(LOG_FLAGS_TLV_SUPPORT) && MYNEWT_VAL(LOG_TLV_NUM_ENTRIES)
224+
struct log_tlv tlv;
225+
rc = log_read_trailer(log, dptr, LOG_TLV_NUM_ENTRIES, &tlv);
226+
TEST_ASSERT(rc == 0);
227+
#endif
228+
221229
TEST_ASSERT(strlen(ltu_str_logs[ltu_str_idx]) == dlen);
222230
TEST_ASSERT(!memcmp(ltu_str_logs[ltu_str_idx], data, dlen));
223231

@@ -263,6 +271,8 @@ ltu_walk_body_verify(struct log *log, struct log_offset *log_offset,
263271

264272
TEST_ASSERT(len < sizeof(data));
265273

274+
len -= log_trailer_len(euh);
275+
266276
rc = log_read_body(log, dptr, data, 0, len);
267277
TEST_ASSERT(rc == len);
268278

sys/log/full/src/log.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -604,12 +604,11 @@ log_trailer_len(const struct log_entry_hdr *hdr)
604604
uint16_t len = 0;
605605

606606
if (hdr->ue_flags & LOG_FLAGS_TLV_SUPPORT) {
607-
len += sizeof(struct log_tlv);
608-
}
609-
610607
#if MYNEWT_VAL(LOG_FLAGS_TLV_SUPPORT) && MYNEWT_VAL(LOG_TLV_NUM_ENTRIES)
611-
len += LOG_NUM_ENTRIES_SIZE;
608+
len += sizeof(struct log_tlv);
609+
len += LOG_NUM_ENTRIES_SIZE;
612610
#endif
611+
}
613612

614613
return len;
615614
}

0 commit comments

Comments
 (0)