diff mbox series

[v1,3/3] validation: timer: fix test failure

Message ID 1519146008-3368-4-git-send-email-odpbot@yandex.ru
State Superseded
Headers show
Series [v1,1/3] validation: timer: fix "Failed to set timer" error | expand

Commit Message

Github ODP bot Feb. 20, 2018, 5 p.m. UTC
From: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>


timer_main test was regularly failing due to worker code receiving
timeout events for cancelled timers in invalid state. However after
fixing implementation bug, several other asserts started to fail, as
they dependent on incorrect behaviour, like non-freshness of cancelled
events.

Fixes: https://bugs.linaro.org/show_bug.cgi?id=3517
Signed-off-by: Dmitry Eremin-Solenikov <dmitry.ereminsolenikov@linaro.org>

---
/** Email created from pull request 491 (lumag:timer-fix-2)
 ** https://github.com/Linaro/odp/pull/491
 ** Patch: https://github.com/Linaro/odp/pull/491.patch
 ** Base sha: d5419e8857b2bc61d3be17fe53f171550fee426b
 ** Merge commit sha: 1623e4e7c0742c5238c1b97abe1e8af93f091443
 **/
 test/validation/api/timer/timer.c | 27 ++++++++++++++-------------
 1 file changed, 14 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/test/validation/api/timer/timer.c b/test/validation/api/timer/timer.c
index c3b807aee..183c61e8d 100644
--- a/test/validation/api/timer/timer.c
+++ b/test/validation/api/timer/timer.c
@@ -275,15 +275,10 @@  static void handle_tmo(odp_event_t ev, bool stale, uint64_t prev_tick)
 		CU_FAIL("odp_timeout_user_ptr() wrong user ptr");
 	if (ttp && ttp->tim != tim)
 		CU_FAIL("odp_timeout_timer() wrong timer");
-	if (stale) {
-		if (odp_timeout_fresh(tmo))
-			CU_FAIL("Wrong status (fresh) for stale timeout");
-		/* Stale timeout => local timer must have invalid tick */
-		if (ttp && ttp->tick != TICK_INVALID)
-			CU_FAIL("Stale timeout for active timer");
-	} else {
-		if (!odp_timeout_fresh(tmo))
-			CU_FAIL("Wrong status (stale) for fresh timeout");
+
+	if (!odp_timeout_fresh(tmo))
+		CU_FAIL("Wrong status (stale) for fresh timeout");
+	if (!stale) {
 		/* Fresh timeout => local timer must have matching tick */
 		if (ttp && ttp->tick != tick) {
 			LOG_DBG("Wrong tick: expected %" PRIu64
@@ -291,6 +286,9 @@  static void handle_tmo(odp_event_t ev, bool stale, uint64_t prev_tick)
 				ttp->tick, tick);
 			CU_FAIL("odp_timeout_tick() wrong tick");
 		}
+		if (ttp && ttp->ev != ODP_EVENT_INVALID)
+			CU_FAIL("Wrong state for fresh timer (event)");
+
 		/* Check that timeout was delivered 'timely' */
 		if (tick > odp_timer_current_tick(tp))
 			CU_FAIL("Timeout delivered early");
@@ -404,11 +402,14 @@  static int worker_entrypoint(void *arg TEST_UNUSED)
 		    (rand_r(&seed) % 2 == 0)) {
 			/* Timer active, cancel it */
 			rc = odp_timer_cancel(tt[i].tim, &tt[i].ev);
-			if (rc != 0)
+			if (rc != 0) {
 				/* Cancel failed, timer already expired */
 				ntoolate++;
-			tt[i].tick = TICK_INVALID;
-			ncancel++;
+				LOG_DBG("Failed to cancel timer, probably already expired\n");
+			} else {
+				tt[i].tick = TICK_INVALID;
+				ncancel++;
+			}
 		} else {
 			if (tt[i].ev != ODP_EVENT_INVALID)
 				/* Timer inactive => set */
@@ -462,7 +463,7 @@  static int worker_entrypoint(void *arg TEST_UNUSED)
 		thr, ntoolate);
 	LOG_DBG("Thread %u: %" PRIu32 " timeouts received\n", thr, nrcv);
 	LOG_DBG("Thread %u: %" PRIu32
-		" stale timeout(s) after odp_timer_free()\n",
+		" stale timeout(s) after odp_timer_cancel()\n",
 		thr, nstale);
 
 	/* Delay some more to ensure timeouts for expired timers can be