blob: 05ec625e794982e52231402284bf54f64edd6eb1 [file] [log] [blame]
Elliott Hughesd35df492017-02-15 15:19:05 -08001/*
2 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
Elliott Hughesc1873762018-12-19 15:13:36 -08003 * Copyright (c) 2015-2018 The strace developers.
Elliott Hughesd35df492017-02-15 15:19:05 -08004 * 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
37int
38main(void)
39{
Elliott Hughes39bac052017-05-25 16:56:11 -070040 TAIL_ALLOC_OBJECT_CONST_PTR(struct timeval, tv);
41 TAIL_ALLOC_OBJECT_CONST_PTR(struct timezone, tz);
Elliott Hughesd35df492017-02-15 15:19:05 -080042
Elliott Hughes39bac052017-05-25 16:56:11 -070043 if (syscall(__NR_gettimeofday, tv, NULL))
Elliott Hughesd35df492017-02-15 15:19:05 -080044 perror_msg_and_skip("gettimeofday");
Elliott Hughes39bac052017-05-25 16:56:11 -070045 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 Hughesd35df492017-02-15 15:19:05 -080048
Elliott Hughes39bac052017-05-25 16:56:11 -070049 if (syscall(__NR_gettimeofday, tv, tz))
Elliott Hughesd35df492017-02-15 15:19:05 -080050 perror_msg_and_skip("gettimeofday");
Elliott Hughes39bac052017-05-25 16:56:11 -070051 printf("gettimeofday({tv_sec=%lld, tv_usec=%llu}"
Elliott Hughesd35df492017-02-15 15:19:05 -080052 ", {tz_minuteswest=%d, tz_dsttime=%d}) = 0\n",
Elliott Hughes39bac052017-05-25 16:56:11 -070053 (long long) tv->tv_sec,
54 zero_extend_signed_to_ull(tv->tv_usec),
55 tz->tz_minuteswest, tz->tz_dsttime);
Elliott Hughesd35df492017-02-15 15:19:05 -080056
Elliott Hughes39bac052017-05-25 16:56:11 -070057 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 Hughesc1873762018-12-19 15:13:36 -080061 ", {tz_minuteswest=%d, tz_dsttime=%d}) = %s\n",
Elliott Hughes39bac052017-05-25 16:56:11 -070062 (long long) tv->tv_sec,
63 zero_extend_signed_to_ull(tv->tv_usec),
Elliott Hughesc1873762018-12-19 15:13:36 -080064 tz->tz_minuteswest, tz->tz_dsttime, sprintrc(-1));
Elliott Hughes39bac052017-05-25 16:56:11 -070065
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 Hughesc1873762018-12-19 15:13:36 -080070 ", {tz_minuteswest=%d, tz_dsttime=%d}) = %s\n",
Elliott Hughes39bac052017-05-25 16:56:11 -070071 (long long) tv->tv_sec,
72 zero_extend_signed_to_ull(tv->tv_usec),
Elliott Hughesc1873762018-12-19 15:13:36 -080073 tz->tz_minuteswest, tz->tz_dsttime, sprintrc(-1));
Elliott Hughes39bac052017-05-25 16:56:11 -070074
75 tv->tv_sec = (time_t) 0xcafef00ddeadbeefLL;
Elliott Hughes77c3ff82017-09-08 17:11:00 -070076 tv->tv_usec = (suseconds_t) 0xbadc0dedfacefeedLL;
Elliott Hughes39bac052017-05-25 16:56:11 -070077 assert(syscall(__NR_settimeofday, tv, tz) == -1);
78 printf("settimeofday({tv_sec=%lld, tv_usec=%llu}"
Elliott Hughesc1873762018-12-19 15:13:36 -080079 ", {tz_minuteswest=%d, tz_dsttime=%d}) = %s\n",
Elliott Hughes39bac052017-05-25 16:56:11 -070080 (long long) tv->tv_sec,
81 zero_extend_signed_to_ull(tv->tv_usec),
Elliott Hughesc1873762018-12-19 15:13:36 -080082 tz->tz_minuteswest, tz->tz_dsttime, sprintrc(-1));
Elliott Hughesd35df492017-02-15 15:19:05 -080083
84 puts("+++ exited with 0 +++");
85 return 0;
86}