From ccb6295d23669d5ee3bb2bbc37bf85873805d484 Mon Sep 17 00:00:00 2001 From: Jim Meyering 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