annotate tests/test-sys_wait.h @ 40196:e63f5d3edab5

relocatable-prog: Update documentation. * doc/relocatable-maint.texi (Supporting Relocation): Update to match the recent changes.
author Bruno Haible <bruno@clisp.org>
date Sun, 24 Feb 2019 01:49:15 +0100
parents b06060465f09
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
13732
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
1 /* Test of macros shared between <sys/wait.h> and <stdlib.h>.
40057
b06060465f09 maint: Run 'make update-copyright'
Paul Eggert <eggert@cs.ucla.edu>
parents: 19484
diff changeset
2 Copyright (C) 2010-2019 Free Software Foundation, Inc.
13732
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
3
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
4 This program is free software: you can redistribute it and/or modify
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
5 it under the terms of the GNU General Public License as published by
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
6 the Free Software Foundation; either version 3 of the License, or
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
7 (at your option) any later version.
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
8
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
9 This program is distributed in the hope that it will be useful,
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
12 GNU General Public License for more details.
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
13
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
14 You should have received a copy of the GNU General Public License
19190
9759915b2aca all: prefer https: URLs
Paul Eggert <eggert@cs.ucla.edu>
parents: 18626
diff changeset
15 along with this program. If not, see <https://www.gnu.org/licenses/>. */
13732
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
16
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
17 /* Written by Eric Blake <ebb9@byu.net>, 2010. */
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
18
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
19 static int
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
20 test_sys_wait_macros (void)
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
21 {
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
22 /* Check subset of <sys/wait.h> macros that must be visible here.
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
23 Note that some of these macros are only portable when operating
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
24 on an lvalue. */
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
25 int i;
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
26 for (i = 0; i < 0x8000; i = (i ? i << 1 : 1))
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
27 {
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
28 /* POSIX requires that for all valid process statuses, that
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
29 exactly one of these three macros is true. But not all
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
30 possible 16-bit values map to valid process status.
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
31 Traditionally, 8 of the bits are for WIFEXITED, 7 of the bits
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
32 to tell between WIFSIGNALED and WIFSTOPPED, and either 0x80
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
33 or 0x8000 to flag that core was also dumped. Since we don't
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
34 know which byte is WIFEXITED, we skip the both possible bits
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
35 that can signal core dump. */
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
36 if (i == 0x80)
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
37 continue;
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
38 if (!!WIFSIGNALED (i) + !!WIFEXITED (i) + !!WIFSTOPPED (i) != 1)
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
39 return 1;
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
40 }
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
41 i = WEXITSTATUS (i) + WSTOPSIG (i) + WTERMSIG (i);
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
42
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
43 switch (i)
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
44 {
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
45 #if 0
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
46 /* Gnulib doesn't guarantee these, yet. */
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
47 case WNOHANG:
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
48 case WUNTRACED:
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
49 #endif
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
50 break;
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
51 }
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
52 return 0;
b16d13c70a22 stdlib tests: Avoid code duplication.
Bruno Haible <bruno@clisp.org>
parents:
diff changeset
53 }