Introduce cacheextents filter
[nbdkit/ericb.git] / tests / test-data-file.sh
blob21dfdac8ddec7a367942ed841bb92dc5538bf21e
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 data plugin with an inline file.
35 source ./functions.sh
36 set -e
37 set -x
39 requires qemu-io --version
41 sock=`mktemp -u`
42 files="data-file.out data-file.pid $sock data-hello.txt"
43 rm -f $files
44 cleanup_fn rm -f $files
46 rm -f data-hello.txt
47 for i in {0..1000}; do
48 echo -n "hello " >> data-hello.txt
49 done
51 # Run nbdkit.
52 start_nbdkit -P data-file.pid -U $sock \
53 --filter=partition \
54 data partition=1 \
55 size=1M \
56 data="
57 @0x1b8 178 190 207 221 0 0 0 0 2 0 131 32 32 0 1 0 0 0 255 7
58 @0x1fe 85 170
59 @0x200 <data-hello.txt
62 # Since we're reading the empty first partition, any read returns zeroes.
63 qemu-io -r -f raw "nbd+unix://?socket=$sock" \
64 -c 'r -v 0 900' | grep -E '^[[:xdigit:]]+:' > data-file.out
65 if [ "$(cat data-file.out)" != "00000000: 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c hello.hello.hell
66 00000010: 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 o.hello.hello.he
67 00000020: 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 llo.hello.hello.
68 00000030: 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c hello.hello.hell
69 00000040: 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 o.hello.hello.he
70 00000050: 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 llo.hello.hello.
71 00000060: 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c hello.hello.hell
72 00000070: 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 o.hello.hello.he
73 00000080: 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 llo.hello.hello.
74 00000090: 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c hello.hello.hell
75 000000a0: 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 o.hello.hello.he
76 000000b0: 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 llo.hello.hello.
77 000000c0: 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c hello.hello.hell
78 000000d0: 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 o.hello.hello.he
79 000000e0: 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 llo.hello.hello.
80 000000f0: 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c hello.hello.hell
81 00000100: 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 o.hello.hello.he
82 00000110: 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 llo.hello.hello.
83 00000120: 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c hello.hello.hell
84 00000130: 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 o.hello.hello.he
85 00000140: 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 llo.hello.hello.
86 00000150: 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c hello.hello.hell
87 00000160: 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 o.hello.hello.he
88 00000170: 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 llo.hello.hello.
89 00000180: 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c hello.hello.hell
90 00000190: 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 o.hello.hello.he
91 000001a0: 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 llo.hello.hello.
92 000001b0: 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c hello.hello.hell
93 000001c0: 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 o.hello.hello.he
94 000001d0: 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 llo.hello.hello.
95 000001e0: 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c hello.hello.hell
96 000001f0: 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 o.hello.hello.he
97 00000200: 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 llo.hello.hello.
98 00000210: 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c hello.hello.hell
99 00000220: 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 o.hello.hello.he
100 00000230: 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 llo.hello.hello.
101 00000240: 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c hello.hello.hell
102 00000250: 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 o.hello.hello.he
103 00000260: 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 llo.hello.hello.
104 00000270: 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c hello.hello.hell
105 00000280: 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 o.hello.hello.he
106 00000290: 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 llo.hello.hello.
107 000002a0: 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c hello.hello.hell
108 000002b0: 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 o.hello.hello.he
109 000002c0: 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 llo.hello.hello.
110 000002d0: 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c hello.hello.hell
111 000002e0: 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 o.hello.hello.he
112 000002f0: 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 llo.hello.hello.
113 00000300: 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c hello.hello.hell
114 00000310: 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 o.hello.hello.he
115 00000320: 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 llo.hello.hello.
116 00000330: 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c hello.hello.hell
117 00000340: 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 o.hello.hello.he
118 00000350: 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 llo.hello.hello.
119 00000360: 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c hello.hello.hell
120 00000370: 6f 20 68 65 6c 6c 6f 20 68 65 6c 6c 6f 20 68 65 o.hello.hello.he
121 00000380: 6c 6c 6f 20 llo." ]
122 then
123 echo "$0: unexpected pattern:"
124 cat data-file.out
125 exit 1