All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH v1] rt_sigpending02: reuse code from sigpending02
@ 2019-03-08 16:38 Matthias Maennich
  2019-03-12 17:11 ` Steve Muckle
                   ` (3 more replies)
  0 siblings, 4 replies; 21+ messages in thread
From: Matthias Maennich @ 2019-03-08 16:38 UTC (permalink / raw)
  To: ltp

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.

Signed-off-by: Matthias Maennich <maennich@google.com>
---
 .../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

diff --git a/testcases/kernel/syscalls/rt_sigpending/Makefile b/testcases/kernel/syscalls/rt_sigpending/Makefile
index 60c2e0140d85..57ba3dac2e41 100644
--- a/testcases/kernel/syscalls/rt_sigpending/Makefile
+++ b/testcases/kernel/syscalls/rt_sigpending/Makefile
@@ -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
diff --git a/testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c b/testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c
deleted file mode 100644
index 06d1c1578f4d..000000000000
--- a/testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c
+++ /dev/null
@@ -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
-};
diff --git a/testcases/kernel/syscalls/sigpending/Makefile b/testcases/kernel/syscalls/sigpending/Makefile
index bd617d806675..00a7d5e2b538 100644
--- a/testcases/kernel/syscalls/sigpending/Makefile
+++ b/testcases/kernel/syscalls/sigpending/Makefile
@@ -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
diff --git a/testcases/kernel/syscalls/sigpending/sigpending02.c b/testcases/kernel/syscalls/sigpending/sigpending02.c
index e7ec0d6819bd..cc50870b107a 100644
--- a/testcases/kernel/syscalls/sigpending/sigpending02.c
+++ b/testcases/kernel/syscalls/sigpending/sigpending02.c
@@ -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.21.0.360.g471c308f928-goog


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

* [LTP] [PATCH v1] rt_sigpending02: reuse code from sigpending02
  2019-03-08 16:38 [LTP] [PATCH v1] rt_sigpending02: reuse code from sigpending02 Matthias Maennich
@ 2019-03-12 17:11 ` Steve Muckle
  2019-03-13  9:42   ` Cyril Hrubis
  2019-03-13 12:02 ` [LTP] [PATCH v2 0/2] new test cases for sigpending / rt_sigpending Matthias Maennich
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 21+ messages in thread
From: Steve Muckle @ 2019-03-12 17:11 UTC (permalink / raw)
  To: ltp

Hi Matthias,

On 03/08/2019 08:38 AM, 'Matthias Maennich' via kernel-team wrote:
> 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.
> 
> Signed-off-by: Matthias Maennich <maennich@google.com>

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.

> ---
>   .../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
> 
> diff --git a/testcases/kernel/syscalls/rt_sigpending/Makefile b/testcases/kernel/syscalls/rt_sigpending/Makefile
> index 60c2e0140d85..57ba3dac2e41 100644
> --- a/testcases/kernel/syscalls/rt_sigpending/Makefile
> +++ b/testcases/kernel/syscalls/rt_sigpending/Makefile
> @@ -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
> diff --git a/testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c b/testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c
> deleted file mode 100644
> index 06d1c1578f4d..000000000000
> --- a/testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c
> +++ /dev/null
> @@ -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
> -};
> diff --git a/testcases/kernel/syscalls/sigpending/Makefile b/testcases/kernel/syscalls/sigpending/Makefile
> index bd617d806675..00a7d5e2b538 100644
> --- a/testcases/kernel/syscalls/sigpending/Makefile
> +++ b/testcases/kernel/syscalls/sigpending/Makefile
> @@ -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
> diff --git a/testcases/kernel/syscalls/sigpending/sigpending02.c b/testcases/kernel/syscalls/sigpending/sigpending02.c
> index e7ec0d6819bd..cc50870b107a 100644
> --- a/testcases/kernel/syscalls/sigpending/sigpending02.c
> +++ b/testcases/kernel/syscalls/sigpending/sigpending02.c
> @@ -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);
>   	}
>   }
>   
> 


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

* [LTP] [PATCH v1] rt_sigpending02: reuse code from sigpending02
  2019-03-12 17:11 ` Steve Muckle
