blob: 76e93af384f730db74f2b81e12f8af3f5f9263ee [file] [log] [blame]
plars865695b2001-08-27 22:15:12 +00001/*
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 Gao4548c6c2012-10-19 18:03:36 +080017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
plars865695b2001-08-27 22:15:12 +000018 */
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"
plars865695b2001-08-27 22:15:12 +000058
59#include <errno.h>
60#include <sys/time.h>
61#include <sys/resource.h>
62
63void cleanup(void);
64void setup(void);
65
subrata_modak56207ce2009-03-23 13:35:39 +000066char *TCID = "setpriority03";
plars865695b2001-08-27 22:15:12 +000067int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000068
plars74948ad2002-11-14 16:16:14 +000069int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000070{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020071 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020072 const char *msg;
plars865695b2001-08-27 22:15:12 +000073 int new_val = 2;
74
Garrett Cooper45e285d2010-11-22 12:19:25 -080075 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
Garrett Cooper60fa8012010-11-22 13:50:58 -080076 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000077 }
78
subrata_modak56207ce2009-03-23 13:35:39 +000079 setup(); /* global setup */
plars865695b2001-08-27 22:15:12 +000080
81 /* The following loop checks looping state if -i option given */
82
83 for (lc = 0; TEST_LOOPING(lc); lc++) {
Caspar Zhangd59a6592013-03-07 14:59:12 +080084 /* reset tst_count in case we are looping */
85 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000086
87 /*
88 * Use an invalid PRIO value by making it negative.
89 * This should give an EINVAL error.
90 * PRIO_PROCESS = 0, PRIO_PGRP = 1, PRIO_USER = 2
91 */
subrata_modakbdbaec52009-02-26 12:14:51 +000092
plars865695b2001-08-27 22:15:12 +000093 /* call the system call with the TEST() macro */
94 TEST(setpriority(-PRIO_PGRP, 0, new_val));
subrata_modakbdbaec52009-02-26 12:14:51 +000095
plars865695b2001-08-27 22:15:12 +000096 if (TEST_RETURN == 0) {
97 tst_resm(TFAIL, "call failed to produce expected error "
98 "- errno = %d - %s", TEST_ERRNO,
99 strerror(TEST_ERRNO));
100 }
subrata_modakbdbaec52009-02-26 12:14:51 +0000101
plars865695b2001-08-27 22:15:12 +0000102 switch (TEST_ERRNO) {
103 case EINVAL:
104 tst_resm(TPASS, "expected failure - errno = %d - %s",
105 TEST_ERRNO, strerror(TEST_ERRNO));
106 break;
107 default:
108 tst_resm(TFAIL, "call failed to produce expected error "
109 "- errno = %d - %s", TEST_ERRNO,
110 strerror(TEST_ERRNO));
111 }
112 }
113 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -0800114 tst_exit();
plars865695b2001-08-27 22:15:12 +0000115
plars865695b2001-08-27 22:15:12 +0000116}
117
118/*
119 * setup() - performs all the ONE TIME setup for this test.
120 */
subrata_modak56207ce2009-03-23 13:35:39 +0000121void setup(void)
plars865695b2001-08-27 22:15:12 +0000122{
Garrett Cooper2c282152010-12-16 00:55:50 -0800123
plars865695b2001-08-27 22:15:12 +0000124 tst_sig(NOFORK, DEF_HANDLER, cleanup);
125
plars865695b2001-08-27 22:15:12 +0000126 TEST_PAUSE;
127}
128
129/*
130 * cleanup() - performs all the ONE TIME cleanup for this test at completion
subrata_modak56207ce2009-03-23 13:35:39 +0000131 * or premature exit.
plars865695b2001-08-27 22:15:12 +0000132 */
subrata_modak56207ce2009-03-23 13:35:39 +0000133void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000134{
plars865695b2001-08-27 22:15:12 +0000135
Chris Dearmanec6edca2012-10-17 19:54:01 -0700136}