2 * This file is part of ioctl_rtc strace test.
4 * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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.
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.
34 #include <sys/ioctl.h>
35 #include <linux/types.h>
36 #include <linux/rtc.h>
39 static const unsigned long lmagic = (unsigned long) 0xdeadbeefbadc0dedULL;
42 print_rtc_time(const struct rtc_time *rt)
44 printf("{tm_sec=%d, tm_min=%d, tm_hour=%d"
45 ", tm_mday=%d, tm_mon=%d, tm_year=%d",
46 rt->tm_sec, rt->tm_min, rt->tm_hour,
47 rt->tm_mday, rt->tm_mon, rt->tm_year);
49 printf(", tm_wday=%d, tm_yday=%d, tm_isdst=%d}",
50 rt->tm_wday, rt->tm_yday, rt->tm_isdst);
56 static struct xlat rtc_argless[] = {
71 const unsigned int size = get_page_size();
73 void *const page = tail_alloc(size);
74 fill_memory(page, size);
76 TAIL_ALLOC_OBJECT_CONST_PTR(struct rtc_time, rt);
77 fill_memory(rt, sizeof(*rt));
79 TAIL_ALLOC_OBJECT_CONST_PTR(struct rtc_wkalrm, wk);
80 fill_memory(wk, sizeof(*wk));
82 TAIL_ALLOC_OBJECT_CONST_PTR(struct rtc_pll_info, pll);
83 fill_memory(pll, sizeof(*pll));
86 ioctl(-1, RTC_ALM_READ, 0);
87 printf("ioctl(-1, RTC_ALM_READ, NULL) = -1 EBADF (%m)\n");
89 ioctl(-1, RTC_ALM_READ, page);
90 printf("ioctl(-1, RTC_ALM_READ, %p) = -1 EBADF (%m)\n", page);
93 ioctl(-1, RTC_RD_TIME, 0);
94 printf("ioctl(-1, RTC_RD_TIME, NULL) = -1 EBADF (%m)\n");
96 ioctl(-1, RTC_RD_TIME, page);
97 printf("ioctl(-1, RTC_RD_TIME, %p) = -1 EBADF (%m)\n", page);
100 ioctl(-1, RTC_ALM_SET, 0);
101 printf("ioctl(-1, RTC_ALM_SET, NULL) = -1 EBADF (%m)\n");
103 ioctl(-1, RTC_ALM_SET, rt);
104 printf("ioctl(-1, RTC_ALM_SET, ");
107 printf(") = -1 EBADF (%m)\n");
110 ioctl(-1, RTC_SET_TIME, 0);
111 printf("ioctl(-1, RTC_SET_TIME, NULL) = -1 EBADF (%m)\n");
113 ioctl(-1, RTC_SET_TIME, rt);
114 printf("ioctl(-1, RTC_SET_TIME, ");
117 printf(") = -1 EBADF (%m)\n");
120 ioctl(-1, RTC_IRQP_SET, lmagic);
121 printf("ioctl(-1, RTC_IRQP_SET, %lu) = -1 EBADF (%m)\n", lmagic);
124 ioctl(-1, RTC_EPOCH_SET, lmagic);
125 printf("ioctl(-1, RTC_EPOCH_SET, %lu) = -1 EBADF (%m)\n", lmagic);
128 ioctl(-1, RTC_IRQP_READ, 0);
129 printf("ioctl(-1, RTC_IRQP_READ, NULL) = -1 EBADF (%m)\n");
131 ioctl(-1, RTC_IRQP_READ, page);
132 printf("ioctl(-1, RTC_IRQP_READ, %p) = -1 EBADF (%m)\n", page);
135 ioctl(-1, RTC_EPOCH_READ, 0);
136 printf("ioctl(-1, RTC_EPOCH_READ, NULL) = -1 EBADF (%m)\n");
138 ioctl(-1, RTC_EPOCH_READ, page);
139 printf("ioctl(-1, RTC_EPOCH_READ, %p) = -1 EBADF (%m)\n", page);
142 ioctl(-1, RTC_WKALM_RD, 0);
143 printf("ioctl(-1, RTC_WKALM_RD, NULL) = -1 EBADF (%m)\n");
145 ioctl(-1, RTC_WKALM_RD, page);
146 printf("ioctl(-1, RTC_WKALM_RD, %p) = -1 EBADF (%m)\n", page);
149 ioctl(-1, RTC_WKALM_SET, 0);
150 printf("ioctl(-1, RTC_WKALM_SET, NULL) = -1 EBADF (%m)\n");
152 ioctl(-1, RTC_WKALM_SET, wk);
153 printf("ioctl(-1, RTC_WKALM_SET, {enabled=%u, pending=%u, time=",
154 (unsigned) wk->enabled, (unsigned) wk->pending);
155 print_rtc_time(&wk->time);
157 printf("}) = -1 EBADF (%m)\n");
160 ioctl(-1, RTC_PLL_GET, 0);
161 printf("ioctl(-1, RTC_PLL_GET, NULL) = -1 EBADF (%m)\n");
163 ioctl(-1, RTC_PLL_GET, page);
164 printf("ioctl(-1, RTC_PLL_GET, %p) = -1 EBADF (%m)\n", page);
167 ioctl(-1, RTC_PLL_SET, 0);
168 printf("ioctl(-1, RTC_PLL_SET, NULL) = -1 EBADF (%m)\n");
170 ioctl(-1, RTC_PLL_SET, pll);
171 printf("ioctl(-1, RTC_PLL_SET, {pll_ctrl=%d, pll_value=%d"
172 ", pll_max=%d, pll_min=%d, pll_posmult=%d, pll_negmult=%d"
173 ", pll_clock=%ld}) = -1 EBADF (%m)\n",
174 pll->pll_ctrl, pll->pll_value, pll->pll_max, pll->pll_min,
175 pll->pll_posmult, pll->pll_negmult, pll->pll_clock);
179 ioctl(-1, RTC_VL_READ, 0);
180 printf("ioctl(-1, RTC_VL_READ, NULL) = -1 EBADF (%m)\n");
182 ioctl(-1, RTC_VL_READ, page);
183 printf("ioctl(-1, RTC_VL_READ, %p) = -1 EBADF (%m)\n", page);
187 for (i = 0; i < ARRAY_SIZE(rtc_argless); ++i) {
188 ioctl(-1, (unsigned long) rtc_argless[i].val, lmagic);
189 printf("ioctl(-1, %s) = -1 EBADF (%m)\n", rtc_argless[i].str);
192 ioctl(-1, RTC_UIE_OFF, lmagic);
193 printf("ioctl(-1, %s) = -1 EBADF (%m)\n", "PHN_NOT_OH or RTC_UIE_OFF");
195 ioctl(-1, RTC_AIE_ON, lmagic);
197 printf("ioctl(-1, %s) = -1 EBADF (%m)\n", "PA_PERF_ON or RTC_AIE_ON");
199 printf("ioctl(-1, %s) = -1 EBADF (%m)\n", "RTC_AIE_ON");
202 ioctl(-1, _IO(0x70, 0x40), lmagic);
203 printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n", "NVRAM_INIT", lmagic);
205 puts("+++ exited with 0 +++");