diff mbox

[API-NEXT,PATCHv4] validation: increase timer expiration wait time

Message ID 1452845274-11510-1-git-send-email-maxim.uvarov@linaro.org
State Superseded
Headers show

Commit Message

Maxim Uvarov Jan. 15, 2016, 8:07 a.m. UTC
Following current test logic validation test should correctly
wait for all scheduled timer expirations. Setting that time
to 1ms is not correct due to code above schedules timer to 1.1ms
and context switch in linux takes 10ms.

Problem that odp_timer_pool_destroy() does not disarm all trigered
timers before freeing pool shared memory still exist. That should
be covered with separate test case.

Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
---
 test/validation/timer/timer.c | 38 ++++++++++++++++++++++++--------------
 1 file changed, 24 insertions(+), 14 deletions(-)

Comments

Maxim Uvarov Jan. 15, 2016, 9:18 a.m. UTC | #1
it has to be v1, please skip it. Resend 2 new patches for that issue.

Maxim.

On 01/15/2016 11:07, Maxim Uvarov wrote:
> Following current test logic validation test should correctly
> wait for all scheduled timer expirations. Setting that time
> to 1ms is not correct due to code above schedules timer to 1.1ms
> and context switch in linux takes 10ms.
>
> Problem that odp_timer_pool_destroy() does not disarm all trigered
> timers before freeing pool shared memory still exist. That should
> be covered with separate test case.
>
> Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
> ---
>   test/validation/timer/timer.c | 38 ++++++++++++++++++++++++--------------
>   1 file changed, 24 insertions(+), 14 deletions(-)
>
> diff --git a/test/validation/timer/timer.c b/test/validation/timer/timer.c
> index dda5e4c..db0a5ca 100644
> --- a/test/validation/timer/timer.c
> +++ b/test/validation/timer/timer.c
> @@ -266,6 +266,23 @@ static void handle_tmo(odp_event_t ev, bool stale, uint64_t prev_tick)
>   	}
>   }
>
> +/* Delay to ensure timeouts for expired timers can be
> + * received.
> + * Delay time = (max timer expiration time) +
> + *		(timer handler execution time) +
> + *		(system overhead for thread creation and schedule
> + *		 context switches)
> + */
> +static void _wait_for_timers_expiration(void)
> +{
> +	struct timespec ts;
> +
> +	ts.tv_sec = 0;
> +	ts.tv_nsec = 50 * ODP_TIME_MSEC_IN_NS;
> +	if (nanosleep(&ts, NULL) < 0)
> +		CU_FAIL_FATAL("nanosleep failed");
> +}
> +
>   /* @private Worker thread entrypoint which performs timer alloc/set/cancel/free
>    * tests */
>   static void *worker_entrypoint(void *arg TEST_UNUSED)
> @@ -305,7 +322,7 @@ static void *worker_entrypoint(void *arg TEST_UNUSED)
>   		uint64_t tck = odp_timer_current_tick(tp) + 1 +
>   			       odp_timer_ns_to_tick(tp,
>   						    (rand_r(&seed) % RANGE_MS)
> -						    * 1000000ULL);
> +						    * ODP_TIME_MSEC_IN_NS);
>   		odp_timer_set_t rc;
>   		rc = odp_timer_set_abs(tt[i].tim, tck, &tt[i].ev);
>   		if (rc != ODP_TIMER_SUCCESS) {
> @@ -351,7 +368,8 @@ static void *worker_entrypoint(void *arg TEST_UNUSED)
>   				/* Timer active => reset */
>   				nreset++;
>   			uint64_t tck = 1 + odp_timer_ns_to_tick(tp,
> -				       (rand_r(&seed) % RANGE_MS) * 1000000ULL);
> +				       (rand_r(&seed) % RANGE_MS) *
> +				       ODP_TIME_MSEC_IN_NS);
>   			odp_timer_set_t rc;
>   			uint64_t cur_tick;
>   			/* Loop until we manage to read cur_tick and set a
> @@ -372,11 +390,8 @@ static void *worker_entrypoint(void *arg TEST_UNUSED)
>   				tt[i].tick = cur_tick + tck;
>   			}
>   		}
> -		struct timespec ts;
> -		ts.tv_sec = 0;
> -		ts.tv_nsec = 1000000; /* 1ms */
> -		if (nanosleep(&ts, NULL) < 0)
> -			CU_FAIL_FATAL("nanosleep failed");
> +
> +		_wait_for_timers_expiration();
>   	}
>
>   	/* Cancel and free all timers */
> @@ -401,13 +416,8 @@ static void *worker_entrypoint(void *arg TEST_UNUSED)
>   	LOG_DBG("Thread %u: %" PRIu32 " stale timeout(s) after odp_timer_free()\n",
>   		thr, nstale);
>
> -	/* Delay some more to ensure timeouts for expired timers can be
> -	 * received */
> -	struct timespec ts;
> -	ts.tv_sec = 0;
> -	ts.tv_nsec = 1000000; /* 1ms */
> -	if (nanosleep(&ts, NULL) < 0)
> -		CU_FAIL_FATAL("nanosleep failed");
> +	_wait_for_timers_expiration();
> +
>   	while (nstale != 0) {
>   		odp_event_t ev = odp_queue_deq(queue);
>   		if (ev != ODP_EVENT_INVALID) {
diff mbox

Patch

diff --git a/test/validation/timer/timer.c b/test/validation/timer/timer.c
index dda5e4c..db0a5ca 100644
--- a/test/validation/timer/timer.c
+++ b/test/validation/timer/timer.c
@@ -266,6 +266,23 @@  static void handle_tmo(odp_event_t ev, bool stale, uint64_t prev_tick)
 	}
 }
 
