coreutils
[Top][All Lists]
Advanced

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

[coreutils] Re: tests/backref-multibyte-slow timeout 5s is too short for


From: Jim Meyering
Subject: [coreutils] Re: tests/backref-multibyte-slow timeout 5s is too short for my imac 400
Date: Thu, 04 Nov 2010 11:49:42 +0100

Pádraig Brady wrote:
> On 04/11/10 09:40, Jim Meyering wrote:
...
>> Using Perl would work...
>> I've wanted this sort of ability for other tests (e.g., coreutils'
>> tests/rm/ext3-perf), so maybe it's worth adding an option to GNU timeout:
>> run a reference command, measuring how long it takes, S, and use F*S
>> as the timeout.  This brings up the issue of whether timeout could take
>> a floating-point timeout.  I think it should.
>
> Maybe. I was wary about adding sub second support
> as it would complicate the implementation somewhat,
> while also being less guaranteed by the system.
> For what it's worth, my previous shell version
> supports sub second resolution:
> http://www.pixelbeat.org/scripts/timeout

It was well worth it for sleep, and I've always found it surprising
that timeout does not offer the same capability.

>> Whether this hypothetical version of timeout is installed isn't a big deal.
>> grep's test script could simply test for the new option and skip
>> the test if it's not available, just as it currently does if timeout
>> itself is not installed.  The important thing is that it be installed
>> by developers, and we can arrange for that.
>>
>> Pádraig Brady wrote timeout for coreutils, so I've Cc'd him and that list.
>> Pádraig, what do you think?
>>
>> Now that I ask that, I think the better approach, for now at least,
>> is to write a little perl script that does what I'm proposing.
>
> I don't think timeout should be running any reference command.
> That can always be done outside with `time`.

The built-in time command is not terribly portable, and /usr/bin/time
is often not installed.  If you use "time -p" (fails with zsh, and with
/usr/bin/time), you'll still have to parse output like this:

    $ dash -c 'time -p sleep .1'
    real 0.10
    user 0.00
    sys 0.00

Writing a perl script sounds like a better investment.
Hmm... maybe just do the timing in perl.
That gives this small patch:

diff --git a/tests/backref-multibyte-slow b/tests/backref-multibyte-slow
index eb32b43..940d6df 100644
--- a/tests/backref-multibyte-slow
+++ b/tests/backref-multibyte-slow
@@ -10,9 +10,16 @@ fail=0
 # Create a 13000-line input
 $AWK 'BEGIN {for (i=0; i<13000; i++) print "aba"}' /dev/null > in || fail=1

+# Use 10 times the duration of running grep in the C locale as the timeout
+# when running in en_US.UTF-8.  Round up to whole seconds, since timeout
+# can't deal with fractional seconds.
+max_seconds=$(LC_ALL=C perl -le 'use Time::HiRes qw(time); my $s = time();
+              system q,grep -E '\''^([a-z]).\1$'\'' in > /dev/null,;
+              my $elapsed = time() - $s; print int (1 + 10 * $elapsed)')
+
 for LOC in en_US.UTF-8; do
   out=out-$LOC
-  LC_ALL=$LOC timeout 5s grep -E '^([a-z]).\1$' in > $out 2>&1
+  LC_ALL=$LOC timeout ${max_seconds}s grep -E '^([a-z]).\1$' in > $out 2>&1
   test $? = 0 || fail=1
   compare $out in || fail=1
 done

However, it's incomplete, since it doesn't first ensure that perl
is available.  Also, the factor of 10 may not be enough on some systems.

Gilles, does that work for you?



reply via email to

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