tests: net: Simple test for net_pkt clone

Added simple test case for net_pkt_clone() to verify
cursor position after cloning.

Signed-off-by: Ravi kumar Veeramally <ravikumar.veeramally@linux.intel.com>
This commit is contained in:
Ravi kumar Veeramally 2020-02-21 13:42:39 +02:00 committed by Johan Hedberg
commit 01867fa28c

View file

@ -672,6 +672,45 @@ void test_net_pkt_pull(void)
net_pkt_unref(dummy_pkt);
}
void test_net_pkt_clone(void)
{
u8_t buf[26] = {"abcdefghijklmnopqrstuvwxyz"};
struct net_pkt *pkt;
struct net_pkt *cloned_pkt;
int ret;
pkt = net_pkt_alloc_with_buffer(eth_if, 64,
AF_UNSPEC, 0, K_NO_WAIT);
zassert_true(pkt != NULL, "Pkt not allocated");
ret = net_pkt_write(pkt, buf, sizeof(buf));
zassert_true(ret == 0, "Pkt write failed");
zassert_true(net_pkt_get_len(pkt) == sizeof(buf),
"Pkt length mismatch");
net_pkt_cursor_init(pkt);
net_pkt_set_overwrite(pkt, true);
net_pkt_skip(pkt, 6);
zassert_true(sizeof(buf) - 6 == net_pkt_remaining_data(pkt),
"Pkt remaining data mismatch");
cloned_pkt = net_pkt_clone(pkt, K_NO_WAIT);
zassert_true(cloned_pkt != NULL, "Pkt not cloned");
zassert_true(net_pkt_get_len(cloned_pkt) == sizeof(buf),
"Cloned pkt length mismatch");
zassert_true(sizeof(buf) - 6 == net_pkt_remaining_data(pkt),
"Pkt remaining data mismatch");
zassert_true(sizeof(buf) - 6 == net_pkt_remaining_data(cloned_pkt),
"Cloned pkt remaining data mismatch");
net_pkt_unref(pkt);
net_pkt_unref(cloned_pkt);
}
void test_main(void)
{
eth_if = net_if_get_default();
@ -683,7 +722,8 @@ void test_main(void)
ztest_unit_test(test_net_pkt_advanced_basics),
ztest_unit_test(test_net_pkt_easier_rw_usage),
ztest_unit_test(test_net_pkt_copy),
ztest_unit_test(test_net_pkt_pull)
ztest_unit_test(test_net_pkt_pull),
ztest_unit_test(test_net_pkt_clone)
);
ztest_run_test_suite(net_pkt_tests);