Dmitry V. Levin | 79cafcd | 2015-09-17 20:05:20 +0000 | [diff] [blame] | 1 | /* |
Dmitry V. Levin | 3a7c659 | 2016-01-06 09:51:37 +0000 | [diff] [blame] | 2 | * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org> |
Dmitry V. Levin | 79cafcd | 2015-09-17 20:05:20 +0000 | [diff] [blame] | 3 | * All rights reserved. |
| 4 | * |
| 5 | * Redistribution and use in source and binary forms, with or without |
| 6 | * modification, are permitted provided that the following conditions |
| 7 | * are met: |
| 8 | * 1. Redistributions of source code must retain the above copyright |
| 9 | * notice, this list of conditions and the following disclaimer. |
| 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 11 | * notice, this list of conditions and the following disclaimer in the |
| 12 | * documentation and/or other materials provided with the distribution. |
| 13 | * 3. The name of the author may not be used to endorse or promote products |
| 14 | * derived from this software without specific prior written permission. |
| 15 | * |
| 16 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
| 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
| 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
| 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
| 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
| 21 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 22 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 23 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
| 25 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 26 | */ |
| 27 | |
Dmitry V. Levin | 0c8853c | 2016-01-02 13:28:43 +0000 | [diff] [blame] | 28 | #include "tests.h" |
Dmitry V. Levin | 79cafcd | 2015-09-17 20:05:20 +0000 | [diff] [blame] | 29 | #include <fcntl.h> |
Dmitry V. Levin | 6a2f43c | 2016-08-09 14:38:29 +0000 | [diff] [blame] | 30 | #include <asm/unistd.h> |
Dmitry V. Levin | 79cafcd | 2015-09-17 20:05:20 +0000 | [diff] [blame] | 31 | |
| 32 | #if defined __NR_timerfd_create \ |
| 33 | && defined __NR_timerfd_gettime \ |
| 34 | && defined __NR_timerfd_settime \ |
| 35 | && defined O_CLOEXEC |
| 36 | |
Dmitry V. Levin | 3a7c659 | 2016-01-06 09:51:37 +0000 | [diff] [blame] | 37 | # include <stdio.h> |
| 38 | # include <stdint.h> |
| 39 | # include <time.h> |
| 40 | # include <unistd.h> |
| 41 | |
Dmitry V. Levin | 79cafcd | 2015-09-17 20:05:20 +0000 | [diff] [blame] | 42 | int |
| 43 | main(void) |
| 44 | { |
| 45 | (void) close(0); |
| 46 | if (syscall(__NR_timerfd_create, CLOCK_MONOTONIC, O_CLOEXEC | O_NONBLOCK)) |
Dmitry V. Levin | 3a7c659 | 2016-01-06 09:51:37 +0000 | [diff] [blame] | 47 | perror_msg_and_skip("timerfd_create"); |
Dmitry V. Levin | 79cafcd | 2015-09-17 20:05:20 +0000 | [diff] [blame] | 48 | puts("timerfd_create(CLOCK_MONOTONIC, TFD_CLOEXEC|TFD_NONBLOCK) = 0"); |
| 49 | |
| 50 | struct { |
| 51 | struct itimerspec its; |
| 52 | uint32_t pad[4]; |
| 53 | } old = { |
| 54 | .pad = { 0xdeadbeef, 0xbadc0ded, 0xdeadbeef, 0xbadc0ded } |
| 55 | }, new = { |
| 56 | .its = { |
| 57 | .it_interval = { 0xdeface1, 0xdeface2 }, |
| 58 | .it_value = { 0xdeface3, 0xdeface4 } |
| 59 | }, |
| 60 | .pad = { 0xdeadbeef, 0xbadc0ded, 0xdeadbeef, 0xbadc0ded } |
| 61 | }; |
| 62 | |
| 63 | if (syscall(__NR_timerfd_settime, 0, 0, &new.its, &old.its)) |
Dmitry V. Levin | 3a7c659 | 2016-01-06 09:51:37 +0000 | [diff] [blame] | 64 | perror_msg_and_skip("timerfd_settime"); |
Dmitry V. Levin | 79cafcd | 2015-09-17 20:05:20 +0000 | [diff] [blame] | 65 | printf("timerfd_settime(0, 0" |
| 66 | ", {it_interval={%jd, %jd}, it_value={%jd, %jd}}" |
| 67 | ", {it_interval={%jd, %jd}, it_value={%jd, %jd}}" |
| 68 | ") = 0\n", |
| 69 | (intmax_t) new.its.it_interval.tv_sec, |
| 70 | (intmax_t) new.its.it_interval.tv_nsec, |
| 71 | (intmax_t) new.its.it_value.tv_sec, |
| 72 | (intmax_t) new.its.it_value.tv_nsec, |
| 73 | (intmax_t) old.its.it_interval.tv_sec, |
| 74 | (intmax_t) old.its.it_interval.tv_nsec, |
| 75 | (intmax_t) old.its.it_value.tv_sec, |
| 76 | (intmax_t) old.its.it_value.tv_nsec); |
| 77 | |
| 78 | if (syscall(__NR_timerfd_gettime, 0, &old.its)) |
Dmitry V. Levin | 3a7c659 | 2016-01-06 09:51:37 +0000 | [diff] [blame] | 79 | perror_msg_and_skip("timerfd_gettime"); |
Dmitry V. Levin | 79cafcd | 2015-09-17 20:05:20 +0000 | [diff] [blame] | 80 | printf("timerfd_gettime(0" |
| 81 | ", {it_interval={%jd, %jd}, it_value={%jd, %jd}}" |
| 82 | ") = 0\n", |
| 83 | (intmax_t) old.its.it_interval.tv_sec, |
| 84 | (intmax_t) old.its.it_interval.tv_nsec, |
| 85 | (intmax_t) old.its.it_value.tv_sec, |
| 86 | (intmax_t) old.its.it_value.tv_nsec); |
| 87 | |
| 88 | puts("+++ exited with 0 +++"); |
| 89 | return 0; |
| 90 | } |
| 91 | |
| 92 | #else |
| 93 | |
Dmitry V. Levin | 3a7c659 | 2016-01-06 09:51:37 +0000 | [diff] [blame] | 94 | SKIP_MAIN_UNDEFINED("__NR_timerfd_create && __NR_timerfd_gettime" |
| 95 | " && __NR_timerfd_settime && O_CLOEXEC") |
Dmitry V. Levin | 79cafcd | 2015-09-17 20:05:20 +0000 | [diff] [blame] | 96 | |
| 97 | #endif |