diff options
author | Petri Savolainen <petri.savolainen@linaro.org> | 2018-04-19 13:03:29 +0300 |
---|---|---|
committer | Maxim Uvarov <maxim.uvarov@linaro.org> | 2018-04-23 21:24:40 +0300 |
commit | 5d4be5077adeec54d1956c86dcb87b186c39a7cb (patch) | |
tree | f4deb6742f0227e76607397d226a5605efd02db9 | |
parent | 3aa3f4352083d159260cebc23b87607e73aa6f2b (diff) |
validation: timer: don't assume low timer tick frequency
Timer tick can be the same as CPU frequency. So, test cannot
loop until two current_tick calls return the same tick value.
Similarly, test cannot assume that expiration tick of a relative
timeout call can be exactly calculated from a current_tick value.
Signed-off-by: Petri Savolainen <petri.savolainen@linaro.org>
Reviewed-by: Bill Fischofer <bill.fischofer@linaro.org>
Signed-off-by: Maxim Uvarov <maxim.uvarov@linaro.org>
-rw-r--r-- | test/validation/api/timer/timer.c | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/test/validation/api/timer/timer.c b/test/validation/api/timer/timer.c index 9cbb08bbb..bd4f1b997 100644 --- a/test/validation/api/timer/timer.c +++ b/test/validation/api/timer/timer.c @@ -291,19 +291,17 @@ static void handle_tmo(odp_event_t ev, bool stale, uint64_t prev_tick) CU_FAIL("Wrong status (stale) for fresh timeout"); if (!stale) { - /* Fresh timeout => local timer must have matching tick */ - if (ttp->tick != tick) { - LOG_DBG("Wrong tick: expected %" PRIu64 - " actual %" PRIu64 "\n", + /* tmo tick cannot be smaller than pre-calculated tick */ + if (tick < ttp->tick) { + LOG_DBG("Too small tick: pre-calculated %" PRIu64 + " timeout %" PRIu64 "\n", ttp->tick, tick); - CU_FAIL("odp_timeout_tick() wrong tick"); + CU_FAIL("odp_timeout_tick() too small tick"); } - if (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"); + if (tick < prev_tick) { LOG_DBG("Too late tick: %" PRIu64 " prev_tick %" PRIu64"\n", @@ -421,23 +419,23 @@ static int worker_entrypoint(void *arg TEST_UNUSED) ncancel++; } } else { + odp_timer_set_t rc; + uint64_t cur_tick; + uint64_t tck, nsec; + if (tt[i].ev != ODP_EVENT_INVALID) /* Timer inactive => set */ nset++; else /* Timer active => reset */ nreset++; - uint64_t tck = 1 + 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 - * relative timer in the same tick */ - do { - cur_tick = odp_timer_current_tick(tp); - rc = odp_timer_set_rel(tt[i].tim, - tck, &tt[i].ev); - } while (cur_tick != odp_timer_current_tick(tp)); + + nsec = (rand_r(&seed) % RANGE_MS) * 1000000ULL; + tck = 1 + odp_timer_ns_to_tick(tp, nsec); + + cur_tick = odp_timer_current_tick(tp); + rc = odp_timer_set_rel(tt[i].tim, tck, &tt[i].ev); + if (rc == ODP_TIMER_TOOEARLY || rc == ODP_TIMER_TOOLATE) { CU_FAIL("Failed to set timer (tooearly/toolate)"); |