1 /* 2 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv (at) altlinux.org> 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 28 #include "tests.h" 29 #include <fcntl.h> 30 #include <asm/unistd.h> 31 32 #if defined __NR_timerfd_create \ 33 && defined __NR_timerfd_gettime \ 34 && defined __NR_timerfd_settime \ 35 && defined O_CLOEXEC 36 37 # include <stdio.h> 38 # include <stdint.h> 39 # include <time.h> 40 # include <unistd.h> 41 42 int 43 main(void) 44 { 45 (void) close(0); 46 if (syscall(__NR_timerfd_create, CLOCK_MONOTONIC, O_CLOEXEC | O_NONBLOCK)) 47 perror_msg_and_skip("timerfd_create"); 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 .its = { 55 .it_interval = { 0xdeface5, 0xdeface6 }, 56 .it_value = { 0xdeface7, 0xdeface8 } 57 }, 58 .pad = { 0xdeadbeef, 0xbadc0ded, 0xdeadbeef, 0xbadc0ded } 59 }, new = { 60 .its = { 61 .it_interval = { 0xdeface1, 0xdeface2 }, 62 .it_value = { 0xdeface3, 0xdeface4 } 63 }, 64 .pad = { 0xdeadbeef, 0xbadc0ded, 0xdeadbeef, 0xbadc0ded } 65 }; 66 67 if (syscall(__NR_timerfd_settime, 0, 0, &new.its, &old.its)) 68 perror_msg_and_skip("timerfd_settime"); 69 printf("timerfd_settime(0, 0" 70 ", {it_interval={tv_sec=%jd, tv_nsec=%jd}" 71 ", it_value={tv_sec=%jd, tv_nsec=%jd}}" 72 ", {it_interval={tv_sec=%jd, tv_nsec=%jd}" 73 ", it_value={tv_sec=%jd, tv_nsec=%jd}}" 74 ") = 0\n", 75 (intmax_t) new.its.it_interval.tv_sec, 76 (intmax_t) new.its.it_interval.tv_nsec, 77 (intmax_t) new.its.it_value.tv_sec, 78 (intmax_t) new.its.it_value.tv_nsec, 79 (intmax_t) old.its.it_interval.tv_sec, 80 (intmax_t) old.its.it_interval.tv_nsec, 81 (intmax_t) old.its.it_value.tv_sec, 82 (intmax_t) old.its.it_value.tv_nsec); 83 84 if (syscall(__NR_timerfd_gettime, 0, &old.its)) 85 perror_msg_and_skip("timerfd_gettime"); 86 printf("timerfd_gettime(0" 87 ", {it_interval={tv_sec=%jd, tv_nsec=%jd}" 88 ", it_value={tv_sec=%jd, tv_nsec=%jd}}) = 0\n", 89 (intmax_t) old.its.it_interval.tv_sec, 90 (intmax_t) old.its.it_interval.tv_nsec, 91 (intmax_t) old.its.it_value.tv_sec, 92 (intmax_t) old.its.it_value.tv_nsec); 93 94 puts("+++ exited with 0 +++"); 95 return 0; 96 } 97 98 #else 99 100 SKIP_MAIN_UNDEFINED("__NR_timerfd_create && __NR_timerfd_gettime" 101 " && __NR_timerfd_settime && O_CLOEXEC") 102 103 #endif 104