summaryrefslogtreecommitdiff
path: root/tests/xettimeofday.c
blob: 44ed129aeabf073578ed834a250544e357c723af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
 * Copyright (c) 2015-2018 The strace developers.
 * All rights reserved.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "tests.h"
#include <assert.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/time.h>
#include "scno.h"

int
main(void)
{
	TAIL_ALLOC_OBJECT_CONST_PTR(struct timeval, tv);
	TAIL_ALLOC_OBJECT_CONST_PTR(struct timezone, tz);

	if (syscall(__NR_gettimeofday, tv, NULL))
		perror_msg_and_skip("gettimeofday");
	printf("gettimeofday({tv_sec=%lld, tv_usec=%llu}, NULL) = 0\n",
	       (long long) tv->tv_sec,
	       zero_extend_signed_to_ull(tv->tv_usec));

	if (syscall(__NR_gettimeofday, tv, tz))
		perror_msg_and_skip("gettimeofday");
	printf("gettimeofday({tv_sec=%lld, tv_usec=%llu}"
	       ", {tz_minuteswest=%d, tz_dsttime=%d}) = 0\n",
	       (long long) tv->tv_sec,
	       zero_extend_signed_to_ull(tv->tv_usec),
	       tz->tz_minuteswest, tz->tz_dsttime);

	tv->tv_sec = -1;
	tv->tv_usec = 1000000;
	assert(syscall(__NR_settimeofday, tv, tz) == -1);
	printf("settimeofday({tv_sec=%lld, tv_usec=%llu}"
	       ", {tz_minuteswest=%d, tz_dsttime=%d}) = %s\n",
	       (long long) tv->tv_sec,
	       zero_extend_signed_to_ull(tv->tv_usec),
	       tz->tz_minuteswest, tz->tz_dsttime, sprintrc(-1));

	tv->tv_sec = 0xdeadbeefU;
	tv->tv_usec = 0xfacefeedU;
	assert(syscall(__NR_settimeofday, tv, tz) == -1);
	printf("settimeofday({tv_sec=%lld, tv_usec=%llu}"
	       ", {tz_minuteswest=%d, tz_dsttime=%d}) = %s\n",
	       (long long) tv->tv_sec,
	       zero_extend_signed_to_ull(tv->tv_usec),
	       tz->tz_minuteswest, tz->tz_dsttime, sprintrc(-1));

	tv->tv_sec = (time_t) 0xcafef00ddeadbeefLL;
	tv->tv_usec = (suseconds_t) 0xbadc0dedfacefeedLL;
	assert(syscall(__NR_settimeofday, tv, tz) == -1);
	printf("settimeofday({tv_sec=%lld, tv_usec=%llu}"
	       ", {tz_minuteswest=%d, tz_dsttime=%d}) = %s\n",
	       (long long) tv->tv_sec,
	       zero_extend_signed_to_ull(tv->tv_usec),
	       tz->tz_minuteswest, tz->tz_dsttime, sprintrc(-1));

	puts("+++ exited with 0 +++");
	return 0;
}