run-tests: track start and end time of tests
authorPierre-Yves David <pierre-yves.david@fb.com>
Thu, 07 May 2015 23:34:58 -0700
changeset 25097 a4fce7905721
parent 25096 081b08e4ea13
child 25098 bf84ab53c2fd
run-tests: track start and end time of tests We currently have information about how long each test took, but we have no data about their actual scheduling. So we now track when a test started and stopped (in the referential of the whole tests run) to expose this information. The data is currently in the json only because the json output is meant to be extensible. Later changeset will includes this data in the text output and we will be happy to bikeshed its formating there. Yes, "end" is actually just "start" + "time", but computing it an including it in the output is simple, cheap and convenient.
tests/run-tests.py
tests/test-run-tests.t
--- a/tests/run-tests.py	Fri May 15 09:07:27 2015 -0400
+++ b/tests/run-tests.py	Thu May 07 23:34:58 2015 -0700
@@ -1200,6 +1200,7 @@
         self.warned = []
 
         self.times = []
+        self._firststarttime =  None
         # Data stored for the benefit of generating xunit reports.
         self.successes = []
         self.faildata = {}
@@ -1324,6 +1325,8 @@
         # This module has one limitation. It can only work for Linux user
         # and not for Windows.
         test.started = os.times()
+        if self._firststarttime is None: # thread racy but irrelevant
+            self._firststarttime = test.started[4]
 
     def stopTest(self, test, interrupted=False):
         super(TestResult, self).stopTest(test)
@@ -1332,10 +1335,13 @@
 
         starttime = test.started
         endtime = test.stopped
+        origin = self._firststarttime
         self.times.append((test.name,
                            endtime[2] - starttime[2], # user space CPU time
                            endtime[3] - starttime[3], # sys  space CPU time
                            endtime[4] - starttime[4], # real time
+                           starttime[4] - origin, # start date in run context
+                           endtime[4] - origin, # end date in run context
                            ))
 
         if interrupted:
@@ -1570,9 +1576,10 @@
                             tres = {'result': res,
                                     'time': ('%0.3f' % timesd[tc.name][2]),
                                     'cuser': ('%0.3f' % timesd[tc.name][0]),
-                                    'csys': ('%0.3f' % timesd[tc.name][1])}
+                                    'csys': ('%0.3f' % timesd[tc.name][1]),
+                                    'start': ('%0.3f' % timesd[tc.name][3]),
+                                    'end': ('%0.3f' % timesd[tc.name][4])}
                             outcome[tc.name] = tres
-
                     jsonout = json.dumps(outcome, sort_keys=True, indent=4)
                     fp.writelines(("testreport =", jsonout))
                 finally:
--- a/tests/test-run-tests.t	Fri May 15 09:07:27 2015 -0400
+++ b/tests/test-run-tests.t	Thu May 07 23:34:58 2015 -0700
@@ -480,19 +480,25 @@
       "test-failure.t": [\{] (re)
           "csys": "\s*[\d\.]{4,5}", ? (re)
           "cuser": "\s*[\d\.]{4,5}", ? (re)
+          "end": "\s*[\d\.]{4,5}", ? (re)
           "result": "failure", ? (re)
+          "start": "\s*[\d\.]{4,5}", ? (re)
           "time": "\s*[\d\.]{4,5}" (re)
       }, ? (re)
       "test-skip.t": {
           "csys": "\s*[\d\.]{4,5}", ? (re)
           "cuser": "\s*[\d\.]{4,5}", ? (re)
+          "end": "\s*[\d\.]{4,5}", ? (re)
           "result": "skip", ? (re)
+          "start": "\s*[\d\.]{4,5}", ? (re)
           "time": "\s*[\d\.]{4,5}" (re)
       }, ? (re)
       "test-success.t": [\{] (re)
           "csys": "\s*[\d\.]{4,5}", ? (re)
           "cuser": "\s*[\d\.]{4,5}", ? (re)
+          "end": "\s*[\d\.]{4,5}", ? (re)
           "result": "success", ? (re)
+          "start": "\s*[\d\.]{4,5}", ? (re)
           "time": "\s*[\d\.]{4,5}" (re)
       }
   } (no-eol)
@@ -519,19 +525,25 @@
       "test-failure.t": [\{] (re)
           "csys": "\s*[\d\.]{4,5}", ? (re)
           "cuser": "\s*[\d\.]{4,5}", ? (re)
+          "end": "\s*[\d\.]{4,5}", ? (re)
           "result": "success", ? (re)
+          "start": "\s*[\d\.]{4,5}", ? (re)
           "time": "\s*[\d\.]{4,5}" (re)
       }, ? (re)
       "test-skip.t": {
           "csys": "\s*[\d\.]{4,5}", ? (re)
           "cuser": "\s*[\d\.]{4,5}", ? (re)
+          "end": "\s*[\d\.]{4,5}", ? (re)
           "result": "skip", ? (re)
+          "start": "\s*[\d\.]{4,5}", ? (re)
           "time": "\s*[\d\.]{4,5}" (re)
       }, ? (re)
       "test-success.t": [\{] (re)
           "csys": "\s*[\d\.]{4,5}", ? (re)
           "cuser": "\s*[\d\.]{4,5}", ? (re)
+          "end": "\s*[\d\.]{4,5}", ? (re)
           "result": "success", ? (re)
+          "start": "\s*[\d\.]{4,5}", ? (re)
           "time": "\s*[\d\.]{4,5}" (re)
       }
   } (no-eol)