tests: net: lib: lwm2m: content_senml_cbor: move to new ztest API

Move net content_senml_cbor tests to use new ztest API

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
This commit is contained in:
Hu Zhenyu 2022-10-18 10:46:15 +08:00 committed by Carles Cufí
commit d2ffa8a3eb
2 changed files with 53 additions and 102 deletions

View file

@ -1,6 +1,7 @@
CONFIG_NETWORKING=y
CONFIG_NET_TEST=y
CONFIG_ZTEST=y
CONFIG_ZTEST_NEW_API=y
CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y

View file

@ -100,7 +100,7 @@ static struct lwm2m_engine_obj_inst *test_obj_create(uint16_t obj_inst_id)
return &test_inst;
}
static void test_obj_init(void)
static void *test_obj_init(void)
{
struct lwm2m_engine_obj_inst *obj_inst = NULL;
@ -115,6 +115,8 @@ static void test_obj_init(void)
(void)lwm2m_register_obj(&test_obj);
(void)lwm2m_create_obj_inst(TEST_OBJ_ID, TEST_OBJ_INST_ID, &obj_inst);
return NULL;
}
/* 2 bytes for Content Format option + payload marker */
@ -147,13 +149,15 @@ static void test_payload_set(struct test_payload_buffer payload)
test_msg.in.offset = 1;
}
static void test_prepare(void)
static void test_prepare(void *dummy)
{
ARG_UNUSED(dummy);
context_reset();
}
static void test_prepare_nomem(void)
static void test_prepare_nomem(void *dummy)
{
ARG_UNUSED(dummy);
context_reset();
/* Leave some space for Content-format option */
@ -161,12 +165,13 @@ static void test_prepare_nomem(void)
test_msg.cpkt.offset = sizeof(test_msg.msg_data) - TEST_PAYLOAD_OFFSET;
}
static void test_prepare_nodata(void)
static void test_prepare_nodata(void *dummy)
{
ARG_UNUSED(dummy);
context_reset();
}
static void test_put_s8(void)
ZTEST(net_content_senml_cbor, test_put_s8)
{
int ret;
int i;
@ -244,7 +249,7 @@ static void test_put_s8(void)
}
}
void test_put_s8_nomem(void)
ZTEST(net_content_senml_cbor_nomem, test_put_s8_nomem)
{
int ret;
@ -254,7 +259,7 @@ void test_put_s8_nomem(void)
zassert_equal(ret, -ENOMEM, "Invalid error code returned");
}
static void test_put_s16(void)
ZTEST(net_content_senml_cbor, test_put_s16)
{
int ret;
int i;
@ -332,7 +337,7 @@ static void test_put_s16(void)
}
}
void test_put_s16_nomem(void)
ZTEST(net_content_senml_cbor_nomem, test_put_s16_nomem)
{
int ret;
@ -342,7 +347,7 @@ void test_put_s16_nomem(void)
zassert_equal(ret, -ENOMEM, "Invalid error code returned");
}
static void test_put_s32(void)
ZTEST(net_content_senml_cbor, test_put_s32)
{
int ret;
int i;
@ -420,7 +425,7 @@ static void test_put_s32(void)
}
}
void test_put_s32_nomem(void)
ZTEST(net_content_senml_cbor_nomem, test_put_s32_nomem)
{
int ret;
@ -430,7 +435,7 @@ void test_put_s32_nomem(void)
zassert_equal(ret, -ENOMEM, "Invalid error code returned");
}
static void test_put_s64(void)
ZTEST(net_content_senml_cbor, test_put_s64)
{
int ret;
int i;
@ -508,7 +513,7 @@ static void test_put_s64(void)
}
}
void test_put_s64_nomem(void)
ZTEST(net_content_senml_cbor_nomem, test_put_s64_nomem)
{
int ret;
@ -518,7 +523,7 @@ void test_put_s64_nomem(void)
zassert_equal(ret, -ENOMEM, "Invalid error code returned");
}
static void test_put_string(void)
ZTEST(net_content_senml_cbor, test_put_string)
{
int ret;
struct test_payload_buffer expected_payload = {
@ -552,7 +557,7 @@ static void test_put_string(void)
"Invalid packet offset");
}
static void test_put_string_nomem(void)
ZTEST(net_content_senml_cbor_nomem, test_put_string_nomem)
{
int ret;
@ -562,7 +567,7 @@ static void test_put_string_nomem(void)
zassert_equal(ret, -ENOMEM, "Invalid error code returned");
}
static void test_put_float(void)
ZTEST(net_content_senml_cbor, test_put_float)
{
int ret;
int i;
@ -687,7 +692,7 @@ static void test_put_float(void)
}
}
static void test_put_float_nomem(void)
ZTEST(net_content_senml_cbor_nomem, test_put_float_nomem)
{
int ret;
@ -697,7 +702,7 @@ static void test_put_float_nomem(void)
zassert_equal(ret, -ENOMEM, "Invalid error code returned");
}
static void test_put_bool(void)
ZTEST(net_content_senml_cbor, test_put_bool)
{
int ret;
int i;
@ -757,7 +762,7 @@ static void test_put_bool(void)
}
}
static void test_put_bool_nomem(void)
ZTEST(net_content_senml_cbor_nomem, test_put_bool_nomem)
{
int ret;
@ -767,7 +772,7 @@ static void test_put_bool_nomem(void)
zassert_equal(ret, -ENOMEM, "Invalid error code returned");
}
static void test_put_objlnk(void)
ZTEST(net_content_senml_cbor, test_put_objlnk)
{
int ret;
int i;
@ -845,7 +850,7 @@ static void test_put_objlnk(void)
}
}
static void test_put_objlnk_nomem(void)
ZTEST(net_content_senml_cbor_nomem, test_put_objlnk_nomem)
{
int ret;
@ -889,7 +894,7 @@ static void test_put_opaque(void)
"Invalid packet offset");
}
static void test_put_opaque_nomem(void)
ZTEST(net_content_senml_cbor_nomem, test_put_opaque_nomem)
{
int ret;
@ -899,7 +904,7 @@ static void test_put_opaque_nomem(void)
zassert_equal(ret, -ENOMEM, "Invalid error code returned");
}
static void test_put_time(void)
ZTEST(net_content_senml_cbor, test_put_time)
{
int ret;
int64_t value = 1170111600;
@ -935,7 +940,7 @@ static void test_put_time(void)
}
static void test_put_time_nomem(void)
ZTEST(net_content_senml_cbor_nomem, test_put_time_nomem)
{
int ret;
@ -945,7 +950,7 @@ static void test_put_time_nomem(void)
zassert_equal(ret, -ENOMEM, "Invalid error code returned");
}
static void test_get_s32(void)
ZTEST(net_content_senml_cbor, test_get_s32)
{
int ret;
int i;
@ -1013,7 +1018,7 @@ static void test_get_s32(void)
}
}
static void test_get_s32_nodata(void)
ZTEST(net_content_senml_cbor_nodata, test_get_s32_nodata)
{
int ret;
@ -1023,7 +1028,7 @@ static void test_get_s32_nodata(void)
zassert_equal(ret, -EBADMSG, "Invalid error code returned");
}
static void test_get_s64(void)
ZTEST(net_content_senml_cbor, test_get_s64)
{
int ret;
int i;
@ -1091,7 +1096,7 @@ static void test_get_s64(void)
}
}
static void test_get_s64_nodata(void)
ZTEST(net_content_senml_cbor_nodata, test_get_s64_nodata)
{
int ret;
@ -1101,7 +1106,7 @@ static void test_get_s64_nodata(void)
zassert_equal(ret, -EBADMSG, "Invalid error code returned");
}
static void test_get_string(void)
ZTEST(net_content_senml_cbor, test_get_string)
{
int ret;
struct test_payload_buffer payload = {
@ -1134,7 +1139,7 @@ static void test_get_string(void)
"Invalid packet offset");
}
static void test_get_string_nodata(void)
ZTEST(net_content_senml_cbor_nodata, test_get_string_nodata)
{
int ret;
@ -1146,7 +1151,7 @@ static void test_get_string_nodata(void)
#define DOUBLE_CMP_EPSILON 0.000000001
static void test_get_float(void)
ZTEST(net_content_senml_cbor, test_get_float)
{
int ret;
int i;
@ -1267,7 +1272,7 @@ static void test_get_float(void)
}
}
static void test_get_float_nodata(void)
ZTEST(net_content_senml_cbor_nodata, test_get_float_nodata)
{
int ret;
@ -1277,7 +1282,7 @@ static void test_get_float_nodata(void)
zassert_equal(ret, -EBADMSG, "Invalid error code returned");
}
static void test_get_bool(void)
ZTEST(net_content_senml_cbor, test_get_bool)
{
int ret;
int i;
@ -1328,7 +1333,7 @@ static void test_get_bool(void)
}
}
static void test_get_bool_nodata(void)
ZTEST(net_content_senml_cbor_nodata, test_get_bool_noda)
{
int ret;
@ -1338,7 +1343,7 @@ static void test_get_bool_nodata(void)
zassert_equal(ret, -EBADMSG, "Invalid error code returned");
}
static void test_get_objlnk(void)
ZTEST(net_content_senml_cbor, test_get_objlnk)
{
int ret;
int i;
@ -1411,7 +1416,7 @@ static void test_get_objlnk(void)
}
}
static void test_get_objlnk_nodata(void)
ZTEST(net_content_senml_cbor_nodata, test_get_objlnk_nodata)
{
int ret;
@ -1456,7 +1461,13 @@ static void test_get_opaque(void)
"Invalid packet offset");
}
static void test_get_opaque_nodata(void)
ZTEST(net_content_senml_cbor, test_opaque)
{
test_put_opaque();
test_get_opaque();
}
ZTEST(net_content_senml_cbor_nodata, test_get_opaque_nodata)
{
int ret;
@ -1466,7 +1477,7 @@ static void test_get_opaque_nodata(void)
zassert_equal(ret, -EBADMSG, "Invalid error code returned");
}
static void test_get_time(void)
ZTEST(net_content_senml_cbor, test_get_time)
{
int ret;
int64_t expected_value = 1170111600;
@ -1498,7 +1509,7 @@ static void test_get_time(void)
"Invalid packet offset");
}
static void test_get_time_nodata(void)
ZTEST(net_content_senml_cbor_nodata, test_get_time_nodata)
{
int ret;
@ -1508,67 +1519,6 @@ static void test_get_time_nodata(void)
zassert_equal(ret, -EBADMSG, "Invalid error code returned");
}
void test_main(void)
{
test_obj_init();
ztest_test_suite(
lwm2m_content_senml_cbor,
ztest_unit_test_setup_teardown(test_put_s8, test_prepare, unit_test_noop),
ztest_unit_test_setup_teardown(test_put_s8_nomem,
test_prepare_nomem, unit_test_noop),
ztest_unit_test_setup_teardown(test_put_s16, test_prepare, unit_test_noop),
ztest_unit_test_setup_teardown(test_put_s16_nomem,
test_prepare_nomem, unit_test_noop),
ztest_unit_test_setup_teardown(test_put_s32, test_prepare, unit_test_noop),
ztest_unit_test_setup_teardown(test_put_s32_nomem,
test_prepare_nomem, unit_test_noop),
ztest_unit_test_setup_teardown(test_put_s64, test_prepare, unit_test_noop),
ztest_unit_test_setup_teardown(test_put_s64_nomem,
test_prepare_nomem, unit_test_noop),
ztest_unit_test_setup_teardown(test_put_string, test_prepare, unit_test_noop),
ztest_unit_test_setup_teardown(test_put_string_nomem,
test_prepare_nomem, unit_test_noop),
ztest_unit_test_setup_teardown(test_put_float, test_prepare, unit_test_noop),
ztest_unit_test_setup_teardown(test_put_float_nomem,
test_prepare_nomem, unit_test_noop),
ztest_unit_test_setup_teardown(test_put_bool, test_prepare, unit_test_noop),
ztest_unit_test_setup_teardown(test_put_bool_nomem,
test_prepare_nomem, unit_test_noop),
ztest_unit_test_setup_teardown(test_put_objlnk, test_prepare, unit_test_noop),
ztest_unit_test_setup_teardown(test_put_objlnk_nomem,
test_prepare_nomem, unit_test_noop),
ztest_unit_test_setup_teardown(test_put_opaque, test_prepare, unit_test_noop),
ztest_unit_test_setup_teardown(test_put_opaque_nomem,
test_prepare_nomem, unit_test_noop),
ztest_unit_test_setup_teardown(test_put_time, test_prepare, unit_test_noop),
ztest_unit_test_setup_teardown(test_put_time_nomem,
test_prepare_nomem, unit_test_noop),
ztest_unit_test_setup_teardown(test_get_s32, test_prepare, unit_test_noop),
ztest_unit_test_setup_teardown(test_get_s32_nodata,
test_prepare_nodata, unit_test_noop),
ztest_unit_test_setup_teardown(test_get_s64, test_prepare, unit_test_noop),
ztest_unit_test_setup_teardown(test_get_s64_nodata,
test_prepare_nodata, unit_test_noop),
ztest_unit_test_setup_teardown(test_get_string, test_prepare, unit_test_noop),
ztest_unit_test_setup_teardown(test_get_string_nodata,
test_prepare_nodata, unit_test_noop),
ztest_unit_test_setup_teardown(test_get_float, test_prepare, unit_test_noop),
ztest_unit_test_setup_teardown(test_get_float_nodata,
test_prepare_nodata, unit_test_noop),
ztest_unit_test_setup_teardown(test_get_bool, test_prepare, unit_test_noop),
ztest_unit_test_setup_teardown(test_get_bool_nodata,
test_prepare_nodata, unit_test_noop),
ztest_unit_test_setup_teardown(test_get_objlnk, test_prepare, unit_test_noop),
ztest_unit_test_setup_teardown(test_get_objlnk_nodata,
test_prepare_nodata, unit_test_noop),
ztest_unit_test_setup_teardown(test_get_opaque, test_prepare, unit_test_noop),
ztest_unit_test_setup_teardown(test_get_opaque_nodata,
test_prepare_nodata, unit_test_noop),
ztest_unit_test_setup_teardown(test_get_time, test_prepare, unit_test_noop),
ztest_unit_test_setup_teardown(test_get_time_nodata,
test_prepare_nodata, unit_test_noop)
);
ztest_run_test_suite(lwm2m_content_senml_cbor);
}
ZTEST_SUITE(net_content_senml_cbor, NULL, test_obj_init, test_prepare, NULL, NULL);
ZTEST_SUITE(net_content_senml_cbor_nomem, NULL, test_obj_init, test_prepare_nomem, NULL, NULL);
ZTEST_SUITE(net_content_senml_cbor_nodata, NULL, test_obj_init, test_prepare_nodata, NULL, NULL);