Imported Upstream version 20091031
[ltp-debian.git] / testcases / kernel / syscalls / getgid / getgid03.c
blob90fdb49631e019d4b3b8e08e71033a706cf578ae
1 /*
3 * Copyright (c) International Business Machines Corp., 2001
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.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * NAME
22 * getgid03.c
24 * DESCRIPTION
25 * Testcase to check the basic functionality of getgid().
27 * ALGORITHM
28 * call setup
29 * loop if that option was specified
30 * Execute getgid() call using TEST macro
31 * if not expected value
32 * break remaining tests and cleanup
33 * if STD_FUNCTIONAL_TEST
34 * Execute getuid() call
35 * Execute getpwduid() call
36 * if the passwd entry is NULL
37 * break the remaining tests and cleanup
38 * else if pwent->pw_gid != TEST_RETURN
39 * print failure message
40 * else
41 * print pass message
42 * else
43 * print pass message
44 * call cleanup
46 * USAGE: <for command-line>
47 * getgid03 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
48 * where, -c n : Run n copies concurrently.
49 * -f : Turn off functionality Testing.
50 * -i n : Execute test n times.
51 * -I x : Execute test for x seconds.
52 * -P x : Pause for x seconds between iterations.
53 * -t : Turn on syscall timing.
55 * HISTORY
56 * 07/2001 Ported by Wayne Boyer
58 * RESTRICTIONS
59 * none
62 #include <pwd.h>
63 #include <errno.h>
65 #include "test.h"
66 #include "usctest.h"
68 #include "compat_16.h"
70 void cleanup(void);
71 void setup(void);
73 TCID_DEFINE(getgid03);
74 int TST_TOTAL = 1;
75 extern int Tst_count;
77 int main(int ac, char **av)
79 int lc; /* loop counter */
80 char *msg; /* message returned from parse_opts */
81 int uid;
82 struct passwd *pwent;
84 /* parse standard options */
85 if ((msg = parse_opts(ac, av, (option_t *) NULL, NULL)) != (char *)NULL) {
86 tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
87 /*NOTREACHED*/}
89 setup(); /* global setup */
91 /* The following loop checks looping state if -i option given */
92 for (lc = 0; TEST_LOOPING(lc); lc++) {
94 /* reset Tst_count in case we are looping */
95 Tst_count = 0;
97 TEST(GETGID());
99 if (TEST_RETURN < 0) {
100 tst_brkm(TBROK, cleanup, "This should never happen");
103 if (STD_FUNCTIONAL_TEST) {
104 uid = getuid();
105 pwent = getpwuid(uid);
107 if (pwent == NULL) {
108 tst_brkm(TBROK, cleanup, "getuid() returned "
109 "unexpected value %d", uid);
110 } else if (!GID_SIZE_CHECK(pwent->pw_gid)) {
111 tst_brkm(TBROK,
112 cleanup,
113 "gid for uid %d is too large for testing getgid16",
114 uid);
115 } else {
116 if (pwent->pw_gid != TEST_RETURN) {
117 tst_resm(TFAIL, "getgid() return value "
118 "%ld unexpected - expected %d",
119 TEST_RETURN, pwent->pw_gid);
120 } else {
121 tst_resm(TPASS, "group id %ld returned "
122 "correctly", TEST_RETURN);
125 } else {
126 tst_resm(TPASS, "call succeeded");
129 cleanup();
131 /*NOTREACHED*/ return 0;
135 * setup() - performs all ONE TIME setup for this test
137 void setup()
139 /* capture signals */
140 tst_sig(NOFORK, DEF_HANDLER, cleanup);
142 /* Pause if that option was specified */
143 TEST_PAUSE;
147 * cleanup() - performs all the ONE TIME cleanup for this test at completion
148 * or premature exit.
150 void cleanup()
153 * print timing status if that option was specified.
154 * print errno log if that option was specified
156 TEST_CLEANUP;
158 /* exit with return code appropriate for results */
159 tst_exit();