blob: 4d8ae26af2c0cb48d3da017250ff0ddd14e84046 (
plain) (
blame)
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
|
#!/bin/sh
printf '1..10\n'
set -e
holes() { "${HOLES:-./holes}" "$@"; }
zeroes() { dd if=/dev/zero bs=${2:-1} count=$1 2>/dev/null; }
nonzeroes() { zeroes $1 $2 | tr '\0' x; }
check_output() {
msg=$1
expected="$(cat)"
shift
if output="$(eval "$@" 2>&1)"; then
if [ "$output" = "$expected" ]; then
printf 'ok - %s\n' "$msg"
return
fi
fi
printf 'not ok - %s\n' "$msg"
if [ "$output" != "$expected" ]; then
printf 'Unexpected output:\n%s\n' "$output" | sed 's/^/# /'
fi
}
check_output 'no hole' 'echo foobar | holes' <<EOF
EOF
check_output 'big, no hole' 'nonzeroes 1 M | holes' <<EOF
EOF
check_output 'empty file' 'true | holes' <<EOF
00000000 0
EOF
check_output 'small holes' '{ nonzeroes 17; zeroes 35; nonzeroes 67; zeroes 67; } | holes -n1' <<EOF
00000011 35
00000077 67
EOF
check_output 'small, undetected holes' '{ nonzeroes 17; zeroes 35; nonzeroes 67; zeroes 63; } | holes' <<EOF
EOF
check_output 'medium holes' '{ zeroes 4 1k; nonzeroes 60 1k; zeroes 300 1k; nonzeroes 7 1k; } | holes' <<EOF
00000000 4096
00010000 307200
EOF
check_output 'medium, offsetted holes' '{ zeroes 4090; nonzeroes 60 1k; zeroes 307117; nonzeroes 7 1k; } | holes' <<EOF
00000000 4090
0000fffa 307117
EOF
check_output 'huge holes' '{ zeroes 5 M; nonzeroes 7 M; zeroes 7 M; } | holes' <<EOF
00000000 5242880
00c00000 7340032
EOF
check_output 'huge, offsetted holes' '{ nonzeroes 3636; zeroes 5 M; nonzeroes 7 M; zeroes 7 M; } | holes' <<EOF
00000e34 5242880
00c00e34 7340032
EOF
check_output 'detect non-zeroes' '{ nonzeroes 3636; zeroes 5 M; nonzeroes 7 M; zeroes 7 M; } | tr "\\0" "\\377" | holes -b 0xff' <<EOF
00000e34 5242880
00c00e34 7340032
EOF
|