[LTP] [PATCH] timer_settime02: Catch SIGALRM
Martin Doucha
mdoucha@suse.cz
Mon Jul 29 16:28:04 CEST 2024
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.
Signed-off-by: Martin Doucha <mdoucha@suse.cz>
---
.../syscalls/timer_settime/timer_settime02.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/testcases/kernel/syscalls/timer_settime/timer_settime02.c b/testcases/kernel/syscalls/timer_settime/timer_settime02.c
index 2723dc03d..46caefe4f 100644
--- a/testcases/kernel/syscalls/timer_settime/timer_settime02.c
+++ b/testcases/kernel/syscalls/timer_settime/timer_settime02.c
@@ -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[] = {
@@ -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)
@@ -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) {
@@ -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));
+ }
}
}
--
2.44.0
More information about the ltp
mailing list