Skip to contentSkip to conversation

rt_sigpending02: reuse code from sigpending02

PATCH New Matthias Maennich 4 participants 21 messages Mar 8, 2019 – Mar 21, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rt_sigpending02: reuse code from sigpending02

Rather than forking the code of sigpending02 completely, reuse its code for rt_sigpending02 by conditionally compiling the syscalls accordingly.

That way we ensure tests written for either rt_sigpending or sigpending are also considered for the respective other.

---
 .../kernel/syscalls/rt_sigpending/Makefile    |  8 ++++
 .../syscalls/rt_sigpending/rt_sigpending02.c  | 48 -------------------
 testcases/kernel/syscalls/sigpending/Makefile |  2 +
 .../kernel/syscalls/sigpending/sigpending02.c | 16 +++++--
 4 files changed, 23 insertions(+), 51 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c
testcases/kernel/syscalls/rt_sigpending/Makefile +8 -0
index 60c2e0140d85..57ba3dac2e41 100644
@@ -4,4 +4,12 @@
 top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
+
+CPPFLAGS += -DTEST_RT_SIGPENDING
+
+rt_sigpending02: $(abs_srcdir)/../sigpending/sigpending02.c
+	$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) $(OUTPUT_OPTION)
+
+MAKE_TARGETS := rt_sigpending02
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c deleted +0 -48

48 lines not on this page · raw message

testcases/kernel/syscalls/sigpending/Makefile +2 -0
index bd617d806675..00a7d5e2b538 100644
@@ -20,4 +20,6 @@ top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 
+CPPFLAGS += -DTEST_SIGPENDING
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/sigpending/sigpending02.c +13 -3
index e7ec0d6819bd..cc50870b107a 100644
@@ -6,7 +6,10 @@
  *	Paul Larson
  *
  * DESCRIPTION
- *	Test to see that the proper errors are returned by sigpending
+ *	Test to see that the proper errors are returned by sigpending. All the
+ *	tests can also be compiled to use the rt_sigpending syscall instead. To
+ *	simplify the documentation, only sigpending() is usually mentioned
+ *	below.
  *
  *	Test 1:
  *		Call sigpending(sigset_t*=-1), it should return -1 with errno EFAULT
@@ -17,6 +20,7 @@
 #include <sys/types.h>
 
 #include "tst_test.h"
+#include "ltp_signal.h"
 #include "lapi/syscalls.h"
 
 static void run(void)
@@ -24,20 +28,26 @@ static void run(void)
 	/* set sigset to point to an invalid location */
 	sigset_t *sigset = (sigset_t *) - 1;
 
+#if defined(TEST_SIGPENDING)
 	TEST(tst_syscall(__NR_sigpending, sigset));
+#elif defined(TEST_RT_SIGPENDING)
+	TEST(tst_syscall(__NR_rt_sigpending, sigset, SIGSETSIZE));
+#else
+#error Neither TEST_SIGPENDING nor TEST_RT_SIGPENDING is defined!
+#endif
 
 	/* check return code */
 	if (TST_RET == -1) {
 		if (TST_ERR != EFAULT) {
 			tst_res(TFAIL | TTERRNO,
-				"sigpending() Failed with wrong errno, "
+				"syscall failed with wrong errno, "
 				"expected errno=%d, got ", EFAULT);
 		} else {
 			tst_res(TPASS | TTERRNO, "expected failure");
 		}
 	} else {
 		tst_res(TFAIL,
-			"sigpending() Failed, expected return value=-1, got %ld", TST_RET);
+			"syscall failed, expected return value=-1, got %ld", TST_RET);
 	}
 }
 
Signature · 1 line
2.21.0.360.g471c308f928-goog
#1 lore raw

PATCH 1/1 rt_sigpending02: reuse code from sigpending02

Hi Matthias,

Quoted 7 lines · Matthias Maennich' via kernel-team

Rather than forking the code of sigpending02 completely, reuse its code for rt_sigpending02 by conditionally compiling the syscalls accordingly.

That way we ensure tests written for either rt_sigpending or sigpending are also considered for the respective other.

Cyril recently proposed a test multiplex function which hasn't yet gone in:

http://lists.linux.it/pipermail/ltp/2019-March/011119.html

This would remove the need for the custom Makefile bit.

One downside with this multiplexed approach is that we then don't have an entry in the testcases/kernel/syscalls/ directory for all syscalls which can cause some confusion, but that could perhaps be addressed by adding symlinks for the missing ones.

Quoted 144 lines
---
  .../kernel/syscalls/rt_sigpending/Makefile    |  8 ++++
  .../syscalls/rt_sigpending/rt_sigpending02.c  | 48 -------------------
  testcases/kernel/syscalls/sigpending/Makefile |  2 +
  .../kernel/syscalls/sigpending/sigpending02.c | 16 +++++--
  4 files changed, 23 insertions(+), 51 deletions(-)

delete mode 100644 testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c

testcases/kernel/syscalls/rt_sigpending/Makefile +8 -0
index 60c2e0140d85..57ba3dac2e41 100644
@@ -4,4 +4,12 @@
  top_srcdir		?= ../../../..
 
  include $(top_srcdir)/include/mk/testcases.mk
+
+CPPFLAGS += -DTEST_RT_SIGPENDING
+
+rt_sigpending02: $(abs_srcdir)/../sigpending/sigpending02.c
+	$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) $(OUTPUT_OPTION)
+
+MAKE_TARGETS := rt_sigpending02
+
  include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c deleted +0 -48
deleted file mode 100644
index 06d1c1578f4d..000000000000
@@ -1,48 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0
-/*
- *  Copyright (c) International Business Machines  Corp., 2002
- *
- * AUTHORS
- *	Paul Larson
- *
- * DESCRIPTION
- *	Test to see that the proper errors are returned by rt_sigpending
- *
- *	Test 1:
- *		Call rt_sigpending(sigset_t*=-1, SIGSETSIZE),
- *		it should return -1 with errno EFAULT
- */
-
-#include <errno.h>
-#include <signal.h>
-#include <sys/types.h>
-
-#include "tst_test.h"
-#include "ltp_signal.h"
-#include "lapi/syscalls.h"
-
-static void run(void)
-{
-	/* set sigset to point to an invalid location */
-	sigset_t *sigset = (sigset_t *) - 1;
-
-	TEST(tst_syscall(__NR_rt_sigpending, sigset, SIGSETSIZE));
-
-	/* check return code */
-	if (TST_RET == -1) {
-		if (TST_ERR != EFAULT) {
-			tst_res(TFAIL | TTERRNO,
-				"rt_sigpending() Failed with wrong errno, "
-				"expected errno=%d, got ", EFAULT);
-		} else {
-			tst_res(TPASS | TTERRNO, "expected failure");
-		}
-	} else {
-		tst_res(TFAIL,
-			"rt_sigpending() Failed, expected return value=-1, got %ld", TST_RET);
-	}
-}
-
-static struct tst_test test = {
-	.test_all = run
-};
testcases/kernel/syscalls/sigpending/Makefile +2 -0
index bd617d806675..00a7d5e2b538 100644
@@ -20,4 +20,6 @@ top_srcdir		?= ../../../..
 
  include $(top_srcdir)/include/mk/testcases.mk
 
+CPPFLAGS += -DTEST_SIGPENDING
+
  include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/sigpending/sigpending02.c +13 -3
index e7ec0d6819bd..cc50870b107a 100644
@@ -6,7 +6,10 @@
   *	Paul Larson
   *
   * DESCRIPTION
