public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Martin Doucha <mdoucha@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] timer_settime02: Catch SIGALRM
Date: Mon, 29 Jul 2024 16:28:04 +0200	[thread overview]
Message-ID: <20240729142806.6131-1-mdoucha@suse.cz> (raw)

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

             reply	other threads:[~2024-07-29 14:29 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-29 14:28 Martin Doucha [this message]
2024-07-29 17:24 ` [LTP] [PATCH] timer_settime02: Catch SIGALRM Petr Vorel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240729142806.6131-1-mdoucha@suse.cz \
    --to=mdoucha@suse.cz \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox