All of lore.kernel.org
 help / color / mirror / Atom feed
From: Steve Muckle <smuckle@google.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 2/2] sigpending/rt_sigpending: add basic test
Date: Mon, 18 Mar 2019 17:04:29 -0700	[thread overview]
Message-ID: <e0bff8a9-ee41-c2af-74cd-57f79ef6e72a@google.com> (raw)
In-Reply-To: <20190313120222.47673-3-maennich@google.com>

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


  reply	other threads:[~2019-03-19  0:04 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=e0bff8a9-ee41-c2af-74cd-57f79ef6e72a@google.com \
    --to=smuckle@google.com \
    --cc=ltp@lists.linux.it \
    /path/to/YOUR_REPLY

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

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is 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.