From b45b1e393c954d73276f8e627d229b1367f44313 Mon Sep 17 00:00:00 2001 From: David D Date: Sun, 2 Feb 2020 06:33:08 +0200 Subject: [PATCH] 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 --- tests/net/net_pkt/src/main.c | 46 ++++++++++++++++++++++++++++++++- tests/net/net_pkt/testcase.yaml | 6 +++++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/tests/net/net_pkt/src/main.c b/tests/net/net_pkt/src/main.c index e459844ab97fe7..fc662a4daf4c4d 100644 --- a/tests/net/net_pkt/src/main.c +++ b/tests/net/net_pkt/src/main.c @@ -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); diff --git a/tests/net/net_pkt/testcase.yaml b/tests/net/net_pkt/testcase.yaml index 37c05a5f73d538..3c06095236504e 100644 --- a/tests/net/net_pkt/testcase.yaml +++ b/tests/net/net_pkt/testcase.yaml @@ -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