public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Wei Gao via ltp <ltp@lists.linux.it>
To: Petr Vorel <pvorel@suse.cz>
Cc: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 2/2] mq_timedreceive01: Workaround segfault on libc variant on 32 bit
Date: Tue, 12 Nov 2024 22:00:21 -0500	[thread overview]
Message-ID: <ZzQWRTZTrWWMDNDv@wegao> (raw)
In-Reply-To: <20241112171831.156440-2-pvorel@suse.cz>

On Tue, Nov 12, 2024 at 06:18:31PM +0100, Petr Vorel wrote:
> EFAULT test segfaults on newer kernels (e.g. 6.4) on libc variant on
> 32bit.  Similarly to 1d4d5a0750 use typical LTP workaround to test by
> forked child + checking the terminating signal.
> 
> Signed-off-by: Petr Vorel <pvorel@suse.cz>
> ---
>  .../mq_timedreceive/mq_timedreceive01.c       | 78 ++++++++++++++-----
>  1 file changed, 58 insertions(+), 20 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c b/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c
> index d4f447d047..a5a43a1771 100644
> --- a/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c
> +++ b/testcases/kernel/syscalls/mq_timedreceive/mq_timedreceive01.c
> @@ -129,32 +129,16 @@ static void setup(void)
>  	setup_common();
>  }
>  
> -static void do_test(unsigned int i)
> +
> +static void verify_mqt_receive(unsigned int i, pid_t pid)
>  {
>  	struct time64_variants *tv = &variants[tst_variant];
>  	const struct test_case *tc = &tcase[i];
> -	unsigned int j;
> -	unsigned int prio;
>  	size_t len = MAX_MSGSIZE;
>  	char rmsg[len];
> -	pid_t pid = -1;
>  	void *abs_timeout;
> -
> -	tst_ts_set_sec(&ts, tc->tv_sec);
> -	tst_ts_set_nsec(&ts, tc->tv_nsec);
> -
> -	if (tc->signal)
> -		pid = set_sig(tc->rq, tv->clock_gettime);
> -
> -	if (tc->timeout)
> -		set_timeout(tc->rq, tv->clock_gettime);
> -
> -	if (tc->send) {
> -		if (tv->mqt_send(*tc->fd, smsg, tc->len, tc->prio, NULL) < 0) {
> -			tst_res(TFAIL | TTERRNO, "mq_timedsend() failed");
> -			return;
> -		}
> -	}
> +	unsigned int j;
> +	unsigned int prio;
>  
>  	if (tc->invalid_msg)
>  		len -= 1;
> @@ -208,6 +192,60 @@ static void do_test(unsigned int i)
>  			TST_RET, prio, len);
>  }
>  
> +static void test_bad_addr(unsigned int i)
> +{
> +	struct time64_variants *tv = &variants[tst_variant];
> +	pid_t pid;
> +	int status;
> +
> +	pid = SAFE_FORK();
> +	if (!pid) {
> +		verify_mqt_receive(i, pid);
> +		_exit(0);
nit:
If this is a normal exit, i suggest use s/_exit(0)/exit(0) ?
> +	}
> +
> +	SAFE_WAITPID(pid, &status, 0);
> +
> +	if (WIFEXITED(status) && !WEXITSTATUS(status))
> +		return;
> +
> +	if (tv->ts_type == TST_LIBC_TIMESPEC &&
> +		WIFSIGNALED(status) && WTERMSIG(status) == SIGSEGV) {
> +		tst_res(TPASS, "Child killed by expected signal");
> +		return;
> +	}
> +
> +	tst_res(TFAIL, "Child %s", tst_strstatus(status));
> +}
> +
> +static void do_test(unsigned int i)
> +{
> +	struct time64_variants *tv = &variants[tst_variant];
> +	const struct test_case *tc = &tcase[i];
> +	pid_t pid = -1;
> +
> +	tst_ts_set_sec(&ts, tc->tv_sec);
> +	tst_ts_set_nsec(&ts, tc->tv_nsec);
> +
> +	if (tc->bad_ts_addr) {
> +		test_bad_addr(i);
> +		return;
> +	}
> +
> +	if (tc->signal)
> +		pid = set_sig(tc->rq, tv->clock_gettime);
> +
> +	if (tc->timeout)
> +		set_timeout(tc->rq, tv->clock_gettime);
> +
> +	if (tc->send && tv->mqt_send(*tc->fd, smsg, tc->len, tc->prio, NULL) < 0) {
> +		tst_res(TFAIL | TTERRNO, "mq_timedsend() failed");
> +		return;
> +	}
> +
> +	verify_mqt_receive(i, pid);
> +}
> +
>  static struct tst_test test = {
>  	.tcnt = ARRAY_SIZE(tcase),
>  	.test = do_test,
> -- 
> 2.47.0
> 

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  reply	other threads:[~2024-11-13  3:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-12 17:18 [LTP] [PATCH 1/2] mq_timedreceive01: Fix different signedness error on 32bit Petr Vorel
2024-11-12 17:18 ` [LTP] [PATCH 2/2] mq_timedreceive01: Workaround segfault on libc variant on 32 bit Petr Vorel
2024-11-13  3:00   ` Wei Gao via ltp [this message]
2024-11-14 14:53     ` Petr Vorel
2024-11-15 12:57       ` Jan Stancek
2024-11-26 14:31   ` Cyril Hrubis
2024-11-26 18:32     ` Petr Vorel
2024-11-13  1:37 ` [LTP] [PATCH 1/2] mq_timedreceive01: Fix different signedness error on 32bit Wei Gao via ltp
2024-11-26 14:29 ` Cyril Hrubis

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=ZzQWRTZTrWWMDNDv@wegao \
    --to=ltp@lists.linux.it \
    --cc=pvorel@suse.cz \
    --cc=wegao@suse.com \
    /path/to/YOUR_REPLY

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

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