blob: cc3ae5047711c41eaf56ea41bab1b9b4b563f352 [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
Cyril Hrubisdbec1502012-11-28 12:59:23 +01004 * Copyright (c) 2012 Cyril Hrubis <chrubis@suse.cz>
plars865695b2001-08-27 22:15:12 +00005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
14 * the GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
Wanlong Gao4548c6c2012-10-19 18:03:36 +080018 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000019 */
20
Cyril Hrubisdbec1502012-11-28 12:59:23 +010021 /*
22 * wait402 - check for ECHILD errno when using an illegal pid value
23 */
plars865695b2001-08-27 22:15:12 +000024
25#include "test.h"
plars865695b2001-08-27 22:15:12 +000026
27#include <errno.h>
28#define _USE_BSD
29#include <sys/types.h>
30#include <sys/resource.h>
31#include <sys/wait.h>
robbiew5832f9b2002-08-12 14:57:23 +000032#include <stdlib.h>
33#include <string.h>
plars865695b2001-08-27 22:15:12 +000034
subrata_modak56207ce2009-03-23 13:35:39 +000035char *TCID = "wait402";
plars865695b2001-08-27 22:15:12 +000036int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000037
Cyril Hrubisdbec1502012-11-28 12:59:23 +010038static void cleanup(void);
39static void setup(void);
plars865695b2001-08-27 22:15:12 +000040
Cyril Hrubisdbec1502012-11-28 12:59:23 +010041static long get_pid_max(void)
vapier6c53d8e2006-08-06 04:34:47 +000042{
Cyril Hrubisdbec1502012-11-28 12:59:23 +010043 long pid_max;
vapier6c53d8e2006-08-06 04:34:47 +000044
Cyril Hrubisdbec1502012-11-28 12:59:23 +010045 SAFE_FILE_SCANF(NULL, "/proc/sys/kernel/pid_max", "%ld", &pid_max);
vapier6c53d8e2006-08-06 04:34:47 +000046
Cyril Hrubisdbec1502012-11-28 12:59:23 +010047 return pid_max;
vapier6c53d8e2006-08-06 04:34:47 +000048}
49
subrata_modak56207ce2009-03-23 13:35:39 +000050int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000051{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020052 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020053 const char *msg;
vapier6c53d8e2006-08-06 04:34:47 +000054 pid_t epid = get_pid_max() + 1;
robbieweda1cbd2003-03-24 20:55:05 +000055
plars865695b2001-08-27 22:15:12 +000056 int status = 1;
Cyril Hrubisdbec1502012-11-28 12:59:23 +010057 struct rusage rusage;
plars865695b2001-08-27 22:15:12 +000058
Cyril Hrubisdbec1502012-11-28 12:59:23 +010059 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
Garrett Cooper60fa8012010-11-22 13:50:58 -080060 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000061
Cyril Hrubisdbec1502012-11-28 12:59:23 +010062 setup();
plars865695b2001-08-27 22:15:12 +000063
64 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080065 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000066
Cyril Hrubisdbec1502012-11-28 12:59:23 +010067 TEST(wait4(epid, &status, 0, &rusage));
subrata_modakbdbaec52009-02-26 12:14:51 +000068
plars865695b2001-08-27 22:15:12 +000069 if (TEST_RETURN == 0) {
subrata_modak56207ce2009-03-23 13:35:39 +000070 tst_brkm(TFAIL, cleanup,
71 "call failed to produce expected error - errno = %d - %s",
72 TEST_ERRNO, strerror(TEST_ERRNO));
plars865695b2001-08-27 22:15:12 +000073 }
74
plars865695b2001-08-27 22:15:12 +000075 switch (TEST_ERRNO) {
76 case ECHILD:
subrata_modak56207ce2009-03-23 13:35:39 +000077 tst_resm(TPASS,
78 "received expected failure - errno = %d - %s",
79 TEST_ERRNO, strerror(TEST_ERRNO));
plars865695b2001-08-27 22:15:12 +000080 break;
81 default:
subrata_modak56207ce2009-03-23 13:35:39 +000082 tst_brkm(TFAIL, cleanup,
83 "call failed to produce expected "
84 "error - errno = %d - %s", TEST_ERRNO,
85 strerror(TEST_ERRNO));
plars865695b2001-08-27 22:15:12 +000086 }
plars865695b2001-08-27 22:15:12 +000087 }
88
89 cleanup();
Garrett Cooper7d0a4a52010-12-16 10:05:08 -080090 tst_exit();
plars865695b2001-08-27 22:15:12 +000091}
92
Cyril Hrubisdbec1502012-11-28 12:59:23 +010093static void setup(void)
plars865695b2001-08-27 22:15:12 +000094{
Garrett Cooper2c282152010-12-16 00:55:50 -080095
plars865695b2001-08-27 22:15:12 +000096 tst_sig(FORK, DEF_HANDLER, cleanup);
97
plars865695b2001-08-27 22:15:12 +000098 TEST_PAUSE;
99}
100
Cyril Hrubisdbec1502012-11-28 12:59:23 +0100101static void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000102{
Chris Dearmanec6edca2012-10-17 19:54:01 -0700103}