1 #include <errno.h>
2 #include <inttypes.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <time.h>
6 #include <pthread.h>
7
8 #define assert(_Expression) (void)( (!!(_Expression)) || (_my_assert(#_Expression, __FILE__, __LINE__), 0) )
9
_my_assert(char * message,char * file,unsigned int line)10 static __inline void _my_assert(char *message, char *file, unsigned int line)
11 {
12 fprintf(stderr, "Assertion failed: %s , file %s, line %u\n", message, file, line);
13 exit(1);
14 }
15
test_clock_settime()16 void test_clock_settime()
17 {
18 int rc;
19 struct timespec tp, request = { 1, 0 }, remain;
20
21 rc = clock_gettime(CLOCK_REALTIME, &tp);
22 assert(rc == 0);
23 printf("[%10"PRId64".%09d] clock_gettime (CLOCK_REALTIME)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
24
25 rc = clock_settime(CLOCK_MONOTONIC, &tp);
26 assert(rc == -1 && (errno == EINVAL));
27
28 rc = clock_settime(CLOCK_PROCESS_CPUTIME_ID, &tp);
29 assert(rc == -1 && (errno == EINVAL));
30
31 rc = clock_settime(CLOCK_THREAD_CPUTIME_ID, &tp);
32 assert(rc == -1 && (errno == EINVAL));
33
34 rc = clock_settime(CLOCK_REALTIME, &tp);
35 assert(rc == 0 || (errno == EPERM));
36
37 rc = clock_gettime(CLOCK_REALTIME, &tp);
38 assert(rc == 0);
39 printf("[%10"PRId64".%09d] clock_gettime (CLOCK_REALTIME)\n", (__int64) tp.tv_sec, (int) tp.tv_nsec);
40 }
41
main(int argc,char * argv[])42 int main(int argc, char *argv[])
43 {
44 test_clock_settime();
45
46 return 0;
47 }
48