[3/3] validation: packet: add tests for odp_packet_zero_data()

Message ID 1493215206-6131-3-git-send-email-odpbot@yandex.ru
State New
Headers show
Series
  • Untitled series #1243
Related show

Commit Message

Github ODP bot April 26, 2017, 2 p.m.
From: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>


Check that odp_packet_zero_data() works with single-segment packets and
with segmented packets.

Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>

---
/** Email created from pull request 18 (lumag:packet-zero)
 ** https://github.com/Linaro/odp/pull/18
 ** Patch: https://github.com/Linaro/odp/pull/18.patch
 ** Base sha: bac3806356694060d30bf3c83e4133410fecd9ab
 ** Merge commit sha: a44d13fa3221bf63f7cfe5a00acb07d49dd6abc9
 **/
 test/common_plat/validation/api/packet/packet.c | 39 +++++++++++++++++++++++++
 test/common_plat/validation/api/packet/packet.h |  1 +
 2 files changed, 40 insertions(+)

Patch

diff --git a/test/common_plat/validation/api/packet/packet.c b/test/common_plat/validation/api/packet/packet.c
index 284aaeb..5d3ad83 100644
--- a/test/common_plat/validation/api/packet/packet.c
+++ b/test/common_plat/validation/api/packet/packet.c
@@ -1292,6 +1292,44 @@  void packet_test_copydata(void)
 	odp_packet_free(pkt);
 }
 
+static
+void packet_test_zerodata_pkt(odp_packet_t pkt)
+{
+	uint32_t pkt_len = odp_packet_len(pkt);
+	uint8_t *data_buf;
+	uint32_t i;
+	int correct_memory;
+
+	CU_ASSERT_FATAL(pkt_len > 0);
+
+	data_buf = malloc(pkt_len);
+	CU_ASSERT_PTR_NOT_NULL_FATAL(data_buf);
+
+	for (i = 0; i < pkt_len; i++)
+		data_buf[i] = (uint8_t)i;
+
+	CU_ASSERT(!odp_packet_copy_from_mem(pkt, 0, pkt_len, data_buf));
+	CU_ASSERT(!odp_packet_zero_data(pkt, 0, pkt_len));
+	memset(data_buf, 0xff, pkt_len);
+	CU_ASSERT(!odp_packet_copy_to_mem(pkt, 0, pkt_len, data_buf));
+
+	correct_memory = 1;
+	for (i = 0; i < pkt_len; i++)
+		if (data_buf[i] != 0) {
+			correct_memory = 0;
+			break;
+		}
+	CU_ASSERT(correct_memory);
+
+	free(data_buf);
+}
+
+void packet_test_zerodata(void)
+{
+	packet_test_zerodata_pkt(test_packet);
+	packet_test_zerodata_pkt(segmented_test_packet);
+}
+
 void packet_test_concatsplit(void)
 {
 	odp_packet_t pkt, pkt2;
@@ -2412,6 +2450,7 @@  odp_testinfo_t packet_suite[] = {
 	ODP_TEST_INFO(packet_test_add_rem_data),
 	ODP_TEST_INFO(packet_test_copy),
 	ODP_TEST_INFO(packet_test_copydata),
+	ODP_TEST_INFO(packet_test_zerodata),
 	ODP_TEST_INFO(packet_test_concatsplit),
 	ODP_TEST_INFO(packet_test_concat_small),
 	ODP_TEST_INFO(packet_test_concat_extend_trunc),
diff --git a/test/common_plat/validation/api/packet/packet.h b/test/common_plat/validation/api/packet/packet.h
index 783b7a1..42d2f4c 100644
--- a/test/common_plat/validation/api/packet/packet.h
+++ b/test/common_plat/validation/api/packet/packet.h
@@ -29,6 +29,7 @@  void packet_test_error_flags(void);
 void packet_test_add_rem_data(void);
 void packet_test_copy(void);
 void packet_test_copydata(void);
+void packet_test_zerodata(void);
 void packet_test_concatsplit(void);
 void packet_test_concat_small(void);
 void packet_test_concat_extend_trunc(void);