]>
Commit | Line | Data |
---|---|---|
609cf614 UD |
1 | /* Copyright (C) 2006 Free Software Foundation, Inc. |
2 | This file is part of the GNU C Library. | |
3 | Contributed by Jakub Jelinek <jakub@redhat.com>, 2006. | |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Lesser General Public | |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
9 | ||
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
59ba27a6 PE |
16 | License along with the GNU C Library; if not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
609cf614 UD |
18 | |
19 | #include <limits.h> | |
20 | #include <stdio.h> | |
21 | #include <string.h> | |
22 | #include <rpc/rpc.h> | |
23 | #include <sys/mman.h> | |
24 | #include <unistd.h> | |
25 | ||
26 | static int | |
27 | do_test (void) | |
28 | { | |
29 | XDR xdrs; | |
30 | void *buf; | |
31 | size_t ps = sysconf (_SC_PAGESIZE); | |
32 | uintptr_t half = -1; | |
33 | int v_int; | |
34 | u_short v_u_short; | |
35 | ||
36 | half = (half >> 1) & ~(uintptr_t) (ps - 1); | |
37 | buf = mmap ((void *) half, 2 * ps, PROT_READ | PROT_WRITE, | |
38 | MAP_PRIVATE | MAP_ANON, -1, 0); | |
39 | if (buf == MAP_FAILED || buf != (void *) half) | |
40 | { | |
41 | puts ("Couldn't mmap 2 pages in the middle of address space"); | |
42 | return 0; | |
43 | } | |
44 | ||
45 | xdrmem_create (&xdrs, (char *) buf, 2 * ps, XDR_ENCODE); | |
46 | ||
47 | #define T(type, val) \ | |
48 | v_##type = val; \ | |
49 | if (! xdr_##type (&xdrs, &v_##type)) \ | |
50 | { \ | |
51 | puts ("encoding of " #type \ | |
52 | " " #val " failed"); \ | |
53 | return 1; \ | |
54 | } | |
55 | ||
56 | T(int, 127) | |
57 | ||
58 | u_int pos = xdr_getpos (&xdrs); | |
59 | ||
60 | T(u_short, 31) | |
61 | ||
62 | if (! xdr_setpos (&xdrs, pos)) | |
63 | { | |
64 | puts ("xdr_setpos during encoding failed"); | |
65 | return 1; | |
66 | } | |
67 | ||
68 | T(u_short, 36) | |
69 | ||
70 | #undef T | |
71 | ||
72 | xdr_destroy (&xdrs); | |
73 | ||
74 | xdrmem_create (&xdrs, (char *) buf, 2 * ps, XDR_DECODE); | |
75 | ||
76 | #define T(type, val) \ | |
77 | v_##type = 0x15; \ | |
78 | if (! xdr_##type (&xdrs, &v_##type)) \ | |
79 | { \ | |
80 | puts ("decoding of " #type \ | |
81 | " " #val " failed"); \ | |
82 | return 1; \ | |
83 | } \ | |
84 | if (v_##type != val) \ | |
85 | { \ | |
86 | puts ("decoded value differs, " \ | |
87 | "type " #type " " #val); \ | |
88 | return 1; \ | |
89 | } | |
90 | ||
91 | T(int, 127) | |
92 | ||
93 | pos = xdr_getpos (&xdrs); | |
94 | ||
95 | T(u_short, 36) | |
96 | ||
97 | if (! xdr_setpos (&xdrs, pos)) | |
98 | { | |
99 | puts ("xdr_setpos during encoding failed"); | |
100 | return 1; | |
101 | } | |
102 | ||
103 | T(u_short, 36) | |
104 | ||
105 | #undef T | |
106 | ||
107 | xdr_destroy (&xdrs); | |
108 | ||
109 | return 0; | |
110 | } | |
111 | ||
112 | #define TEST_FUNCTION do_test () | |
113 | #include "../test-skeleton.c" |