Home | History | Annotate | Download | only in clock_gettime
      1 /*
      2  * Copyright (c) Wipro Technologies Ltd, 2003.  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	: clock_gettime02
     20  *
     21  *    EXECUTED BY	: anyone
     22  *
     23  *    TEST TITLE	: Basic test for clock_gettime(2)
     24  *
     25  *    TEST CASE TOTAL	: 2
     26  *
     27  *    AUTHOR		: Aniruddha Marathe <aniruddha.marathe (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 clock_gettime(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 for each defined clock value
     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  * clock_gettime02 [-c n] [-e] [-i n] [-I x] [-P x] [-t] [-p]
     53  * where:
     54  * 	-c n : Run n copies simultaneously.
     55  *	-e   : Turn on errno logging.
     56  *	-i n : Execute test n times.
     57  *	-I x : Execute test for x seconds.
     58  *	-p   : Pause for SIGUSR1 before starting
     59  *	-P x : Pause for x seconds between iterations.
     60  *	-t   : Turn on syscall timing.
     61  *
     62  *RESTRICTIONS:
     63  * None
     64  *****************************************************************************/
     65 
     66 #include <stdlib.h>
     67 #include <errno.h>
     68 #include <time.h>
     69 #include <signal.h>
     70 
     71 #include "test.h"
     72 #include "common_timers.h"
     73 
     74 void setup(void);
     75 static clockid_t clocks[2] = { CLOCK_REALTIME, CLOCK_MONOTONIC };
     76 
     77 char *TCID = "clock_gettime02";
     78 int TST_TOTAL = ARRAY_SIZE(clocks);
     79 
     80 int main(int ac, char **av)
     81 {
     82 	int lc, i;
     83 	struct timespec spec;
     84 
     85 	tst_parse_opts(ac, av, NULL, NULL);
     86 
     87 	setup();
     88 
     89 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     90 
     91 		tst_count = 0;
     92 
     93 		for (i = 0; i < TST_TOTAL; i++) {
     94 			TEST(ltp_syscall(__NR_clock_gettime, clocks[i], &spec));
     95 			tst_resm((TEST_RETURN < 0 ? TFAIL | TTERRNO : TPASS),
     96 				 "%s",
     97 				 (TEST_RETURN == 0 ? "passed" : "failed"));
     98 		}
     99 	}
    100 
    101 	CLEANUP();
    102 	tst_exit();
    103 }
    104 
    105 /* setup() - performs all ONE TIME setup for this test */
    106 void setup(void)
    107 {
    108 
    109 	tst_sig(NOFORK, DEF_HANDLER, CLEANUP);
    110 
    111 	TEST_PAUSE;
    112 }
    113 
    114 /*
    115  * CLEANUP() - Performs one time CLEANUP for this test at
    116  * completion or premature exit
    117  */
    118 void cleanup(void)
    119 {
    120 }
    121