blob: fb55fcefb7d40f2aa3b5b780414dcd65a168840e [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 * 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"
plars865695b2001-08-27 22:15:12 +000055
56#include <errno.h>
57#include <sys/time.h>
58#include <sys/resource.h>
59
plars865695b2001-08-27 22:15:12 +000060void cleanup(void);
61void setup(void);
62
subrata_modak56207ce2009-03-23 13:35:39 +000063char *TCID = "setpriority04";
plars865695b2001-08-27 22:15:12 +000064int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000065
plars74948ad2002-11-14 16:16:14 +000066int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000067{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020068 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020069 const char *msg;
plars865695b2001-08-27 22:15:12 +000070 int new_val = 2;
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +040071 pid_t unused_pid;
plars865695b2001-08-27 22:15:12 +000072
Garrett Cooper45e285d2010-11-22 12:19:25 -080073 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
Garrett Cooper60fa8012010-11-22 13:50:58 -080074 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
plars865695b2001-08-27 22:15:12 +000075 }
76
subrata_modak56207ce2009-03-23 13:35:39 +000077 setup(); /* global setup */
plars865695b2001-08-27 22:15:12 +000078
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +040079 unused_pid = tst_get_unused_pid(cleanup);
80
plars865695b2001-08-27 22:15:12 +000081 /* 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 * Try to access an invalid process.
89 * This should give an ESRCH error.
90 */
robbiew2287bde2003-03-24 15:58:35 +000091
plars865695b2001-08-27 22:15:12 +000092 /* call the system call with the TEST() macro */
Stanislav Kholmanskikh23b37f32014-06-30 14:48:24 +040093 TEST(setpriority(PRIO_PROCESS, unused_pid, new_val));
subrata_modakbdbaec52009-02-26 12:14:51 +000094
plars865695b2001-08-27 22:15:12 +000095 if (TEST_RETURN == 0) {
vapier631d16c2006-08-06 00:40:45 +000096 tst_resm(TFAIL, "call failed to produce expected error "
plars865695b2001-08-27 22:15:12 +000097 "- errno = %d - %s", TEST_ERRNO,
98 strerror(TEST_ERRNO));
99 continue;
100 }
subrata_modakbdbaec52009-02-26 12:14:51 +0000101
plars865695b2001-08-27 22:15:12 +0000102 switch (TEST_ERRNO) {
103 case ESRCH:
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
114 cleanup();
115
Garrett Cooper53740502010-12-16 00:04:01 -0800116 tst_exit();
plars865695b2001-08-27 22:15:12 +0000117}
118
119/*
120 * setup() - performs all the ONE TIME setup for this test.
121 */
vapier631d16c2006-08-06 00:40:45 +0000122void setup(void)
plars865695b2001-08-27 22:15:12 +0000123{
Garrett Cooper2c282152010-12-16 00:55:50 -0800124
plars865695b2001-08-27 22:15:12 +0000125 tst_sig(NOFORK, DEF_HANDLER, cleanup);
126
plars865695b2001-08-27 22:15:12 +0000127 TEST_PAUSE;
128}
129
130/*
131 * cleanup() - performs all the ONE TIME cleanup for this test at completion
subrata_modak56207ce2009-03-23 13:35:39 +0000132 * or premature exit.
plars865695b2001-08-27 22:15:12 +0000133 */
vapier631d16c2006-08-06 00:40:45 +0000134void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000135{
plars865695b2001-08-27 22:15:12 +0000136
Chris Dearmanec6edca2012-10-17 19:54:01 -0700137}