Skip to content

Commit e7cafd7

Browse files
committed
openposix: sem_timedwait: replace sleep with tst_process_state_wait3
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> Reviewed-by: Petr Vorel <pvorel@suse.cz> Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
1 parent d331f1f commit e7cafd7

File tree

2 files changed

+6
-2
lines changed
  • testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait

2 files changed

+6
-2
lines changed

testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/2-1.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include <time.h>
2323
#include <sys/mman.h>
2424
#include "posixtest.h"
25+
#include "proc.h"
2526

2627
#define TEST "2-1"
2728
#define SHM_NAME "/posixtest_2-1"
@@ -79,7 +80,8 @@ int main(void)
7980
} else if (pid > 0) // parent to unlock semaphore
8081
{
8182
int i;
82-
sleep(1);
83+
84+
tst_process_state_wait3(pid, 'S', 1);
8385
if (sem_post(mysemp) == -1) {
8486
perror(ERROR_PREFIX "sem_post");
8587
return PTS_FAIL;

testcases/open_posix_testsuite/conformance/interfaces/sem_timedwait/9-1.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include <sys/wait.h>
2222
#include <time.h>
2323
#include "posixtest.h"
24+
#include "proc.h"
2425

2526
#define TEST "9-1"
2627
#define FUNCTION "sem_timedwait"
@@ -79,7 +80,8 @@ int main(void)
7980

8081
} else { // parent to send a signal to child
8182
int i;
82-
sleep(1);
83+
84+
tst_process_state_wait3(pid, 'S', 1);
8385
(void)kill(pid, SIGABRT); // send signal to child
8486
if (wait(&i) == -1) {
8587
perror("Error waiting for child to exit\n");

0 commit comments

Comments
 (0)