tests: net: Add missing tests to net_pkt_clone

Add tests for flag cloning and couple extra.

Signed-off-by: Marcin Gasiorek <marcin.gasiorek@nordicsemi.no>
This commit is contained in:
Marcin Gasiorek 2023-09-15 09:12:20 +02:00 committed by Carles Cufí
commit 4ebf6e5fac
2 changed files with 35 additions and 0 deletions

View file

@ -12,3 +12,4 @@ CONFIG_NET_LOG=y
CONFIG_NET_BUF_POOL_USAGE=y CONFIG_NET_BUF_POOL_USAGE=y
CONFIG_ENTROPY_GENERATOR=y CONFIG_ENTROPY_GENERATOR=y
CONFIG_TEST_RANDOM_GENERATOR=y CONFIG_TEST_RANDOM_GENERATOR=y
CONFIG_NET_ETHERNET_BRIDGE=y

View file

@ -814,6 +814,16 @@ ZTEST(net_pkt_test_suite, test_net_pkt_clone)
net_pkt_lladdr_dst(pkt)->type = NET_LINK_ETHERNET; net_pkt_lladdr_dst(pkt)->type = NET_LINK_ETHERNET;
zassert_mem_equal(net_pkt_lladdr_dst(pkt)->addr, &buf[6], NET_LINK_ADDR_MAX_LENGTH); zassert_mem_equal(net_pkt_lladdr_dst(pkt)->addr, &buf[6], NET_LINK_ADDR_MAX_LENGTH);
net_pkt_set_family(pkt, AF_INET6);
net_pkt_set_captured(pkt, true);
net_pkt_set_eof(pkt, true);
net_pkt_set_ptp(pkt, true);
net_pkt_set_forwarding(pkt, true);
net_pkt_set_l2_bridged(pkt, true);
net_pkt_set_l2_processed(pkt, true);
net_pkt_set_ll_proto_type(pkt, ETH_P_IEEE802154);
net_pkt_set_overwrite(pkt, false); net_pkt_set_overwrite(pkt, false);
cloned_pkt = net_pkt_clone(pkt, K_NO_WAIT); cloned_pkt = net_pkt_clone(pkt, K_NO_WAIT);
zassert_true(cloned_pkt != NULL, "Pkt not cloned"); zassert_true(cloned_pkt != NULL, "Pkt not cloned");
@ -833,6 +843,27 @@ ZTEST(net_pkt_test_suite, test_net_pkt_clone)
zassert_false(net_pkt_is_being_overwritten(pkt), zassert_false(net_pkt_is_being_overwritten(pkt),
"Pkt overwrite flag not restored"); "Pkt overwrite flag not restored");
zassert_equal(net_pkt_family(cloned_pkt), AF_INET6,
"Address family value mismatch");
zassert_true(net_pkt_is_captured(cloned_pkt),
"Cloned pkt captured flag mismatch");
zassert_true(net_pkt_eof(cloned_pkt),
"Cloned pkt eof flag mismatch");
zassert_true(net_pkt_is_ptp(cloned_pkt),
"Cloned pkt ptp_pkt flag mismatch");
zassert_true(net_pkt_forwarding(cloned_pkt),
"Cloned pkt forwarding flag mismatch");
zassert_true(net_pkt_is_l2_bridged(cloned_pkt),
"Cloned pkt l2_bridged flag mismatch");
zassert_true(net_pkt_is_l2_processed(cloned_pkt),
"Cloned pkt l2_processed flag mismatch");
zassert_mem_equal(net_pkt_lladdr_src(cloned_pkt)->addr, buf, NET_LINK_ADDR_MAX_LENGTH); zassert_mem_equal(net_pkt_lladdr_src(cloned_pkt)->addr, buf, NET_LINK_ADDR_MAX_LENGTH);
zassert_true(net_pkt_lladdr_src(cloned_pkt)->addr == cloned_pkt->buffer->data, zassert_true(net_pkt_lladdr_src(cloned_pkt)->addr == cloned_pkt->buffer->data,
"Cloned pkt ll src addr mismatch"); "Cloned pkt ll src addr mismatch");
@ -841,6 +872,9 @@ ZTEST(net_pkt_test_suite, test_net_pkt_clone)
zassert_true(net_pkt_lladdr_dst(cloned_pkt)->addr == net_pkt_cursor_get_pos(cloned_pkt), zassert_true(net_pkt_lladdr_dst(cloned_pkt)->addr == net_pkt_cursor_get_pos(cloned_pkt),
"Cloned pkt ll dst addr mismatch"); "Cloned pkt ll dst addr mismatch");
zassert_equal(net_pkt_ll_proto_type(cloned_pkt), ETH_P_IEEE802154,
"Address ll_proto_type value mismatch");
net_pkt_unref(pkt); net_pkt_unref(pkt);
net_pkt_unref(cloned_pkt); net_pkt_unref(cloned_pkt);
} }