[LTP] [PATCH] openposix: sem_timedwait: replace sleep with tst_process_state_wait3
Jan Stancek
jstancek@redhat.com
Thu Feb 27 11:10:17 CET 2025
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
More information about the ltp
mailing list