grep-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Grep-devel] FYI: [PATCH] tests: stack-overflow: avoid false failure


From: Jim Meyering
Subject: [Grep-devel] FYI: [PATCH] tests: stack-overflow: avoid false failure
Date: Sat, 24 Nov 2018 13:36:04 -1000

I noticed a spurious failure on OS X, so fixed it with this:

> From 2725f1ee63e60da75a3884bcd6363ef6dbe9a39f Mon Sep 17 00:00:00 2001
From: Jim Meyering <address@hidden>
Date: Sat, 24 Nov 2018 12:17:05 -1000
Subject: [PATCH] tests: stack-overflow: avoid false failure

* tests/stack-overflow: This test would fail to elicit a stack overflow
diagnostic on some OS X systems. Rewrite to iterate, gradually increasing
the size of the input regex, stopping when grep emits the desired diagnostic
or the size reaches a reasonable limit.
---
 tests/stack-overflow | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/tests/stack-overflow b/tests/stack-overflow
index 2042ebc..6922045 100755
--- a/tests/stack-overflow
+++ b/tests/stack-overflow
@@ -3,14 +3,23 @@

 . "${srcdir=.}/init.sh"; path_prepend_ ../src

-# Too many open parentheses.
-printf %080000d 0|tr 0 '(' > in || framework_failure_
 echo grep: stack overflow > exp || framework_failure_

+# grep attempts to detect overflow via gnulib's c-stack module.
+# Trigger that with an input regex composed solely of open parentheses,
+# increasing the size of that input until grep emits the expected diagnostic.
 fail=0
-returns_ 2 grep -E -f in >out 2>err || fail=1
+for i in 1 3 5 10 20 30 40 50 100 200; do
+  # Create a file containing $i * 10000 open parentheses:
+  printf %0${i}0000d 0|tr 0 '(' > in || framework_failure_
+  grep -E -f in >out 2>err; st=$?
+  if grep -q 'stack overflow' err; then
+    test $st = 2 || fail=1
+    compare /dev/null out || fail=1
+    compare exp err || fail=1
+    test $fail = 0 && Exit 0
+    fail_ 'printed "stack overflow", but something else was wrong'
+  fi
+done

-compare /dev/null out || fail=1
-compare exp err || fail=1
-
-Exit $fail
+fail_ 'grep never printed "stack overflow"'



reply via email to

[Prev in Thread] Current Thread [Next in Thread]