- *	Test to see that the proper errors are returned by sigpending
+ *	Test to see that the proper errors are returned by sigpending. All the
+ *	tests can also be compiled to use the rt_sigpending syscall instead. To
+ *	simplify the documentation, only sigpending() is usually mentioned
+ *	below.
   *
   *	Test 1:
   *		Call sigpending(sigset_t*=-1), it should return -1 with errno EFAULT
@@ -17,6 +20,7 @@
  #include <sys/types.h>
 
  #include "tst_test.h"
+#include "ltp_signal.h"
  #include "lapi/syscalls.h"
 
  static void run(void)
@@ -24,20 +28,26 @@ static void run(void)
  	/* set sigset to point to an invalid location */
  	sigset_t *sigset = (sigset_t *) - 1;
 
+#if defined(TEST_SIGPENDING)
  	TEST(tst_syscall(__NR_sigpending, sigset));
+#elif defined(TEST_RT_SIGPENDING)
+	TEST(tst_syscall(__NR_rt_sigpending, sigset, SIGSETSIZE));
+#else
+#error Neither TEST_SIGPENDING nor TEST_RT_SIGPENDING is defined!
+#endif
 
  	/* check return code */
  	if (TST_RET == -1) {
  		if (TST_ERR != EFAULT) {
  			tst_res(TFAIL | TTERRNO,
-				"sigpending() Failed with wrong errno, "
+				"syscall failed with wrong errno, "
  				"expected errno=%d, got ", EFAULT);
  		} else {
  			tst_res(TPASS | TTERRNO, "expected failure");
  		}
  	} else {
  		tst_res(TFAIL,
-			"sigpending() Failed, expected return value=-1, got %ld", TST_RET);
+			"syscall failed, expected return value=-1, got %ld", TST_RET);
  	}
  }
 
#2 lore raw

PATCH 1/1 rt_sigpending02: reuse code from sigpending02

Hi!

Quoted 4 lines

One downside with this multiplexed approach is that we then don't have an entry in the testcases/kernel/syscalls/ directory for all syscalls which can cause some confusion, but that could perhaps be addressed by adding symlinks for the missing ones.

Actually my long term plan is to include metadata in the testcases which would, among other things, describe which syscalls/libcalls the tests is excercising and I want this information to be propagated to the test runner as well, so instead of relying on one binary file per syscall we would have proper metadata describing the tests.

And the biggest problem here is that it looks that there is very little interest in investing time into this approach. I've send a (quick and dirty) RFC patch that tried to show a direction for such work, but nearly nobody replied to it, so I postponed the work a bit.

See:

http://patchwork.ozlabs.org/project/ltp/list/?series=78493

Signature · 2 lines
Cyril Hrubis
[email protected]
#3 lore raw

PATCH 1/1 rt_sigpending02: reuse code from sigpending02

Hi!

Quoted 5 lines · Cyril Hrubis

Hi!

Quoted 4 lines

One downside with this multiplexed approach is that we then don't have an entry in the testcases/kernel/syscalls/ directory for all syscalls which can cause some confusion, but that could perhaps be addressed by adding symlinks for the missing ones.

I am not sure multiplexing is the right approach here (not saying it is not!). In case of (rt_)sigpending, I would like to see them as separate binaries that effectively do disjunct things. There might be the case that sigpending is not available on that particular kernel and rt_sigpending is. I would like the sigpending to fail with TCONF and the rt_sigpending to TPASS in that case. Is that something that can be achieved with multiplexing?

I was already working on a v2 of this patch set to add a further test case and will send this out shortly. I would like to reconsider multiplexing at a later time and for now follow the pattern of other syscall related tests like sigwait, sigtimedwait, rt_sigtimedwait.

Quoted 7 lines

Actually my long term plan is to include metadata in the testcases which would, among other things, describe which syscalls/libcalls the tests is excercising and I want this information to be propagated to the test runner as well, so instead of relying on one binary file per syscall we would have proper metadata describing the tests.

Quoted 8 lines

And the biggest problem here is that it looks that there is very little interest in investing time into this approach. I've send a (quick and dirty) RFC patch that tried to show a direction for such work, but nearly nobody replied to it, so I postponed the work a bit.

See:

http://patchwork.ozlabs.org/project/ltp/list/?series=78493

That looks actually promising. I will have a more detailed look these days!

Signature · 2 lines
Cheers,
Matthias
#4 lore raw

PATCH 1/1 rt_sigpending02: reuse code from sigpending02

Quoted 3 lines · Matthias Maennich

I am not sure multiplexing is the right approach here (not saying it is not!). In case of (rt_)sigpending, I would like to see them as separate binaries that effectively do disjunct things.

Ok I don't have a strong feeling either way, keeping them as separate binaries seems a little more complex as far as the build goes (i.e. Makefile stuff that has to reach into a sibling directory), but it's also slightly clearer there are tests for both syscalls when perusing the source.

Quoted 4 lines

There might be the case that sigpending is not available on that particular kernel and rt_sigpending is. I would like the sigpending to fail with TCONF and the rt_sigpending to TPASS in that case. Is that something that can be achieved with multiplexing?

Yep tests can return multiple results (have multiple sub-tests) so this is doable.

Quoted 4 lines

I was already working on a v2 of this patch set to add a further test case and will send this out shortly. I would like to reconsider multiplexing at a later time and for now follow the pattern of other syscall related tests like sigwait, sigtimedwait, rt_sigtimedwait.

SGTM

cheers,
steve

#5 lore raw

v2 cover new test cases for sigpending / rt_sigpending

In reply to Matthias Maennich

Hi!

Reusing the code from sigpending for rt_sigpending is a patch I sent in earlier. Based on that this adds a new test case for both syscalls to test the more common use of sigpending.

Cheers,
Matthias

Matthias Maennich (2):
rt_sigpending02: reuse code from sigpending02
sigpending/rt_sigpending: add basic test

 .../kernel/syscalls/rt_sigpending/Makefile    |   8 ++
 .../syscalls/rt_sigpending/rt_sigpending02.c  |  48 --------
 testcases/kernel/syscalls/sigpending/Makefile |   2 +
 .../kernel/syscalls/sigpending/sigpending02.c | 114 +++++++++++++++++-
 4 files changed, 118 insertions(+), 54 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c
Signature · 1 line
2.21.0.360.g471c308f928-goog
#6 lore raw

PATCH v2 1/2 rt_sigpending02: reuse code from sigpending02

Rather than forking the code of sigpending02 completely, reuse its code for rt_sigpending02 by conditionally compiling the syscalls accordingly.

That way we ensure tests written for either rt_sigpending or sigpending are also considered for the respective other.

---
 .../kernel/syscalls/rt_sigpending/Makefile    |  8 ++++
 .../syscalls/rt_sigpending/rt_sigpending02.c  | 48 -------------------
 testcases/kernel/syscalls/sigpending/Makefile |  2 +
 .../kernel/syscalls/sigpending/sigpending02.c | 16 +++++--
 4 files changed, 23 insertions(+), 51 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c
testcases/kernel/syscalls/rt_sigpending/Makefile +8 -0
index 60c2e0140d85..57ba3dac2e41 100644
@@ -4,4 +4,12 @@
 top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
+
+CPPFLAGS += -DTEST_RT_SIGPENDING
+
+rt_sigpending02: $(abs_srcdir)/../sigpending/sigpending02.c
+	$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) $(OUTPUT_OPTION)
+
+MAKE_TARGETS := rt_sigpending02
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c deleted +0 -48

48 lines not on this page · raw message

