test: net: pkt: Added a test case for net_pkt_pull()

Added a test case for net_pkt_pull() with large packet buffers

Signed-off-by: David D <a8961713@gmail.com>
This commit is contained in:
David D 2020-02-02 06:33:08 +02:00 committed by Jukka Rissanen
commit b45b1e393c
2 changed files with 51 additions and 1 deletions

View file

@ -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();
@ -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);

View file

@ -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