• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * Test Name: getpriority01
22  *
23  * Test Description:
24  *  Verify that getpriority() succeeds get the scheduling priority of
25  *  the current process, process group or user.
26  *
27  * Expected Result:
28  *  getpriority() should return the highest priority of the test process.
29  *
30  * Algorithm:
31  *  Setup:
32  *   Setup signal handling.
33  *   Pause for SIGUSR1 if option specified.
34  *
35  *  Test:
36  *   Loop if the proper options are given.
37  *   Execute system call
38  *   Check return code, if system call failed (return=-1)
39  *   	Log the errno and Issue a FAIL message.
40  *   Otherwise,
41  *   	Verify the Functionality of system call
42  *      if successful,
43  *      	Issue Functionality-Pass message.
44  *      Otherwise,
45  *		Issue Functionality-Fail message.
46  *  Cleanup:
47  *   Print errno log and/or timing stats if options given
48  *
49  * Usage:  <for command-line>
50  *  getpriority01 [-c n] [-i n] [-I x] [-P x] [-t]
51  *     where,  -c n : Run n copies concurrently.
52  *	       -i n : Execute test n times.
53  *	       -I x : Execute test for x seconds.
54  *	       -P x : Pause for x seconds between iterations.
55  *	       -t   : Turn on syscall timing.
56  *
57  * HISTORY
58  *	07/2001 Ported by Wayne Boyer
59  *
60  * RESTRICTIONS:
61  *  None.
62  *
63  */
64 
65 #include <stdio.h>
66 #include <unistd.h>
67 #include <sys/types.h>
68 #include <errno.h>
69 #include <fcntl.h>
70 #include <string.h>
71 #include <signal.h>
72 #include <sys/param.h>
73 #include <sys/time.h>
74 #include <sys/resource.h>
75 
76 #include "test.h"
77 
78 char *TCID = "getpriority01";
79 int TST_TOTAL = 1;
80 
81 void setup();			/* setup function for the test */
82 void cleanup();			/* cleanup function for the test */
83 
84 int prio_which[] = { PRIO_PROCESS, PRIO_PGRP, PRIO_USER };
85 
main(int ac,char ** av)86 int main(int ac, char **av)
87 {
88 	int lc;
89 	int ind;
90 	int which;		/* scheduling priority category */
91 
92 	TST_TOTAL = sizeof(prio_which) / sizeof(int);
93 
94 	tst_parse_opts(ac, av, NULL, NULL);
95 
96 	setup();
97 
98 	for (lc = 0; TEST_LOOPING(lc); lc++) {
99 
100 		tst_count = 0;
101 
102 		for (ind = 0; ind < TST_TOTAL; ind++) {
103 			which = prio_which[ind];
104 
105 			/*
106 			 * Invoke getpriority with the specified
107 			 * 'which' argument for the calling process.
108 			 */
109 			TEST(getpriority(which, 0));
110 
111 			if (TEST_RETURN < 0 && TEST_ERRNO != 0) {
112 				tst_resm(TFAIL, "getpriority(%d, 0) "
113 					 "Failed, errno=%d : %s",
114 					 which, TEST_ERRNO,
115 					 strerror(TEST_ERRNO));
116 			} else {
117 				tst_resm(TPASS, "getpriority(%d, 0) returned "
118 					 "%ld priority value",
119 					 which, TEST_RETURN);
120 			}
121 		}
122 	}
123 
124 	cleanup();
125 
126 	tst_exit();
127 }
128 
129 /*
130  * setup() - performs all ONE TIME setup for this test.
131  */
setup(void)132 void setup(void)
133 {
134 
135 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
136 
137 	TEST_PAUSE;
138 }
139 
140 /*
141  * cleanup() - performs all ONE TIME cleanup for this test at
142  *             completion or premature exit.
143  */
cleanup(void)144 void cleanup(void)
145 {
146 
147 }
148