tests: vsock: Use VMADDR_CID_LOCAL for loopback testing.
[nbdkit/ericb.git] / tests / test-extentlist.sh
blob73ce3ca6de7a78639a04ad0e9b127b0582d91474
1 #!/usr/bin/env bash
2 # nbdkit
3 # Copyright (C) 2016-2020 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 extentlist filter.
35 source ./functions.sh
36 set -e
37 set -x
39 requires jq --version
40 requires qemu-img --version
41 requires qemu-img map --help
43 out=test-extentlist.out
44 input=test-extentlist.in
45 expected=test-extentlist.expected
46 files="$out $input $expected"
47 rm -f $files
48 cleanup_fn rm $files
50 test ()
52 nbdkit -v -D extentlist.lookup=1 \
53 -r -U - \
54 --filter=extentlist \
55 null size=$1 extentlist=$input \
56 --run 'qemu-img map -f raw --output=json $nbd' |
57 jq -c '.[] | {start:.start, length:.length, data:.data, zero:.zero}' \
58 > $out
59 diff -u $out $expected
62 # Empty extent list.
63 cat > $input <<'EOF'
64 EOF
66 cat > $expected <<'EOF'
67 {"start":0,"length":0,"data":false,"zero":false}
68 EOF
69 test 0
70 cat > $expected <<'EOF'
71 {"start":0,"length":1048576,"data":false,"zero":true}
72 EOF
73 test 1M
75 # Extent list covering 0-1M with data.
76 cat > $input <<'EOF'
77 0 1M
78 EOF
80 cat > $expected <<'EOF'
81 {"start":0,"length":0,"data":false,"zero":false}
82 EOF
83 test 0
84 cat > $expected <<'EOF'
85 {"start":0,"length":1048576,"data":true,"zero":false}
86 EOF
87 test 1M
89 # Extent list covering 1-2M with data.
90 cat > $input <<'EOF'
91 1M 1M
92 EOF
94 cat > $expected <<'EOF'
95 {"start":0,"length":0,"data":false,"zero":false}
96 EOF
97 test 0
98 cat > $expected <<'EOF'
99 {"start":0,"length":1048576,"data":false,"zero":true}
101 test 1M
102 cat > $expected <<'EOF'
103 {"start":0,"length":1048576,"data":false,"zero":true}
104 {"start":1048576,"length":1048576,"data":true,"zero":false}
106 test 2M
107 cat > $expected <<'EOF'
108 {"start":0,"length":1048576,"data":false,"zero":true}
109 {"start":1048576,"length":1048576,"data":true,"zero":false}
110 {"start":2097152,"length":1048576,"data":false,"zero":true}
112 test 3M
114 # Extent list covering 1-2M with data, but in a more fragmented
115 # way than the above.
116 cat > $input <<'EOF'
117 1024K 512K
118 1536K 512K
121 cat > $expected <<'EOF'
122 {"start":0,"length":0,"data":false,"zero":false}
124 test 0
125 cat > $expected <<'EOF'
126 {"start":0,"length":1048576,"data":false,"zero":true}
128 test 1M
129 cat > $expected <<'EOF'
130 {"start":0,"length":1048576,"data":false,"zero":true}
131 {"start":1048576,"length":1048576,"data":true,"zero":false}
133 test 2M
134 cat > $expected <<'EOF'
135 {"start":0,"length":1048576,"data":false,"zero":true}
136 {"start":1048576,"length":1048576,"data":true,"zero":false}
137 {"start":2097152,"length":1048576,"data":false,"zero":true}
139 test 3M
141 # Adjacent data and holes.
142 cat > $input <<'EOF'
143 0 1M
144 2M 1M
145 4M 1M
148 cat > $expected <<'EOF'
149 {"start":0,"length":0,"data":false,"zero":false}
151 test 0
152 cat > $expected <<'EOF'
153 {"start":0,"length":1048576,"data":true,"zero":false}
155 test 1M
156 cat > $expected <<'EOF'
157 {"start":0,"length":1048576,"data":true,"zero":false}
158 {"start":1048576,"length":1048576,"data":false,"zero":true}
160 test 2M
161 cat > $expected <<'EOF'
162 {"start":0,"length":1048576,"data":true,"zero":false}
163 {"start":1048576,"length":1048576,"data":false,"zero":true}
164 {"start":2097152,"length":1048576,"data":true,"zero":false}
166 test 3M
167 cat > $expected <<'EOF'
168 {"start":0,"length":1048576,"data":true,"zero":false}
169 {"start":1048576,"length":1048576,"data":false,"zero":true}
170 {"start":2097152,"length":1048576,"data":true,"zero":false}
171 {"start":3145728,"length":1048576,"data":false,"zero":true}
172 {"start":4194304,"length":1048576,"data":true,"zero":false}
173 {"start":5242880,"length":1048576,"data":false,"zero":true}
175 test 6M