Zeng Linggang | 3b9a89f | 2014-06-23 10:38:42 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2014 Fujitsu Ltd. |
| 3 | * Author: Zeng Linggang <zenglg.jy@cn.fujitsu.com> |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of version 2 of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it would be useful, but |
| 10 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 12 | * |
| 13 | * You should have received a copy of the GNU General Public License along |
| 14 | * with this program; if not, write the Free Software Foundation, Inc., |
| 15 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 16 | */ |
| 17 | /* |
| 18 | * Test Description: |
| 19 | * Verify that, |
| 20 | * The calling process does not have any unwaited-for children, |
| 21 | * ECHILD would return. |
| 22 | */ |
| 23 | |
| 24 | #include <errno.h> |
| 25 | #include <sys/types.h> |
| 26 | #include <sys/wait.h> |
| 27 | |
| 28 | #include "test.h" |
Zeng Linggang | 3b9a89f | 2014-06-23 10:38:42 +0800 | [diff] [blame] | 29 | |
| 30 | char *TCID = "wait01"; |
| 31 | int TST_TOTAL = 1; |
| 32 | static void setup(void); |
| 33 | static void wait_verify(void); |
| 34 | static void cleanup(void); |
| 35 | |
| 36 | int main(int argc, char **argv) |
| 37 | { |
| 38 | int lc; |
| 39 | const char *msg; |
| 40 | |
| 41 | msg = parse_opts(argc, argv, NULL, NULL); |
| 42 | if (msg != NULL) |
| 43 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
| 44 | |
| 45 | setup(); |
| 46 | |
| 47 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 48 | tst_count = 0; |
| 49 | wait_verify(); |
| 50 | } |
| 51 | |
| 52 | cleanup(); |
| 53 | tst_exit(); |
| 54 | } |
| 55 | |
| 56 | static void setup(void) |
| 57 | { |
| 58 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 59 | |
| 60 | TEST_PAUSE; |
| 61 | } |
| 62 | |
| 63 | static void wait_verify(void) |
| 64 | { |
| 65 | TEST(wait(NULL)); |
| 66 | |
| 67 | if (TEST_RETURN != -1) { |
| 68 | tst_resm(TFAIL | TTERRNO, "wait failed unexpectedly: %ld", |
| 69 | TEST_RETURN); |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | if (TEST_ERRNO == ECHILD) { |
| 74 | tst_resm(TPASS | TTERRNO, "wait failed as expected"); |
| 75 | } else { |
| 76 | tst_resm(TFAIL | TTERRNO, |
| 77 | "wait failed unexpectedly; expected: %d - %s", |
| 78 | ECHILD, strerror(ECHILD)); |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | static void cleanup(void) |
| 83 | { |
Zeng Linggang | 3b9a89f | 2014-06-23 10:38:42 +0800 | [diff] [blame] | 84 | } |