1 /* vi: set sw=4 ts=4 sts=4: */
3 * timerfd test for uClibc
4 * Copyright (C) 2012 by Kevin Cernekee <cernekee@gmail.com>
6 * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
19 #include <sys/timerfd.h>
20 #include <sys/fcntl.h>
25 int fd, ret, result = 0;
30 fd = timerfd_create(CLOCK_MONOTONIC, TFD_NONBLOCK);
32 perror("timerfd() failed");
35 s.it_value.tv_sec = 1;
36 s.it_value.tv_nsec = 0;
37 s.it_interval.tv_sec = 0;
38 s.it_interval.tv_nsec = 0;
39 timerfd_settime(fd, 0, &s, NULL);
42 /* this should return immediately with EAGAIN due to TFD_NONBLOCK */
43 ret = read(fd, &val, sizeof(val));
44 if (ret != -1 || errno != EAGAIN) {
45 error(0, 0, "first read() returned %d", ret);
49 /* let the timer expire, then check it again */
52 } while (now - start < 2);
54 ret = read(fd, &val, sizeof(val));
55 if (ret != sizeof(val)) {
56 error(0, 0, "second read() returned %d", ret);
60 /* we are expecting a single expiration, since it_interval is 0 */
62 error(0, 0, "wrong number of expirations: %" PRIx64, val);
70 #define TEST_FUNCTION do_test ()
71 #include "../test-skeleton.c"