[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH] tests: fix unportable assumption on sys/wait.h
From: |
Eric Blake |
Subject: |
[PATCH] tests: fix unportable assumption on sys/wait.h |
Date: |
Fri, 17 Sep 2010 15:49:49 -0600 |
* tests/test-sys_wait.c (main): Relax test.
* tests/test-stdlib.c (main): Likewise.
Signed-off-by: Eric Blake <address@hidden>
---
This test was passing on Linux but failing on cygwin; with this
patch it now passes on both.
ChangeLog | 4 ++++
tests/test-stdlib.c | 18 +++++++++++++++---
tests/test-sys_wait.c | 16 ++++++++++++++--
3 files changed, 33 insertions(+), 5 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index 0f8cbe1..4a4f733 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
2010-09-17 Eric Blake <address@hidden>
+ tests: fix unportable assumption on sys/wait.h
+ * tests/test-sys_wait.c (main): Relax test.
+ * tests/test-stdlib.c (main): Likewise.
+
init.sh: accomodate directory with no .exes
* tests/init.sh: Accomodate directory containing only scripts.
diff --git a/tests/test-stdlib.c b/tests/test-stdlib.c
index e613b27..5a8f045 100644
--- a/tests/test-stdlib.c
+++ b/tests/test-stdlib.c
@@ -45,9 +45,21 @@ main (void)
Note that some of these macros are only portable when operating
on an lvalue. */
int i;
- for (i = 0; i < 0x10000; i = (i ? i << 1 : 1))
- if (!!WIFSIGNALED (i) + !!WIFEXITED (i) + !!WIFSTOPPED (i) != 1)
- return 1;
+ for (i = 0; i < 0x8000; i = (i ? i << 1 : 1))
+ {
+ /* POSIX requires that for all valid process statuses, that
+ exactly one of these three macros is true. But not all
+ possible 16-bit values map to valid process status.
+ Traditionally, 8 of the bits are for WIFEXITED, 7 of the bits
+ to tell between WIFSIGNALED and WIFSTOPPED, and either 0x80
+ or 0x8000 to flag that core was also dumped. Since we don't
+ know which byte is WIFEXITED, we skip the both possible bits
+ that can signal core dump. */
+ if (i == 0x80)
+ continue;
+ if (!!WIFSIGNALED (i) + !!WIFEXITED (i) + !!WIFSTOPPED (i) != 1)
+ return 1;
+ }
i = WEXITSTATUS (i) + WSTOPSIG (i) + WTERMSIG (i);
switch (i)
diff --git a/tests/test-sys_wait.c b/tests/test-sys_wait.c
index 917de0d..e9e63b6 100644
--- a/tests/test-sys_wait.c
+++ b/tests/test-sys_wait.c
@@ -30,8 +30,20 @@ main (void)
that these are safe only on lvalues. */
int i;
for (i = 0; i < 0x10000; i = (i ? i << 1 : 1))
- if (!!WIFSIGNALED (i) + !!WIFEXITED (i) + !!WIFSTOPPED (i) != 1)
- return 1;
+ {
+ /* POSIX requires that for all valid process statuses, that
+ exactly one of these three macros is true. But not all
+ possible 16-bit values map to valid process status.
+ Traditionally, 8 of the bits are for WIFEXITED, 7 of the bits
+ to tell between WIFSIGNALED and WIFSTOPPED, and either 0x80
+ or 0x8000 to flag that core was also dumped. Since we don't
+ know which byte is WIFEXITED, we skip the both possible bits
+ that can signal core dump. */
+ if (i == 0x80)
+ continue;
+ if (!!WIFSIGNALED (i) + !!WIFEXITED (i) + !!WIFSTOPPED (i) != 1)
+ return 1;
+ }
i = WEXITSTATUS (i) + WSTOPSIG (i) + WTERMSIG (i);
switch (i)
--
1.7.2.3
- [PATCH] tests: fix unportable assumption on sys/wait.h,
Eric Blake <=