summaryrefslogtreecommitdiff
path: root/tests/clock_xettime.c
blob: 2a67a81978bee77e701b5fa9ffc987cab26f40dd (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
67
68
69
70
71
72
73
74
75
76
77
/*
 * 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 <stdio.h>
#include <stdint.h>
#include <time.h>
#include <unistd.h>
#include "scno.h"

#if defined __NR_clock_getres \
 && defined __NR_clock_gettime \
 && defined __NR_clock_settime

int
main(void)
{
	struct {
		struct timespec ts;
		uint32_t pad[2];
	} t = {
		.pad = { 0xdeadbeef, 0xbadc0ded }
	};
	long rc;

	if (syscall(__NR_clock_getres, CLOCK_REALTIME, &t.ts))
		perror_msg_and_skip("clock_getres CLOCK_REALTIME");
	printf("clock_getres(CLOCK_REALTIME, {tv_sec=%lld, tv_nsec=%llu})"
	       " = 0\n",
	       (long long) t.ts.tv_sec,
	       zero_extend_signed_to_ull(t.ts.tv_nsec));

	if (syscall(__NR_clock_gettime, CLOCK_PROCESS_CPUTIME_ID, &t.ts))
		perror_msg_and_skip("clock_gettime CLOCK_PROCESS_CPUTIME_ID");
	printf("clock_gettime(CLOCK_PROCESS_CPUTIME_ID"
	       ", {tv_sec=%lld, tv_nsec=%llu}) = 0\n",
	       (long long) t.ts.tv_sec,
	       zero_extend_signed_to_ull(t.ts.tv_nsec));

	t.ts.tv_sec = 0xdeface1;
	t.ts.tv_nsec = 0xdeface2;
	rc = syscall(__NR_clock_settime, CLOCK_THREAD_CPUTIME_ID, &t.ts);
	printf("clock_settime(CLOCK_THREAD_CPUTIME_ID"
	       ", {tv_sec=%lld, tv_nsec=%llu}) = %s\n",
	       (long long) t.ts.tv_sec,
	       zero_extend_signed_to_ull(t.ts.tv_nsec), sprintrc(rc));

	t.ts.tv_sec = 0xdeadbeefU;
	t.ts.tv_nsec = 0xfacefeedU;
	rc = syscall(__NR_clock_settime, CLOCK_THREAD_CPUTIME_ID, &t.ts);
	printf("clock_settime(CLOCK_THREAD_CPUTIME_ID"
	       ", {tv_sec=%lld, tv_nsec=%llu}) = %s\n",
	       (long long) t.ts.tv_sec,
	       zero_extend_signed_to_ull(t.ts.tv_nsec), sprintrc(rc));

	t.ts.tv_sec = (time_t) 0xcafef00ddeadbeefLL;
	t.ts.tv_nsec = (long) 0xbadc0dedfacefeedLL;
	rc = syscall(__NR_clock_settime, CLOCK_THREAD_CPUTIME_ID, &t.ts);
	printf("clock_settime(CLOCK_THREAD_CPUTIME_ID"
	       ", {tv_sec=%lld, tv_nsec=%llu}) = %s\n",
	       (long long) t.ts.tv_sec,
	       zero_extend_signed_to_ull(t.ts.tv_nsec), sprintrc(rc));

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

#else

SKIP_MAIN_UNDEFINED("__NR_clock_getres && __NR_clock_gettime && __NR_clock_settime")

#endif