tests: vsock: Use VMADDR_CID_LOCAL for loopback testing.
[nbdkit/ericb.git] / tests / test-parallel-file.sh
blob20276d48a45205690b196f8ebee280ccc1e25b79
1 #!/usr/bin/env bash
2 # nbdkit
3 # Copyright (C) 2017-2019 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 source ./functions.sh
35 # Check file-data was created by Makefile and qemu-io exists.
36 requires test -f file-data
37 requires qemu-io --version
39 nbdkit --dump-plugin file | grep -q ^thread_model=parallel ||
40 { echo "nbdkit lacks support for parallel requests"; exit 77; }
42 cleanup_fn rm -f test-parallel-file.data test-parallel-file.out
44 # Populate file, and sanity check that qemu-io can issue parallel requests
45 printf '%1024s' . > test-parallel-file.data
46 qemu-io -f raw -c "aio_write -P 1 0 512" -c "aio_write -P 2 512 512" \
47 -c aio_flush test-parallel-file.data ||
48 { echo "'qemu-io' can't drive parallel requests"; exit 77; }
50 # Set up the file plugin to delay both reads and writes (for a good chance
51 # that parallel requests are in flight), and with writes longer than reads
52 # (to more easily detect if out-of-order completion happens). This test
53 # may have spurious failures under heavy loads on the test machine, where
54 # tuning the delays may help.
56 # With --threads=1, the write should complete first because it was issued first
57 nbdkit -v -t 1 -U - --filter=delay file test-parallel-file.data \
58 wdelay=2 rdelay=1 --run 'qemu-io -f raw -c "aio_write -P 2 512 512" \
59 -c "aio_read -P 1 0 512" -c aio_flush $nbd' |
60 tee test-parallel-file.out
61 if test "$(grep '512/512' test-parallel-file.out)" != \
62 "wrote 512/512 bytes at offset 512
63 read 512/512 bytes at offset 0"; then
64 exit 1
67 # With default --threads, the faster read should complete first
68 nbdkit -v -U - --filter=delay file test-parallel-file.data \
69 wdelay=2 rdelay=1 --run 'qemu-io -f raw -c "aio_write -P 2 512 512" \
70 -c "aio_read -P 1 0 512" -c aio_flush $nbd' |
71 tee test-parallel-file.out
72 if test "$(grep '512/512' test-parallel-file.out)" != \
73 "read 512/512 bytes at offset 0
74 wrote 512/512 bytes at offset 512"; then
75 exit 1
78 # With --filter=noparallel, the write should complete first because it was issued first
79 nbdkit -v -U - --filter=noparallel --filter=delay file test-parallel-file.data \
80 wdelay=2 rdelay=1 --run 'qemu-io -f raw -c "aio_write -P 2 512 512" \
81 -c "aio_read -P 1 0 512" -c aio_flush $nbd' |
82 tee test-parallel-file.out
83 if test "$(grep '512/512' test-parallel-file.out)" != \
84 "wrote 512/512 bytes at offset 512
85 read 512/512 bytes at offset 0"; then
86 exit 1
89 exit 0