Skip to content

Commit

Permalink
[nrf fromlist] tests: mgmt: Adapt to API changes in zcbor 0.8.0
Browse files Browse the repository at this point in the history
zcbor_new_state and zcbor_tstr_put_term

Signed-off-by: Øyvind Rønningstad <[email protected]>
  • Loading branch information
oyvindronningstad committed Jan 18, 2024
1 parent 2aefab6 commit c970356
Show file tree
Hide file tree
Showing 16 changed files with 97 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ bool create_mcumgr_format_packet(zcbor_state_t *zse, uint8_t *buffer, uint8_t *o

ok = zcbor_map_start_encode(zse, 2) &&
zcbor_tstr_put_lit(zse, "d") &&
zcbor_tstr_put_term(zse, "some test data") &&
zcbor_tstr_put_lit(zse, "some test data") &&
zcbor_map_end_encode(zse, 2);

*buffer_size = (zse->payload_mut - buffer);
Expand Down
2 changes: 1 addition & 1 deletion tests/subsys/mgmt/mcumgr/fs_mgmt_hash_supported/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ ZTEST(fs_mgmt_hash_supported, test_supported)

/* Search expected type array for this type and update details */
zcbor_new_decode_state(state, 10, &nb->data[sizeof(struct smp_hdr)],
(nb->len - sizeof(struct smp_hdr)), 1);
(nb->len - sizeof(struct smp_hdr)), 1, NULL, 0);

ok = zcbor_map_start_decode(state);

Expand Down
11 changes: 7 additions & 4 deletions tests/subsys/mgmt/mcumgr/mcumgr_client/src/img_gr_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,10 @@ void img_read_response(int count)
zcbor_tstr_put_lit(zse, "slot") &&
zcbor_uint32_put(zse, image_dummy_info[i].slot_num) &&
zcbor_tstr_put_lit(zse, "version") &&
zcbor_tstr_put_term(zse, image_dummy_info[i].version) &&
zcbor_tstr_put_term(zse, image_dummy_info[i].version,
sizeof(image_dummy_info[i].version)) &&

zcbor_tstr_put_term(zse, "hash") &&
zcbor_tstr_put_lit(zse, "hash") &&
zcbor_bstr_encode_ptr(zse, image_dummy_info[i].hash, IMG_MGMT_DATA_SHA_LEN) &&
ZCBOR_ENCODE_FLAG(zse, "bootable", image_dummy_info[i].flags.bootable) &&
ZCBOR_ENCODE_FLAG(zse, "pending", image_dummy_info[i].flags.pending) &&
Expand Down Expand Up @@ -180,7 +181,8 @@ void img_state_write_verify(struct net_buf *nb)
ZCBOR_MAP_DECODE_KEY_DECODER("hash", zcbor_bstr_decode, &hash)
};

zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data + sizeof(struct smp_hdr), nb->len, 1);
zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data + sizeof(struct smp_hdr), nb->len, 1,
NULL, 0);

decoded = 0;
/* Init buffer values */
Expand Down Expand Up @@ -231,7 +233,8 @@ void img_upload_init_verify(struct net_buf *nb)
ZCBOR_MAP_DECODE_KEY_DECODER("sha", zcbor_bstr_decode, &sha)
};

zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data + sizeof(struct smp_hdr), nb->len, 1);
zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data + sizeof(struct smp_hdr), nb->len, 1,
NULL, 0);

decoded = 0;
/* Init buffer values */
Expand Down
4 changes: 2 additions & 2 deletions tests/subsys/mgmt/mcumgr/mcumgr_client/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,12 +225,12 @@ ZTEST(mcumgr_client, test_os_echo)
smp_stub_set_rx_data_verify(NULL);
smp_client_send_status_stub(MGMT_ERR_EOK);
/* Test timeout */
rc = os_mgmt_client_echo(&os_client, os_echo_test);
rc = os_mgmt_client_echo(&os_client, os_echo_test, sizeof(os_echo_test));
zassert_equal(MGMT_ERR_ETIMEOUT, rc, "Expected to receive %d response %d",
MGMT_ERR_ETIMEOUT, rc);
/* Test successfully operation */
smp_stub_set_rx_data_verify(os_echo_verify);
rc = os_mgmt_client_echo(&os_client, os_echo_test);
rc = os_mgmt_client_echo(&os_client, os_echo_test, sizeof(os_echo_test));
zassert_equal(MGMT_ERR_EOK, rc, "Expected to receive %d response %d", MGMT_ERR_EOK, rc);
}

Expand Down
3 changes: 2 additions & 1 deletion tests/subsys/mgmt/mcumgr/mcumgr_client/src/os_gr_stub.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ void os_echo_verify(struct net_buf *nb)
ZCBOR_MAP_DECODE_KEY_DECODER("d", zcbor_tstr_decode, &echo_data)
};

zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data + sizeof(struct smp_hdr), nb->len, 1);
zcbor_new_decode_state(zsd, ARRAY_SIZE(zsd), nb->data + sizeof(struct smp_hdr), nb->len, 1,
NULL, 0);
echo_data.len = 0;

