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 * setpriority04.c
23 *
24 * DESCRIPTION
25 * setpriority04 - test for an expected failure by using an invalid
26 * process id
27 *
28 * ALGORITHM
29 * loop if that option was specified
30 * issue the system call with an invalid process id
31 * check the errno value
32 * issue a PASS message if we get ESRCH - errno 3
33 * otherwise, the tests fails
34 * issue a FAIL message
35 * break any remaining tests
36 * call cleanup
37 *
38 * USAGE: <for command-line>
39 * setpriority04 [-c n] [-e] [-i n] [-I x] [-p x] [-t]
40 * where, -c n : Run n copies concurrently.
41 * -e : Turn on errno logging.
42 * -i n : Execute test n times.
43 * -I x : Execute test for x seconds.
44 * -P x : Pause for x seconds between iterations.
45 * -t : Turn on syscall timing.
46 *
47 * HISTORY
48 * 03/2001 - Written by Wayne Boyer
49 *
50 * RESTRICTIONS
51 * none
52 */
53
54 #include "test.h"
55
56 #include <errno.h>
57 #include <sys/time.h>
58 #include <sys/resource.h>
59
60 void cleanup(void);
61 void setup(void);
62
63 char *TCID = "setpriority04";
64 int TST_TOTAL = 1;
65
main(int ac,char ** av)66 int main(int ac, char **av)
67 {
68 int lc;
69 int new_val = 2;
70 pid_t unused_pid;
71
72 tst_parse_opts(ac, av, NULL, NULL);
73
74 setup(); /* global setup */
75
76 unused_pid = tst_get_unused_pid(cleanup);
77
78 /* The following loop checks looping state if -i option given */
79
80 for (lc = 0; TEST_LOOPING(lc); lc++) {
81 /* reset tst_count in case we are looping */
82 tst_count = 0;
83
84 /*
85 * Try to access an invalid process.
86 * This should give an ESRCH error.
87 */
88
89 /* call the system call with the TEST() macro */
90 TEST(setpriority(PRIO_PROCESS, unused_pid, new_val));
91
92 if (TEST_RETURN == 0) {
93 tst_resm(TFAIL, "call failed to produce expected error "
94 "- errno = %d - %s", TEST_ERRNO,
95 strerror(TEST_ERRNO));
96 continue;
97 }
98
99 switch (TEST_ERRNO) {
100 case ESRCH:
101 tst_resm(TPASS, "expected failure - errno = %d - %s",
102 TEST_ERRNO, strerror(TEST_ERRNO));
103 break;
104 default:
105 tst_resm(TFAIL, "call failed to produce expected error "
106 "- errno = %d - %s", TEST_ERRNO,
107 strerror(TEST_ERRNO));
108 }
109 }
110
111 cleanup();
112
113 tst_exit();
114 }
115
116 /*
117 * setup() - performs all the ONE TIME setup for this test.
118 */
setup(void)119 void setup(void)
120 {
121
122 tst_sig(NOFORK, DEF_HANDLER, cleanup);
123
124 TEST_PAUSE;
125 }
126
127 /*
128 * cleanup() - performs all the ONE TIME cleanup for this test at completion
129 * or premature exit.
130 */
cleanup(void)131 void cleanup(void)
132 {
133
134 }
135