File: Sparse_-_Basic.test

package info (click to toggle)
pv 1.10.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,076 kB
  • sloc: ansic: 8,421; sh: 6,426; makefile: 131; sed: 16
file content (89 lines) | stat: -rwxr-xr-x 2,894 bytes parent folder | download
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
#!/bin/sh
#
# Transfer a large chunk of data through pv using pipes, sending it in a
# bursty fashion, and make sure some of it consists of blocks of null bytes. 
# Check data correctness afterwards, and if dd can produce a sparse file,
# check that pv's output is also sparse.

# Allow all tests to be skipped, e.g. during a release build
test "${SKIP_ALL_TESTS}" = "1" && exit 77

true "${testSubject:?not set - call this from 'make check'}"
true "${workFile1:?not set - call this from 'make check'}"
true "${workFile2:?not set - call this from 'make check'}"
true "${workFile3:?not set - call this from 'make check'}"

# generate some data, with a hole in the middle.
dd if=/dev/urandom of="${workFile1}" bs=4096 count=640 2>/dev/null
dd if=/dev/null of="${workFile1}" bs=4096 count=0 seek=1280 2>/dev/null
dd if=/dev/urandom of="${workFile1}" bs=4096 count=1280 seek=1280 2>/dev/null

# check that sparse files are supported.
cat < "${workFile1}" > "${workFile3}"
inputBlocks="$(ls -1s "${workFile1}" | awk '{print $1}')"
nonSparseBlocks="$(ls -1s "${workFile3}" | awk '{print $1}')"
if test "${inputBlocks}" -eq "${nonSparseBlocks}"; then
	echo 'sparse files not supported'
	exit 77
fi

inputChecksum=$(cksum "${workFile1}" | awk '{print $1}')

# read through pv and test afterwards
(
dd if="${workFile1}" bs=1 count=9000
sleep 1
dd if="${workFile1}" bs=1 skip=9000 count=1240
sleep 1
dd if="${workFile1}" bs=1024 skip=10 count=1014
sleep 1
dd if="${workFile1}" bs=1024 skip=1024 count=1024
sleep 1
dd if="${workFile1}" bs=1024 skip=2048
) 2>/dev/null | "${testSubject}" -q -O -L 2M | cat > "${workFile2}"

outputChecksum=$(cksum "${workFile2}" | awk '{print $1}')

if ! test "${inputChecksum}" = "${outputChecksum}"; then
	echo "checksum mismatch with dd | pv | cat"
	exit 1
fi

# same again but with one less pipe
(
dd if="${workFile1}" bs=1 count=9000
sleep 1
dd if="${workFile1}" bs=1 skip=9000 count=1240
sleep 1
dd if="${workFile1}" bs=1024 skip=10 count=1014
sleep 1
dd if="${workFile1}" bs=1024 skip=1024 count=1024
sleep 1
dd if="${workFile1}" bs=1024 skip=2048
) 2>/dev/null | "${testSubject}" -q -O -L 2M > "${workFile2}"

outputChecksum=$(cksum "${workFile2}" | awk '{print $1}')

if ! test "${inputChecksum}" = "${outputChecksum}"; then
	echo "checksum mismatch with dd | pv > file"
	exit 1
fi

outputBlocks="$(ls -1s "${workFile2}" | awk '{print $1}')"

# Note that we only check that the output has any holes at all (and that the
# input had holes).  We don't compare pv's output with dd's output directly,
# because the exact number of holes might differ intermittently.

if test "${nonSparseBlocks}" -gt "${inputBlocks}" && ! test "${outputBlocks}" -lt "${nonSparseBlocks}"; then
	echo "output is not sparse"
	echo "input file:"
	ls -ls "${workFile1}"
	echo "output file:"
	ls -ls "${workFile2}"
	echo "input file without holes:"
	ls -ls "${workFile3}"
	exit 1
fi

exit 0