public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
From: Andrea Cervesato via ltp <ltp@lists.linux.it>
To: ltp@lists.linux.it
Subject: Re: [LTP] [PATCH 1/2] syscalls/msgstress01: Fix the stop logic
Date: Thu, 23 May 2024 15:40:34 +0200	[thread overview]
Message-ID: <dfb56b3f-127e-412d-9653-da655af76a4b@suse.com> (raw)
In-Reply-To: <20240523133132.13978-2-chrubis@suse.cz>

Hi,

LGTM.

Acked-by: Andrea Cervesato <andrea.cervesato@suse.com>

On 5/23/24 15:31, Cyril Hrubis wrote:
> The stop flag didn't really work because:
>
> - if queue is full msgsnd() will block in the kernel
> - if queue is empty msgrcv() will block in the kernel
>
> And if the other process from the reader-writer pair exits the queue
> will be never changed and the test will get stuck and killed by watchdog
> timer.
>
> What we need to do is to use IPC_NOWAIT, retry manually (after short
> usleep) and handle errors manually as well. In that case no processes
> will sleep in kernel and setting the stop flag will actually stop the
> test.
>
> Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
> ---
>   .../syscalls/ipc/msgstress/msgstress01.c      | 23 ++++++++++++++++---
>   1 file changed, 20 insertions(+), 3 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/ipc/msgstress/msgstress01.c b/testcases/kernel/syscalls/ipc/msgstress/msgstress01.c
> index 5c84957b3..62ffcf63b 100644
> --- a/testcases/kernel/syscalls/ipc/msgstress/msgstress01.c
> +++ b/testcases/kernel/syscalls/ipc/msgstress/msgstress01.c
> @@ -101,8 +101,17 @@ static void writer(const int id, const int pos)
>   	struct sysv_data *buff = &ipc_data[pos];
>   	int iter = num_iterations;
>   
> -	while (--iter >= 0 && !(*stop))
> -		SAFE_MSGSND(id, &buff->msg, 100, 0);
> +	while (--iter >= 0 && !(*stop)) {
> +		int size = msgsnd(id, &buff->msg, 100, IPC_NOWAIT);
> +		if (size < 0) {
> +			if (errno == EAGAIN) {
> +				usleep(10);
> +				continue;
> +			}
> +
> +			tst_brk(TBROK | TERRNO, "msgsnd() failed");
> +		}
> +	}
>   }
>   
>   static void reader(const int id, const int pos)
> @@ -115,7 +124,15 @@ static void reader(const int id, const int pos)
>   	while (--iter >= 0 && !(*stop)) {
>   		memset(&msg_recv, 0, sizeof(struct sysv_msg));
>   
> -		size = SAFE_MSGRCV(id, &msg_recv, 100, MSGTYPE, 0);
> +		size = msgrcv(id, &msg_recv, 100, MSGTYPE, IPC_NOWAIT);
> +		if (size < 0) {
> +			if (errno == ENOMSG) {
> +				usleep(10);
> +				continue;
> +			}
> +
> +			tst_brk(TBROK | TERRNO, "msgrcv() failed");
> +		}
>   
>   		if (msg_recv.type != buff->msg.type) {
>   			tst_res(TFAIL, "Received the wrong message type");

Andrea


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

  reply	other threads:[~2024-05-23 13:41 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-23 13:31 [LTP] [PATCH 0/2] Fix msgstress01 timeouts Cyril Hrubis
2024-05-23 13:31 ` [LTP] [PATCH 1/2] syscalls/msgstress01: Fix the stop logic Cyril Hrubis
2024-05-23 13:40   ` Andrea Cervesato via ltp [this message]
2024-05-23 13:31 ` [LTP] [PATCH 2/2] syscalls/msgstress01: Fix timeouts Cyril Hrubis
2024-05-23 14:37   ` Martin Doucha
2024-05-23 15:20   ` Petr Vorel
2024-05-23 15:33     ` Cyril Hrubis
2024-05-23 15:41   ` Petr Vorel
2024-05-23 15:43     ` Petr Vorel
2024-05-23 15:55       ` Petr Vorel
2024-05-23 15:55     ` 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=dfb56b3f-127e-412d-9653-da655af76a4b@suse.com \
    --to=ltp@lists.linux.it \
    --cc=andrea.cervesato@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