Skip to content

Commit

Permalink
test: net: pkt: Added a test case for net_pkt_pull()
Browse files Browse the repository at this point in the history
Added a test case for net_pkt_pull() with large packet buffers

Signed-off-by: David D <[email protected]>
  • Loading branch information
a8961713 authored and jukkar committed Feb 3, 2020
1 parent 3de9677 commit b45b1e3
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
46 changes: 45 additions & 1 deletion tests/net/net_pkt/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,49 @@ void test_net_pkt_copy(void)
"Pkt not properly unreferenced");
}

#define PULL_TEST_PKT_DATA_SIZE 600

void test_net_pkt_pull(void)
{
const int PULL_AMOUNT = 8;
struct net_pkt *dummy_pkt;
static u8_t pkt_data[PULL_TEST_PKT_DATA_SIZE];
static u8_t pkt_data_readback[PULL_TEST_PKT_DATA_SIZE];
int i;

for (i = 0; i < PULL_TEST_PKT_DATA_SIZE; ++i) {
pkt_data[i] = i & 0xff;
}

dummy_pkt = net_pkt_alloc_with_buffer(eth_if,
PULL_TEST_PKT_DATA_SIZE,
AF_UNSPEC,
0,
K_NO_WAIT);
zassert_true(dummy_pkt != NULL, "Pkt not allocated");

zassert_true(net_pkt_write(dummy_pkt,
pkt_data,
PULL_TEST_PKT_DATA_SIZE) == 0,
"Write packet failed");

net_pkt_cursor_init(dummy_pkt);
net_pkt_pull(dummy_pkt, PULL_AMOUNT);
zassert_equal(net_pkt_get_len(dummy_pkt),
PULL_TEST_PKT_DATA_SIZE - PULL_AMOUNT,
"Pull failed to set new size");
zassert_true(net_pkt_read(dummy_pkt,
pkt_data_readback,
PULL_TEST_PKT_DATA_SIZE - PULL_AMOUNT) == 0,
"Read packet failed");
zassert_mem_equal(pkt_data_readback,
&pkt_data[PULL_AMOUNT],
PULL_TEST_PKT_DATA_SIZE - PULL_AMOUNT,
"Packet data changed");

net_pkt_unref(dummy_pkt);
}

void test_main(void)
{
eth_if = net_if_get_default();
Expand All @@ -639,7 +682,8 @@ void test_main(void)
ztest_unit_test(test_net_pkt_basics_of_rw),
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_copy),
ztest_unit_test(test_net_pkt_pull)
);

ztest_run_test_suite(net_pkt_tests);
Expand Down
6 changes: 6 additions & 0 deletions tests/net/net_pkt/testcase.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@ tests:
net.packet:
min_ram: 20
tags: net
net.packet.large_buffer:
min_ram: 20
tags: net
extra_configs:
- CONFIG_NET_BUF_FIXED_DATA_SIZE=y
- CONFIG_NET_BUF_DATA_SIZE=512

0 comments on commit b45b1e3

Please sign in to comment.