testcases/kernel/syscalls/sigpending/Makefile +2 -0
index bd617d806675..00a7d5e2b538 100644
@@ -20,4 +20,6 @@ top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 
+CPPFLAGS += -DTEST_SIGPENDING
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/sigpending/sigpending02.c +13 -3
index e7ec0d6819bd..cc50870b107a 100644
@@ -6,7 +6,10 @@
  *	Paul Larson
  *
  * DESCRIPTION
- *	Test to see that the proper errors are returned by sigpending
+ *	Test to see that the proper errors are returned by sigpending. All the
+ *	tests can also be compiled to use the rt_sigpending syscall instead. To
+ *	simplify the documentation, only sigpending() is usually mentioned
+ *	below.
  *
  *	Test 1:
  *		Call sigpending(sigset_t*=-1), it should return -1 with errno EFAULT
@@ -17,6 +20,7 @@
 #include <sys/types.h>
 
 #include "tst_test.h"
+#include "ltp_signal.h"
 #include "lapi/syscalls.h"
 
 static void run(void)
@@ -24,20 +28,26 @@ static void run(void)
 	/* set sigset to point to an invalid location */
 	sigset_t *sigset = (sigset_t *) - 1;
 
+#if defined(TEST_SIGPENDING)
 	TEST(tst_syscall(__NR_sigpending, sigset));
+#elif defined(TEST_RT_SIGPENDING)
+	TEST(tst_syscall(__NR_rt_sigpending, sigset, SIGSETSIZE));
+#else
+#error Neither TEST_SIGPENDING nor TEST_RT_SIGPENDING is defined!
+#endif
 
 	/* check return code */
 	if (TST_RET == -1) {
 		if (TST_ERR != EFAULT) {
 			tst_res(TFAIL | TTERRNO,
-				"sigpending() Failed with wrong errno, "
+				"syscall failed with wrong errno, "
 				"expected errno=%d, got ", EFAULT);
 		} else {
 			tst_res(TPASS | TTERRNO, "expected failure");
 		}
 	} else {
 		tst_res(TFAIL,
-			"sigpending() Failed, expected return value=-1, got %ld", TST_RET);
+			"syscall failed, expected return value=-1, got %ld", TST_RET);
 	}
 }
 
Signature · 1 line
2.21.0.360.g471c308f928-goog
#7 lore raw

PATCH v2 2/2 sigpending/rt_sigpending: add basic test

In reply to Matthias Maennich

Test basic functionality of sigpending/rt_sigpending.

---
 .../kernel/syscalls/sigpending/sigpending02.c | 112 ++++++++++++++++--
 1 file changed, 102 insertions(+), 10 deletions(-)
testcases/kernel/syscalls/sigpending/sigpending02.c +102 -10
index cc50870b107a..e75c6aa69c4c 100644
@@ -4,14 +4,18 @@
  *
  * AUTHORS
  *	Paul Larson
+ *	Matthias Maennich
  *
  * DESCRIPTION
- *	Test to see that the proper errors are returned by sigpending. All the
- *	tests can also be compiled to use the rt_sigpending syscall instead. To
- *	simplify the documentation, only sigpending() is usually mentioned
- *	below.
+ *	Test to assert basic functionality of sigpending. All the tests can also be
+ *	compiled to use the rt_sigpending syscall instead. To simplify the
+ *	documentation, only sigpending() is usually mentioned below.
  *
  *	Test 1:
+ *		Suppress handling SIGUSR1 and SIGUSR1, raise them and assert their
+ *		signal pending.
+ *
+ *	Test 2:
  *		Call sigpending(sigset_t*=-1), it should return -1 with errno EFAULT
  */
 
@@ -23,19 +27,101 @@
 #include "ltp_signal.h"
 #include "lapi/syscalls.h"
 
