Debian Codegraph @

tests/big-match

raw
1 #!/bin/sh
2 # Check that grep doesn't mishandle long matching lines.
3
4 . "${srcdir=.}/init.sh"; path_prepend_ ../src
5 expensive_
6
7 # Create a one-line file containing slightly more than 2 GiB.
8 echo x | dd bs=1024k seek=2048 >2G-plus-2 || framework_failure_
9
10 skip_diagnostic=
11
12 # These two patterns catch different kinds of
13 # failures due to internal integer overflows.
14 # However, the second one, '^.*x\(\)\1', provokes
15 # so much memory consumption via regexec.c that it renders
16 # some systems unusable.
17 for pattern in '^.*'; do
18 diagnostic=$(LC_ALL=C grep -a "$pattern" 2G-plus-2 2>&1 >/dev/null)
19 status=$?
20
21 case $status,$diagnostic in
22 0,*) ;;
23 2,*': line too long for re_search')
24 skip_diagnostic='regular expression library cannot handle the test' ;;
25 137,''|2,*': memory exhausted')
26 # The 137/no-diagnostic arises when the kernel OOM-kills grep.
27 skip_diagnostic='not enough main memory to run the test' ;;
28 *) fail=1 ;;
29 esac
30 done
31
32 case $fail,$skip_diagnostic in
33 0,?*) skip_ "$skip_diagnostic" ;;
34 esac
35
36 Exit $fail