Package qm :: Package test :: Module execution_thread
[hide private]
[frames] | no frames]

Source Code for Module qm.test.execution_thread

  1  ######################################################################## 
  2  # 
  3  # File:   execution_thread.py 
  4  # Author: Mark Mitchell 
  5  # Date:   2001-08-04 
  6  # 
  7  # Contents: 
  8  #   Code for coordinating the running of tests. 
  9  # 
 10  # Copyright (c) 2001, 2002 by CodeSourcery, LLC.  All rights reserved.  
 11  # 
 12  # For license terms see the file COPYING. 
 13  # 
 14  ######################################################################## 
 15   
 16  ######################################################################## 
 17  # Imports 
 18  ######################################################################## 
 19   
 20  import os 
 21  import qm.common 
 22  from   qm.test.base import * 
 23  from   qm.test.context import * 
 24  from   qm.test.execution_engine import * 
 25  import qm.xmlutil 
 26  import Queue 
 27  from   result import * 
 28  import sys 
 29  from   threading import * 
 30   
 31  ######################################################################## 
 32  # Classes 
 33  ######################################################################## 
 34   
35 -class ExecutionThread(Thread, ExecutionEngine):
36 """A 'ExecutionThread' executes tests in a separate thread. 37 38 A 'ExecutionThread' is an 'ExecutionEngine' that runs tests in a 39 separate thread. 40 41 This class schedules the tests, plus the setup and cleanup of any 42 resources they require, across one or more targets. 43 44 The shedule is determined dynamically as the tests are executed 45 based on which targets are idle and which are not. Therefore, the 46 testing load should be reasonably well balanced, even across a 47 heterogeneous network of testing machines.""" 48
49 - def __init__(self, 50 database, 51 test_ids, 52 context, 53 targets, 54 result_streams = None, 55 expectations = None):
56 """Set up a test run. 57 58 'database' -- The 'Database' containing the tests that will be 59 run. 60 61 'test_ids' -- A sequence of IDs of tests to run. Where 62 possible, the tests are started in the order specified. 63 64 'context' -- The context object to use when running tests. 65 66 'targets' -- A sequence of 'Target' objects, representing 67 targets on which tests may be run. 68 69 'result_streams' -- A sequence of 'ResultStream' objects. Each 70 stream will be provided with results as they are available. 71 This thread will not perform any locking of these streams as 72 they are written to; each stream must provide its own 73 synchronization if it will be accessed before 'run' returns. 74 75 'expectations' -- If not 'None', a dictionary mapping test IDs 76 to expected outcomes.""" 77 78 Thread.__init__(self, None, None, None) 79 ExecutionEngine.__init__(self, database, test_ids, context, 80 targets, result_streams, expectations) 81 82 # This is a deamon thread; if the main QMTest thread exits, 83 # this thread should not prolong the life of the process. 84 # Because the daemon flag is inherited from the creating thread, 85 # threads created by the targets will automatically be daemon 86 # threads. 87 self.setDaemon(1) 88 89 # Access to __terminated is guarded with this lock. 90 self.__lock = Lock()
91 92
93 - def run(self):
94 """Run the tests. 95 96 This method runs the tests specified in the __init__ 97 function.""" 98 self.Run()
99 100
101 - def RequestTermination(self):
102 """Request termination. 103 104 Request that the execution thread be terminated. This may 105 take some time; tests that are already running will continue 106 to run, for example.""" 107 108 self.__lock.acquire() 109 ExecutionEngine.RequestTermination(self) 110 self.__lock.release()
111 112
113 - def _IsTerminationRequested(self):
114 """Returns true if termination has been requested. 115 116 return -- True if Terminate has been called.""" 117 118 self.__lock.acquire() 119 terminated = ExecutionEngine._IsTerminationRequested(self) 120 self.__lock.release() 121 return terminated
122 123 124 ######################################################################## 125 # Local Variables: 126 # mode: python 127 # indent-tabs-mode: nil 128 # fill-column: 72 129 # End: 130