Patchwork [V2] run-tests: '--time' option provide more details to linux users

login
register
mail settings
Submitter Anurag Goel
Date May 29, 2014, 11:31 a.m.
Message ID <f1b7b84a4f310afc9fcf.1401363112@ubuntu.ubuntu-domain>
Download mbox | patch
Permalink /patch/4894/
State Superseded
Commit 4ca4e15720223743bcdff42ce88c47675a94dcb8
Headers show

Comments

Anurag Goel - May 29, 2014, 11:31 a.m.
# HG changeset patch
# User anuraggoel <anurag.dsps@gmail.com>
# Date 1401362915 -19800
#      Thu May 29 16:58:35 2014 +0530
# Node ID f1b7b84a4f310afc9fcf132bf73c671e53b14384
# Parent  bde505f47141257e5aa0c71f8a3834047d5251e2
run-tests: '--time' option provide more details to linux users

As our tests exceute in child process, this patch includes os.times()
module in replace of time.time() module to provide addition info like
children's user time and children's system time along with real time
taken by a process.

There is one limitation of this patch.It can only work for linux users and not
for windows users because in windows, os.times() module work only for parent
process.

I have also added a test case which check the behaviour of --time option.
Pierre-Yves David - June 5, 2014, 11:58 p.m.
On 05/29/2014 04:31 AM, Anurag Goel wrote:
> # HG changeset patch
> # User anuraggoel <anurag.dsps@gmail.com>
> # Date 1401362915 -19800
> #      Thu May 29 16:58:35 2014 +0530
> # Node ID f1b7b84a4f310afc9fcf132bf73c671e53b14384
> # Parent  bde505f47141257e5aa0c71f8a3834047d5251e2
> run-tests: '--time' option provide more details to linux users

I'm waiting for the "test for run-test.py" topic to improve before 
having a deeper look at that changeset.

At that point. I'll request some test to the feature.
Pierre-Yves David - June 14, 2014, 5:02 a.m.
On 05/29/2014 04:31 AM, Anurag Goel wrote:
> # HG changeset patch
> # User anuraggoel <anurag.dsps@gmail.com>
> # Date 1401362915 -19800
> #      Thu May 29 16:58:35 2014 +0530
> # Node ID f1b7b84a4f310afc9fcf132bf73c671e53b14384
> # Parent  bde505f47141257e5aa0c71f8a3834047d5251e2
> run-tests: '--time' option provide more details to linux users

Now that a run-tests.py is tested in test-run-tests.t is it time to adds 
tests to this changesets and send a V2

(make sure you take other people feedback in account too.

Patch

diff -r bde505f47141 -r f1b7b84a4f31 tests/run-tests.py
--- a/tests/run-tests.py	Fri May 02 01:09:14 2014 +0200
+++ b/tests/run-tests.py	Thu May 29 16:58:35 2014 +0530
@@ -1069,6 +1069,7 @@ 
 
         self.times = []
         self._started = {}
+        self._stopped = {}
 
     def addFailure(self, test, reason):
         self.failures.append((test, reason))
@@ -1149,17 +1150,22 @@ 
     def startTest(self, test):
         super(TestResult, self).startTest(test)
 
-        self._started[test.name] = time.time()
+        self._started[test.name] = os.times()
 
     def stopTest(self, test, interrupted=False):
         super(TestResult, self).stopTest(test)
 
-        self.times.append((test.name, time.time() - self._started[test.name]))
+        self._stopped[test.name] = os.times()
+        self.times.append((test.name, self._stopped[test.name][2] -
+                    self._started[test.name][2], self._stopped[test.name][3] -
+                    self._started[test.name][3], self._stopped[test.name][4] -
+                    self._started[test.name][4]))
         del self._started[test.name]
+        del self._stopped[test.name]
 
         if interrupted:
             self.stream.writeln('INTERRUPTED: %s (after %d seconds)' % (
-                test.name, self.times[-1][1]))
+                test.name, self.times[-1][3]))
 
 class TestSuite(unittest.TestSuite):
     """Custom unitest TestSuite that knows how to execute Mercurial tests."""
@@ -1320,11 +1326,12 @@ 
 
     def printtimes(self, times):
         self.stream.writeln('# Producing time report')
-        times.sort(key=lambda t: (t[1], t[0]), reverse=True)
-        cols = '%7.3f   %s'
-        self.stream.writeln('%-7s   %s' % ('Time', 'Test'))
-        for test, timetaken in times:
-            self.stream.writeln(cols % (timetaken, test))
+        times.sort(key=lambda t: (t[3]))
+        cols = '%0.3f %7.3f %7.3f   %s'
+        self.stream.writeln('%-7s %-7s %-7s   %s' % ('cuser', 'csys', 'real',
+                    'Test'))
+        for test, cuser, csys, real in times:
+            self.stream.writeln(cols % (cuser, csys, real, test))
 
 class TestRunner(object):
     """Holds context for executing tests.
diff -r bde505f47141 -r f1b7b84a4f31 tests/test-run-tests.t
--- a/tests/test-run-tests.t	Fri May 02 01:09:14 2014 +0200
+++ b/tests/test-run-tests.t	Thu May 29 16:58:35 2014 +0530
@@ -74,6 +74,16 @@ 
   foo.bar\r \(no-eol\) (re) (esc)
   foo.bar\r \(no-eol\) (re)
 
+testing --time option
+
+  $ touch "$TESTDIR/temp.t"
+  $ python "$TESTDIR/run-tests.py" --time "$TESTDIR/temp.t"
+  
+  # Ran 0 tests, 0 skipped, 0 warned, 0 failed.
+  # Producing time report
+  cuser   csys    real      Test
+  $ rm "$TESTDIR/temp.t"
+
 testing hghave
 
   $ "$TESTDIR/hghave" true