@ 2019-03-13  9:42   ` Cyril Hrubis
  2019-03-13 11:42     ` Matthias Maennich
  0 siblings, 1 reply; 21+ messages in thread
From: Cyril Hrubis @ 2019-03-13  9:42 UTC (permalink / raw)
  To: ltp

Hi!
> 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

-- 
Cyril Hrubis
chrubis@suse.cz

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

* [LTP] [PATCH v1] rt_sigpending02: reuse code from sigpending02
  2019-03-13  9:42   ` Cyril Hrubis
@ 2019-03-13 11:42     ` Matthias Maennich
  2019-03-13 16:31       ` Steve Muckle
  0 siblings, 1 reply; 21+ messages in thread
From: Matthias Maennich @ 2019-03-13 11:42 UTC (permalink / raw)
  To: ltp

Hi!

On Wed, Mar 13, 2019 at 10:42:28AM +0100, Cyril Hrubis wrote:
> Hi!
> > 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.

> 
> 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
That looks actually promising. I will have a more detailed look these days!

-- 
Cheers,
Matthias

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

* [LTP] [PATCH v2 0/2] new test cases for sigpending / rt_sigpending
  2019-03-08 16:38 [LTP] [PATCH v1] rt_sigpending02: reuse code from sigpending02 Matthias Maennich
  2019-03-12 17:11 ` Steve Muckle
@ 2019-03-13 12:02 ` Matthias Maennich
  2019-03-13 12:02   ` [LTP] [PATCH v2 1/2] rt_sigpending02: reuse code from sigpending02 Matthias Maennich
  2019-03-13 12:02   ` [LTP] [PATCH v2 2/2] sigpending/rt_sigpending: add basic test Matthias Maennich
  2019-03-19 11:31 ` [LTP] [PATCH v3 0/2] new test cases for sigpending / rt_sigpending Matthias Maennich
  2019-03-19 18:41 ` [LTP] [PATCH v4 0/3] rt_sigpending02: reuse code from sigpending02 Matthias Maennich
  3 siblings, 2 replies; 21+ messages in thread
From: Matthias Maennich @ 2019-03-13 12:02 UTC (permalink / raw)
  To: ltp

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

-- 
2.21.0.360.g471c308f928-goog


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

* [LTP] [PATCH v2 1/2] rt_sigpending02: reuse code from sigpending02
  2019-03-13 12:02 ` [LTP] [PATCH v2 0/2] new test cases for sigpending / rt_sigpending Matthias Maennich
@ 2019-03-13 12:02   ` Matthias Maennich
  2019-03-13 12:02   ` [LTP] [PATCH v2 2/2] sigpending/rt_sigpending: add basic test Matthias Maennich
  1 sibling, 0 replies; 21+ messages in thread
From: Matthias Maennich @ 2019-03-13 12:02 UTC (permalink / raw)
  To: ltp

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.

Signed-off-by: Matthias Maennich <maennich@google.com>
---
 .../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

diff --git a/testcases/kernel/syscalls/rt_sigpending/Makefile b/testcases/kernel/syscalls/rt_sigpending/Makefile
index 60c2e0140d85..57ba3dac2e41 100644
--- a/testcases/kernel/syscalls/rt_sigpending/Makefile
+++ b/testcases/kernel/syscalls/rt_sigpending/Makefile
@@ -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
diff --git a/testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c b/testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c
deleted file mode 100644
index 06d1c1578f4d..000000000000
--- a/testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c
+++ /dev/null
@@ -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
-};
diff --git a/testcases/kernel/syscalls/sigpending/Makefile b/testcases/kernel/syscalls/sigpending/Makefile
index bd617d806675..00a7d5e2b538 100644
--- a/testcases/kernel/syscalls/sigpending/Makefile
+++ b/testcases/kernel/syscalls/sigpending/Makefile
@@ -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
diff --git a/testcases/kernel/syscalls/sigpending/sigpending02.c b/testcases/kernel/syscalls/sigpending/sigpending02.c
index e7ec0d6819bd..cc50870b107a 100644
--- a/testcases/kernel/syscalls/sigpending/sigpending02.c
+++ b/testcases/kernel/syscalls/sigpending/sigpending02.c
@@ -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.21.0.360.g471c308f928-goog


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

