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 |
Wanlong Gao | fed9641 | 2012-10-24 10:10:29 +0800 | [diff] [blame] | 13 | * with this program; if not, write the Free Software Foundation, Inc., |
| 14 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 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" |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 78 | |
| 79 | static void setup(); |
| 80 | static void cleanup(); |
| 81 | |
Cyril Hrubis | fdce7d5 | 2013-04-04 18:35:48 +0200 | [diff] [blame] | 82 | char *TCID = "sched_getparam02"; |
| 83 | int TST_TOTAL = 1; |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 84 | |
| 85 | static struct sched_param param; |
| 86 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 87 | int main(int ac, char **av) |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 88 | { |
| 89 | |
Cyril Hrubis | 89af32a | 2012-10-24 16:39:11 +0200 | [diff] [blame] | 90 | int lc; |
Cyril Hrubis | 0b9589f | 2014-05-27 17:40:33 +0200 | [diff] [blame] | 91 | const char *msg; |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 92 | int status; |
| 93 | pid_t child_pid; |
| 94 | |
Garrett Cooper | 0ae003b | 2010-12-19 10:36:32 -0800 | [diff] [blame] | 95 | if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) |
Garrett Cooper | 60fa801 | 2010-11-22 13:50:58 -0800 | [diff] [blame] | 96 | tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg); |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 97 | |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 98 | setup(); |
| 99 | |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 100 | for (lc = 0; TEST_LOOPING(lc); lc++) { |
| 101 | |
Caspar Zhang | d59a659 | 2013-03-07 14:59:12 +0800 | [diff] [blame] | 102 | tst_count = 0; |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 103 | |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 104 | switch (child_pid = FORK_OR_VFORK()) { |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 105 | |
| 106 | case -1: |
| 107 | /* fork() failed */ |
| 108 | tst_resm(TFAIL, "fork() failed"); |
| 109 | continue; |
| 110 | |
| 111 | case 0: |
| 112 | /* Child */ |
| 113 | param.sched_priority = 100; |
| 114 | |
subrata_modak | 4bb656a | 2009-02-26 12:02:09 +0000 | [diff] [blame] | 115 | /* |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 116 | * Call sched_getparam(2) with pid = getppid() sothat |
| 117 | * it will get the scheduling parameters for parent |
| 118 | * process |
| 119 | */ |
| 120 | TEST(sched_getparam(getppid(), ¶m)); |
subrata_modak | bdbaec5 | 2009-02-26 12:14:51 +0000 | [diff] [blame] | 121 | |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 122 | /* |
subrata_modak | 56207ce | 2009-03-23 13:35:39 +0000 | [diff] [blame] | 123 | * Check return code & priority. For normal process, |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 124 | * scheduling policy is SCHED_OTHER. For this |
| 125 | * scheduling policy, only allowed priority value is 0. |
| 126 | * So we should get 0 for priority value |
| 127 | */ |
Garrett Cooper | 0ae003b | 2010-12-19 10:36:32 -0800 | [diff] [blame] | 128 | if (TEST_RETURN == 0 && param.sched_priority == 0) |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 129 | exit(0); |
Garrett Cooper | 0ae003b | 2010-12-19 10:36:32 -0800 | [diff] [blame] | 130 | else { |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 131 | tst_resm(TWARN, "sched_getparam()" |
subrata_modak | 923b23f | 2009-11-02 13:57:16 +0000 | [diff] [blame] | 132 | "returned %ld, errno = %d : %s;" |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 133 | " returned process priority value" |
| 134 | " is %d", TEST_RETURN, TEST_ERRNO, |
| 135 | strerror(TEST_ERRNO), |
| 136 | param.sched_priority); |
| 137 | exit(1); |
| 138 | } |
| 139 | |
| 140 | default: |
| 141 | /* Parent */ |
| 142 | if ((waitpid(child_pid, &status, 0)) < 0) { |
| 143 | tst_resm(TFAIL, "wait() failed"); |
| 144 | continue; |
| 145 | } |
Garrett Cooper | 0ae003b | 2010-12-19 10:36:32 -0800 | [diff] [blame] | 146 | if ((WIFEXITED(status)) && (WEXITSTATUS(status) == 0)) |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 147 | tst_resm(TPASS, "Test Passed"); |
Garrett Cooper | 0ae003b | 2010-12-19 10:36:32 -0800 | [diff] [blame] | 148 | else |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 149 | tst_resm(TFAIL, "Test Failed"); |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 152 | } |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 153 | |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 154 | cleanup(); |
Garrett Cooper | c89ea2b | 2010-12-19 10:07:55 -0800 | [diff] [blame] | 155 | tst_exit(); |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 156 | } |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 157 | |
| 158 | /* setup() - performs all ONE TIME setup for this test */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 159 | void setup(void) |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 160 | { |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 161 | |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 162 | tst_sig(FORK, DEF_HANDLER, cleanup); |
| 163 | |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 164 | TEST_PAUSE; |
| 165 | |
Garrett Cooper | 2c28215 | 2010-12-16 00:55:50 -0800 | [diff] [blame] | 166 | } |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 167 | |
| 168 | /* |
| 169 | *cleanup() - performs all ONE TIME cleanup for this test at |
| 170 | * completion or premature exit. |
| 171 | */ |
Mike Frysinger | c57fba5 | 2014-04-09 18:56:30 -0400 | [diff] [blame] | 172 | void cleanup(void) |
plars | a8b7bfe | 2002-12-05 22:00:00 +0000 | [diff] [blame] | 173 | { |
Garrett Cooper | c89ea2b | 2010-12-19 10:07:55 -0800 | [diff] [blame] | 174 | } |