diff mbox

[API-NEXT,2/2] validation: packet: add multi-segment head/tail push/pull tests

Message ID 1458497716-12483-2-git-send-email-bill.fischofer@linaro.org
State Superseded
Headers show

Commit Message

Bill Fischofer March 20, 2016, 6:15 p.m. UTC
Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>
---
 test/validation/packet/packet.c | 62 ++++++++++++++++++++++++++++++-----------
 1 file changed, 46 insertions(+), 16 deletions(-)
diff mbox

Patch

diff --git a/test/validation/packet/packet.c b/test/validation/packet/packet.c
index a764ed9..cebb295 100644
--- a/test/validation/packet/packet.c
+++ b/test/validation/packet/packet.c
@@ -366,19 +366,26 @@  static void _verify_headroom_shift(odp_packet_t packet,
 	void *data;
 	char *data_orig = odp_packet_data(packet);
 	char *head_orig = odp_packet_head(packet);
+	uint32_t seg_count_before = odp_packet_num_segs(packet);
+	uint32_t seg_count_after;
 
 	if (shift >= 0)
 		data = odp_packet_push_head(packet, shift);
 	else
 		data = odp_packet_pull_head(packet, -shift);
+	seg_count_after = odp_packet_num_segs(packet);
 
 	CU_ASSERT_PTR_NOT_NULL(data);
-	CU_ASSERT(odp_packet_headroom(packet) == room - shift);
-	CU_ASSERT(odp_packet_seg_len(packet) == seg_data_len + shift);
-	CU_ASSERT(odp_packet_len(packet) == pkt_data_len + shift);
-	CU_ASSERT(odp_packet_data(packet) == data);
-	CU_ASSERT(odp_packet_head(packet) == head_orig);
-	CU_ASSERT(data == data_orig - shift);
+	if (seg_count_before == seg_count_after) {
+		CU_ASSERT(odp_packet_headroom(packet) == room - shift);
+		CU_ASSERT(odp_packet_seg_len(packet) == seg_data_len + shift);
+		CU_ASSERT(odp_packet_len(packet) == pkt_data_len + shift);
+		CU_ASSERT(odp_packet_data(packet) == data);
+		CU_ASSERT(odp_packet_head(packet) == head_orig);
+		CU_ASSERT(data == data_orig - shift);
+	} else {
+		CU_ASSERT(data != NULL);
+	}
 }
 
 void packet_test_headroom(void)
@@ -403,6 +410,13 @@  void packet_test_headroom(void)
 	_verify_headroom_shift(pkt, push_val + pull_val);
 	_verify_headroom_shift(pkt, -push_val);
 	_verify_headroom_shift(pkt, 0);
+
+	if (segmentation_supported) {
+		push_val = room * 2;
+		_verify_headroom_shift(pkt, push_val);
+		_verify_headroom_shift(pkt, 0);
+		_verify_headroom_shift(pkt, -push_val);
+	}
 }
 
 static void _verify_tailroom_shift(odp_packet_t pkt,
@@ -413,6 +427,8 @@  static void _verify_tailroom_shift(odp_packet_t pkt,
 	uint32_t seg_data_len, pkt_data_len;
 	void *tail;
 	char *tail_orig;
+	uint32_t seg_count_before = odp_packet_num_segs(pkt);
+	uint32_t seg_count_after;
 
 	room = odp_packet_tailroom(pkt);
 	pkt_data_len = odp_packet_len(pkt);
@@ -437,19 +453,26 @@  static void _verify_tailroom_shift(odp_packet_t pkt,
 	} else {
 		tail = odp_packet_pull_tail(pkt, -shift);
 	}
+	seg_count_after = odp_packet_num_segs(pkt);
 
 	CU_ASSERT_PTR_NOT_NULL(tail);
-	CU_ASSERT(odp_packet_seg_data_len(pkt, seg) == seg_data_len + shift);
-	CU_ASSERT(odp_packet_len(pkt) == pkt_data_len + shift);
-	CU_ASSERT(odp_packet_tailroom(pkt) == room - shift);
-	if (room == 0 || (room - shift) == 0)
-		return;
-	if (shift >= 0) {
-		CU_ASSERT(odp_packet_tail(pkt) == tail_orig + shift);
-		CU_ASSERT(tail == tail_orig);
+
+	if (seg_count_before == seg_count_after) {
+		CU_ASSERT(odp_packet_seg_data_len(pkt, seg) ==
+			  seg_data_len + shift);
+		CU_ASSERT(odp_packet_len(pkt) == pkt_data_len + shift);
+		CU_ASSERT(odp_packet_tailroom(pkt) == room - shift);
+		if (room == 0 || (room - shift) == 0)
+			return;
+		if (shift >= 0) {
+			CU_ASSERT(odp_packet_tail(pkt) == tail_orig + shift);
+			CU_ASSERT(tail == tail_orig);
+		} else {
+			CU_ASSERT(odp_packet_tail(pkt) == tail);
+			CU_ASSERT(tail == tail_orig + shift);
+		}
 	} else {
-		CU_ASSERT(odp_packet_tail(pkt) == tail);
-		CU_ASSERT(tail == tail_orig + shift);
+		CU_ASSERT(odp_packet_data(pkt) != NULL);
 	}
 }
 
@@ -478,6 +501,13 @@  void packet_test_tailroom(void)
 	_verify_tailroom_shift(pkt, push_val + pull_val);
 	_verify_tailroom_shift(pkt, -push_val);
 	_verify_tailroom_shift(pkt, 0);
+
+	if (segmentation_supported) {
+		push_val = room * 2;
+		_verify_tailroom_shift(pkt, push_val);
+		_verify_tailroom_shift(pkt, 0);
+		_verify_tailroom_shift(pkt, -push_val);
+	}
 }
 
 void packet_test_segments(void)