Home | History | Annotate | Download | only in nanosleep
      1 /*
      2  * Copyright (c) 2002, Intel Corporation. All rights reserved.
      3  * Created by:  julie.n.fleischer REMOVE-THIS AT intel DOT com
      4  * This file is licensed under the GPL license.  For the full content
      5  * of this license, see the COPYING file at the top level of this
      6  * source tree.
      7 
      8  * Test that nanosleep() sets errno to EINVAL if rqtp contained a
      9  * nanosecond value < 0 or >= 1,000 million
     10  */
     11 #include <stdio.h>
     12 #include <time.h>
     13 #include <errno.h>
     14 #include "posixtest.h"
     15 
     16 #define NUMTESTS 7
     17 
     18 int main(void)
     19 {
     20 	struct timespec tssleepfor, tsstorage;
     21 	int sleepnsec[NUMTESTS] = { -1, -5, -1000000000, 1000000000,
     22 		1000000001, 2000000000, 2000000000
     23 	};
     24 	int i;
     25 	int failure = 0;
     26 
     27 	tssleepfor.tv_sec = 0;
     28 
     29 	for (i = 0; i < NUMTESTS; i++) {
     30 		tssleepfor.tv_nsec = sleepnsec[i];
     31 		printf("sleep %d\n", sleepnsec[i]);
     32 		if (nanosleep(&tssleepfor, &tsstorage) == -1) {
     33 			if (EINVAL != errno) {
     34 				printf("errno != EINVAL\n");
     35 				failure = 1;
     36 			}
     37 		} else {
     38 			printf("nanosleep() did not return -1 on failure\n");
     39 			return PTS_UNRESOLVED;
     40 		}
     41 	}
     42 
     43 	if (failure) {
     44 		printf("At least one test FAILED\n");
     45 		return PTS_FAIL;
     46 	} else {
     47 		printf("All tests PASSED\n");
     48 		return PTS_PASS;
     49 	}
     50 }
     51