file: Add an internal "mode"
[nbdkit.git] / tests / test-parallel-nbd.sh
blobca93fd3528a2e194b4107d52809403f153d7e257
1 #!/usr/bin/env bash
2 # nbdkit
3 # Copyright (C) 2017-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 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
38 requires timeout 60s true
40 nbdkit --dump-plugin nbd | grep -q ^thread_model=parallel ||
41 { echo "nbdkit lacks support for parallel requests"; exit 77; }
43 sock=$(mktemp -u /tmp/nbdkit-test-sock.XXXXXX)
44 files="test-parallel-nbd.out $sock test-parallel-nbd.data test-parallel-nbd.pid"
45 rm -f $files
46 cleanup_fn rm -f $files
48 # Populate file, and sanity check that qemu-io can issue parallel requests
49 printf '%1024s' . > test-parallel-nbd.data
50 timeout 30s </dev/null qemu-io -f raw -c "aio_write -P 1 0 512" \
51 -c "aio_write -P 2 512 512" -c aio_flush test-parallel-nbd.data ||
52 { echo "'qemu-io' can't drive parallel requests"; exit 77; }
54 # Set up the file plugin to delay both reads and writes (for a good chance
55 # that parallel requests are in flight), and with writes longer than reads
56 # (to more easily detect if out-of-order completion happens). This test
57 # may have spurious failures under heavy loads on the test machine, where
58 # tuning the delays may help.
60 start_nbdkit -P test-parallel-nbd.pid \
61 -U $sock \
62 --filter=delay \
63 file test-parallel-nbd.data wdelay=2 rdelay=1
65 # With --threads=1, the write should complete first because it was issued first
66 nbdkit -v -t 1 -U - nbd socket=$sock --run '
67 timeout 60s </dev/null qemu-io -f raw \
68 -c "aio_write -P 2 512 512" -c "aio_read -P 1 0 512" \
69 -c aio_flush $nbd' | tee test-parallel-nbd.out
70 if test "$(grep '512/512' test-parallel-nbd.out)" != \
71 "wrote 512/512 bytes at offset 512
72 read 512/512 bytes at offset 0"; then
73 exit 1
76 # With default --threads, the faster read should complete first
77 nbdkit -v -U - nbd socket=$sock --run '
78 timeout 60s </dev/null qemu-io -f raw \
79 -c "aio_write -P 2 512 512" -c "aio_read -P 1 0 512" \
80 -c aio_flush $nbd' | tee test-parallel-nbd.out
81 if test "$(grep '512/512' test-parallel-nbd.out)" != \
82 "read 512/512 bytes at offset 0
83 wrote 512/512 bytes at offset 512"; then
84 exit 1