[llvm] r186695 - lit: Support cancellation on Windows

Nico Rieck nico.rieck at gmail.com
Fri Jul 19 10:08:08 PDT 2013


Author: nrieck
Date: Fri Jul 19 12:08:08 2013
New Revision: 186695

URL: http://llvm.org/viewvc/llvm-project?rev=186695&view=rev
Log:
lit: Support cancellation on Windows

The current machinery using KeyboardInterrupt for canceling doesn't work
with multiple threads on Windows as it just cancels the currently run tests
but the runners continue.

We install a handler for Ctrl-C which stops the provider from providing any
more tests to the runners. Together with aborting all currently running
tests, this brings lit to a halt.

Modified:
    llvm/trunk/utils/lit/lit/main.py

Modified: llvm/trunk/utils/lit/lit/main.py
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/utils/lit/lit/main.py?rev=186695&r1=186694&r2=186695&view=diff
==============================================================================
--- llvm/trunk/utils/lit/lit/main.py (original)
+++ llvm/trunk/utils/lit/lit/main.py Fri Jul 19 12:08:08 2013
@@ -76,6 +76,12 @@ class TestProvider:
         self.iter = iter(tests)
         self.lock = threading.Lock()
         self.startTime = time.time()
+        self.canceled = False
+
+    def cancel(self):
+        self.lock.acquire()
+        self.canceled = True
+        self.lock.release()
 
     def get(self):
         # Check if we have run out of time.
@@ -85,6 +91,10 @@ class TestProvider:
 
         # Otherwise take the next test.
         self.lock.acquire()
+        if self.canceled:
+          self.lock.release()
+          return None
+
         try:
             item = self.iter.next()
         except StopIteration:
@@ -346,6 +356,17 @@ def main(builtinParameters = {}):
     startTime = time.time()
     display = TestingProgressDisplay(opts, len(tests), progressBar)
     provider = TestProvider(tests, opts.maxTime)
+
+    try:
+      import win32api
+    except ImportError:
+      pass
+    else:
+      def console_ctrl_handler(type):
+        provider.cancel()
+        return True
+      win32api.SetConsoleCtrlHandler(console_ctrl_handler, True)
+
     runTests(opts.numThreads, litConfig, provider, display)
     display.finish()
 





More information about the llvm-commits mailing list