Message ID | 20240523133132.13978-2-chrubis@suse.cz |
---|---|
State | Accepted |
Headers | show |
Series | Fix msgstress01 timeouts | expand |
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
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");
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(-)