Skip to content

Commit

Permalink
timer_settime02: Catch SIGALRM
Browse files Browse the repository at this point in the history
If any of the tested timers expires due to a bug, the test will be
killed by SIGALRM. Catch the signal and report a failure.

Link: https://lore.kernel.org/ltp/20240729142806.6131-1-mdoucha@suse.cz/
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Martin Doucha <mdoucha@suse.cz>
  • Loading branch information
mdoucha authored and pevik committed Jul 29, 2024
1 parent dfb293e commit 94740a2
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions testcases/kernel/syscalls/timer_settime/timer_settime02.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ static struct tst_its *pnew_set = &new_set, *pold_set = &old_set, *null_set = NU
static void *faulty_set;
static kernel_timer_t timer;
static kernel_timer_t timer_inval = (kernel_timer_t)-1;
static volatile int caught_sig;

/* separate description-array to (hopefully) improve readability */
static const char * const descriptions[] = {
Expand Down Expand Up @@ -69,10 +70,16 @@ static struct time64_variants variants[] = {
#endif
};

static void sighandler(int sig)
{
caught_sig = sig;
}

static void setup(void)
{
tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
faulty_set = tst_get_bad_addr(NULL);
signal(SIGALRM, sighandler);
}

static void run(unsigned int n)
Expand All @@ -87,6 +94,8 @@ static void run(unsigned int n)
for (i = 0; i < CLOCKS_DEFINED; ++i) {
clock_t clock = clock_list[i];

caught_sig = 0;

/* Init temporary timer */
TEST(tst_syscall(__NR_timer_create, clock, NULL, &timer));
if (TST_RET != 0) {
Expand Down Expand Up @@ -131,6 +140,12 @@ static void run(unsigned int n)
TEST(tst_syscall(__NR_timer_delete, timer));
if (TST_RET != 0)
tst_res(TFAIL | TTERRNO, "timer_delete() failed!");

if (caught_sig) {
tst_res(TFAIL,
"Caught unexpected signal %s while testing %s",
tst_strsig(caught_sig), get_clock_str(clock));
}
}
}

Expand Down

0 comments on commit 94740a2

Please sign in to comment.