Skip to content

Commit

Permalink
timer_settime01: Check signal timing
Browse files Browse the repository at this point in the history
Add a new check that the timer signal does not get delivered too early.
Also fix a bug where tc->it_value_tv_usec was ignored in TIMER_ABSTIME
subtests.

Link: https://lore.kernel.org/ltp/[email protected]/
Reviewed-by: Petr Vorel <[email protected]>
Reviewed-by: Cyril Hrubis <[email protected]>
Signed-off-by: Martin Doucha <[email protected]>
  • Loading branch information
mdoucha authored and pevik committed Aug 15, 2024
1 parent 12588ee commit 819fdc6
Showing 1 changed file with 33 additions and 16 deletions.
49 changes: 33 additions & 16 deletions testcases/kernel/syscalls/timer_settime/timer_settime01.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,11 @@ static struct time64_variants variants[] = {

static volatile int caught_signal;

static void clear_signal(void)
static void clear_signal(clock_t clock, const struct tst_ts *exptime)
{
struct time64_variants *tv = &variants[tst_variant];
struct tst_ts curtime = { .type = tv->ts_type };

/*
* The busy loop is intentional. The signal is sent after X
* seconds of CPU time has been accumulated for the process and
Expand All @@ -74,6 +77,17 @@ static void clear_signal(void)
}

caught_signal = 0;

if (tv->clock_gettime(clock, tst_ts_get(&curtime)) < 0) {
tst_res(TFAIL, "clock_gettime(%s) failed",
get_clock_str(clock));
return;
}

if (tst_ts_lt(curtime, *exptime)) {
tst_res(TFAIL, "Timer %s expired too early",
get_clock_str(clock));
}
}

static void sighandler(int sig)
Expand Down Expand Up @@ -116,22 +130,22 @@ static void run(unsigned int n)
memset(&new_set, 0, sizeof(new_set));
memset(&old_set, 0, sizeof(old_set));

new_set.type = old_set.type = tv->ts_type;
new_set.type = old_set.type = timenow.type = tv->ts_type;
val = tc->it_value_tv_usec;

if (tc->flag & TIMER_ABSTIME) {
timenow.type = tv->ts_type;
if (tv->clock_gettime(clock, tst_ts_get(&timenow)) < 0) {
tst_res(TFAIL,
"clock_gettime(%s) failed - skipping the test",
get_clock_str(clock));
continue;
}
tst_ts_add_us(timenow, val);
if (tv->clock_gettime(clock, tst_ts_get(&timenow)) < 0) {
tst_res(TFAIL,
"clock_gettime(%s) failed - skipping the test",
get_clock_str(clock));
continue;
}

timenow = tst_ts_add_us(timenow, val);

if (tc->flag & TIMER_ABSTIME)
tst_its_set_value_from_ts(&new_set, timenow);
} else {
else
tst_its_set_value_from_us(&new_set, val);
}

tst_its_set_interval_from_us(&new_set, tc->it_interval_tv_usec);

Expand All @@ -157,11 +171,14 @@ static void run(unsigned int n)
tst_its_get_value_nsec(new_set));
}

clear_signal();
clear_signal(clock, &timenow);

/* Wait for another event when interval was set */
if (tc->it_interval_tv_usec)
clear_signal();
if (tc->it_interval_tv_usec) {
timenow = tst_ts_add_us(timenow,
tc->it_interval_tv_usec);
clear_signal(clock, &timenow);
}

tst_res(TPASS, "timer_settime(%s) passed",
get_clock_str(clock));
Expand Down

0 comments on commit 819fdc6

Please sign in to comment.