diff mbox

[API-NEXT,PATCHv2,3/3] validation: packet: test packet reference count

Message ID 1441975993-4687-4-git-send-email-maxim.uvarov@linaro.org
State New
Headers show

Commit Message

Maxim Uvarov Sept. 11, 2015, 12:53 p.m. UTC
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(+)
diff mbox

Patch

diff --git a/test/validation/packet/packet.c b/test/validation/packet/packet.c
index 0c749c3..94d03e0 100644
--- a/test/validation/packet/packet.c
+++ b/test/validation/packet/packet.c
@@ -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,
 };
 
diff --git a/test/validation/packet/packet.h b/test/validation/packet/packet.h
index f8a16a8..d1feff8 100644
--- a/test/validation/packet/packet.h
+++ b/test/validation/packet/packet.h
@@ -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[];