plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 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., 59 |
| 14 | * Temple Place - Suite 330, Boston MA 02111-1307, USA. |
| 15 | * |
| 16 | */ |
| 17 | /********************************************************** |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 18 | * |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 19 | * TEST IDENTIFIER : sched_getparam02 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 20 | * |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 21 | * EXECUTED BY : anyone |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 22 | * |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 23 | * TEST TITLE : Get scheduling parametes for parent process |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 24 | * |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 25 | * TEST CASE TOTAL : 1 |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 26 | * |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 27 | * AUTHOR : Saji Kumar.V.R <saji.kumar@wipro.com> |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 28 | * |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 29 | * SIGNALS |
| 30 | * Uses SIGUSR1 to pause before test if option set. |
| 31 | * (See the parse_opts(3) man page). |
| 32 | * |
| 33 | * DESCRIPTION |
| 34 | * Verifies functionality of sched_getparam() for a process other than |
| 35 | * current process (ie, pid != 0). Here we get the scheduling parameters |
| 36 | * for parent process. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 37 | * |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 38 | * Setup: |
| 39 | * Setup signal handling. |
| 40 | * Pause for SIGUSR1 if option specified. |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 41 | * |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 42 | * Test: |
| 43 | * Loop if the proper options are given. |
| 44 | * fork a child |
| 45 | * |
| 46 | * CHILD: |
| 47 | * Gets the scheduling parameters for parent process |
| 48 | * If successfull, |
| 49 | * TEST passed |
| 50 | * else |
| 51 | * TEST failed. |
| 52 | * |
| 53 | * PARENT: |
| 54 | * wait for child to finish |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 55 | * |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 56 | * Cleanup: |
| 57 | * Print errno log and/or timing stats if options given |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 58 | * |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 59 | * USAGE: <for command-line> |
| 60 | * sched_getparam02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p] |
| 61 | * where, -c n : Run n copies concurrently. |
| 62 | * -e : Turn on errno logging. |
| 63 | * -h : Show help screen |
| 64 | * -f : Turn off functional testing |
| 65 | * -i n : Execute test n times. |
| 66 | * -I x : Execute test for x seconds. |
| 67 | * -p : Pause for SIGUSR1 before starting |
| 68 | * -P x : Pause for x seconds between iterations. |
| 69 | * -t : Turn on syscall timing. |
| 70 | * |
| 71 | ****************************************************************/ |
| 72 | |
| 73 | #include <errno.h> |
| 74 | #include <sched.h> |
| 75 | #include <sys/wait.h> |
| 76 | #include <stdlib.h> |
| 77 | #include "test.h" |
| 78 | #include "usctest.h" |
| 79 | |
| 80 | static void setup(); |
| 81 | static void cleanup(); |
| 82 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 83 | char *TCID = "sched_getparam02"; /* Test program identifier. */ |
| 84 | int TST_TOTAL = 1; /* Total number of test cases. */ |
| 85 | extern int Tst_count; /* Test Case counter for tst_* routines */ |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 86 | |
| 87 | static struct sched_param param; |
| 88 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 89 | int main(int ac, char **av) |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 90 | { |
| 91 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 92 | int lc; /* loop counter */ |
| 93 | char *msg; /* message returned from parse_opts */ |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 94 | int status; |
| 95 | pid_t child_pid; |
| 96 | |
| 97 | /* parse standard options */ |
Garrett Cooper | 45e285d | 2010-11-22 12:19:25 -0800 | [diff] [blame] | 98 | if ((msg = parse_opts(ac, av, NULL, NULL)) |
| 99 | != NULL) { |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame^] | 100 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | /* perform global setup for test */ |
| 104 | setup(); |
| 105 | |
| 106 | /* check looping state if -i option given */ |
| 107 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 108 | |
| 109 | /* reset Tst_count in case we are looping. */ |
| 110 | Tst_count = 0; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 111 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 112 | switch (child_pid = FORK_OR_VFORK()) { |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 113 | |
| 114 | case -1: |
| 115 | /* fork() failed */ |
| 116 | tst_resm(TFAIL, "fork() failed"); |
| 117 | continue; |
| 118 | |
| 119 | case 0: |
| 120 | /* Child */ |
| 121 | param.sched_priority = 100; |
| 122 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 123 | /* |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 124 | * Call sched_getparam(2) with pid = getppid() sothat |
| 125 | * it will get the scheduling parameters for parent |
| 126 | * process |
| 127 | */ |
| 128 | TEST(sched_getparam(getppid(), ¶m)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 129 | |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 130 | /* |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 131 | * Check return code & priority. For normal process, |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 132 | * scheduling policy is SCHED_OTHER. For this |
| 133 | * scheduling policy, only allowed priority value is 0. |
| 134 | * So we should get 0 for priority value |
| 135 | */ |
| 136 | if ((TEST_RETURN == 0) && (param.sched_priority == 0)) { |
| 137 | exit(0); |
| 138 | } else { |
| 139 | tst_resm(TWARN, "sched_getparam()" |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 140 | "returned %ld, errno = %d : %s;" |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 141 | " returned process priority value" |
| 142 | " is %d", TEST_RETURN, TEST_ERRNO, |
| 143 | strerror(TEST_ERRNO), |
| 144 | param.sched_priority); |
| 145 | exit(1); |
| 146 | } |
| 147 | |
| 148 | default: |
| 149 | /* Parent */ |
| 150 | if ((waitpid(child_pid, &status, 0)) < 0) { |
| 151 | tst_resm(TFAIL, "wait() failed"); |
| 152 | continue; |
| 153 | } |
| 154 | if ((WIFEXITED(status)) && (WEXITSTATUS(status) == 0)) { |
| 155 | tst_resm(TPASS, "Test Passed"); |
| 156 | } else { |
| 157 | tst_resm(TFAIL, "Test Failed"); |
| 158 | } |
| 159 | } |
| 160 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 161 | } /* End for TEST_LOOPING */ |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 162 | |
| 163 | /* cleanup and exit */ |
| 164 | cleanup(); |
| 165 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 166 | /*NOTREACHED*/ return 0; |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 167 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 168 | } /* End main */ |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 169 | |
| 170 | /* setup() - performs all ONE TIME setup for this test */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 171 | void setup() |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 172 | { |
| 173 | /* capture signals */ |
| 174 | tst_sig(FORK, DEF_HANDLER, cleanup); |
| 175 | |
| 176 | /* Pause if that option was specified */ |
| 177 | TEST_PAUSE; |
| 178 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 179 | } /* End setup() */ |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 180 | |
| 181 | /* |
| 182 | *cleanup() - performs all ONE TIME cleanup for this test at |
| 183 | * completion or premature exit. |
| 184 | */ |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 185 | void cleanup() |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 186 | { |
| 187 | |
| 188 | /* |
| 189 | * print timing stats if that option was specified. |
| 190 | * print errno log if that option was specified. |
| 191 | */ |
| 192 | TEST_CLEANUP; |
| 193 | |
| 194 | /* exit with return code appropriate for results */ |
| 195 | tst_exit(); |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 196 | } /* End cleanup() */ |