-static void run(void)
-{
-	/* set sigset to point to an invalid location */
-	sigset_t *sigset = (sigset_t *) - 1;
+#define min(x, y) (((x) < (y)) ? (x) : (y))
 
 #if defined(TEST_SIGPENDING)
-	TEST(tst_syscall(__NR_sigpending, sigset));
+#define tested_sigpending(sigset) TEST(tst_syscall(__NR_sigpending, sigset))
 #elif defined(TEST_RT_SIGPENDING)
-	TEST(tst_syscall(__NR_rt_sigpending, sigset, SIGSETSIZE));
+#define tested_sigpending(sigset)                                              \
+	TEST(tst_syscall(__NR_rt_sigpending, sigset, SIGSETSIZE))
 #else
 #error Neither TEST_SIGPENDING nor TEST_RT_SIGPENDING is defined!
 #endif
 
+static int sighandler_counter = 0;
+static void sighandler(int signum)
+{
+	(void)signum;
+	++sighandler_counter;
+}
+
+static void test_sigpending(void)
+{
+	int SIGMAX = min(sizeof(sigset_t) * 8, _NSIG);
+
+	// set up signal mask and handler
+	sigset_t only_SIGUSR, old_mask;
+	sighandler_t old_sighandler1, old_sighandler2;
+	sigemptyset(&only_SIGUSR);
+	sigaddset(&only_SIGUSR, SIGUSR1);
+	sigaddset(&only_SIGUSR, SIGUSR2);
+	if (sigprocmask(SIG_SETMASK, &only_SIGUSR, &old_mask))
+		tst_brk(TBROK, "sigprocmask failed");
+	old_sighandler1 = SAFE_SIGNAL(SIGUSR1, sighandler);
+	old_sighandler2 = SAFE_SIGNAL(SIGUSR2, sighandler);
+
+	// Initially no signal should be pending
+	sigset_t pending;
+	sigemptyset(&pending);
+	tested_sigpending(&pending);
+
+	for (int i = 1; i < SIGMAX; ++i)
+		if (sigismember(&pending, i))
+			tst_brk(TFAIL,
+				"initialization failed: no signal should be pending by now");
+
+	// raise a signal
+	if (raise(SIGUSR1))
+		tst_brk(TBROK, "raising SIGUSR1 failed");
+	if (sighandler_counter > 0)
+		tst_brk(TFAIL,
+			"signal handler is not (yet) supposed to be called");
+
+	// now we should have exactly one pending signal (SIGUSR1)
+	sigemptyset(&pending);
+	tested_sigpending(&pending);
+	for (int i = 1; i < SIGMAX; ++i)
+		if ((i == SIGUSR1) != sigismember(&pending, i))
+			tst_brk(TFAIL, "only SIGUSR1 should be pending by now");
+
+	// raise another signal
+	if (raise(SIGUSR2))
+		tst_brk(TBROK, "raising SIGUSR2 failed");
+	if (sighandler_counter > 0)
+		tst_brk(TFAIL,
+			"signal handler is not (yet) supposed to be called");
+
+	// now we should have exactly two pending signals (SIGUSR1, SIGUSR2)
+	sigemptyset(&pending);
+	tested_sigpending(&pending);
+	for (int i = 1; i < SIGMAX; ++i)
+		if ((i == SIGUSR1 || i == SIGUSR2) != sigismember(&pending, i))
+			tst_brk(TFAIL,
+				"only SIGUSR1, SIGUSR2 should be pending by now");
+
+	tst_res(TPASS, "basic sigpending test successful");
+
+	// reinstate old mask
+	if (sigprocmask(SIG_SETMASK, &old_mask, NULL))
+		tst_brk(TBROK, "sigprocmask failed");
+
+	//@this time the signal handler has been called, once for each signal
+	if (sighandler_counter != 2)
+		tst_brk(TFAIL,
+			"signal handler has not been called for each signal");
+
+	// reinstate the original signal handlers
+	SAFE_SIGNAL(SIGUSR1, old_sighandler1);
+	SAFE_SIGNAL(SIGUSR2, old_sighandler2);
+}
+
+static void test_efault_on_invalid_sigset(void)
+{
+	/* set sigset to point to an invalid location */
+	sigset_t *sigset = (sigset_t *)-1;
+
+	tested_sigpending(sigset);
+
 	/* check return code */
 	if (TST_RET == -1) {
 		if (TST_ERR != EFAULT) {
@@ -51,6 +137,12 @@ static void run(void)
 	}
 }
 
+static void run(void)
+{
+	test_sigpending();
+	test_efault_on_invalid_sigset();
+}
+
 static struct tst_test test = {
 	.test_all = run
 };
Signature · 1 line
2.21.0.360.g471c308f928-goog
#8 lore raw

PATCH v2 2/2 sigpending/rt_sigpending: add basic test

Hi Matthias I had a couple minor comments,

Quoted 49 lines · Matthias Maennich' via kernel-team

Test basic functionality of sigpending/rt_sigpending.

---
  .../kernel/syscalls/sigpending/sigpending02.c | 112 ++++++++++++++++--
  1 file changed, 102 insertions(+), 10 deletions(-)
testcases/kernel/syscalls/sigpending/sigpending02.c +10 -10
index cc50870b107a..e75c6aa69c4c 100644
@@ -4,14 +4,18 @@
   *
   * AUTHORS
   *	Paul Larson
+ *	Matthias Maennich
   *
   * DESCRIPTION
- *	Test to see that the proper errors are returned by sigpending. All the
- *	tests can also be compiled to use the rt_sigpending syscall instead. To
- *	simplify the documentation, only sigpending() is usually mentioned
- *	below.
+ *	Test to assert basic functionality of sigpending. All the tests can also be
+ *	compiled to use the rt_sigpending syscall instead. To simplify the
+ *	documentation, only sigpending() is usually mentioned below.
   *
   *	Test 1:
+ *		Suppress handling SIGUSR1 and SIGUSR1, raise them and assert their
+ *		signal pending.
+ *
+ *	Test 2:
   *		Call sigpending(sigset_t*=-1), it should return -1 with errno EFAULT
   */
 
@@ -23,19 +27,101 @@
  #include "ltp_signal.h"
  #include "lapi/syscalls.h"
 
-static void run(void)
-{
-	/* set sigset to point to an invalid location */
-	sigset_t *sigset = (sigset_t *) - 1;
+#define min(x, y) (((x) < (y)) ? (x) : (y))
 
  #if defined(TEST_SIGPENDING)
-	TEST(tst_syscall(__NR_sigpending, sigset));
+#define tested_sigpending(sigset) TEST(tst_syscall(__NR_sigpending, sigset))
  #elif defined(TEST_RT_SIGPENDING)
-	TEST(tst_syscall(__NR_rt_sigpending, sigset, SIGSETSIZE));

testcases/kernel/syscalls/sigpending/sigpending02.c line 44

Quoted 10 lines
testcases/kernel/syscalls/sigpending/sigpending02.c +6 -0
+#define tested_sigpending(sigset)                                              \
+	TEST(tst_syscall(__NR_rt_sigpending, sigset, SIGSETSIZE))
  #else
  #error Neither TEST_SIGPENDING nor TEST_RT_SIGPENDING is defined!
  #endif
 
+static int sighandler_counter = 0;
+static void sighandler(int signum)
+{
+	(void)signum;

You can use LTP_ATTRIBUTE_UNUSED on signum to avoid the above statement

testcases/kernel/syscalls/sigpending/sigpending02.c line 52

Quoted 8 lines
testcases/kernel/syscalls/sigpending/sigpending02.c +8 -0
+	++sighandler_counter;
+}
+
+static void test_sigpending(void)
+{
+	int SIGMAX = min(sizeof(sigset_t) * 8, _NSIG);
+
+	// set up signal mask and handler

AFAIK /* */ comments are preferred in new LTP commits.

Quoted 89 lines
testcases/kernel/syscalls/sigpending/sigpending02.c +78 -0
+	sigset_t only_SIGUSR, old_mask;
+	sighandler_t old_sighandler1, old_sighandler2;
+	sigemptyset(&only_SIGUSR);
+	sigaddset(&only_SIGUSR, SIGUSR1);
+	sigaddset(&only_SIGUSR, SIGUSR2);
+	if (sigprocmask(SIG_SETMASK, &only_SIGUSR, &old_mask))
+		tst_brk(TBROK, "sigprocmask failed");
+	old_sighandler1 = SAFE_SIGNAL(SIGUSR1, sighandler);
+	old_sighandler2 = SAFE_SIGNAL(SIGUSR2, sighandler);
+
+	// Initially no signal should be pending
+	sigset_t pending;
+	sigemptyset(&pending);
+	tested_sigpending(&pending);
+
+	for (int i = 1; i < SIGMAX; ++i)
+		if (sigismember(&pending, i))
+			tst_brk(TFAIL,
+				"initialization failed: no signal should be pending by now");
+
+	// raise a signal
+	if (raise(SIGUSR1))
+		tst_brk(TBROK, "raising SIGUSR1 failed");
+	if (sighandler_counter > 0)
+		tst_brk(TFAIL,
+			"signal handler is not (yet) supposed to be called");
+
+	// now we should have exactly one pending signal (SIGUSR1)
+	sigemptyset(&pending);
+	tested_sigpending(&pending);
+	for (int i = 1; i < SIGMAX; ++i)
+		if ((i == SIGUSR1) != sigismember(&pending, i))
+			tst_brk(TFAIL, "only SIGUSR1 should be pending by now");
+
+	// raise another signal
+	if (raise(SIGUSR2))
+		tst_brk(TBROK, "raising SIGUSR2 failed");
+	if (sighandler_counter > 0)
+		tst_brk(TFAIL,
+			"signal handler is not (yet) supposed to be called");
+
+	// now we should have exactly two pending signals (SIGUSR1, SIGUSR2)
+	sigemptyset(&pending);
+	tested_sigpending(&pending);
+	for (int i = 1; i < SIGMAX; ++i)
+		if ((i == SIGUSR1 || i == SIGUSR2) != sigismember(&pending, i))
+			tst_brk(TFAIL,
+				"only SIGUSR1, SIGUSR2 should be pending by now");
+
+	tst_res(TPASS, "basic sigpending test successful");
+
+	// reinstate old mask
+	if (sigprocmask(SIG_SETMASK, &old_mask, NULL))
+		tst_brk(TBROK, "sigprocmask failed");
+
+	// at this time the signal handler has been called, once for each signal
+	if (sighandler_counter != 2)
+		tst_brk(TFAIL,
+			"signal handler has not been called for each signal");
+
+	// reinstate the original signal handlers
+	SAFE_SIGNAL(SIGUSR1, old_sighandler1);
+	SAFE_SIGNAL(SIGUSR2, old_sighandler2);
+}
+
+static void test_efault_on_invalid_sigset(void)
+{
+	/* set sigset to point to an invalid location */
+	sigset_t *sigset = (sigset_t *)-1;
+
+	tested_sigpending(sigset);
+
  	/* check return code */
  	if (TST_RET == -1) {
  		if (TST_ERR != EFAULT) {
@@ -51,6 +137,12 @@ static void run(void)
  	}
  }
 
+static void run(void)
+{
+	test_sigpending();
+	test_efault_on_invalid_sigset();
+}
+
  static struct tst_test test = {
  	.test_all = run
  };
#9 lore raw

v3 cover new test cases for sigpending / rt_sigpending

In reply to Matthias Maennich

Reusing the code from sigpending for rt_sigpending is a patch I sent in earlier. Based on that this adds a new test case for both syscalls to test the more common use of sigpending.

v2 -> v3:
- fix comment style
- use LTP_ATTRIBUTE_UNUSED

Cheers,
Matthias

Matthias Maennich (2):
rt_sigpending02: reuse code from sigpending02
sigpending/rt_sigpending: add basic test

 .../kernel/syscalls/rt_sigpending/Makefile    |   8 ++
 .../syscalls/rt_sigpending/rt_sigpending02.c  |  48 --------
 testcases/kernel/syscalls/sigpending/Makefile |   2 +
 .../kernel/syscalls/sigpending/sigpending02.c | 113 +++++++++++++++++-
 4 files changed, 117 insertions(+), 54 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c
Signature · 1 line
2.21.0.225.g810b269d1ac-goog
#10 lore raw

PATCH v3 1/2 rt_sigpending02: reuse code from sigpending02

Rather than forking the code of sigpending02 completely, reuse its code for rt_sigpending02 by conditionally compiling the syscalls accordingly.

That way we ensure tests written for either rt_sigpending or sigpending are also considered for the respective other.

---
 .../kernel/syscalls/rt_sigpending/Makefile    |  8 ++++
 .../syscalls/rt_sigpending/rt_sigpending02.c  | 48 -------------------
 testcases/kernel/syscalls/sigpending/Makefile |  2 +
 .../kernel/syscalls/sigpending/sigpending02.c | 16 +++++--
 4 files changed, 23 insertions(+), 51 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c
testcases/kernel/syscalls/rt_sigpending/Makefile +8 -0
index 60c2e0140d85..57ba3dac2e41 100644
@@ -4,4 +4,12 @@
 top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
+
+CPPFLAGS += -DTEST_RT_SIGPENDING
+
+rt_sigpending02: $(abs_srcdir)/../sigpending/sigpending02.c
+	$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) $(OUTPUT_OPTION)
+
+MAKE_TARGETS := rt_sigpending02
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c deleted +0 -48

48 lines not on this page · raw message

testcases/kernel/syscalls/sigpending/Makefile +2 -0
index bd617d806675..00a7d5e2b538 100644
@@ -20,4 +20,6 @@ top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 
+CPPFLAGS += -DTEST_SIGPENDING
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/sigpending/sigpending02.c +13 -3
index e7ec0d6819bd..cc50870b107a 100644
@@ -6,7 +6,10 @@
  *	Paul Larson
  *
  * DESCRIPTION
- *	Test to see that the proper errors are returned by sigpending
+ *	Test to see that the proper errors are returned by sigpending. All the
+ *	tests can also be compiled to use the rt_sigpending syscall instead. To
+ *	simplify the documentation, only sigpending() is usually mentioned
+ *	below.
  *
  *	Test 1:
  *		Call sigpending(sigset_t*=-1), it should return -1 with errno EFAULT
@@ -17,6 +20,7 @@
 #include <sys/types.h>
 
 #include "tst_test.h"
+#include "ltp_signal.h"
 #include "lapi/syscalls.h"
 
 static void run(void)
@@ -24,20 +28,26 @@ static void run(void)
 	/* set sigset to point to an invalid location */
 	sigset_t *sigset = (sigset_t *) - 1;
 
+#if defined(TEST_SIGPENDING)
 	TEST(tst_syscall(__NR_sigpending, sigset));
+#elif defined(TEST_RT_SIGPENDING)
+	TEST(tst_syscall(__NR_rt_sigpending, sigset, SIGSETSIZE));
+#else
+#error Neither TEST_SIGPENDING nor TEST_RT_SIGPENDING is defined!
+#endif
 
 	/* check return code */
 	if (TST_RET == -1) {
 		if (TST_ERR != EFAULT) {
 			tst_res(TFAIL | TTERRNO,
-				"sigpending() Failed with wrong errno, "
+				"syscall failed with wrong errno, "
 				"expected errno=%d, got ", EFAULT);
 		} else {
 			tst_res(TPASS | TTERRNO, "expected failure");
 		}
 	} else {
 		tst_res(TFAIL,
-			"sigpending() Failed, expected return value=-1, got %ld", TST_RET);
+			"syscall failed, expected return value=-1, got %ld", TST_RET);
 	}
 }
 
Signature · 1 line
2.21.0.225.g810b269d1ac-goog
#11 lore raw

PATCH v3 1/2 rt_sigpending02: reuse code from sigpending02

Hi Matthias,

...

testcases/kernel/syscalls/sigpending/sigpending02.c static void run(void) · line 29

Quoted 4 lines

static void run(void)

testcases/kernel/syscalls/sigpending/sigpending02.c +0 -0
@@ -24,20 +28,26 @@ static void run(void)
 	/* set sigset to point to an invalid location */
 	sigset_t *sigset = (sigset_t *) - 1;

There is (undocumented) library helper tst_get_bad_addr() which might bring some arch portability.

testcases/kernel/syscalls/sigpending/sigpending02.c static void run(void) · line 32

Quoted 2 lines
testcases/kernel/syscalls/sigpending/sigpending02.c +1 -0
+#if defined(TEST_SIGPENDING)
 	TEST(tst_syscall(__NR_sigpending, sigset));

BTW: Looking into this, which I merged in 63f8a3f77 ("sigpending: use direct syscall") removed testing sigpending() glibc wrapper from intel. Now:
sigpending02.c:67: CONF: syscall(-1) __NR_sigpending not supported @Cyril, is it ok for us?
I guess, we should do something about #506 [1] to solve problems like this.

testcases/kernel/syscalls/sigpending/sigpending02.c static void run(void) · line 44

Quoted 13 lines
testcases/kernel/syscalls/sigpending/sigpending02.c +6 -1
+#elif defined(TEST_RT_SIGPENDING)
+	TEST(tst_syscall(__NR_rt_sigpending, sigset, SIGSETSIZE));
+#else
+#error Neither TEST_SIGPENDING nor TEST_RT_SIGPENDING is defined!
+#endif
 
 	/* check return code */
 	if (TST_RET == -1) {
 		if (TST_ERR != EFAULT) {
 			tst_res(TFAIL | TTERRNO,
-				"sigpending() Failed with wrong errno, "
+				"syscall failed with wrong errno, "
 				"expected errno=%d, got ", EFAULT);

I'd join this string. + trailing space after got.

testcases/kernel/syscalls/sigpending/sigpending02.c static void run(void) · line 52

Quoted 9 lines
testcases/kernel/syscalls/sigpending/sigpending02.c +1 -1
 		} else {
 			tst_res(TPASS | TTERRNO, "expected failure");
 		}
 	} else {
 		tst_res(TFAIL,
-			"sigpending() Failed, expected return value=-1, got %ld", TST_RET);
+			"syscall failed, expected return value=-1, got %ld", TST_RET);
 	}
 }

