@@ -414,7 +414,7 @@ static struct net_pkt *prepare_echo_request_with_bad_options(
414414 return NULL ;
415415}
416416
417- static void test_icmpv4 (void )
417+ static void * icmpv4_setup (void )
418418{
419419 struct net_if_addr * ifaddr ;
420420
@@ -427,9 +427,19 @@ static void test_icmpv4(void)
427427 if (!ifaddr ) {
428428 zassert_true (false, "Failed to add address" );
429429 }
430+ return NULL ;
430431}
431432
432- static void test_icmpv4_send_echo_req (void )
433+ static void icmpv4_teardown (void * dummy )
434+ {
435+ ARG_UNUSED (dummy );
436+
437+ iface = net_if_get_first_by_type (& NET_L2_GET_NAME (DUMMY ));
438+
439+ net_if_ipv4_addr_rm (iface , & my_addr );
440+ }
441+
442+ static void icmpv4_send_echo_req (void )
433443{
434444 struct net_pkt * pkt ;
435445
@@ -446,7 +456,7 @@ static void test_icmpv4_send_echo_req(void)
446456 }
447457}
448458
449- static void test_icmpv4_send_echo_rep (void )
459+ static void icmpv4_send_echo_rep (void )
450460{
451461 struct net_pkt * pkt ;
452462
@@ -461,11 +471,10 @@ static void test_icmpv4_send_echo_rep(void)
461471 net_pkt_unref (pkt );
462472 zassert_true (false, "Failed to send" );
463473 }
464-
465474 net_icmpv4_unregister_handler (& echo_rep_handler );
466475}
467476
468- static void test_icmpv4_send_echo_req_opt ( void )
477+ ZTEST ( net_icmpv4 , test_icmpv4_send_echo_req_opt )
469478{
470479 struct net_pkt * pkt ;
471480
@@ -482,7 +491,7 @@ static void test_icmpv4_send_echo_req_opt(void)
482491 }
483492}
484493
485- static void test_icmpv4_send_echo_req_bad_opt ( void )
494+ ZTEST ( net_icmpv4 , test_send_echo_req_bad_opt )
486495{
487496 struct net_pkt * pkt ;
488497
@@ -492,20 +501,15 @@ static void test_icmpv4_send_echo_req_bad_opt(void)
492501 "EchoRequest with bad opts packet prep failed" );
493502 }
494503
495- if (! net_ipv4_input (pkt )) {
504+ if (net_ipv4_input (pkt )) {
496505 net_pkt_unref (pkt );
497- zassert_true (false, "Failed to send" );
498506 }
499507}
500508
501- /**test case main entry */
502- void test_main (void )
509+ ZTEST (net_icmpv4 , test_icmpv4_send_echo )
503510{
504- ztest_test_suite (test_icmpv4_fn ,
505- ztest_unit_test (test_icmpv4 ),
506- ztest_unit_test (test_icmpv4_send_echo_req ),
507- ztest_unit_test (test_icmpv4_send_echo_rep ),
508- ztest_unit_test (test_icmpv4_send_echo_req_opt ),
509- ztest_unit_test (test_icmpv4_send_echo_req_bad_opt ));
510- ztest_run_test_suite (test_icmpv4_fn );
511+ icmpv4_send_echo_req ();
512+ icmpv4_send_echo_rep ();
511513}
514+
515+ ZTEST_SUITE (net_icmpv4 , NULL , icmpv4_setup , NULL , NULL , icmpv4_teardown );
0 commit comments