Skip to content

Commit

Permalink
validation: packet: improve odp_packet_reset() test coverage
Browse files Browse the repository at this point in the history
Improve odp_packet_reset() test coverage by extending packet data into
available tailroom. Also, try to configure some headroom to test packets.

Signed-off-by: Matias Elo <[email protected]>
Reviewed-by: Tuomas Taipale <[email protected]>
  • Loading branch information
MatiasElo committed May 21, 2024
1 parent e00a940 commit 507cefd
Showing 1 changed file with 32 additions and 3 deletions.
35 changes: 32 additions & 3 deletions test/validation/api/packet/packet.c
Original file line number Diff line number Diff line change
Expand Up @@ -907,14 +907,21 @@ static void packet_test_length(void)

static void packet_test_reset(void)
{
uint32_t len, max_len, headroom;
uint32_t len, max_len, headroom = 128, tailroom;
uint32_t uarea_size = default_param.pkt.uarea_size;
uintptr_t ptr_len;
void *data, *new_data, *tail, *new_tail;
void *data, *new_data, *head, *tail, *new_tail;
struct udata_struct *udat;
odp_packet_t pkt;
odp_pool_t pool;
odp_pool_param_t pool_param = default_param;

pkt = odp_packet_alloc(default_pool, packet_len);
pool_param.pkt.headroom = ODPH_MIN(pool_capa.pkt.max_headroom, headroom);

pool = odp_pool_create("packet reset", &pool_param);
CU_ASSERT_FATAL(pool != ODP_POOL_INVALID);

pkt = odp_packet_alloc(pool, packet_len);
CU_ASSERT_FATAL(pkt != ODP_PACKET_INVALID);

if (uarea_size) {
Expand All @@ -929,6 +936,7 @@ static void packet_test_reset(void)
CU_ASSERT(len == packet_len);

headroom = odp_packet_headroom(pkt);
CU_ASSERT(headroom >= pool_param.pkt.headroom);

if (headroom) {
data = odp_packet_data(pkt);
Expand All @@ -947,6 +955,25 @@ static void packet_test_reset(void)
CU_ASSERT(ptr_len == headroom);
}

tailroom = odp_packet_tailroom(pkt);

if (tailroom) {
data = odp_packet_data(pkt);
head = odp_packet_head(pkt);
tail = odp_packet_tail(pkt);
headroom = odp_packet_headroom(pkt);

CU_ASSERT(odp_packet_push_tail(pkt, tailroom) == tail);
CU_ASSERT(odp_packet_pull_head(pkt, tailroom) != NULL);

odp_packet_reset(pkt, len);
CU_ASSERT(odp_packet_data(pkt) == data);
CU_ASSERT(odp_packet_head(pkt) == head);
CU_ASSERT(odp_packet_tail(pkt) == tail);
CU_ASSERT(odp_packet_headroom(pkt) == headroom);
CU_ASSERT(odp_packet_tailroom(pkt) == tailroom);
}

data = odp_packet_data(pkt);
new_data = odp_packet_pull_head(pkt, 1);
CU_ASSERT(odp_packet_len(pkt) == len - 1);
Expand Down Expand Up @@ -998,6 +1025,8 @@ static void packet_test_reset(void)
}

odp_packet_free(pkt);

CU_ASSERT(odp_pool_destroy(pool) == 0);
}

static void packet_test_reset_meta(void)
Expand Down

0 comments on commit 507cefd

Please sign in to comment.