• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
3  * Copyright (c) 2015-2018 The strace developers.
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
main(void)38 main(void)
39 {
40 	TAIL_ALLOC_OBJECT_CONST_PTR(struct timeval, tv);
41 	TAIL_ALLOC_OBJECT_CONST_PTR(struct timezone, tz);
42 
43 	if (syscall(__NR_gettimeofday, tv, NULL))
44 		perror_msg_and_skip("gettimeofday");
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));
48 
49 	if (syscall(__NR_gettimeofday, tv, tz))
50 		perror_msg_and_skip("gettimeofday");
51 	printf("gettimeofday({tv_sec=%lld, tv_usec=%llu}"
52 	       ", {tz_minuteswest=%d, tz_dsttime=%d}) = 0\n",
53 	       (long long) tv->tv_sec,
54 	       zero_extend_signed_to_ull(tv->tv_usec),
55 	       tz->tz_minuteswest, tz->tz_dsttime);
56 
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}"
61 	       ", {tz_minuteswest=%d, tz_dsttime=%d}) = %s\n",
62 	       (long long) tv->tv_sec,
63 	       zero_extend_signed_to_ull(tv->tv_usec),
64 	       tz->tz_minuteswest, tz->tz_dsttime, sprintrc(-1));
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}"
70 	       ", {tz_minuteswest=%d, tz_dsttime=%d}) = %s\n",
71 	       (long long) tv->tv_sec,
72 	       zero_extend_signed_to_ull(tv->tv_usec),
73 	       tz->tz_minuteswest, tz->tz_dsttime, sprintrc(-1));
74 
75 	tv->tv_sec = (time_t) 0xcafef00ddeadbeefLL;
76 	tv->tv_usec = (suseconds_t) 0xbadc0dedfacefeedLL;
77 	assert(syscall(__NR_settimeofday, tv, tz) == -1);
78 	printf("settimeofday({tv_sec=%lld, tv_usec=%llu}"
79 	       ", {tz_minuteswest=%d, tz_dsttime=%d}) = %s\n",
80 	       (long long) tv->tv_sec,
81 	       zero_extend_signed_to_ull(tv->tv_usec),
82 	       tz->tz_minuteswest, tz->tz_dsttime, sprintrc(-1));
83 
84 	puts("+++ exited with 0 +++");
85 	return 0;
86 }
87