Kind regards,
Petr

[1] https://github.com/linux-test-project/ltp/issues/506

#12 lore raw

PATCH v3 1/2 rt_sigpending02: reuse code from sigpending02

Hi Matthias,

Quoted 6 lines

testcases/kernel/syscalls/sigpending/sigpending02.c static void run(void) · line 29

Quoted 4 lines

static void run(void)

testcases/kernel/syscalls/sigpending/sigpending02.c +0 -0
@@ -24,20 +28,26 @@ static void run(void)
 	/* set sigset to point to an invalid location */
 	sigset_t *sigset = (sigset_t *) - 1;

There is (undocumented) library helper tst_get_bad_addr() which might bring some arch portability.

Sorry, this was added long time ago, not by you + you're going to remove it in the next commit.

Kind regards,
Petr

#13 lore raw

PATCH v3 2/2 sigpending/rt_sigpending: add basic test

In reply to Matthias Maennich

Test basic functionality of sigpending/rt_sigpending.

---
 .../kernel/syscalls/sigpending/sigpending02.c | 111 ++++++++++++++++--
 1 file changed, 101 insertions(+), 10 deletions(-)
testcases/kernel/syscalls/sigpending/sigpending02.c +101 -10
index cc50870b107a..e03a527b53f6 100644
@@ -4,14 +4,18 @@
  *
  * AUTHORS
  *	Paul Larson
