t_ufetchstore.c revision 1.2 1 1.2 rin /* $NetBSD: t_ufetchstore.c,v 1.2 2019/04/07 03:35:25 rin Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*
4 1.1 thorpej * Copyright (c) 2019 The NetBSD Foundation, Inc.
5 1.1 thorpej * All rights reserved.
6 1.1 thorpej *
7 1.1 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.1 thorpej * by Jason R. Thorpe.
9 1.1 thorpej *
10 1.1 thorpej * Redistribution and use in source and binary forms, with or without
11 1.1 thorpej * modification, are permitted provided that the following conditions
12 1.1 thorpej * are met:
13 1.1 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.1 thorpej * notice, this list of conditions and the following disclaimer.
15 1.1 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.1 thorpej * documentation and/or other materials provided with the distribution.
18 1.1 thorpej *
19 1.1 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 thorpej * POSSIBILITY OF SUCH DAMAGE.
30 1.1 thorpej */
31 1.1 thorpej
32 1.1 thorpej #include <sys/cdefs.h>
33 1.1 thorpej __COPYRIGHT("@(#) Copyright (c) 2019\
34 1.1 thorpej The NetBSD Foundation, inc. All rights reserved.");
35 1.2 rin __RCSID("$NetBSD: t_ufetchstore.c,v 1.2 2019/04/07 03:35:25 rin Exp $");
36 1.1 thorpej
37 1.1 thorpej #include <sys/types.h>
38 1.1 thorpej #include <sys/endian.h>
39 1.1 thorpej #include <sys/module.h>
40 1.1 thorpej #include <sys/sysctl.h>
41 1.1 thorpej
42 1.1 thorpej #include <err.h>
43 1.1 thorpej #include <errno.h>
44 1.1 thorpej #include <limits.h>
45 1.1 thorpej
46 1.1 thorpej #include <atf-c.h>
47 1.1 thorpej
48 1.1 thorpej #include "common.h"
49 1.1 thorpej
50 1.1 thorpej #define mib_name "kern.ufetchstore_test.test"
51 1.1 thorpej
52 1.1 thorpej static bool module_loaded;
53 1.1 thorpej
54 1.1 thorpej #define MODULE_PATH \
55 1.1 thorpej "/usr/tests/modules/ufetchstore_tester/ufetchstore_tester.kmod"
56 1.1 thorpej #define MODULE_NAME "ufetchstore_tester"
57 1.1 thorpej
58 1.1 thorpej #define CHECK_MODULE() \
59 1.1 thorpej do { \
60 1.1 thorpej load_module(); \
61 1.1 thorpej if (! module_loaded) { \
62 1.1 thorpej atf_tc_skip("loading '%s' module failed.", MODULE_NAME);\
63 1.1 thorpej } \
64 1.1 thorpej } while (/*CONSTCOND*/0)
65 1.1 thorpej
66 1.1 thorpej static void
67 1.1 thorpej load_module(void)
68 1.1 thorpej {
69 1.1 thorpej #ifndef SKIP_MODULE
70 1.1 thorpej if (module_loaded)
71 1.1 thorpej return;
72 1.1 thorpej
73 1.1 thorpej modctl_load_t params = {
74 1.1 thorpej .ml_filename = MODULE_PATH,
75 1.1 thorpej .ml_flags = MODCTL_NO_PROP,
76 1.1 thorpej };
77 1.1 thorpej
78 1.1 thorpej if (modctl(MODCTL_LOAD, ¶ms) != 0) {
79 1.1 thorpej warn("failed to load module '%s'", MODULE_PATH);
80 1.1 thorpej } else {
81 1.1 thorpej module_loaded = true;
82 1.1 thorpej }
83 1.1 thorpej #else
84 1.1 thorpej module_loaded = true;
85 1.1 thorpej #endif /* ! SKIP_MODULE */
86 1.1 thorpej }
87 1.1 thorpej
88 1.2 rin #define UADDR64(x) ((uintptr_t)(x))
89 1.1 thorpej
90 1.1 thorpej static void
91 1.1 thorpej unload_module(void)
92 1.1 thorpej {
93 1.1 thorpej #ifndef SKIP_MODULE
94 1.1 thorpej char module_name[] = MODULE_NAME;
95 1.1 thorpej
96 1.1 thorpej if (modctl(MODCTL_UNLOAD, module_name) != 0) {
97 1.1 thorpej warn("failed to unload module '%s'", MODULE_NAME);
98 1.1 thorpej } else {
99 1.1 thorpej module_loaded = false;
100 1.1 thorpej }
101 1.1 thorpej #endif /* ! SKIP_MODULE */
102 1.1 thorpej }
103 1.1 thorpej
104 1.1 thorpej static void *
105 1.1 thorpej vm_max_address(void)
106 1.1 thorpej {
107 1.1 thorpej static unsigned long max_addr = 0;
108 1.1 thorpej int rv;
109 1.1 thorpej
110 1.1 thorpej if (max_addr == 0) {
111 1.1 thorpej size_t max_addr_size = sizeof(max_addr);
112 1.1 thorpej rv = sysctlbyname("vm.maxaddress", &max_addr, &max_addr_size,
113 1.1 thorpej NULL, 0);
114 1.1 thorpej if (rv != 0)
115 1.1 thorpej err(1, "sysctlbyname('vm.maxaddress')");
116 1.1 thorpej }
117 1.1 thorpej return (void *)max_addr;
118 1.1 thorpej }
119 1.1 thorpej
120 1.1 thorpej static int
121 1.1 thorpej do_sysctl(struct ufetchstore_test_args *args)
122 1.1 thorpej {
123 1.1 thorpej uint64_t arg_addr64 = (uintptr_t)args;
124 1.1 thorpej int rv;
125 1.1 thorpej
126 1.1 thorpej args->fetchstore_error = EBADF; /* poison */
127 1.1 thorpej args->pointer_size = (int)sizeof(void *);
128 1.1 thorpej
129 1.1 thorpej /*
130 1.1 thorpej * Yes, the intent is to provide the pointer, not the structure,
131 1.1 thorpej * to the kernel side of the test harness.
132 1.1 thorpej */
133 1.1 thorpej rv = sysctlbyname(mib_name, NULL, NULL, &arg_addr64,
134 1.1 thorpej sizeof(arg_addr64));
135 1.1 thorpej if (rv != 0) {
136 1.1 thorpej rv = errno;
137 1.1 thorpej warn("sysctlbyname('%s') -> %d", mib_name, rv);
138 1.1 thorpej return rv;
139 1.1 thorpej }
140 1.1 thorpej return 0;
141 1.1 thorpej }
142 1.1 thorpej
143 1.1 thorpej static int
144 1.1 thorpej do_ufetch_8(const uint8_t *uaddr, uint8_t *res)
145 1.1 thorpej {
146 1.1 thorpej struct ufetchstore_test_args args = {
147 1.2 rin .uaddr64 = UADDR64(uaddr),
148 1.1 thorpej .test_op = OP_LOAD,
149 1.1 thorpej .size = 8,
150 1.1 thorpej };
151 1.1 thorpej
152 1.1 thorpej ATF_REQUIRE_EQ(do_sysctl(&args), 0);
153 1.1 thorpej *res = args.val8;
154 1.1 thorpej return args.fetchstore_error;
155 1.1 thorpej }
156 1.1 thorpej
157 1.1 thorpej static int
158 1.1 thorpej do_ufetch_16(const uint16_t *uaddr, uint16_t *res)
159 1.1 thorpej {
160 1.1 thorpej struct ufetchstore_test_args args = {
161 1.2 rin .uaddr64 = UADDR64(uaddr),
162 1.1 thorpej .test_op = OP_LOAD,
163 1.1 thorpej .size = 16,
164 1.1 thorpej };
165 1.1 thorpej
166 1.1 thorpej ATF_REQUIRE_EQ(do_sysctl(&args), 0);
167 1.1 thorpej *res = args.val16;
168 1.1 thorpej return args.fetchstore_error;
169 1.1 thorpej }
170 1.1 thorpej
171 1.1 thorpej static int
172 1.1 thorpej do_ufetch_32(const uint32_t *uaddr, uint32_t *res)
173 1.1 thorpej {
174 1.1 thorpej struct ufetchstore_test_args args = {
175 1.2 rin .uaddr64 = UADDR64(uaddr),
176 1.1 thorpej .test_op = OP_LOAD,
177 1.1 thorpej .size = 32,
178 1.1 thorpej };
179 1.1 thorpej
180 1.1 thorpej ATF_REQUIRE_EQ(do_sysctl(&args), 0);
181 1.1 thorpej *res = args.val32;
182 1.1 thorpej return args.fetchstore_error;
183 1.1 thorpej }
184 1.1 thorpej
185 1.1 thorpej #ifdef _LP64
186 1.1 thorpej static int
187 1.1 thorpej do_ufetch_64(const uint64_t *uaddr, uint64_t *res)
188 1.1 thorpej {
189 1.1 thorpej struct ufetchstore_test_args args = {
190 1.2 rin .uaddr64 = UADDR64(uaddr),
191 1.1 thorpej .test_op = OP_LOAD,
192 1.1 thorpej .size = 64,
193 1.1 thorpej };
194 1.1 thorpej
195 1.1 thorpej ATF_REQUIRE_EQ(do_sysctl(&args), 0);
196 1.1 thorpej *res = args.val64;
197 1.1 thorpej return args.fetchstore_error;
198 1.1 thorpej }
199 1.1 thorpej #endif /* _LP64 */
200 1.1 thorpej
201 1.1 thorpej static int
202 1.1 thorpej do_ustore_8(uint8_t *uaddr, uint8_t val)
203 1.1 thorpej {
204 1.1 thorpej struct ufetchstore_test_args args = {
205 1.2 rin .uaddr64 = UADDR64(uaddr),
206 1.1 thorpej .test_op = OP_STORE,
207 1.1 thorpej .size = 8,
208 1.1 thorpej .val8 = val,
209 1.1 thorpej };
210 1.1 thorpej
211 1.1 thorpej ATF_REQUIRE_EQ(do_sysctl(&args), 0);
212 1.1 thorpej return args.fetchstore_error;
213 1.1 thorpej }
214 1.1 thorpej
215 1.1 thorpej static int
216 1.1 thorpej do_ustore_16(uint16_t *uaddr, uint16_t val)
217 1.1 thorpej {
218 1.1 thorpej struct ufetchstore_test_args args = {
219 1.2 rin .uaddr64 = UADDR64(uaddr),
220 1.1 thorpej .test_op = OP_STORE,
221 1.1 thorpej .size = 16,
222 1.1 thorpej .val16 = val,
223 1.1 thorpej };
224 1.1 thorpej
225 1.1 thorpej ATF_REQUIRE_EQ(do_sysctl(&args), 0);
226 1.1 thorpej return args.fetchstore_error;
227 1.1 thorpej }
228 1.1 thorpej
229 1.1 thorpej static int
230 1.1 thorpej do_ustore_32(uint32_t *uaddr, uint32_t val)
231 1.1 thorpej {
232 1.1 thorpej struct ufetchstore_test_args args = {
233 1.2 rin .uaddr64 = UADDR64(uaddr),
234 1.1 thorpej .test_op = OP_STORE,
235 1.1 thorpej .size = 32,
236 1.1 thorpej .val32 = val,
237 1.1 thorpej };
238 1.1 thorpej
239 1.1 thorpej ATF_REQUIRE_EQ(do_sysctl(&args), 0);
240 1.1 thorpej return args.fetchstore_error;
241 1.1 thorpej }
242 1.1 thorpej
243 1.1 thorpej #ifdef _LP64
244 1.1 thorpej static int
245 1.1 thorpej do_ustore_64(uint64_t *uaddr, uint64_t val)
246 1.1 thorpej {
247 1.1 thorpej struct ufetchstore_test_args args = {
248 1.2 rin .uaddr64 = UADDR64(uaddr),
249 1.1 thorpej .test_op = OP_STORE,
250 1.1 thorpej .size = 64,
251 1.1 thorpej .val64 = val,
252 1.1 thorpej };
253 1.1 thorpej
254 1.1 thorpej ATF_REQUIRE_EQ(do_sysctl(&args), 0);
255 1.1 thorpej return args.fetchstore_error;
256 1.1 thorpej }
257 1.1 thorpej #endif /* _LP64 */
258 1.1 thorpej
259 1.1 thorpej static int
260 1.1 thorpej do_ucas_32(uint32_t *uaddr, uint32_t expected, uint32_t new, uint32_t *actualp)
261 1.1 thorpej {
262 1.1 thorpej struct ufetchstore_test_args args = {
263 1.2 rin .uaddr64 = UADDR64(uaddr),
264 1.1 thorpej .test_op = OP_CAS,
265 1.1 thorpej .size = 32,
266 1.1 thorpej .val32 = new,
267 1.1 thorpej .ea_val32 = expected,
268 1.1 thorpej };
269 1.1 thorpej
270 1.1 thorpej ATF_REQUIRE_EQ(do_sysctl(&args), 0);
271 1.1 thorpej *actualp = args.ea_val32;
272 1.1 thorpej return args.fetchstore_error;
273 1.1 thorpej }
274 1.1 thorpej
275 1.1 thorpej #ifdef _LP64
276 1.1 thorpej static int
277 1.1 thorpej do_ucas_64(uint64_t *uaddr, uint64_t expected, uint64_t new, uint64_t *actualp)
278 1.1 thorpej {
279 1.1 thorpej struct ufetchstore_test_args args = {
280 1.2 rin .uaddr64 = UADDR64(uaddr),
281 1.1 thorpej .test_op = OP_CAS,
282 1.1 thorpej .size = 64,
283 1.1 thorpej .val64 = new,
284 1.1 thorpej .ea_val64 = expected,
285 1.1 thorpej };
286 1.1 thorpej
287 1.1 thorpej ATF_REQUIRE_EQ(do_sysctl(&args), 0);
288 1.1 thorpej *actualp = args.ea_val64;
289 1.1 thorpej return args.fetchstore_error;
290 1.1 thorpej }
291 1.1 thorpej #endif /* _LP64 */
292 1.1 thorpej
293 1.1 thorpej struct memory_cell {
294 1.1 thorpej unsigned long guard0;
295 1.1 thorpej union {
296 1.1 thorpej unsigned long test_cell;
297 1.1 thorpej #ifdef _LP64
298 1.1 thorpej uint64_t val64;
299 1.1 thorpej #endif
300 1.1 thorpej uint32_t val32[sizeof(long) / 4];
301 1.1 thorpej uint16_t val16[sizeof(long) / 2];
302 1.1 thorpej uint8_t val8 [sizeof(long) ];
303 1.1 thorpej };
304 1.1 thorpej unsigned long guard1;
305 1.1 thorpej };
306 1.1 thorpej
307 1.1 thorpej #define index8 1
308 1.1 thorpej #define index16 1
309 1.1 thorpej #define index32 0
310 1.1 thorpej
311 1.1 thorpej #define test_pattern8 0xa5
312 1.1 thorpej #define test_pattern16 0x5a6b
313 1.1 thorpej #define test_pattern32 0xb01cafe1
314 1.1 thorpej #ifdef _LP64
315 1.1 thorpej #define test_pattern64 0xcafedeadfeedbabe
316 1.1 thorpej #endif
317 1.1 thorpej
318 1.1 thorpej #if _BYTE_ORDER == _LITTLE_ENDIAN
319 1.1 thorpej #define test_cell_val8 ((unsigned long)test_pattern8 << (index8 * NBBY))
320 1.1 thorpej #define test_cell_val16 ((unsigned long)test_pattern16 << (index16 * NBBY*2))
321 1.1 thorpej #define test_cell_val32 ((unsigned long)test_pattern32 << (index32 * NBBY*4))
322 1.1 thorpej #ifdef _LP64
323 1.1 thorpej #define test_cell_val64 ((unsigned long)test_pattern64)
324 1.1 thorpej #endif
325 1.1 thorpej #endif /* _BYTE_ORDER == _LITTLE_ENDIAN */
326 1.1 thorpej
327 1.1 thorpej #if _BYTE_ORDER == _BIG_ENDIAN
328 1.1 thorpej #ifdef _LP64
329 1.1 thorpej #define test_cell_val8 ((unsigned long)test_pattern8 << (56-(index8 * NBBY)))
330 1.1 thorpej #define test_cell_val16 ((unsigned long)test_pattern16 << (48-(index16 * NBBY*2)))
331 1.1 thorpej #define test_cell_val32 ((unsigned long)test_pattern32 << (32-(index32 * NBBY*4)))
332 1.1 thorpej #define test_cell_val64 ((unsigned long)test_pattern64)
333 1.1 thorpej #else /* ! _LP64 */
334 1.1 thorpej #define test_cell_val8 ((unsigned long)test_pattern8 << (24-(index8 * NBBY)))
335 1.1 thorpej #define test_cell_val16 ((unsigned long)test_pattern16 << (16-(index16 * NBBY*2)))
336 1.1 thorpej #define test_cell_val32 ((unsigned long)test_pattern32)
337 1.1 thorpej #endif /* _LP64 */
338 1.1 thorpej #endif /* #if _BYTE_ORDER == _BIG_ENDIAN */
339 1.1 thorpej
340 1.1 thorpej #define read_test_cell(cell) (cell)->test_cell
341 1.1 thorpej #define write_test_cell(cell, v) (cell)->test_cell = (v)
342 1.1 thorpej
343 1.1 thorpej #define memory_cell_initializer \
344 1.1 thorpej { \
345 1.1 thorpej .guard0 = ULONG_MAX, \
346 1.1 thorpej .test_cell = 0, \
347 1.1 thorpej .guard1 = ULONG_MAX, \
348 1.1 thorpej }
349 1.1 thorpej
350 1.1 thorpej static bool
351 1.1 thorpej memory_cell_check_guard(const struct memory_cell * const cell)
352 1.1 thorpej {
353 1.1 thorpej return cell->guard0 == ULONG_MAX &&
354 1.1 thorpej cell->guard1 == ULONG_MAX;
355 1.1 thorpej }
356 1.1 thorpej
357 1.1 thorpej ATF_TC_WITH_CLEANUP(ufetch_8);
358 1.1 thorpej ATF_TC_HEAD(ufetch_8, tc)
359 1.1 thorpej {
360 1.1 thorpej atf_tc_set_md_var(tc, "descr",
361 1.1 thorpej "test for correct ufetch_8 behavior");
362 1.1 thorpej }
363 1.1 thorpej ATF_TC_BODY(ufetch_8, tc)
364 1.1 thorpej {
365 1.1 thorpej struct memory_cell cell = memory_cell_initializer;
366 1.1 thorpej uint8_t res;
367 1.1 thorpej
368 1.1 thorpej CHECK_MODULE();
369 1.1 thorpej
370 1.1 thorpej write_test_cell(&cell, test_cell_val8);
371 1.1 thorpej ATF_REQUIRE_EQ(do_ufetch_8(&cell.val8[index8], &res), 0);
372 1.1 thorpej ATF_REQUIRE(memory_cell_check_guard(&cell));
373 1.1 thorpej ATF_REQUIRE(res == test_pattern8);
374 1.1 thorpej }
375 1.1 thorpej ATF_TC_CLEANUP(ufetch_8, tc)
376 1.1 thorpej {
377 1.1 thorpej unload_module();
378 1.1 thorpej }
379 1.1 thorpej
380 1.1 thorpej ATF_TC_WITH_CLEANUP(ufetch_16);
381 1.1 thorpej ATF_TC_HEAD(ufetch_16, tc)
382 1.1 thorpej {
383 1.1 thorpej atf_tc_set_md_var(tc, "descr",
384 1.1 thorpej "test for correct ufetch_16 behavior");
385 1.1 thorpej }
386 1.1 thorpej ATF_TC_BODY(ufetch_16, tc)
387 1.1 thorpej {
388 1.1 thorpej struct memory_cell cell = memory_cell_initializer;
389 1.1 thorpej uint16_t res;
390 1.1 thorpej
391 1.1 thorpej CHECK_MODULE();
392 1.1 thorpej
393 1.1 thorpej write_test_cell(&cell, test_cell_val16);
394 1.1 thorpej ATF_REQUIRE_EQ(do_ufetch_16(&cell.val16[index16], &res), 0);
395 1.1 thorpej ATF_REQUIRE(memory_cell_check_guard(&cell));
396 1.1 thorpej ATF_REQUIRE(res == test_pattern16);
397 1.1 thorpej }
398 1.1 thorpej ATF_TC_CLEANUP(ufetch_16, tc)
399 1.1 thorpej {
400 1.1 thorpej unload_module();
401 1.1 thorpej }
402 1.1 thorpej
403 1.1 thorpej ATF_TC_WITH_CLEANUP(ufetch_32);
404 1.1 thorpej ATF_TC_HEAD(ufetch_32, tc)
405 1.1 thorpej {
406 1.1 thorpej atf_tc_set_md_var(tc, "descr",
407 1.1 thorpej "test for correct ufetch_32 behavior");
408 1.1 thorpej }
409 1.1 thorpej ATF_TC_BODY(ufetch_32, tc)
410 1.1 thorpej {
411 1.1 thorpej struct memory_cell cell = memory_cell_initializer;
412 1.1 thorpej uint32_t res;
413 1.1 thorpej
414 1.1 thorpej CHECK_MODULE();
415 1.1 thorpej
416 1.1 thorpej write_test_cell(&cell, test_cell_val32);
417 1.1 thorpej ATF_REQUIRE_EQ(do_ufetch_32(&cell.val32[index32], &res), 0);
418 1.1 thorpej ATF_REQUIRE(memory_cell_check_guard(&cell));
419 1.1 thorpej ATF_REQUIRE(res == test_pattern32);
420 1.1 thorpej }
421 1.1 thorpej ATF_TC_CLEANUP(ufetch_32, tc)
422 1.1 thorpej {
423 1.1 thorpej unload_module();
424 1.1 thorpej }
425 1.1 thorpej
426 1.1 thorpej #ifdef _LP64
427 1.1 thorpej ATF_TC_WITH_CLEANUP(ufetch_64);
428 1.1 thorpej ATF_TC_HEAD(ufetch_64, tc)
429 1.1 thorpej {
430 1.1 thorpej atf_tc_set_md_var(tc, "descr",
431 1.1 thorpej "test for correct ufetch_64 behavior");
432 1.1 thorpej }
433 1.1 thorpej ATF_TC_BODY(ufetch_64, tc)
434 1.1 thorpej {
435 1.1 thorpej struct memory_cell cell = memory_cell_initializer;
436 1.1 thorpej uint64_t res;
437 1.1 thorpej
438 1.1 thorpej CHECK_MODULE();
439 1.1 thorpej
440 1.1 thorpej write_test_cell(&cell, test_cell_val64);
441 1.1 thorpej ATF_REQUIRE_EQ(do_ufetch_64(&cell.val64, &res), 0);
442 1.1 thorpej ATF_REQUIRE(memory_cell_check_guard(&cell));
443 1.1 thorpej ATF_REQUIRE(res == test_pattern64);
444 1.1 thorpej }
445 1.1 thorpej ATF_TC_CLEANUP(ufetch_64, tc)
446 1.1 thorpej {
447 1.1 thorpej unload_module();
448 1.1 thorpej }
449 1.1 thorpej #endif /* _LP64 */
450 1.1 thorpej
451 1.1 thorpej ATF_TC_WITH_CLEANUP(ufetch_8_null);
452 1.1 thorpej ATF_TC_HEAD(ufetch_8_null, tc)
453 1.1 thorpej {
454 1.1 thorpej atf_tc_set_md_var(tc, "descr",
455 1.1 thorpej "test for correct ufetch_8 NULL pointer behavior");
456 1.1 thorpej }
457 1.1 thorpej ATF_TC_BODY(ufetch_8_null, tc)
458 1.1 thorpej {
459 1.1 thorpej uint8_t res;
460 1.1 thorpej
461 1.1 thorpej CHECK_MODULE();
462 1.1 thorpej
463 1.1 thorpej ATF_REQUIRE_EQ(do_ufetch_8(NULL, &res), EFAULT);
464 1.1 thorpej }
465 1.1 thorpej ATF_TC_CLEANUP(ufetch_8_null, tc)
466 1.1 thorpej {
467 1.1 thorpej unload_module();
468 1.1 thorpej }
469 1.1 thorpej
470 1.1 thorpej ATF_TC_WITH_CLEANUP(ufetch_16_null);
471 1.1 thorpej ATF_TC_HEAD(ufetch_16_null, tc)
472 1.1 thorpej {
473 1.1 thorpej atf_tc_set_md_var(tc, "descr",
474 1.1 thorpej "test for correct ufetch_16 NULL pointer behavior");
475 1.1 thorpej }
476 1.1 thorpej ATF_TC_BODY(ufetch_16_null, tc)
477 1.1 thorpej {
478 1.1 thorpej uint16_t res;
479 1.1 thorpej
480 1.1 thorpej CHECK_MODULE();
481 1.1 thorpej
482 1.1 thorpej ATF_REQUIRE_EQ(do_ufetch_16(NULL, &res), EFAULT);
483 1.1 thorpej }
484 1.1 thorpej ATF_TC_CLEANUP(ufetch_16_null, tc)
485 1.1 thorpej {
486 1.1 thorpej unload_module();
487 1.1 thorpej }
488 1.1 thorpej
489 1.1 thorpej ATF_TC_WITH_CLEANUP(ufetch_32_null);
490 1.1 thorpej ATF_TC_HEAD(ufetch_32_null, tc)
491 1.1 thorpej {
492 1.1 thorpej atf_tc_set_md_var(tc, "descr",
493 1.1 thorpej "test for correct ufetch_32 NULL pointer behavior");
494 1.1 thorpej }
495 1.1 thorpej ATF_TC_BODY(ufetch_32_null, tc)
496 1.1 thorpej {
497 1.1 thorpej uint32_t res;
498 1.1 thorpej
499 1.1 thorpej CHECK_MODULE();
500 1.1 thorpej
501 1.1 thorpej ATF_REQUIRE_EQ(do_ufetch_32(NULL, &res), EFAULT);
502 1.1 thorpej }
503 1.1 thorpej ATF_TC_CLEANUP(ufetch_32_null, tc)
504 1.1 thorpej {
505 1.1 thorpej unload_module();
506 1.1 thorpej }
507 1.1 thorpej
508 1.1 thorpej #ifdef _LP64
509 1.1 thorpej ATF_TC_WITH_CLEANUP(ufetch_64_null);
510 1.1 thorpej ATF_TC_HEAD(ufetch_64_null, tc)
511 1.1 thorpej {
512 1.1 thorpej atf_tc_set_md_var(tc, "descr",
513 1.1 thorpej "test for correct ufetch_64 NULL pointer behavior");
514 1.1 thorpej }
515 1.1 thorpej ATF_TC_BODY(ufetch_64_null, tc)
516 1.1 thorpej {
517 1.1 thorpej uint64_t res;
518 1.1 thorpej
519 1.1 thorpej CHECK_MODULE();
520 1.1 thorpej
521 1.1 thorpej ATF_REQUIRE_EQ(do_ufetch_64(NULL, &res), EFAULT);
522 1.1 thorpej }
523 1.1 thorpej ATF_TC_CLEANUP(ufetch_64_null, tc)
524 1.1 thorpej {
525 1.1 thorpej unload_module();
526 1.1 thorpej }
527 1.1 thorpej #endif /* _LP64 */
528 1.1 thorpej
529 1.1 thorpej ATF_TC_WITH_CLEANUP(ufetch_8_max);
530 1.1 thorpej ATF_TC_HEAD(ufetch_8_max, tc)
531 1.1 thorpej {
532 1.1 thorpej atf_tc_set_md_var(tc, "descr",
533 1.1 thorpej "test for correct ufetch_8 VM_MAX_ADDRESS pointer behavior");
534 1.1 thorpej }
535 1.1 thorpej ATF_TC_BODY(ufetch_8_max, tc)
536 1.1 thorpej {
537 1.1 thorpej uint8_t res;
538 1.1 thorpej
539 1.1 thorpej CHECK_MODULE();
540 1.1 thorpej
541 1.1 thorpej ATF_REQUIRE_EQ(do_ufetch_8(vm_max_address(), &res), EFAULT);
542 1.1 thorpej }
543 1.1 thorpej ATF_TC_CLEANUP(ufetch_8_max, tc)
544 1.1 thorpej {
545 1.1 thorpej unload_module();
546 1.1 thorpej }
547 1.1 thorpej
548 1.1 thorpej ATF_TC_WITH_CLEANUP(ufetch_16_max);
549 1.1 thorpej ATF_TC_HEAD(ufetch_16_max, tc)
550 1.1 thorpej {
551 1.1 thorpej atf_tc_set_md_var(tc, "descr",
552 1.1 thorpej "test for correct ufetch_16 VM_MAX_ADDRESS pointer behavior");
553 1.1 thorpej }
554 1.1 thorpej ATF_TC_BODY(ufetch_16_max, tc)
555 1.1 thorpej {
556 1.1 thorpej uint16_t res;
557 1.1 thorpej
558 1.1 thorpej CHECK_MODULE();
559 1.1 thorpej
560 1.1 thorpej ATF_REQUIRE_EQ(do_ufetch_16(vm_max_address(), &res), EFAULT);
561 1.1 thorpej }
562 1.1 thorpej ATF_TC_CLEANUP(ufetch_16_max, tc)
563 1.1 thorpej {
564 1.1 thorpej unload_module();
565 1.1 thorpej }
566 1.1 thorpej
567 1.1 thorpej ATF_TC_WITH_CLEANUP(ufetch_32_max);
568 1.1 thorpej ATF_TC_HEAD(ufetch_32_max, tc)
569 1.1 thorpej {
570 1.1 thorpej atf_tc_set_md_var(tc, "descr",
571 1.1 thorpej "test for correct ufetch_32 VM_MAX_ADDRESS pointer behavior");
572 1.1 thorpej }
573 1.1 thorpej ATF_TC_BODY(ufetch_32_max, tc)
574 1.1 thorpej {
575 1.1 thorpej uint32_t res;
576 1.1 thorpej
577 1.1 thorpej CHECK_MODULE();
578 1.1 thorpej
579 1.1 thorpej ATF_REQUIRE_EQ(do_ufetch_32(vm_max_address(), &res), EFAULT);
580 1.1 thorpej }
581 1.1 thorpej ATF_TC_CLEANUP(ufetch_32_max, tc)
582 1.1 thorpej {
583 1.1 thorpej unload_module();
584 1.1 thorpej }
585 1.1 thorpej
586 1.1 thorpej #ifdef _LP64
587 1.1 thorpej ATF_TC_WITH_CLEANUP(ufetch_64_max);
588 1.1 thorpej ATF_TC_HEAD(ufetch_64_max, tc)
589 1.1 thorpej {
590 1.1 thorpej atf_tc_set_md_var(tc, "descr",
591 1.1 thorpej "test for correct ufetch_64 VM_MAX_ADDRESS pointer behavior");
592 1.1 thorpej }
593 1.1 thorpej ATF_TC_BODY(ufetch_64_max, tc)
594 1.1 thorpej {
595 1.1 thorpej uint64_t res;
596 1.1 thorpej
597 1.1 thorpej CHECK_MODULE();
598 1.1 thorpej
599 1.1 thorpej ATF_REQUIRE_EQ(do_ufetch_64(vm_max_address(), &res), EFAULT);
600 1.1 thorpej }
601 1.1 thorpej ATF_TC_CLEANUP(ufetch_64_max, tc)
602 1.1 thorpej {
603 1.1 thorpej unload_module();
604 1.1 thorpej }
605 1.1 thorpej #endif /* _LP64 */
606 1.1 thorpej
607 1.1 thorpej ATF_TC_WITH_CLEANUP(ustore_8);
608 1.1 thorpej ATF_TC_HEAD(ustore_8, tc)
609 1.1 thorpej {
610 1.1 thorpej atf_tc_set_md_var(tc, "descr",
611 1.1 thorpej "test for correct ustore_8 behavior");
612 1.1 thorpej }
613 1.1 thorpej ATF_TC_BODY(ustore_8, tc)
614 1.1 thorpej {
615 1.1 thorpej struct memory_cell cell = memory_cell_initializer;
616 1.1 thorpej
617 1.1 thorpej CHECK_MODULE();
618 1.1 thorpej
619 1.1 thorpej ATF_REQUIRE_EQ(do_ustore_8(&cell.val8[index8], test_pattern8), 0);
620 1.1 thorpej ATF_REQUIRE(memory_cell_check_guard(&cell));
621 1.1 thorpej ATF_REQUIRE(read_test_cell(&cell) == test_cell_val8);
622 1.1 thorpej }
623 1.1 thorpej ATF_TC_CLEANUP(ustore_8, tc)
624 1.1 thorpej {
625 1.1 thorpej unload_module();
626 1.1 thorpej }
627 1.1 thorpej
628 1.1 thorpej ATF_TC_WITH_CLEANUP(ustore_16);
629 1.1 thorpej ATF_TC_HEAD(ustore_16, tc)
630 1.1 thorpej {
631 1.1 thorpej atf_tc_set_md_var(tc, "descr",
632 1.1 thorpej "test for correct ustore_16 behavior");
633 1.1 thorpej }
634 1.1 thorpej ATF_TC_BODY(ustore_16, tc)
635 1.1 thorpej {
636 1.1 thorpej struct memory_cell cell = memory_cell_initializer;
637 1.1 thorpej
638 1.1 thorpej CHECK_MODULE();
639 1.1 thorpej
640 1.1 thorpej ATF_REQUIRE_EQ(do_ustore_16(&cell.val16[index16], test_pattern16), 0);
641 1.1 thorpej ATF_REQUIRE(memory_cell_check_guard(&cell));
642 1.1 thorpej ATF_REQUIRE(read_test_cell(&cell) == test_cell_val16);
643 1.1 thorpej }
644 1.1 thorpej ATF_TC_CLEANUP(ustore_16, tc)
645 1.1 thorpej {
646 1.1 thorpej unload_module();
647 1.1 thorpej }
648 1.1 thorpej
649 1.1 thorpej ATF_TC_WITH_CLEANUP(ustore_32);
650 1.1 thorpej ATF_TC_HEAD(ustore_32, tc)
651 1.1 thorpej {
652 1.1 thorpej atf_tc_set_md_var(tc, "descr",
653 1.1 thorpej "test for correct ustore_32 behavior");
654 1.1 thorpej }
655 1.1 thorpej ATF_TC_BODY(ustore_32, tc)
656 1.1 thorpej {
657 1.1 thorpej struct memory_cell cell = memory_cell_initializer;
658 1.1 thorpej
659 1.1 thorpej CHECK_MODULE();
660 1.1 thorpej
661 1.1 thorpej ATF_REQUIRE_EQ(do_ustore_32(&cell.val32[index32], test_pattern32), 0);
662 1.1 thorpej ATF_REQUIRE(memory_cell_check_guard(&cell));
663 1.1 thorpej ATF_REQUIRE(read_test_cell(&cell) == test_cell_val32);
664 1.1 thorpej }
665 1.1 thorpej ATF_TC_CLEANUP(ustore_32, tc)
666 1.1 thorpej {
667 1.1 thorpej unload_module();
668 1.1 thorpej }
669 1.1 thorpej
670 1.1 thorpej #ifdef _LP64
671 1.1 thorpej ATF_TC_WITH_CLEANUP(ustore_64);
672 1.1 thorpej ATF_TC_HEAD(ustore_64, tc)
673 1.1 thorpej {
674 1.1 thorpej atf_tc_set_md_var(tc, "descr",
675 1.1 thorpej "test for correct ustore_64 behavior");
676 1.1 thorpej }
677 1.1 thorpej ATF_TC_BODY(ustore_64, tc)
678 1.1 thorpej {
679 1.1 thorpej struct memory_cell cell = memory_cell_initializer;
680 1.1 thorpej
681 1.1 thorpej CHECK_MODULE();
682 1.1 thorpej
683 1.1 thorpej ATF_REQUIRE_EQ(do_ustore_64(&cell.val64, test_pattern64), 0);
684 1.1 thorpej ATF_REQUIRE(memory_cell_check_guard(&cell));
685 1.1 thorpej ATF_REQUIRE(read_test_cell(&cell) == test_cell_val64);
686 1.1 thorpej }
687 1.1 thorpej ATF_TC_CLEANUP(ustore_64, tc)
688 1.1 thorpej {
689 1.1 thorpej unload_module();
690 1.1 thorpej }
691 1.1 thorpej #endif /* _LP64 */
692 1.1 thorpej
693 1.1 thorpej ATF_TC_WITH_CLEANUP(ustore_8_null);
694 1.1 thorpej ATF_TC_HEAD(ustore_8_null, tc)
695 1.1 thorpej {
696 1.1 thorpej atf_tc_set_md_var(tc, "descr",
697 1.1 thorpej "test for correct ustore_8 NULL pointer behavior");
698 1.1 thorpej }
699 1.1 thorpej ATF_TC_BODY(ustore_8_null, tc)
700 1.1 thorpej {
701 1.1 thorpej CHECK_MODULE();
702 1.1 thorpej
703 1.1 thorpej ATF_REQUIRE_EQ(do_ustore_8(NULL, 0), EFAULT);
704 1.1 thorpej }
705 1.1 thorpej ATF_TC_CLEANUP(ustore_8_null, tc)
706 1.1 thorpej {
707 1.1 thorpej unload_module();
708 1.1 thorpej }
709 1.1 thorpej
710 1.1 thorpej ATF_TC_WITH_CLEANUP(ustore_16_null);
711 1.1 thorpej ATF_TC_HEAD(ustore_16_null, tc)
712 1.1 thorpej {
713 1.1 thorpej atf_tc_set_md_var(tc, "descr",
714 1.1 thorpej "test for correct ustore_16 NULL pointer behavior");
715 1.1 thorpej }
716 1.1 thorpej ATF_TC_BODY(ustore_16_null, tc)
717 1.1 thorpej {
718 1.1 thorpej CHECK_MODULE();
719 1.1 thorpej
720 1.1 thorpej ATF_REQUIRE_EQ(do_ustore_16(NULL, 0), EFAULT);
721 1.1 thorpej }
722 1.1 thorpej ATF_TC_CLEANUP(ustore_16_null, tc)
723 1.1 thorpej {
724 1.1 thorpej unload_module();
725 1.1 thorpej }
726 1.1 thorpej
727 1.1 thorpej ATF_TC_WITH_CLEANUP(ustore_32_null);
728 1.1 thorpej ATF_TC_HEAD(ustore_32_null, tc)
729 1.1 thorpej {
730 1.1 thorpej atf_tc_set_md_var(tc, "descr",
731 1.1 thorpej "test for correct ustore_32 NULL pointer behavior");
732 1.1 thorpej }
733 1.1 thorpej ATF_TC_BODY(ustore_32_null, tc)
734 1.1 thorpej {
735 1.1 thorpej CHECK_MODULE();
736 1.1 thorpej
737 1.1 thorpej ATF_REQUIRE_EQ(do_ustore_32(NULL, 0), EFAULT);
738 1.1 thorpej }
739 1.1 thorpej ATF_TC_CLEANUP(ustore_32_null, tc)
740 1.1 thorpej {
741 1.1 thorpej unload_module();
742 1.1 thorpej }
743 1.1 thorpej
744 1.1 thorpej #ifdef _LP64
745 1.1 thorpej ATF_TC_WITH_CLEANUP(ustore_64_null);
746 1.1 thorpej ATF_TC_HEAD(ustore_64_null, tc)
747 1.1 thorpej {
748 1.1 thorpej atf_tc_set_md_var(tc, "descr",
749 1.1 thorpej "test for correct ustore_64 NULL pointer behavior");
750 1.1 thorpej }
751 1.1 thorpej ATF_TC_BODY(ustore_64_null, tc)
752 1.1 thorpej {
753 1.1 thorpej CHECK_MODULE();
754 1.1 thorpej
755 1.1 thorpej ATF_REQUIRE_EQ(do_ustore_64(NULL, 0), EFAULT);
756 1.1 thorpej }
757 1.1 thorpej ATF_TC_CLEANUP(ustore_64_null, tc)
758 1.1 thorpej {
759 1.1 thorpej unload_module();
760 1.1 thorpej }
761 1.1 thorpej #endif /* _LP64 */
762 1.1 thorpej
763 1.1 thorpej ATF_TC_WITH_CLEANUP(ustore_8_max);
764 1.1 thorpej ATF_TC_HEAD(ustore_8_max, tc)
765 1.1 thorpej {
766 1.1 thorpej atf_tc_set_md_var(tc, "descr",
767 1.1 thorpej "test for correct ustore_8 VM_MAX_ADDRESS pointer behavior");
768 1.1 thorpej }
769 1.1 thorpej ATF_TC_BODY(ustore_8_max, tc)
770 1.1 thorpej {
771 1.1 thorpej CHECK_MODULE();
772 1.1 thorpej
773 1.1 thorpej ATF_REQUIRE_EQ(do_ustore_8(vm_max_address(), 0), EFAULT);
774 1.1 thorpej }
775 1.1 thorpej ATF_TC_CLEANUP(ustore_8_max, tc)
776 1.1 thorpej {
777 1.1 thorpej unload_module();
778 1.1 thorpej }
779 1.1 thorpej
780 1.1 thorpej ATF_TC_WITH_CLEANUP(ustore_16_max);
781 1.1 thorpej ATF_TC_HEAD(ustore_16_max, tc)
782 1.1 thorpej {
783 1.1 thorpej atf_tc_set_md_var(tc, "descr",
784 1.1 thorpej "test for correct ustore_16 VM_MAX_ADDRESS pointer behavior");
785 1.1 thorpej }
786 1.1 thorpej ATF_TC_BODY(ustore_16_max, tc)
787 1.1 thorpej {
788 1.1 thorpej CHECK_MODULE();
789 1.1 thorpej
790 1.1 thorpej ATF_REQUIRE_EQ(do_ustore_16(vm_max_address(), 0), EFAULT);
791 1.1 thorpej }
792 1.1 thorpej ATF_TC_CLEANUP(ustore_16_max, tc)
793 1.1 thorpej {
794 1.1 thorpej unload_module();
795 1.1 thorpej }
796 1.1 thorpej
797 1.1 thorpej ATF_TC_WITH_CLEANUP(ustore_32_max);
798 1.1 thorpej ATF_TC_HEAD(ustore_32_max, tc)
799 1.1 thorpej {
800 1.1 thorpej atf_tc_set_md_var(tc, "descr",
801 1.1 thorpej "test for correct ustore_32 VM_MAX_ADDRESS pointer behavior");
802 1.1 thorpej }
803 1.1 thorpej ATF_TC_BODY(ustore_32_max, tc)
804 1.1 thorpej {
805 1.1 thorpej CHECK_MODULE();
806 1.1 thorpej
807 1.1 thorpej ATF_REQUIRE_EQ(do_ustore_32(vm_max_address(), 0), EFAULT);
808 1.1 thorpej }
809 1.1 thorpej ATF_TC_CLEANUP(ustore_32_max, tc)
810 1.1 thorpej {
811 1.1 thorpej unload_module();
812 1.1 thorpej }
813 1.1 thorpej
814 1.1 thorpej #ifdef _LP64
815 1.1 thorpej ATF_TC_WITH_CLEANUP(ustore_64_max);
816 1.1 thorpej ATF_TC_HEAD(ustore_64_max, tc)
817 1.1 thorpej {
818 1.1 thorpej atf_tc_set_md_var(tc, "descr",
819 1.1 thorpej "test for correct ustore_64 VM_MAX_ADDRESS pointer behavior");
820 1.1 thorpej }
821 1.1 thorpej ATF_TC_BODY(ustore_64_max, tc)
822 1.1 thorpej {
823 1.1 thorpej CHECK_MODULE();
824 1.1 thorpej
825 1.1 thorpej ATF_REQUIRE_EQ(do_ustore_64(vm_max_address(), 0), EFAULT);
826 1.1 thorpej }
827 1.1 thorpej ATF_TC_CLEANUP(ustore_64_max, tc)
828 1.1 thorpej {
829 1.1 thorpej unload_module();
830 1.1 thorpej }
831 1.1 thorpej #endif /* _LP64 */
832 1.1 thorpej
833 1.1 thorpej ATF_TC_WITH_CLEANUP(ucas_32);
834 1.1 thorpej ATF_TC_HEAD(ucas_32, tc)
835 1.1 thorpej {
836 1.1 thorpej atf_tc_set_md_var(tc, "descr",
837 1.1 thorpej "test for correct ucas_32 behavior");
838 1.1 thorpej }
839 1.1 thorpej ATF_TC_BODY(ucas_32, tc)
840 1.1 thorpej {
841 1.1 thorpej uint32_t cell = 0xdeadbeef;
842 1.1 thorpej uint32_t actual = 0;
843 1.1 thorpej
844 1.1 thorpej CHECK_MODULE();
845 1.1 thorpej
846 1.1 thorpej ATF_REQUIRE_EQ(do_ucas_32(&cell, 0xdeadbeef, 0xbeefdead, &actual), 0);
847 1.1 thorpej ATF_REQUIRE(actual == 0xdeadbeef);
848 1.1 thorpej ATF_REQUIRE(cell == 0xbeefdead);
849 1.1 thorpej }
850 1.1 thorpej ATF_TC_CLEANUP(ucas_32, tc)
851 1.1 thorpej {
852 1.1 thorpej unload_module();
853 1.1 thorpej }
854 1.1 thorpej
855 1.1 thorpej #ifdef _LP64
856 1.1 thorpej ATF_TC_WITH_CLEANUP(ucas_64);
857 1.1 thorpej ATF_TC_HEAD(ucas_64, tc)
858 1.1 thorpej {
859 1.1 thorpej atf_tc_set_md_var(tc, "descr",
860 1.1 thorpej "test for correct ucas_64 behavior");
861 1.1 thorpej }
862 1.1 thorpej ATF_TC_BODY(ucas_64, tc)
863 1.1 thorpej {
864 1.1 thorpej uint64_t cell = 0xdeadbeef;
865 1.1 thorpej uint64_t actual = 0;
866 1.1 thorpej
867 1.1 thorpej CHECK_MODULE();
868 1.1 thorpej
869 1.1 thorpej ATF_REQUIRE_EQ(do_ucas_64(&cell, 0xdeadbeef, 0xbeefdead, &actual), 0);
870 1.1 thorpej ATF_REQUIRE(actual == 0xdeadbeef);
871 1.1 thorpej ATF_REQUIRE(cell == 0xbeefdead);
872 1.1 thorpej }
873 1.1 thorpej ATF_TC_CLEANUP(ucas_64, tc)
874 1.1 thorpej {
875 1.1 thorpej unload_module();
876 1.1 thorpej }
877 1.1 thorpej #endif /* _LP64 */
878 1.1 thorpej
879 1.1 thorpej ATF_TC_WITH_CLEANUP(ucas_32_miscompare);
880 1.1 thorpej ATF_TC_HEAD(ucas_32_miscompare, tc)
881 1.1 thorpej {
882 1.1 thorpej atf_tc_set_md_var(tc, "descr",
883 1.1 thorpej "test for correct ucas_32 behavior with miscompare");
884 1.1 thorpej }
885 1.1 thorpej ATF_TC_BODY(ucas_32_miscompare, tc)
886 1.1 thorpej {
887 1.1 thorpej uint32_t cell = 0xa5a5a5a5;
888 1.1 thorpej uint32_t actual = 0;
889 1.1 thorpej
890 1.1 thorpej CHECK_MODULE();
891 1.1 thorpej
892 1.1 thorpej ATF_REQUIRE_EQ(do_ucas_32(&cell, 0xdeadbeef, 0xbeefdead, &actual), 0);
893 1.1 thorpej ATF_REQUIRE(actual == 0xa5a5a5a5);
894 1.1 thorpej ATF_REQUIRE(cell == 0xa5a5a5a5);
895 1.1 thorpej }
896 1.1 thorpej ATF_TC_CLEANUP(ucas_32_miscompare, tc)
897 1.1 thorpej {
898 1.1 thorpej unload_module();
899 1.1 thorpej }
900 1.1 thorpej
901 1.1 thorpej #ifdef _LP64
902 1.1 thorpej ATF_TC_WITH_CLEANUP(ucas_64_miscompare);
903 1.1 thorpej ATF_TC_HEAD(ucas_64_miscompare, tc)
904 1.1 thorpej {
905 1.1 thorpej atf_tc_set_md_var(tc, "descr",
906 1.1 thorpej "test for correct ucas_64 behavior with miscompare");
907 1.1 thorpej }
908 1.1 thorpej ATF_TC_BODY(ucas_64_miscompare, tc)
909 1.1 thorpej {
910 1.1 thorpej uint64_t cell = 0xa5a5a5a5;
911 1.1 thorpej uint64_t actual = 0;
912 1.1 thorpej
913 1.1 thorpej CHECK_MODULE();
914 1.1 thorpej
915 1.1 thorpej ATF_REQUIRE_EQ(do_ucas_64(&cell, 0xdeadbeef, 0xbeefdead, &actual), 0);
916 1.1 thorpej ATF_REQUIRE(actual == 0xa5a5a5a5);
917 1.1 thorpej ATF_REQUIRE(cell == 0xa5a5a5a5);
918 1.1 thorpej }
919 1.1 thorpej ATF_TC_CLEANUP(ucas_64_miscompare, tc)
920 1.1 thorpej {
921 1.1 thorpej unload_module();
922 1.1 thorpej }
923 1.1 thorpej #endif /* _LP64 */
924 1.1 thorpej
925 1.1 thorpej ATF_TC_WITH_CLEANUP(ucas_32_null);
926 1.1 thorpej ATF_TC_HEAD(ucas_32_null, tc)
927 1.1 thorpej {
928 1.1 thorpej atf_tc_set_md_var(tc, "descr",
929 1.1 thorpej "test for correct ucas_32 NULL pointer behavior");
930 1.1 thorpej }
931 1.1 thorpej ATF_TC_BODY(ucas_32_null, tc)
932 1.1 thorpej {
933 1.1 thorpej uint32_t actual = 0;
934 1.1 thorpej
935 1.1 thorpej CHECK_MODULE();
936 1.1 thorpej
937 1.1 thorpej ATF_REQUIRE_EQ(do_ucas_32(NULL, 0xdeadbeef, 0xbeefdead, &actual),
938 1.1 thorpej EFAULT);
939 1.1 thorpej }
940 1.1 thorpej ATF_TC_CLEANUP(ucas_32_null, tc)
941 1.1 thorpej {
942 1.1 thorpej unload_module();
943 1.1 thorpej }
944 1.1 thorpej
945 1.1 thorpej #ifdef _LP64
946 1.1 thorpej ATF_TC_WITH_CLEANUP(ucas_64_null);
947 1.1 thorpej ATF_TC_HEAD(ucas_64_null, tc)
948 1.1 thorpej {
949 1.1 thorpej atf_tc_set_md_var(tc, "descr",
950 1.1 thorpej "test for correct ucas_64 NULL pointer behavior");
951 1.1 thorpej }
952 1.1 thorpej ATF_TC_BODY(ucas_64_null, tc)
953 1.1 thorpej {
954 1.1 thorpej uint64_t actual = 0;
955 1.1 thorpej
956 1.1 thorpej CHECK_MODULE();
957 1.1 thorpej
958 1.1 thorpej ATF_REQUIRE_EQ(do_ucas_64(NULL, 0xdeadbeef, 0xbeefdead, &actual),
959 1.1 thorpej EFAULT);
960 1.1 thorpej }
961 1.1 thorpej ATF_TC_CLEANUP(ucas_64_null, tc)
962 1.1 thorpej {
963 1.1 thorpej unload_module();
964 1.1 thorpej }
965 1.1 thorpej #endif /* _LP64 */
966 1.1 thorpej
967 1.1 thorpej ATF_TC_WITH_CLEANUP(ucas_32_max);
968 1.1 thorpej ATF_TC_HEAD(ucas_32_max, tc)
969 1.1 thorpej {
970 1.1 thorpej atf_tc_set_md_var(tc, "descr",
971 1.1 thorpej "test for correct ucas_32 VM_MAX_ADDRESS pointer behavior");
972 1.1 thorpej }
973 1.1 thorpej ATF_TC_BODY(ucas_32_max, tc)
974 1.1 thorpej {
975 1.1 thorpej uint32_t actual = 0;
976 1.1 thorpej
977 1.1 thorpej CHECK_MODULE();
978 1.1 thorpej
979 1.1 thorpej ATF_REQUIRE_EQ(do_ucas_32(vm_max_address(), 0xdeadbeef, 0xbeefdead,
980 1.1 thorpej &actual), EFAULT);
981 1.1 thorpej }
982 1.1 thorpej ATF_TC_CLEANUP(ucas_32_max, tc)
983 1.1 thorpej {
984 1.1 thorpej unload_module();
985 1.1 thorpej }
986 1.1 thorpej
987 1.1 thorpej #ifdef _LP64
988 1.1 thorpej ATF_TC_WITH_CLEANUP(ucas_64_max);
989 1.1 thorpej ATF_TC_HEAD(ucas_64_max, tc)
990 1.1 thorpej {
991 1.1 thorpej atf_tc_set_md_var(tc, "descr",
992 1.1 thorpej "test for correct ucas_64 VM_MAX_ADDRESS pointer behavior");
993 1.1 thorpej }
994 1.1 thorpej ATF_TC_BODY(ucas_64_max, tc)
995 1.1 thorpej {
996 1.1 thorpej uint64_t actual = 0;
997 1.1 thorpej
998 1.1 thorpej CHECK_MODULE();
999 1.1 thorpej
1000 1.1 thorpej ATF_REQUIRE_EQ(do_ucas_64(vm_max_address(), 0xdeadbeef, 0xbeefdead,
1001 1.1 thorpej &actual), EFAULT);
1002 1.1 thorpej }
1003 1.1 thorpej ATF_TC_CLEANUP(ucas_64_max, tc)
1004 1.1 thorpej {
1005 1.1 thorpej unload_module();
1006 1.1 thorpej }
1007 1.1 thorpej #endif /* _LP64 */
1008 1.1 thorpej
1009 1.1 thorpej ATF_TP_ADD_TCS(tp)
1010 1.1 thorpej {
1011 1.1 thorpej ATF_TP_ADD_TC(tp, ufetch_8);
1012 1.1 thorpej ATF_TP_ADD_TC(tp, ufetch_16);
1013 1.1 thorpej ATF_TP_ADD_TC(tp, ufetch_32);
1014 1.1 thorpej #ifdef _LP64
1015 1.1 thorpej ATF_TP_ADD_TC(tp, ufetch_64);
1016 1.1 thorpej #endif
1017 1.1 thorpej
1018 1.1 thorpej ATF_TP_ADD_TC(tp, ufetch_8_null);
1019 1.1 thorpej ATF_TP_ADD_TC(tp, ufetch_16_null);
1020 1.1 thorpej ATF_TP_ADD_TC(tp, ufetch_32_null);
1021 1.1 thorpej #ifdef _LP64
1022 1.1 thorpej ATF_TP_ADD_TC(tp, ufetch_64_null);
1023 1.1 thorpej #endif
1024 1.1 thorpej
1025 1.1 thorpej ATF_TP_ADD_TC(tp, ufetch_8_max);
1026 1.1 thorpej ATF_TP_ADD_TC(tp, ufetch_16_max);
1027 1.1 thorpej ATF_TP_ADD_TC(tp, ufetch_32_max);
1028 1.1 thorpej #ifdef _LP64
1029 1.1 thorpej ATF_TP_ADD_TC(tp, ufetch_64_max);
1030 1.1 thorpej #endif
1031 1.1 thorpej
1032 1.1 thorpej ATF_TP_ADD_TC(tp, ustore_8);
1033 1.1 thorpej ATF_TP_ADD_TC(tp, ustore_16);
1034 1.1 thorpej ATF_TP_ADD_TC(tp, ustore_32);
1035 1.1 thorpej #ifdef _LP64
1036 1.1 thorpej ATF_TP_ADD_TC(tp, ustore_64);
1037 1.1 thorpej #endif
1038 1.1 thorpej
1039 1.1 thorpej ATF_TP_ADD_TC(tp, ustore_8_null);
1040 1.1 thorpej ATF_TP_ADD_TC(tp, ustore_16_null);
1041 1.1 thorpej ATF_TP_ADD_TC(tp, ustore_32_null);
1042 1.1 thorpej #ifdef _LP64
1043 1.1 thorpej ATF_TP_ADD_TC(tp, ustore_64_null);
1044 1.1 thorpej #endif
1045 1.1 thorpej
1046 1.1 thorpej ATF_TP_ADD_TC(tp, ustore_8_max);
1047 1.1 thorpej ATF_TP_ADD_TC(tp, ustore_16_max);
1048 1.1 thorpej ATF_TP_ADD_TC(tp, ustore_32_max);
1049 1.1 thorpej #ifdef _LP64
1050 1.1 thorpej ATF_TP_ADD_TC(tp, ustore_64_max);
1051 1.1 thorpej #endif
1052 1.1 thorpej
1053 1.1 thorpej ATF_TP_ADD_TC(tp, ucas_32);
1054 1.1 thorpej #ifdef _LP64
1055 1.1 thorpej ATF_TP_ADD_TC(tp, ucas_64);
1056 1.1 thorpej #endif
1057 1.1 thorpej
1058 1.1 thorpej ATF_TP_ADD_TC(tp, ucas_32_miscompare);
1059 1.1 thorpej #ifdef _LP64
1060 1.1 thorpej ATF_TP_ADD_TC(tp, ucas_64_miscompare);
1061 1.1 thorpej #endif
1062 1.1 thorpej
1063 1.1 thorpej ATF_TP_ADD_TC(tp, ucas_32_null);
1064 1.1 thorpej #ifdef _LP64
1065 1.1 thorpej ATF_TP_ADD_TC(tp, ucas_64_null);
1066 1.1 thorpej #endif
1067 1.1 thorpej
1068 1.1 thorpej ATF_TP_ADD_TC(tp, ucas_32_max);
1069 1.1 thorpej #ifdef _LP64
1070 1.1 thorpej ATF_TP_ADD_TC(tp, ucas_64_max);
1071 1.1 thorpej #endif
1072 1.1 thorpej
1073 1.1 thorpej return atf_no_error();
1074 1.1 thorpej }
1075