test: Update the new ZTEST APIs tests/net/mld
TEST=twister -T tests/net/mld
Signed-off-by: Hu Zhenyu <zhenyu.hu@intel.com>
diff --git a/tests/net/mld/prj.conf b/tests/net/mld/prj.conf
index 5eeab7f..59d326f 100644
--- a/tests/net/mld/prj.conf
+++ b/tests/net/mld/prj.conf
@@ -1,4 +1,5 @@
CONFIG_ZTEST=y
+CONFIG_ZTEST_NEW_API=y
CONFIG_MAIN_STACK_SIZE=2048
CONFIG_NET_TEST=y
CONFIG_NETWORKING=y
diff --git a/tests/net/mld/src/main.c b/tests/net/mld/src/main.c
index a3f562c..5bda52d 100644
--- a/tests/net/mld/src/main.c
+++ b/tests/net/mld/src/main.c
@@ -200,7 +200,7 @@
}
}
-static void test_mld_setup(void)
+static void *test_mld_setup(void)
{
struct net_if_addr *ifaddr;
@@ -214,6 +214,8 @@
NET_ADDR_MANUAL, 0);
zassert_not_null(ifaddr, "Cannot add IPv6 address");
+
+ return NULL;
}
static void test_join_group(void)
@@ -246,12 +248,7 @@
zassert_equal(ret, 0, "Cannot leave IPv6 multicast group");
- if (IS_ENABLED(CONFIG_NET_TC_THREAD_PREEMPTIVE)) {
- /* Let the network stack to proceed */
- k_msleep(THREAD_SLEEP);
- } else {
- k_yield();
- }
+ k_msleep(THREAD_SLEEP);
}
static void test_catch_join_group(void)
@@ -411,12 +408,8 @@
zassert_true(ret == 0 || ret == -EALREADY,
"Cannot join MLDv2-capable routers multicast group");
- if (IS_ENABLED(CONFIG_NET_TC_THREAD_PREEMPTIVE)) {
- /* Let the network stack to proceed */
- k_msleep(THREAD_SLEEP);
- } else {
- k_yield();
- }
+ k_msleep(THREAD_SLEEP);
+
}
static void leave_mldv2_capable_routers_group(void)
@@ -432,12 +425,7 @@
zassert_equal(ret, 0,
"Cannot leave MLDv2-capable routers multicast group");
- if (IS_ENABLED(CONFIG_NET_TC_THREAD_PREEMPTIVE)) {
- /* Let the network stack to proceed */
- k_msleep(THREAD_SLEEP);
- } else {
- k_yield();
- }
+ k_msleep(THREAD_SLEEP);
}
/* We are not really interested to parse the query at this point */
@@ -468,12 +456,7 @@
send_query(net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY)));
- if (IS_ENABLED(CONFIG_NET_TC_THREAD_PREEMPTIVE)) {
- /* Let the network stack to proceed */
- k_msleep(THREAD_SLEEP);
- } else {
- k_yield();
- }
+ k_msleep(THREAD_SLEEP);
if (k_sem_take(&wait_data, K_MSEC(WAIT_TIME))) {
zassert_true(0, "Timeout while waiting query event");
@@ -516,7 +499,7 @@
/* This value should be longer that the one in net_if.c when DAD timeouts */
#define DAD_TIMEOUT (MSEC_PER_SEC / 5U)
-static void test_allnodes(void)
+ZTEST(net_mld_test_suite, test_allnodes)
{
struct net_if *iface = NULL;
struct net_if_mcast_addr *ifmaddr;
@@ -533,7 +516,7 @@
"allnodes multicast address");
}
-static void test_solicit_node(void)
+ZTEST(net_mld_test_suite, test_solicit_node)
{
struct net_if *iface = NULL;
struct net_if_mcast_addr *ifmaddr;
@@ -547,21 +530,24 @@
"solicit node multicast address");
}
-void test_main(void)
+ZTEST(net_mld_test_suite, test_join_leave)
{
- ztest_test_suite(net_mld_test,
- ztest_unit_test(test_mld_setup),
- ztest_unit_test(test_join_group),
- ztest_unit_test(test_leave_group),
- ztest_unit_test(test_catch_join_group),
- ztest_unit_test(test_catch_leave_group),
- ztest_unit_test(test_verify_join_group),
- ztest_unit_test(test_verify_leave_group),
- ztest_unit_test(test_catch_query),
- ztest_unit_test(test_verify_send_report),
- ztest_unit_test(test_allnodes),
- ztest_unit_test(test_solicit_node)
- );
-
- ztest_run_test_suite(net_mld_test);
+ test_join_group();
+ test_leave_group();
}
+
+ZTEST(net_mld_test_suite, test_catch_join_leave)
+{
+ test_catch_join_group();
+ test_catch_leave_group();
+}
+
+ZTEST(net_mld_test_suite, test_verify_join_leave)
+{
+ test_verify_join_group();
+ test_verify_leave_group();
+ test_catch_query();
+ test_verify_send_report();
+}
+
+ZTEST_SUITE(net_mld_test_suite, NULL, test_mld_setup, NULL, NULL, NULL);