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

Move net content_oma_tlv tests to use new ztest API
Split all the test cases into 3 test suites, each test suite has
its own before function.

Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
This commit is contained in:
Hu Zhenyu 2022-08-24 23:51:58 +08:00 committed by Fabio Baltieri
commit a07402d692
2 changed files with 39 additions and 109 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

@ -54,19 +54,19 @@ static void context_reset(void)
test_path.level = LWM2M_PATH_LEVEL_RESOURCE;
}
static void test_prepare(void)
static void test_prepare(void *dummy)
{
context_reset();
}
static void test_prepare_nomem(void)
static void test_prepare_nomem(void *dummy)
{
context_reset();
test_packet.offset = sizeof(test_payload);
}
static void test_prepare_nodata(void)
static void test_prepare_nodata(void *dummy)
{
context_reset();
@ -81,7 +81,7 @@ static void test_payload_set(const uint8_t *payload, size_t len)
test_in.offset = 1; /* Payload marker */
}
static void test_put_s8(void)
ZTEST(net_content_oma_tlv, test_put_s8)
{
int ret;
int i;
@ -137,7 +137,7 @@ static void test_put_s8(void)
}
}
static void test_put_s8_nomem(void)
ZTEST(net_content_oma_tlv_nomem, test_put_s8_nomem)
{
int ret;
@ -145,7 +145,7 @@ static void test_put_s8_nomem(void)
zassert_equal(ret, -ENOMEM, "Invalid error code returned");
}
static void test_put_s16(void)
ZTEST(net_content_oma_tlv, test_put_s16)
{
int ret;
int i;
@ -203,7 +203,7 @@ static void test_put_s16(void)
}
}
static void test_put_s16_nomem(void)
ZTEST(net_content_oma_tlv_nomem, test_put_s16_nomem)
{
int ret;
@ -211,7 +211,7 @@ static void test_put_s16_nomem(void)
zassert_equal(ret, -ENOMEM, "Invalid error code returned");
}
static void test_put_s32(void)
ZTEST(net_content_oma_tlv, test_put_s32)
{
int ret;
int i;
@ -273,7 +273,7 @@ static void test_put_s32(void)
}
}
static void test_put_s32_nomem(void)
ZTEST(net_content_oma_tlv_nomem, test_put_s32_nomem)
{
int ret;
@ -281,7 +281,7 @@ static void test_put_s32_nomem(void)
zassert_equal(ret, -ENOMEM, "Invalid error code returned");
}
static void test_put_s64(void)
ZTEST(net_content_oma_tlv, test_put_s64)
{
int ret;
int i;
@ -353,7 +353,7 @@ static void test_put_s64(void)
}
}
static void test_put_s64_nomem(void)
ZTEST(net_content_oma_tlv_nomem, test_put_s64_nomem)
{
int ret;
@ -361,7 +361,7 @@ static void test_put_s64_nomem(void)
zassert_equal(ret, -ENOMEM, "Invalid error code returned");
}
static void test_put_string(void)
ZTEST(net_content_oma_tlv, test_put_string)
{
int ret;
const char *test_string = "test_string";
@ -387,7 +387,7 @@ static void test_put_string(void)
"Invalid packet offset");
}
static void test_put_string_nomem(void)
ZTEST(net_content_oma_tlv_nomem, test_put_string_nomem)
{
int ret;
const char *test_string = "test_string";
@ -399,8 +399,7 @@ static void test_put_string_nomem(void)
}
#define DOUBLE_CMP_EPSILON 0.000000001
static void test_put_float(void)
ZTEST(net_content_oma_tlv, test_put_float)
{
int ret;
int i;
@ -512,7 +511,7 @@ static void test_put_float(void)
}
}
static void test_put_float_nomem(void)
ZTEST(net_content_oma_tlv_nomem, test_put_float_nomem)
{
int ret;
double value = 1.2;
@ -521,7 +520,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_oma_tlv, test_put_bool)
{
int ret;
int i;
@ -568,7 +567,7 @@ static void test_put_bool(void)
}
}
static void test_put_bool_nomem(void)
ZTEST(net_content_oma_tlv_nomem, test_put_bool_nomem)
{
int ret;
@ -576,7 +575,7 @@ static void test_put_bool_nomem(void)
zassert_equal(ret, -ENOMEM, "Invalid error code returned");
}
static void test_put_opaque(void)
ZTEST(net_content_oma_tlv, test_put_opaque)
{
int ret;
const char *test_opaque = "test_opaque";
@ -602,7 +601,7 @@ static void test_put_opaque(void)
"Invalid packet offset");
}
static void test_put_opaque_nomem(void)
ZTEST(net_content_oma_tlv_nomem, test_put_opaque_nomem)
{
int ret;
const char *test_opaque = "test_opaque";
@ -613,7 +612,7 @@ static void test_put_opaque_nomem(void)
zassert_equal(ret, -ENOMEM, "Invalid error code returned");
}
static void test_put_objlnk(void)
ZTEST(net_content_oma_tlv, test_put_objlnk)
{
int ret;
int i;
@ -671,7 +670,7 @@ static void test_put_objlnk(void)
}
}
static void test_put_objlnk_nomem(void)
ZTEST(net_content_oma_tlv_nomem, test_put_objlnk_nomem)
{
int ret;
struct lwm2m_objlnk value = { 0, 0 };
@ -680,7 +679,7 @@ static void test_put_objlnk_nomem(void)
zassert_equal(ret, -ENOMEM, "Invalid error code returned");
}
static void test_get_s32(void)
ZTEST(net_content_oma_tlv, test_get_s32)
{
int ret;
int i;
@ -731,7 +730,7 @@ static void test_get_s32(void)
}
}
static void test_get_s32_nodata(void)
ZTEST(net_content_oma_tlv_nodata, test_get_s32_nodata)
{
int ret;
int32_t value;
@ -740,7 +739,7 @@ static void test_get_s32_nodata(void)
zassert_equal(ret, -ENODATA, "Invalid error code returned");
}
static void test_get_s64(void)
ZTEST(net_content_oma_tlv, test_get_s64)
{
int ret;
int i;
@ -802,7 +801,7 @@ static void test_get_s64(void)
}
}
static void test_get_s64_nodata(void)
ZTEST(net_content_oma_tlv_nodata, test_get_s64_nodata)
{
int ret;
int64_t value;
@ -811,7 +810,7 @@ static void test_get_s64_nodata(void)
zassert_equal(ret, -ENODATA, "Invalid error code returned");
}
static void test_get_string(void)
ZTEST(net_content_oma_tlv, test_get_string)
{
int ret;
const char *test_string = "test_string";
@ -827,7 +826,6 @@ static void test_get_string(void)
.len = sizeof("test_string") - 1 + 3
};
test_payload_set(payload.data, payload.len);
ret = oma_tlv_reader.get_string(&test_in, buf, sizeof(buf));
@ -838,7 +836,7 @@ static void test_get_string(void)
"Invalid packet offset");
}
static void test_get_string_nodata(void)
ZTEST(net_content_oma_tlv_nodata, test_get_string_nodata)
{
int ret;
uint8_t buf[16];
@ -849,7 +847,7 @@ static void test_get_string_nodata(void)
#define DOUBLE_CMP_EPSILON 0.000000001
static void test_get_float(void)
ZTEST(net_content_oma_tlv, test_get_float)
{
int ret;
int i;
@ -938,7 +936,7 @@ static void test_get_float(void)
}
}
static void test_get_float_nodata(void)
ZTEST(net_content_oma_tlv_nodata, test_get_float_nodata)
{
int ret;
double value;
@ -947,7 +945,7 @@ static void test_get_float_nodata(void)
zassert_equal(ret, -ENODATA, "Invalid error code returned");
}
static void test_get_bool(void)
ZTEST(net_content_oma_tlv, test_get_bool)
{
int ret;
int i;
@ -984,7 +982,7 @@ static void test_get_bool(void)
}
}
static void test_get_bool_nodata(void)
ZTEST(net_content_oma_tlv_nodata, test_get_bool_nodata)
{
int ret;
bool value;
@ -993,7 +991,7 @@ static void test_get_bool_nodata(void)
zassert_equal(ret, -ENODATA, "Invalid error code returned");
}
static void test_get_opaque(void)
ZTEST(net_content_oma_tlv, test_get_opaque)
{
int ret;
const char *test_opaque = "test_opaque";
@ -1022,7 +1020,7 @@ static void test_get_opaque(void)
"Invalid packet offset");
}
static void test_get_opaque_nodata(void)
ZTEST(net_content_oma_tlv_nodata, test_get_opaque_nodata)
{
int ret;
uint8_t value[4];
@ -1034,7 +1032,7 @@ static void test_get_opaque_nodata(void)
zassert_equal(ret, -ENODATA, "Invalid error code returned %d");
}
static void test_get_objlnk(void)
ZTEST(net_content_oma_tlv, test_get_objlnk)
{
int ret;
int i;
@ -1083,7 +1081,7 @@ static void test_get_objlnk(void)
}
}
static void test_get_objlnk_nodata(void)
ZTEST(net_content_oma_tlv_nodata, test_get_objlnk_nodata)
{
int ret;
struct lwm2m_objlnk value;
@ -1092,75 +1090,6 @@ static void test_get_objlnk_nodata(void)
zassert_equal(ret, -ENODATA, "Invalid error code returned");
}
void test_main(void)
{
ztest_test_suite(
lwm2m_content_plain_text,
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_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_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_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_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_objlnk, test_prepare, unit_test_noop),
ztest_unit_test_setup_teardown(
test_get_objlnk_nodata, test_prepare_nodata, unit_test_noop)
);
ztest_run_test_suite(lwm2m_content_plain_text);
}
ZTEST_SUITE(net_content_oma_tlv, NULL, NULL, test_prepare, NULL, NULL);
ZTEST_SUITE(net_content_oma_tlv_nomem, NULL, NULL, test_prepare_nomem, NULL, NULL);
ZTEST_SUITE(net_content_oma_tlv_nodata, NULL, NULL, test_prepare_nodata, NULL, NULL);