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

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.