1 /*
2 * Copyright (c) Wipro Technologies Ltd, 2002. All Rights Reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it would be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
11 *
12 * You should have received a copy of the GNU General Public License along
13 * with this program; if not, write the Free Software Foundation, Inc.,
14 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
15 *
16 */
17 /**********************************************************
18 *
19 * TEST IDENTIFIER : sched_getparam01
20 *
21 * EXECUTED BY : anyone
22 *
23 * TEST TITLE : Basic test for sched_getparam(2)
24 *
25 * TEST CASE TOTAL : 1
26 *
27 * AUTHOR : Saji Kumar.V.R <saji.kumar@wipro.com>
28 *
29 * SIGNALS
30 * Uses SIGUSR1 to pause before test if option set.
31 * (See the parse_opts(3) man page).
32 *
33 * DESCRIPTION
34 * This is a Phase I test for the sched_getparam(2) system call.
35 * It is intended to provide a limited exposure of the system call.
36 *
37 * Setup:
38 * Setup signal handling.
39 * Pause for SIGUSR1 if option specified.
40 *
41 * Test:
42 * Loop if the proper options are given.
43 * Execute system call
44 * Check return code, if system call failed (return=-1)
45 * Log the errno and Issue a FAIL message.
46 * Otherwise, Issue a PASS message.
47 *
48 * Cleanup:
49 * Print errno log and/or timing stats if options given
50 *
51 * USAGE: <for command-line>
52 * sched_getparam01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
53 * where, -c n : Run n copies concurrently.
54 * -e : Turn on errno logging.
55 * -h : Show help screen
56 * -f : Turn off functional testing
57 * -i n : Execute test n times.
58 * -I x : Execute test for x seconds.
59 * -p : Pause for SIGUSR1 before starting
60 * -P x : Pause for x seconds between iterations.
61 * -t : Turn on syscall timing.
62 *
63 ****************************************************************/
64
65 #include <errno.h>
66 #include <sched.h>
67 #include "test.h"
68
69 static void setup();
70 static void cleanup();
71
72 char *TCID = "sched_getparam01";
73 int TST_TOTAL = 1;
74
75 static struct sched_param param;
76
main(int ac,char ** av)77 int main(int ac, char **av)
78 {
79
80 int lc;
81
82 tst_parse_opts(ac, av, NULL, NULL);
83
84 setup();
85
86 for (lc = 0; TEST_LOOPING(lc); lc++) {
87
88 tst_count = 0;
89
90 param.sched_priority = 100;
91
92 /*
93 * Call sched_getparam(2) with pid=0 sothat it will
94 * get the scheduling parameters for the calling process
95 */
96 TEST(sched_getparam(0, ¶m));
97
98 /*
99 * Check return code & priority. For normal process,
100 * scheduling policy is SCHED_OTHER. For this scheduling
101 * policy, only allowed priority value is 0. So we should
102 * get 0 for priority value
103 */
104 if ((TEST_RETURN == 0) && (param.sched_priority == 0)) {
105 tst_resm(TPASS, "sched_getparam() returned %ld",
106 TEST_RETURN);
107 } else {
108 tst_resm(TFAIL, "Test Failed, sched_getparam()"
109 "returned %ld, errno = %d : %s; returned "
110 "process priority value is %d", TEST_RETURN,
111 TEST_ERRNO, strerror(TEST_ERRNO),
112 param.sched_priority);
113 }
114 }
115
116 cleanup();
117 tst_exit();
118
119 }
120
121 /* setup() - performs all ONE TIME setup for this test */
setup(void)122 void setup(void)
123 {
124
125 tst_sig(NOFORK, DEF_HANDLER, cleanup);
126
127 TEST_PAUSE;
128
129 }
130
131 /*
132 *cleanup() - performs all ONE TIME cleanup for this test at
133 * completion or premature exit.
134 */
cleanup(void)135 void cleanup(void)
136 {
137 }
138