Patchwork [025,of,179,tests-refactor] run-tests: handle interrupted in Test.run()

login
register
mail settings
Submitter Gregory Szorc
Date May 2, 2014, 6:37 p.m.
Message ID <6688e53bdf9587c8f6d3.1399055862@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/4520/
State Accepted
Commit e5eed8ded1685e526e634468befd0c31234aebbc
Headers show

Comments

Gregory Szorc - May 2, 2014, 6:37 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1397964438 25200
#      Sat Apr 19 20:27:18 2014 -0700
# Branch stable
# Node ID 6688e53bdf9587c8f6d347e2d3f25de231c7f425
# Parent  317c7fdd311251775694fc9231e6197b15532fdd
run-tests: handle interrupted in Test.run()

Patch

diff --git a/tests/run-tests.py b/tests/run-tests.py
--- a/tests/run-tests.py
+++ b/tests/run-tests.py
@@ -544,17 +544,18 @@  def outputcoverage(options):
 
 class Test(object):
     """Encapsulates a single, runnable test.
 
     Test instances can be run multiple times via run(). However, multiple
     runs cannot be run concurrently.
     """
 
-    def __init__(self, path, options, count, refpath):
+    def __init__(self, test, path, options, count, refpath):
+        self._test = test
         self._path = path
         self._options = options
         self._count = count
         self._daemonpids = []
 
         # If we're not in --debug mode and reference output file exists,
         # check test output against it.
         if options.debug:
@@ -591,17 +592,19 @@  class Test(object):
 
         try:
             ret, out = self._run(testtmp, replacements, env)
             updateduration()
             result.ret = ret
             result.out = out
         except KeyboardInterrupt:
             updateduration()
-            result.interrupted = True
+            log('INTERRUPTED: %s (after %d seconds)' % (self._test,
+                                                        result.duration))
+            raise
         except Exception, e:
             updateduration()
             result.exception = e
 
         killdaemons(env['DAEMON_PIDS'])
 
         result.refout = self._refout
 
@@ -666,17 +669,16 @@  class Test(object):
 
 class TestResult(object):
     """Holds the result of a test execution."""
 
     def __init__(self):
         self.ret = None
         self.out = None
         self.duration = None
-        self.interrupted = False
         self.exception = None
         self.refout = None
 
     @property
     def skipped(self):
         """Whether the test was skipped."""
         return self.ret == SKIPPED_STATUS
 
@@ -1084,25 +1086,21 @@  def runone(options, test, count):
     else:
         return skip("unknown test type")
 
     vlog("# Test", test)
 
     if os.path.exists(err):
         os.remove(err)       # Remove any previous output files
 
-    t = runner(testpath, options, count, ref)
+    t = runner(test, testpath, options, count, ref)
     res = TestResult()
     t.run(res)
     del t # For cleanup side-effects.
 
-    if res.interrupted:
-        log('INTERRUPTED: %s (after %d seconds)' % (test, res.duration))
-        raise KeyboardInterrupt()
-
     if res.exception:
         return fail('Exception during execution: %s' % res.exception, 255)
 
     ret = res.ret
     out = res.out
 
     times.append((test, res.duration))
     vlog("# Ret was:", ret)