* [LTP] [PATCH v2 2/2] sigpending/rt_sigpending: add basic test
  2019-03-13 12:02 ` [LTP] [PATCH v2 0/2] new test cases for sigpending / rt_sigpending Matthias Maennich
  2019-03-13 12:02   ` [LTP] [PATCH v2 1/2] rt_sigpending02: reuse code from sigpending02 Matthias Maennich
@ 2019-03-13 12:02   ` Matthias Maennich
  2019-03-19  0:04     ` Steve Muckle
  1 sibling, 1 reply; 21+ messages in thread
From: Matthias Maennich @ 2019-03-13 12:02 UTC (permalink / raw)
  To: ltp

Test basic functionality of sigpending/rt_sigpending.

Signed-off-by: Matthias Maennich <maennich@google.com>
---
 .../kernel/syscalls/sigpending/sigpending02.c | 112 ++++++++++++++++--
 1 file changed, 102 insertions(+), 10 deletions(-)

diff --git a/testcases/kernel/syscalls/sigpending/sigpending02.c b/testcases/kernel/syscalls/sigpending/sigpending02.c
index cc50870b107a..e75c6aa69c4c 100644
--- a/testcases/kernel/syscalls/sigpending/sigpending02.c
+++ b/testcases/kernel/syscalls/sigpending/sigpending02.c
@@ -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
 };
-- 
2.21.0.360.g471c308f928-goog


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

* [LTP] [PATCH v1] rt_sigpending02: reuse code from sigpending02
  2019-03-13 11:42     ` Matthias Maennich
@ 2019-03-13 16:31       ` Steve Muckle
  0 siblings, 0 replies; 21+ messages in thread
From: Steve Muckle @ 2019-03-13 16:31 UTC (permalink / raw)
  To: ltp

On 03/13/2019 04:42 AM, Matthias Maennich wrote:
> 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.

> 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.

> 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

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

* [LTP] [PATCH v2 2/2] sigpending/rt_sigpending: add basic test
  2019-03-13 12:02   ` [LTP] [PATCH v2 2/2] sigpending/rt_sigpending: add basic test Matthias Maennich
@ 2019-03-19  0:04     ` Steve Muckle
  0 siblings, 0 replies; 21+ messages in thread
From: Steve Muckle @ 2019-03-19  0:04 UTC (permalink / raw)
  To: ltp

Hi Matthias I had a couple minor comments,

On 03/13/2019 05:02 AM, 'Matthias Maennich' via kernel-team wrote:
> Test basic functionality of sigpending/rt_sigpending.
> 
> Signed-off-by: Matthias Maennich <maennich@google.com>
> ---
>   .../kernel/syscalls/sigpending/sigpending02.c | 112 ++++++++++++++++--
>   1 file changed, 102 insertions(+), 10 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/sigpending/sigpending02.c b/testcases/kernel/syscalls/sigpending/sigpending02.c
> index cc50870b107a..e75c6aa69c4c 100644
> --- a/testcases/kernel/syscalls/sigpending/sigpending02.c
> +++ b/testcases/kernel/syscalls/sigpending/sigpending02.c
> @@ -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;

You can use LTP_ATTRIBUTE_UNUSED on signum to avoid the above statement

> +	++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.

> +	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
>   };
> 


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

* [LTP] [PATCH v3 0/2] new test cases for sigpending / rt_sigpending
  2019-03-08 16:38 [LTP] [PATCH v1] rt_sigpending02: reuse code from sigpending02 Matthias Maennich
  2019-03-12 17:11 ` Steve Muckle
  2019-03-13 12:02 ` [LTP] [PATCH v2 0/2] new test cases for sigpending / rt_sigpending Matthias Maennich
