File: Modifiers_-_--size_from_dir_size.test

package info (click to toggle)
pv 1.10.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,112 kB
  • sloc: ansic: 8,465; sh: 7,034; makefile: 132; sed: 39
file content (67 lines) | stat: -rwxr-xr-x 1,980 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
#!/bin/sh
#
# Similar to the "--size" check but, instead, using directory's size with
# "--size @".

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

# Process 100 bytes at 100 bytes per second, interval 0.1 seconds, with the
# size set from a directory containing 10 files of $1/10 bytes, and
# expecting a percentage of $2 at the end.
sizeCheck () {
	# Make a directory containing 10 files of $1/10 bytes each.
	rm -rf "${workFile2}"
	mkdir "${workFile2}"
	mkdir "${workFile2}/subdir"
	s="$1"
	s=$((s/10))
	for f in 1 2 3 4 5; do
		dd if=/dev/zero bs="$s" count=1 2>/dev/null >"${workFile2}/$f"
		dd if=/dev/zero bs="$s" count=1 2>/dev/null >"${workFile2}/subdir/$f"
	done

	# Run 100 bytes through the program, using the reference directory's
	# total size as the percentage reference.
	dd if=/dev/zero bs=100 count=1 2>/dev/null \
	| "${testSubject}" -s "@${workFile2}" -n -i 0.1 -L 100 >/dev/null 2>"${workFile1}"

	# If "-s @<directory>" is unsupported, skip the test.
	if test $? -eq 64; then
		rm -rf "${workFile2}"
		echo 'not available on this build'
		exit 77
	fi

	rm -rf "${workFile2}"

	lineCount=$(wc -l < "${workFile1}" | tr -dc '0-9')
	finalLine=$(sed -n '$p' < "${workFile1}")

	# The number of output lines should be >5 and <13, and the final
	# percentage should be $2.
	#
	if ! test "${lineCount}" -gt 5; then
		echo "(reference size=$1) fewer than 6 output lines (${lineCount})"
		exit 1
	fi
	if ! test "${lineCount}" -lt 13; then
		echo "(reference size=$1) more than 12 output lines (${lineCount})"
		exit 1
	fi
	if ! test "${finalLine}" = "$2"; then
		echo "(reference size=$1): final percentage was not $2 (${finalLine})"
		cat "${workFile1}"
		exit 1
	fi
}

sizeCheck 100 100
sizeCheck 200 50
sizeCheck 50 200

exit 0