blob: ee09955b68ed664eb49ec48dc921b4f7aef1e961 [file] [log] [blame]
Dmitry V. Levinba351372016-05-25 15:44:32 +00001/*
2 * This file is part of ioctl_rtc strace test.
3 *
4 * Copyright (c) 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 <errno.h>
32#include <stdio.h>
33#include <string.h>
34#include <sys/ioctl.h>
35#include <linux/types.h>
36#include <linux/rtc.h>
37#include "xlat.h"
38
39static const unsigned int magic = 0xdeadbeef;
40static const unsigned long lmagic = (unsigned long) 0xdeadbeefbadc0ded;
41
42static void
43init_magic(void *addr, const unsigned int size)
44{
45 unsigned int *p = addr;
46 const unsigned int *end = addr + size - sizeof(int);
47
48 for (; p <= end; ++p)
49 *(unsigned int *) p = magic;
50}
51
52static void
53print_rtc_time(const struct rtc_time *rt)
54{
55 printf("{tm_sec=%d, tm_min=%d, tm_hour=%d"
56 ", tm_mday=%d, tm_mon=%d, tm_year=%d",
57 rt->tm_sec, rt->tm_min, rt->tm_hour,
58 rt->tm_mday, rt->tm_mon, rt->tm_year);
59#ifdef VERBOSE_IOCTL
60 printf(", tm_wday=%d, tm_yday=%d, tm_isdst=%d}",
61 rt->tm_wday, rt->tm_yday, rt->tm_isdst);
62#else
63 printf(", ...}");
64#endif
65}
66
67static struct xlat rtc_argless[] = {
68 XLAT(RTC_AIE_OFF),
69 XLAT(RTC_PIE_ON),
70 XLAT(RTC_PIE_OFF),
71 XLAT(RTC_UIE_ON),
72 XLAT(RTC_WIE_ON),
73 XLAT(RTC_WIE_OFF),
74#ifdef RTC_VL_CLR
75 XLAT(RTC_VL_CLR),
76#endif
77};
78
79int
80main(void)
81{
82 const unsigned int size = get_page_size();
83
84 void *const page = tail_alloc(size);
85 init_magic(page, size);
86
87 struct rtc_time *rt = tail_alloc(sizeof(*rt));
88 init_magic(rt, sizeof(*rt));
89
90 struct rtc_wkalrm *wk = tail_alloc(sizeof(*wk));
91 init_magic(wk, sizeof(*wk));
92
93 struct rtc_pll_info *pll = tail_alloc(sizeof(*pll));
94 init_magic(pll, sizeof(*pll));
95
96 /* RTC_ALM_READ */
97 ioctl(-1, RTC_ALM_READ, 0);
98 printf("ioctl(-1, RTC_ALM_READ, NULL) = -1 EBADF (%m)\n");
99
100 ioctl(-1, RTC_ALM_READ, page);
101 printf("ioctl(-1, RTC_ALM_READ, %p) = -1 EBADF (%m)\n", page);
102
103 /* RTC_RD_TIME */
104 ioctl(-1, RTC_RD_TIME, 0);
105 printf("ioctl(-1, RTC_RD_TIME, NULL) = -1 EBADF (%m)\n");
106
107 ioctl(-1, RTC_RD_TIME, page);
108 printf("ioctl(-1, RTC_RD_TIME, %p) = -1 EBADF (%m)\n", page);
109
110 /* RTC_ALM_SET */
111 ioctl(-1, RTC_ALM_SET, 0);
112 printf("ioctl(-1, RTC_ALM_SET, NULL) = -1 EBADF (%m)\n");
113
114 ioctl(-1, RTC_ALM_SET, rt);
115 printf("ioctl(-1, RTC_ALM_SET, ");
116 print_rtc_time(rt);
117 errno = EBADF;
118 printf(") = -1 EBADF (%m)\n");
119
120 /* RTC_SET_TIME */
121 ioctl(-1, RTC_SET_TIME, 0);
122 printf("ioctl(-1, RTC_SET_TIME, NULL) = -1 EBADF (%m)\n");
123
124 ioctl(-1, RTC_SET_TIME, rt);
125 printf("ioctl(-1, RTC_SET_TIME, ");
126 print_rtc_time(rt);
127 errno = EBADF;
128 printf(") = -1 EBADF (%m)\n");
129
130 /* RTC_IRQP_SET */
131 ioctl(-1, RTC_IRQP_SET, lmagic);
132 printf("ioctl(-1, RTC_IRQP_SET, %lu) = -1 EBADF (%m)\n", lmagic);
133
134 /* RTC_EPOCH_SET */
135 ioctl(-1, RTC_EPOCH_SET, lmagic);
136 printf("ioctl(-1, RTC_EPOCH_SET, %lu) = -1 EBADF (%m)\n", lmagic);
137
138 /* RTC_IRQP_READ */
139 ioctl(-1, RTC_IRQP_READ, 0);
140 printf("ioctl(-1, RTC_IRQP_READ, NULL) = -1 EBADF (%m)\n");
141
142 ioctl(-1, RTC_IRQP_READ, page);
143 printf("ioctl(-1, RTC_IRQP_READ, %p) = -1 EBADF (%m)\n", page);
144
145 /* RTC_EPOCH_READ */
146 ioctl(-1, RTC_EPOCH_READ, 0);
147 printf("ioctl(-1, RTC_EPOCH_READ, NULL) = -1 EBADF (%m)\n");
148
149 ioctl(-1, RTC_EPOCH_READ, page);
150 printf("ioctl(-1, RTC_EPOCH_READ, %p) = -1 EBADF (%m)\n", page);
151
152 /* RTC_WKALM_RD */
153 ioctl(-1, RTC_WKALM_RD, 0);
154 printf("ioctl(-1, RTC_WKALM_RD, NULL) = -1 EBADF (%m)\n");
155
156 ioctl(-1, RTC_WKALM_RD, page);
157 printf("ioctl(-1, RTC_WKALM_RD, %p) = -1 EBADF (%m)\n", page);
158
159 /* RTC_WKALM_SET */
160 ioctl(-1, RTC_WKALM_SET, 0);
161 printf("ioctl(-1, RTC_WKALM_SET, NULL) = -1 EBADF (%m)\n");
162
163 ioctl(-1, RTC_WKALM_SET, wk);
164 printf("ioctl(-1, RTC_WKALM_SET, {enabled=%u, pending=%u, time=",
165 (unsigned) wk->enabled, (unsigned) wk->pending);
166 print_rtc_time(&wk->time);
167 errno = EBADF;
168 printf("}) = -1 EBADF (%m)\n");
169
170 /* RTC_PLL_GET */
171 ioctl(-1, RTC_PLL_GET, 0);
172 printf("ioctl(-1, RTC_PLL_GET, NULL) = -1 EBADF (%m)\n");
173
174 ioctl(-1, RTC_PLL_GET, page);
175 printf("ioctl(-1, RTC_PLL_GET, %p) = -1 EBADF (%m)\n", page);
176
177 /* RTC_PLL_SET */
178 ioctl(-1, RTC_PLL_SET, 0);
179 printf("ioctl(-1, RTC_PLL_SET, NULL) = -1 EBADF (%m)\n");
180
181 ioctl(-1, RTC_PLL_SET, pll);
182 printf("ioctl(-1, RTC_PLL_SET, {pll_ctrl=%d, pll_value=%d"
183 ", pll_max=%d, pll_min=%d, pll_posmult=%d, pll_negmult=%d"
184 ", pll_clock=%ld}) = -1 EBADF (%m)\n",
185 pll->pll_ctrl, pll->pll_value, pll->pll_max, pll->pll_min,
186 pll->pll_posmult, pll->pll_negmult, pll->pll_clock);
187
188#ifdef RTC_VL_READ
189 /* RTC_VL_READ */
190 ioctl(-1, RTC_VL_READ, 0);
191 printf("ioctl(-1, RTC_VL_READ, NULL) = -1 EBADF (%m)\n");
192
193 ioctl(-1, RTC_VL_READ, page);
194 printf("ioctl(-1, RTC_VL_READ, %p) = -1 EBADF (%m)\n", page);
195#endif
196
197 unsigned int i;
198 for (i = 0; i < ARRAY_SIZE(rtc_argless); ++i) {
199 ioctl(-1, (unsigned long) rtc_argless[i].val, lmagic);
200 printf("ioctl(-1, %s) = -1 EBADF (%m)\n", rtc_argless[i].str);
201 }
202
203 ioctl(-1, RTC_UIE_OFF, lmagic);
204 printf("ioctl(-1, %s) = -1 EBADF (%m)\n", "PHN_NOT_OH or RTC_UIE_OFF");
205
206 ioctl(-1, RTC_AIE_ON, lmagic);
207#ifdef HPPA
208 printf("ioctl(-1, %s) = -1 EBADF (%m)\n", "PA_PERF_ON or RTC_AIE_ON");
209#else
210 printf("ioctl(-1, %s) = -1 EBADF (%m)\n", "RTC_AIE_ON");
211#endif
212
213 ioctl(-1, _IO(0x70, 0x40), lmagic);
214 printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n", "NVRAM_INIT", lmagic);
215
216 puts("+++ exited with 0 +++");
217 return 0;
218}