All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] openposix: sem_timedwait: replace sleep with tst_process_state_wait3
@ 2025-02-27 10:10 Jan Stancek
  2025-02-27 13:38 ` Petr Vorel
  2025-02-27 14:57 ` Cyril Hrubis
  0 siblings, 2 replies; 4+ messages in thread
From: Jan Stancek @ 2025-02-27 10:10 UTC (permalink / raw)
  To: ltp

This makes the test faster and also avoids a small race - when the
time is very close to starting new second, this makes the test use
timeout that's effectively just slightly over one second, because
nanosecond portion is always set to 0. And previously child would
sleep roughly one second.

Signed-off-by: Jan Stancek <jstancek@redhat.com>
---
 .../conformance/interfaces/sem_timedwait/2-1.c                | 4 +++-
 .../conformance/interfaces/sem_timedwait/9-1.c                | 4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/2-1.c
index d9012cc5ed1a..61603cee56b1 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/2-1.c
@@ -22,6 +22,7 @@
 #include <time.h>
 #include <sys/mman.h>
 #include "posixtest.h"
+#include "proc.h"
 
 #define TEST "2-1"
 #define SHM_NAME "/posixtest_2-1"
@@ -79,7 +80,8 @@ int main(void)
 	} else if (pid > 0)	// parent to unlock semaphore
 	{
 		int i;
-		sleep(1);
+
+		tst_process_state_wait3(pid, 'S', 1);
 		if (sem_post(mysemp) == -1) {
 			perror(ERROR_PREFIX "sem_post");
 			return PTS_FAIL;
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/9-1.c b/testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/9-1.c
index f9175839dab3..ee7ad7aefe26 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/9-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/9-1.c
@@ -21,6 +21,7 @@
 #include <sys/wait.h>
 #include <time.h>
 #include "posixtest.h"
+#include "proc.h"
 
 #define TEST "9-1"
 #define FUNCTION "sem_timedwait"
@@ -79,7 +80,8 @@ int main(void)
 
 	} else {		// parent to send a signal to child
 		int i;
-		sleep(1);
+
+		tst_process_state_wait3(pid, 'S', 1);
 		(void)kill(pid, SIGABRT);	// send signal to child
 		if (wait(&i) == -1) {
 			perror("Error waiting for child to exit\n");
-- 
2.43.0


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

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

* Re: [LTP] [PATCH] openposix: sem_timedwait: replace sleep with tst_process_state_wait3
  2025-02-27 10:10 [LTP] [PATCH] openposix: sem_timedwait: replace sleep with tst_process_state_wait3 Jan Stancek
@ 2025-02-27 13:38 ` Petr Vorel
  2025-02-28 12:25   ` Jan Stancek
  2025-02-27 14:57 ` Cyril Hrubis
  1 sibling, 1 reply; 4+ messages in thread
From: Petr Vorel @ 2025-02-27 13:38 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp

Hi Jan,

> This makes the test faster and also avoids a small race - when the
> time is very close to starting new second, this makes the test use
> timeout that's effectively just slightly over one second, because
> nanosecond portion is always set to 0. And previously child would
> sleep roughly one second.

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

I also wonder if other tests with sleep(1) are relevant. e.g.

conformance/interfaces/pthread_rwlock_timedrdlock/6-2.c
conformance/interfaces/pthread_rwlock_timedwrlock/6-2.c

(There are more sleep() uses, but I suppose others aren't relevant.)

Also, some tests (e.g conformance/interfaces/clock_nanosleep/1-3.c updated few
years ago) did not updated sleep() in docs comment.

Kind regards,
Petr

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

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

* Re: [LTP] [PATCH] openposix: sem_timedwait: replace sleep with tst_process_state_wait3
  2025-02-27 10:10 [LTP] [PATCH] openposix: sem_timedwait: replace sleep with tst_process_state_wait3 Jan Stancek
  2025-02-27 13:38 ` Petr Vorel
@ 2025-02-27 14:57 ` Cyril Hrubis
  1 sibling, 0 replies; 4+ messages in thread
From: Cyril Hrubis @ 2025-02-27 14:57 UTC (permalink / raw)
  To: Jan Stancek; +Cc: ltp

Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>

-- 
Cyril Hrubis
chrubis@suse.cz

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

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

* Re: [LTP] [PATCH] openposix: sem_timedwait: replace sleep with tst_process_state_wait3
  2025-02-27 13:38 ` Petr Vorel
@ 2025-02-28 12:25   ` Jan Stancek
  0 siblings, 0 replies; 4+ messages in thread
From: Jan Stancek @ 2025-02-28 12:25 UTC (permalink / raw)
  To: Petr Vorel; +Cc: ltp

On Thu, Feb 27, 2025 at 2:39 PM Petr Vorel <pvorel@suse.cz> wrote:
>
> Hi Jan,
>
> > This makes the test faster and also avoids a small race - when the
> > time is very close to starting new second, this makes the test use
> > timeout that's effectively just slightly over one second, because
> > nanosecond portion is always set to 0. And previously child would
> > sleep roughly one second.
>
> LGTM.
> Reviewed-by: Petr Vorel <pvorel@suse.cz>

Thanks, pushed.

>
> I also wonder if other tests with sleep(1) are relevant. e.g.
>
> conformance/interfaces/pthread_rwlock_timedrdlock/6-2.c
> conformance/interfaces/pthread_rwlock_timedwrlock/6-2.c
>
> (There are more sleep() uses, but I suppose others aren't relevant.)

I suspect there are still many testcases where sleep() could be replaced.

>
> Also, some tests (e.g conformance/interfaces/clock_nanosleep/1-3.c updated few
> years ago) did not updated sleep() in docs comment.
>
> Kind regards,
> Petr
>


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

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

end of thread, other threads:[~2025-02-28 12:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-27 10:10 [LTP] [PATCH] openposix: sem_timedwait: replace sleep with tst_process_state_wait3 Jan Stancek
2025-02-27 13:38 ` Petr Vorel
2025-02-28 12:25   ` Jan Stancek
2025-02-27 14:57 ` Cyril Hrubis

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.