@ 2019-03-19 11:31 ` Matthias Maennich
  2019-03-19 11:31   ` [LTP] [PATCH v3 1/2] rt_sigpending02: reuse code from sigpending02 Matthias Maennich
  2019-03-19 11:31   ` [LTP] [PATCH v3 2/2] sigpending/rt_sigpending: add basic test Matthias Maennich
  2019-03-19 18:41 ` [LTP] [PATCH v4 0/3] rt_sigpending02: reuse code from sigpending02 Matthias Maennich
  3 siblings, 2 replies; 21+ messages in thread
From: Matthias Maennich @ 2019-03-19 11:31 UTC (permalink / raw)
  To: ltp


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

-- 
2.21.0.225.g810b269d1ac-goog


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

* [LTP] [PATCH v3 1/2] rt_sigpending02: reuse code from sigpending02
  2019-03-19 11:31 ` [LTP] [PATCH v3 0/2] new test cases for sigpending / rt_sigpending Matthias Maennich
@ 2019-03-19 11:31   ` Matthias Maennich
  2019-03-19 16:44     ` Petr Vorel
  2019-03-19 11:31   ` [LTP] [PATCH v3 2/2] sigpending/rt_sigpending: add basic test Matthias Maennich
  1 sibling, 1 reply; 21+ messages in thread
From: Matthias Maennich @ 2019-03-19 11:31 UTC (permalink / raw)
  To: ltp

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.

Signed-off-by: Matthias Maennich <maennich@google.com>
---
 .../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

diff --git a/testcases/kernel/syscalls/rt_sigpending/Makefile b/testcases/kernel/syscalls/rt_sigpending/Makefile
index 60c2e0140d85..57ba3dac2e41 100644
--- a/testcases/kernel/syscalls/rt_sigpending/Makefile
+++ b/testcases/kernel/syscalls/rt_sigpending/Makefile
@@ -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
diff --git a/testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c b/testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c
deleted file mode 100644
index 06d1c1578f4d..000000000000
--- a/testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c
+++ /dev/null
@@ -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
-};
diff --git a/testcases/kernel/syscalls/sigpending/Makefile b/testcases/kernel/syscalls/sigpending/Makefile
index bd617d806675..00a7d5e2b538 100644
--- a/testcases/kernel/syscalls/sigpending/Makefile
+++ b/testcases/kernel/syscalls/sigpending/Makefile
@@ -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
diff --git a/testcases/kernel/syscalls/sigpending/sigpending02.c b/testcases/kernel/syscalls/sigpending/sigpending02.c
index e7ec0d6819bd..cc50870b107a 100644
--- a/testcases/kernel/syscalls/sigpending/sigpending02.c
+++ b/testcases/kernel/syscalls/sigpending/sigpending02.c
@@ -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.21.0.225.g810b269d1ac-goog


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

* [LTP] [PATCH v3 2/2] sigpending/rt_sigpending: add basic test
  2019-03-19 11:31 ` [LTP] [PATCH v3 0/2] new test cases for sigpending / rt_sigpending Matthias Maennich
  2019-03-19 11:31   ` [LTP] [PATCH v3 1/2] rt_sigpending02: reuse code from sigpending02 Matthias Maennich