+ *	Matthias Maennich
  *
  * DESCRIPTION
- *	Test to see that the proper errors are returned by sigpending. All the
- *	tests can also be compiled to use the rt_sigpending syscall instead. To
- *	simplify the documentation, only sigpending() is usually mentioned
- *	below.
+ *	Test to assert basic functionality of sigpending. All the tests can also be
+ *	compiled to use the rt_sigpending syscall instead. To simplify the
+ *	documentation, only sigpending() is usually mentioned below.
  *
  *	Test 1:
+ *		Suppress handling SIGUSR1 and SIGUSR1, raise them and assert their
+ *		signal pending.
+ *
+ *	Test 2:
  *		Call sigpending(sigset_t*=-1), it should return -1 with errno EFAULT
  */
 
@@ -23,19 +27,100 @@
 #include "ltp_signal.h"
 #include "lapi/syscalls.h"
 
-static void run(void)
-{
-	/* set sigset to point to an invalid location */
-	sigset_t *sigset = (sigset_t *) - 1;
+#define min(x, y) (((x) < (y)) ? (x) : (y))
 
 #if defined(TEST_SIGPENDING)
-	TEST(tst_syscall(__NR_sigpending, sigset));
+#define tested_sigpending(sigset) TEST(tst_syscall(__NR_sigpending, sigset))
 #elif defined(TEST_RT_SIGPENDING)
-	TEST(tst_syscall(__NR_rt_sigpending, sigset, SIGSETSIZE));
+#define tested_sigpending(sigset)                                              \
+	TEST(tst_syscall(__NR_rt_sigpending, sigset, SIGSETSIZE))
 #else
 #error Neither TEST_SIGPENDING nor TEST_RT_SIGPENDING is defined!
 #endif
 
+static int sighandler_counter = 0;
+static void sighandler(int signum LTP_ATTRIBUTE_UNUSED)
+{
+	++sighandler_counter;
+}
+
+static void test_sigpending(void)
+{
+	int SIGMAX = min(sizeof(sigset_t) * 8, _NSIG);
+
+	/* set up signal mask and handler */
+	sigset_t only_SIGUSR, old_mask;
+	sighandler_t old_sighandler1, old_sighandler2;
+	sigemptyset(&only_SIGUSR);
+	sigaddset(&only_SIGUSR, SIGUSR1);
+	sigaddset(&only_SIGUSR, SIGUSR2);
+	if (sigprocmask(SIG_SETMASK, &only_SIGUSR, &old_mask))
+		tst_brk(TBROK, "sigprocmask failed");
+	old_sighandler1 = SAFE_SIGNAL(SIGUSR1, sighandler);
+	old_sighandler2 = SAFE_SIGNAL(SIGUSR2, sighandler);
+
+	/* Initially no signal should be pending */
+	sigset_t pending;
+	sigemptyset(&pending);
+	tested_sigpending(&pending);
+
+	for (int i = 1; i < SIGMAX; ++i)
+		if (sigismember(&pending, i))
+			tst_brk(TFAIL,
+				"initialization failed: no signal should be pending by now");
+
+	/* raise a signal */
+	if (raise(SIGUSR1))
+		tst_brk(TBROK, "raising SIGUSR1 failed");
+	if (sighandler_counter > 0)
+		tst_brk(TFAIL,
+			"signal handler is not (yet) supposed to be called");
+
+	/* now we should have exactly one pending signal (SIGUSR1) */
+	sigemptyset(&pending);
+	tested_sigpending(&pending);
+	for (int i = 1; i < SIGMAX; ++i)
+		if ((i == SIGUSR1) != sigismember(&pending, i))
+			tst_brk(TFAIL, "only SIGUSR1 should be pending by now");
+
+	/* raise another signal */
+	if (raise(SIGUSR2))
+		tst_brk(TBROK, "raising SIGUSR2 failed");
+	if (sighandler_counter > 0)
+		tst_brk(TFAIL,
+			"signal handler is not (yet) supposed to be called");
+
+	/* now we should have exactly two pending signals (SIGUSR1, SIGUSR2) */
+	sigemptyset(&pending);
+	tested_sigpending(&pending);
+	for (int i = 1; i < SIGMAX; ++i)
+		if ((i == SIGUSR1 || i == SIGUSR2) != sigismember(&pending, i))
+			tst_brk(TFAIL,
+				"only SIGUSR1, SIGUSR2 should be pending by now");
+
+	tst_res(TPASS, "basic sigpending test successful");
+
+	/* reinstate old mask */
+	if (sigprocmask(SIG_SETMASK, &old_mask, NULL))
+		tst_brk(TBROK, "sigprocmask failed");
+
+	/*@this time the signal handler has been called, once for each signal */
+	if (sighandler_counter != 2)
+		tst_brk(TFAIL,
+			"signal handler has not been called for each signal");
+
+	/* reinstate the original signal handlers */
+	SAFE_SIGNAL(SIGUSR1, old_sighandler1);
+	SAFE_SIGNAL(SIGUSR2, old_sighandler2);
+}
+
+static void test_efault_on_invalid_sigset(void)
+{
+	/* set sigset to point to an invalid location */
+	sigset_t *sigset = (sigset_t *)-1;
+
+	tested_sigpending(sigset);
+
 	/* check return code */
 	if (TST_RET == -1) {
 		if (TST_ERR != EFAULT) {
@@ -51,6 +136,12 @@ static void run(void)
 	}
 }
 
+static void run(void)
+{
+	test_sigpending();
+	test_efault_on_invalid_sigset();
+}
+
 static struct tst_test test = {
 	.test_all = run
 };
Signature · 1 line
2.21.0.225.g810b269d1ac-goog
#14 lore raw

PATCH v3 2/2 sigpending/rt_sigpending: add basic test

Hi Matthias,

testcases/kernel/syscalls/sigpending/sigpending02.c line 30

Quoted 5 lines
testcases/kernel/syscalls/sigpending/sigpending02.c +1 -4
-static void run(void)
-{
-	/* set sigset to point to an invalid location */
-	sigset_t *sigset = (sigset_t *) - 1;
+#define min(x, y) (((x) < (y)) ? (x) : (y))

We have MIN() macro in include/tst_minmax.h.

testcases/kernel/syscalls/sigpending/sigpending02.c line 41

Quoted 12 lines

#if defined(TEST_SIGPENDING)

testcases/kernel/syscalls/sigpending/sigpending02.c +4 -2
-	TEST(tst_syscall(__NR_sigpending, sigset));
+#define tested_sigpending(sigset) TEST(tst_syscall(__NR_sigpending, sigset))
 #elif defined(TEST_RT_SIGPENDING)
-	TEST(tst_syscall(__NR_rt_sigpending, sigset, SIGSETSIZE));
+#define tested_sigpending(sigset)                                              \
+	TEST(tst_syscall(__NR_rt_sigpending, sigset, SIGSETSIZE))
 #else
 #error Neither TEST_SIGPENDING nor TEST_RT_SIGPENDING is defined!
 #endif
 
+static int sighandler_counter = 0;

IMHO static is automatically 0, thus no assignment needed.

Kind regards,
Petr

#15 lore raw

PATCH v3 2/2 sigpending/rt_sigpending: add basic test

In reply to Matthias Maennich

Hi Matthias,

Review

Quoted 1 line
(quoted diff) +1 -0
+	for (int i = 1; i < SIGMAX; ++i)

Please define i before.
Old distros using old C standards (probably -std=gnu89) by default, which breaks build [1]:

gcc -g -O2 -g -O2 -fno-strict-aliasing -pipe -Wall -W -Wold-style-definition -D_FORTIFY_SOURCE=2 -DTEST_RT_SIGPENDING -I../../../../include -I../../../../include -I../../../../include/old/ -L../../../../lib /usr/src/ltp/testcases/kernel/syscalls/rt_sigpending/../sigpending/sigpending02.c -lltp -o rt_sigpending02
/usr/src/ltp/testcases/kernel/syscalls/rt_sigpending/../sigpending/sigpending02.c: In function 'test_sigpending':
/usr/src/ltp/testcases/kernel/syscalls/rt_sigpending/../sigpending/sigpending02.c:67:2: error: 'for' loop initial declarations are only allowed in C99 or C11 mode
for (int i = 1; i < SIGMAX; ++i)
^
/usr/src/ltp/testcases/kernel/syscalls/rt_sigpending/../sigpending/sigpending02.c:67:2: note: use option -std=c99, -std=gnu99, -std=c11 or -std=gnu11 to compile your code /usr/src/ltp/testcases/kernel/syscalls/rt_sigpending/../sigpending/sigpending02.c:82:11: error: redefinition of 'i'

...

testcases/kernel/syscalls/sigpending/sigpending02.c line 84

Quoted 6 lines
testcases/kernel/syscalls/sigpending/sigpending02.c +6 -0
+	/* now we should have exactly one pending signal (SIGUSR1) */
+	sigemptyset(&pending);
+	tested_sigpending(&pending);
+	for (int i = 1; i < SIGMAX; ++i)
+		if ((i == SIGUSR1) != sigismember(&pending, i))
+			tst_brk(TFAIL, "only SIGUSR1 should be pending by now");

Kind regards,
Petr

[1] https://api.travis-ci.org/v3/job/508433905/log.txt

#16 lore raw

v4 cover rt_sigpending02: reuse code from sigpending02

In reply to Matthias Maennich

Reusing the code from sigpending for rt_sigpending is a patch I sent in earlier. Based on that this adds a new test case for both syscalls to test the more common use of sigpending.

v3 -> v4:
- address review comments

v2 -> v3:
- fix comment style
- use LTP_ATTRIBUTE_UNUSED

Matthias Maennich (3):
rt_sigpending02: reuse code from sigpending02 sigpending/rt_sigpending: add basic test
sigpending: improve portability by using tst_get_bad_addr()

 .../kernel/syscalls/rt_sigpending/Makefile    |   8 ++
 .../syscalls/rt_sigpending/rt_sigpending02.c  |  48 --------
 testcases/kernel/syscalls/sigpending/Makefile |   2 +
 .../kernel/syscalls/sigpending/sigpending02.c | 116 ++++++++++++++++--
 4 files changed, 119 insertions(+), 55 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c
Signature · 1 line
2.21.0.225.g810b269d1ac-goog
#17 lore raw

PATCH v4 1/3 rt_sigpending02: reuse code from sigpending02

Rather than forking the code of sigpending02 completely, reuse its code for rt_sigpending02 by conditionally compiling the syscalls accordingly.

That way we ensure tests written for either rt_sigpending or sigpending are also considered for the respective other.

---
 .../kernel/syscalls/rt_sigpending/Makefile    |  8 ++++
 .../syscalls/rt_sigpending/rt_sigpending02.c  | 48 -------------------
 testcases/kernel/syscalls/sigpending/Makefile |  2 +
 .../kernel/syscalls/sigpending/sigpending02.c | 19 ++++++--
 4 files changed, 25 insertions(+), 52 deletions(-)
 delete mode 100644 testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c
testcases/kernel/syscalls/rt_sigpending/Makefile +8 -0
index 60c2e0140d85..57ba3dac2e41 100644
@@ -4,4 +4,12 @@
 top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
+
+CPPFLAGS += -DTEST_RT_SIGPENDING
+
+rt_sigpending02: $(abs_srcdir)/../sigpending/sigpending02.c
+	$(LINK.c) $^ $(LOADLIBES) $(LDLIBS) $(OUTPUT_OPTION)
+
+MAKE_TARGETS := rt_sigpending02
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c deleted +0 -48

48 lines not on this page · raw message

testcases/kernel/syscalls/sigpending/Makefile +2 -0
index bd617d806675..00a7d5e2b538 100644
@@ -20,4 +20,6 @@ top_srcdir		?= ../../../..
 
 include $(top_srcdir)/include/mk/testcases.mk
 
+CPPFLAGS += -DTEST_SIGPENDING
+
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
testcases/kernel/syscalls/sigpending/sigpending02.c +15 -4
index e7ec0d6819bd..70dda858d7c5 100644
@@ -6,7 +6,10 @@
  *	Paul Larson
  *
  * DESCRIPTION
- *	Test to see that the proper errors are returned by sigpending
+ *	Test to see that the proper errors are returned by sigpending. All the
+ *	tests can also be compiled to use the rt_sigpending syscall instead. To
+ *	simplify the documentation, only sigpending() is usually mentioned
+ *	below.
  *
  *	Test 1:
  *		Call sigpending(sigset_t*=-1), it should return -1 with errno EFAULT
@@ -17,6 +20,7 @@
 #include <sys/types.h>
 
 #include "tst_test.h"
+#include "ltp_signal.h"
 #include "lapi/syscalls.h"
 
 static void run(void)
@@ -24,20 +28,27 @@ static void run(void)
 	/* set sigset to point to an invalid location */
 	sigset_t *sigset = (sigset_t *) - 1;
 
+#if defined(TEST_SIGPENDING)
 	TEST(tst_syscall(__NR_sigpending, sigset));
+#elif defined(TEST_RT_SIGPENDING)
+	TEST(tst_syscall(__NR_rt_sigpending, sigset, SIGSETSIZE));
+#else
+#error Neither TEST_SIGPENDING nor TEST_RT_SIGPENDING is defined!
+#endif
 
 	/* check return code */
 	if (TST_RET == -1) {
 		if (TST_ERR != EFAULT) {
 			tst_res(TFAIL | TTERRNO,
-				"sigpending() Failed with wrong errno, "
-				"expected errno=%d, got ", EFAULT);
+				"syscall failed with wrong errno, expected errno=%d, got %d",
+				EFAULT, TST_ERR);
 		} else {
 			tst_res(TPASS | TTERRNO, "expected failure");
 		}
 	} else {
 		tst_res(TFAIL,
-			"sigpending() Failed, expected return value=-1, got %ld", TST_RET);
+			"syscall failed, expected return value=-1, got %ld",
+			TST_RET);
 	}
 }
 
Signature · 1 line
2.21.0.225.g810b269d1ac-goog
#18 lore raw

PATCH v4 2/3 sigpending/rt_sigpending: add basic test

In reply to Matthias Maennich

Test basic functionality of sigpending/rt_sigpending.

---
 .../kernel/syscalls/sigpending/sigpending02.c | 113 ++++++++++++++++--
 1 file changed, 102 insertions(+), 11 deletions(-)
testcases/kernel/syscalls/sigpending/sigpending02.c +102 -11
index 70dda858d7c5..0419fbedb8be 100644
@@ -4,14 +4,18 @@
  *
  * AUTHORS
  *	Paul Larson
+ *	Matthias Maennich
  *
  * DESCRIPTION
- *	Test to see that the proper errors are returned by sigpending. All the
- *	tests can also be compiled to use the rt_sigpending syscall instead. To
- *	simplify the documentation, only sigpending() is usually mentioned
- *	below.
+ *	Test to assert basic functionality of sigpending. All the tests can also be
+ *	compiled to use the rt_sigpending syscall instead. To simplify the
+ *	documentation, only sigpending() is usually mentioned below.
  *
  *	Test 1:
+ *		Suppress handling SIGUSR1 and SIGUSR1, raise them and assert their
+ *		signal pending.
+ *
+ *	Test 2:
  *		Call sigpending(sigset_t*=-1), it should return -1 with errno EFAULT
  */
 
@@ -23,19 +27,100 @@
 #include "ltp_signal.h"
 #include "lapi/syscalls.h"
 
-static void run(void)
-{
-	/* set sigset to point to an invalid location */
-	sigset_t *sigset = (sigset_t *) - 1;
-
 #if defined(TEST_SIGPENDING)
-	TEST(tst_syscall(__NR_sigpending, sigset));
+#define tested_sigpending(sigset) TEST(tst_syscall(__NR_sigpending, sigset))
 #elif defined(TEST_RT_SIGPENDING)
-	TEST(tst_syscall(__NR_rt_sigpending, sigset, SIGSETSIZE));
+#define tested_sigpending(sigset)                                              \
+	TEST(tst_syscall(__NR_rt_sigpending, sigset, SIGSETSIZE))
 #else
 #error Neither TEST_SIGPENDING nor TEST_RT_SIGPENDING is defined!
 #endif
 
+static int sighandler_counter;
+static void sighandler(int signum LTP_ATTRIBUTE_UNUSED)
+{
+	++sighandler_counter;
+}
+
+static void test_sigpending(void)
+{
+	int SIGMAX = MIN(sizeof(sigset_t) * 8, (size_t)_NSIG);
+
+	int i; /* loop index */
+
+	/* set up signal mask and handler */
+	sigset_t only_SIGUSR, old_mask;
+	sighandler_t old_sighandler1, old_sighandler2;
+	sigemptyset(&only_SIGUSR);
+	sigaddset(&only_SIGUSR, SIGUSR1);
+	sigaddset(&only_SIGUSR, SIGUSR2);
+	if (sigprocmask(SIG_SETMASK, &only_SIGUSR, &old_mask))
+		tst_brk(TBROK, "sigprocmask failed");
+	old_sighandler1 = SAFE_SIGNAL(SIGUSR1, sighandler);
+	old_sighandler2 = SAFE_SIGNAL(SIGUSR2, sighandler);
+
+	/* Initially no signal should be pending */
+	sigset_t pending;
+	sigemptyset(&pending);
+	tested_sigpending(&pending);
+
+	for (i = 1; i < SIGMAX; ++i)
+		if (sigismember(&pending, i))
+			tst_brk(TFAIL,
+				"initialization failed: no signal should be pending by now");
+
+	/* raise a signal */
+	if (raise(SIGUSR1))
+		tst_brk(TBROK, "raising SIGUSR1 failed");
+	if (sighandler_counter > 0)
+		tst_brk(TFAIL,
+			"signal handler is not (yet) supposed to be called");
+
+	/* now we should have exactly one pending signal (SIGUSR1) */
+	sigemptyset(&pending);
+	tested_sigpending(&pending);
+	for (i = 1; i < SIGMAX; ++i)
+		if ((i == SIGUSR1) != sigismember(&pending, i))
+			tst_brk(TFAIL, "only SIGUSR1 should be pending by now");
+
+	/* raise another signal */
+	if (raise(SIGUSR2))
+		tst_brk(TBROK, "raising SIGUSR2 failed");
+	if (sighandler_counter > 0)
+		tst_brk(TFAIL,
+			"signal handler is not (yet) supposed to be called");
+
+	/* now we should have exactly two pending signals (SIGUSR1, SIGUSR2) */
+	sigemptyset(&pending);
+	tested_sigpending(&pending);
+	for (i = 1; i < SIGMAX; ++i)
+		if ((i == SIGUSR1 || i == SIGUSR2) != sigismember(&pending, i))
+			tst_brk(TFAIL,
+				"only SIGUSR1, SIGUSR2 should be pending by now");
+
+	tst_res(TPASS, "basic sigpending test successful");
+
+	/* reinstate old mask */
+	if (sigprocmask(SIG_SETMASK, &old_mask, NULL))
+		tst_brk(TBROK, "sigprocmask failed");
+
+	/*@this time the signal handler has been called, once for each signal */
+	if (sighandler_counter != 2)
+		tst_brk(TFAIL,
+			"signal handler has not been called for each signal");
+
+	/* reinstate the original signal handlers */
+	SAFE_SIGNAL(SIGUSR1, old_sighandler1);
+	SAFE_SIGNAL(SIGUSR2, old_sighandler2);
+}
+
+static void test_efault_on_invalid_sigset(void)
+{
+	/* set sigset to point to an invalid location */
+	sigset_t *sigset = (sigset_t *)-1;
+
+	tested_sigpending(sigset);
+
 	/* check return code */
 	if (TST_RET == -1) {
 		if (TST_ERR != EFAULT) {
@@ -52,6 +137,12 @@ static void run(void)
 	}
 }
 
+static void run(void)
+{
+	test_sigpending();
+	test_efault_on_invalid_sigset();
+}
+
 static struct tst_test test = {
 	.test_all = run
 };
Signature · 1 line
2.21.0.225.g810b269d1ac-goog
#19 lore raw

PATCH v4 3/3 sigpending: improve portability by using tst_get_bad_addr()

In reply to Matthias Maennich
---
 testcases/kernel/syscalls/sigpending/sigpending02.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
testcases/kernel/syscalls/sigpending/sigpending02.c +1 -1
index 0419fbedb8be..94e51bb1638f 100644
@@ -117,7 +117,7 @@ static void test_sigpending(void)
 static void test_efault_on_invalid_sigset(void)
 {
 	/* set sigset to point to an invalid location */
-	sigset_t *sigset = (sigset_t *)-1;
+	sigset_t *sigset = tst_get_bad_addr(NULL);
 
 	tested_sigpending(sigset);
 
Signature · 1 line
2.21.0.225.g810b269d1ac-goog
#20 lore raw

v4 cover rt_sigpending02: reuse code from sigpending02

In reply to Matthias Maennich

Hi Matthias,

Quoted 10 lines

Reusing the code from sigpending for rt_sigpending is a patch I sent in earlier. Based on that this adds a new test case for both syscalls to test the more common use of sigpending.

v3 -> v4:
- address review comments

v2 -> v3:
- fix comment style
- use LTP_ATTRIBUTE_UNUSED

Thanks for your changes, pushed!

Kind regards,
Petr