Home | History | Annotate | Download | only in getpgid
      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
     17  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     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  */
     46 #define _GNU_SOURCE 1
     47 
     48 #include <errno.h>
     49 #include <unistd.h>
     50 #include <stdarg.h>
     51 #include <sys/wait.h>
     52 #include <sys/types.h>
     53 #include "test.h"
     54 
     55 void setup(void);
     56 void cleanup(void);
     57 
     58 char *TCID = "getpgid02";
     59 int TST_TOTAL = 2;
     60 
     61 int pgid_0, pgid_1;
     62 #define BADPID -99
     63 
     64 struct test_case_t {
     65 	int *id;
     66 	int error;
     67 } TC[] = {
     68 	/* The pid value is negative */
     69 	{
     70 	&pgid_0, ESRCH},
     71 	    /* The pid value does not match any process */
     72 	{
     73 	&pgid_1, ESRCH}
     74 };
     75 
     76 int main(int ac, char **av)
     77 {
     78 	int lc;
     79 	int i;
     80 
     81 	tst_parse_opts(ac, av, NULL, NULL);
     82 
     83 	setup();
     84 
     85 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     86 		/* reset tst_count in case we are looping */
     87 		tst_count = 0;
     88 
     89 		/* loop through the test cases */
     90 		for (i = 0; i < TST_TOTAL; i++) {
     91 
     92 			TEST(getpgid(*TC[i].id));
     93 
     94 			if (TEST_RETURN != -1) {
     95 				tst_resm(TFAIL, "call succeeded unexpectedly");
     96 				continue;
     97 			}
     98 
     99 			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);
    107 			}
    108 		}
    109 	}
    110 	cleanup();
    111 
    112 	tst_exit();
    113 }
    114 
    115 /*
    116  * setup() - performs all ONE TIME setup for this test.
    117  */
    118 void setup(void)
    119 {
    120 
    121 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
    122 
    123 	TEST_PAUSE;
    124 
    125 	pgid_0 = BADPID;
    126 
    127 	pgid_1 = tst_get_unused_pid(cleanup);
    128 }
    129 
    130 /*
    131  * cleanup() - performs all ONE TIME cleanup for this test at
    132  *	       completion or premature exit.
    133  */
    134 void cleanup(void)
    135 {
    136 
    137 }
    138