public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] [PATCH] timer_settime02: Catch SIGALRM
@ 2024-07-29 14:28 Martin Doucha
  2024-07-29 17:24 ` Petr Vorel
  0 siblings, 1 reply; 2+ messages in thread
From: Martin Doucha @ 2024-07-29 14:28 UTC (permalink / raw)
  To: ltp

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


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-07-29 17:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-29 14:28 [LTP] [PATCH] timer_settime02: Catch SIGALRM Martin Doucha
2024-07-29 17:24 ` Petr Vorel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox