diff mbox

[API-NEXT,PATCHv6,3/5] validation: packet: add packet splice/reference tests

Message ID 1476157506-11032-4-git-send-email-bill.fischofer@linaro.org
State New
Headers show

Commit Message

Bill Fischofer Oct. 11, 2016, 3:45 a.m. UTC
Add validation tests for the new packet splice/reference APIs:
- odp_packet_splice()
- odp_packet_ref()
- odp_packet_is_a_splice()
- odp_packet_spliced()

Signed-off-by: Bill Fischofer <bill.fischofer@linaro.org>

---
 test/common_plat/validation/api/packet/packet.c | 176 ++++++++++++++++++++++++
 test/common_plat/validation/api/packet/packet.h |   1 +
 2 files changed, 177 insertions(+)

-- 
2.7.4
diff mbox

Patch

diff --git a/test/common_plat/validation/api/packet/packet.c b/test/common_plat/validation/api/packet/packet.c
index a4426e2..f5c07e0 100644
--- a/test/common_plat/validation/api/packet/packet.c
+++ b/test/common_plat/validation/api/packet/packet.c
@@ -1317,6 +1317,181 @@  void packet_test_offset(void)
 	CU_ASSERT_PTR_NOT_NULL(ptr);
 }
 
+void packet_test_splice(void)
+{
+	odp_packet_t base_pkt, segmented_base_pkt, hdr_pkt[4],
+		ref_pkt[4], splice_pkt[4];
+	uint32_t pkt_len, segmented_pkt_len, hdr_len[4], offset[4];
+
+	base_pkt = odp_packet_copy(test_packet, odp_packet_pool(test_packet));
+	pkt_len  = odp_packet_len(test_packet);
+	CU_ASSERT_FATAL(base_pkt != ODP_PACKET_INVALID);
+
+	segmented_base_pkt =
+		odp_packet_copy(segmented_test_packet,
+				odp_packet_pool(segmented_test_packet));
+	segmented_pkt_len = odp_packet_len(segmented_test_packet);
+	CU_ASSERT_FATAL(segmented_base_pkt != ODP_PACKET_INVALID);
+
+	CU_ASSERT(odp_packet_is_a_splice(base_pkt) == 0);
+	CU_ASSERT(odp_packet_is_spliced(base_pkt) == 0);
+
+	hdr_pkt[0] =
+		odp_packet_copy_part(segmented_test_packet, 0,
+				     odp_packet_len(segmented_test_packet) / 4,
+				     odp_packet_pool(segmented_test_packet));
+	CU_ASSERT_FATAL(hdr_pkt[0] != ODP_PACKET_INVALID);
+	hdr_len[0] = odp_packet_len(hdr_pkt[0]);
+	offset[0]  = 0;
+
+	hdr_pkt[1] =
+		odp_packet_copy_part(segmented_test_packet, 10,
+				     odp_packet_len(segmented_test_packet) / 8,
+				     odp_packet_pool(segmented_test_packet));
+	CU_ASSERT_FATAL(hdr_pkt[1] != ODP_PACKET_INVALID);
+	hdr_len[1] = odp_packet_len(hdr_pkt[1]);
+	offset[1]  = 5;
+
+	hdr_pkt[2] = odp_packet_copy_part(test_packet, 0,
+					  odp_packet_len(test_packet) / 4,
+					  odp_packet_pool(test_packet));
+	CU_ASSERT_FATAL(hdr_pkt[2] != ODP_PACKET_INVALID);
+	hdr_len[2] = odp_packet_len(hdr_pkt[2]);
+	offset[2]  = 64;
+
+	hdr_pkt[3] = odp_packet_copy_part(test_packet, 0,
+					  odp_packet_len(test_packet) / 4,
+					  odp_packet_pool(test_packet));
+	CU_ASSERT_FATAL(hdr_pkt[3] != ODP_PACKET_INVALID);
+	hdr_len[3] = odp_packet_len(hdr_pkt[3]);
+	offset[3]  = 64;
+
+	/* Nothing is a splice or is spliced before we start */
+	CU_ASSERT(odp_packet_is_a_splice(hdr_pkt[0]) == 0);
+	CU_ASSERT(odp_packet_is_a_splice(hdr_pkt[1]) == 0);
+	CU_ASSERT(odp_packet_is_a_splice(hdr_pkt[2]) == 0);
+	CU_ASSERT(odp_packet_is_a_splice(hdr_pkt[3]) == 0);
+	CU_ASSERT(odp_packet_is_spliced(hdr_pkt[0]) == 0);
+	CU_ASSERT(odp_packet_is_spliced(hdr_pkt[1]) == 0);
+	CU_ASSERT(odp_packet_is_spliced(hdr_pkt[2]) == 0);
+	CU_ASSERT(odp_packet_is_spliced(hdr_pkt[3]) == 0);
+
+	/* Attempt an invalid splice */
+	splice_pkt[0] = odp_packet_splice(hdr_pkt[0], base_pkt, pkt_len);
+	CU_ASSERT(splice_pkt[0] == ODP_PACKET_INVALID);
+	CU_ASSERT(odp_packet_is_a_splice(hdr_pkt[0]) == 0);
+	CU_ASSERT(odp_packet_is_a_splice(base_pkt) == 0);
+	CU_ASSERT(odp_packet_is_spliced(hdr_pkt[0]) == 0);
+	CU_ASSERT(odp_packet_is_spliced(base_pkt) == 0);
+
+	/* We can't splice to ourselves */
+	splice_pkt[0] = odp_packet_splice(hdr_pkt[0], hdr_pkt[0], 0);
+	CU_ASSERT(splice_pkt[0] == ODP_PACKET_INVALID);
+	CU_ASSERT(odp_packet_is_a_splice(hdr_pkt[0]) == 0);
+	CU_ASSERT(odp_packet_is_spliced(hdr_pkt[0]) == 0);
+
+	/* Now create a couple of valid splices */
+	splice_pkt[0] = odp_packet_splice(hdr_pkt[0], base_pkt, offset[0]);
+	splice_pkt[1] = odp_packet_splice(hdr_pkt[1], base_pkt, offset[1]);
+
+	CU_ASSERT(splice_pkt[0] != ODP_PACKET_INVALID);
+	CU_ASSERT(splice_pkt[1] != ODP_PACKET_INVALID);
+
+	CU_ASSERT(odp_packet_is_a_splice(splice_pkt[0]) > 0);
+	CU_ASSERT(odp_packet_is_a_splice(splice_pkt[1]) > 0);
+	CU_ASSERT(odp_packet_is_a_splice(base_pkt) == 0);
+
+	CU_ASSERT(odp_packet_is_spliced(base_pkt) == 2);
+	CU_ASSERT(odp_packet_is_spliced(splice_pkt[0]) == 0);
+	CU_ASSERT(odp_packet_is_spliced(splice_pkt[1]) == 0);
+
+	/* Verify splice lenghts and contents */
+	CU_ASSERT(odp_packet_len(splice_pkt[0]) ==
+		  hdr_len[0] + pkt_len - offset[0]);
+	CU_ASSERT(odp_packet_len(splice_pkt[1]) ==
+		  hdr_len[1] + pkt_len - offset[1]);
+
+	_packet_compare_offset(splice_pkt[0], hdr_len[0],
+			       base_pkt, offset[0],
+			       pkt_len - offset[0]);
+
+	_packet_compare_offset(splice_pkt[1], hdr_len[1],
+			       base_pkt, offset[1],
+			       pkt_len - offset[1]);
+
+	/* Delete the splices */
+	odp_packet_free(splice_pkt[0]);
+	odp_packet_free(splice_pkt[1]);
+
+	/* Verify that base_pkt is no longer spliced */
+	CU_ASSERT(odp_packet_is_a_splice(base_pkt) == 0);
+	CU_ASSERT(odp_packet_is_spliced(base_pkt) == 0);
+
+	/* Now create a two more shared splices */
+	splice_pkt[2] = odp_packet_splice(hdr_pkt[2], base_pkt, offset[2]);
+	splice_pkt[3] = odp_packet_splice(hdr_pkt[3], base_pkt, offset[3]);
+
+	CU_ASSERT(splice_pkt[2] != ODP_PACKET_INVALID);
+	CU_ASSERT(splice_pkt[3] != ODP_PACKET_INVALID);
+	CU_ASSERT(odp_packet_is_a_splice(splice_pkt[2]) == 1);
+	CU_ASSERT(odp_packet_is_a_splice(splice_pkt[3]) == 1);
+	CU_ASSERT(odp_packet_is_spliced(base_pkt) == 2);
+
+	CU_ASSERT(odp_packet_len(splice_pkt[2]) ==
+		  odp_packet_len(splice_pkt[3]));
+
+	_packet_compare_offset(splice_pkt[2], 0,
+			       splice_pkt[3], 0,
+			       odp_packet_len(splice_pkt[2]));
+
+	/* Delete the splices */
+	odp_packet_free(splice_pkt[2]);
+	odp_packet_free(splice_pkt[3]);
+
+	/* Verify that base_pkt is no longer spliced */
+	CU_ASSERT(odp_packet_is_a_splice(base_pkt) == 0);
+	CU_ASSERT(odp_packet_is_spliced(base_pkt) == 0);
+
+	/* Create an invalid reference */
+	ref_pkt[0] = odp_packet_ref(segmented_base_pkt, segmented_pkt_len);
+	CU_ASSERT(ref_pkt[0] == ODP_PACKET_INVALID);
+	CU_ASSERT(odp_packet_is_a_splice(segmented_base_pkt) == 0);
+	CU_ASSERT(odp_packet_is_spliced(segmented_base_pkt) == 0);
+
+	/* Now create valid references */
+	ref_pkt[0] = odp_packet_ref(segmented_base_pkt, offset[0]);
+	CU_ASSERT(odp_packet_is_a_splice(ref_pkt[0]) == 1);
+	CU_ASSERT(odp_packet_is_a_splice(segmented_base_pkt) == 0);
+	CU_ASSERT(odp_packet_is_spliced(segmented_base_pkt) == 1);
+
+	ref_pkt[1] = odp_packet_ref(segmented_base_pkt, offset[1]);
+	CU_ASSERT(odp_packet_is_a_splice(ref_pkt[1]) == 1);
+	CU_ASSERT(odp_packet_is_a_splice(segmented_base_pkt) == 0);
+	CU_ASSERT(odp_packet_is_spliced(ref_pkt[1]) == 0);
+	CU_ASSERT(odp_packet_is_spliced(segmented_base_pkt) == 2);
+
+	/* Verify reference lengths */
+	CU_ASSERT(odp_packet_len(ref_pkt[0]) == segmented_pkt_len - offset[0]);
+	CU_ASSERT(odp_packet_len(ref_pkt[1]) == segmented_pkt_len - offset[1]);
+
+	/* Free the base pkts -- references should still be valid */
+	odp_packet_free(base_pkt);
+	odp_packet_free(segmented_base_pkt);
+
+	CU_ASSERT(odp_packet_is_a_splice(ref_pkt[0]) == 1);
+	CU_ASSERT(odp_packet_is_a_splice(ref_pkt[1]) == 1);
+
+	_packet_compare_offset(ref_pkt[0], 0,
+			       segmented_test_packet, offset[0],
+			       segmented_pkt_len - offset[0]);
+	_packet_compare_offset(ref_pkt[1], 0,
+			       segmented_test_packet, offset[1],
+			       segmented_pkt_len - offset[1]);
+
+	odp_packet_free(ref_pkt[0]);
+	odp_packet_free(ref_pkt[1]);
+}
+
 odp_testinfo_t packet_suite[] = {
 	ODP_TEST_INFO(packet_test_alloc_free),
 	ODP_TEST_INFO(packet_test_alloc_free_multi),
@@ -1340,6 +1515,7 @@  odp_testinfo_t packet_suite[] = {
 	ODP_TEST_INFO(packet_test_concatsplit),
 	ODP_TEST_INFO(packet_test_align),
 	ODP_TEST_INFO(packet_test_offset),
+	ODP_TEST_INFO(packet_test_splice),
 	ODP_TEST_INFO_NULL,
 };
 
diff --git a/test/common_plat/validation/api/packet/packet.h b/test/common_plat/validation/api/packet/packet.h
index 10a377c..25d2248 100644
--- a/test/common_plat/validation/api/packet/packet.h
+++ b/test/common_plat/validation/api/packet/packet.h
@@ -32,6 +32,7 @@  void packet_test_copydata(void);
 void packet_test_concatsplit(void);
 void packet_test_align(void);
 void packet_test_offset(void);
+void packet_test_splice(void);
 
 /* test arrays: */
 extern odp_testinfo_t packet_suite[];