[LTP] [PATCH 2/7] openposix: pthread_spin_init/{2-1,2-2}: Fix
Cyril Hrubis
chrubis@suse.cz
Mon Jun 20 11:21:41 CEST 2022
Propagate a failure in child to the parent properly.
Signed-off-by: Cyril Hrubis <chrubis@suse.cz>
---
.../interfaces/pthread_spin_init/2-1.c | 20 +++++++++++++++++--
.../interfaces/pthread_spin_init/2-2.c | 20 +++++++++++++++++--
2 files changed, 36 insertions(+), 4 deletions(-)
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_init/2-1.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_init/2-1.c
index b7dd9e05e..f20822c50 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_init/2-1.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_init/2-1.c
@@ -100,7 +100,11 @@ int main(void)
if (pid == -1) {
perror("Error at fork()");
return PTS_UNRESOLVED;
- } else if (pid > 0) {
+ }
+
+ if (pid > 0) {
+ int status;
+
/* Parent */
/* wait until child writes to spinlock data */
while (spinlock_data->data != 1)
@@ -116,13 +120,23 @@ int main(void)
spinlock_data->data = 2;
/* Wait until child ends */
- wait(NULL);
+ wait(&status);
if ((shm_unlink(shm_name)) != 0) {
perror("Error at shm_unlink()");
return PTS_UNRESOLVED;
}
+ if (!WIFEXITED(status)) {
+ printf("Parent: did not exit properly!\n");
+ return PTS_FAIL;
+ }
+
+ if (WEXITSTATUS(status)) {
+ printf("Parent: failure in child\n");
+ return WEXITSTATUS(status);
+ }
+
printf("Test PASSED\n");
return PTS_PASS;
} else {
@@ -170,5 +184,7 @@ int main(void)
printf("Child: error at pthread_spin_destroy()\n");
return PTS_UNRESOLVED;
}
+
+ return PTS_PASS;
}
}
diff --git a/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_init/2-2.c b/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_init/2-2.c
index f3cb9b2a3..df0d4df87 100644
--- a/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_init/2-2.c
+++ b/testcases/open_posix_testsuite/conformance/interfaces/pthread_spin_init/2-2.c
@@ -106,7 +106,11 @@ int main(void)
if (pid == -1) {
perror("Error at fork()");
return PTS_UNRESOLVED;
- } else if (pid > 0) {
+ }
+
+ if (pid > 0) {
+ int status;
+
/* Parent */
/* wait until child writes to spinlock data */
while (spinlock_data->data != 1)
@@ -122,13 +126,23 @@ int main(void)
spinlock_data->data = 2;
/* Wait until child ends */
- wait(NULL);
+ wait(&status);
if ((shm_unlink(shm_name)) != 0) {
perror("Error at shm_unlink()");
return PTS_UNRESOLVED;
}
+ if (!WIFEXITED(status)) {
+ printf("Parent: did not exit properly!\n");
+ return PTS_FAIL;
+ }
+
+ if (WEXITSTATUS(status)) {
+ printf("Parent: failure in child\n");
+ return WEXITSTATUS(status);
+ }
+
printf("Test PASSED\n");
return PTS_PASS;
} else {
@@ -175,5 +189,7 @@ int main(void)
printf("Child: error at pthread_spin_destroy()\n");
return PTS_UNRESOLVED;
}
+
+ return PTS_PASS;
}
}
--
2.35.1
More information about the ltp
mailing list