Skip to content

Commit

Permalink
sys/log: Reverse TLV implementation for number of entries support
Browse files Browse the repository at this point in the history
  • Loading branch information
vrahane committed Jul 31, 2024
1 parent 2c38d9e commit a7a659b
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
14 changes: 8 additions & 6 deletions sys/log/full/selftest/util/src/log_test_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ static int ltu_str_max_idx = 0;

struct dummy_log {
struct log_entry_hdr hdr;
struct log_tlv tlv;
uint32_t num_entries;
struct log_tlv tlv;
};

struct dummy_log dummy_log = {
Expand All @@ -71,11 +71,11 @@ struct dummy_log dummy_log = {
.ue_level = 3,
.ue_num_entries = 5
},
.num_entries = 0,
.tlv = {
.tag = LOG_TLV_NUM_ENTRIES,
.len = LOG_NUM_ENTRIES_SIZE
},
.num_entries = 0,
};

char *ltu_str_logs[] = {
Expand Down Expand Up @@ -126,11 +126,13 @@ ltu_init_arr(void)
#endif
memcpy(dummy_log_arr + offset, ltu_str_logs[i], strlen(ltu_str_logs[i]));
offset += strlen(ltu_str_logs[i]);
#if MYNEWT_VAL(LOG_FLAGS_TLV_SUPPORT) && MYNEWT_VAL(LOG_TLV_NUM_ENTRIES)
memcpy(dummy_log_arr + offset, &dummy_log.tlv, sizeof(struct log_tlv));
offset += sizeof(struct log_tlv);
#if MYNEWT_VAL(LOG_FLAGS_TLV_SUPPORT)
#if MYNEWT_VAL(LOG_TLV_NUM_ENTRIES)
memcpy(dummy_log_arr + offset, &dummy_log.num_entries, LOG_NUM_ENTRIES_SIZE);
offset += LOG_NUM_ENTRIES_SIZE;
memcpy(dummy_log_arr + offset, &dummy_log.tlv, sizeof(struct log_tlv));
offset += sizeof(struct log_tlv);
#endif
#endif
}
ltu_off_arr[i] = offset;
Expand Down Expand Up @@ -300,7 +302,7 @@ ltu_walk_verify(struct log *log, struct log_offset *log_offset,
TEST_ASSERT(rc == dlen);

#if MYNEWT_VAL(LOG_FLAGS_TLV_SUPPORT) && MYNEWT_VAL(LOG_TLV_NUM_ENTRIES)
uint32_t num_entries;;
uint32_t num_entries;
rc = log_read_trailer(log, dptr, LOG_TLV_NUM_ENTRIES, &num_entries);
TEST_ASSERT(rc == 0);
#endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ TEST_CASE_SELF(log_test_case_cbmem_append_mbuf)
uint16_t *off_arr;
int i;
int rc;
struct log_entry_hdr *hdr;
int num_strs = ltu_num_strs();

ltu_setup_cbmem(&cbmem, &log);
Expand All @@ -38,7 +39,8 @@ TEST_CASE_SELF(log_test_case_cbmem_append_mbuf)
TEST_ASSERT_FATAL(off_arr != NULL);

for (i = 0; i < num_strs; i++) {
len = off_arr[i+1] - off_arr[i];
hdr = (struct log_entry_hdr *)(dummy_log_arr + off_arr[i]);
len = off_arr[i+1] - off_arr[i] - log_trailer_len(&log, hdr);
/* Split chain into several mbufs. */
om = ltu_flat_to_fragged_mbuf(dummy_log_arr + off_arr[i],
len, 2);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ TEST_CASE_SELF(log_test_case_cbmem_append_mbuf_body)
for (i = 0; i < num_strs; i++) {
hdr = (struct log_entry_hdr *)(dummy_log_arr + off_arr[i]);
len = off_arr[i + 1] - off_arr[i] -
log_hdr_len(hdr);
log_hdr_len(hdr) - log_trailer_len(&log, hdr);

/* Split chain into several mbufs. */
om = ltu_flat_to_fragged_mbuf(dummy_log_arr + off_arr[i] + log_hdr_len(hdr),
Expand Down
13 changes: 6 additions & 7 deletions sys/log/full/src/log_cbmem.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ log_cbmem_append_body(struct log *log, const struct log_entry_hdr *hdr,
{
int rc = 0;
struct cbmem *cbmem;
uint16_t num_tlvs = 0;
uint8_t num_tlvs = 0;
struct cbmem_scat_gath sg = {
.entries = (struct cbmem_scat_gath_entry[]) {
{
Expand Down Expand Up @@ -79,7 +79,7 @@ log_cbmem_append_body(struct log *log, const struct log_entry_hdr *hdr,
#endif
#if MYNEWT_VAL(LOG_TLV_NUM_TLVS)
/* Number of TLVs is only written if there are more than one TLVs */
if (num_tlvs > 0) {
if (num_tlvs > 1) {
sg.entries[6].flat_buf = &(struct log_tlv) {LOG_NUM_TLVS_SIZE, LOG_TLV_NUM_TLVS};
sg.entries[6].flat_len = sizeof(struct log_tlv);
sg.entries[5].flat_len = LOG_NUM_TLVS_SIZE;
Expand Down Expand Up @@ -115,7 +115,7 @@ log_cbmem_append_mbuf_body(struct log *log, const struct log_entry_hdr *hdr,
{
int rc = 0;
struct cbmem *cbmem;
uint16_t num_tlvs = 0;
uint8_t num_tlvs = 0;
struct cbmem_scat_gath sg = {
.entries = (struct cbmem_scat_gath_entry[]) {
{
Expand Down Expand Up @@ -166,7 +166,7 @@ log_cbmem_append_mbuf_body(struct log *log, const struct log_entry_hdr *hdr,
#endif
#if MYNEWT_VAL(LOG_TLV_NUM_TLVS)
/* Number of TLVs is only written if there are more than one TLVs */
if (num_tlvs > 0) {
if (num_tlvs > 1) {
sg.entries[6].flat_buf = &(struct log_tlv) {LOG_NUM_TLVS_SIZE, LOG_TLV_NUM_TLVS};
sg.entries[6].flat_len = sizeof(struct log_tlv);
sg.entries[5].flat_len = LOG_NUM_TLVS_SIZE;
Expand Down Expand Up @@ -204,7 +204,7 @@ log_cbmem_append_mbuf(struct log *log, struct os_mbuf *om)
* time is so that we account for the image hash as well.
*/

os_mbuf_pullup(om, LOG_BASE_ENTRY_HDR_SIZE);
om = os_mbuf_pullup(om, LOG_BASE_ENTRY_HDR_SIZE);

/*
* We can just pass the om->om_data ptr as the log_entry_hdr
Expand All @@ -213,10 +213,9 @@ log_cbmem_append_mbuf(struct log *log, struct os_mbuf *om)
*/
hdr_len = log_hdr_len((struct log_entry_hdr *)om->om_data);

os_mbuf_pullup(om, hdr_len);
om = os_mbuf_pullup(om, hdr_len);

memcpy(&hdr, om->om_data, hdr_len);

os_mbuf_adj(om, hdr_len);

rc = log_cbmem_append_mbuf_body(log, &hdr, om);
Expand Down

0 comments on commit a7a659b

Please sign in to comment.