Revert "ci: skip "lib/test-fork-safe-execvpe.sh" on Alpine Linux"
[libnbd.git] / copy / copy-nbd-to-nbd.sh
blobb04b76995262a1c2c864378488cb10ed6452b288
1 #!/usr/bin/env bash
2 # nbd client library in userspace
3 # Copyright Red Hat
5 # This library is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation; either
8 # version 2 of the License, or (at your option) any later version.
10 # This library is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with this library; if not, write to the Free Software
17 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19 . ../tests/functions.sh
21 set -e
22 set -x
24 requires nbdkit --exit-with-parent --version
25 requires cmp /dev/null /dev/null
26 requires hexdump -C /dev/null
28 pidfile1=copy-nbd-to-nbd.pid1
29 pidfile2=copy-nbd-to-nbd.pid2
30 file1=copy-nbd-to-nbd.file1
31 file2=copy-nbd-to-nbd.file2
32 sock1=$(mktemp -u /tmp/libnbd-test-copy.XXXXXX)
33 sock2=$(mktemp -u /tmp/libnbd-test-copy.XXXXXX)
34 cleanup_fn rm -f $pidfile1 $pidfile2 $file1 $file2 $sock1 $sock2
36 nbdkit --exit-with-parent -f -v -P $pidfile1 -U $sock1 pattern size=10M &
37 # Wait for the pidfile to appear.
38 for i in {1..60}; do
39 if test -f $pidfile1; then
40 break
42 sleep 1
43 done
44 if ! test -f $pidfile1; then
45 echo "$0: nbdkit did not start up"
46 exit 1
49 nbdkit --exit-with-parent -f -v -P $pidfile2 -U $sock2 memory size=10M &
50 # Wait for the pidfile to appear.
51 for i in {1..60}; do
52 if test -f $pidfile2; then
53 break
55 sleep 1
56 done
57 if ! test -f $pidfile2; then
58 echo "$0: nbdkit did not start up"
59 exit 1
62 $VG nbdcopy "nbd+unix:///?socket=$sock1" "nbd+unix:///?socket=$sock2"
64 # Download the file from both servers and check they are the same.
65 $VG nbdcopy "nbd+unix:///?socket=$sock1" $file1
66 $VG nbdcopy "nbd+unix:///?socket=$sock2" $file2
68 ls -l $file1 $file2
69 cmp $file1 $file2
71 # Test the data is at least non-zero.
72 test "$(hexdump -C $file1 | head -1)" = "00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 08 |................|"