Home | History | Annotate | Download | only in sched_rr_get_interval
      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_rr_get_interval01
     20  *
     21  *    EXECUTED BY	: root / superuser
     22  *
     23  *    TEST TITLE	: Basic test for sched_rr_get_interval(2)
     24  *
     25  *    TEST CASE TOTAL	: 1
     26  *
     27  *    AUTHOR		: Saji Kumar.V.R <saji.kumar (at) 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_rr_get_interval(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  *	  Change scheduling policy to SCHED_RR
     41  *
     42  *	Test:
     43  *	 Loop if the proper options are given.
     44  *	  Execute system call
     45  *	  Check return code, if it is 0,
     46  *		Test passed.
     47  *	  Otherwise
     48  *		Test failed
     49  *
     50  *	Cleanup:
     51  *	  Print errno log and/or timing stats if options given
     52  *
     53  * USAGE:  <for command-line>
     54  * sched_rr_get_interval01 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-h] [-f] [-p]
     55  *			where,  -c n : Run n copies concurrently.
     56  *				-e   : Turn on errno logging.
     57  *				-h   : Show help screen
     58  *				-f   : Turn off functional testing
     59  *				-i n : Execute test n times.
     60  *				-I x : Execute test for x seconds.
     61  *				-p   : Pause for SIGUSR1 before starting
     62  *				-P x : Pause for x seconds between iterations.
     63  *				-t   : Turn on syscall timing.
     64  *
     65  ****************************************************************/
     66 
     67 #include <errno.h>
     68 #include <sched.h>
     69 #include "test.h"
     70 
     71 static void setup();
     72 static void cleanup();
     73 
     74 char *TCID = "sched_rr_get_interval01";
     75 int TST_TOTAL = 1;
     76 
     77 struct timespec tp;
     78 
     79 int main(int ac, char **av)
     80 {
     81 
     82 	int lc;
     83 
     84 	tst_parse_opts(ac, av, NULL, NULL);
     85 
     86 	setup();
     87 
     88 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     89 
     90 		tst_count = 0;
     91 
     92 		/*
     93 		 * Call sched_rr_get_interval(2) with pid=0 so that it will
     94 		 * write into the timespec structure pointed to by tp, the
     95 		 * round robin time quantum for the current process.
     96 		 */
     97 		TEST(sched_rr_get_interval(0, &tp));
     98 
     99 		if (TEST_RETURN == 0) {
    100 			tst_resm(TPASS, "sched_rr_get_interval() returned %ld",
    101 				 TEST_RETURN);
    102 		} else {
    103 			tst_resm(TFAIL | TTERRNO,
    104 				 "Test Failed, sched_rr_get_interval()"
    105 				 "returned %ld", TEST_RETURN);
    106 		}
    107 	}
    108 
    109 	/* cleanup and exit */
    110 	cleanup();
    111 	tst_exit();
    112 
    113 }
    114 
    115 /* setup() - performs all ONE TIME setup for this test */
    116 void setup(void)
    117 {
    118 	tst_require_root();
    119 	/*
    120 	 * Initialize scheduling parameter structure to use with
    121 	 * sched_setscheduler()
    122 	 */
    123 	struct sched_param p = { 1 };
    124 
    125 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
    126 
    127 	TEST_PAUSE;
    128 
    129 	/* Change scheduling policy to SCHED_RR */
    130 	if ((sched_setscheduler(0, SCHED_RR, &p)) == -1) {
    131 		tst_brkm(TBROK, cleanup, "sched_setscheduler() failed");
    132 	}
    133 }
    134 
    135 /*
    136  *cleanup() -  performs all ONE TIME cleanup for this test at
    137  *		completion or premature exit.
    138  */
    139 void cleanup(void)
    140 {
    141 
    142 }
    143