@@ -778,6 +778,41 @@ void packet_test_offset(void)
CU_ASSERT_PTR_NOT_NULL(ptr);
}
+void packet_test_ref(void)
+{
+ odp_packet_t pkt = test_packet;
+ odp_packet_t pkt_ref;
+ uint32_t pkt_len = odp_packet_len(pkt);
+ uint8_t *data_buf1;
+ uint8_t *data_buf2;
+
+ data_buf1 = malloc(pkt_len);
+ CU_ASSERT_PTR_NOT_NULL_FATAL(data_buf1);
+ data_buf2 = malloc(pkt_len);
+ CU_ASSERT_PTR_NOT_NULL_FATAL(data_buf2);
+
+ pkt_ref = odp_packet_create_ref(pkt);
+ /* Handles should be different */
+ CU_ASSERT(pkt != pkt_ref);
+ /* Debug print also should have refcount bits */
+ CU_ASSERT(odp_packet_to_u64(pkt) !=
+ odp_packet_to_u64(pkt_ref));
+
+ /* Check that packet data is the same for pkt and pkt_ref */
+ CU_ASSERT(!odp_packet_copydata_out(pkt, 0, pkt_len, data_buf1));
+ CU_ASSERT(!odp_packet_copydata_out(pkt_ref, 0, pkt_len, data_buf2));
+ CU_ASSERT(!memcmp(data_buf1, data_buf2, pkt_len));
+
+ odp_packet_free(pkt_ref);
+
+ /* Check original packet data after free reference. */
+ CU_ASSERT(!odp_packet_copydata_out(pkt, 0, pkt_len, data_buf2));
+ CU_ASSERT(!memcmp(data_buf1, data_buf2, pkt_len));
+
+ free(data_buf1);
+ free(data_buf2);
+}
+
CU_TestInfo packet_suite[] = {
_CU_TEST_INFO(packet_test_alloc_free),
_CU_TEST_INFO(packet_test_alloc_segmented),
@@ -797,6 +832,7 @@ CU_TestInfo packet_suite[] = {
_CU_TEST_INFO(packet_test_copy),
_CU_TEST_INFO(packet_test_copydata),
_CU_TEST_INFO(packet_test_offset),
+ _CU_TEST_INFO(packet_test_ref),
CU_TEST_INFO_NULL,
};
@@ -28,6 +28,7 @@ void packet_test_add_rem_data(void);
void packet_test_copy(void);
void packet_test_copydata(void);
void packet_test_offset(void);
+void packet_test_ref(void);
/* test arrays: */
extern CU_TestInfo packet_suite[];
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org> --- test/validation/packet/packet.c | 36 ++++++++++++++++++++++++++++++++++++ test/validation/packet/packet.h | 1 + 2 files changed, 37 insertions(+)