about summary refs log tree commit diff
path: root/rt/tst-clock2.c
blob: 4c8fb9f247590a42a70be95a4c58d4c3b1c425c6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/* Test setting the monotonic clock.  */

#include <time.h>
#include <unistd.h>

#if defined CLOCK_MONOTONIC && defined _POSIX_MONOTONIC_CLOCK

# include <errno.h>
# include <stdio.h>

static int
do_test (void)
{
  if (sysconf (_SC_MONOTONIC_CLOCK) <= 0)
    return 0;

  struct timespec ts;
  if (clock_gettime (CLOCK_MONOTONIC, &ts) != 0)
    {
      puts ("clock_gettime(CLOCK_MONOTONIC) failed");
      return 1;
    }

  /* Setting the monotonic clock must fail.  */
  if (clock_settime (CLOCK_MONOTONIC, &ts) != -1)
    {
      puts ("clock_settime(CLOCK_MONOTONIC) did not fail");
      return 1;
    }
  if (errno != EINVAL)
    {
      printf ("clock_settime(CLOCK_MONOTONIC) set errno to %d, expected %d\n",
	      errno, EINVAL);
      return 1;
    }
  return 0;
}
# define TEST_FUNCTION do_test ()

#else
# define TEST_FUNCTION	0
#endif
#include "../test-skeleton.c"