All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH V2 0/3] syscalls: Rearrange sigwait syscall tests
@ 2020-07-21  8:52 Viresh Kumar
  2020-07-21  8:52 ` [LTP] [PATCH V2 1/3] syscalls: sigwaitinfo: Suppress all warnings around unused parameter Viresh Kumar
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Viresh Kumar @ 2020-07-21  8:52 UTC (permalink / raw)
  To: ltp

Hi,

As suggested by you I have tried to rearrange stuff here and I was able
to fix the linking issues reported earlier by doing following:

-LDLIBS  += -lltpsigwait
+LDLIBS  := -lltpsigwait $(LDLIBS)

And so here is the proper series now, all working fine.

This is rebased over the earlier series which is under review
(specifically the following patch,
[PATCH V7 10/19] syscalls/rt_sigtimedwait: Add support for time64 tests).

V2:
- Fixed build issues with proper ordering of libraries.

--
Viresh

Viresh Kumar (3):
  syscalls: sigwaitinfo: Suppress all warnings around unused parameter
  syscalls: sigwaitinfo: Remove SUCCEED_OR_DIE() macro
  syscalls: sigwait: Separate out code to relevant folders

 include/libsigwait.h                               |  45 ++
 libs/libltpsigwait/Makefile                        |  11 +
 libs/libltpsigwait/sigwait.c                       | 428 +++++++++++++++++
 testcases/kernel/syscalls/rt_sigtimedwait/Makefile |  10 +-
 .../syscalls/rt_sigtimedwait/rt_sigtimedwait01.c   |  78 ++++
 testcases/kernel/syscalls/sigtimedwait/Makefile    |   9 +-
 .../kernel/syscalls/sigtimedwait/sigtimedwait01.c  |  37 ++
 testcases/kernel/syscalls/sigwait/Makefile         |   9 +-
 testcases/kernel/syscalls/sigwait/sigwait01.c      |  37 ++
 testcases/kernel/syscalls/sigwaitinfo/Makefile     |   4 +-
 .../kernel/syscalls/sigwaitinfo/sigwaitinfo01.c    | 511 +--------------------
 11 files changed, 662 insertions(+), 517 deletions(-)
 create mode 100644 include/libsigwait.h
 create mode 100644 libs/libltpsigwait/Makefile
 create mode 100644 libs/libltpsigwait/sigwait.c
 create mode 100644 testcases/kernel/syscalls/rt_sigtimedwait/rt_sigtimedwait01.c
 create mode 100644 testcases/kernel/syscalls/sigtimedwait/sigtimedwait01.c
 create mode 100644 testcases/kernel/syscalls/sigwait/sigwait01.c

-- 
2.14.1


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

* [LTP] [PATCH V2 1/3] syscalls: sigwaitinfo: Suppress all warnings around unused parameter
  2020-07-21  8:52 [LTP] [PATCH V2 0/3] syscalls: Rearrange sigwait syscall tests Viresh Kumar
@ 2020-07-21  8:52 ` Viresh Kumar
  2020-07-21  8:52 ` [LTP] [PATCH V2 2/3] syscalls: sigwaitinfo: Remove SUCCEED_OR_DIE() macro Viresh Kumar
  2020-07-21  8:52 ` [LTP] [PATCH V2 3/3] syscalls: sigwait: Separate out code to relevant folders Viresh Kumar
  2 siblings, 0 replies; 7+ messages in thread
From: Viresh Kumar @ 2020-07-21  8:52 UTC (permalink / raw)
  To: ltp

