Skip to content

Commit

Permalink
syscalls/timer_settime03: Scale interval with clock precision
Browse files Browse the repository at this point in the history
What the test does is to:

- set initial expiration in the past
- set very small interval value
- expect the timer to overrun immediatelly many times
  to trigger timer overrun counter overflow

However the test has harcoded expectation that the kernel timers have
1ns resolution. And while that is true for many modern hardware high
resolution timers are generally not always present.

The test tried to cope with that by adding kernel requirement for
CONFIG_HIGH_RES_TIMERS=y however that does not necessarily mean that the
high resolution hardware is present or that the drivers are loaded.
This only means that the support has been compiled in the kernel.

So instead of disabling the test when kernel timers have lower precision
we scale the timer interval so that the inverval length divided by the
timer precision is constant i.e. handler_delay.

Fixes #925

Signed-off-by: Cyril Hrubis <[email protected]>
Reviewed-by: Li Wang <[email protected]>
Reviewed-by: Petr Vorel <[email protected]>
  • Loading branch information
metan-ucw authored and wangli5665 committed May 27, 2022
1 parent a7362af commit 03f246f
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions testcases/kernel/syscalls/timer_settime/timer_settime03.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
static timer_t timer;
static volatile int handler_called, overrun, saved_errno;

static struct timespec realtime_resolution;

static void sighandler(int sig LTP_ATTRIBUTE_UNUSED)
{
struct itimerspec spec;
Expand Down Expand Up @@ -61,6 +63,11 @@ static void setup(void)

SAFE_SIGNAL(SIGUSR1, sighandler);
SAFE_TIMER_CREATE(CLOCK_REALTIME, &sev, &timer);

SAFE_CLOCK_GETRES(CLOCK_REALTIME, &realtime_resolution);

tst_res(TINFO, "CLOCK_REALTIME resolution %lins",
(long)realtime_resolution.tv_nsec);
}

static void run(void)
Expand All @@ -81,9 +88,9 @@ static void run(void)

/* spec.it_value = now - 1.4 * max overrun value */
/* IOW, overflow will land right in the middle of negative range */
spec.it_value.tv_sec -= handler_delay / 100000000;
spec.it_value.tv_sec -= (handler_delay / 100000000) * realtime_resolution.tv_nsec;
spec.it_value.tv_nsec -= nsec;
spec.it_interval.tv_nsec = 1;
spec.it_interval.tv_nsec = realtime_resolution.tv_nsec;

SAFE_TIMER_SETTIME(timer, TIMER_ABSTIME, &spec, NULL);
while (!handler_called);
Expand Down Expand Up @@ -115,10 +122,6 @@ static struct tst_test test = {
.test_all = run,
.setup = setup,
.cleanup = cleanup,
.needs_kconfigs = (const char *[]) {
"CONFIG_HIGH_RES_TIMERS=y",
NULL
},
.tags = (const struct tst_tag[]) {
{"linux-git", "78c9c4dfbf8c"},
{"CVE", "2018-12896"},
Expand Down

0 comments on commit 03f246f

Please sign in to comment.