File: test-pattern.sh

package info (click to toggle)
libnbd 1.22.5-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,636 kB
  • sloc: ansic: 53,855; ml: 12,311; sh: 8,499; python: 4,595; makefile: 2,902; perl: 165; cpp: 24
file content (101 lines) | stat: -rwxr-xr-x 4,210 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/env bash
# nbd client library in userspace
# Copyright Red Hat
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

# Use nbdkit-pattern-plugin to test we can read from the correct place
# in the file, essentially a test of data integrity.

. ../tests/functions.sh

set -e
set -x

requires_fuse
requires $DD --version
requires $DD iflag=count_bytes,skip_bytes </dev/null
requires hexdump -C /dev/null
requires $NBDKIT --version
requires $NBDKIT pattern --version

# Difficult to arrange for this test to be run this test under
# valgrind, so don't bother.
if [ "x$LIBNBD_VALGRIND" = "x1" ]; then
    echo "$0: test skipped under valgrind"
    exit 77
fi

mp=test-pattern.d
out=test-pattern.out
pidfile=test-pattern.pid
cleanup_fn fusermount3 -u $mp
cleanup_fn rm -rf $mp $out $pidfile

mkdir $mp
$VG nbdfuse -P $pidfile $mp [ $NBDKIT --exit-with-parent pattern size=1G ] &
wait_for_pidfile nbdfuse $pidfile

ls -al $mp

# Read from various places in the file and ensure what we read is
# correct.
$DD if=$mp/nbd skip=4096 count=128 iflag=count_bytes,skip_bytes |
    hexdump -C > $out
cat $out
if [ "$(cat $out)" != '00000000  00 00 00 00 00 00 10 00  00 00 00 00 00 00 10 08  |................|
00000010  00 00 00 00 00 00 10 10  00 00 00 00 00 00 10 18  |................|
00000020  00 00 00 00 00 00 10 20  00 00 00 00 00 00 10 28  |....... .......(|
00000030  00 00 00 00 00 00 10 30  00 00 00 00 00 00 10 38  |.......0.......8|
00000040  00 00 00 00 00 00 10 40  00 00 00 00 00 00 10 48  |.......@.......H|
00000050  00 00 00 00 00 00 10 50  00 00 00 00 00 00 10 58  |.......P.......X|
00000060  00 00 00 00 00 00 10 60  00 00 00 00 00 00 10 68  |.......`.......h|
00000070  00 00 00 00 00 00 10 70  00 00 00 00 00 00 10 78  |.......p.......x|
00000080' ]; then
    echo "$0: error: pattern data did not match expected"
    exit 1
fi

$DD if=$mp/nbd skip=1000000 count=128 iflag=count_bytes,skip_bytes |
    hexdump -C > $out
cat $out
if [ "$(cat $out)" != '00000000  00 00 00 00 00 0f 42 40  00 00 00 00 00 0f 42 48  |......B@......BH|
00000010  00 00 00 00 00 0f 42 50  00 00 00 00 00 0f 42 58  |......BP......BX|
00000020  00 00 00 00 00 0f 42 60  00 00 00 00 00 0f 42 68  |......B`......Bh|
00000030  00 00 00 00 00 0f 42 70  00 00 00 00 00 0f 42 78  |......Bp......Bx|
00000040  00 00 00 00 00 0f 42 80  00 00 00 00 00 0f 42 88  |......B.......B.|
00000050  00 00 00 00 00 0f 42 90  00 00 00 00 00 0f 42 98  |......B.......B.|
00000060  00 00 00 00 00 0f 42 a0  00 00 00 00 00 0f 42 a8  |......B.......B.|
00000070  00 00 00 00 00 0f 42 b0  00 00 00 00 00 0f 42 b8  |......B.......B.|
00000080' ]; then
    echo "$0: error: pattern data did not match expected"
    exit 1
fi

$DD if=$mp/nbd skip=0 count=128 iflag=count_bytes,skip_bytes |
    hexdump -C > $out
cat $out
if [ "$(cat $out)" != '00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 08  |................|
00000010  00 00 00 00 00 00 00 10  00 00 00 00 00 00 00 18  |................|
00000020  00 00 00 00 00 00 00 20  00 00 00 00 00 00 00 28  |....... .......(|
00000030  00 00 00 00 00 00 00 30  00 00 00 00 00 00 00 38  |.......0.......8|
00000040  00 00 00 00 00 00 00 40  00 00 00 00 00 00 00 48  |.......@.......H|
00000050  00 00 00 00 00 00 00 50  00 00 00 00 00 00 00 58  |.......P.......X|
00000060  00 00 00 00 00 00 00 60  00 00 00 00 00 00 00 68  |.......`.......h|
00000070  00 00 00 00 00 00 00 70  00 00 00 00 00 00 00 78  |.......p.......x|
00000080' ]; then
    echo "$0: error: pattern data did not match expected"
    exit 1
fi