selftest: consistently produce high-res UTC time
authorJamie McClymont <jamiemcclymont@catalyst.net.nz>
Thu, 25 Jan 2018 04:23:06 +0000 (17:23 +1300)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 22 Mar 2018 12:26:44 +0000 (13:26 +0100)
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 <jamiemcclymont@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org>
Autobuild-Date(master): Thu Mar 22 13:26:44 CET 2018 on sn-devel-144

lib/torture/subunit.c
selftest/Subunit.pm
selftest/selftest.pl
source4/torture/rpc/witness.c

index 46f1b65053ddc63833002011a8a2f0456f52d5fe..deb96ffa3a983d128d6bfdbe3ab78215858730b8 100644 (file)
@@ -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;
        }
 
index 1cc0e721696673b9c21a873fb03d4acd618767de..07f4b8ff97ddb22853261de7515be2f500a3638a 100644 (file)
@@ -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 ".") {
index a772613b8e10fa53f7bdd79d80fba37e9d41610e..995abd71a04f17c4eff9db97248acb3d1e4f0b1d 100755 (executable)
@@ -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;
index 4b44e91dbcf23ce705a14fcd45ec8c44f5e09300..4e7c682a7ee504d589ffde560192a65ffd63634d 100644 (file)
@@ -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;
        }