From dd1f8cdf6bd1fb9c881d96957d709b0f517852bb Mon Sep 17 00:00:00 2001 From: Jamie McClymont Date: Thu, 25 Jan 2018 17:23:06 +1300 Subject: [PATCH] selftest: consistently produce high-res UTC time Currently some subunit reporters throughout the codebase provide low-res time, meaning timestamps jump back and forth in the subunit file. Also, some subunit reporters produce UTC timestamps while others produce local time. UTC was chosen as the standard for this commit since all of the timestamps end with a Z (= Zulu = UTC). Signed-off-by: Jamie McClymont Reviewed-by: Andrew Bartlett Reviewed-by: Andreas Schneider Autobuild-User(master): Andreas Schneider Autobuild-Date(master): Thu Mar 22 13:26:44 CET 2018 on sn-devel-144 --- lib/torture/subunit.c | 4 ++-- selftest/Subunit.pm | 6 ++++-- selftest/selftest.pl | 7 ++++--- source4/torture/rpc/witness.c | 4 ++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/lib/torture/subunit.c b/lib/torture/subunit.c index 46f1b65053d..deb96ffa3a9 100644 --- a/lib/torture/subunit.c +++ b/lib/torture/subunit.c @@ -62,9 +62,9 @@ static void torture_subunit_report_time(struct torture_context *tctx) return; } - tmp = localtime(&tp.tv_sec); + tmp = gmtime(&tp.tv_sec); if (!tmp) { - perror("localtime"); + perror("gmtime"); return; } diff --git a/selftest/Subunit.pm b/selftest/Subunit.pm index 1cc0e721696..07f4b8ff97d 100644 --- a/selftest/Subunit.pm +++ b/selftest/Subunit.pm @@ -16,6 +16,7 @@ package Subunit; use POSIX; +use Time::HiRes; require Exporter; @ISA = qw(Exporter); @@ -43,10 +44,11 @@ sub end_test($$;$) } } -sub report_time($) +sub report_time() { my ($time) = @_; - my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = localtime($time); + $time = Time::HiRes::time() unless (defined($time)); + my ($sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst) = gmtime($time); $sec = ($time - int($time) + $sec); my $msg = sprintf("%f", $sec); if (substr($msg, 1, 1) eq ".") { diff --git a/selftest/selftest.pl b/selftest/selftest.pl index a772613b8e1..995abd71a04 100755 --- a/selftest/selftest.pl +++ b/selftest/selftest.pl @@ -28,6 +28,7 @@ use lib "$RealBin"; use Subunit; use SocketWrapper; use target::Samba; +use Time::HiRes qw(time); eval { require Time::HiRes; @@ -150,9 +151,9 @@ sub run_testsuite($$$$$) Subunit::start_testsuite($name); Subunit::progress_push(); - Subunit::report_time(time()); + Subunit::report_time(); system($cmd); - Subunit::report_time(time()); + Subunit::report_time(); Subunit::progress_pop(); if ($? == -1) { @@ -781,7 +782,7 @@ my $suitestotal = $#todo + 1; unless ($opt_list) { Subunit::progress($suitestotal); - Subunit::report_time(time()); + Subunit::report_time(); } my $i = 0; diff --git a/source4/torture/rpc/witness.c b/source4/torture/rpc/witness.c index 4b44e91dbcf..4e7c682a7ee 100644 --- a/source4/torture/rpc/witness.c +++ b/source4/torture/rpc/witness.c @@ -790,9 +790,9 @@ static void torture_subunit_report_time(struct torture_context *tctx) return; } - tmp = localtime(&tp.tv_sec); + tmp = gmtime(&tp.tv_sec); if (!tmp) { - torture_comment(tctx, "failed to call localtime"); + torture_comment(tctx, "failed to call gmtime"); return; }