rc = zcbor_map_decode_bulk(zsd, list_res_decode, ARRAY_SIZE(list_res_decode), &decoded);
Expand Down
44 changes: 22 additions & 22 deletions tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_get_not_set_v1)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
zassert_true(ok, "Expected decode to be successful");
Expand Down Expand Up @@ -253,7 +253,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_get_not_set_v2)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
zassert_true(ok, "Expected decode to be successful");
Expand Down Expand Up @@ -318,7 +318,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v1_1)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
zassert_true(ok, "Expected decode to be successful");
Expand Down Expand Up @@ -365,7 +365,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v1_1)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
zassert_true(ok, "Expected decode to be successful");
Expand Down Expand Up @@ -428,7 +428,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v1_2)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
zassert_true(ok, "Expected decode to be successful");
Expand Down Expand Up @@ -475,7 +475,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v1_2)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
zassert_true(ok, "Expected decode to be successful");
Expand Down Expand Up @@ -538,7 +538,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v1_3)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
zassert_true(ok, "Expected decode to be successful");
Expand Down Expand Up @@ -585,7 +585,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v1_3)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
zassert_true(ok, "Expected decode to be successful");
Expand Down Expand Up @@ -648,7 +648,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v2_1)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
zassert_true(ok, "Expected decode to be successful");
Expand Down Expand Up @@ -695,7 +695,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v2_1)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
zassert_true(ok, "Expected decode to be successful");
Expand Down Expand Up @@ -760,7 +760,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v2_2)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
zassert_true(ok, "Expected decode to be successful");
Expand Down Expand Up @@ -807,7 +807,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v2_2)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
zassert_true(ok, "Expected decode to be successful");
Expand Down Expand Up @@ -872,7 +872,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v2_3)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
zassert_true(ok, "Expected decode to be successful");
Expand Down Expand Up @@ -919,7 +919,7 @@ ZTEST(os_mgmt_datetime_not_set, test_datetime_set_invalid_v2_3)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
zassert_true(ok, "Expected decode to be successful");
Expand Down Expand Up @@ -984,7 +984,7 @@ ZTEST(os_mgmt_datetime_set, test_datetime_set_v1)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
zassert_true(ok, "Expected decode to be successful");
Expand Down Expand Up @@ -1030,7 +1030,7 @@ ZTEST(os_mgmt_datetime_set, test_datetime_set_v1)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
zassert_true(ok, "Expected decode to be successful");
Expand Down Expand Up @@ -1098,7 +1098,7 @@ ZTEST(os_mgmt_datetime_set, test_datetime_set_v2)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
zassert_true(ok, "Expected decode to be successful");
Expand Down Expand Up @@ -1144,7 +1144,7 @@ ZTEST(os_mgmt_datetime_set, test_datetime_set_v2)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
zassert_true(ok, "Expected decode to be successful");
Expand Down Expand Up @@ -1225,7 +1225,7 @@ ZTEST(os_mgmt_datetime_hook, test_datetime_set_valid_hook_v1)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
zassert_true(ok, "Expected decode to be successful");
Expand Down Expand Up @@ -1287,7 +1287,7 @@ ZTEST(os_mgmt_datetime_hook, test_datetime_set_valid_hook_v1)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
zassert_true(ok, "Expected decode to be successful");
Expand Down Expand Up @@ -1357,7 +1357,7 @@ ZTEST(os_mgmt_datetime_hook, test_datetime_set_valid_hook_v2)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
zassert_true(ok, "Expected decode to be successful");
Expand Down Expand Up @@ -1418,7 +1418,7 @@ ZTEST(os_mgmt_datetime_hook, test_datetime_set_valid_hook_v2)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 4, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;
zassert_true(ok, "Expected decode to be successful");
Expand Down
6 changes: 3 additions & 3 deletions tests/subsys/mgmt/mcumgr/os_mgmt_datetime/src/smp_test_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ bool create_mcumgr_datetime_set_packet_str(zcbor_state_t *zse, bool version2, co
uint8_t *buffer, uint8_t *output_buffer,
uint16_t *buffer_size)
{
bool ok = zcbor_map_start_encode(zse, 2) &&
zcbor_tstr_put_lit(zse, "datetime") &&
zcbor_tstr_put_term(zse, data) &&
bool ok = zcbor_map_start_encode(zse, 2) &&
zcbor_tstr_put_lit(zse, "datetime") &&
zcbor_tstr_put_term(zse, data, CONFIG_ZCBOR_MAX_STR_LEN) &&
zcbor_map_end_encode(zse, 2);

*buffer_size = (zse->payload_mut - buffer);
Expand Down
4 changes: 2 additions & 2 deletions tests/subsys/mgmt/mcumgr/os_mgmt_info/src/build_date.c
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ ZTEST(os_mgmt_info_build_date, test_info_build_date_1_build_date)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;

Expand Down Expand Up @@ -197,7 +197,7 @@ ZTEST(os_mgmt_info_build_date, test_info_build_date_2_all)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;

Expand Down
6 changes: 3 additions & 3 deletions tests/subsys/mgmt/mcumgr/os_mgmt_info/src/limited.c
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ ZTEST(os_mgmt_info_limited, test_info_1_kernel_name)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0);

ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;

Expand Down Expand Up @@ -147,15 +147,15 @@ ZTEST(os_mgmt_info_limited, test_info_2_all)

/* Process received data by removing header */
(void)net_buf_pull(nb, sizeof(struct smp_hdr));
zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0);

/* Ensure only an error is received */
ok = zcbor_map_decode_bulk(zsd, output_decode, ARRAY_SIZE(output_decode), &decoded) == 0;

zassert_true(ok, "Expected decode to be successful\n");
zassert_equal(decoded, 0, "Expected to receive 0 decoded zcbor element\n");

zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1);
zcbor_new_decode_state(zsd, 3, nb->data, nb->len, 1, NULL, 0);
ok = zcbor_map_decode_bulk(zsd, error_decode, ARRAY_SIZE(error_decode), &decoded) == 0;

zassert_true(ok, "Expected decode to be successful\n");
Expand Down
Loading

0 comments on commit c970356

Please sign in to comment.