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