From 8d54176c0a345955f630778fa48269d1f3ff7ca8 Mon Sep 17 00:00:00 2001
From: Jim Meyering <meyering@meta.com>
Date: Mon, 7 Apr 2025 22:42:22 -0700
Subject: [PATCH] tests: hash-collision-perf: avoid test hang on GNU/Hurd

This test would hang on GNU/Hurd because the perl code
we use to measure subsecond duration isn't ported, and
that loop would never terminate.
* tests/hash-collision-perf: Add a 5-second timeout.
Normal per-iteration duration is 200ms or less.
Reported by Bruno Haible in https://bugs.gnu.org/77613
---
 tests/hash-collision-perf | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/tests/hash-collision-perf b/tests/hash-collision-perf
index b9a5b51..d84b939 100755
--- a/tests/hash-collision-perf
+++ b/tests/hash-collision-perf
@@ -22,6 +22,7 @@
 fail=0

 require_perl_
+require_timeout_

 : > empty || framework_failure_

@@ -31,7 +32,7 @@ require_perl_
 n_pat=40000
 while :; do
   seq $n_pat > in || framework_failure_
-  small_ms=$(LC_ALL=C user_time_ 1 grep --file=in empty) || fail=1
+  small_ms=$(LC_ALL=C user_time_ 1 timeout 5 grep --file=in empty) || fail=1
   test $small_ms -ge 200 && break
   n_pat=$(expr $n_pat '*' 2)
 done
@@ -39,7 +40,7 @@ done
 # Now, search for those same digits mapped to A-J.
 # With the PJW-based hash function, this became O(N^2).
 seq $n_pat | tr 0-9 A-J > in || framework_failure_
-large_ms=$(LC_ALL=C user_time_ 1 grep --file=in empty) || fail=1
+large_ms=$(LC_ALL=C user_time_ 1 timeout 5 grep --file=in empty) || fail=1

 # Deliberately recording in an unused variable so it
 # shows up in set -x output, in case this test fails.
-- 
2.49.0.154.g9d22ac5122

