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