Suppress the warnings using LTP_ATTRIBUTE_UNUSED.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 .../kernel/syscalls/sigwaitinfo/sigwaitinfo01.c    | 26 +++++++++++++---------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
index 05e62999ca6c..86fce4427a6d 100644
--- a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
+++ b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
@@ -50,7 +50,7 @@ static void report_success_cond(const char *func, int line,
 #define REPORT_SUCCESS(exp_return, exp_errno)					\
 	REPORT_SUCCESS_COND(exp_return, exp_errno, 1, "");
 
-static void empty_handler(int sig)
+static void empty_handler(int sig LTP_ATTRIBUTE_UNUSED)
 {
 }
 
@@ -74,7 +74,7 @@ static int my_sigwait(const sigset_t * set, siginfo_t * info,
 
 #ifdef TEST_SIGWAITINFO
 static int my_sigwaitinfo(const sigset_t * set, siginfo_t * info,
-			  void *timeout)
+			  void *timeout LTP_ATTRIBUTE_UNUSED)
 {
 	return sigwaitinfo(set, info);
 }
@@ -106,7 +106,8 @@ static int my_rt_sigtimedwait_time64(const sigset_t * set, siginfo_t * info,
 #endif
 #endif
 
-void test_empty_set(swi_func sigwaitinfo, int signo, enum tst_ts_type type)
+void test_empty_set(swi_func sigwaitinfo, int signo,
+		    enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
 {
 	sigset_t sigs;
 	siginfo_t si;
@@ -150,7 +151,7 @@ void test_timeout(swi_func sigwaitinfo, int signo, enum tst_ts_type type)
  * by POSIX; but works for non-ignored signals under Linux
  */
 void test_unmasked_matching(swi_func sigwaitinfo, int signo,
-			    enum tst_ts_type type)
+			    enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
 {
 	sigset_t sigs;
 	siginfo_t si;
@@ -172,7 +173,7 @@ void test_unmasked_matching(swi_func sigwaitinfo, int signo,
 }
 
 void test_unmasked_matching_noinfo(swi_func sigwaitinfo, int signo,
-				   enum tst_ts_type type)
+				   enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
 {
 	sigset_t sigs;
 	pid_t child;
@@ -190,7 +191,7 @@ void test_unmasked_matching_noinfo(swi_func sigwaitinfo, int signo,
 }
 
 void test_masked_matching(swi_func sigwaitinfo, int signo,
-			  enum tst_ts_type type)
+			  enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
 {
 	sigset_t sigs, oldmask;
 	siginfo_t si;
@@ -229,7 +230,7 @@ void test_masked_matching(swi_func sigwaitinfo, int signo,
 }
 
 void test_masked_matching_rt(swi_func sigwaitinfo, int signo,
-			     enum tst_ts_type type)
+			     enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
 {
 	sigset_t sigs, oldmask;
 	siginfo_t si;
@@ -281,7 +282,7 @@ void test_masked_matching_rt(swi_func sigwaitinfo, int signo,
 }
 
 void test_masked_matching_noinfo(swi_func sigwaitinfo, int signo,
-				 enum tst_ts_type type)
+				 enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
 {
 	sigset_t sigs, oldmask;
 	pid_t child;
@@ -316,7 +317,8 @@ void test_masked_matching_noinfo(swi_func sigwaitinfo, int signo,
 	SAFE_WAIT(NULL);
 }
 
-void test_bad_address(swi_func sigwaitinfo, int signo, enum tst_ts_type type)
+void test_bad_address(swi_func sigwaitinfo, int signo,
+		      enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
 {
 	sigset_t sigs, oldmask;
 	pid_t child;
@@ -345,7 +347,8 @@ void test_bad_address(swi_func sigwaitinfo, int signo, enum tst_ts_type type)
 	SAFE_WAIT(NULL);
 }
 
-void test_bad_address2(swi_func sigwaitinfo, int signo, enum tst_ts_type type)
+void test_bad_address2(swi_func sigwaitinfo, int signo LTP_ATTRIBUTE_UNUSED,
+		       enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
 {
 	pid_t pid;
 	int status;
@@ -391,7 +394,8 @@ void test_bad_address2(swi_func sigwaitinfo, int signo, enum tst_ts_type type)
 	}
 }
 
-void test_bad_address3(swi_func sigwaitinfo, int signo, enum tst_ts_type type)
+void test_bad_address3(swi_func sigwaitinfo, int signo LTP_ATTRIBUTE_UNUSED,
+		       enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
 {
 	sigset_t sigs;
 	SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs);
-- 
2.14.1


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

* [LTP] [PATCH V2 2/3] syscalls: sigwaitinfo: Remove SUCCEED_OR_DIE() macro
  2020-07-21  8:52 [LTP] [PATCH V2 0/3] syscalls: Rearrange sigwait syscall tests Viresh Kumar
  2020-07-21  8:52 ` [LTP] [PATCH V2 1/3] syscalls: sigwaitinfo: Suppress all warnings around unused parameter Viresh Kumar
@ 2020-07-21  8:52 ` Viresh Kumar
  2020-07-22 10:09   ` Cyril Hrubis
  2020-07-21  8:52 ` [LTP] [PATCH V2 3/3] syscalls: sigwait: Separate out code to relevant folders Viresh Kumar
  2 siblings, 1 reply; 7+ messages in thread
From: Viresh Kumar @ 2020-07-21  8:52 UTC (permalink / raw)
  To: ltp

The macro makes it less readable and there isn't a great deal of code it
is trying to remove. Get rid of it.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 .../kernel/syscalls/sigwaitinfo/sigwaitinfo01.c    | 156 ++++++++++++++-------
 1 file changed, 109 insertions(+), 47 deletions(-)

diff --git a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
index 86fce4427a6d..5e1baf9df774 100644
--- a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
+++ b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
@@ -10,13 +10,6 @@
 #include "lapi/syscalls.h"
 #include "tst_sig_proc.h"
 
-#define SUCCEED_OR_DIE(syscall, message, ...)				 \
-	(errno = 0,							 \
-		({int ret=syscall(__VA_ARGS__);				 \
-			if (ret==-1)					 \
-				tst_brk(TBROK|TERRNO, message);\
-			ret;}))
-
 /* Report success iff TST_RET and TST_ERR are equal to
 	 exp_return and exp_errno, resp., and cond is true. If cond is not
 	 true, report condition_errmsg
@@ -113,7 +106,10 @@ void test_empty_set(swi_func sigwaitinfo, int signo,
 	siginfo_t si;
 	pid_t child;
 
-	SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs);
+	TEST(sigemptyset(&sigs));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
+
 	/* Run a child that will wake us up */
 	child = create_sig_proc(signo, INT_MAX, 100000);
 
@@ -135,7 +131,9 @@ void test_timeout(swi_func sigwaitinfo, int signo, enum tst_ts_type type)
 	tst_ts_set_sec(&ts, 1);
 	tst_ts_set_nsec(&ts, 0);
 
-	SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs);
+	TEST(sigemptyset(&sigs));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
 
 	/* Run a child that will wake us up */
 	child = create_sig_proc(signo, INT_MAX, 100000);
@@ -157,8 +155,13 @@ void test_unmasked_matching(swi_func sigwaitinfo, int signo,
 	siginfo_t si;
 	pid_t child;
 
-	SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs);
-	SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, signo);
+	TEST(sigemptyset(&sigs));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
+
+	TEST(sigaddset(&sigs, signo));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
 
 	/* Run a child that will wake us up */
 	child = create_sig_proc(signo, INT_MAX, 100000);
@@ -178,8 +181,14 @@ void test_unmasked_matching_noinfo(swi_func sigwaitinfo, int signo,
 	sigset_t sigs;
 	pid_t child;
 
-	SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs);
-	SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, signo);
+	TEST(sigemptyset(&sigs));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
+
+	TEST(sigaddset(&sigs, signo));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+
 	/* Run a child that will wake us up */
 	child = create_sig_proc(signo, INT_MAX, 100000);
 
@@ -197,16 +206,27 @@ void test_masked_matching(swi_func sigwaitinfo, int signo,
 	siginfo_t si;
 	pid_t child;
 
-	SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs);
-	SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, signo);
+	TEST(sigemptyset(&sigs));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
+
+	TEST(sigaddset(&sigs, signo));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+
 	/* let's not get interrupted by our dying child */
-	SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, SIGCHLD);
+	TEST(sigaddset(&sigs, SIGCHLD));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
 
-	SUCCEED_OR_DIE(sigprocmask, "sigprocmask failed", SIG_SETMASK, &sigs,
-		       &oldmask);
+	TEST(sigprocmask(SIG_SETMASK, &sigs, &oldmask));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigprocmask() failed");
 
 	/* don't wait on a SIGCHLD */
-	SUCCEED_OR_DIE(sigdelset, "sigaddset failed", &sigs, SIGCHLD);
+	TEST(sigdelset(&sigs, SIGCHLD));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigdelset() failed");
 
 	/* Run a child that will wake us up */
 	child = create_sig_proc(signo, 1, 0);
@@ -216,8 +236,9 @@ void test_masked_matching(swi_func sigwaitinfo, int signo,
 			    && si.si_code == SI_USER
 			    && si.si_signo == signo, "Struct siginfo mismatch");
 
-	SUCCEED_OR_DIE(sigprocmask, "restoring original signal mask failed",
-		       SIG_SETMASK, &oldmask, &oldmask);
+	TEST(sigprocmask(SIG_SETMASK, &oldmask, &oldmask));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "restoring original signal mask failed");
 
 	if (sigismember(&oldmask, signo))
 		tst_res(TPASS, "sigwaitinfo restored the original mask");
@@ -239,17 +260,31 @@ void test_masked_matching_rt(swi_func sigwaitinfo, int signo,
 
 	signo = SIGRTMIN + 1;
 
-	SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs);
-	SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, signo);
-	SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, signo + 1);
+	TEST(sigemptyset(&sigs));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
+
+	TEST(sigaddset(&sigs, signo));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+
+	TEST(sigaddset(&sigs, signo + 1));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+
 	/* let's not get interrupted by our dying child */
-	SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, SIGCHLD);
+	TEST(sigaddset(&sigs, SIGCHLD));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
 
-	SUCCEED_OR_DIE(sigprocmask, "sigprocmask failed", SIG_SETMASK, &sigs,
-		       &oldmask);
+	TEST(sigprocmask(SIG_SETMASK, &sigs, &oldmask));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigprocmask() failed");
 
 	/* don't wait on a SIGCHLD */
-	SUCCEED_OR_DIE(sigdelset, "sigdelset failed", &sigs, SIGCHLD);
+	TEST(sigdelset(&sigs, SIGCHLD));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigdelset() failed");
 
 	/* Run a child that will wake us up */
 	child[0] = create_sig_proc(signo, 1, 0);
@@ -271,8 +306,9 @@ void test_masked_matching_rt(swi_func sigwaitinfo, int signo,
 			    && si.si_signo == signo + 1,
 			    "Struct siginfo mismatch");
 
-	SUCCEED_OR_DIE(sigprocmask, "restoring original signal mask failed",
-		       SIG_SETMASK, &oldmask, &oldmask);
+	TEST(sigprocmask(SIG_SETMASK, &oldmask, &oldmask));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "restoring original signal mask failed");
 
 	if (sigismember(&oldmask, signo))
 		tst_res(TPASS, "sigwaitinfo restored the original mask");
@@ -287,16 +323,27 @@ void test_masked_matching_noinfo(swi_func sigwaitinfo, int signo,
 	sigset_t sigs, oldmask;
 	pid_t child;
 
-	SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs);
-	SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, signo);
+	TEST(sigemptyset(&sigs));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
+
+	TEST(sigaddset(&sigs, signo));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+
 	/* let's not get interrupted by our dying child */
-	SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, SIGCHLD);
+	TEST(sigaddset(&sigs, SIGCHLD));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
 
-	SUCCEED_OR_DIE(sigprocmask, "sigprocmask failed", SIG_SETMASK, &sigs,
-		       &oldmask);
+	TEST(sigprocmask(SIG_SETMASK, &sigs, &oldmask));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigprocmask() failed");
 
 	/* don't wait on a SIGCHLD */
-	SUCCEED_OR_DIE(sigdelset, "sigaddset failed", &sigs, SIGCHLD);
+	TEST(sigdelset(&sigs, SIGCHLD));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigdelset() failed");
 
 	/* Run a child that will wake us up */
 	child = create_sig_proc(signo, 1, 0);
@@ -304,8 +351,9 @@ void test_masked_matching_noinfo(swi_func sigwaitinfo, int signo,
 	TEST(sigwaitinfo(&sigs, NULL, NULL));
 	REPORT_SUCCESS(signo, 0);
 
-	SUCCEED_OR_DIE(sigprocmask, "restoring original signal mask failed",
-		       SIG_SETMASK, &oldmask, &oldmask);
+	TEST(sigprocmask(SIG_SETMASK, &oldmask, &oldmask));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "restoring original signal mask failed");
 
 	if (sigismember(&oldmask, signo))
 		tst_res(TPASS, "sigwaitinfo restored the original mask");
@@ -323,16 +371,27 @@ void test_bad_address(swi_func sigwaitinfo, int signo,
 	sigset_t sigs, oldmask;
 	pid_t child;
 
-	SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs);
-	SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, signo);
+	TEST(sigemptyset(&sigs));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
+
+	TEST(sigaddset(&sigs, signo));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+
 	/* let's not get interrupted by our dying child */
-	SUCCEED_OR_DIE(sigaddset, "sigaddset failed", &sigs, SIGCHLD);
+	TEST(sigaddset(&sigs, SIGCHLD));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
 
-	SUCCEED_OR_DIE(sigprocmask, "sigprocmask failed", SIG_SETMASK, &sigs,
-		       &oldmask);
+	TEST(sigprocmask(SIG_SETMASK, &sigs, &oldmask));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigprocmask() failed");
 
 	/* don't wait on a SIGCHLD */
-	SUCCEED_OR_DIE(sigdelset, "sigaddset failed", &sigs, SIGCHLD);
+	TEST(sigdelset(&sigs, SIGCHLD));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigdelset() failed");
 
 	/* Run a child that will wake us up */
 	child = create_sig_proc(signo, 1, 0);