+/* Delay to ensure timeouts for expired timers can be
+ * received.
+ * Delay time = (max timer expiration time) +
+ *		(timer handler execution time) +
+ *		(system overhead for thread creation and schedule
+ *		 context switches)
+ */
+static void _wait_for_timers_expiration(void)
+{
+	struct timespec ts;
+
+	ts.tv_sec = 0;
+	ts.tv_nsec = 50 * ODP_TIME_MSEC_IN_NS;
+	if (nanosleep(&ts, NULL) < 0)
+		CU_FAIL_FATAL("nanosleep failed");
+}
+
 /* @private Worker thread entrypoint which performs timer alloc/set/cancel/free
  * tests */
 static void *worker_entrypoint(void *arg TEST_UNUSED)
@@ -305,7 +322,7 @@  static void *worker_entrypoint(void *arg TEST_UNUSED)
 		uint64_t tck = odp_timer_current_tick(tp) + 1 +
 			       odp_timer_ns_to_tick(tp,
 						    (rand_r(&seed) % RANGE_MS)
-						    * 1000000ULL);
+						    * ODP_TIME_MSEC_IN_NS);
 		odp_timer_set_t rc;
 		rc = odp_timer_set_abs(tt[i].tim, tck, &tt[i].ev);
 		if (rc != ODP_TIMER_SUCCESS) {
@@ -351,7 +368,8 @@  static void *worker_entrypoint(void *arg TEST_UNUSED)
 				/* Timer active => reset */
 				nreset++;
 			uint64_t tck = 1 + odp_timer_ns_to_tick(tp,
-				       (rand_r(&seed) % RANGE_MS) * 1000000ULL);
+				       (rand_r(&seed) % RANGE_MS) *
+				       ODP_TIME_MSEC_IN_NS);
 			odp_timer_set_t rc;
 			uint64_t cur_tick;
 			/* Loop until we manage to read cur_tick and set a
@@ -372,11 +390,8 @@  static void *worker_entrypoint(void *arg TEST_UNUSED)
 				tt[i].tick = cur_tick + tck;
 			}
 		}
-		struct timespec ts;
-		ts.tv_sec = 0;
-		ts.tv_nsec = 1000000; /* 1ms */
-		if (nanosleep(&ts, NULL) < 0)
-			CU_FAIL_FATAL("nanosleep failed");
+
+		_wait_for_timers_expiration();
 	}
 
 	/* Cancel and free all timers */
@@ -401,13 +416,8 @@  static void *worker_entrypoint(void *arg TEST_UNUSED)
 	LOG_DBG("Thread %u: %" PRIu32 " stale timeout(s) after odp_timer_free()\n",
 		thr, nstale);
 
-	/* Delay some more to ensure timeouts for expired timers can be
-	 * received */
-	struct timespec ts;
-	ts.tv_sec = 0;
-	ts.tv_nsec = 1000000; /* 1ms */
-	if (nanosleep(&ts, NULL) < 0)
-		CU_FAIL_FATAL("nanosleep failed");
+	_wait_for_timers_expiration();
+
 	while (nstale != 0) {
 		odp_event_t ev = odp_queue_deq(queue);
 		if (ev != ODP_EVENT_INVALID) {