This option is to specify minimum number ticks (delta between future tick and current tick) required to successfully reset/set the timer.
some hardware timer implementations needs at least two ticks gap between "current tick" and "future tick" to cancel/set timer and let timer test case aware of this behavior by introducing CONFIG_MIN_TICK Signed-off-by: Jerin Jacob <jerin.ja...@caviumnetworks.com> --- test/validation/odp_timer.c | 57 ++++++++++++++++++++++++++++----------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/test/validation/odp_timer.c b/test/validation/odp_timer.c index 5dfc06a..d13c12e 100644 --- a/test/validation/odp_timer.c +++ b/test/validation/odp_timer.c @@ -242,10 +242,11 @@ static void handle_tmo(odp_event_t ev, bool stale, uint64_t prev_tick) if (ttp != NULL && ttp->tick != TICK_INVALID) CU_FAIL("Stale timeout for active timer"); } else { - if (!odp_timeout_fresh(tmo)) + if (!odp_timeout_fresh(tmo) && ttp->tick != TICK_INVALID) CU_FAIL("Wrong status (stale) for fresh timeout"); /* Fresh timeout => local timer must have matching tick */ - if (ttp != NULL && ttp->tick != tick) { + if (ttp != NULL && ttp->tick != TICK_INVALID && + ttp->tick != tick) { LOG_DBG("Wrong tick: expected %"PRIu64" actual %"PRIu64"\n", ttp->tick, tick); CU_FAIL("odp_timeout_tick() wrong tick"); @@ -268,6 +269,17 @@ static void handle_tmo(odp_event_t ev, bool stale, uint64_t prev_tick) } } +#define NAME "timer_pool" +#define RES (10 * ODP_TIME_MSEC / 3) +#define MIN (10 * ODP_TIME_MSEC / 3) +#define MAX (1000000 * ODP_TIME_MSEC) + +/* + * Minimum tick(s)(delta between future tick and current tick) + * required to successfully reset/set the timer + */ +#define CONFIG_MIN_TICK 1 + /* @private Worker thread entrypoint which performs timer alloc/set/cancel/free * tests */ static void *worker_entrypoint(void *arg TEST_UNUSED) @@ -305,7 +317,7 @@ static void *worker_entrypoint(void *arg TEST_UNUSED) /* Initial set all timers with a random expiration time */ uint32_t nset = 0; for (i = 0; i < NTIMERS; i++) { - uint64_t tck = odp_timer_current_tick(tp) + 1 + + uint64_t tck = odp_timer_current_tick(tp) + CONFIG_MIN_TICK + odp_timer_ns_to_tick(tp, (rand_r(&seed) % RANGE_MS) * 1000000ULL); @@ -329,9 +341,9 @@ static void *worker_entrypoint(void *arg TEST_UNUSED) for (ms = 0; ms < 7 * RANGE_MS / 10; ms++) { odp_event_t ev; while ((ev = odp_queue_deq(queue)) != ODP_EVENT_INVALID) { - /* Subtract one from prev_tick to allow for timeouts - * to be delivered a tick late */ - handle_tmo(ev, false, prev_tick - 1); + /* Subtract CONFIG_MIN_TICK from prev_tick to allow + * for timeouts to be delivered a tick late */ + handle_tmo(ev, false, prev_tick - CONFIG_MIN_TICK); nrcv++; } prev_tick = odp_timer_current_tick(tp); @@ -340,10 +352,11 @@ static void *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) { + tt[i].tick = TICK_INVALID; /* Cancel failed, timer already expired */ ntoolate++; - tt[i].tick = TICK_INVALID; + } ncancel++; } else { if (tt[i].ev != ODP_EVENT_INVALID) @@ -352,8 +365,10 @@ static void *worker_entrypoint(void *arg TEST_UNUSED) else /* Timer active => reset */ nreset++; - uint64_t tck = 1 + odp_timer_ns_to_tick(tp, - (rand_r(&seed) % RANGE_MS) * 1000000ULL); + uint64_t tck = CONFIG_MIN_TICK + + odp_timer_ns_to_tick(tp, + (rand_r(&seed) % RANGE_MS) + * 1000000ULL); odp_timer_set_t rc; uint64_t cur_tick; /* Loop until we manage to read cur_tick and set a @@ -403,13 +418,17 @@ 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"); + for (i = 0; i < CONFIG_MIN_TICK; i++) { + /* Delay some more tick(s) to ensure + * timeouts for expired timers can be received */ + struct timespec ts; + + ts.tv_sec = 0; + ts.tv_nsec = RES; /* 1 tick */ + if (nanosleep(&ts, NULL) < 0) + CU_FAIL_FATAL("nanosleep failed"); + } + while (nstale != 0) { odp_event_t ev = odp_queue_deq(queue); if (ev != ODP_EVENT_INVALID) { @@ -458,10 +477,6 @@ static void test_odp_timer_all(void) if (tbp == ODP_POOL_INVALID) CU_FAIL_FATAL("Timeout pool create failed"); -#define NAME "timer_pool" -#define RES (10 * ODP_TIME_MSEC / 3) -#define MIN (10 * ODP_TIME_MSEC / 3) -#define MAX (1000000 * ODP_TIME_MSEC) /* Create a timer pool */ tparam.res_ns = RES; tparam.min_tmo = MIN; -- 2.1.0 _______________________________________________ lng-odp mailing list lng-odp@lists.linaro.org https://lists.linaro.org/mailman/listinfo/lng-odp