@ 2019-03-19 11:31   ` Matthias Maennich
  2019-03-19 16:58     ` Petr Vorel
  2019-03-19 17:24     ` Petr Vorel
  1 sibling, 2 replies; 21+ messages in thread
From: Matthias Maennich @ 2019-03-19 11:31 UTC (permalink / raw)
  To: ltp

Test basic functionality of sigpending/rt_sigpending.

Signed-off-by: Matthias Maennich <maennich@google.com>
---
 .../kernel/syscalls/sigpending/sigpending02.c | 111 ++++++++++++++++--
 1 file changed, 101 insertions(+), 10 deletions(-)

diff --git a/testcases/kernel/syscalls/sigpending/sigpending02.c b/testcases/kernel/syscalls/sigpending/sigpending02.c
index cc50870b107a..e03a527b53f6 100644
--- a/testcases/kernel/syscalls/sigpending/sigpending02.c
+++ b/testcases/kernel/syscalls/sigpending/sigpending02.c
@@ -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
 };
-- 
2.21.0.225.g810b269d1ac-goog


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

* [LTP] [PATCH v3 1/2] rt_sigpending02: reuse code from sigpending02
  2019-03-19 11:31   ` [LTP] [PATCH v3 1/2] rt_sigpending02: reuse code from sigpending02 Matthias Maennich
@ 2019-03-19 16:44     ` Petr Vorel
  2019-03-19 16:52       ` Petr Vorel
  0 siblings, 1 reply; 21+ messages in thread
From: Petr Vorel @ 2019-03-19 16:44 UTC (permalink / raw)
  To: ltp

Hi Matthias,

Reviewed-by: Petr Vorel <pvorel@suse.cz>

...
>  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;
There is (undocumented) library helper tst_get_bad_addr() which might bring some
arch portability.

> +#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.

> +#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.

>  		} 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

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

* [LTP] [PATCH v3 1/2] rt_sigpending02: reuse code from sigpending02
  2019-03-19 16:44     ` Petr Vorel
@ 2019-03-19 16:52       ` Petr Vorel
  0 siblings, 0 replies; 21+ messages in thread
From: Petr Vorel @ 2019-03-19 16:52 UTC (permalink / raw)
  To: ltp

Hi Matthias,

> >  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;
> 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

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

* [LTP] [PATCH v3 2/2] sigpending/rt_sigpending: add basic test
  2019-03-19 11:31   ` [LTP] [PATCH v3 2/2] sigpending/rt_sigpending: add basic test Matthias Maennich
@ 2019-03-19 16:58     ` Petr Vorel
  2019-03-19 17:24     ` Petr Vorel
  1 sibling, 0 replies; 21+ messages in thread
From: Petr Vorel @ 2019-03-19 16:58 UTC (permalink / raw)
  To: ltp

Hi Matthias,

Reviewed-by: Petr Vorel <pvorel@suse.cz>

> -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.

>  #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;
IMHO static is automatically 0, thus no assignment needed.


Kind regards,
Petr

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

* [LTP] [PATCH v3 2/2] sigpending/rt_sigpending: add basic test
  2019-03-19 11:31   ` [LTP] [PATCH v3 2/2] sigpending/rt_sigpending: add basic test Matthias Maennich
  2019-03-19 16:58     ` Petr Vorel
@ 2019-03-19 17:24     ` Petr Vorel
  1 sibling, 0 replies; 21+ messages in thread
From: Petr Vorel @ 2019-03-19 17:24 UTC (permalink / raw)
  To: ltp

Hi Matthias,

> +	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'

