1 /* 2 * This file is part of ioctl_rtc strace test. 3 * 4 * Copyright (c) 2016 Dmitry V. Levin <ldv (at) 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 39 static const unsigned long lmagic = (unsigned long) 0xdeadbeefbadc0dedULL; 40 41 static void 42 print_rtc_time(const struct rtc_time *rt) 43 { 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); 48 #if VERBOSE 49 printf(", tm_wday=%d, tm_yday=%d, tm_isdst=%d}", 50 rt->tm_wday, rt->tm_yday, rt->tm_isdst); 51 #else 52 printf(", ...}"); 53 #endif 54 } 55 56 static struct xlat rtc_argless[] = { 57 XLAT(RTC_AIE_OFF), 58 XLAT(RTC_PIE_ON), 59 XLAT(RTC_PIE_OFF), 60 XLAT(RTC_UIE_ON), 61 XLAT(RTC_WIE_ON), 62 XLAT(RTC_WIE_OFF), 63 #ifdef RTC_VL_CLR 64 XLAT(RTC_VL_CLR), 65 #endif 66 }; 67 68 int 69 main(void) 70 { 71 const unsigned int size = get_page_size(); 72 73 void *const page = tail_alloc(size); 74 fill_memory(page, size); 75 76 struct rtc_time *rt = tail_alloc(sizeof(*rt)); 77 fill_memory(rt, sizeof(*rt)); 78 79 struct rtc_wkalrm *wk = tail_alloc(sizeof(*wk)); 80 fill_memory(wk, sizeof(*wk)); 81 82 struct rtc_pll_info *pll = tail_alloc(sizeof(*pll)); 83 fill_memory(pll, sizeof(*pll)); 84 85 /* RTC_ALM_READ */ 86 ioctl(-1, RTC_ALM_READ, 0); 87 printf("ioctl(-1, RTC_ALM_READ, NULL) = -1 EBADF (%m)\n"); 88 89 ioctl(-1, RTC_ALM_READ, page); 90 printf("ioctl(-1, RTC_ALM_READ, %p) = -1 EBADF (%m)\n", page); 91 92 /* RTC_RD_TIME */ 93 ioctl(-1, RTC_RD_TIME, 0); 94 printf("ioctl(-1, RTC_RD_TIME, NULL) = -1 EBADF (%m)\n"); 95 96 ioctl(-1, RTC_RD_TIME, page); 97 printf("ioctl(-1, RTC_RD_TIME, %p) = -1 EBADF (%m)\n", page); 98 99 /* RTC_ALM_SET */ 100 ioctl(-1, RTC_ALM_SET, 0); 101 printf("ioctl(-1, RTC_ALM_SET, NULL) = -1 EBADF (%m)\n"); 102 103 ioctl(-1, RTC_ALM_SET, rt); 104 printf("ioctl(-1, RTC_ALM_SET, "); 105 print_rtc_time(rt); 106 errno = EBADF; 107 printf(") = -1 EBADF (%m)\n"); 108 109 /* RTC_SET_TIME */ 110 ioctl(-1, RTC_SET_TIME, 0); 111 printf("ioctl(-1, RTC_SET_TIME, NULL) = -1 EBADF (%m)\n"); 112 113 ioctl(-1, RTC_SET_TIME, rt); 114 printf("ioctl(-1, RTC_SET_TIME, "); 115 print_rtc_time(rt); 116 errno = EBADF; 117 printf(") = -1 EBADF (%m)\n"); 118 119 /* RTC_IRQP_SET */ 120 ioctl(-1, RTC_IRQP_SET, lmagic); 121 printf("ioctl(-1, RTC_IRQP_SET, %lu) = -1 EBADF (%m)\n", lmagic); 122 123 /* RTC_EPOCH_SET */ 124 ioctl(-1, RTC_EPOCH_SET, lmagic); 125 printf("ioctl(-1, RTC_EPOCH_SET, %lu) = -1 EBADF (%m)\n", lmagic); 126 127 /* RTC_IRQP_READ */ 128 ioctl(-1, RTC_IRQP_READ, 0); 129 printf("ioctl(-1, RTC_IRQP_READ, NULL) = -1 EBADF (%m)\n"); 130 131 ioctl(-1, RTC_IRQP_READ, page); 132 printf("ioctl(-1, RTC_IRQP_READ, %p) = -1 EBADF (%m)\n", page); 133 134 /* RTC_EPOCH_READ */ 135 ioctl(-1, RTC_EPOCH_READ, 0); 136 printf("ioctl(-1, RTC_EPOCH_READ, NULL) = -1 EBADF (%m)\n"); 137 138 ioctl(-1, RTC_EPOCH_READ, page); 139 printf("ioctl(-1, RTC_EPOCH_READ, %p) = -1 EBADF (%m)\n", page); 140 141 /* RTC_WKALM_RD */ 142 ioctl(-1, RTC_WKALM_RD, 0); 143 printf("ioctl(-1, RTC_WKALM_RD, NULL) = -1 EBADF (%m)\n"); 144 145 ioctl(-1, RTC_WKALM_RD, page); 146 printf("ioctl(-1, RTC_WKALM_RD, %p) = -1 EBADF (%m)\n", page); 147 148 /* RTC_WKALM_SET */ 149 ioctl(-1, RTC_WKALM_SET, 0); 150 printf("ioctl(-1, RTC_WKALM_SET, NULL) = -1 EBADF (%m)\n"); 151 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); 156 errno = EBADF; 157 printf("}) = -1 EBADF (%m)\n"); 158 159 /* RTC_PLL_GET */ 160 ioctl(-1, RTC_PLL_GET, 0); 161 printf("ioctl(-1, RTC_PLL_GET, NULL) = -1 EBADF (%m)\n"); 162 163 ioctl(-1, RTC_PLL_GET, page); 164 printf("ioctl(-1, RTC_PLL_GET, %p) = -1 EBADF (%m)\n", page); 165 166 /* RTC_PLL_SET */ 167 ioctl(-1, RTC_PLL_SET, 0); 168 printf("ioctl(-1, RTC_PLL_SET, NULL) = -1 EBADF (%m)\n"); 169 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); 176 177 #ifdef RTC_VL_READ 178 /* RTC_VL_READ */ 179 ioctl(-1, RTC_VL_READ, 0); 180 printf("ioctl(-1, RTC_VL_READ, NULL) = -1 EBADF (%m)\n"); 181 182 ioctl(-1, RTC_VL_READ, page); 183 printf("ioctl(-1, RTC_VL_READ, %p) = -1 EBADF (%m)\n", page); 184 #endif 185 186 unsigned int i; 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); 190 } 191 192 ioctl(-1, RTC_UIE_OFF, lmagic); 193 printf("ioctl(-1, %s) = -1 EBADF (%m)\n", "PHN_NOT_OH or RTC_UIE_OFF"); 194 195 ioctl(-1, RTC_AIE_ON, lmagic); 196 #ifdef HPPA 197 printf("ioctl(-1, %s) = -1 EBADF (%m)\n", "PA_PERF_ON or RTC_AIE_ON"); 198 #else 199 printf("ioctl(-1, %s) = -1 EBADF (%m)\n", "RTC_AIE_ON"); 200 #endif 201 202 ioctl(-1, _IO(0x70, 0x40), lmagic); 203 printf("ioctl(-1, %s, %#lx) = -1 EBADF (%m)\n", "NVRAM_INIT", lmagic); 204 205 puts("+++ exited with 0 +++"); 206 return 0; 207 } 208