@@ -340,8 +399,9 @@ void test_bad_address(swi_func sigwaitinfo, int signo,
 	TEST(sigwaitinfo(&sigs, (void *)1, NULL));
 	REPORT_SUCCESS(-1, EFAULT);
 
-	SUCCEED_OR_DIE(sigprocmask, "sigprocmask failed", SIG_SETMASK, &oldmask,
-		       &oldmask);
+	TEST(sigprocmask(SIG_SETMASK, &oldmask, &oldmask));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigprocmask() failed");
 
 	SAFE_KILL(child, SIGTERM);
 	SAFE_WAIT(NULL);
@@ -398,7 +458,9 @@ void test_bad_address3(swi_func sigwaitinfo, int signo LTP_ATTRIBUTE_UNUSED,
 		       enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
 {
 	sigset_t sigs;
-	SUCCEED_OR_DIE(sigemptyset, "sigemptyset failed", &sigs);
+	TEST(sigemptyset(&sigs));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
 
 	TEST(sigwaitinfo(&sigs, NULL, (void *)1));
 	REPORT_SUCCESS(-1, EFAULT);
-- 
2.14.1


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

* [LTP] [PATCH V2 3/3] syscalls: sigwait: Separate out code to relevant folders
  2020-07-21  8:52 [LTP] [PATCH V2 0/3] syscalls: Rearrange sigwait syscall tests Viresh Kumar
  2020-07-21  8:52 ` [LTP] [PATCH V2 1/3] syscalls: sigwaitinfo: Suppress all warnings around unused parameter Viresh Kumar
  2020-07-21  8:52 ` [LTP] [PATCH V2 2/3] syscalls: sigwaitinfo: Remove SUCCEED_OR_DIE() macro Viresh Kumar
@ 2020-07-21  8:52 ` Viresh Kumar
  2020-07-22 14:05   ` Cyril Hrubis
  2 siblings, 1 reply; 7+ messages in thread
From: Viresh Kumar @ 2020-07-21  8:52 UTC (permalink / raw)
  To: ltp

The way it is implemented currently is very confusing, all the source
code is present in one file which is referenced from 4 directories to
test different syscalls. The relevant source gets build magically based
on some flag passed in Makefile.

Move the common part to a new library and the relevant part to their
syscall folders.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
---
 include/libsigwait.h                               |  45 ++
 libs/libltpsigwait/Makefile                        |  11 +
 libs/libltpsigwait/sigwait.c                       | 428 +++++++++++++++
 testcases/kernel/syscalls/rt_sigtimedwait/Makefile |  10 +-
 .../syscalls/rt_sigtimedwait/rt_sigtimedwait01.c   |  78 +++
 testcases/kernel/syscalls/sigtimedwait/Makefile    |   9 +-
 .../kernel/syscalls/sigtimedwait/sigtimedwait01.c  |  37 ++
 testcases/kernel/syscalls/sigwait/Makefile         |   9 +-
 testcases/kernel/syscalls/sigwait/sigwait01.c      |  37 ++
 testcases/kernel/syscalls/sigwaitinfo/Makefile     |   4 +-
 .../kernel/syscalls/sigwaitinfo/sigwaitinfo01.c    | 575 +--------------------
 11 files changed, 661 insertions(+), 582 deletions(-)
 create mode 100644 include/libsigwait.h
 create mode 100644 libs/libltpsigwait/Makefile
 create mode 100644 libs/libltpsigwait/sigwait.c
 create mode 100644 testcases/kernel/syscalls/rt_sigtimedwait/rt_sigtimedwait01.c
 create mode 100644 testcases/kernel/syscalls/sigtimedwait/sigtimedwait01.c
 create mode 100644 testcases/kernel/syscalls/sigwait/sigwait01.c

diff --git a/include/libsigwait.h b/include/libsigwait.h
new file mode 100644
index 000000000000..7202fc78fde8
--- /dev/null
+++ b/include/libsigwait.h
@@ -0,0 +1,45 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) 2020 Linaro Limited. All rights reserved.
+ * Author: Viresh Kumar <viresh.kumar@linaro.org>
+ */
+
+#ifndef SIGWAIT_H__
+#define SIGWAIT_H__
+
+#include "tst_test.h"
+#include "tst_timer.h"
+#include <signal.h>
+
+/* swi: sigwaitinfo() */
+typedef int (*swi_func) (const sigset_t * set, siginfo_t * info,
+			 void * timeout);
+typedef void (*test_func) (swi_func, int, enum tst_ts_type type);
+
+struct sigwait_test_desc {
+	test_func tf;
+	int signo;
+};
+
+void test_empty_set(swi_func sigwaitinfo, int signo,
+		    enum tst_ts_type type LTP_ATTRIBUTE_UNUSED);
+void test_timeout(swi_func sigwaitinfo, int signo, enum tst_ts_type type);
+void test_unmasked_matching(swi_func sigwaitinfo, int signo,
+			    enum tst_ts_type type LTP_ATTRIBUTE_UNUSED);
+void test_unmasked_matching_noinfo(swi_func sigwaitinfo, int signo,
+				   enum tst_ts_type type LTP_ATTRIBUTE_UNUSED);
+void test_masked_matching(swi_func sigwaitinfo, int signo,
+			  enum tst_ts_type type LTP_ATTRIBUTE_UNUSED);
+void test_masked_matching_rt(swi_func sigwaitinfo, int signo,
+			     enum tst_ts_type type LTP_ATTRIBUTE_UNUSED);
+void test_masked_matching_noinfo(swi_func sigwaitinfo, int signo,
+				 enum tst_ts_type type LTP_ATTRIBUTE_UNUSED);
+void test_bad_address(swi_func sigwaitinfo, int signo,
+		      enum tst_ts_type type LTP_ATTRIBUTE_UNUSED);
+void test_bad_address2(swi_func sigwaitinfo, int signo LTP_ATTRIBUTE_UNUSED,
+		       enum tst_ts_type type LTP_ATTRIBUTE_UNUSED);
+void test_bad_address3(swi_func sigwaitinfo, int signo LTP_ATTRIBUTE_UNUSED,
+		       enum tst_ts_type type LTP_ATTRIBUTE_UNUSED);
+void sigwait_setup(void);
+void sigwait_cleanup(void);
+#endif /* SIGWAIT_H__ */
diff --git a/libs/libltpsigwait/Makefile b/libs/libltpsigwait/Makefile
new file mode 100644
index 000000000000..e0ea025ade2b
--- /dev/null
+++ b/libs/libltpsigwait/Makefile
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0-or-later
+# Copyright (c) 2020 Viresh Kumar <viresh.kumar@linaro.org>
+
+top_srcdir		?= ../..
+
+include $(top_srcdir)/include/mk/env_pre.mk
+
+INTERNAL_LIB		:= libltpsigwait.a
+
+include $(top_srcdir)/include/mk/lib.mk
+include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/libs/libltpsigwait/sigwait.c b/libs/libltpsigwait/sigwait.c
new file mode 100644
index 000000000000..5fbcdebf1295
--- /dev/null
+++ b/libs/libltpsigwait/sigwait.c
@@ -0,0 +1,428 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright (c) Jiri Palecek<jpalecek@web.de>, 2009 */
+
+#define TST_NO_DEFAULT_MAIN
+#include <errno.h>
+#include <stdlib.h>
+#include <limits.h>
+#include "lapi/syscalls.h"
+#include "libsigwait.h"
+#include "tst_sig_proc.h"
+
+/* Report success iff TST_RET and TST_ERR are equal to
+	 exp_return and exp_errno, resp., and cond is true. If cond is not
+	 true, report condition_errmsg
+*/
+static void report_success_cond(const char *func, int line,
+				long exp_return, int exp_errno, int condition,
+				char *condition_errmsg)
+{
+	if (exp_return == TST_RET
+	    && (exp_return != -1 || exp_errno == TST_ERR))
+		if (condition)
+			tst_res(TPASS, "%s (%d): Test passed", func, line);
+		else
+			tst_res(TFAIL, "%s (%d): %s", func, line,
+				 condition_errmsg);
+	else if (TST_RET != -1)
+		tst_res(TFAIL,
+			 "%s (%d): Unexpected return value; expected %ld, got %ld",
+			 func, line, exp_return, TST_RET);
+	else
+		tst_res(TFAIL | TTERRNO, "%s (%d): Unexpected failure",
+			 func, line);
+}
+
+#define REPORT_SUCCESS_COND(exp_return, exp_errno, condition, condition_errmsg)	\
+	report_success_cond(__FUNCTION__, __LINE__, exp_return, exp_errno, condition, condition_errmsg);
+
+/* Report success iff TST_RET and TST_ERR are equal to
+	 exp_return and exp_errno, resp.
+*/
+#define REPORT_SUCCESS(exp_return, exp_errno)					\
+	REPORT_SUCCESS_COND(exp_return, exp_errno, 1, "");
+
+void test_empty_set(swi_func sigwaitinfo, int signo,
+		    enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
+{
+	sigset_t sigs;
+	siginfo_t si;
+	pid_t child;
+
+	TEST(sigemptyset(&sigs));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
+
+	/* Run a child that will wake us up */
+	child = create_sig_proc(signo, INT_MAX, 100000);
+
+	TEST(sigwaitinfo(&sigs, &si, NULL));
+	REPORT_SUCCESS(-1, EINTR);
+
+	SAFE_KILL(child, SIGTERM);
+	SAFE_WAIT(NULL);
+}
+
+void test_timeout(swi_func sigwaitinfo, int signo, enum tst_ts_type type)
+{
+	sigset_t sigs;
+	siginfo_t si;
+	pid_t child;
+	struct tst_ts ts;
+
+	ts.type = type;
+	tst_ts_set_sec(&ts, 1);
+	tst_ts_set_nsec(&ts, 0);
+
+	TEST(sigemptyset(&sigs));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
+
+	/* Run a child that will wake us up */
+	child = create_sig_proc(signo, INT_MAX, 100000);
+
+	TEST(sigwaitinfo(&sigs, &si, tst_ts_get(&ts)));
+	REPORT_SUCCESS(-1, EAGAIN);
+
+	SAFE_KILL(child, SIGTERM);
+	SAFE_WAIT(NULL);
+}
+
+/* Note: sigwait-ing for a signal that is not blocked is unspecified
+ * by POSIX; but works for non-ignored signals under Linux
+ */
+void test_unmasked_matching(swi_func sigwaitinfo, int signo,
+			    enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
+{
+	sigset_t sigs;
+	siginfo_t si;
+	pid_t child;
+
+	TEST(sigemptyset(&sigs));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
+
+	TEST(sigaddset(&sigs, signo));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+
+	/* Run a child that will wake us up */
+	child = create_sig_proc(signo, INT_MAX, 100000);
+
+	TEST(sigwaitinfo(&sigs, &si, NULL));
+	REPORT_SUCCESS_COND(signo, 0, si.si_pid == child
+			    && si.si_code == SI_USER
+			    && si.si_signo == signo, "Struct siginfo mismatch");
+
+	SAFE_KILL(child, SIGTERM);
+	SAFE_WAIT(NULL);
+}
+
+void test_unmasked_matching_noinfo(swi_func sigwaitinfo, int signo,
+				   enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
+{
+	sigset_t sigs;
+	pid_t child;
+
+	TEST(sigemptyset(&sigs));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
+
+	TEST(sigaddset(&sigs, signo));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+
+	/* Run a child that will wake us up */
+	child = create_sig_proc(signo, INT_MAX, 100000);
+
+	TEST(sigwaitinfo(&sigs, NULL, NULL));
+	REPORT_SUCCESS(signo, 0);
+
+	SAFE_KILL(child, SIGTERM);
+	SAFE_WAIT(NULL);
+}
+
+void test_masked_matching(swi_func sigwaitinfo, int signo,
+			  enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
+{
+	sigset_t sigs, oldmask;
+	siginfo_t si;
+	pid_t child;
+
+	TEST(sigemptyset(&sigs));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
+
+	TEST(sigaddset(&sigs, signo));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+
+	/* let's not get interrupted by our dying child */
+	TEST(sigaddset(&sigs, SIGCHLD));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+
+	TEST(sigprocmask(SIG_SETMASK, &sigs, &oldmask));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigprocmask() failed");
+
+	/* don't wait on a SIGCHLD */
+	TEST(sigdelset(&sigs, SIGCHLD));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigdelset() failed");
+
+	/* Run a child that will wake us up */
+	child = create_sig_proc(signo, 1, 0);
+
+	TEST(sigwaitinfo(&sigs, &si, NULL));
+	REPORT_SUCCESS_COND(signo, 0, si.si_pid == child
+			    && si.si_code == SI_USER
+			    && si.si_signo == signo, "Struct siginfo mismatch");
+
+	TEST(sigprocmask(SIG_SETMASK, &oldmask, &oldmask));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "restoring original signal mask failed");
+
+	if (sigismember(&oldmask, signo))
+		tst_res(TPASS, "sigwaitinfo restored the original mask");
+	else
+		tst_res(TFAIL,
+			 "sigwaitinfo failed to restore the original mask");
+
+	SAFE_KILL(child, SIGTERM);
+	SAFE_WAIT(NULL);
+}
+
+void test_masked_matching_rt(swi_func sigwaitinfo, int signo,
+			     enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
+{
+	sigset_t sigs, oldmask;
+	siginfo_t si;
+	pid_t child[2];
+	int status;
+
+	signo = SIGRTMIN + 1;
+
+	TEST(sigemptyset(&sigs));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
+
+	TEST(sigaddset(&sigs, signo));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+
+	TEST(sigaddset(&sigs, signo + 1));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+
+	/* let's not get interrupted by our dying child */
+	TEST(sigaddset(&sigs, SIGCHLD));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+
+	TEST(sigprocmask(SIG_SETMASK, &sigs, &oldmask));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigprocmask() failed");
+
+	/* don't wait on a SIGCHLD */
+	TEST(sigdelset(&sigs, SIGCHLD));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigdelset() failed");
+
+	/* Run a child that will wake us up */
+	child[0] = create_sig_proc(signo, 1, 0);
+	child[1] = create_sig_proc(signo + 1, 1, 0);
+
+	/* Ensure that the signals have been sent */
+	SAFE_WAITPID(child[0], &status, 0);
+	SAFE_WAITPID(child[1], &status, 0);
+
+	TEST(sigwaitinfo(&sigs, &si, NULL));
+	REPORT_SUCCESS_COND(signo, 0, si.si_pid == child[0]
+			    && si.si_code == SI_USER
+			    && si.si_signo == signo, "Struct siginfo mismatch");
+
+	/* eat the other signal */
+	TEST(sigwaitinfo(&sigs, &si, NULL));
+	REPORT_SUCCESS_COND(signo + 1, 0, si.si_pid == child[1]
+			    && si.si_code == SI_USER
+			    && si.si_signo == signo + 1,
+			    "Struct siginfo mismatch");
+
+	TEST(sigprocmask(SIG_SETMASK, &oldmask, &oldmask));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "restoring original signal mask failed");
+
+	if (sigismember(&oldmask, signo))
+		tst_res(TPASS, "sigwaitinfo restored the original mask");
+	else
+		tst_res(TFAIL,
+			 "sigwaitinfo failed to restore the original mask");
+}
+
+void test_masked_matching_noinfo(swi_func sigwaitinfo, int signo,
+				 enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
+{
+	sigset_t sigs, oldmask;
+	pid_t child;
+
+	TEST(sigemptyset(&sigs));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
+
+	TEST(sigaddset(&sigs, signo));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+
+	/* let's not get interrupted by our dying child */
+	TEST(sigaddset(&sigs, SIGCHLD));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+
+	TEST(sigprocmask(SIG_SETMASK, &sigs, &oldmask));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigprocmask() failed");
+
+	/* don't wait on a SIGCHLD */
+	TEST(sigdelset(&sigs, SIGCHLD));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigdelset() failed");
+
+	/* Run a child that will wake us up */
+	child = create_sig_proc(signo, 1, 0);
+
+	TEST(sigwaitinfo(&sigs, NULL, NULL));
+	REPORT_SUCCESS(signo, 0);
+
+	TEST(sigprocmask(SIG_SETMASK, &oldmask, &oldmask));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "restoring original signal mask failed");
+
+	if (sigismember(&oldmask, signo))
+		tst_res(TPASS, "sigwaitinfo restored the original mask");
+	else
+		tst_res(TFAIL,
+			 "sigwaitinfo failed to restore the original mask");
+
+	SAFE_KILL(child, SIGTERM);
+	SAFE_WAIT(NULL);
+}
+
+void test_bad_address(swi_func sigwaitinfo, int signo,
+		      enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
+{
+	sigset_t sigs, oldmask;
+	pid_t child;
+
+	TEST(sigemptyset(&sigs));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
+
+	TEST(sigaddset(&sigs, signo));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+
+	/* let's not get interrupted by our dying child */
+	TEST(sigaddset(&sigs, SIGCHLD));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
+
+	TEST(sigprocmask(SIG_SETMASK, &sigs, &oldmask));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigprocmask() failed");
+
+	/* don't wait on a SIGCHLD */
+	TEST(sigdelset(&sigs, SIGCHLD));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigdelset() failed");
+
+	/* Run a child that will wake us up */
+	child = create_sig_proc(signo, 1, 0);
+
+	TEST(sigwaitinfo(&sigs, (void *)1, NULL));
+	REPORT_SUCCESS(-1, EFAULT);
+
+	TEST(sigprocmask(SIG_SETMASK, &oldmask, &oldmask));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigprocmask() failed");
+
+	SAFE_KILL(child, SIGTERM);
+	SAFE_WAIT(NULL);
+}
+
+void test_bad_address2(swi_func sigwaitinfo, int signo LTP_ATTRIBUTE_UNUSED,
+		       enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
+{
+	pid_t pid;
+	int status;
+
+	switch (pid = fork()) {
+	case -1:
+		tst_brk(TBROK | TERRNO, "fork() failed");
+	case 0:
+		signal(SIGSEGV, SIG_DFL);
+
+		/*
+		 * depending on glibc implementation we should
+		 * either crash or get EFAULT
+		 */
+		TEST(sigwaitinfo((void *)1, NULL, NULL));
+
+		if (TST_RET == -1 && TST_ERR == EFAULT)
+			_exit(0);
+
+		tst_res(TINFO | TTERRNO, "swi_func returned: %ld",
+			TST_RET);
+		_exit(1);
+		break;
+	default:
+		break;
+	}
+
+	SAFE_WAITPID(pid, &status, 0);
+
+	if ((WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV)
+		|| (WIFEXITED(status) && WEXITSTATUS(status) == 0)) {
+		tst_res(TPASS, "Test passed");
+		return;
+	}
+
+	if (WIFEXITED(status)) {
+		tst_res(TFAIL, "Unrecognised child exit code: %d",
+			WEXITSTATUS(status));
+	}
+	if (WIFSIGNALED(status)) {
+		tst_res(TFAIL, "Unrecognised child termsig: %d",
+			WTERMSIG(status));
+	}
+}
+
+void test_bad_address3(swi_func sigwaitinfo, int signo LTP_ATTRIBUTE_UNUSED,
+		       enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
+{
+	sigset_t sigs;
+	TEST(sigemptyset(&sigs));
+	if (TST_RET == -1)
+		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
+
+	TEST(sigwaitinfo(&sigs, NULL, (void *)1));
+	REPORT_SUCCESS(-1, EFAULT);
+}
+
+static void empty_handler(int sig LTP_ATTRIBUTE_UNUSED)
+{
+}
+
+void sigwait_setup(void)
+{
+	signal(SIGUSR1, empty_handler);
+	signal(SIGALRM, empty_handler);
+	signal(SIGUSR2, SIG_IGN);
+
+	alarm(10);	/* arrange a 10 second timeout */
+}
+
+void sigwait_cleanup(void)
+{
+	alarm(0);
+}
diff --git a/testcases/kernel/syscalls/rt_sigtimedwait/Makefile b/testcases/kernel/syscalls/rt_sigtimedwait/Makefile
index 9524bf91e65e..2055e703b653 100644
--- a/testcases/kernel/syscalls/rt_sigtimedwait/Makefile
+++ b/testcases/kernel/syscalls/rt_sigtimedwait/Makefile
@@ -3,14 +3,10 @@
 
 top_srcdir ?= ../../../..
 
-include $(top_srcdir)/include/mk/testcases.mk
-
-CPPFLAGS += -DTEST_RT_SIGTIMEDWAIT
+LTPLIBS = ltpsigwait
 
-rt_sigtimedwait01: $(abs_srcdir)/../sigwaitinfo/sigwaitinfo01.c
-	$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) $(OUTPUT_OPTION)
+include $(top_srcdir)/include/mk/testcases.mk
 
-MAKE_TARGETS := rt_sigtimedwait01
+LDLIBS  := -lltpsigwait $(LDLIBS)
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
-
diff --git a/testcases/kernel/syscalls/rt_sigtimedwait/rt_sigtimedwait01.c b/testcases/kernel/syscalls/rt_sigtimedwait/rt_sigtimedwait01.c
new file mode 100644
index 000000000000..8b6153744938
--- /dev/null
+++ b/testcases/kernel/syscalls/rt_sigtimedwait/rt_sigtimedwait01.c
@@ -0,0 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright (c) Jiri Palecek<jpalecek@web.de>, 2009 */
+
+#include "libsigwait.h"
+
+static int my_rt_sigtimedwait(const sigset_t * set, siginfo_t * info,
+			      void *timeout)
+{
+	/* _NSIG is always the right number of bits of signal map for all arches */
+	return tst_syscall(__NR_rt_sigtimedwait, set, info, timeout, _NSIG/8);
+}
+
+#if (__NR_rt_sigtimedwait_time64 != __LTP__NR_INVALID_SYSCALL)
+static int my_rt_sigtimedwait_time64(const sigset_t * set, siginfo_t * info,
+				     void *timeout)
+{
+	/* _NSIG is always the right number of bits of signal map for all arches */
+	return tst_syscall(__NR_rt_sigtimedwait_time64, set, info, timeout, _NSIG/8);
+}
+#endif
+
+struct sigwait_test_desc tests[] = {
+	{ test_empty_set, SIGUSR1},
+	{ test_unmasked_matching, SIGUSR1},
+	{ test_masked_matching, SIGUSR1},
+	{ test_unmasked_matching_noinfo, SIGUSR1},
+	{ test_masked_matching_noinfo, SIGUSR1},
+	{ test_bad_address, SIGUSR1},
+	{ test_bad_address2, SIGUSR1},
+	{ test_bad_address3, SIGUSR1},
+	{ test_timeout, 0},
+	/* Special cases */
+	/* 1: sigwaitinfo does respond to ignored signal */
+	{ test_masked_matching, SIGUSR2},
+	/* 2: An ignored signal doesn't cause sigwaitinfo to return EINTR */
+	{ test_timeout, SIGUSR2},
+	/* 3: The handler is not called when the signal is waited for by sigwaitinfo */
+	{ test_masked_matching, SIGTERM},
+	/* 4: Simultaneous realtime signals are delivered in the order of increasing signal number */
+	{ test_masked_matching_rt, -1},
+};
+
+static struct test_variants {
+	swi_func swi;
+	enum tst_ts_type type;
+	char *desc;
+} variants[] = {
+#if (__NR_rt_sigtimedwait != __LTP__NR_INVALID_SYSCALL)
+	{ .swi = my_rt_sigtimedwait, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"},
+#endif
+
+#if (__NR_rt_sigtimedwait_time64 != __LTP__NR_INVALID_SYSCALL)
+	{ .swi = my_rt_sigtimedwait_time64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"},
+#endif
+};
+
+static void run(unsigned int i)
+{
+	struct test_variants *tv = &variants[tst_variant];
+	struct sigwait_test_desc *tc = &tests[i];
+
+	tc->tf(tv->swi, tc->signo, tv->type);
+}
+
+static void setup(void)
+{
+	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
+	sigwait_setup();
+}
+
+static struct tst_test test = {
+	.test= run,
+	.tcnt = ARRAY_SIZE(tests),
+	.test_variants = ARRAY_SIZE(variants),
+	.setup = setup,
+	.cleanup = sigwait_cleanup,
+	.forks_child = 1,
+};
diff --git a/testcases/kernel/syscalls/sigtimedwait/Makefile b/testcases/kernel/syscalls/sigtimedwait/Makefile
index 7ba1f9c0571d..2055e703b653 100644
--- a/testcases/kernel/syscalls/sigtimedwait/Makefile
+++ b/testcases/kernel/syscalls/sigtimedwait/Makefile
@@ -3,13 +3,10 @@
 
 top_srcdir ?= ../../../..
 
-include $(top_srcdir)/include/mk/testcases.mk
-
-CPPFLAGS += -DTEST_SIGTIMEDWAIT
+LTPLIBS = ltpsigwait
 
-sigtimedwait01: $(abs_srcdir)/../sigwaitinfo/sigwaitinfo01.c
-	$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) $(OUTPUT_OPTION)
+include $(top_srcdir)/include/mk/testcases.mk
 
-MAKE_TARGETS := sigtimedwait01
+LDLIBS  := -lltpsigwait $(LDLIBS)
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/sigtimedwait/sigtimedwait01.c b/testcases/kernel/syscalls/sigtimedwait/sigtimedwait01.c
new file mode 100644
index 000000000000..946d8e7239a0
--- /dev/null
+++ b/testcases/kernel/syscalls/sigtimedwait/sigtimedwait01.c
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright (c) Jiri Palecek<jpalecek@web.de>, 2009 */
+
+#include "libsigwait.h"
+
+static int my_sigtimedwait(const sigset_t * set, siginfo_t * info,
+			   void *timeout)
+{
+	return sigtimedwait(set, info, timeout);
+}
+
+struct sigwait_test_desc tests[] = {
+	{ test_empty_set, SIGUSR1},
+	{ test_unmasked_matching, SIGUSR1},
+	{ test_masked_matching, SIGUSR1},
+	{ test_unmasked_matching_noinfo, SIGUSR1},
+	{ test_masked_matching_noinfo, SIGUSR1},
+	{ test_bad_address, SIGUSR1},
+	{ test_bad_address2, SIGUSR1},
+	{ test_bad_address3, SIGUSR1},
+	{ test_timeout, 0},
+};
+
+static void run(unsigned int i)
+{
+	struct sigwait_test_desc *tc = &tests[i];
+
+	tc->tf(my_sigtimedwait, tc->signo, TST_LIBC_TIMESPEC);
+}
+
+static struct tst_test test = {
+	.test= run,
+	.tcnt = ARRAY_SIZE(tests),
+	.setup = sigwait_setup,
+	.cleanup = sigwait_cleanup,
+	.forks_child = 1,
+};
diff --git a/testcases/kernel/syscalls/sigwait/Makefile b/testcases/kernel/syscalls/sigwait/Makefile
index e1e4ad486af9..2055e703b653 100644
--- a/testcases/kernel/syscalls/sigwait/Makefile
+++ b/testcases/kernel/syscalls/sigwait/Makefile
@@ -3,13 +3,10 @@
 
 top_srcdir ?= ../../../..
 
-include $(top_srcdir)/include/mk/testcases.mk
-
-CPPFLAGS += -DTEST_SIGWAIT
+LTPLIBS = ltpsigwait
 
-sigwait01: $(abs_srcdir)/../sigwaitinfo/sigwaitinfo01.c
-	$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) $(OUTPUT_OPTION)
+include $(top_srcdir)/include/mk/testcases.mk
 
-MAKE_TARGETS := sigwait01
+LDLIBS  := -lltpsigwait $(LDLIBS)
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/sigwait/sigwait01.c b/testcases/kernel/syscalls/sigwait/sigwait01.c
new file mode 100644
index 000000000000..563d15635fd9
--- /dev/null
+++ b/testcases/kernel/syscalls/sigwait/sigwait01.c
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/* Copyright (c) Jiri Palecek<jpalecek@web.de>, 2009 */
+
+#include "libsigwait.h"
+
+static int my_sigwait(const sigset_t * set,
+		      siginfo_t * info LTP_ATTRIBUTE_UNUSED,
+		      void *timeout LTP_ATTRIBUTE_UNUSED)
+{
+	int ret;
+	int err = sigwait(set, &ret);
+
+	if (err == 0)
+		return ret;
+	errno = err;
+	return -1;
+}
+
+struct sigwait_test_desc tests[] = {
+	{ test_unmasked_matching_noinfo, SIGUSR1},
+	{ test_masked_matching_noinfo, SIGUSR1},
+};
+
+static void run(unsigned int i)
+{
+	struct sigwait_test_desc *tc = &tests[i];
+
+	tc->tf(my_sigwait, tc->signo, TST_LIBC_TIMESPEC);
+}
+
+static struct tst_test test = {
+	.test= run,
+	.tcnt = ARRAY_SIZE(tests),
+	.setup = sigwait_setup,
+	.cleanup = sigwait_cleanup,
+	.forks_child = 1,
+};
diff --git a/testcases/kernel/syscalls/sigwaitinfo/Makefile b/testcases/kernel/syscalls/sigwaitinfo/Makefile
index 27c6b72c40a3..2055e703b653 100644
--- a/testcases/kernel/syscalls/sigwaitinfo/Makefile
+++ b/testcases/kernel/syscalls/sigwaitinfo/Makefile
@@ -3,8 +3,10 @@
 
 top_srcdir ?= ../../../..
 
+LTPLIBS = ltpsigwait
+
 include $(top_srcdir)/include/mk/testcases.mk
 
-CPPFLAGS += -DTEST_SIGWAITINFO
+LDLIBS  := -lltpsigwait $(LDLIBS)
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
diff --git a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
index 5e1baf9df774..6563d14f0ec7 100644
--- a/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
+++ b/testcases/kernel/syscalls/sigwaitinfo/sigwaitinfo01.c
@@ -1,584 +1,35 @@
 // SPDX-License-Identifier: GPL-2.0-or-later
 /* Copyright (c) Jiri Palecek<jpalecek@web.de>, 2009 */
 
-#include "tst_test.h"
-#include "tst_timer.h"
-#include <errno.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <limits.h>
-#include "lapi/syscalls.h"
-#include "tst_sig_proc.h"
+#include "libsigwait.h"
 
-/* Report success iff TST_RET and TST_ERR are equal to
-	 exp_return and exp_errno, resp., and cond is true. If cond is not
-	 true, report condition_errmsg
-*/
-static void report_success_cond(const char *func, int line,
-				long exp_return, int exp_errno, int condition,
-				char *condition_errmsg)
-{
-	if (exp_return == TST_RET
-	    && (exp_return != -1 || exp_errno == TST_ERR))
-		if (condition)
-			tst_res(TPASS, "%s (%d): Test passed", func, line);
-		else
-			tst_res(TFAIL, "%s (%d): %s", func, line,
-				 condition_errmsg);
-	else if (TST_RET != -1)
-		tst_res(TFAIL,
-			 "%s (%d): Unexpected return value; expected %ld, got %ld",
-			 func, line, exp_return, TST_RET);
-	else
-		tst_res(TFAIL | TTERRNO, "%s (%d): Unexpected failure",
-			 func, line);
-}
-
-#define REPORT_SUCCESS_COND(exp_return, exp_errno, condition, condition_errmsg)	\
-	report_success_cond(__FUNCTION__, __LINE__, exp_return, exp_errno, condition, condition_errmsg);
-
-/* Report success iff TST_RET and TST_ERR are equal to
-	 exp_return and exp_errno, resp.
-*/
-#define REPORT_SUCCESS(exp_return, exp_errno)					\
-	REPORT_SUCCESS_COND(exp_return, exp_errno, 1, "");
-
-static void empty_handler(int sig LTP_ATTRIBUTE_UNUSED)
-{
-}
-
-typedef int (*swi_func) (const sigset_t * set, siginfo_t * info,
-			 void * timeout);
-typedef void (*test_func) (swi_func, int, enum tst_ts_type type);
-
-#ifdef TEST_SIGWAIT
-static int my_sigwait(const sigset_t * set, siginfo_t * info,
-		      void *timeout)
-{
-	int ret;
-	int err = sigwait(set, &ret);
-
-	if (err == 0)
-		return ret;
-	errno = err;
-	return -1;
-}
-#endif
-
-#ifdef TEST_SIGWAITINFO
 static int my_sigwaitinfo(const sigset_t * set, siginfo_t * info,
 			  void *timeout LTP_ATTRIBUTE_UNUSED)
 {
 	return sigwaitinfo(set, info);
 }
-#endif
-
-#ifdef TEST_SIGTIMEDWAIT
-static int my_sigtimedwait(const sigset_t * set, siginfo_t * info,
-			   void *timeout)
-{
-	return sigtimedwait(set, info, timeout);
-}
-#endif
-
-#ifdef TEST_RT_SIGTIMEDWAIT
-static int my_rt_sigtimedwait(const sigset_t * set, siginfo_t * info,
-			      void *timeout)
-{
-	/* _NSIG is always the right number of bits of signal map for all arches */
-	return tst_syscall(__NR_rt_sigtimedwait, set, info, timeout, _NSIG/8);
-}
-
-#if (__NR_rt_sigtimedwait_time64 != __LTP__NR_INVALID_SYSCALL)
-static int my_rt_sigtimedwait_time64(const sigset_t * set, siginfo_t * info,
-				     void *timeout)
-{
-	/* _NSIG is always the right number of bits of signal map for all arches */
-	return tst_syscall(__NR_rt_sigtimedwait_time64, set, info, timeout, _NSIG/8);
-}
-#endif
-#endif
-
-void test_empty_set(swi_func sigwaitinfo, int signo,
-		    enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
-{
-	sigset_t sigs;
-	siginfo_t si;
-	pid_t child;
-
-	TEST(sigemptyset(&sigs));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
-
-	/* Run a child that will wake us up */
-	child = create_sig_proc(signo, INT_MAX, 100000);
-
-	TEST(sigwaitinfo(&sigs, &si, NULL));
-	REPORT_SUCCESS(-1, EINTR);
-
-	SAFE_KILL(child, SIGTERM);
-	SAFE_WAIT(NULL);
-}
-
-void test_timeout(swi_func sigwaitinfo, int signo, enum tst_ts_type type)
-{
-	sigset_t sigs;
-	siginfo_t si;
-	pid_t child;
-	struct tst_ts ts;
-
-	ts.type = type;
-	tst_ts_set_sec(&ts, 1);
-	tst_ts_set_nsec(&ts, 0);
-
-	TEST(sigemptyset(&sigs));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
-
-	/* Run a child that will wake us up */
-	child = create_sig_proc(signo, INT_MAX, 100000);
-
-	TEST(sigwaitinfo(&sigs, &si, tst_ts_get(&ts)));
-	REPORT_SUCCESS(-1, EAGAIN);
-
-	SAFE_KILL(child, SIGTERM);
-	SAFE_WAIT(NULL);
-}
-
-/* Note: sigwait-ing for a signal that is not blocked is unspecified
- * by POSIX; but works for non-ignored signals under Linux
- */
-void test_unmasked_matching(swi_func sigwaitinfo, int signo,
-			    enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
-{
-	sigset_t sigs;
-	siginfo_t si;
-	pid_t child;
-
-	TEST(sigemptyset(&sigs));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
-
-	TEST(sigaddset(&sigs, signo));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
-
-	/* Run a child that will wake us up */
-	child = create_sig_proc(signo, INT_MAX, 100000);
-
-	TEST(sigwaitinfo(&sigs, &si, NULL));
-	REPORT_SUCCESS_COND(signo, 0, si.si_pid == child
-			    && si.si_code == SI_USER
-			    && si.si_signo == signo, "Struct siginfo mismatch");
-
-	SAFE_KILL(child, SIGTERM);
-	SAFE_WAIT(NULL);
-}
-
-void test_unmasked_matching_noinfo(swi_func sigwaitinfo, int signo,
-				   enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
-{
-	sigset_t sigs;
-	pid_t child;
-
-	TEST(sigemptyset(&sigs));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
-
-	TEST(sigaddset(&sigs, signo));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
-
-	/* Run a child that will wake us up */
-	child = create_sig_proc(signo, INT_MAX, 100000);
-
-	TEST(sigwaitinfo(&sigs, NULL, NULL));
-	REPORT_SUCCESS(signo, 0);
-
-	SAFE_KILL(child, SIGTERM);
-	SAFE_WAIT(NULL);
-}
-
-void test_masked_matching(swi_func sigwaitinfo, int signo,
-			  enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
-{
-	sigset_t sigs, oldmask;
-	siginfo_t si;
-	pid_t child;
-
-	TEST(sigemptyset(&sigs));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
-
-	TEST(sigaddset(&sigs, signo));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
-
-	/* let's not get interrupted by our dying child */
-	TEST(sigaddset(&sigs, SIGCHLD));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
-
-	TEST(sigprocmask(SIG_SETMASK, &sigs, &oldmask));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigprocmask() failed");
-
-	/* don't wait on a SIGCHLD */
-	TEST(sigdelset(&sigs, SIGCHLD));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigdelset() failed");
-
-	/* Run a child that will wake us up */
-	child = create_sig_proc(signo, 1, 0);
-
-	TEST(sigwaitinfo(&sigs, &si, NULL));
-	REPORT_SUCCESS_COND(signo, 0, si.si_pid == child
-			    && si.si_code == SI_USER
-			    && si.si_signo == signo, "Struct siginfo mismatch");
-
-	TEST(sigprocmask(SIG_SETMASK, &oldmask, &oldmask));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "restoring original signal mask failed");
-
-	if (sigismember(&oldmask, signo))
-		tst_res(TPASS, "sigwaitinfo restored the original mask");
-	else
-		tst_res(TFAIL,
-			 "sigwaitinfo failed to restore the original mask");
-
-	SAFE_KILL(child, SIGTERM);
-	SAFE_WAIT(NULL);
-}
-
-void test_masked_matching_rt(swi_func sigwaitinfo, int signo,
-			     enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
-{
-	sigset_t sigs, oldmask;
-	siginfo_t si;
-	pid_t child[2];
-	int status;
-
-	signo = SIGRTMIN + 1;
 
-	TEST(sigemptyset(&sigs));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
-
-	TEST(sigaddset(&sigs, signo));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
-
-	TEST(sigaddset(&sigs, signo + 1));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
-
-	/* let's not get interrupted by our dying child */
-	TEST(sigaddset(&sigs, SIGCHLD));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
-
-	TEST(sigprocmask(SIG_SETMASK, &sigs, &oldmask));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigprocmask() failed");
-
-	/* don't wait on a SIGCHLD */
-	TEST(sigdelset(&sigs, SIGCHLD));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigdelset() failed");
-
-	/* Run a child that will wake us up */
-	child[0] = create_sig_proc(signo, 1, 0);
-	child[1] = create_sig_proc(signo + 1, 1, 0);
-
-	/* Ensure that the signals have been sent */
-	SAFE_WAITPID(child[0], &status, 0);
-	SAFE_WAITPID(child[1], &status, 0);
-
-	TEST(sigwaitinfo(&sigs, &si, NULL));
-	REPORT_SUCCESS_COND(signo, 0, si.si_pid == child[0]
-			    && si.si_code == SI_USER
-			    && si.si_signo == signo, "Struct siginfo mismatch");
-
-	/* eat the other signal */
-	TEST(sigwaitinfo(&sigs, &si, NULL));
-	REPORT_SUCCESS_COND(signo + 1, 0, si.si_pid == child[1]
-			    && si.si_code == SI_USER
-			    && si.si_signo == signo + 1,
-			    "Struct siginfo mismatch");
-
-	TEST(sigprocmask(SIG_SETMASK, &oldmask, &oldmask));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "restoring original signal mask failed");
-
-	if (sigismember(&oldmask, signo))
-		tst_res(TPASS, "sigwaitinfo restored the original mask");
-	else
-		tst_res(TFAIL,
-			 "sigwaitinfo failed to restore the original mask");
-}
-
-void test_masked_matching_noinfo(swi_func sigwaitinfo, int signo,
-				 enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
-{
-	sigset_t sigs, oldmask;
-	pid_t child;
-
-	TEST(sigemptyset(&sigs));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
-
-	TEST(sigaddset(&sigs, signo));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
-
-	/* let's not get interrupted by our dying child */
-	TEST(sigaddset(&sigs, SIGCHLD));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
-
-	TEST(sigprocmask(SIG_SETMASK, &sigs, &oldmask));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigprocmask() failed");
-
-	/* don't wait on a SIGCHLD */
-	TEST(sigdelset(&sigs, SIGCHLD));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigdelset() failed");
-
-	/* Run a child that will wake us up */
-	child = create_sig_proc(signo, 1, 0);
-
-	TEST(sigwaitinfo(&sigs, NULL, NULL));
-	REPORT_SUCCESS(signo, 0);
-
-	TEST(sigprocmask(SIG_SETMASK, &oldmask, &oldmask));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "restoring original signal mask failed");
-
-	if (sigismember(&oldmask, signo))
-		tst_res(TPASS, "sigwaitinfo restored the original mask");
-	else
-		tst_res(TFAIL,
-			 "sigwaitinfo failed to restore the original mask");
-
-	SAFE_KILL(child, SIGTERM);
-	SAFE_WAIT(NULL);
-}
-
-void test_bad_address(swi_func sigwaitinfo, int signo,
-		      enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
-{
-	sigset_t sigs, oldmask;
-	pid_t child;
-
-	TEST(sigemptyset(&sigs));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
-
-	TEST(sigaddset(&sigs, signo));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
-
-	/* let's not get interrupted by our dying child */
-	TEST(sigaddset(&sigs, SIGCHLD));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigaddset() failed");
-
-	TEST(sigprocmask(SIG_SETMASK, &sigs, &oldmask));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigprocmask() failed");
-
-	/* don't wait on a SIGCHLD */
-	TEST(sigdelset(&sigs, SIGCHLD));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigdelset() failed");
-
-	/* Run a child that will wake us up */
-	child = create_sig_proc(signo, 1, 0);
-
-	TEST(sigwaitinfo(&sigs, (void *)1, NULL));
-	REPORT_SUCCESS(-1, EFAULT);
-
-	TEST(sigprocmask(SIG_SETMASK, &oldmask, &oldmask));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigprocmask() failed");
-
-	SAFE_KILL(child, SIGTERM);
-	SAFE_WAIT(NULL);
-}
-
-void test_bad_address2(swi_func sigwaitinfo, int signo LTP_ATTRIBUTE_UNUSED,
-		       enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
-{
-	pid_t pid;
-	int status;
-
-	switch (pid = fork()) {
-	case -1:
-		tst_brk(TBROK | TERRNO, "fork() failed");
-	case 0:
-		signal(SIGSEGV, SIG_DFL);
-
-		/*
-		 * depending on glibc implementation we should
-		 * either crash or get EFAULT
-		 */
-		TEST(sigwaitinfo((void *)1, NULL, NULL));
-
-		if (TST_RET == -1 && TST_ERR == EFAULT)
-			_exit(0);
-
-		tst_res(TINFO | TTERRNO, "swi_func returned: %ld",
-			TST_RET);
-		_exit(1);
-		break;
-	default:
-		break;
-	}
-
-	SAFE_WAITPID(pid, &status, 0);
-
-	if ((WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV)
-		|| (WIFEXITED(status) && WEXITSTATUS(status) == 0)) {
-		tst_res(TPASS, "Test passed");
-		return;
-	}
-
-	if (WIFEXITED(status)) {
-		tst_res(TFAIL, "Unrecognised child exit code: %d",
-			WEXITSTATUS(status));
-	}
-	if (WIFSIGNALED(status)) {
-		tst_res(TFAIL, "Unrecognised child termsig: %d",
-			WTERMSIG(status));
-	}
-}
-
-void test_bad_address3(swi_func sigwaitinfo, int signo LTP_ATTRIBUTE_UNUSED,
-		       enum tst_ts_type type LTP_ATTRIBUTE_UNUSED)
-{
-	sigset_t sigs;
-	TEST(sigemptyset(&sigs));
-	if (TST_RET == -1)
-		tst_brk(TBROK | TTERRNO, "sigemptyset() failed");
-
-	TEST(sigwaitinfo(&sigs, NULL, (void *)1));
-	REPORT_SUCCESS(-1, EFAULT);
-}
-
-struct test_desc {
-	test_func tf;
-	swi_func swi;
-	int signo;
-} tests[] = {
-#ifdef TEST_RT_SIGTIMEDWAIT
-	{
-	test_empty_set, NULL, SIGUSR1}, {
-	test_unmasked_matching, NULL, SIGUSR1}, {
-	test_masked_matching, NULL, SIGUSR1}, {
-	test_unmasked_matching_noinfo, NULL, SIGUSR1}, {
-	test_masked_matching_noinfo, NULL, SIGUSR1}, {
-	test_bad_address, NULL, SIGUSR1}, {
-	test_bad_address2, NULL, SIGUSR1}, {
-	test_bad_address3, NULL, SIGUSR1}, {
-	test_timeout, NULL, 0},
-	    /* Special cases */
-	    /* 1: sigwaitinfo does respond to ignored signal */
-	{
-	test_masked_matching, NULL, SIGUSR2},
-	    /* 2: An ignored signal doesn't cause sigwaitinfo to return EINTR */
-	{
-	test_timeout, NULL, SIGUSR2},
-	    /* 3: The handler is not called when the signal is waited for by sigwaitinfo */
-	{
-	test_masked_matching, NULL, SIGTERM},
-	    /* 4: Simultaneous realtime signals are delivered in the order of increasing signal number */
-	{
-	test_masked_matching_rt, NULL, -1},
-#endif
-#if defined TEST_SIGWAIT
-	{
-	test_unmasked_matching_noinfo, my_sigwait, SIGUSR1}, {
-	test_masked_matching_noinfo, my_sigwait, SIGUSR1},
-#endif
-#if defined TEST_SIGWAITINFO
-	{
-	test_empty_set, my_sigwaitinfo, SIGUSR1}, {
-	test_unmasked_matching, my_sigwaitinfo, SIGUSR1}, {
-	test_masked_matching, my_sigwaitinfo, SIGUSR1}, {
-	test_unmasked_matching_noinfo, my_sigwaitinfo, SIGUSR1}, {
-	test_masked_matching_noinfo, my_sigwaitinfo, SIGUSR1}, {
-	test_bad_address, my_sigwaitinfo, SIGUSR1}, {
-	test_bad_address2, my_sigwaitinfo, SIGUSR1},
-#endif
-#if defined TEST_SIGTIMEDWAIT
-	{
-	test_empty_set, my_sigtimedwait, SIGUSR1}, {
-	test_unmasked_matching, my_sigtimedwait, SIGUSR1}, {
-	test_masked_matching, my_sigtimedwait, SIGUSR1}, {
-	test_unmasked_matching_noinfo, my_sigtimedwait, SIGUSR1}, {
-	test_masked_matching_noinfo, my_sigtimedwait, SIGUSR1}, {
-	test_bad_address, my_sigtimedwait, SIGUSR1}, {
-	test_bad_address2, my_sigtimedwait, SIGUSR1}, {
-	test_bad_address3, my_sigtimedwait, SIGUSR1}, {
-	test_timeout, my_sigtimedwait, 0},
-#endif
-};
-
-static struct test_variants {
-	swi_func swi;
-	enum tst_ts_type type;
-	char *desc;
-} variants[] = {
-#ifdef TEST_RT_SIGTIMEDWAIT
-
-#if (__NR_rt_sigtimedwait != __LTP__NR_INVALID_SYSCALL)
-	{ .swi = my_rt_sigtimedwait, .type = TST_KERN_OLD_TIMESPEC, .desc = "syscall with old kernel spec"},
-#endif
-
-#if (__NR_rt_sigtimedwait_time64 != __LTP__NR_INVALID_SYSCALL)
-	{ .swi = my_rt_sigtimedwait_time64, .type = TST_KERN_TIMESPEC, .desc = "syscall time64 with kernel spec"},
-#endif
-
-#else /* !TEST_RT_SIGTIMEDWAIT */
-
-	{ .swi = NULL, .type = TST_LIBC_TIMESPEC, .desc = "syscall with libc spec"},
-
-#endif /* TEST_RT_SIGTIMEDWAIT */
+struct sigwait_test_desc tests[] = {
+	{ test_empty_set, SIGUSR1},
+	{ test_unmasked_matching, SIGUSR1},
+	{ test_masked_matching, SIGUSR1},
+	{ test_unmasked_matching_noinfo, SIGUSR1},
+	{ test_masked_matching_noinfo, SIGUSR1},
+	{ test_bad_address, SIGUSR1},
+	{ test_bad_address2, SIGUSR1},
 };
 
 static void run(unsigned int i)
 {
-	struct test_variants *tv = &variants[tst_variant];
-	struct test_desc *tc = &tests[i];
-	swi_func swi;
-
-	swi = tv->swi ? tv->swi : tc->swi;
+	struct sigwait_test_desc *tc = &tests[i];
 
-	tc->tf(swi, tc->signo, tv->type);
-}
-
-static void setup(void)
-{
-	tst_res(TINFO, "Testing variant: %s", variants[tst_variant].desc);
-
-	signal(SIGUSR1, empty_handler);
-	signal(SIGALRM, empty_handler);
-	signal(SIGUSR2, SIG_IGN);
-
-	alarm(10);	/* arrange a 10 second timeout */
-}
-
-static void cleanup(void)
-{
-	alarm(0);
+	tc->tf(my_sigwaitinfo, tc->signo, TST_LIBC_TIMESPEC);
 }
 
 static struct tst_test test = {
 	.test= run,
 	.tcnt = ARRAY_SIZE(tests),
-	.test_variants = ARRAY_SIZE(variants),
-	.setup = setup,
-	.cleanup = cleanup,
+	.setup = sigwait_setup,
+	.cleanup = sigwait_cleanup,
 	.forks_child = 1,
 };
-- 
2.14.1


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

* [LTP] [PATCH V2 2/3] syscalls: sigwaitinfo: Remove SUCCEED_OR_DIE() macro
  2020-07-21  8:52 ` [LTP] [PATCH V2 2/3] syscalls: sigwaitinfo: Remove SUCCEED_OR_DIE() macro Viresh Kumar
@ 2020-07-22 10:09   ` Cyril Hrubis
  2020-07-22 10:11     ` Cyril Hrubis
  0 siblings, 1 reply; 7+ messages in thread
From: Cyril Hrubis @ 2020-07-22 10:09 UTC (permalink / raw)
  To: ltp

Hi!
> The macro makes it less readable and there isn't a great deal of code it
> is trying to remove. Get rid of it.

Looking at the code we may as well add SAFE_SIGEMPTYSET() and
SAFE_SIGADDSET() instead, what do you think?

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH V2 2/3] syscalls: sigwaitinfo: Remove SUCCEED_OR_DIE() macro
  2020-07-22 10:09   ` Cyril Hrubis
@ 2020-07-22 10:11     ` Cyril Hrubis
  0 siblings, 0 replies; 7+ messages in thread
From: Cyril Hrubis @ 2020-07-22 10:11 UTC (permalink / raw)
  To: ltp

Hi!
> > The macro makes it less readable and there isn't a great deal of code it
> > is trying to remove. Get rid of it.
> 
> Looking at the code we may as well add SAFE_SIGEMPTYSET() and
> SAFE_SIGADDSET() instead, what do you think?

Looking at the patch that separates the files, it may be easier to apply
that and do this on the top of that...

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH V2 3/3] syscalls: sigwait: Separate out code to relevant folders
  2020-07-21  8:52 ` [LTP] [PATCH V2 3/3] syscalls: sigwait: Separate out code to relevant folders Viresh Kumar
@ 2020-07-22 14:05   ` Cyril Hrubis
  0 siblings, 0 replies; 7+ messages in thread
From: Cyril Hrubis @ 2020-07-22 14:05 UTC (permalink / raw)
  To: ltp

Hi!
Applied, thanks.

The library still could use some improvements, but the code is much
better after this patchset.

A few things for followup:

* Add the SAFE_SIG* macros and use them
* Remove the useless alarm() in test setup and cleanup
  as the new library maintains timeouts already
* Get rid of the ugly REPORT_SUCCESS() functions

-- 
Cyril Hrubis
chrubis@suse.cz

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

end of thread, other threads:[~2020-07-22 14:05 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-21  8:52 [LTP] [PATCH V2 0/3] syscalls: Rearrange sigwait syscall tests Viresh Kumar
2020-07-21  8:52 ` [LTP] [PATCH V2 1/3] syscalls: sigwaitinfo: Suppress all warnings around unused parameter Viresh Kumar
2020-07-21  8:52 ` [LTP] [PATCH V2 2/3] syscalls: sigwaitinfo: Remove SUCCEED_OR_DIE() macro Viresh Kumar
2020-07-22 10:09   ` Cyril Hrubis
2020-07-22 10:11     ` Cyril Hrubis
2020-07-21  8:52 ` [LTP] [PATCH V2 3/3] syscalls: sigwait: Separate out code to relevant folders Viresh Kumar
2020-07-22 14:05   ` Cyril Hrubis

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.