]> granicus.if.org Git - strace/blob - tests/timer_xettime.c
tests: fill old_value argument in timer{,fd}_xettime tests
[strace] / tests / timer_xettime.c
1 /*
2  * This file is part of timer_xettime strace test.
3  *
4  * Copyright (c) 2015-2016 Dmitry V. Levin <ldv@altlinux.org>
5  * 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
30 #include "tests.h"
31 #include <asm/unistd.h>
32
33 #if defined __NR_timer_create \
34  && defined __NR_timer_gettime \
35  && defined __NR_timer_settime
36
37 # include <stdio.h>
38 # include <stdint.h>
39 # include <signal.h>
40 # include <time.h>
41 # include <unistd.h>
42
43 int
44 main(void)
45 {
46         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
50         int tid;
51         struct sigevent sev = { .sigev_notify = SIGEV_NONE };
52
53         if (syscall(__NR_timer_create, CLOCK_MONOTONIC, &sev, &tid))
54                 perror_msg_and_skip("timer_create");
55         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                 .its = {
63                         .it_interval = { 0xdeface5, 0xdeface6 },
64                         .it_value = { 0xdeface7, 0xdeface8 }
65                 },
66                 .pad = { 0xdeadbeef, 0xbadc0ded, 0xdeadbeef, 0xbadc0ded }
67         }, new = {
68                 .its = {
69                         .it_interval = { 0xdeface1, 0xdeface2 },
70                         .it_value = { 0xdeface3, 0xdeface4 }
71                 },
72                 .pad = { 0xdeadbeef, 0xbadc0ded, 0xdeadbeef, 0xbadc0ded }
73         };
74
75         if (syscall(__NR_timer_settime, tid, 0, &new.its, &old.its))
76                 perror_msg_and_skip("timer_settime");
77         printf("timer_settime(%d, 0"
78                ", {it_interval={%jd, %jd}, it_value={%jd, %jd}}"
79                ", {it_interval={%jd, %jd}, it_value={%jd, %jd}}"
80                ") = 0\n",
81                tid,
82                (intmax_t) new.its.it_interval.tv_sec,
83                (intmax_t) new.its.it_interval.tv_nsec,
84                (intmax_t) new.its.it_value.tv_sec,
85                (intmax_t) new.its.it_value.tv_nsec,
86                (intmax_t) old.its.it_interval.tv_sec,
87                (intmax_t) old.its.it_interval.tv_nsec,
88                (intmax_t) old.its.it_value.tv_sec,
89                (intmax_t) old.its.it_value.tv_nsec);
90
91         if (syscall(__NR_timer_gettime, tid, &old.its))
92                 perror_msg_and_skip("timer_gettime");
93         printf("timer_gettime(%d"
94                ", {it_interval={%jd, %jd}, it_value={%jd, %jd}}"
95                ") = 0\n",
96                tid,
97                (intmax_t) old.its.it_interval.tv_sec,
98                (intmax_t) old.its.it_interval.tv_nsec,
99                (intmax_t) old.its.it_value.tv_sec,
100                (intmax_t) old.its.it_value.tv_nsec);
101
102         puts("+++ exited with 0 +++");
103         return 0;
104 }
105
106 #else
107
108 SKIP_MAIN_UNDEFINED("__NR_timer_create && __NR_timer_gettime && __NR_timer_settime")
109
110 #endif