...
> +	/* 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

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

* [LTP] [PATCH v4 0/3] rt_sigpending02: reuse code from sigpending02
  2019-03-08 16:38 [LTP] [PATCH v1] rt_sigpending02: reuse code from sigpending02 Matthias Maennich
                   ` (2 preceding siblings ...)
  2019-03-19 11:31 ` [LTP] [PATCH v3 0/2] new test cases for sigpending / rt_sigpending Matthias Maennich
@ 2019-03-19 18:41 ` Matthias Maennich
  2019-03-19 18:41   ` [LTP] [PATCH v4 1/3] " Matthias Maennich
                     ` (3 more replies)
  3 siblings, 4 replies; 21+ messages in thread
From: Matthias Maennich @ 2019-03-19 18:41 UTC (permalink / raw)
  To: ltp

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

-- 
2.21.0.225.g810b269d1ac-goog


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

* [LTP] [PATCH v4 1/3] rt_sigpending02: reuse code from sigpending02
  2019-03-19 18:41 ` [LTP] [PATCH v4 0/3] rt_sigpending02: reuse code from sigpending02 Matthias Maennich
@ 2019-03-19 18:41   ` Matthias Maennich
  2019-03-19 18:41   ` [LTP] [PATCH v4 2/3] sigpending/rt_sigpending: add basic test Matthias Maennich
                     ` (2 subsequent siblings)
  3 siblings, 0 replies; 21+ messages in thread
From: Matthias Maennich @ 2019-03-19 18:41 UTC (permalink / raw)
  To: ltp

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.

Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Matthias Maennich <maennich@google.com>
---
 .../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

diff --git a/testcases/kernel/syscalls/rt_sigpending/Makefile b/testcases/kernel/syscalls/rt_sigpending/Makefile
index 60c2e0140d85..57ba3dac2e41 100644
--- a/testcases/kernel/syscalls/rt_sigpending/Makefile
+++ b/testcases/kernel/syscalls/rt_sigpending/Makefile
@@ -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
diff --git a/testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c b/testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c
deleted file mode 100644
index 06d1c1578f4d..000000000000
--- a/testcases/kernel/syscalls/rt_sigpending/rt_sigpending02.c
+++ /dev/null
@@ -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
-};
diff --git a/testcases/kernel/syscalls/sigpending/Makefile b/testcases/kernel/syscalls/sigpending/Makefile
index bd617d806675..00a7d5e2b538 100644
--- a/testcases/kernel/syscalls/sigpending/Makefile
+++ b/testcases/kernel/syscalls/sigpending/Makefile
@@ -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
diff --git a/testcases/kernel/syscalls/sigpending/sigpending02.c b/testcases/kernel/syscalls/sigpending/sigpending02.c
index e7ec0d6819bd..70dda858d7c5 100644
--- a/testcases/kernel/syscalls/sigpending/sigpending02.c
+++ b/testcases/kernel/syscalls/sigpending/sigpending02.c
@@ -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);
 	}
 }
 
-- 
2.21.0.225.g810b269d1ac-goog


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

* [LTP] [PATCH v4 2/3] sigpending/rt_sigpending: add basic test
  2019-03-19 18:41 ` [LTP] [PATCH v4 0/3] rt_sigpending02: reuse code from sigpending02 Matthias Maennich
  2019-03-19 18:41   ` [LTP] [PATCH v4 1/3] " Matthias Maennich
@ 2019-03-19 18:41   ` Matthias Maennich
  2019-03-19 18:41   ` [LTP] [PATCH v4 3/3] sigpending: improve portability by using tst_get_bad_addr() Matthias Maennich
  2019-03-21 18:50   ` [LTP] [PATCH v4 0/3] rt_sigpending02: reuse code from sigpending02 Petr Vorel
  3 siblings, 0 replies; 21+ messages in thread
From: Matthias Maennich @ 2019-03-19 18:41 UTC (permalink / raw)
  To: ltp

Test basic functionality of sigpending/rt_sigpending.

Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Matthias Maennich <maennich@google.com>
---
 .../kernel/syscalls/sigpending/sigpending02.c | 113 ++++++++++++++++--
 1 file changed, 102 insertions(+), 11 deletions(-)

diff --git a/testcases/kernel/syscalls/sigpending/sigpending02.c b/testcases/kernel/syscalls/sigpending/sigpending02.c
index 70dda858d7c5..0419fbedb8be 100644
--- a/testcases/kernel/syscalls/sigpending/sigpending02.c
+++ b/testcases/kernel/syscalls/sigpending/sigpending02.c
@@ -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
 };
-- 
2.21.0.225.g810b269d1ac-goog


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

* [LTP] [PATCH v4 3/3] sigpending: improve portability by using tst_get_bad_addr()
  2019-03-19 18:41 ` [LTP] [PATCH v4 0/3] rt_sigpending02: reuse code from sigpending02 Matthias Maennich
  2019-03-19 18:41   ` [LTP] [PATCH v4 1/3] " Matthias Maennich
  2019-03-19 18:41   ` [LTP] [PATCH v4 2/3] sigpending/rt_sigpending: add basic test Matthias Maennich
@ 2019-03-19 18:41   ` Matthias Maennich
  2019-03-21 18:50   ` [LTP] [PATCH v4 0/3] rt_sigpending02: reuse code from sigpending02 Petr Vorel
  3 siblings, 0 replies; 21+ messages in thread
From: Matthias Maennich @ 2019-03-19 18:41 UTC (permalink / raw)
  To: ltp

Suggested-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Matthias Maennich <maennich@google.com>
---
 testcases/kernel/syscalls/sigpending/sigpending02.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/testcases/kernel/syscalls/sigpending/sigpending02.c b/testcases/kernel/syscalls/sigpending/sigpending02.c
index 0419fbedb8be..94e51bb1638f 100644
--- a/testcases/kernel/syscalls/sigpending/sigpending02.c
+++ b/testcases/kernel/syscalls/sigpending/sigpending02.c
@@ -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);
 
-- 
2.21.0.225.g810b269d1ac-goog


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

* [LTP] [PATCH v4 0/3] rt_sigpending02: reuse code from sigpending02
  2019-03-19 18:41 ` [LTP] [PATCH v4 0/3] rt_sigpending02: reuse code from sigpending02 Matthias Maennich
                     ` (2 preceding siblings ...)
  2019-03-19 18:41   ` [LTP] [PATCH v4 3/3] sigpending: improve portability by using tst_get_bad_addr() Matthias Maennich
@ 2019-03-21 18:50   ` Petr Vorel
  3 siblings, 0 replies; 21+ messages in thread
From: Petr Vorel @ 2019-03-21 18:50 UTC (permalink / raw)
  To: ltp

Hi Matthias,

> 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

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

end of thread, other threads:[~2019-03-21 18:50 UTC | newest]

Thread overview: 21+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-03-08 16:38 [LTP] [PATCH v1] rt_sigpending02: reuse code from sigpending02 Matthias Maennich
2019-03-12 17:11 ` Steve Muckle
2019-03-13  9:42   ` Cyril Hrubis
2019-03-13 11:42     ` Matthias Maennich
2019-03-13 16:31       ` Steve Muckle
2019-03-13 12:02 ` [LTP] [PATCH v2 0/2] new test cases for sigpending / rt_sigpending Matthias Maennich
2019-03-13 12:02   ` [LTP] [PATCH v2 1/2] rt_sigpending02: reuse code from sigpending02 Matthias Maennich
2019-03-13 12:02   ` [LTP] [PATCH v2 2/2] sigpending/rt_sigpending: add basic test Matthias Maennich
2019-03-19  0:04     ` Steve Muckle
2019-03-19 11:31 ` [LTP] [PATCH v3 0/2] new test cases for sigpending / rt_sigpending Matthias Maennich
2019-03-19 11:31   ` [LTP] [PATCH v3 1/2] rt_sigpending02: reuse code from sigpending02 Matthias Maennich
2019-03-19 16:44     ` Petr Vorel
2019-03-19 16:52       ` Petr Vorel
2019-03-19 11:31   ` [LTP] [PATCH v3 2/2] sigpending/rt_sigpending: add basic test Matthias Maennich
2019-03-19 16:58     ` Petr Vorel
2019-03-19 17:24     ` Petr Vorel
2019-03-19 18:41 ` [LTP] [PATCH v4 0/3] rt_sigpending02: reuse code from sigpending02 Matthias Maennich
2019-03-19 18:41   ` [LTP] [PATCH v4 1/3] " Matthias Maennich
2019-03-19 18:41   ` [LTP] [PATCH v4 2/3] sigpending/rt_sigpending: add basic test Matthias Maennich
2019-03-19 18:41   ` [LTP] [PATCH v4 3/3] sigpending: improve portability by using tst_get_bad_addr() Matthias Maennich
2019-03-21 18:50   ` [LTP] [PATCH v4 0/3] rt_sigpending02: reuse code from sigpending02 Petr Vorel

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.