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