blob: 92482e3ae890c592a363975df6e5ede608414b1e [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
2 *
3 * Copyright (c) International Business Machines Corp., 2001
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Wanlong Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
19
20/*
21 * NAME
22 * getpgid02.c
23 *
24 * DESCRIPTION
25 * Testcase to check the basic functionality of getpgid().
26 *
27 * ALGORITHM
28 * test 1: Does getpgid(-99) and expects ESRCH.
29 * test 2: Searches an unused pid and expects ESRCH.
30 *
31 * USAGE: <for command-line>
32 * getpgid02 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
33 * where, -c n : Run n copies concurrently.
34 * -e : Turn on errno logging.
35 * -i n : Execute test n times.
36 * -I x : Execute test for x seconds.
37 * -P x : Pause for x seconds between iterations.
38 * -t : Turn on syscall timing.
39 *
40 * HISTORY
41 * 07/2001 Ported by Wayne Boyer
42 *
43 * RESTRICTIONS
44 * none
45 */
robbiewe861ea92003-03-26 20:28:36 +000046#define _GNU_SOURCE 1
plars865695b2001-08-27 22:15:12 +000047
plars865695b2001-08-27 22:15:12 +000048#include <errno.h>
robbiewe861ea92003-03-26 20:28:36 +000049#include <unistd.h>
robbiew3a280882003-03-03 15:49:21 +000050#include <stdarg.h>
Steven Jackson249f4052016-12-13 16:16:00 +000051#include <sys/wait.h>
robbiewe861ea92003-03-26 20:28:36 +000052#include <sys/types.h>
53#include "test.h"
plars865695b2001-08-27 22:15:12 +000054
55void setup(void);
56void cleanup(void);
57
nstrazfa31d552002-05-14 16:50:06 +000058char *TCID = "getpgid02";
plars865695b2001-08-27 22:15:12 +000059int TST_TOTAL = 2;
plars865695b2001-08-27 22:15:12 +000060
subrata_modak56207ce2009-03-23 13:35:39 +000061int pgid_0, pgid_1;
plars865695b2001-08-27 22:15:12 +000062#define BADPID -99
63
plars865695b2001-08-27 22:15:12 +000064struct test_case_t {
subrata_modak56207ce2009-03-23 13:35:39 +000065 int *id;
66 int error;
plars865695b2001-08-27 22:15:12 +000067} TC[] = {
68 /* The pid value is negative */
subrata_modak56207ce2009-03-23 13:35:39 +000069 {
70 &pgid_0, ESRCH},
71 /* The pid value does not match any process */
72 {
73 &pgid_1, ESRCH}
plars865695b2001-08-27 22:15:12 +000074};
75
robbiewe861ea92003-03-26 20:28:36 +000076int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000077{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020078 int lc;
plars865695b2001-08-27 22:15:12 +000079 int i;
plars865695b2001-08-27 22:15:12 +000080
Cyril Hrubisd6d11d02015-03-09 17:35:43 +010081 tst_parse_opts(ac, av, NULL, NULL);
plars865695b2001-08-27 22:15:12 +000082
83 setup();
84
plars865695b2001-08-27 22:15:12 +000085 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080086 /* reset tst_count in case we are looping */
87 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000088
plars865695b2001-08-27 22:15:12 +000089 /* loop through the test cases */
90 for (i = 0; i < TST_TOTAL; i++) {
91
92 TEST(getpgid(*TC[i].id));
93
subrata_modak56207ce2009-03-23 13:35:39 +000094 if (TEST_RETURN != -1) {
95 tst_resm(TFAIL, "call succeeded unexpectedly");
96 continue;
97 }
plars865695b2001-08-27 22:15:12 +000098
subrata_modak56207ce2009-03-23 13:35:39 +000099 if (TEST_ERRNO == TC[i].error) {
100 tst_resm(TPASS, "expected failure - "
101 "errno = %d : %s", TEST_ERRNO,
102 strerror(TEST_ERRNO));
103 } else {
104 tst_resm(TFAIL, "unexpected error - %d : %s - "
105 "expected %d", TEST_ERRNO,
106 strerror(TEST_ERRNO), TC[i].error);
plars865695b2001-08-27 22:15:12 +0000107 }
108 }
109 }
110 cleanup();
111
Garrett Cooper7d0a4a52010-12-16 10:05:08 -0800112 tst_exit();
plars865695b2001-08-27 22:15:12 +0000113}
114
115/*
116 * setup() - performs all ONE TIME setup for this test.
117 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400118void setup(void)
plars865695b2001-08-27 22:15:12 +0000119{
Garrett Cooper2c282152010-12-16 00:55:50 -0800120
plars865695b2001-08-27 22:15:12 +0000121 tst_sig(NOFORK, DEF_HANDLER, cleanup);
122
plars865695b2001-08-27 22:15:12 +0000123 TEST_PAUSE;
124
125 pgid_0 = BADPID;
126
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +0400127 pgid_1 = tst_get_unused_pid(cleanup);
plars865695b2001-08-27 22:15:12 +0000128}
129
plars865695b2001-08-27 22:15:12 +0000130/*
131 * cleanup() - performs all ONE TIME cleanup for this test at
132 * completion or premature exit.
133 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400134void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000135{
plars865695b2001-08-27 22:15:12 +0000136
Chris Dearmanec6edca2012-10-17 19:54:01 -0700137}