File: Integrity_-_Large_file_support.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 (82 lines) | stat: -rwxr-xr-x 3,202 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
#!/bin/sh
#
# Make sure that files larger than 2GB are supported.

# 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'}"

# Check there is enough free space for this test.
workFile1Dir="${workFile1%/*}"
workFile1FreeKiB=$(df -kP "${workFile1Dir}" | sed -n '$p' | awk '{print $(NF-2)}')
test -n "${workFile1FreeKiB}" || workFile1FreeKiB=0
if ! test "${workFile1FreeKiB}" -gt 3300000 2>/dev/null; then
	echo "test requires at least 3GB free on ${workFile1Dir}"
	exit 77
fi

# Generate a 3GB sparse file - we don't really need 3GB of free space unless
# sparse files are not supported.
true > "${workFile1}"
if ! dd if="/dev/zero" of="${workFile1}" count=1 bs=1048576 seek=3072 2>/dev/null; then
	echo "failed to create 3GB specimen file"
	exit 77
fi

# NB the "stat" command is not portable - BSD stat(1) has a different syntax
# to GNU stat(1) - so we have to parse the output of ls(1).
# shellcheck disable=SC2012
fileSize=$(ls -nl "${workFile1}" 2>/dev/null | awk '{print $5}')
test -n "${fileSize}" || fileSize=0
if ! test "${fileSize}" -gt 3000000; then
	echo "failed to validate specimen file size"
	exit 77
fi

# Transfer the file, and count how many bytes came through.
bytesTransferred=$("${testSubject}" -n -b "${workFile1}" 2>"${workFile2}" | wc -c 2>/dev/null | tr -dc '0-9')
test -n "${bytesTransferred}" || bytesTransferred=0
bytesReported=$(sed -n '$p' "${workFile2}" | tr -dc '0-9')
test -n "${bytesReported}" || bytesReported=0
if ! test "${bytesTransferred}" -eq "${fileSize}"; then
	echo "transferred ${bytesTransferred} of ${fileSize} bytes"
	exit 1
fi
if ! test "${bytesReported}" -eq "${fileSize}"; then
	echo "counted ${bytesReported} of ${fileSize} bytes"
	exit 1
fi

# Transfer the file from stdin, and count how many bytes came through.
bytesTransferred=$("${testSubject}" -n -b < "${workFile1}" 2>"${workFile2}" | wc -c 2>/dev/null | tr -dc '0-9')
test -n "${bytesTransferred}" || bytesTransferred=0
bytesReported=$(sed -n '$p' "${workFile2}" | tr -dc '0-9')
test -n "${bytesReported}" || bytesReported=0
if ! test "${bytesTransferred}" -eq "${fileSize}"; then
	echo "stdin - transferred ${bytesTransferred} of ${fileSize} bytes"
	exit 1
fi
if ! test "${bytesReported}" -eq "${fileSize}"; then
	echo "stdin - counted ${bytesReported} of ${fileSize} bytes"
	exit 1
fi

# Use the file as a size value and transfer its size of bytes from dev/zero,
# and count how many bytes came through.
bytesTransferred=$("${testSubject}" -n -b -S -s "@${workFile1}" /dev/zero 2>"${workFile2}" | wc -c 2>/dev/null | tr -dc '0-9')
test -n "${bytesTransferred}" || bytesTransferred=0
bytesReported=$(sed -n '$p' "${workFile2}" | tr -dc '0-9')
test -n "${bytesReported}" || bytesReported=0
if ! test "${bytesTransferred}" -eq "${fileSize}"; then
	echo "size read - transferred ${bytesTransferred} of ${fileSize} bytes"
	exit 1
fi
if ! test "${bytesReported}" -eq "${fileSize}"; then
	echo "size read - counted ${bytesReported} of ${fileSize} bytes"
	exit 1
fi

exit 0