Skip to content

Commit

Permalink
sys/log/full/selftest: Add unit tests for log fcb2 image hash and num…
Browse files Browse the repository at this point in the history
…_entries
  • Loading branch information
vrahane committed Jun 4, 2024
1 parent ddce678 commit f9683b0
Show file tree
Hide file tree
Showing 8 changed files with 190 additions and 5 deletions.
29 changes: 29 additions & 0 deletions sys/log/full/selftest/fcb2_align1_imghash/pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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_align1_imghash
pkg.type: unittest
pkg.description: "Log unit tests; FCB2 flash-alignment=1."
pkg.author: "Apache Mynewt <dev@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/test/testutil"
33 changes: 33 additions & 0 deletions sys/log/full/selftest/fcb2_align1_imghash/src/log_test_align1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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"

int
main(int argc, char **argv)
{
log_test_suite_cbmem_flat();
log_test_suite_cbmem_mbuf();
log_test_suite_fcb_flat();
log_test_suite_fcb_mbuf();
log_test_suite_misc();

return tu_any_failed;
}
25 changes: 25 additions & 0 deletions sys/log/full/selftest/fcb2_align1_imghash/syscfg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# 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_FCB2: 1
MCU_FLASH_MIN_WRITE_SIZE: 1
LOG_FLAGS_IMAGE_HASH: 1

# The mbuf append tests allocate lots of mbufs; ensure no exhaustion.
MSYS_1_BLOCK_COUNT: 1000
29 changes: 29 additions & 0 deletions sys/log/full/selftest/fcb2_align1_imghash_num_entries/pkg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# 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_align1_imghash_num_entries
pkg.type: unittest
pkg.description: "Log unit tests; FCB2 flash-alignment=1."
pkg.author: "Apache Mynewt <dev@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/test/testutil"
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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"

int
main(int argc, char **argv)
{
log_test_suite_cbmem_flat();
log_test_suite_cbmem_mbuf();
log_test_suite_fcb_flat();
log_test_suite_fcb_mbuf();
log_test_suite_misc();

return tu_any_failed;
}
27 changes: 27 additions & 0 deletions sys/log/full/selftest/fcb2_align1_imghash_num_entries/syscfg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# 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_FCB2: 1
MCU_FLASH_MIN_WRITE_SIZE: 1
LOG_FLAGS_IMAGE_HASH: 1
LOG_FLAGS_TLV_SUPPORT: 1
LOG_TLV_NUM_ENTRIES: 1

# The mbuf append tests allocate lots of mbufs; ensure no exhaustion.
MSYS_1_BLOCK_COUNT: 1000
12 changes: 11 additions & 1 deletion sys/log/full/selftest/util/src/log_test_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ ltu_walk_verify(struct log *log, struct log_offset *log_offset,
char data[128];
int dlen;
uint16_t hdr_len;
uint16_t trailer_len;

TEST_ASSERT(ltu_str_idx < ltu_str_max_idx);

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

hdr_len = log_hdr_len(&ueh);
dlen = len - hdr_len;
trailer_len = log_trailer_len(&ueh);
dlen = len - hdr_len - trailer_len;
TEST_ASSERT(dlen < sizeof(data));

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

#if MYNEWT_VAL(LOG_FLAGS_TLV_SUPPORT) && MYNEWT_VAL(LOG_TLV_NUM_ENTRIES)
struct log_tlv tlv;
rc = log_read_trailer(log, dptr, LOG_TLV_NUM_ENTRIES, &tlv);
TEST_ASSERT(rc == 0);
#endif

TEST_ASSERT(strlen(ltu_str_logs[ltu_str_idx]) == dlen);
TEST_ASSERT(!memcmp(ltu_str_logs[ltu_str_idx], data, dlen));

Expand Down Expand Up @@ -263,6 +271,8 @@ ltu_walk_body_verify(struct log *log, struct log_offset *log_offset,

TEST_ASSERT(len < sizeof(data));

len -= log_trailer_len(euh);

rc = log_read_body(log, dptr, data, 0, len);
TEST_ASSERT(rc == len);

Expand Down
7 changes: 3 additions & 4 deletions sys/log/full/src/log.c
Original file line number Diff line number Diff line change
Expand Up @@ -604,12 +604,11 @@ log_trailer_len(const struct log_entry_hdr *hdr)
uint16_t len = 0;

if (hdr->ue_flags & LOG_FLAGS_TLV_SUPPORT) {
len += sizeof(struct log_tlv);
}

#if MYNEWT_VAL(LOG_FLAGS_TLV_SUPPORT) && MYNEWT_VAL(LOG_TLV_NUM_ENTRIES)
len += LOG_NUM_ENTRIES_SIZE;
len += sizeof(struct log_tlv);
len += LOG_NUM_ENTRIES_SIZE;
#endif
}

return len;
}
Expand Down

0 comments on commit f9683b0

Please sign in to comment.