diff mbox series

[API-NEXT,v1,1/2] validation: pktio: recv tmo test improvements

Message ID 1517922007-6874-2-git-send-email-odpbot@yandex.ru
State New
Headers show
Series [API-NEXT,v1,1/2] validation: pktio: recv tmo test improvements | expand

Commit Message

Github ODP bot Feb. 6, 2018, 1 p.m. UTC
From: Petri Savolainen <petri.savolainen@linaro.org>


Add checks and improve test output when recv tmo function
fails to timeout correctly.

Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>

---
/** Email created from pull request 455 (psavol:next-fix-recv-tmo)
 ** https://github.com/Linaro/odp/pull/455
 ** Patch: https://github.com/Linaro/odp/pull/455.patch
 ** Base sha: 1836820278b57de6144c75872e148976d49d28a2
 ** Merge commit sha: 7aa3734cf260df25134c8b302983d3a79cf7c47c
 **/
 test/validation/api/pktio/pktio.c | 35 +++++++++++++++++++++++++++--------
 1 file changed, 27 insertions(+), 8 deletions(-)
diff mbox series

Patch

diff --git a/test/validation/api/pktio/pktio.c b/test/validation/api/pktio/pktio.c
index 6592b2600..53a36145b 100644
--- a/test/validation/api/pktio/pktio.c
+++ b/test/validation/api/pktio/pktio.c
@@ -511,7 +511,7 @@  static int wait_for_packets(pktio_info_t *pktio_rx, odp_packet_t pkt_tbl[],
 
 static int recv_packets_tmo(odp_pktio_t pktio, odp_packet_t pkt_tbl[],
 			    uint32_t seq_tbl[], int num, recv_tmo_mode_e mode,
-			    uint64_t tmo, uint64_t ns)
+			    uint64_t tmo, uint64_t ns, int no_pkt)
 {
 	odp_packet_t pkt_tmp[num];
 	odp_pktin_queue_t pktin[MAX_QUEUES];
@@ -542,8 +542,19 @@  static int recv_packets_tmo(odp_pktio_t pktio, odp_packet_t pkt_tbl[],
 						  num - num_rx, tmo);
 		ts2 = odp_time_global();
 
+		CU_ASSERT(n >= 0);
+
 		if (n <= 0)
 			break;
+
+		/* When we don't expect any packets, drop all packets and
+		 * retry timeout test. */
+		if (no_pkt) {
+			printf("    drop %i dummy packets\n", n);
+			odp_packet_free_multi(pkt_tmp, n);
+			continue;
+		}
+
 		for (i = 0; i < n; i++) {
 			if (pktio_pkt_seq(pkt_tmp[i]) == seq_tbl[num_rx])
 				pkt_tbl[num_rx++] = pkt_tmp[i];
@@ -554,8 +565,15 @@  static int recv_packets_tmo(odp_pktio_t pktio, odp_packet_t pkt_tbl[],
 			CU_ASSERT(from_val < (unsigned)num_q);
 	} while (num_rx < num);
 
-	if (num_rx < num)
-		CU_ASSERT(odp_time_diff_ns(ts2, ts1) >= ns);
+	if (num_rx < num) {
+		uint64_t diff = odp_time_diff_ns(ts2, ts1);
+
+		if (diff < ns)
+			printf("    diff %" PRIu64 ", ns %" PRIu64 "\n",
+			       diff, ns);
+
+		CU_ASSERT(diff >= ns);
+	}
 
 	return num_rx;
 }
@@ -967,8 +985,9 @@  static void test_recv_tmo(recv_tmo_mode_e mode)
 
 	/* No packets sent yet, so should wait */
 	ns = 100 * ODP_TIME_MSEC_IN_NS;
+
 	ret = recv_packets_tmo(pktio_rx, &pkt_tbl[0], &pkt_seq[0], 1, mode,
-			       odp_pktin_wait_time(ns), ns);
+			       odp_pktin_wait_time(ns), ns, 1);
 	CU_ASSERT(ret == 0);
 
 	ret = create_packets(pkt_tbl, pkt_seq, test_pkt_count, pktio_tx,
@@ -979,19 +998,19 @@  static void test_recv_tmo(recv_tmo_mode_e mode)
 	CU_ASSERT_FATAL(ret == test_pkt_count);
 
 	ret = recv_packets_tmo(pktio_rx, &pkt_tbl[0], &pkt_seq[0], 1, mode,
-			       odp_pktin_wait_time(UINT64_MAX), 0);
+			       odp_pktin_wait_time(UINT64_MAX), 0, 0);
 	CU_ASSERT_FATAL(ret == 1);
 
 	ret = recv_packets_tmo(pktio_rx, &pkt_tbl[1], &pkt_seq[1], 1, mode,
-			       ODP_PKTIN_NO_WAIT, 0);
+			       ODP_PKTIN_NO_WAIT, 0, 0);
 	CU_ASSERT_FATAL(ret == 1);
 
 	ret = recv_packets_tmo(pktio_rx, &pkt_tbl[2], &pkt_seq[2], 1, mode,
-			       odp_pktin_wait_time(0), 0);
+			       odp_pktin_wait_time(0), 0, 0);
 	CU_ASSERT_FATAL(ret == 1);
 
 	ret = recv_packets_tmo(pktio_rx, &pkt_tbl[3], &pkt_seq[3], 3, mode,
-			       odp_pktin_wait_time(ns), ns);
+			       odp_pktin_wait_time(ns), ns, 0);
 	CU_ASSERT_FATAL(ret == 3);
 
 	for (i = 0; i < test_pkt_count; i++)