blob: 09cd616b125ef53f8742101b26b337f6b5fe2e04 [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 * sched_yield01.C
23 *
24 * DESCRIPTION
25 * Testcase to check that sched_yield returns correct values.
26 *
27 * ALGORITHM
28 * Call sched_yield(), check its return value. If it is 0, then pass,
29 * otherwise fail with proper errno!
30 *
31 * USAGE: <for command-line>
32 * sched_yield01 [-c n] [-i n] [-I x] [-P x] [-t]
33 * where, -c n : Run n copies concurrently.
34 * -i n : Execute test n times.
35 * -I x : Execute test for x seconds.
36 * -P x : Pause for x seconds between iterations.
37 * -t : Turn on syscall timing.
38 *
39 * HISTORY
40 * 07/2001 Ported by Wayne Boyer
41 *
42 * RESTRICTIONS
43 * None
44 */
45#include <stdio.h>
46#include <sched.h>
47#include <errno.h>
48#include "test.h"
plars865695b2001-08-27 22:15:12 +000049
50char *TCID = "sched_yield01";
51int TST_TOTAL = 1;
plars865695b2001-08-27 22:15:12 +000052
53void setup(void);
54void cleanup(void);
55
plars74948ad2002-11-14 16:16:14 +000056int main(int ac, char **av)
plars865695b2001-08-27 22:15:12 +000057{
Cyril Hrubis89af32a2012-10-24 16:39:11 +020058 int lc;
Cyril Hrubis0b9589f2014-05-27 17:40:33 +020059 const char *msg;
plars865695b2001-08-27 22:15:12 +000060
Garrett Cooper45e285d2010-11-22 12:19:25 -080061 if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
Garrett Cooper60fa8012010-11-22 13:50:58 -080062 tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
Wanlong Gao354ebb42012-12-07 10:10:04 +080063 }
plars865695b2001-08-27 22:15:12 +000064
65 setup();
66
plars865695b2001-08-27 22:15:12 +000067 for (lc = 0; TEST_LOOPING(lc); lc++) {
68
Caspar Zhangd59a6592013-03-07 14:59:12 +080069 /* reset tst_count in case we are looping */
70 tst_count = 0;
plars865695b2001-08-27 22:15:12 +000071
72 TEST(sched_yield());
73
74 if (TEST_RETURN != 0) {
75 tst_resm(TFAIL, "call failed - errno %d : %s",
76 TEST_ERRNO, strerror(TEST_ERRNO));
77 } else {
78 tst_resm(TPASS, "sched_yield() call succeeded");
79 }
80 }
81 cleanup();
Garrett Cooper1e6f5a62010-12-19 09:58:10 -080082 tst_exit();
plars865695b2001-08-27 22:15:12 +000083
plars865695b2001-08-27 22:15:12 +000084}
85
86/*
87 * setup() - performs all ONE TIME setup for this test.
88 */
Mike Frysingerc57fba52014-04-09 18:56:30 -040089void setup(void)
plars865695b2001-08-27 22:15:12 +000090{
Garrett Cooper2c282152010-12-16 00:55:50 -080091
plars865695b2001-08-27 22:15:12 +000092 tst_sig(NOFORK, DEF_HANDLER, cleanup);
93
plars865695b2001-08-27 22:15:12 +000094 TEST_PAUSE;
95}
96
97/*
98 * cleanup() - performs all ONE TIME cleanup for this test at
99 * completion or premature exit.
100 */
Mike Frysingerc57fba52014-04-09 18:56:30 -0400101void cleanup(void)
plars865695b2001-08-27 22:15:12 +0000102{
plars865695b2001-08-27 22:15:12 +0000103
Chris Dearmanec6edca2012-10-17 19:54:01 -0700104}