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