blob: 6fcd00ef6f972991030600c07d2d6c5e17e00252 [file] [log] [blame]
Dmitry V. Levin13140982015-09-17 18:25:12 +00001/*
Dmitry V. Levinb1b692e2016-02-08 00:13:00 +00002 * This file is part of timer_xettime strace test.
3 *
Dmitry V. Levin0566d542016-01-06 09:50:44 +00004 * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
Dmitry V. Levin13140982015-09-17 18:25:12 +00005 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
23 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 */
29
Dmitry V. Levin0c8853c2016-01-02 13:28:43 +000030#include "tests.h"
Dmitry V. Levin6a2f43c2016-08-09 14:38:29 +000031#include <asm/unistd.h>
Dmitry V. Levin13140982015-09-17 18:25:12 +000032
33#if defined __NR_timer_create \
34 && defined __NR_timer_gettime \
35 && defined __NR_timer_settime
36
Dmitry V. Levin0566d542016-01-06 09:50:44 +000037# include <stdio.h>
38# include <stdint.h>
39# include <signal.h>
40# include <time.h>
41# include <unistd.h>
42
Dmitry V. Levin13140982015-09-17 18:25:12 +000043int
44main(void)
45{
Dmitry V. Levinb1b692e2016-02-08 00:13:00 +000046 syscall(__NR_timer_settime, 0xdefaced, TIMER_ABSTIME, NULL, NULL);
47 printf("timer_settime(%d, TIMER_ABSTIME, NULL, NULL)"
48 " = -1 EINVAL (%m)\n", 0xdefaced);
49
Dmitry V. Levin13140982015-09-17 18:25:12 +000050 int tid;
51 struct sigevent sev = { .sigev_notify = SIGEV_NONE };
52
53 if (syscall(__NR_timer_create, CLOCK_MONOTONIC, &sev, &tid))
Dmitry V. Levin0566d542016-01-06 09:50:44 +000054 perror_msg_and_skip("timer_create");
Dmitry V. Levin13140982015-09-17 18:25:12 +000055 printf("timer_create(CLOCK_MONOTONIC, {sigev_signo=0"
56 ", sigev_notify=SIGEV_NONE}, [%d]) = 0\n", tid);
57
58 struct {
59 struct itimerspec its;
60 uint32_t pad[4];
61 } old = {
62 .pad = { 0xdeadbeef, 0xbadc0ded, 0xdeadbeef, 0xbadc0ded }
63 }, new = {
64 .its = {
65 .it_interval = { 0xdeface1, 0xdeface2 },
66 .it_value = { 0xdeface3, 0xdeface4 }
67 },
68 .pad = { 0xdeadbeef, 0xbadc0ded, 0xdeadbeef, 0xbadc0ded }
69 };
70
71 if (syscall(__NR_timer_settime, tid, 0, &new.its, &old.its))
Dmitry V. Levin0566d542016-01-06 09:50:44 +000072 perror_msg_and_skip("timer_settime");
Dmitry V. Levin13140982015-09-17 18:25:12 +000073 printf("timer_settime(%d, 0"
74 ", {it_interval={%jd, %jd}, it_value={%jd, %jd}}"
75 ", {it_interval={%jd, %jd}, it_value={%jd, %jd}}"
76 ") = 0\n",
77 tid,
78 (intmax_t) new.its.it_interval.tv_sec,
79 (intmax_t) new.its.it_interval.tv_nsec,
80 (intmax_t) new.its.it_value.tv_sec,
81 (intmax_t) new.its.it_value.tv_nsec,
82 (intmax_t) old.its.it_interval.tv_sec,
83 (intmax_t) old.its.it_interval.tv_nsec,
84 (intmax_t) old.its.it_value.tv_sec,
85 (intmax_t) old.its.it_value.tv_nsec);
86
87 if (syscall(__NR_timer_gettime, tid, &old.its))
Dmitry V. Levin0566d542016-01-06 09:50:44 +000088 perror_msg_and_skip("timer_gettime");
Dmitry V. Levin13140982015-09-17 18:25:12 +000089 printf("timer_gettime(%d"
90 ", {it_interval={%jd, %jd}, it_value={%jd, %jd}}"
91 ") = 0\n",
92 tid,
93 (intmax_t) old.its.it_interval.tv_sec,
94 (intmax_t) old.its.it_interval.tv_nsec,
95 (intmax_t) old.its.it_value.tv_sec,
96 (intmax_t) old.its.it_value.tv_nsec);
97
98 puts("+++ exited with 0 +++");
99 return 0;
100}
101
102#else
103
Dmitry V. Levin0566d542016-01-06 09:50:44 +0000104SKIP_MAIN_UNDEFINED("__NR_timer_create && __NR_timer_gettime && __NR_timer_settime")
Dmitry V. Levin13140982015-09-17 18:25:12 +0000105
106#endif