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 clock_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 <stdint.h>
15#include "posixtest.h"
16
17#define NUMINVALIDTESTS 9
18
19static int invalid_tests[NUMINVALIDTESTS] = {
20	INT32_MIN,
21	INT32_MAX,
22	2147483647,
23	-2147483647,
24	-1073743192,
25	1073743192,
26	-1,
27	1000000000,
28	1000000001
29};
30
31int main(int argc, char *argv[])
32{
33	struct timespec tssleep;
34	int i;
35	int failure = 0;
36
37	tssleep.tv_sec=0;
38
39	for (i=0; i<NUMINVALIDTESTS;i++) {
40		tssleep.tv_nsec=invalid_tests[i];
41		printf("sleep %d\n", invalid_tests[i]);
42		if (clock_nanosleep(CLOCK_REALTIME, 0, &tssleep, NULL) !=
43			EINVAL) {
44			printf("errno != EINVAL\n");
45			failure = 1;
46		}
47	}
48
49	if (failure) {
50		printf("At least one test FAILED\n");
51		return PTS_FAIL;
52	} else {
53		printf("All tests PASSED\n");
54		return PTS_PASS;
55	}
56}
57