blob: 841ba565846ad8169b649642a8b713d305715e21 [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 <stdio.h>
31#include <stdint.h>
32#include <time.h>
33#include <unistd.h>
34#include <asm/unistd.h>
35
36#if defined __NR_clock_getres \
37 && defined __NR_clock_gettime \
38 && defined __NR_clock_settime
39
40int
41main(void)
42{
43 struct {
44 struct timespec ts;
45 uint32_t pad[2];
46 } t = {
47 .pad = { 0xdeadbeef, 0xbadc0ded }
48 };
Elliott Hughesc1873762018-12-19 15:13:36 -080049 long rc;
Elliott Hughesd35df492017-02-15 15:19:05 -080050
51 if (syscall(__NR_clock_getres, CLOCK_REALTIME, &t.ts))
52 perror_msg_and_skip("clock_getres CLOCK_REALTIME");
Elliott Hughes39bac052017-05-25 16:56:11 -070053 printf("clock_getres(CLOCK_REALTIME, {tv_sec=%lld, tv_nsec=%llu})"
54 " = 0\n",
55 (long long) t.ts.tv_sec,
56 zero_extend_signed_to_ull(t.ts.tv_nsec));
Elliott Hughesd35df492017-02-15 15:19:05 -080057
58 if (syscall(__NR_clock_gettime, CLOCK_PROCESS_CPUTIME_ID, &t.ts))
59 perror_msg_and_skip("clock_gettime CLOCK_PROCESS_CPUTIME_ID");
Elliott Hughes39bac052017-05-25 16:56:11 -070060 printf("clock_gettime(CLOCK_PROCESS_CPUTIME_ID"
61 ", {tv_sec=%lld, tv_nsec=%llu}) = 0\n",
62 (long long) t.ts.tv_sec,
63 zero_extend_signed_to_ull(t.ts.tv_nsec));
Elliott Hughesd35df492017-02-15 15:19:05 -080064
65 t.ts.tv_sec = 0xdeface1;
66 t.ts.tv_nsec = 0xdeface2;
Elliott Hughesc1873762018-12-19 15:13:36 -080067 rc = syscall(__NR_clock_settime, CLOCK_THREAD_CPUTIME_ID, &t.ts);
Elliott Hughes39bac052017-05-25 16:56:11 -070068 printf("clock_settime(CLOCK_THREAD_CPUTIME_ID"
Elliott Hughesc1873762018-12-19 15:13:36 -080069 ", {tv_sec=%lld, tv_nsec=%llu}) = %s\n",
Elliott Hughes39bac052017-05-25 16:56:11 -070070 (long long) t.ts.tv_sec,
Elliott Hughesc1873762018-12-19 15:13:36 -080071 zero_extend_signed_to_ull(t.ts.tv_nsec), sprintrc(rc));
Elliott Hughes39bac052017-05-25 16:56:11 -070072
73 t.ts.tv_sec = 0xdeadbeefU;
74 t.ts.tv_nsec = 0xfacefeedU;
Elliott Hughesc1873762018-12-19 15:13:36 -080075 rc = syscall(__NR_clock_settime, CLOCK_THREAD_CPUTIME_ID, &t.ts);
Elliott Hughes39bac052017-05-25 16:56:11 -070076 printf("clock_settime(CLOCK_THREAD_CPUTIME_ID"
Elliott Hughesc1873762018-12-19 15:13:36 -080077 ", {tv_sec=%lld, tv_nsec=%llu}) = %s\n",
Elliott Hughes39bac052017-05-25 16:56:11 -070078 (long long) t.ts.tv_sec,
Elliott Hughesc1873762018-12-19 15:13:36 -080079 zero_extend_signed_to_ull(t.ts.tv_nsec), sprintrc(rc));
Elliott Hughes39bac052017-05-25 16:56:11 -070080
81 t.ts.tv_sec = (time_t) 0xcafef00ddeadbeefLL;
82 t.ts.tv_nsec = (long) 0xbadc0dedfacefeedLL;
Elliott Hughesc1873762018-12-19 15:13:36 -080083 rc = syscall(__NR_clock_settime, CLOCK_THREAD_CPUTIME_ID, &t.ts);
Elliott Hughes39bac052017-05-25 16:56:11 -070084 printf("clock_settime(CLOCK_THREAD_CPUTIME_ID"
Elliott Hughesc1873762018-12-19 15:13:36 -080085 ", {tv_sec=%lld, tv_nsec=%llu}) = %s\n",
Elliott Hughes39bac052017-05-25 16:56:11 -070086 (long long) t.ts.tv_sec,
Elliott Hughesc1873762018-12-19 15:13:36 -080087 zero_extend_signed_to_ull(t.ts.tv_nsec), sprintrc(rc));
Elliott Hughesd35df492017-02-15 15:19:05 -080088
89 puts("+++ exited with 0 +++");
90 return 0;
91}
92
93#else
94
95SKIP_MAIN_UNDEFINED("__NR_clock_getres && __NR_clock_gettime && __NR_clock_settime")
96
97#endif