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 | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame^] | 3 | * Copyright (c) 2015-2018 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 <assert.h> |
| 31 | #include <stdio.h> |
| 32 | #include <stdint.h> |
| 33 | #include <unistd.h> |
| 34 | #include <sys/time.h> |
| 35 | #include <asm/unistd.h> |
| 36 | |
| 37 | int |
| 38 | main(void) |
| 39 | { |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 40 | TAIL_ALLOC_OBJECT_CONST_PTR(struct timeval, tv); |
| 41 | TAIL_ALLOC_OBJECT_CONST_PTR(struct timezone, tz); |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 42 | |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 43 | if (syscall(__NR_gettimeofday, tv, NULL)) |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 44 | perror_msg_and_skip("gettimeofday"); |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 45 | printf("gettimeofday({tv_sec=%lld, tv_usec=%llu}, NULL) = 0\n", |
| 46 | (long long) tv->tv_sec, |
| 47 | zero_extend_signed_to_ull(tv->tv_usec)); |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 48 | |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 49 | if (syscall(__NR_gettimeofday, tv, tz)) |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 50 | perror_msg_and_skip("gettimeofday"); |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 51 | printf("gettimeofday({tv_sec=%lld, tv_usec=%llu}" |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 52 | ", {tz_minuteswest=%d, tz_dsttime=%d}) = 0\n", |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 53 | (long long) tv->tv_sec, |
| 54 | zero_extend_signed_to_ull(tv->tv_usec), |
| 55 | tz->tz_minuteswest, tz->tz_dsttime); |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 56 | |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 57 | tv->tv_sec = -1; |
| 58 | tv->tv_usec = 1000000; |
| 59 | assert(syscall(__NR_settimeofday, tv, tz) == -1); |
| 60 | printf("settimeofday({tv_sec=%lld, tv_usec=%llu}" |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame^] | 61 | ", {tz_minuteswest=%d, tz_dsttime=%d}) = %s\n", |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 62 | (long long) tv->tv_sec, |
| 63 | zero_extend_signed_to_ull(tv->tv_usec), |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame^] | 64 | tz->tz_minuteswest, tz->tz_dsttime, sprintrc(-1)); |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 65 | |
| 66 | tv->tv_sec = 0xdeadbeefU; |
| 67 | tv->tv_usec = 0xfacefeedU; |
| 68 | assert(syscall(__NR_settimeofday, tv, tz) == -1); |
| 69 | printf("settimeofday({tv_sec=%lld, tv_usec=%llu}" |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame^] | 70 | ", {tz_minuteswest=%d, tz_dsttime=%d}) = %s\n", |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 71 | (long long) tv->tv_sec, |
| 72 | zero_extend_signed_to_ull(tv->tv_usec), |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame^] | 73 | tz->tz_minuteswest, tz->tz_dsttime, sprintrc(-1)); |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 74 | |
| 75 | tv->tv_sec = (time_t) 0xcafef00ddeadbeefLL; |
Elliott Hughes | 77c3ff8 | 2017-09-08 17:11:00 -0700 | [diff] [blame] | 76 | tv->tv_usec = (suseconds_t) 0xbadc0dedfacefeedLL; |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 77 | assert(syscall(__NR_settimeofday, tv, tz) == -1); |
| 78 | printf("settimeofday({tv_sec=%lld, tv_usec=%llu}" |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame^] | 79 | ", {tz_minuteswest=%d, tz_dsttime=%d}) = %s\n", |
Elliott Hughes | 39bac05 | 2017-05-25 16:56:11 -0700 | [diff] [blame] | 80 | (long long) tv->tv_sec, |
| 81 | zero_extend_signed_to_ull(tv->tv_usec), |
Elliott Hughes | c187376 | 2018-12-19 15:13:36 -0800 | [diff] [blame^] | 82 | tz->tz_minuteswest, tz->tz_dsttime, sprintrc(-1)); |
Elliott Hughes | d35df49 | 2017-02-15 15:19:05 -0800 | [diff] [blame] | 83 | |
| 84 | puts("+++ exited with 0 +++"); |
| 85 | return 0; |
| 86 | } |