tests: Enhance retry test to cover failed reopen
[nbdkit/ericb.git] / tests / test-pattern.sh
blobf37369316f868cc62edbf34c10a58f5b6f01fbae
1 #!/usr/bin/env bash
2 # nbdkit
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
7 # met:
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
31 # SUCH DAMAGE.
33 # Test the pattern plugin.
35 # Note we don't have any client which can issue misaligned NBD
36 # requests. qemu-io will issue 512-byte aligned requests no matter
37 # what read parameters we give it. Hence these tests are rather
38 # limited. (XXX)
40 source ./functions.sh
41 set -e
43 sock=`mktemp -u`
44 files="pattern.out pattern.pid $sock"
45 rm -f $files
46 cleanup_fn rm -f $files
48 # Test that qemu-io works
49 if ! qemu-io --help >/dev/null; then
50 echo "$0: missing or broken qemu-io"
51 exit 77
54 # Run nbdkit with pattern plugin.
55 start_nbdkit -P pattern.pid -U $sock pattern 1G
57 qemu-io -r -f raw "nbd+unix://?socket=$sock" \
58 -c 'r -v 0 512' | grep -E '^[[:xdigit:]]+:' > pattern.out
59 if [ "$(cat pattern.out)" != "00000000: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 ................
60 00000010: 00 00 00 00 00 00 00 10 00 00 00 00 00 00 00 18 ................
61 00000020: 00 00 00 00 00 00 00 20 00 00 00 00 00 00 00 28 ................
62 00000030: 00 00 00 00 00 00 00 30 00 00 00 00 00 00 00 38 .......0.......8
63 00000040: 00 00 00 00 00 00 00 40 00 00 00 00 00 00 00 48 ...............H
64 00000050: 00 00 00 00 00 00 00 50 00 00 00 00 00 00 00 58 .......P.......X
65 00000060: 00 00 00 00 00 00 00 60 00 00 00 00 00 00 00 68 ...............h
66 00000070: 00 00 00 00 00 00 00 70 00 00 00 00 00 00 00 78 .......p.......x
67 00000080: 00 00 00 00 00 00 00 80 00 00 00 00 00 00 00 88 ................
68 00000090: 00 00 00 00 00 00 00 90 00 00 00 00 00 00 00 98 ................
69 000000a0: 00 00 00 00 00 00 00 a0 00 00 00 00 00 00 00 a8 ................
70 000000b0: 00 00 00 00 00 00 00 b0 00 00 00 00 00 00 00 b8 ................
71 000000c0: 00 00 00 00 00 00 00 c0 00 00 00 00 00 00 00 c8 ................
72 000000d0: 00 00 00 00 00 00 00 d0 00 00 00 00 00 00 00 d8 ................
73 000000e0: 00 00 00 00 00 00 00 e0 00 00 00 00 00 00 00 e8 ................
74 000000f0: 00 00 00 00 00 00 00 f0 00 00 00 00 00 00 00 f8 ................
75 00000100: 00 00 00 00 00 00 01 00 00 00 00 00 00 00 01 08 ................
76 00000110: 00 00 00 00 00 00 01 10 00 00 00 00 00 00 01 18 ................
77 00000120: 00 00 00 00 00 00 01 20 00 00 00 00 00 00 01 28 ................
78 00000130: 00 00 00 00 00 00 01 30 00 00 00 00 00 00 01 38 .......0.......8
79 00000140: 00 00 00 00 00 00 01 40 00 00 00 00 00 00 01 48 ...............H
80 00000150: 00 00 00 00 00 00 01 50 00 00 00 00 00 00 01 58 .......P.......X
81 00000160: 00 00 00 00 00 00 01 60 00 00 00 00 00 00 01 68 ...............h
82 00000170: 00 00 00 00 00 00 01 70 00 00 00 00 00 00 01 78 .......p.......x
83 00000180: 00 00 00 00 00 00 01 80 00 00 00 00 00 00 01 88 ................
84 00000190: 00 00 00 00 00 00 01 90 00 00 00 00 00 00 01 98 ................
85 000001a0: 00 00 00 00 00 00 01 a0 00 00 00 00 00 00 01 a8 ................
86 000001b0: 00 00 00 00 00 00 01 b0 00 00 00 00 00 00 01 b8 ................
87 000001c0: 00 00 00 00 00 00 01 c0 00 00 00 00 00 00 01 c8 ................
88 000001d0: 00 00 00 00 00 00 01 d0 00 00 00 00 00 00 01 d8 ................
89 000001e0: 00 00 00 00 00 00 01 e0 00 00 00 00 00 00 01 e8 ................
90 000001f0: 00 00 00 00 00 00 01 f0 00 00 00 00 00 00 01 f8 ................" ]
91 then
92 echo "$0: unexpected pattern:"
93 cat pattern.out
94 exit 1