| 1 |
#!/bin/sh |
| 2 |
# Check that grep --binary-file=without-match quickly skips files with holes. |
| 3 |
|
| 4 |
. "${srcdir=.}/init.sh"; path_prepend_ ../src |
| 5 |
|
| 6 |
expensive_ |
| 7 |
require_perl_ |
| 8 |
|
| 9 |
# Skip this test if there is no usable SEEK_HOLE support, |
| 10 |
# as is the case with linux-3.5.0 on ext4 and tmpfs file systems. |
| 11 |
$PERL -e '$f=*STDERR; sysseek($f,2**22,0); syswrite($f,"a");' \ |
| 12 |
-e 'exit ("0 but true" ne sysseek($f,0,4))' 2> seek-hole-test \ |
| 13 |
|| skip_ "this system/FS lacks SEEK_HOLE support" |
| 14 |
|
| 15 |
# Try to make this test not THAT expensive, on typical hosts. |
| 16 |
virtual_memory_KiB=10240 |
| 17 |
if echo x | (ulimit -v $virtual_memory_KiB && grep x) >/dev/null 2>&1; then |
| 18 |
ulimit -v $virtual_memory_KiB |
| 19 |
fi |
| 20 |
|
| 21 |
# Create a file that starts with at least a buffer's worth of text, |
| 22 |
# but has a big hole later. |
| 23 |
(${AWK-awk} 'BEGIN{ for (i=0;i<1000;i++) printf "%080d\n", 0 }' < /dev/null |
| 24 |
echo x | dd bs=1024k seek=8000000 |
| 25 |
) >8T-or-so || skip_ 'cannot create big sparse file' |
| 26 |
|
| 27 |
grep --binary-file=without-match x 8T-or-so >/dev/null |
| 28 |
test $? -eq 1 || fail=1 |
| 29 |
|
| 30 |
Exit $fail |