3 # Copyright (C) 2018 Red Hat Inc.
5 # Redistribution and use in source and binary forms, with or without
6 # modification, are permitted provided that the following conditions are
9 # * Redistributions of source code must retain the above copyright
10 # notice, this list of conditions and the following disclaimer.
12 # * 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.
16 # * Neither the name of Red Hat nor the names of its contributors may be
17 # used to endorse or promote products derived from this software without
18 # specific prior written permission.
20 # THIS SOFTWARE IS PROVIDED BY RED HAT AND CONTRIBUTORS ''AS IS'' AND
21 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
22 # THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
23 # PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL RED HAT OR
24 # CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
27 # USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28 # ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
29 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
30 # OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 # Test the memory plugin with the largest possible size supported
40 requires qemu-io
--version
42 sock
=$
(mktemp
-u /tmp
/nbdkit-test-sock.XXXXXX
)
43 files
="memory-largest-for-qemu.out memory-largest-for-qemu.pid $sock"
45 cleanup_fn
rm -f $files
47 # Run nbdkit with memory plugin.
48 start_nbdkit
-P memory-largest-for-qemu.pid
-U $sock memory
$largest_qemu_disk
50 # Write some stuff to the beginning, middle and end.
52 # Ideally we would write the last sector only. However qemu-io has a
53 # bug where offsets are calculated using floating point numbers and
54 # silently truncated to 53 bits of precision. Reading the last 1024
55 # bytes happens to give the correct result here.
56 # https://www.mail-archive.com/qemu-devel@nongnu.org/msg770572.html
57 qemu-io
-f raw
"nbd+unix://?socket=$sock" \
59 -c 'w -P 2 1000000001 65536' \
60 -c 'w -P 3 9223372035781032960 1024'
62 qemu-io
-r -f raw
"nbd+unix://?socket=$sock" \
63 -c 'r -v 0 512' |
grep -E '^[[:xdigit:]]+:' > memory-largest-for-qemu.out
64 if [ "$(cat memory-largest-for-qemu.out)" != "00000000: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
65 00000010: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
66 00000020: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
67 00000030: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
68 00000040: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
69 00000050: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
70 00000060: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
71 00000070: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
72 00000080: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
73 00000090: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
74 000000a0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
75 000000b0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
76 000000c0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
77 000000d0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
78 000000e0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
79 000000f0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
80 00000100: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
81 00000110: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
82 00000120: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
83 00000130: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
84 00000140: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
85 00000150: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
86 00000160: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
87 00000170: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
88 00000180: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
89 00000190: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
90 000001a0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
91 000001b0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
92 000001c0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
93 000001d0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
94 000001e0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................
95 000001f0: 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 01 ................" ]
97 echo "$0: unexpected memory:"
98 cat memory-largest-for-qemu.out
102 qemu-io
-r -f raw
"nbd+unix://?socket=$sock" \
103 -c 'r -v 1000000001 512' |
grep -E '^[[:xdigit:]]+:' > memory-largest-for-qemu.out
104 if [ "$(cat memory-largest-for-qemu.out)" != "3b9aca01: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
105 3b9aca11: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
106 3b9aca21: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
107 3b9aca31: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
108 3b9aca41: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
109 3b9aca51: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
110 3b9aca61: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
111 3b9aca71: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
112 3b9aca81: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
113 3b9aca91: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
114 3b9acaa1: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
115 3b9acab1: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
116 3b9acac1: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
117 3b9acad1: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
118 3b9acae1: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
119 3b9acaf1: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
120 3b9acb01: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
121 3b9acb11: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
122 3b9acb21: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
123 3b9acb31: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
124 3b9acb41: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
125 3b9acb51: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
126 3b9acb61: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
127 3b9acb71: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
128 3b9acb81: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
129 3b9acb91: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
130 3b9acba1: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
131 3b9acbb1: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
132 3b9acbc1: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
133 3b9acbd1: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
134 3b9acbe1: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................
135 3b9acbf1: 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 02 ................" ]
137 echo "$0: unexpected memory:"
138 cat memory-largest-for-qemu.out
142 # This block of memory was not set, so it should read back as zeroes.
143 qemu-io
-r -f raw
"nbd+unix://?socket=$sock" \
144 -c 'r -v 2000000000 512' |
grep -E '^[[:xdigit:]]+:' > memory-largest-for-qemu.out
145 if [ "$(cat memory-largest-for-qemu.out)" != "77359400: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
146 77359410: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
147 77359420: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
148 77359430: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
149 77359440: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
150 77359450: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
151 77359460: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
152 77359470: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
153 77359480: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
154 77359490: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
155 773594a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
156 773594b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
157 773594c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
158 773594d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
159 773594e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
160 773594f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
161 77359500: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
162 77359510: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
163 77359520: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
164 77359530: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
165 77359540: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
166 77359550: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
167 77359560: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
168 77359570: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
169 77359580: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
170 77359590: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
171 773595a0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
172 773595b0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
173 773595c0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
174 773595d0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
175 773595e0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................
176 773595f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ................" ]
178 echo "$0: unexpected memory:"
179 cat memory-largest-for-qemu.out
183 qemu-io
-r -f raw
"nbd+unix://?socket=$sock" \
184 -c 'r -v 9223372035781032960 1024' |
grep -E '^[[:xdigit:]]+:' > memory-largest-for-qemu.out
185 if [ "$(cat memory-largest-for-qemu.out)" != "7fffffffbffffc00: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
186 7fffffffbffffc10: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
187 7fffffffbffffc20: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
188 7fffffffbffffc30: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
189 7fffffffbffffc40: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
190 7fffffffbffffc50: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
191 7fffffffbffffc60: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
192 7fffffffbffffc70: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
193 7fffffffbffffc80: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
194 7fffffffbffffc90: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
195 7fffffffbffffca0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
196 7fffffffbffffcb0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
197 7fffffffbffffcc0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
198 7fffffffbffffcd0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
199 7fffffffbffffce0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
200 7fffffffbffffcf0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
201 7fffffffbffffd00: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
202 7fffffffbffffd10: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
203 7fffffffbffffd20: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
204 7fffffffbffffd30: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
205 7fffffffbffffd40: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
206 7fffffffbffffd50: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
207 7fffffffbffffd60: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
208 7fffffffbffffd70: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
209 7fffffffbffffd80: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
210 7fffffffbffffd90: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
211 7fffffffbffffda0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
212 7fffffffbffffdb0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
213 7fffffffbffffdc0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
214 7fffffffbffffdd0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
215 7fffffffbffffde0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
216 7fffffffbffffdf0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
217 7fffffffbffffe00: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
218 7fffffffbffffe10: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
219 7fffffffbffffe20: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
220 7fffffffbffffe30: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
221 7fffffffbffffe40: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
222 7fffffffbffffe50: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
223 7fffffffbffffe60: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
224 7fffffffbffffe70: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
225 7fffffffbffffe80: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
226 7fffffffbffffe90: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
227 7fffffffbffffea0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
228 7fffffffbffffeb0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
229 7fffffffbffffec0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
230 7fffffffbffffed0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
231 7fffffffbffffee0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
232 7fffffffbffffef0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
233 7fffffffbfffff00: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
234 7fffffffbfffff10: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
235 7fffffffbfffff20: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
236 7fffffffbfffff30: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
237 7fffffffbfffff40: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
238 7fffffffbfffff50: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
239 7fffffffbfffff60: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
240 7fffffffbfffff70: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
241 7fffffffbfffff80: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
242 7fffffffbfffff90: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
243 7fffffffbfffffa0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
244 7fffffffbfffffb0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
245 7fffffffbfffffc0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
246 7fffffffbfffffd0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
247 7fffffffbfffffe0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................
248 7fffffffbffffff0: 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 ................" ]
250 echo "$0: unexpected memory:"
251 cat memory-largest-for-qemu.out