@@ -1317,6 +1317,110 @@ 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[8];
+
+ 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[1] =
+ 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[1] != ODP_PACKET_INVALID);
+ hdr_len[1] = odp_packet_len(hdr_pkt[1]);
+ offset[1] = 0;
+
+ hdr_pkt[2] =
+ 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[2] != ODP_PACKET_INVALID);
+ hdr_len[2] = odp_packet_len(hdr_pkt[2]);
+ offset[2] = 5;
+
+ 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_spliced(hdr_pkt[1]) == 0);
+ CU_ASSERT(odp_packet_is_spliced(hdr_pkt[2]) == 0);
+
+ splice_pkt[1] = odp_packet_splice(hdr_pkt[1], base_pkt, offset[1]);
+ splice_pkt[2] = odp_packet_splice(hdr_pkt[2], base_pkt, offset[2]);
+
+ CU_ASSERT(splice_pkt[1] != ODP_PACKET_INVALID);
+ CU_ASSERT(splice_pkt[2] != ODP_PACKET_INVALID);
+
+ CU_ASSERT(odp_packet_is_a_splice(splice_pkt[1]) > 0);
+ CU_ASSERT(odp_packet_is_a_splice(splice_pkt[2]) > 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[1]) == 0);
+ CU_ASSERT(odp_packet_is_spliced(splice_pkt[2]) == 0);
+
+ CU_ASSERT(odp_packet_len(splice_pkt[1]) ==
+ hdr_len[1] + pkt_len - offset[1]);
+ CU_ASSERT(odp_packet_len(splice_pkt[2]) ==
+ hdr_len[2] + pkt_len - offset[2]);
+
+ _packet_compare_offset(splice_pkt[1], hdr_len[1],
+ base_pkt, offset[1],
+ pkt_len - offset[1]);
+
+ _packet_compare_offset(splice_pkt[2], hdr_len[2],
+ base_pkt, offset[2],
+ pkt_len - offset[2]);
+
+ odp_packet_free(splice_pkt[1]);
+ odp_packet_free(splice_pkt[2]);
+
+ CU_ASSERT(odp_packet_is_a_splice(base_pkt) == 0);
+ CU_ASSERT(odp_packet_is_spliced(base_pkt) == 0);
+
+ 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(segmented_base_pkt) == 1);
+
+ ref_pkt[2] = odp_packet_ref(segmented_base_pkt, offset[2]);
+ CU_ASSERT(odp_packet_is_a_splice(ref_pkt[2]) == 1);
+ CU_ASSERT(odp_packet_is_a_splice(segmented_base_pkt) == 0);
+ CU_ASSERT(odp_packet_is_spliced(ref_pkt[2]) == 0);
+ CU_ASSERT(odp_packet_is_spliced(segmented_base_pkt) == 2);
+
+ CU_ASSERT(odp_packet_len(ref_pkt[1]) == segmented_pkt_len - offset[1]);
+ CU_ASSERT(odp_packet_len(ref_pkt[2]) == segmented_pkt_len - offset[2]);
+
+ odp_packet_free(base_pkt);
+ odp_packet_free(segmented_base_pkt);
+
+ CU_ASSERT(odp_packet_is_a_splice(ref_pkt[1]) == 1);
+ CU_ASSERT(odp_packet_is_a_splice(ref_pkt[2]) == 1);
+
+ _packet_compare_offset(ref_pkt[1], 0,
+ segmented_test_packet, offset[1],
+ segmented_pkt_len - offset[1]);
+ _packet_compare_offset(ref_pkt[2], 0,
+ segmented_test_packet, offset[2],
+ segmented_pkt_len - offset[2]);
+
+ odp_packet_free(ref_pkt[1]);
+ odp_packet_free(ref_pkt[2]);
+}
+
odp_testinfo_t packet_suite[] = {
ODP_TEST_INFO(packet_test_alloc_free),
ODP_TEST_INFO(packet_test_alloc_free_multi),
@@ -1340,6 +1444,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,
};
@@ -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[];
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 | 105 ++++++++++++++++++++++++ test/common_plat/validation/api/packet/packet.h | 1 + 2 files changed, 106 insertions(+) -- 2.7.4