Here are some test-improving patches:
From ccb6295d23669d5ee3bb2bbc37bf85873805d484 Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyer...@fb.com> Date: Sat, 1 Aug 2015 12:51:15 -0700 Subject: [PATCH 1/3] tests: new function to measure elapsed user time
* tests/init.cfg (user_time_): New function. --- tests/init.cfg | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tests/init.cfg b/tests/init.cfg index db2ab1e..be03357 100644 --- a/tests/init.cfg +++ b/tests/init.cfg @@ -172,3 +172,31 @@ hex_printf_() # would act like this with the multibyte tr from HP-UX and Solaris: # LC_ALL=ja_JP.eucJP tr A '\244\263' tr() { LC_ALL=C env -- tr "$@"; } + +# Usage: user_time_ EXPECTED_EXIT_STATUS CMD ... +# If CMD ... exits with the expected exit status, print the elapsed +# child "user" time (not "system" time) in milliseconds and return 0. +# Otherwise, diagnose the exit status mismatch and return nonzero. +user_time_() +{ + $PERL -le ' + my $expected_exit_status = $ARGV[0]; + shift @ARGV; + + system (@ARGV); + my ($user, $system, $child_user, $child_system) = times; + + my $me = q('"$ME_"'); + $? == -1 + and die qq($me: failed to exec ") . join (" ", @ARGV) . qq(": $!\n); + my $rc = $?; + my $sig = ($rc & 127); + $sig and die "$me: child died with signal $sig\n"; + $rc >>= 8; + $rc == $expected_exit_status + or die "$me: bad exit status: expected $expected_exit_status; got $rc\n"; + + # Print milliseconds of child user time. + $child_user *= 1000; + print int ($child_user + 0.5)' "$@" +} -- 2.3.7
From ce898d98d5ff0ffbd988c993d2b3f1e414a6df2a Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyer...@fb.com> Date: Sun, 26 Jul 2015 11:04:20 -0700 Subject: [PATCH 2/3] tests: long-pattern-perf: measure user time, not elapsed Measuring user time makes this test less prone to false positive failure, and also lets us use a tighter bound. * tests/long-pattern-perf: Measure elapsed user time rather than wall-clock time, to permit a tighter bound on the ratio of N-to-10N timings. Suggested by Giuseppe Ottaviano. Also, use regexps built from mostly 5-digit numbers, so that the 10:1 ratio applies to lines of "seq" output as well as to total bytes. --- tests/long-pattern-perf | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/tests/long-pattern-perf b/tests/long-pattern-perf index cba6553..c222c02 100755 --- a/tests/long-pattern-perf +++ b/tests/long-pattern-perf @@ -17,8 +17,6 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. . "${srcdir=.}/init.sh"; path_prepend_ ../src -require_timeout_ -require_hi_res_time_ fail=0 @@ -26,25 +24,15 @@ echo x > in || framework_failure_ # We could use seq -s '' (avoiding the tr filter), but I # suspect some version of seq does not honor that option. # Note that we want 10x the byte count (not line count) in the larger file. -seq 5000 | tr -d '\012' > re || framework_failure_ -seq 40000 | tr -d '\012' > re-10x || framework_failure_ +seq 10000 20000 | tr -d '\012' > re || framework_failure_ +seq 10000 100000 | tr -d '\012' > re-10x || framework_failure_ -start=$(hi_res_time_) -grep -f re in; st=$? -stop=$(hi_res_time_) -test $st = 1 || fail=1 +base_ms=$(user_time_ 1 grep -f re in ) || fail=1 +b10x_ms=$(user_time_ 1 grep -f re-10x in) || fail=1 # Increasing the length of the regular expression by a factor # of 10 should cause no more than a 10x increase in duration. -# However, we'll draw the line at 30x to avoid false-positives. -# Use an integer; some 'timeout' implementations have trouble with -# floating-point. -n_sec=$( - $AWK 'BEGIN { print 1 + int (30 * ('$stop' - '$start'))}' < /dev/null -) - -# Expect no match, i.e., exit status of 1. Anything else is an error. -timeout $n_sec grep -f re-10x in; st=$? -test $st = 1 || fail=1 +# However, we'll draw the line at 20x to avoid false-positives. +expr $base_ms '<' $b10x_ms / 20 && fail=1 Exit $fail -- 2.3.7
From 3ba6c9655a1c2465e6bd6e8453886eb579ee0eaa Mon Sep 17 00:00:00 2001 From: Jim Meyering <meyer...@fb.com> Date: Sat, 1 Aug 2015 14:38:30 -0700 Subject: [PATCH 3/3] tests: mb-non-UTF8-performance: use new function * tests/mb-non-UTF8-performance: Rewrite to use the user-time measuring function in init.cfg. --- tests/mb-non-UTF8-performance | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/tests/mb-non-UTF8-performance b/tests/mb-non-UTF8-performance index 42bb5b5..228361d 100755 --- a/tests/mb-non-UTF8-performance +++ b/tests/mb-non-UTF8-performance @@ -19,31 +19,20 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. . "${srcdir=.}/init.sh"; path_prepend_ ../src -require_timeout_ -require_hi_res_time_ fail=0 -yes $(printf '%078d' 0) | head -50000 > in || framework_failure_ - -start=$(hi_res_time_) -LC_ALL=C grep -i foobar in; st=$? -stop=$(hi_res_time_) - -# Use a multiple of the LC_ALL=C duration as the timeout for the JP/EUC test. -# A multiple of 3 seems to be enough for i5,i7, but AMD needs >25. -# Use an integer; some 'timeout' implementations have trouble with -# floating-point in JP_EUC locales. -timeout=$( - $AWK 'BEGIN { print 1 + int (30 * ('$stop' - '$start'))}' < /dev/null -) - -test $st = 1 || fail=1 +# Make this large enough so that even on high-end systems +# it incurs at least 5-10ms of user time. +yes $(printf '%078d' 0) | head -400000 > in || framework_failure_ +ubyte_ms=$(LC_ALL=C user_time_ 1 grep -i foobar in) || fail=1 require_JP_EUC_locale_ +mbyte_ms=$(user_time_ 1 grep -i foobar in) || fail=1 -# Expect no match, i.e., exit status of 1. Anything else is an error. -timeout $timeout grep -i foobar in; st=$? -test $st = 1 || fail=1 +# The duration of the multi-byte run must be no more than 30 times +# that of the single-byte one. +# A multiple of 3 seems to be enough for i5,i7, but AMD needs >25. +expr $ubyte_ms '<' $mbyte_ms / 30 && fail=1 Exit $fail -- 2.3.7