Home | History | Annotate | Download | only in nanosleep
      1 /*
      2  * Copyright (c) International Business Machines  Corp., 2001
      3  *  07/2001 Ported by Wayne Boyer
      4  * Copyright (C) 2015 Cyril Hrubis <chrubis (at) suse.cz>
      5  *
      6  * This program is free software;  you can redistribute it and/or modify
      7  * it under the terms of the GNU General Public License as published by
      8  * the Free Software Foundation; either version 2 of the License, or
      9  * (at your option) any later version.
     10  *
     11  * This program is distributed in the hope that it will be useful,
     12  * but WITHOUT ANY WARRANTY;  without even the implied warranty of
     13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
     14  * the GNU General Public License for more details.
     15  *
     16  * You should have received a copy of the GNU General Public License
     17  * along with this program;  if not, write to the Free Software Foundation,
     18  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
     19  */
     20 
     21 /*
     22  * Test Name: nanosleep01
     23  *
     24  * Test Description:
     25  *  nanosleep() should return with value 0 and the process should be
     26  *  suspended for time specified by timespec structure.
     27  */
     28 
     29 #include <errno.h>
     30 #include "test.h"
     31 
     32 char *TCID = "nanosleep01";
     33 int TST_TOTAL = 1;
     34 
     35 static void setup(void);
     36 
     37 int main(int ac, char **av)
     38 {
     39 	int lc;
     40 	struct timespec timereq = {.tv_sec = 2, .tv_nsec = 9999};
     41 
     42 	tst_parse_opts(ac, av, NULL, NULL);
     43 
     44 	setup();
     45 
     46 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     47 		tst_timer_start(CLOCK_MONOTONIC);
     48 		TEST(nanosleep(&timereq, NULL));
     49 		tst_timer_stop();
     50 
     51 		if (TEST_RETURN == -1) {
     52 			tst_resm(TFAIL | TERRNO, "nanosleep() failed");
     53 			continue;
     54 		}
     55 
     56 		if (tst_timespec_lt(tst_timer_elapsed(), timereq)) {
     57 			tst_resm(TFAIL,
     58 			         "nanosleep() suspended for %lli us, expected %lli",
     59 				 tst_timer_elapsed_us(), tst_timespec_to_us(timereq));
     60 		} else {
     61 			tst_resm(TPASS, "nanosleep() suspended for %lli us",
     62 			         tst_timer_elapsed_us());
     63 		}
     64 	}
     65 
     66 	tst_exit();
     67 }
     68 
     69 static void setup(void)
     70 {
     71 	tst_sig(FORK, DEF_HANDLER, NULL);
     72 	tst_timer_check(CLOCK_MONOTONIC);
     73 	TEST_PAUSE;
     74 }
     75