plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 1 | /* |
| 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 Gao | 4548c6c | 2012-10-19 18:03:36 +0800 | [diff] [blame] | 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 18 | */ |
| 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 | */ |
robbiew | e861ea9 | 2003-03-26 20:28:36 +0000 | [diff] [blame] | 46 | #define _GNU_SOURCE 1 |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 47 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 48 | #include <errno.h> |
robbiew | e861ea9 | 2003-03-26 20:28:36 +0000 | [diff] [blame] | 49 | #include <unistd.h> |
robbiew | 3a28088 | 2003-03-03 15:49:21 +0000 | [diff] [blame] | 50 | #include <stdarg.h> |
robbiew | e861ea9 | 2003-03-26 20:28:36 +0000 | [diff] [blame] | 51 | #include <wait.h> |
| 52 | #include <sys/types.h> |
| 53 | #include "test.h" |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 54 | |
| 55 | void setup(void); |
| 56 | void cleanup(void); |
| 57 | |
nstraz | fa31d55 | 2002-05-14 16:50:06 +0000 | [diff] [blame] | 58 | char *TCID = "getpgid02"; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 59 | int TST_TOTAL = 2; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 60 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 61 | int pgid_0, pgid_1; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 62 | #define BADPID -99 |
| 63 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 64 | struct test_case_t { |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 65 | int *id; |
| 66 | int error; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 67 | } TC[] = { |
| 68 | /* The pid value is negative */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 69 | { |
| 70 | &pgid_0, ESRCH}, |
| 71 | /* The pid value does not match any process */ |
| 72 | { |
| 73 | &pgid_1, ESRCH} |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 74 | }; |
| 75 | |
robbiew | e861ea9 | 2003-03-26 20:28:36 +0000 | [diff] [blame] | 76 | int main(int ac, char **av) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 77 | { |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 78 | int lc; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 79 | int i; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 80 | const char *msg; /* message returned by parse_opts */ |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 81 | |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 82 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 83 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | setup(); |
| 87 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 88 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 89 | /* reset tst_count in case we are looping */ |
| 90 | tst_count = 0; |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 91 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 92 | /* loop through the test cases */ |
| 93 | for (i = 0; i < TST_TOTAL; i++) { |
| 94 | |
| 95 | TEST(getpgid(*TC[i].id)); |
| 96 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 97 | if (TEST_RETURN != -1) { |
| 98 | tst_resm(TFAIL, "call succeeded unexpectedly"); |
| 99 | continue; |
| 100 | } |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 101 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 102 | if (TEST_ERRNO == TC[i].error) { |
| 103 | tst_resm(TPASS, "expected failure - " |
| 104 | "errno = %d : %s", TEST_ERRNO, |
| 105 | strerror(TEST_ERRNO)); |
| 106 | } else { |
| 107 | tst_resm(TFAIL, "unexpected error - %d : %s - " |
| 108 | "expected %d", TEST_ERRNO, |
| 109 | strerror(TEST_ERRNO), TC[i].error); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 110 | } |
| 111 | } |
| 112 | } |
| 113 | cleanup(); |
| 114 | |
Garrett Cooper | 7d0a4a5 | 2010-12-16 10:05:08 -0800 | [diff] [blame] | 115 | tst_exit(); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | /* |
| 119 | * setup() - performs all ONE TIME setup for this test. |
| 120 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 121 | void setup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 122 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 123 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 124 | tst_sig(NOFORK, DEF_HANDLER, cleanup); |
| 125 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 126 | TEST_PAUSE; |
| 127 | |
| 128 | pgid_0 = BADPID; |
| 129 | |
Stanislav Kholmanskikh | 23b37f3 | 2014-06-30 14:48:24 +0400 | [diff] [blame] | 130 | pgid_1 = tst_get_unused_pid(cleanup); |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 131 | } |
| 132 | |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 133 | /* |
| 134 | * cleanup() - performs all ONE TIME cleanup for this test at |
| 135 | * completion or premature exit. |
| 136 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 137 | void cleanup(void) |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 138 | { |
plars | 865695b | 2001-08-27 22:15:12 +0000 | [diff] [blame] | 139 | |
Chris Dearman | ec6edca | 2012-10-17 19:54:01 -0700 | [diff] [blame] | 140 | } |