Commit 470e333a authored by Hu Zhenyu's avatar Hu Zhenyu Committed by Carles Cufi
Browse files

tests: net: icmpv4 move to new ztest API



Move net icmpv4 tests to use new ztest API
1. Add teardown, remove addr
2. Fix a packet release bug in test_send_echo_req_bad_opt
3. Combine send_echo_req/rep, as they should be run in sequence

Signed-off-by: default avatarHu Zhenyu <zhenyu.hu@intel.com>
parent 52ddc6e3
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -13,5 +13,6 @@ CONFIG_NET_LOG=y
CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_ZTEST=y
CONFIG_ZTEST_NEW_API=y
CONFIG_MAIN_STACK_SIZE=1280
CONFIG_NET_IPV4_HDR_OPTIONS=y
+21 −17
Original line number Diff line number Diff line
@@ -414,7 +414,7 @@ fail:
	return NULL;
}

static void test_icmpv4(void)
static void *icmpv4_setup(void)
{
	struct net_if_addr *ifaddr;

@@ -427,9 +427,19 @@ static void test_icmpv4(void)
	if (!ifaddr) {
		zassert_true(false, "Failed to add address");
	}
	return NULL;
}

static void test_icmpv4_send_echo_req(void)
static void icmpv4_teardown(void *dummy)
{
	ARG_UNUSED(dummy);

	iface = net_if_get_first_by_type(&NET_L2_GET_NAME(DUMMY));

	net_if_ipv4_addr_rm(iface, &my_addr);
}

static void icmpv4_send_echo_req(void)
{
	struct net_pkt *pkt;

@@ -446,7 +456,7 @@ static void test_icmpv4_send_echo_req(void)
	}
}

static void test_icmpv4_send_echo_rep(void)
static void icmpv4_send_echo_rep(void)
{
	struct net_pkt *pkt;

@@ -461,11 +471,10 @@ static void test_icmpv4_send_echo_rep(void)
		net_pkt_unref(pkt);
		zassert_true(false, "Failed to send");
	}

	net_icmpv4_unregister_handler(&echo_rep_handler);
}

static void test_icmpv4_send_echo_req_opt(void)
ZTEST(net_icmpv4, test_icmpv4_send_echo_req_opt)
{
	struct net_pkt *pkt;

@@ -482,7 +491,7 @@ static void test_icmpv4_send_echo_req_opt(void)
	}
}

static void test_icmpv4_send_echo_req_bad_opt(void)
ZTEST(net_icmpv4, test_send_echo_req_bad_opt)
{
	struct net_pkt *pkt;

@@ -492,20 +501,15 @@ static void test_icmpv4_send_echo_req_bad_opt(void)
			     "EchoRequest with bad opts packet prep failed");
	}

	if (!net_ipv4_input(pkt)) {
	if (net_ipv4_input(pkt)) {
		net_pkt_unref(pkt);
		zassert_true(false, "Failed to send");
	}
}

/**test case main entry */
void test_main(void)
ZTEST(net_icmpv4, test_icmpv4_send_echo)
{
	ztest_test_suite(test_icmpv4_fn,
			 ztest_unit_test(test_icmpv4),
			 ztest_unit_test(test_icmpv4_send_echo_req),
			 ztest_unit_test(test_icmpv4_send_echo_rep),
			 ztest_unit_test(test_icmpv4_send_echo_req_opt),
			 ztest_unit_test(test_icmpv4_send_echo_req_bad_opt));
	ztest_run_test_suite(test_icmpv4_fn);
	icmpv4_send_echo_req();
	icmpv4_send_echo_rep();
}

ZTEST_SUITE(net_icmpv4, NULL, icmpv4_setup, NULL, NULL, icmpv4_teardown);