| 1 |
#!/bin/sh |
| 2 |
# grep-2.21 would incur a 100x penalty for 10x increase in regexp length |
| 3 |
|
| 4 |
# Copyright 2015-2025 Free Software Foundation, Inc. |
| 5 |
|
| 6 |
# This program is free software: you can redistribute it and/or modify |
| 7 |
# it under the terms of the GNU General Public License as published by |
| 8 |
# the Free Software Foundation, either version 3 of the License, or |
| 9 |
# (at your option) any later version. |
| 10 |
|
| 11 |
# This program is distributed in the hope that it will be useful, |
| 12 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 |
# GNU General Public License for more details. |
| 15 |
|
| 16 |
# You should have received a copy of the GNU General Public License |
| 17 |
# along with this program. If not, see <https://www.gnu.org/licenses/>. |
| 18 |
|
| 19 |
. "${srcdir=.}/init.sh"; path_prepend_ ../src |
| 20 |
|
| 21 |
fail=0 |
| 22 |
|
| 23 |
# This test is susceptible to failure due to differences in |
| 24 |
# system load during the two test runs, so we'll mark it as |
| 25 |
# "expensive", making it less likely to be run by regular users. |
| 26 |
expensive_ |
| 27 |
require_perl_ |
| 28 |
|
| 29 |
echo x > in || framework_failure_ |
| 30 |
# Note that we want 10x the byte count (not line count) in the larger file. |
| 31 |
seq 10000 50000 | tr -d '\012' > r || framework_failure_ |
| 32 |
cat r r r r r r r r r r > re-10x || framework_failure_ |
| 33 |
mv r re || framework_failure_ |
| 34 |
|
| 35 |
returns_ 0 user_time_ 1 grep -f re in > base-ms \ |
| 36 |
|| framework_failure_ 'failed to compute baseline timing' |
| 37 |
base_ms=$(cat base-ms) |
| 38 |
|
| 39 |
# This test caused trouble on at least two types of fringe hosts: those |
| 40 |
# with very little memory (a 1.5GB RAM Solaris host) and a Linux/s390x |
| 41 |
# (emulated with qemu-system-s390x). The former became unusable due to |
| 42 |
# mem requirements of the 2nd test, and the latter ended up taking >35x |
| 43 |
# more time than the base case. Skipping this test for any system using |
| 44 |
# more than this many milliseconds for the first case should avoid those |
| 45 |
# false-positive failures while skipping the test on few other systems. |
| 46 |
test 800 -lt "$base_ms" && skip_ "this base-case test took too long" |
| 47 |
|
| 48 |
returns_ 0 user_time_ 1 grep -f re-10x in > b10x-ms \ |
| 49 |
|| framework_failure_ 'failed to compute 10x timing' |
| 50 |
b10x_ms=$(cat b10x-ms) |
| 51 |
|
| 52 |
# Increasing the length of the regular expression by a factor |
| 53 |
# of 10 should cause no more than a 10x increase in duration. |
| 54 |
# However, we'll draw the line at 20x to avoid false-positives. |
| 55 |
returns_ 1 expr $base_ms '<' $b10x_ms / 20 || fail=1 |
| 56 |
|
| 57 |
Exit $fail |