Package SimPy :: Module testSimPy

[hide private]
[frames] | no frames]

# Source Code for Module SimPy.testSimPy

       1  #!/usr / bin / env python
       2  from SimPy.Simulation  import *
       3  from SimPy.MonitorTest import *
       4  import unittest
       5  from random import random
       6  # $Revision: 163 $ $Date: 2008-12-15 12:47:44 +0100 (Mo, 15 Dez 2008) $
       7  """testSimPy.py
       8  SimPy version 2.0
       9  Unit tests for Simulation.py.
      10
      11  **Change history**:
      12  # 2002 11 15 Added tests for priority queues and preemption
      13  # 2002 11 22 testing problem in accum
      14  # 2003 03 30 added tests for SEP001v17 interrupts
      15  # 2003 04 05 added test for interruptReset
      16  # 2003 04 08 added tests for process state transitions
      17  # 2003 04 10 changed to 'self.cancel(victim)' syntax
      18  # 2003 04 13 removed dummy init assertions
      19  # 2004 02 28 added test for monitored queues (gav)
      20  # 2004 05 03 corrected test for monitored queues (gav)
      21  # 2004 09 17 added tests for waitevent, queueevent, waituntil (new in 1.5)
      22  # 2005 05 19 added tests for compound yield statements (reneging)
      23  # 2006 01 15 added tests for Store and Level and the get / put yield statements
      24  # 2006 02 02 removed histogram plotting suite
      25  # 2006 05 10 changed test testStatic for Level to test that float type
      26               supported for initialBuffered
      27  # 2006 05 16 added tests for Store and Level to test basic Producer / Consumer
      28               principles
      29  # 2006 10 16 added tests for compound get statement (Unmonitored Store / Level)
      30  # 2006 10 17 added tests for compound put statement (Unmonitored Store / Level)
      31  # 2007 01 08 added tests for monitoring of Store / Level with compound get / put
      32  # 2007 01 08 added test for Store with filter function
      33  # 2007 12 05 added tests for start method (Process)
      34  # 2008 03 03 added test for nested preempts
      35
      36  #'$Revision: 163 $ $Date: 2008-12-15 12:47:44 +0100 (Mo, 15 Dez 2008) $ kgm'
      37
      38  """
      39
      40
      41  simulationVersion=version
      42  print "Under test: Simulation.py %s"%simulationVersion
      43  __version__ = '2.0 $Revision: 163 $ $Date: 2008-12-15 12:47:44 +0100 (Mo, 15 Dez 2008) $ '
      44  print 'testSimpy.py %s'%__version__
      45  ## -------------------------------------------------------------
      46  ##                    TEST SIMULATION
      47  ## -------------------------------------------------------------
      48 -class P(Process):
      49     """ P class for testing"""
      50 -   def __init__(self, name = '', T = 0):
      51          Process.__init__(self)
      52          self.name = name
      53          self.T = T
      54
      55 -   def execute(self):
      56          yield hold, self, self.T
      57
      58 -class PActions(Process):
      59     """ PActions class for testing"""
      60 -   def __init__(self, name = '', T = 0):
      61          Process.__init__(self)
      62          self.name = name
      63          self.T = T
      64
      65 -   def ACTIONS(self):
      66          yield hold, self, self.T
      67
      68 -class makeSimulationtestcase(unittest.TestCase):
      69     """ Tests of simulation
      70     """
      71 -   def testInit(self):
      72          """Test initialisation
      73          """
      74          initialize()
      75          simulate(until = 10)
      76          assert(now() == 0),'time not 0'
      77
      78 -   def testActivate(self):
      79          """Test activate()
      80          """
      81          P1 = P(name = 'P1', T = 100.0)
      82          initialize()
      83          activate(P1, P1.execute(),0)
      84          simulate(until = 5)
      85          assert(now() == 5),'Simulate stopped at %s not %s' % (now(),5)
      86
      87 -   def testStart(self):
      88         """Test start method
      89         """
      90         P1 = P(name = 'P1', T = 100.0)
      91         initialize()
      92         P1.start(P1.execute(),0)
      93         simulate(until = 5)
      94         assert(now() == 5),'Simulate stopped at %s not %s' % (now(),5)
      95
      96 -   def testStartActions(self):
      97        """Test start method with ACTIONS PEM
      98        """
      99        P1 = PActions(name = 'P1', T = 100.0)
     100        initialize()
     101        P1.start()
     102        simulate(until = 5)
     103        assert(now() == 5),'Simulate stopped at %s not %s' % (now(),5)
     104
     105 -   def testYield(self):
     106          """Test yield hold and simulate(until)
     107          """
     108          P1 = P(name = 'P1', T = 10)
     109          initialize()
     110          activate(P1, P1.execute(),0)
     111          simulate(until = 5)
     112          assert(now() == 5),'Simulate stopped at %s not %s' % (now(),5)
     113          ## should stop at 0 for next event is at 10s
     114          P2 = P(name = 'P2', T = 10)
     115          initialize()
     116          activate(P2, P2.execute(),0)
     117          simulate(until = 20)
     118          assert(now() == 10),'P1 hold to %s not %s' % (now(),10)
     119
     120
     121 -def makeSSuite():
     122      suite = unittest.TestSuite()
     123      testInit = makeSimulationtestcase('testInit')
     124      testActivate = makeSimulationtestcase('testActivate')
     125      testStart = makeSimulationtestcase('testStart')
     126      testStartActions = makeSimulationtestcase('testStartActions')
     127      testYield = makeSimulationtestcase('testYield')
     128      ##testrequest3 = makeSimulationtestcase('testrequest3')
     129      ##testrequest4 = makeSimulationtestcase('testrequest4')
     130      suite.addTests([testInit, testActivate, testStart, testStartActions, testYield])
     131      return suite
     132
     133  ## -------------------------------------------------------------
     134  ##                    TEST RESOURCES
     135  ## -------------------------------------------------------------
     136
     137 -class Job(Process):
     138     """ Job class for testing"""
     139 -   def __init__(self, server = None, name = ''):
     140          Process.__init__(self)
     141          self.name = name
     142          self.R = server
     143
     144 -   def execute(self):
     145          yield request, self, self.R
     146
     147
     148 -class makeResourcetestcase(unittest.TestCase):
     149     """ First simple tests of Resources
     150     """
     151 -   def testInit(self):
     152          """Test initialisation"""
     153          R = Resource()
     154          assert R.name == 'a_resource', 'Not null name'
     155          assert R.capacity == 1, 'Not unit capacity'
     156          assert R.unitName == 'units', 'Not the correct unit name'
     157          R = Resource(name = '', capacity = 1)
     158          assert R.name == '', 'Not null name'
     159          assert R.capacity == 1, 'Not unit capacity'
     160          assert R.unitName == 'units', 'Not the correct unit name'
     161          R = Resource(capacity = 3, name = '3 - version', unitName = 'blobs')
     162          assert R.name == '3 - version', 'Wrong name, it is' + R.name
     163          assert R.capacity == 3, 'Not capacity 3, it is '+`R.capacity`
     164          assert R.unitName == 'blobs', 'Not the correct unit name'
     165          ## next test 0 capacity is allowed
     166          R = Resource(capacity = 0, name = '0 - version')
     167          assert R.capacity == 0, 'Not capacity 0, it is '+`R.capacity`
     168
     169 -   def testrequest(self):
     170          """Test request"""
     171          ## NB this next call should be changed to
     172          ## R = Resource() when Simulation is fixed
     173          R0 = Resource(name = '', capacity = 0)
     174          assert R0.name == '', 'Not null name'
     175          assert R0.capacity == 0, 'Not capacity 0, it is '+`R0.capacity`
     176          ## now test requesting: ------------------------------------
     177          initialize()
     178          R1 = Resource(capacity = 0, name = '3 - version', unitName = 'blobs')
     179          J = Job(name = 'job', server = R1)
     180          activate(J, J.execute(), at = 0.0) # this requests a unit of R1
     181          ## when simulation starts
     182          simulate(until = 10.0)
     183          assert R1.n == 0, 'Should be 0, it is ' + str(R1.n)
     184          lenW = len(R1.waitQ)
     185          assert lenW == 1, 'Should be 1, it is ' + str(lenW)
     186          assert len(R1.activeQ) == 0, 'len activeQ Should be 0, it is '+\
     187          str(len(R1.activeQ))
     188
     189 -   def testrequest2(self):
     190          """Test request2 with capacity = 1"""
     191          ## now test requesting: ------------------------------------
     192          initialize()
     193          R2 = Resource(capacity = 1, name = '3 - version', unitName = 'blobs')
     194          J2 = Job(name = 'job', server = R2)
     195          activate(J2, J2.execute(), at = 0.0) # requests a unit of R2
     196          ## when simulation starts
     197          simulate(until = 10.0)
     198          assert R2.n == 0, 'Should be 0, it is ' + str(R2.n)
     199          lenW = len(R2.waitQ)
     200          lenA = len(R2.activeQ)
     201          assert lenW == 0, 'lenW Should be 0, it is ' + str(lenW)
     202          assert lenA == 1, 'lenA Should be 1, it is ' + str(lenA)
     203
     204 -   def testrequest3(self):
     205          """Test request3 with capacity = 1 several requests"""
     206          ## now test requesting: ------------------------------------
     207          initialize()
     208          R3 = Resource(capacity = 1, name = '3 - version', unitName = 'blobs')
     209          J2 = Job(name = 'job', server = R3)
     210          J3 = Job(name = 'job', server = R3)
     211          J4 = Job(name = 'job', server = R3)
     212          activate(J2, J2.execute(), at = 0.0) # requests a unit of R3
     213          activate(J3, J3.execute(), at = 0.0) # requests a unit of R3
     214          activate(J4, J4.execute(), at = 0.0) # requests a unit of R3
     215          ## when simulation starts
     216          simulate(until = 10.0)
     217          assert R3.n == 0, 'Should be 0, it is ' + str(R3.n)
     218          lenW = len(R3.waitQ)
     219          lenA = len(R3.activeQ)
     220          assert lenW == 2, 'lenW Should be 2, it is ' + str(lenW)
     221          assert R3.waitQ == [J3, J4],'WaitQ wrong' + str(R3.waitQ)
     222          assert lenA == 1, 'lenA Should be 1, it is ' + str(lenA)
     223          assert R3.activeQ == [J2],'activeQ wrong, it is ' + str(R3.activeQ[0])
     224
     225 -   def testrequest4(self):
     226          """Test request4 with capacity = 2 several requests"""
     227          ## now test requesting: ------------------------------------
     228          initialize()
     229          R3 = Resource(capacity = 2, name = '4 - version', unitName = 'blobs')
     230          J2 = Job(name = 'job', server = R3)
     231          J3 = Job(name = 'job', server = R3)
     232          J4 = Job(name = 'job', server = R3)
     233          activate(J2, J2.execute(), at = 0.0) # requests a unit of R3
     234          activate(J3, J3.execute(), at = 0.0) # requests a unit of R3
     235          activate(J4, J4.execute(), at = 0.0) # requests a unit of R3
     236          ## when simulation starts
     237          simulate(until = 10.0)
     238          assert R3.n == 0, 'Should be 0, it is ' + str(R3.n)
     239          lenW = len(R3.waitQ)
     240          lenA = len(R3.activeQ)
     241          assert lenW == 1, 'lenW Should be 1, it is ' + str(lenW)
     242          assert R3.waitQ == [J4],'WaitQ wrong' + str(R3.waitQ)
     243          assert lenA == 2, 'lenA Should be 2, it is ' + str(lenA)
     244          assert R3.activeQ == [J2, J3],'activeQ wrong, it is ' + str(R3.activeQ[0])
     245
     246  #------- Test Priority Queues
     247
     248 -   def testrequestPriority(self):
     249          """Test PriorityQ, with no preemption, 0 capacity"""
     250          class Job(Process):
     251             """ Job class for testing"""
     252             def __init__(self, server = None, name = ''):
     253                Process.__init__(self)
     254                self.name = name
     255                self.R = server
     256
     257             def execute(self, priority):
     258                yield request, self, self.R, priority
     259
     260          initialize()
     261          Rp = Resource(capacity = 0, qType = PriorityQ)
     262          J5 = Job(name = 'job 5', server = Rp)
     263          J6 = Job(name = 'job 6', server = Rp)
     264          J7 = Job(name = 'job 7', server = Rp)
     265          activate(J5, J5.execute(priority = 3))
     266          activate(J6, J6.execute(priority = 0))
     267          activate(J7, J7.execute(priority = 1))
     268          simulate(until = 100)
     269          assert Rp.waitQ == [J5, J7, J6],'WaitQ wrong' + str([(x.name, x.priority[Rp]) for x in Rp.waitQ])
     270
     271          """Test PriorityQ mechanism"""
     272
     273          def sorted(q):
     274             if not q or len(q) == 1:
     275                sortok = 1
     276                return sortok
     277             sortok = q[0] >= q[1] and sorted(q[2:])
     278             return sortok
     279
     280          initialize()
     281          Rp = Resource(capacity = 0, qType = PriorityQ)
     282          for i in range(10):
     283             J = Job(name = 'job ' + str(i),server = Rp)
     284             activate(J, J.execute(priority = random()))
     285          simulate(until = 1000)
     286          qp = [x._priority[Rp] for x in Rp.waitQ]
     287          assert sorted(qp),'waitQ not sorted by priority: ' + str([(x.name, x._priority[Rp]) for x in Rp.waitQ])
     288
     289
     290 -   def testrequestPriority1(self):
     291          """Test PriorityQ, with no preemption, capacity == 1"""
     292          class Job(Process):
     293             """ Job class for testing"""
     294             def __init__(self, server = None, name = ''):
     295                Process.__init__(self)
     296                self.name = name
     297                self.R = server
     298
     299             def execute(self, priority):
     300                yield request, self, self.R, priority
     301
     302          initialize()
     303          Rp = Resource(capacity = 1, qType = PriorityQ)
     304          J5 = Job(name = 'job 5', server = Rp)
     305          J6 = Job(name = 'job 6', server = Rp)
     306          J7 = Job(name = 'job 7', server = Rp)
     307          activate(J5, J5.execute(priority = 2))
     308          activate(J6, J6.execute(priority = 4))
     309          activate(J7, J7.execute(priority = 3))
     310          simulate(until = 100)
     311          assert Rp.waitQ == [J6, J7],'WaitQ wrong ' + str([(x.name, x._priority[Rp]) for x in Rp.waitQ])
     312
     313 -   def testrequestPriority2(self):
     314         """Test PriorityQ, with preemption, capacity == 1"""
     315         class nuJob(Process):
     316            def __init__(self, name):
     317               Process.__init__(self, name)
     318
     319            def execute(self, res, priority):
     320               self.preempt = len(res.activeQ) > 0 and priority > res.activeQ[-1]._priority[res]
     321               t = now()
     322               yield request, self, res, priority
     323               if self.preempt:
     324                  assert len(res.waitQ) == 1, 'No preemption ' + 'activeQ = ' + str(res.activeQ[0].name)
     325               yield hold, self, 30
     326               t1 = now()
     327               if self.preempt:
     328                  assert t + 30 == t1, 'Wrong completion time for preemptor ' + self.name
     329               else:
     330                  assert t + 60 == t1, 'Wrong completion time for preempted ' + self.name + ' ' + str(now())
     331               yield release, self, res
     332
     333         initialize()
     334         res = Resource(name = 'server', capacity = 1, qType = PriorityQ, preemptable = 1)
     335         n1 = nuJob(name = 'nuJob 1')
     336         n2 = nuJob(name = 'nuJob 2')
     337         activate(n1, n1.execute(res, priority = 0))
     338         activate(n2, n2.execute(res, priority = 1),at = 15)
     339         simulate(until = 100)
     340
     341 -   def testrequestPriority3(self):
     342         """Test preemption of preemptor"""
     343         class nuJob(Process):
     344            seqOut = []
     345            def __init__(self, name):
     346               Process.__init__(self, name)
     347               self.serviceTime = 30
     348
     349            def execute(self, res, priority):
     350               self.preempt = len(res.activeQ) > 0 and priority > res.activeQ[-1]._priority[res]
     351               nrwaiting = len(res.waitQ)
     352               yield request, self, res, priority
     353               if self.preempt:
     354                  assert len(res.waitQ) == nrwaiting + 1, 'No preemption ' + 'activeQ = ' + str(res.activeQ[0].name)
     355               yield hold, self, self.serviceTime
     356               yield release, self, res
     357               nuJob.seqOut.append((self, now()))
     358
     359
     360
     361         initialize()
     362         res = Resource(name = 'server', capacity = 1, qType = PriorityQ, preemptable = 1)
     363         n1 = nuJob(name = 'nuJob 1')
     364         n2 = nuJob(name = 'nuJob 2')
     365         n3 = nuJob(name = 'nuJob 3')
     366         activate(n1, n1.execute(res, priority=-1))
     367         start2 = 10
     368         activate(n2, n2.execute(res, priority = 0),at = start2)
     369         start3 = 20
     370         activate(n3, n3.execute(res, priority = 1),at = start3)
     371         simulate(until = 100)
     372         assert [x[1] for x in nuJob.seqOut] == [start3 + n3.serviceTime, start2 + 2 * n2.serviceTime, 90],\
     373                'Wrong service sequence / times: ' + str([x for x in nuJob.seqOut])
     374
     375 -   def testrequestNestedPreempt(self):
     376        """Test that a process can preempt another process holding multiple resources
     377        """
     378        class Requestor(Process):
     379            def run(self, res1, res2, res3, priority = 1):
     380                yield request, self, res1, priority
     381                yield request, self, res2, priority
     382                yield request, self, res3, priority
     383                record.observe(y = self.name)
     384                yield hold, self, 100
     385                record.observe(y = self.name)
     386                yield release, self, res3
     387                yield release, self, res2
     388                yield release, self, res1
     389
     390        initialize()
     391        outer = Resource(name = 'outer', qType = PriorityQ, preemptable = True)
     392        inner = Resource(name = 'inner', qType = PriorityQ, preemptable = True)
     393        innermost = Resource(name = 'innermost', qType = PriorityQ, preemptable = True)
     394        record = Monitor()
     395        r1 = Requestor('r1')
     396        activate(r1, r1.run(res1 = outer, res2 = inner, res3 = innermost, priority = 1))
     397        r2 = Requestor('r2')
     398        activate(r2, r2.run(res1 = outer, res2 = inner, res3 = innermost, priority = 10),at = 50)
     399        simulate(until = 200)
     400        assert record == [[0, 'r1'],[50, 'r2'],[150, 'r2'],[200, 'r1']],\
     401                'was %s; preempt did not work'%record
     402
     403
     404 -   def testmonitored(self):
     405        """ test monitoring of number in the two queues, waitQ and activeQ
     406        """
     407        class Job(Process):
     408            def __init__(self, name):
     409               Process.__init__(self, name)
     410
     411            def execute(self, res):
     412               yield request, self, res
     413               yield hold, self, 2
     414               yield release, self, res
     415
     416        initialize()
     417        res = Resource(name = 'server', capacity = 1, monitored = 1)
     418        n1 = Job(name = 'Job 1')
     419        n2 = Job(name = 'Job 2')
     420        n3 = Job(name = 'Job 3')
     421        activate(n1, n1.execute(res),at = 2)
     422        activate(n2, n2.execute(res),at = 2)
     423        activate(n3, n3.execute(res),at = 2) # 3 arrive at 2
     424        simulate(until = 100)
     425        assert res.waitMon == [[2, 1], [2, 2], [4, 1], [6, 0]],'Wrong waitMon:%s'%res.waitMon
     426        assert res.actMon == [[2, 1], [4, 0], [4, 1], [6, 0], [6, 1], [8, 0]],'Wrong actMon:%s'%res.actMon
     427        #print res.actMon
     428        assert res.waitMon.timeAverage() == (0 * 2 + 2 * 2 + 1 * 2) / 8.0, 'Wrong waitMon.timeAverage:%s'%res.waitMon.timeAverage()
     429
     430
     431 -def makeRSuite():
     432      suite = unittest.TestSuite()
     433      testInit = makeResourcetestcase('testInit')
     434      testrequest = makeResourcetestcase('testrequest')
     435      testrequest2 = makeResourcetestcase('testrequest2')
     436      testrequest3 = makeResourcetestcase('testrequest3')
     437      testrequest4 = makeResourcetestcase('testrequest4')
     438      testrequestPriority = makeResourcetestcase('testrequestPriority')
     439      testrequestPriority1 = makeResourcetestcase('testrequestPriority1')
     440      testrequestPriority2 = makeResourcetestcase('testrequestPriority2')
     441      testrequestPriority3 = makeResourcetestcase('testrequestPriority3')
     442      testrequestNestedPreempt = makeResourcetestcase('testrequestNestedPreempt')
     443      testmonitored = makeResourcetestcase('testmonitored')
     444      suite.addTests([testInit, testrequest, testrequest2, testrequest3, testrequest4, testrequestPriority,
     445                      testrequestPriority1, testrequestPriority2, testrequestPriority3,
     446                      testrequestNestedPreempt, testmonitored])
     447      return suite
     448
     449
     450  ##=====================================================
     451  ##                   Test Interrupts
     452  ##=====================================================
     453
     454
     455 -class Interruptor(Process):
     456 -   def __init__(self):
     457        Process.__init__(self)
     458
     459 -   def breakin(self, waitbefore, howoften = 1):
     460        for i in range(howoften):
     461           yield hold, self, waitbefore
     462           self.interrupt(victim)
     463
     464 -class Interrupted(Process):
     465 -   def __init__(self):
     466        Process.__init__(self)
     467
     468 -   def myActivity(self, howlong, theEnd = 200):
     469        global igothit
     470        igothit={}
     471        while now() <= theEnd:
     472           yield hold, self, howlong
     473           if self.interrupted():
     474              byWhom = self.interruptCause
     475              igothit[now()] = byWhom
     476           else:
     477              pass
     478
     479 -class makeInterrupttestcase(unittest.TestCase):
     480     """
     481     Tests interrupts as defined in SEP001v17
     482     """
     483 -   def testInterrupt1(self):
     484        """
     485        Test single interrupt during victim activity
     486        """
     487        global victim
     488        initialize()
     489        breaker = Interruptor()
     490        activate(breaker, breaker.breakin(10))
     491        victim = Interrupted()
     492        activate(victim, victim.myActivity(100))
     493        simulate(until = 200)
     494        assert igothit[10] == breaker, 'Not interrupted at 10 by breaker'
     495        assert len(igothit) == 1, 'Interrupted more than once'
     496
     497 -   def testInterrupt2(self):
     498        """
     499        Test multiple interrupts during victim activity
     500        """
     501        global victim
     502        initialize()
     503        breaker = Interruptor()
     504        activate(breaker, breaker.breakin(10, howoften = 3))
     505        victim = Interrupted()
     506        activate(victim, victim.myActivity(100))
     507        simulate(until = 200)
     508        for i in (10, 20, 30):
     509           assert igothit[i] == breaker, 'Not interrupted at %s by breaker' %i
     510        assert len(igothit) == 3, 'Interrupted wrong number of times'
     511
     512 -   def testInterrupt3(self):
     513        """
     514        Test interrupts after victim activity
     515        """
     516        global victim
     517        initialize()
     518        breaker = Interruptor()
     519        activate(breaker, breaker.breakin(50, howoften = 5))
     520        victim = Interrupted()
     521        activate(victim, victim.myActivity(10, theEnd = 10))
     522        simulate(until = 200)
     523        assert len(igothit) == 0, 'There has been an interrupt after victim lifetime'
     524
     525 -   def testInterrupt4(self):
     526        """
     527        Test multiple interrupts by multiple processes during victim activity
     528        """
     529        global victim
     530        initialize()
     531        breaker1 = Interruptor()
     532        activate(breaker1, breaker1.breakin(15, howoften = 3))
     533        breaker2 = Interruptor()
     534        activate(breaker2, breaker2.breakin(20, howoften = 3))
     535        victim = Interrupted()
     536        activate(victim, victim.myActivity(100))
     537        simulate(until = 200)
     538        for i in (15, 30, 45):
     539           assert igothit[i] == breaker1, 'Not interrupted at %s by breaker1' %i
     540        for i in (20, 40, 60):
     541           assert igothit[i] == breaker2, 'Not interrupted at %s by breaker2' %i
     542        assert len(igothit) == 6, 'Interrupted wrong number of times'
     543
     544 -   def testInterrupt5(self):
     545        """
     546        Test reset of 'interrupted' state.
     547        """
     548        global victim
     549        initialize()
     550        breaker = Interruptor()
     551        victim = Interrupted()
     552
     553        def newProcess(self):
     554           while True:
     555              assert not self.interrupted(),'Incorrectly interrupted'
     556              yield hold, self, 100
     557              if self.interrupted():
     558                 self.interruptReset()
     559                 assert not self.interrupted(),'Incorrectly interrupted'
     560
     561        victim.newProcess = newProcess
     562        activate(victim, newProcess(victim))
     563        activate(breaker, breaker.breakin(10, howoften = 3))
     564        simulate(until = 1000)
     565
     566 -def makeISuite():
     567     suite = unittest.TestSuite()
     568     testInterrupt1 = makeInterrupttestcase('testInterrupt1')
     569     testInterrupt2 = makeInterrupttestcase('testInterrupt2')
     570     testInterrupt3 = makeInterrupttestcase('testInterrupt3')
     571     testInterrupt4 = makeInterrupttestcase('testInterrupt4')
     572     testInterrupt5 = makeInterrupttestcase('testInterrupt5')
     573     suite.addTests([testInterrupt1, testInterrupt2, testInterrupt3, testInterrupt4, testInterrupt5])
     574     return suite
     575
     576  ## -------------------------------------------------------------
     577  ##                    TEST PROCESS STATES
     578  ## -------------------------------------------------------------
     579
     580 -class PS1(Process):
     581 -   def __init__(self):
     582        Process.__init__(self)
     583
     584 -   def life1(self):
     585        yield hold, self, 10
     586
     587 -   def life2(self):
     588        yield hold, self, 10
     589        yield passivate, self
     590        yield hold, self, 10
     591
     592 -class Observer1(Process):
     593 -   def __init__(self):
     594        Process.__init__(self)
     595
     596 -   def look1(self, p):
     597        assert p.active(),'p not active'
     598        assert not p.passive(), 'p passive'
     599        assert not p.terminated(),'p terminated'
     600        assert not p.interrupted(),'p interrupted'
     601        yield hold, self, 11
     602        assert not p.active(),'p active'
     603        assert not p.passive(),'p passive'
     604        assert p.terminated(),'p not terminated'
     605        assert not p.interrupted(),'p interrupted'
     606
     607 -   def look2(self, p):
     608        assert not p.active(),'p active'
     609        assert p.passive(),'p not passive'
     610        assert not p.terminated(),'p not terminated'
     611        assert not p.interrupted(),'p interrupted'
     612        activate(p, p.life1())
     613        yield hold, self, 11
     614        assert not p.active(),'p active'
     615        assert not p.passive(),'p not passive'
     616        assert p.terminated(),'p not terminated'
     617        assert not p.interrupted(),'p interrupted'
     618
     619 -   def look3(self, p):
     620        assert not p.active(),'p active'
     621        assert p.passive(),'p not passive'
     622        assert not p.terminated(),'p not terminated'
     623        assert not p.interrupted(),'p interrupted'
     624        activate(p, p.life2())
     625        yield hold, self, 11
     626        assert not p.active(),'p active'
     627        assert p.passive(),'p not passive'
     628        assert not p.terminated(),'p terminated'
     629        assert not p.interrupted(),'p interrupted'
     630
     631 -   def look4(self, p):
     632        yield hold, self, 5
     633        assert p.active(),'p not active'
     634        assert not p.passive(),'p passive'
     635        assert not p.terminated(),'p terminated'
     636        assert not p.interrupted(),'p interrupted'
     637        self.cancel(p)
     638        assert not p.active(),'p active'
     639        assert p.passive(),'p not passive'
     640        assert not p.terminated(),'p terminated'
     641        assert not p.interrupted(),'p interrupted'
     642        reactivate(p)
     643        assert p.active(),'p not active'
     644        assert not p.passive(),'p passive'
     645        assert not p.terminated(),'p terminated'
     646        assert not p.interrupted(),'p interrupted'
     647        yield hold, self
     648        assert not p.active(),'p active'
     649        assert not p.passive(),'p passive'
     650        assert p.terminated(),'p terminated'
     651        assert not p.interrupted(),'p interrupted'
     652
     653 -   def look5(self, p):
     654        yield hold, self, 11
     655        assert not p.active(),'p active'
     656        assert p.passive(),'p not passive'
     657        assert not p.terminated(),'p terminated'
     658        assert not p.interrupted(),'p interrupted'
     659        self.cancel(p)
     660        assert not p.active(),'p active'
     661        assert p.passive(),'p not passive'
     662        assert not p.terminated(),'p terminated'
     663        assert not p.interrupted(),'p interrupted'
     664
     665 -class PS2(Process):
     666 -   def __init__(self):
     667        Process.__init__(self)
     668
     669 -   def life1(self, res):
     670        yield hold, self, 1
     671        yield request, self, res
     672        yield hold, self, 5
     673        yield request, self, res
     674
     675 -   def life2(self, res):
     676        yield request, self, res
     677        assert self.interrupted(),'p not interrupted'
     678        assert self.queuing(res)
     679        self.interruptReset()
     680        assert not self.interrupted(), 'p interrupted'
     681        assert self.queuing(res)
     682
     683 -class Observer2(Process):
     684 -   def __init__(self):
     685        Process.__init__(self)
     686
     687 -   def look1(self, p1, p2, res):
     688        assert p1.active(), 'p1 not active'
     689        assert not p1.queuing(res), 'p1 queuing'
     690        assert p2.active(), 'p2 noit active'
     691        assert not p2.queuing(res), 'p2 queuing'
     692        yield hold, self, 2
     693        assert p1.active(), 'p1 not active'
     694        assert not p1.queuing(res), 'p1 queuing'
     695        assert p2.passive(), 'p2 active'
     696        assert p2.queuing(res), 'p2 not queuing'
     697
     698 -   def look2(self, p,res):
     699        yield request, self, res
     700        yield hold, self, 5
     701        assert p.passive(),'p not passive'
     702        assert p.queuing(res),'p not queuing for resource'
     703        assert not p.interrupted(), 'p interrupted'
     704        self.interrupt(p)
     705        yield hold, self
     706
     707 -class makePStatetestcase(unittest.TestCase):
     708     """
     709     Tests states and state transitions as defined in SEP003
     710     """
     711
     712 -   def testState1(self):
     713        """
     714        Tests state transitions by hold
     715        """
     716        ## active => hold => terminated
     717        initialize()
     718        p = PS1()
     719        activate(p, p.life1())
     720        ob = Observer1()
     721        activate(ob, ob.look1(p),prior = True)
     722        simulate(until = 12)
     723
     724 -   def testState2(self):
     725        """
     726        Tests state transitions by activate and passivate
     727        """
     728        ## passive => activate => hold => terminated
     729        initialize()
     730        p = PS1()
     731        ob1 = Observer1()
     732        activate(ob1, ob1.look2(p))
     733        simulate(until = 12)
     734        ## passive => activate => hold => active => passivate => passive
     735        initialize()
     736        p1 = PS1()
     737        ob2 = Observer1()
     738        activate(ob2, ob2.look3(p1),prior = True)
     739        simulate(until = 12)
     740
     741 -   def testState3(self):
     742        """
     743        Tests state transitions by cancel()
     744        """
     745        ## active => cancel => passive => reactivate => active => terminated
     746        initialize()
     747        p2 = PS1()
     748        activate(p2, p2.life1())
     749        ob3 = Observer1()
     750        activate(ob3, ob3.look4(p2))
     751        simulate(until = 12)
     752
     753        ## passive => cancel => passive
     754        initialize()
     755        p3 = PS1()
     756        activate(p3, p3.life2())
     757        ob4 = Observer1()
     758        activate(ob4, ob4.look5(p3))
     759        simulate(until = 12)
     760
     761 -   def testState4(self):
     762        """
     763        Test request / release state transitions
     764        """
     765        ## not queuing, active => request => queuing, passive => release => not queuing, active
     766        initialize()
     767        res = Resource(capacity = 1)
     768        pq1 = PS2()
     769        activate(pq1, pq1.life1(res))
     770        pq2 = PS2()
     771        activate(pq2, pq2.life1(res))
     772        obq1 = Observer2()
     773        activate(obq1, obq1.look1(pq1, pq2, res))
     774        simulate(until = 12)
     775
     776        ## queuing, passive => interrupt =>  queuing, interrupted => interruptRest => queuing, not interrupted
     777        initialize()
     778        res = Resource(capacity = 1)
     779        pq3 = PS2()
     780        activate(pq3, pq3.life2(res))
     781        obq2 = Observer2()
     782        activate(obq2, obq2.look2(pq3, res),prior = True)
     783        simulate(until = 12)
     784
     785
     786
     787 -def makePSuite():
     788     suite = unittest.TestSuite()
     789     testState1 = makePStatetestcase('testState1')
     790     testState2 = makePStatetestcase('testState2')
     791     testState3 = makePStatetestcase('testState3')
     792     testState4 = makePStatetestcase('testState4')
     793     suite.addTests([testState1, testState2, testState3, testState4])
     794     return suite
     795
     796  ## -------------------------------------------------------------
     797  ##                    TEST Events / Signals
     798  ## -------------------------------------------------------------
     799
     800 -class SignalProcess(Process):
     801 -   def makeSignal(self, ev1, ev2):
     802        yield hold, self, 1
     803        ev1.signal('from SignalProcess')
     804        while ev2.queues:
     805           nq0 = len(ev2.queues)
     806           ev2.signal('from SignalProcess')
     807           assert len(ev2.queues) == (nq0 - 1),'wrong number of processes dequeued'
     808
     809 -class WaitProcess(Process):
     810 -   def waitForSig(self, ev1):
     811        yield waitevent, self, ev1
     812        assert ev1.waits == [],'not all processes waiting for event out of waiting list'
     813        assert ev1 in self.eventsFired, 'did not record firing event'
     814
     815 -class QueueProcess(Process):
     816 -   def queueForSig(self, ev2):
     817        yield queueevent, self, ev2
     818        assert ev2 in self.eventsFired, 'did not record firing event'
     819
     820 -class SignalProcessOR(Process):
     821 -   def makeSignal(self, ev1, ev2):
     822        yield hold, self, 1
     823        ev1.signal('from SignalProcess')
     824        yield hold, self, 3
     825        assert len(ev2.queues) == QueueProcessOR.nrProcesses, 'wrong number of processes queuing for event ev2'
     826        while ev2.queues:
     827           nq0 = len(ev2.queues)
     828           ev2.signal('from SignalProcess')
     829           assert len(ev2.queues) == (nq0 - 1),'wrong number of processes dequeued'
     830        assert not ev2.queues, 'not all processes queuing for ev2 dequeued'
     831
     832 -class WaitProcessOR(Process):
     833 -   def waitForSig(self, evset):
     834        yield waitevent, self, evset
     835        for e in evset:
     836           assert e.waits == [],'process not out of waiting list for all events in OR'
     837
     838 -class WaitProcessOR1(Process):
     839 -    def signalandwait(self):
     840        e1 = SimEvent()
     841        e1.signal()
     842        e2 = SimEvent()
     843        e2.signal()
     844        yield waitevent, self,[e1, e2]
     845        assert self.eventsFired == [e1, e2],'eventsFired does not report all events'
     846
     847
     848 -class QueueProcessOR(Process):
     849      nrProcesses = 0
     850 -    def __init__(self):
     851          Process.__init__(self)
     852          QueueProcessOR.nrProcesses += 1
     853 -    def queueForSig(self, evset):
     854        yield queueevent, self, evset
     855        occurred = False
     856        for e in evset:
     857            occurred = occurred or (e in self.eventsFired)
     858        assert occurred, 'queuing process activated by wrong event(s)'
     859
     860 -class QueueProcessOR1(Process):
     861 -    def signalandqueue(self):
     862          e1 = SimEvent()
     863          e1.signal()
     864          e2 = SimEvent()
     865          e2.signal()
     866          yield queueevent, self,[e1, e2]
     867          assert self.eventsFired == [e1, e2],\
     868                  '(queueevent) eventsFired does not report all fired events'
     869
     870 -class makeEtestcase(unittest.TestCase):
     871     """
     872     Test SimEvent / signal as introduced with SimPy 1.5
     873     """
     874
     875 -   def testSimEvents1(self):
     876        """
     877        Tests basic signal semantics
     878        """
     879        e = SimEvent()
     880        e.signal('param')
     881        assert e.occurred, 'signal does not set \'occurred\' to True'
     882        assert e.signalparam == 'param', 'signal parameter wrong'
     883        e.signal()
     884        assert e.signalparam is None, 'signal with no parameter did not overwrite signalparam'
     885        e.signal()
     886        assert e.occurred, 'multiple calls to signal do not set \'occurred\''
     887
     888 -   def testSimEvents2(self):
     889        """
     890        Tests basic waiting and queuing semantics
     891        """
     892        initialize()
     893        ev1 = SimEvent('ev1')
     894        ev2 = SimEvent('ev2')
     895        w1 = WaitProcess()
     896        activate(w1, w1.waitForSig(ev1))
     897        w2 = WaitProcess()
     898        activate(w2, w2.waitForSig(ev1))
     899        for i in range(3):
     900           q = QueueProcess()
     901           activate(q, q.queueForSig(ev2))
     902        simulate(until = 2)
     903
     904 -   def testSimEvents3(self):
     905        """
     906        Tests waiting, queuing for at least one event out of a list / tuple.
     907        """
     908        initialize()
     909        e1 = SimEvent('e1')
     910        e2 = SimEvent('e2')
     911        e3 = SimEvent('e3')
     912        s = SignalProcessOR()
     913        activate(s, s.makeSignal(e1, e3))
     914        w = WaitProcessOR()
     915        activate(w, w.waitForSig([e1, e2]))
     916        for i in range(5):
     917           q = QueueProcessOR()
     918           activate(q, q.queueForSig([e2, e3]))
     919        simulate(until = 10)
     920
     921 -   def testSimEvents4(self):
     922        """Tests that eventsFired reports all events which fired
     923        """
     924        initialize()
     925        w = WaitProcessOR1()
     926        activate(w, w.signalandwait())
     927        simulate(until = 5)
     928
     929 -   def testSimEvents5(self):
     930        """Tests that eventsFired reports all events which fired
     931        """
     932        initialize()
     933        w = QueueProcessOR1()
     934        activate(w, w.signalandqueue())
     935        simulate(until = 5)
     936
     937 -def makeESuite():
     938     suite = unittest.TestSuite()
     939     testSimEvents1 = makeEtestcase('testSimEvents1')
     940     testSimEvents2 = makeEtestcase('testSimEvents2')
     941     testSimEvents3 = makeEtestcase('testSimEvents3')
     942     testSimEvents4 = makeEtestcase('testSimEvents4')
     943     testSimEvents5 = makeEtestcase('testSimEvents5')
     944     suite.addTests([testSimEvents1, testSimEvents2, testSimEvents3, testSimEvents4, testSimEvents5])
     945     return suite
     946
     947  ## -------------------------------------------------------------
     948  ##                    TEST waituntil
     949  ## -------------------------------------------------------------
     950
     951 -class Signaller(Process):
     952 -    def makeconditions(self, waiter):
     953          global a, b,c
     954          a = True
     955          yield hold, self, 1
     956          b = True
     957          yield hold, self, 1
     958          c = True
     959          yield hold, self, 1
     960          assert waiter.terminated(),'waituntil did not fire'
     961
     962 -class Waiter(Process):
     963 -    def waitforit(self):
     964          def waitcond():
     965              return a and b and c
     966          yield waituntil, self, waitcond
     967
     968 -class makeWtestcase(unittest.TestCase):
     969     """
     970     Test waituntil as introduced with SimPy 1.5
     971     """
     972
     973 -   def testwaituntil1(self):
     974         global a, b,c
     975         a = b=c = False
     976         initialize()
     977         w = Waiter()
     978         activate(w, w.waitforit())
     979         s = Signaller()
     980         activate(s, s.makeconditions(w))
     981         simulate(until = 5)
     982
     983 -def makeWSuite():
     984     suite = unittest.TestSuite()
     985     testwaituntil1 = makeWtestcase('testwaituntil1')
     986     suite.addTests([testwaituntil1])
     987     return suite
     988
     989  ## -------------------------------------------------------------
     990  ##                    TEST COMPOUND 'YIELD REQUEST' COMMANDS
     991  ## -------------------------------------------------------------
     992
     993  ## -------------------------------------------------------------
     994  ##             TEST 'yield (request, self, res),(hold, self, delay)'
     995  ##                   == timeout renege
     996  ##             for both unmonitored and monitored resources
     997  ## -------------------------------------------------------------
     998
     999 -class JobTO(Process):
    1000     """ Job class for testing timeout reneging
    1001     """
    1002 -   def __init__(self, server = None, name = ''):
    1003          Process.__init__(self, name)
    1004          self.res = server
    1005          self.gotResource = None
    1006
    1007 -   def execute(self, timeout, usetime):
    1008          yield (request, self, self.res),(hold, self, timeout)
    1009          if self.acquired(self.res):
    1010              self.gotResource = True
    1011              yield hold, self, usetime
    1012              yield release, self, self.res
    1013          else:
    1014              self.gotResource = False
    1015
    1016 -class JobTO_P(Process):
    1017     """ Job class for testing timeout reneging with priorities
    1018     """
    1019 -   def __init__(self, server = None, name = ''):
    1020          Process.__init__(self, name)
    1021          self.res = server
    1022          self.gotResource = None
    1023
    1024 -   def execute(self, timeout, usetime, priority):
    1025          yield (request, self, self.res, priority),(hold, self, timeout)
    1026          if self.acquired(self.res):
    1027              self.gotResource = True
    1028              yield hold, self, usetime
    1029              yield release, self, self.res
    1030          else:
    1031              self.gotResource = False
    1032
    1033 -class makeTimeoutTestcase(unittest.TestCase):
    1034      """ Tests of 'yield (request, self, res),(hold, self, delay)'
    1035          timeout reneging command
    1036      """
    1037 -    def testNoTimeout(self):
    1038          """Test that resource gets acquired without timeout
    1039          """
    1040          res = Resource(name = 'Server', capacity = 1)
    1041          initialize()
    1042          usetime = 5
    1043          timeout = 1000000
    1044          j1 = JobTO(server = res, name = 'Job_1')
    1045          activate(j1, j1.execute(timeout = timeout, usetime = usetime))
    1046          j2 = JobTO(server = res, name = 'Job_2')
    1047          activate(j2, j2.execute(timeout = timeout, usetime = usetime))
    1048          simulate(until = 2 * usetime)
    1049          assert now() == 2 * usetime, 'time not == 2 * usetime'
    1050          assert j1.gotResource and j2.gotResource,\
    1051              'at least one job failed to get resource'
    1052          assert not (res.waitQ or res.activeQ),\
    1053              'job waiting or using resource'
    1054
    1055 -    def testNoTimeoutM(self):
    1056          """Test that resource gets acquired without timeout.
    1057             Resource monitored.
    1058          """
    1059          res = Resource(name = 'Server', capacity = 1, monitored = True)
    1060          initialize()
    1061          usetime = 5
    1062          timeout = 1000000
    1063          j1 = JobTO(server = res, name = 'Job_1')
    1064          activate(j1, j1.execute(timeout = timeout, usetime = usetime))
    1065          j2 = JobTO(server = res, name = 'Job_2')
    1066          activate(j2, j2.execute(timeout = timeout, usetime = usetime))
    1067          simulate(until = 2 * usetime)
    1068          assert now() == 2 * usetime, 'time not == 2 * usetime'
    1069          assert j1.gotResource and j2.gotResource,\
    1070              'at least one job failed to get resource'
    1071          assert not (res.waitQ or res.activeQ),\
    1072              'job waiting or using resource'
    1073          assert res.waitMon == [[0, 1],[usetime, 0]],'res.waitMon wrong: %s'%res.waitMon
    1074
    1075 -    def testTimeout1(self):
    1076          """Test that timeout occurs when resource busy
    1077          """
    1078          res = Resource(name = 'Server', capacity = 1)
    1079          initialize()
    1080          usetime = 5
    1081          timeout = 3
    1082          j1 = JobTO(server = res, name = 'Job_1')
    1083          activate(j1, j1.execute(timeout = timeout, usetime = usetime))
    1084          j2 = JobTO(server = res, name = 'Job_2')
    1085          activate(j2, j2.execute(timeout = timeout, usetime = usetime))
    1086          simulate(until = 2 * usetime)
    1087          assert(now() == usetime),'time not == usetime'
    1088          assert(j1.gotResource),'Job_1 did not get resource'
    1089          assert(not j2.gotResource),'Job_2 did not renege'
    1090          assert not (res.waitQ or res.activeQ),\
    1091              'job waiting or using resource'
    1092
    1093 -    def testTimeout1M(self):
    1094          """Test that timeout occurs when resource busy.
    1095             Resource monitored.
    1096          """
    1097          res = Resource(name = 'Server', capacity = 1, monitored = True)
    1098          initialize()
    1099          usetime = 5
    1100          timeout = 3
    1101          j1 = JobTO(server = res, name = 'Job_1')
    1102          activate(j1, j1.execute(timeout = timeout, usetime = usetime))
    1103          j2 = JobTO(server = res, name = 'Job_2')
    1104          activate(j2, j2.execute(timeout = timeout, usetime = usetime))
    1105          simulate(until = 2 * usetime)
    1106          assert(now() == usetime),'time not == usetime'
    1107          assert(j1.gotResource),'Job_1 did not get resource'
    1108          assert(not j2.gotResource),'Job_2 did not renege'
    1109          assert not (res.waitQ or res.activeQ),\
    1110              'job waiting or using resource'
    1111          assert res.waitMon == [[0, 1],[timeout, 0]],'res.waitMon wrong: %s'%res.waitMon
    1112
    1113 -    def testTimeout_MP(self):
    1114          """Test that timeout occurs when resource busy.
    1115             Resource monitored. Requests with priority and preemption.
    1116          """
    1117          res = Resource(name = 'Server', capacity = 1, monitored = True, qType = PriorityQ, preemptable = True)
    1118          initialize()
    1119          usetime = 5
    1120          timeout = 3
    1121          j1 = JobTO_P(server = res, name = 'Job_1')
    1122          activate(j1, j1.execute(timeout = timeout, usetime = usetime, priority = 1))
    1123          j2 = JobTO_P(server = res, name = 'Job_2')
    1124          j2_arrival = 1
    1125          activate(j2, j2.execute(timeout = timeout, usetime = usetime, priority = 5),at = j2_arrival)
    1126          j3 = JobTO_P(server = res, name = 'Job_2')
    1127          j3_arrival = 2
    1128          activate(j3, j3.execute(timeout = timeout, usetime = usetime, priority = 10),at = j3_arrival)
    1129          simulate(until = 3 * usetime)
    1130          assert(now() == 3 * usetime),'time not == 2 * usetime, but %s'%now()
    1131          assert(j1.gotResource),'Job_1 did not get resource'
    1132          assert(j2.gotResource),'Job_2 did renege'
    1133          assert(j2.gotResource),'Job_3 did renege'
    1134          assert not (res.waitQ or res.activeQ),\
    1135              'job waiting or using resource'
    1136          assert res.waitMon == [[j2_arrival, 1],[j3_arrival, 2],[usetime + j3_arrival, 1],[usetime + j2_arrival + usetime, 0]],\
    1137               'res.waitMon wrong: %s'%res.waitMon
    1138
    1139 -    def testTimeout2(self):
    1140          """Test that timeout occurs when resource has no capacity free
    1141          """
    1142          res = Resource(name = 'Server', capacity = 0)
    1143          initialize()
    1144          usetime = 5
    1145          timeout = 3
    1146          j1 = JobTO(server = res, name = 'Job_1')
    1147          activate(j1, j1.execute(timeout = timeout, usetime = usetime))
    1148          j2 = JobTO(server = res, name = 'Job_2')
    1149          activate(j2, j2.execute(timeout = timeout, usetime = usetime))
    1150          simulate(until = 2 * usetime)
    1151          assert now() == timeout, 'time %s not == timeout'%now()
    1152          assert not j1.gotResource, 'Job_1 got resource'
    1153          assert not j2.gotResource, 'Job_2 got resource'
    1154          assert not (res.waitQ or res.activeQ),\
    1155              'job waiting or using resource'
    1156
    1157 -    def testTimeout2M(self):
    1158          """Test that timeout occurs when resource has no capacity free.
    1159             Resource monitored.
    1160          """
    1161          res = Resource(name = 'Server', capacity = 0, monitored = True)
    1162          initialize()
    1163          usetime = 5
    1164          timeout = 3
    1165          j1 = JobTO(server = res, name = 'Job_1')
    1166          activate(j1, j1.execute(timeout = timeout, usetime = usetime))
    1167          j2 = JobTO(server = res, name = 'Job_2')
    1168          activate(j2, j2.execute(timeout = timeout, usetime = usetime))
    1169          simulate(until = 2 * usetime)
    1170          assert now() == timeout, 'time %s not == timeout'%now()
    1171          assert not j1.gotResource, 'Job_1 got resource'
    1172          assert not j2.gotResource, 'Job_2 got resource'
    1173          assert not (res.waitQ or res.activeQ),\
    1174              'job waiting or using resource'
    1175          assert res.waitMon == [[0, 1],[0, 2],[timeout, 1],[timeout, 0]],\
    1176              'res.waitMon is wrong: %s'%res.waitMon
    1177
    1178 -def makeTOSuite():
    1179      suite = unittest.TestSuite()
    1180      testNoTimeout = makeTimeoutTestcase('testNoTimeout')
    1181      testNoTimeoutM = makeTimeoutTestcase('testNoTimeoutM')
    1182      testTimeout1 = makeTimeoutTestcase('testTimeout1')
    1183      testTimeout1M = makeTimeoutTestcase('testTimeout1M')
    1184      testTimeout_MP = makeTimeoutTestcase('testTimeout_MP')
    1185      testTimeout2 = makeTimeoutTestcase('testTimeout2')
    1186      testTimeout2M = makeTimeoutTestcase('testTimeout2M')
    1187      suite.addTests([testNoTimeout, testNoTimeoutM,
    1188                      testTimeout1, testTimeout1M, testTimeout_MP,
    1189                     testTimeout2, testTimeout2M])
    1190      return suite
    1191
    1192  ## ------------------------------------------------------------------
    1193  ##             TEST 'yield (request, self, res),(waitevent, self, event)'
    1194  ##                   == event renege
    1195  ##             for both unmonitored and monitored resources
    1196  ## ------------------------------------------------------------------
    1197
    1198
    1199 -class JobEvt(Process):
    1200     """ Job class for testing event reneging
    1201     """
    1202 -   def __init__(self, server = None, name = ''):
    1203          Process.__init__(self, name)
    1204          self.res = server
    1205          self.gotResource = None
    1206
    1207 -   def execute(self, event, usetime):
    1208          yield (request, self, self.res),(waitevent, self, event)
    1209          if self.acquired(self.res):
    1210              self.gotResource = True
    1211              yield hold, self, usetime
    1212              yield release, self, self.res
    1213          else:
    1214              self.gotResource = False
    1215
    1216 -class JobEvtMulti(Process):
    1217     """ Job class for testing event reneging with multi - event lists
    1218     """
    1219 -   def __init__(self, server = None, name = ''):
    1220          Process.__init__(self, name)
    1221          self.res = server
    1222          self.gotResource = None
    1223
    1224 -   def execute(self, eventlist, usetime):
    1225          yield (request, self, self.res),(waitevent, self, eventlist)
    1226          if self.acquired(self.res):
    1227              self.gotResource = True
    1228              yield hold, self, usetime
    1229              yield release, self, self.res
    1230          else:
    1231              self.gotResource = False
    1232
    1233 -class FireEvent(Process):
    1234      """Fires reneging event
    1235      """
    1236 -    def fire(self, fireDelay, event):
    1237          yield hold, self, fireDelay
    1238          event.signal()
    1239
    1240 -class makeEventRenegeTestcase(unittest.TestCase):
    1241      """Tests of 'yield (request, self, res),(waiteevent, self, event)'
    1242         event reneging command
    1243      """
    1244 -    def testNoEvent(self):
    1245          """Test that processes acquire resource normally if no event fires
    1246          """
    1247          res = Resource(name = 'Server', capacity = 1)
    1248          event = SimEvent('Renege_trigger') #never gets fired
    1249          initialize()
    1250          usetime = 5
    1251          j1 = JobEvt(server = res, name = 'Job_1')
    1252          activate(j1, j1.execute(event = event, usetime = usetime))
    1253          j2 = JobEvt(server = res, name = 'Job_2')
    1254          activate(j2, j2.execute(event = event, usetime = usetime))
    1255          simulate(until = 2 * usetime)
    1256          # Both jobs should get server (in sequence)
    1257          assert now() == 2 * usetime, 'time not == 2 * usetime'
    1258          assert j1.gotResource and j2.gotResource,\
    1259              'at least one job failed to get resource'
    1260          assert not (res.waitQ or res.activeQ),\
    1261              'job waiting or using resource'
    1262
    1263 -    def testNoEventM(self):
    1264          """Test that processes acquire resource normally if no event fires.
    1265             Resource monitored.
    1266          """
    1267          res = Resource(name = 'Server', capacity = 1, monitored = True)
    1268          event = SimEvent('Renege_trigger') #never gets fired
    1269          initialize()
    1270          usetime = 5
    1271          j1 = JobEvt(server = res, name = 'Job_1')
    1272          activate(j1, j1.execute(event = event, usetime = usetime))
    1273          j2 = JobEvt(server = res, name = 'Job_2')
    1274          activate(j2, j2.execute(event = event, usetime = usetime))
    1275          simulate(until = 2 * usetime)
    1276          # Both jobs should get server (in sequence)
    1277          assert now() == 2 * usetime, 'time not == 2 * usetime'
    1278          assert j1.gotResource and j2.gotResource,\
    1279              'at least one job failed to get resource'
    1280          assert not (res.waitQ or res.activeQ),\
    1281              'job waiting or using resource'
    1282          assert res.waitMon == [[0, 1],[usetime, 0]],'res.waitMoni is wrong: %s'%res.waitMon
    1283
    1284 -    def testWaitEvent1(self):
    1285          """Test that signalled event leads to renege when resource busy
    1286          """
    1287          res = Resource(name = 'Server', capacity = 1)
    1288          initialize()
    1289          event = SimEvent('Renege_trigger')
    1290          usetime = 5
    1291          eventtime = 1
    1292          j1 = JobEvt(server = res, name = 'Job_1')
    1293          activate(j1, j1.execute(event = event, usetime = usetime))
    1294          j2 = JobEvt(server = res, name = 'Job_2')
    1295          activate(j2, j2.execute(event = event, usetime = usetime))
    1296          f = FireEvent(name = 'FireEvent')
    1297          activate(f, f.fire(fireDelay = eventtime, event = event))
    1298          simulate(until = 2 * usetime)
    1299          # Job_1 should get server, Job_2 renege
    1300          assert(now() == usetime),'time not == usetime'
    1301          assert(j1.gotResource),'Job_1 did not get resource'
    1302          assert(not j2.gotResource),'Job_2 did not renege'
    1303          assert not (res.waitQ or res.activeQ),\
    1304              'job waiting or using resource'
    1305
    1306 -    def testWaitEvent1M(self):
    1307          """Test that signalled event leads to renege when resource busy.
    1308             Resource monitored.
    1309          """
    1310          res = Resource(name = 'Server', capacity = 1, monitored = True)
    1311          initialize()
    1312          event = SimEvent('Renege_trigger')
    1313          usetime = 5
    1314          eventtime = 1
    1315          j1 = JobEvt(server = res, name = 'Job_1')
    1316          activate(j1, j1.execute(event = event, usetime = usetime))
    1317          j2 = JobEvt(server = res, name = 'Job_2')
    1318          activate(j2, j2.execute(event = event, usetime = usetime))
    1319          f = FireEvent(name = 'FireEvent')
    1320          activate(f, f.fire(fireDelay = eventtime, event = event))
    1321          simulate(until = 2 * usetime)
    1322          # Job_1 should get server, Job_2 renege
    1323          assert(now() == usetime),'time not == usetime'
    1324          assert(j1.gotResource),'Job_1 did not get resource'
    1325          assert(not j2.gotResource),'Job_2 did not renege'
    1326          assert not (res.waitQ or res.activeQ),\
    1327              'job waiting or using resource'
    1328          assert res.waitMon == [[0, 1],[eventtime, 0]],'res.waitMon is wrong: %s'%res.waitMon
    1329
    1330 -    def testWaitEvent2(self):
    1331          """Test that renege - triggering event can be one of an event list
    1332          """
    1333          res = Resource(name = 'Server', capacity = 1)
    1334          initialize()
    1335          event1 = SimEvent('Renege_trigger_1')
    1336          event2 = SimEvent('Renege_trigger_2')
    1337          usetime = 5
    1338          eventtime = 1 #for both events
    1339          j1 = JobEvtMulti(server = res, name = 'Job_1')
    1340          activate(j1, j1.execute(eventlist = [event1, event2],usetime = usetime))
    1341          j2 = JobEvtMulti(server = res, name = 'Job_2')
    1342          activate(j2, j2.execute(eventlist = [event1, event2],usetime = usetime))
    1343          f1 = FireEvent(name = 'FireEvent_1')
    1344          activate(f1, f1.fire(fireDelay = eventtime, event = event1))
    1345          f2 = FireEvent(name = 'FireEvent_2')
    1346          activate(f2, f2.fire(fireDelay = eventtime, event = event2))
    1347          simulate(until = 2 * usetime)
    1348          # Job_1 should get server, Job_2 should renege
    1349          assert(now() == usetime),'time not == usetime'
    1350          assert(j1.gotResource),'Job_1 did not get resource'
    1351          assert(not j2.gotResource),'Job_2 did not renege'
    1352          assert not (res.waitQ or res.activeQ),\
    1353              'job waiting or using resource'
    1354
    1355 -    def testWaitEvent2M(self):
    1356          """Test that renege - triggering event can be one of an event list.
    1357             Resource monitored.
    1358          """
    1359          res = Resource(name = 'Server', capacity = 1, monitored = True)
    1360          initialize()
    1361          event1 = SimEvent('Renege_trigger_1')
    1362          event2 = SimEvent('Renege_trigger_2')
    1363          usetime = 5
    1364          eventtime = 1 #for both events
    1365          j1 = JobEvtMulti(server = res, name = 'Job_1')
    1366          activate(j1, j1.execute(eventlist = [event1, event2],usetime = usetime))
    1367          j2 = JobEvtMulti(server = res, name = 'Job_2')
    1368          activate(j2, j2.execute(eventlist = [event1, event2],usetime = usetime))
    1369          f1 = FireEvent(name = 'FireEvent_1')
    1370          activate(f1, f1.fire(fireDelay = eventtime, event = event1))
    1371          f2 = FireEvent(name = 'FireEvent_2')
    1372          activate(f2, f2.fire(fireDelay = eventtime, event = event2))
    1373          simulate(until = 2 * usetime)
    1374          # Job_1 should get server, Job_2 should renege
    1375          assert(now() == usetime),'time not == usetime'
    1376          assert(j1.gotResource),'Job_1 did not get resource'
    1377          assert(not j2.gotResource),'Job_2 did not renege'
    1378          assert not (res.waitQ or res.activeQ),\
    1379              'job waiting or using resource'
    1380          assert res.waitMon == [[0, 1],[eventtime, 0]],'res.waitMon is wrong: %s'%res.waitMon
    1381
    1382 -def makeEvtRenegeSuite():
    1383      suite = unittest.TestSuite()
    1384      testNoEvent = makeEventRenegeTestcase('testNoEvent')
    1385      testNoEventM = makeEventRenegeTestcase('testNoEventM')
    1386      testWaitEvent1 = makeEventRenegeTestcase('testWaitEvent1')
    1387      testWaitEvent1M = makeEventRenegeTestcase('testWaitEvent1M')
    1388      testWaitEvent2 = makeEventRenegeTestcase('testWaitEvent2')
    1389      testWaitEvent2M = makeEventRenegeTestcase('testWaitEvent2M')
    1390
    1391      suite.addTests([testNoEvent, testNoEventM, testWaitEvent1, testWaitEvent1M,
    1392                      testWaitEvent2, testWaitEvent2M])
    1393      return suite
    1394
    1395  #---Buffer tests (post 1.6.1)-------------------------------------
    1396  ## ------------------------------------------------------------------
    1397  ##             TEST 'yield get, self, level, whatToGet' and
    1398  ##                  'yield put, self, level, whatToPut, priority'
    1399  ##             for Level instances
    1400  ## ------------------------------------------------------------------
    1401 -class Producer(Process):
    1402      produced = 0
    1403 -    def produce(self, buffer):
    1404          for i in range(4):
    1405              Producer.produced += 1
    1406              yield put, self, buffer
    1407              yield hold, self, 1
    1408 -    def producePriority(self, buffer, priority):
    1409          """PriorityQ for Producers"""
    1410          Producer.produced += 4
    1411          yield put, self, buffer, 4,priority
    1412          yield hold, self, 1
    1413          self.done = now()
    1414          doneList.append(self.name)
    1415 -    def produce1(self, buffer):
    1416          for i in range(4):
    1417              yield put, self, buffer, 4
    1418              yield hold, self, 1
    1419 -class Consumer(Process):
    1420      consumed = 0
    1421 -    def consume(self, buffer):
    1422          """FIFO"""
    1423          yield get, self, buffer
    1424          Consumer.consumed += 1
    1425          assert self.got == 1, 'wrong self.got: %s'%self.got
    1426          yield get, self, buffer, 3
    1427          Consumer.consumed += 3
    1428          assert self.got == 3, 'wrong self.got: %s'%self.got
    1429
    1430 -    def consume1(self, buffer):
    1431          """producer PriorityQ, consumer FIFO"""
    1432          while True:
    1433              yield get, self, buffer, 2
    1434              yield hold, self, 1
    1435 -    def consumePriority(self, buffer, priority):
    1436          """PriorityQ for Consumers"""
    1437          yield get, self, buffer, 4,priority
    1438          doneList.append(self.name)
    1439
    1440  ### Begin classes for testConPrinciple (Level) ###
    1441 -class  ProducerPrincL(Process):
    1442 -    def produce(self, buffer, productionTime):
    1443          while True:
    1444              assert not(buffer.amount > 0 and len(buffer.getQ) > 0),\
    1445                  'Consumer(s) waiting while buffer not empty'
    1446              yield hold, self, productionTime
    1447              yield put, self, buffer, 1
    1448
    1449 -class ConsumerPrincL(Process):
    1450 -    def consume(self, buffer, consumptionTime):
    1451          while True:
    1452              assert not(buffer.amount == 0 and len(buffer.putQ) > 0),\
    1453                  'Producer(s) waiting while buffer empty'
    1454              yield get, self, buffer, 1
    1455              yield hold, self, consumptionTime
    1456
    1457  ### End classes for testConPrinciple (Level) ###
    1458
    1459 -class makeLevelTestcase(unittest.TestCase):
    1460 -    def testStatic(self):
    1461          """Tests initialization of Level instances
    1462          """
    1463          a = Level()
    1464          assert a.capacity == sys.maxint, 'wrong capacity:%s'%a
    1465          assert a.amount == 0, 'wrong buffer content: %s'%a
    1466          assert a.name == 'a_level', 'wrong name: %s'%a
    1467          assert not a.monitored, 'should not be monitored: %s'%a
    1468          assert a.putQMon is None, 'should not have putQMon: %s'%a
    1469          assert a.getQMon is None, 'should not have getQMon: %s'%a
    1470          assert a.bufferMon is None, 'should not have bufferMon: %s'%a
    1471          assert a.putQType.__name__ == 'FIFO' and a.getQType.__name__ == 'FIFO',\
    1472                 'putQType and getQType should be FIFO: %s'%a
    1473
    1474          b = Level(name = 'b', initialBuffered = 10.0, monitored = True, capacity = 12,
    1475                      putQType = PriorityQ)
    1476          a = Level()
    1477          assert b.capacity == 12, 'wrong capacity:%s'%b
    1478          assert b.amount == 10, 'wrong buffer content: %s'%b
    1479          assert b.name == 'b', 'wrong name: %s'%b
    1480          assert b.monitored, 'should be monitored: %s'%b
    1481          assert not (b.putQMon is None),'should have putQMon: %s'%b
    1482          assert not (b.getQMon is None),'should have getQMon: %s'%b
    1483          assert not (b.bufferMon is None),'should have bufferMon: %s'%b
    1484          assert b.putQType.__name__ == 'PriorityQ',\
    1485                 'putQType should be PriorityQ: %s'%b
    1486          assert b.getQType.__name__ == 'FIFO',\
    1487                  'getQType should be PriorityQ: %s'%b
    1488
    1489 -    def testConProdPrinciple(self):
    1490          """Level: tests basic Producer / Consumer principles:
    1491          -   Consumers must not be waiting while Level buffer value > 0,
    1492          -   Producers must not be waiting while Level buffer value == 0
    1493          """
    1494          bufferSize = 1
    1495          productionTime = 1
    1496          consumptionTime = 5
    1497          endtime = 50
    1498
    1499          initialize()
    1500          buffer = Level(capacity = bufferSize)
    1501          consumer = ConsumerPrincL()
    1502          activate(consumer, consumer.consume(buffer, consumptionTime))
    1503          producer = ProducerPrincL()
    1504          activate(producer, producer.produce(buffer, productionTime))
    1505          simulate(until = endtime)
    1506
    1507 -    def testConProd1(self):
    1508          """Level: tests put / get in 1 Producer / 1 Consumer scenario"""
    1509          initialize()
    1510          buffer = Level(initialBuffered = 0)
    1511          p = Producer()
    1512          activate(p, p.produce(buffer))
    1513          c = Consumer()
    1514          activate(c, c.consume(buffer))
    1515          simulate(until = 100)
    1516          assert Producer.produced - Consumer.consumed == buffer.amount,\
    1517              'items produced / consumed / buffered do not tally: %s %s %s'\
    1518                  %(Producer.produced, Consumer.consumed, buffer.amount)
    1519
    1520 -    def testConProdM(self):
    1521          """Level: tests put / get in multiple Producer / Consumer scenario"""
    1522          initialize()
    1523          buffer = Level(initialBuffered = 0)
    1524          Producer.produced = 0
    1525          Consumer.consumed = 0
    1526          for i in range(2):
    1527              c = Consumer()
    1528              activate(c, c.consume(buffer))
    1529          for i in range(3):
    1530              p = Producer()
    1531              activate(p, p.produce(buffer))
    1532          simulate(until = 10)
    1533          assert Producer.produced - Consumer.consumed == buffer.amount,\
    1534              'items produced / consumed / buffered do not tally: %s %s %s'\
    1535                  %(Producer.produced, Consumer.consumed, buffer.amount)
    1536
    1537 -    def testConProdPriorM(self):
    1538          """Level: tests put / get in multiple Producer / Consumer scenario,
    1539          with Producers having different priorities.
    1540          How: Producers forced to queue; all after first should be done in
    1541          priority order
    1542          """
    1543          global doneList
    1544          doneList = []
    1545          initialize()
    1546          buffer = Level(capacity = 7, putQType = PriorityQ, monitored = True)
    1547          for i in range(4):
    1548              p = Producer(i)
    1549              pPriority = i
    1550              activate(p, p.producePriority(buffer = buffer, priority = pPriority))
    1551          c = Consumer()
    1552          activate(c, c.consume1(buffer = buffer))
    1553          simulate(until = 100)
    1554          assert doneList == [0, 3,2, 1],'puts were not done in priority order: %s'\
    1555                                      %doneList
    1556
    1557 -    def testConPriorProdM(self):
    1558          """Level: tests put / get in multiple Producer / Consumer scenario, with
    1559          Consumers having different priorities.
    1560          How: Consumers forced to queue; all after first should be done in
    1561          priority order
    1562          """
    1563          global doneList
    1564          doneList = []
    1565          initialize()
    1566          buffer = Level(capacity = 7, getQType = PriorityQ, monitored = True)
    1567          for i in range(4):
    1568              c = Consumer(i)
    1569              cPriority = i
    1570              activate(c, c.consumePriority(buffer = buffer, priority = cPriority))
    1571          p = Producer()
    1572          activate(p, p.produce1(buffer = buffer))
    1573          simulate(until = 100)
    1574          assert doneList == [3, 2,1, 0],'gets were not done in priority order: %s'\
    1575                                      %doneList
    1576
    1577 -def makeLevelSuite():
    1578      suite = unittest.TestSuite()
    1579      testStatic = makeLevelTestcase('testStatic')
    1580      testConProdPrinciple = makeLevelTestcase('testConProdPrinciple')
    1581      testConProd1 = makeLevelTestcase('testConProd1')
    1582      testConProdM = makeLevelTestcase('testConProdM')
    1583      testConProdPriorM = makeLevelTestcase('testConProdPriorM')
    1584      testConPriorProdM = makeLevelTestcase('testConPriorProdM')
    1585      suite.addTests([testStatic, testConProdPrinciple, testConProd1,
    1586                      testConProdM, testConProdPriorM,
    1587                      testConPriorProdM])
    1588      return suite
    1589
    1590  ## ------------------------------------------------------------------
    1591  ##             TEST 'yield get, self, store, whatToGet' and
    1592  ##                  'yield put, self, store, whatToPut'
    1593  ##             for Store instances
    1594  ## ------------------------------------------------------------------
    1595
    1596 -class ProducerWidget(Process):
    1597      produced = 0
    1598 -    def produce(self, buffer):
    1599          for i in range(4):
    1600              ProducerWidget.produced += 1
    1601              yield put, self, buffer,[Widget(weight = 5)]
    1602              yield hold, self, 1
    1603 -    def producePriority(self, buffer, priority):
    1604          """PriorityQ for Producers"""
    1605          ProducerWidget.produced += 4
    1606          toStore = [Widget(weight = 5)] * 4
    1607          yield put, self, buffer, toStore, priority
    1608          yield hold, self, 1
    1609          self.done = now()
    1610          doneList.append(self.name)
    1611 -    def produce1(self, buffer):
    1612          for i in range(4):
    1613              yield put, self, buffer,[Widget(weight = 5)] * 4
    1614              yield hold, self, 1
    1615 -    def produceUnordered(self, buffer):
    1616          produced = [Widget(weight = i) for i in [9, 1,8, 2,7, 3,6, 4,5]]
    1617          yield put, self, buffer, produced
    1618
    1619 -class ConsumerWidget(Process):
    1620      consumed = 0
    1621 -    def consume(self, buffer):
    1622          """FIFO"""
    1623          yield get, self, buffer
    1624          ConsumerWidget.consumed += 1
    1625          assert len(self.got) == 1, 'wrong self.got: %s'%self.got
    1626          yield get, self, buffer, 3
    1627          ConsumerWidget.consumed += 3
    1628          assert len(self.got) == 3, 'wrong self.got: %s'%self.got
    1629
    1630 -    def consume1(self, buffer):
    1631          """producer PriorityQ, consumer FIFO"""
    1632          while True:
    1633              yield get, self, buffer, 2
    1634              yield hold, self, 1
    1635
    1636 -    def consumePriority(self, buffer, priority):
    1637          """PriorityQ for Consumers"""
    1638          yield get, self, buffer, 4,priority
    1639          doneList.append(self.name)
    1640
    1641 -    def consumeSorted(self, buffer, gotten):
    1642          yield get, self, buffer
    1643          gotten.append(self.got[0].weight)
    1644
    1645 -class Widget:
    1646 -    def __init__(self, weight):
    1647          self.weight = weight
    1648
    1649 -def mySortFunc(self, par):
    1650      """Sorts Widget instances by weight attribute."""
    1651      tmplist = [(x.weight, x) for x in par]
    1652      tmplist.sort()
    1653      return [x for (key, x) in tmplist]
    1654
    1655  ### Begin classes for testConPrinciple (Store) ###
    1656 -class  ProducerPrincS(Process):
    1657 -    def produce(self, buffer, productionTime):
    1658          while True:
    1659              assert not(buffer.nrBuffered > 0 and len(buffer.getQ) > 0),\
    1660                  'Consumer(s) waiting while buffer not empty'
    1661              yield hold, self, productionTime
    1662              product = WidgetPrinc()
    1663              yield put, self, buffer,[product]
    1664
    1665 -class ConsumerPrincS(Process):
    1666 -    def consume(self, buffer, consumptionTime):
    1667          while True:
    1668              assert not(buffer.nrBuffered == 0 and buffer.putQ),\
    1669                  'Producer(s) waiting while buffer empty'
    1670              yield get, self, buffer, 1
    1671              yield hold, self, consumptionTime
    1672
    1673 -class WidgetPrinc:
    1674      pass
    1675
    1676 -class FilterConsumer(Process):
    1677      """Used in testBufferFilter"""
    1678 -    class Widget:
    1679 -        def __init__(self, weighs):
    1680              self.weight = weighs
    1681
    1682 -    def getItems(self, store, a,b):
    1683          """get all items with weight between a and b"""
    1684          def between_a_and_b(buf):
    1685              res = []
    1686              for item in buf:
    1687                  if a < item.weight < b:
    1688                      res.append(item)
    1689
    1690          all = store.buffered
    1691          yield get, self, store, between_a_and_b
    1692          'All retrieved items weight in range?'
    1693          for it in self.got:
    1694              assert a < it.weight < b, 'weight %s not in range %s..%s'\
    1695                                   %(it.weight, a,b)
    1696          'Any item fitting filter pred left in buffer?'
    1697          for it in store.buffer:
    1698              assert not (a < it.weight < b),\
    1699                  'item left in buffer which fits filter (%s<%s<%s)'\
    1700                  %(a, it.weight, b)
    1701          'All items either in store.buffer of self.got?'
    1702          for it in all:
    1703              assert (it in self.buffer) or (it in self.got),\
    1704                     'item w. weight %s neither in store nor in got'%it.weight
    1705
    1706  ### End classes for testConPrinciple (Store) ###
    1707
    1708 -class makeStoreTestcase(unittest.TestCase):
    1709 -    def testStatic(self):
    1710          """Store: tests initialization of Store instances
    1711          """
    1712          a = Store()
    1713          assert a.capacity == sys.maxint, 'wrong capacity:%s'%a
    1714          assert a.nrBuffered == 0, 'wrong buffer content: %s'%a
    1715          assert a.name == 'a_store', 'wrong name: %s'%a
    1716          assert not a.monitored, 'should not be monitored: %s'%a
    1717          assert a.putQMon is None, 'should not have putQMon: %s'%a
    1718          assert a.getQMon is None, 'should not have getQMon: %s'%a
    1719          assert a.bufferMon is None, 'should not have bufferMon: %s'%a
    1720          assert a.putQType.__name__ == 'FIFO' and a.getQType.__name__ == 'FIFO',\
    1721                 'putQType and getQType should be FIFO: %s'%a
    1722
    1723          stored = [Widget(weight = 5)] * 10
    1724          b = Store(name = 'b', initialBuffered = stored, monitored = True, capacity = 12,
    1725                      putQType = PriorityQ)
    1726          assert b.capacity == 12, 'wrong capacity:%s'%b
    1727          assert b.nrBuffered == 10, 'wrong buffer content: %s'%b
    1728          assert b.name == 'b', 'wrong name: %s'%b
    1729          assert b.monitored, 'should be monitored: %s'%b
    1730          assert not (b.putQMon is None),'should have putQMon: %s'%b
    1731          assert not (b.getQMon is None),'should have getQMon: %s'%b
    1732          assert not (b.bufferMon is None),'should have bufferMon: %s'%b
    1733          assert b.putQType.__name__ == 'PriorityQ',\
    1734                 'putQType should be PriorityQ: %s'%b
    1735          assert b.getQType.__name__ == 'FIFO',\
    1736                  'getQType should be PriorityQ: %s'%b
    1737
    1738 -    def testConProdPrinciple(self):
    1739          """Store: tests basic Producer / Consumer principles:
    1740          -   Consumers must not be waiting while items in Store buffer,
    1741          -   Producers must not be waiting while space available in Store buffer
    1742          """
    1743          bufferSize = 1
    1744          productionTime = 1
    1745          consumptionTime = 5
    1746          endtime = 50
    1747
    1748          initialize()
    1749          buffer = Store(capacity = bufferSize)
    1750          consumer = ConsumerPrincS()
    1751          activate(consumer, consumer.consume(buffer, consumptionTime))
    1752          producer = ProducerPrincS()
    1753          activate(producer, producer.produce(buffer, productionTime))
    1754          simulate(until = endtime)
    1755
    1756 -    def testConProd1(self):
    1757          """Store: tests put / get in 1 Producer / 1 Consumer scenario"""
    1758          initialize()
    1759          buffer = Store(initialBuffered = [])
    1760          p = ProducerWidget()
    1761          activate(p, p.produce(buffer))
    1762          c = ConsumerWidget()
    1763          activate(c, c.consume(buffer))
    1764          simulate(until = 100)
    1765          assert \
    1766             ProducerWidget.produced - ConsumerWidget.consumed == buffer.nrBuffered,\
    1767             'items produced / consumed / buffered do not tally: %s %s %s'\
    1768             %(ProducerWidget.produced, ConsumerWidget.consumed, buffer.nrBuffered)
    1769
    1770 -    def testConProdM(self):
    1771          """Store: tests put / get in multiple Producer / Consumer scenario"""
    1772          initialize()
    1773          buffer = Store(initialBuffered = [])
    1774          ProducerWidget.produced = 0
    1775          ConsumerWidget.consumed = 0
    1776          for i in range(2):
    1777              c = ConsumerWidget()
    1778              activate(c, c.consume(buffer))
    1779          for i in range(3):
    1780              p = ProducerWidget()
    1781              activate(p, p.produce(buffer))
    1782          simulate(until = 10)
    1783          assert ProducerWidget.produced - ConsumerWidget.consumed == buffer.nrBuffered,\
    1784              'items produced / consumed / buffered do not tally: %s %s %s'\
    1785              %(ProducerWidget.produced, ConsumerWidget.consumed, buffer.nrBuffered)
    1786
    1787 -    def testConProdPriorM(self):
    1788          """Store: Tests put / get in multiple Producer / Consumer scenario,
    1789          with Producers having different priorities.
    1790          How; Producers forced to queue; all after first should be done in
    1791          priority order
    1792          """
    1793          global doneList
    1794          doneList = []
    1795          initialize()
    1796          buffer = Store(capacity = 7, putQType = PriorityQ, monitored = True)
    1797          for i in range(4):
    1798              p = ProducerWidget(i)
    1799              pPriority = i
    1800              activate(p, p.producePriority(buffer = buffer, priority = pPriority))
    1801          c = ConsumerWidget()
    1802          activate(c, c.consume1(buffer = buffer))
    1803          simulate(until = 100)
    1804          assert doneList == [0, 3,2, 1],'puts were not done in priority order: %s'\
    1805                                      %doneList
    1806
    1807 -    def testConPriorProdM(self):
    1808          """Tests put / get in multiple Producer / Consumer scenario, with
    1809          Consumers having different priorities.
    1810          How; Consumers forced to queue; all after first should be done in
    1811          priority order
    1812          """
    1813          global doneList
    1814          doneList = []
    1815          initialize()
    1816          buffer = Store(capacity = 7, getQType = PriorityQ, monitored = True)
    1817          for i in range(4):
    1818              c = ConsumerWidget(str(i))
    1819              cPriority = i
    1820              activate(c, c.consumePriority(buffer = buffer, priority = cPriority))
    1821          p = ProducerWidget()
    1822          activate(p, p.produce1(buffer = buffer))
    1823          simulate(until = 100)
    1824          assert doneList == ['3', '2', '1', '0'],\
    1825                'gets were not done in priority order: %s'%doneList
    1826
    1827 -    def testBufferSort(self):
    1828          """Tests the optional sorting of theBuffer by applying a user - defined
    1829          sort function."""
    1830          initialize()
    1831          gotten = []
    1832          sortedStore = Store()
    1833          sortedStore.addSort(mySortFunc)
    1834          p = ProducerWidget()
    1835          activate(p, p.produceUnordered(sortedStore))
    1836          for i in range(9):
    1837              c = ConsumerWidget()
    1838              activate(c, c.consumeSorted(buffer = sortedStore, gotten = gotten),at = 1)
    1839          simulate(until = 10)
    1840          assert gotten == [1, 2,3, 4,5, 6,7, 8,9],'sort wrong: %s'%gotten
    1841
    1842 -    def testBufferFilter(self):
    1843          """Tests get from a Store with a filter function
    1844          """
    1845          initialize()
    1846          ItClass = FilterConsumer.Widget
    1847          all = [ItClass(1),ItClass(4),ItClass(6),ItClass(12)]
    1848          st = Store(initialBuffered = all)
    1849          fc = FilterConsumer()
    1850          minw = 2;maxw = 10
    1851          activate(fc, fc.getItems(store = st, a = minw, b = maxw))
    1852          simulate(until = 1)
    1853
    1854 -def makeStoreSuite():
    1855      suite = unittest.TestSuite()
    1856      testStatic = makeStoreTestcase('testStatic')
    1857      testConProdPrinciple = makeStoreTestcase('testConProdPrinciple')
    1858      testConProd1 = makeStoreTestcase('testConProd1')
    1859      testConProdM = makeStoreTestcase('testConProdM')
    1860      testConProdPriorM = makeStoreTestcase('testConProdPriorM')
    1861      testConPriorProdM = makeStoreTestcase('testConPriorProdM')
    1862      testBufferSort = makeStoreTestcase('testBufferSort')
    1863      testBufferFilter = makeStoreTestcase('testBufferFilter')
    1864      suite.addTests([testStatic, testConProdPrinciple, testConProd1,
    1865                      testConProdM, testConProdPriorM,
    1866                      testConPriorProdM, testBufferSort,
    1867                      testBufferFilter])
    1868      return suite
    1869
    1870  ## ------------------------------------------------------------------
    1871  ##
    1872  ##  Store: Tests for compound get / put
    1873  ##
    1874  ## ------------------------------------------------------------------
    1875 -class TBT(Process):
    1876      """Store: For testBasicTime"""
    1877 -    def tbt(self, store):
    1878          yield get, self, store, 1
    1879          assert self.got, 'Did not get Item'
    1880          yield (get, self, store, 1),(hold, self, 5)
    1881          if self.acquired(store):
    1882              assert len(self.got) == 1, 'did not get 1 Item'
    1883          else:
    1884              assert not self.got and now() == 5 and not store.getQ,\
    1885                     'time renege not working'
    1886
    1887 -class TBE(Process):
    1888      """Store: For testBasicEvent"""
    1889 -    def tbe(self, store, trigger):
    1890          yield get, self, store, 1
    1891          assert self.got, 'Did not get Item'
    1892          yield (get, self, store, 1),(waitevent, self, trigger)
    1893          if self.acquired(store):
    1894              assert False, 'should have reneged'
    1895          else:
    1896              assert self.eventsFired[0] == trigger and now() == 5 \
    1897                  and not store.getQ, 'event renege not working'
    1898
    1899 -class TBEtrigger(Process):
    1900      """Store: For testBasicEvent"""
    1901 -    def fire(self, trigger):
    1902          yield hold, self, 5
    1903          trigger.signal()
    1904
    1905 -class TBTput(Process):
    1906      """Store: for testBasicTimePut"""
    1907 -    def tbt(self, store):
    1908          class Item:pass
    1909          yield (put, self, store,[Item()]),(hold, self, 4)
    1910          if self.stored(store):
    1911              assert store.nrBuffered == 1 and not store.putQ,\
    1912                     'put did not execute'
    1913          else:
    1914              assert False, 'should not have reneged'
    1915          yield (put, self, store,[Item()]),(hold, self, 5)
    1916          if self.stored(store):
    1917              assert False, 'should have reneged'
    1918          else:
    1919              assert store.nrBuffered == 1 and not store.putQ,\
    1920                     'renege not working correctly'
    1921
    1922 -class TBEput(Process):
    1923      """Store: for testBasicEventPut"""
    1924 -    def tbe(self, store, trigger):
    1925          class Item:pass
    1926          yield (put, self, store,[Item()]),(waitevent, self, trigger)
    1927          if self.stored(store):
    1928              assert store.nrBuffered == 1 and not store.putQ,\
    1929                     'put did not execute'
    1930          else:
    1931              assert False, 'should have not have reneged'
    1932          yield (put, self, store,[Item()]),(waitevent, self, trigger)
    1933          if self.stored(store):
    1934              assert False, 'should have reneged'
    1935          else:
    1936              assert now() == 5 and self.eventsFired[0] == trigger\
    1937                     and not store.putQ, 'renege not working correctly'
    1938
    1939 -class TBEtriggerPut(Process):
    1940      """Store: For testBasicEventPut"""
    1941 -    def fire(self, trigger):
    1942          yield hold, self, 5
    1943          trigger.signal()
    1944
    1945 -class makeStoreCompTestcase(unittest.TestCase):
    1946      """Store: Testcase for compound get statements"""
    1947      ## ------------------------------------------------------------------
    1948      ##             TEST 'yield (get, self, store),(hold, self, time)'
    1949      ##                   == timeout renege
    1950      ##             for both unmonitored and monitored Stores
    1951      ## ------------------------------------------------------------------
    1952
    1953 -    def testBasicTime(self):
    1954          """Store (unmonitored):
    1955          test 'yield (get, self, store),(hold, self, timeout)"""
    1956          class Item:pass
    1957          initialize()
    1958          st = Store(initialBuffered = [Item()])
    1959          t = TBT()
    1960          activate(t, t.tbt(store = st))
    1961          simulate(until = 10)
    1962
    1963
    1964      ## ------------------------------------------------------------------
    1965      ##             TEST 'yield (put, self, store),(hold, self, time)'
    1966      ##                   == timeout renege
    1967      ##             for both unmonitored and monitored Stores
    1968      ## ------------------------------------------------------------------
    1969 -    def testBasicTimePut(self):
    1970          """Store (unmonitored):
    1971          test 'yield (put, self, store),(hold, self, time)"""
    1972          initialize()
    1973          st = Store(capacity = 1)
    1974          t = TBTput()
    1975          activate(t, t.tbt(store = st))
    1976          simulate(until = 10)
    1977
    1978 -    def testBasicTimePutM(self):
    1979          """Store (monitored):
    1980          test monitors with 'yield (put, self, store),(hold, self, time)"""
    1981          initialize()
    1982          st = Store(capacity = 1, monitored = True)
    1983          t = TBTput()
    1984          activate(t, t.tbt(store = st))
    1985          simulate(until = 10)
    1986          #First put succeeds, second attempt reneges at t = 5?
    1987          assert st.putQMon == [[0, 0],[0, 1],[5, 0]],'putQMon wrong: %s'\
    1988                                                 %st.putQMon
    1989          #First Item goes into buffer at t = 0, second not (renege)?
    1990          assert st.bufferMon == [[0, 0],[0, 1]],'bufferMon wrong: %s'%st.bufferMon
    1991
    1992
    1993      ## ------------------------------------------------------------------
    1994      ##             TEST 'yield (get, self, store),(waitevent, self, event)'
    1995      ##                   == event renege
    1996      ##             for both unmonitored and monitored Stores
    1997      ## ------------------------------------------------------------------
    1998 -    def testBasicEvent(self):
    1999          """Store (unmonitored):
    2000          test 'yield (get, self, store),(waitevent, self, event)"""
    2001          class Item:pass
    2002          initialize()
    2003          st = Store(initialBuffered = [Item()])
    2004          trig = SimEvent()
    2005          t = TBE()
    2006          activate(t, t.tbe(store = st, trigger = trig))
    2007          tr = TBEtrigger()
    2008          activate(tr, tr.fire(trigger = trig))
    2009          simulate(until = 10)
    2010
    2011
    2012      ## ------------------------------------------------------------------
    2013      ##             TEST 'yield (put, self, store),(waitevent, self, event)'
    2014      ##                   == event renege
    2015      ##             for both unmonitored and monitored Stores
    2016      ## ------------------------------------------------------------------
    2017 -    def testBasicEventPut(self):
    2018          """Store (unmonitored):
    2019          test 'yield (put, self, store),(waitevent, self, event)"""
    2020          initialize()
    2021          s = SimEvent()
    2022          store = Store(capacity = 1)
    2023          t = TBEtriggerPut()
    2024          activate(t, t.fire(trigger = s))
    2025          tb = TBEput()
    2026          activate(tb, tb.tbe(store = store, trigger = s))
    2027          simulate(until = 10)
    2028
    2029 -    def testBasicEventPutM(self):
    2030          """Store (monitored):
    2031          test monitors with 'yield (put, self, store),(waitevent, self, event)"""
    2032          initialize()
    2033          s = SimEvent()
    2034          st = Store(capacity = 1, monitored = True)
    2035          t = TBEtriggerPut()
    2036          activate(t, t.fire(trigger = s))
    2037          tb = TBEput()
    2038          activate(tb, tb.tbe(store = st, trigger = s))
    2039          simulate(until = 10)
    2040          #First put succeeds, second attempt reneges at t = 5?
    2041          assert st.putQMon == [[0, 0],[0, 1],[5, 0]],'putQMon wrong: %s'\
    2042                                                 %st.putQMon
    2043          #First Item goes into buffer at t = 0, second not (renege)?
    2044          assert st.bufferMon == [[0, 0],[0, 1]],'bufferMon wrong: %s'%st.bufferMon
    2045
    2046 -def makeStoreCompSuite():
    2047      suite = unittest.TestSuite()
    2048      ## Unmonitored Stores
    2049      testBasicTime  = makeStoreCompTestcase('testBasicTime')
    2050      testBasicEvent = makeStoreCompTestcase('testBasicEvent')
    2051      testBasicTimePut  = makeStoreCompTestcase('testBasicTimePut')
    2052      testBasicEventPut = makeStoreCompTestcase('testBasicEventPut')
    2053      ## Monitored Stores
    2054      testBasicTimePutM = makeStoreCompTestcase('testBasicTimePutM')
    2055      testBasicEventPutM = makeStoreCompTestcase('testBasicEventPutM')
    2056
    2057      suite.addTests([testBasicTime,
    2058                      testBasicEvent,
    2059                      testBasicTimePut,
    2060                      testBasicEventPut,
    2061                      testBasicTimePutM,
    2062                      testBasicEventPutM])
    2063      return suite
    2064
    2065  ## ------------------------------------------------------------------
    2066  ##
    2067  ##  Level: Tests for compound get
    2068  ##
    2069  ## ------------------------------------------------------------------
    2070 -class TBTLev(Process):
    2071      """Level: For testBasicTime"""
    2072 -    def tbt(self, level):
    2073          yield get, self, level, 1
    2074          assert self.got, 'did not get 1 unit'
    2075          yield (get, self, level, 1),(hold, self, 5)
    2076          if self.acquired(level):
    2077              assert self.got == 1, 'did not get 1 unit'
    2078          else:
    2079              assert not self.got and now() == 5, 'time renege not working'
    2080
    2081 -class TBELev(Process):
    2082      """Level: For testBasicEvent"""
    2083 -    def tbe(self, level, trigger):
    2084          yield get, self, level, 1
    2085          assert self.got, 'did not get 1 unit'
    2086          yield (get, self, level, 1),(waitevent, self, trigger)
    2087          if self.acquired(level):
    2088              assert self.got == 1, 'did not get 1 Item'
    2089          else:
    2090              assert now() == 5.5 and self.eventsFired[0] == trigger,\
    2091                     'event renege not working'
    2092
    2093 -class TBEtriggerLev(Process):
    2094      """Level: For testBasicEvent"""
    2095 -    def fire(self, trigger):
    2096          yield hold, self, 5.5
    2097          trigger.signal()
    2098
    2099 -class TBTLevPut(Process):
    2100      """Level: For testBasicTimePut"""
    2101 -    def tbt(self, level):
    2102          yield put, self, level, 1
    2103          assert level.amount, 'did not put 1 unit'
    2104          yield (put, self, level, 1),(hold, self, 5)
    2105          if self.stored(level):
    2106              assert False, 'should have reneged'
    2107          else:
    2108              assert level.amount == 1 and now() == 5, 'time renege not working'
    2109
    2110 -class TBELevPut(Process):
    2111      """Level: For testBasicEventPut and testBasicEventPutM"""
    2112 -    def tbe(self, level, trigger):
    2113          yield (put, self, level, 1),(waitevent, self, trigger)
    2114          if self.stored(level):
    2115              assert level.amount == 1, 'did not put 1 unit'
    2116          else:
    2117              assert False, 'should not have reneged'
    2118          yield (put, self, level, 1),(waitevent, self, trigger)
    2119          if self.stored(level):
    2120              assert False, 'should have reneged'
    2121          else:
    2122              assert now() == 5.5 and self.eventsFired[0] == trigger ,\
    2123                     'renege not working'
    2124
    2125 -class TBEtriggerLevPut(Process):
    2126      """Level: For testBasicEventPut"""
    2127 -    def fire(self, trigger):
    2128          yield hold, self, 5.5
    2129          trigger.signal()
    2130
    2131 -class makeLevelCompTestcase(unittest.TestCase):
    2132      """Level: Testcase for compound get and put statements"""
    2133      ## ------------------------------------------------------------------
    2134      ##             TEST 'yield (get, self, level),(hold, self, time)'
    2135      ##                   == timeout renege
    2136      ##             for both unmonitored and monitored Levels
    2137      ## ------------------------------------------------------------------
    2138
    2139 -    def testBasicTime(self):
    2140          """Level (unmonitored): test 'yield (get, self, level),(hold, self, timeout)"""
    2141          initialize()
    2142          l = Level(initialBuffered = 1)
    2143          t = TBTLev()
    2144          activate(t, t.tbt(level = l))
    2145          simulate(until = 10)
    2146
    2147      ## ------------------------------------------------------------------
    2148      ##             TEST 'yield (put, self, store),(hold, self, time)'
    2149      ##                   == timeout renege
    2150      ##             for both unmonitored and monitored Stores
    2151      ## ------------------------------------------------------------------
    2152 -    def testBasicTimePut(self):
    2153          """Level (unmonitored):
    2154          test 'yield (put, self, level),(hold, self, timeout)"""
    2155          initialize()
    2156          l = Level(capacity = 1)
    2157          t = TBTLevPut()
    2158          activate(t, t.tbt(level = l))
    2159          simulate(until = 10)
    2160
    2161
    2162      ## ------------------------------------------------------------------
    2163      ##             TEST 'yield (get, self, store),(waitevent, self, event)'
    2164      ##                   == event renege
    2165      ##             for both unmonitored and monitored Levels
    2166      ## ------------------------------------------------------------------
    2167 -    def testBasicEvent(self):
    2168          """Level (unmonitored):
    2169          test 'yield (get, self, level),(waitevent, self, event)"""
    2170          initialize()
    2171          l = Level(initialBuffered = 1)
    2172          trig = SimEvent()
    2173          t = TBELev()
    2174          activate(t, t.tbe(level = l, trigger = trig))
    2175          tr = TBEtriggerLev()
    2176          activate(tr, tr.fire(trigger = trig))
    2177          simulate(until = 10)
    2178
    2179 -    def testBasicEventM(self):
    2180          """Level (monitored):
    2181          test monitors with 'yield (get, self, level),(waitevent, self, event)"""
    2182          initialize()
    2183          l = Level(initialBuffered = 1, monitored = True)
    2184          trig = SimEvent()
    2185          t = TBELev()
    2186          activate(t, t.tbe(level = l, trigger = trig))
    2187          tr = TBEtriggerLev()
    2188          activate(tr, tr.fire(trigger = trig))
    2189          simulate(until = 10)
    2190          #First get (t = 0) succeeded and second timed out at t = 5.5?
    2191          assert l.getQMon == [[0, 0],[0, 1],[5.5, 0]],'getQMon not working: %s'\
    2192                                                 %l.getQMon
    2193          #Level amount incr. then decr. by 1 (t = 0), 2nd get reneged at t = 5.5?
    2194          assert l.bufferMon == [[0, 1],[0, 0]],\
    2195                 'bufferMon not working: %s'%l.bufferMon
    2196
    2197      ## ------------------------------------------------------------------
    2198      ##             TEST 'yield (put, self, store),(waitevent, self, event)'
    2199      ##                   == event renege
    2200      ##             for both unmonitored and monitored Levels
    2201      ## ------------------------------------------------------------------
    2202 -    def testBasicEventPut(self):
    2203          """Level (unmonitored):
    2204          test 'yield (put, self, level),(waitevent, self, event)"""
    2205          initialize()
    2206          l = Level(capacity = 1)
    2207          trig = SimEvent()
    2208          t = TBELevPut()
    2209          activate(t, t.tbe(level = l, trigger = trig))
    2210          tr = TBEtriggerLevPut()
    2211          activate(tr, tr.fire(trigger = trig))
    2212          simulate(until = 10)
    2213
    2214 -    def testBasicEventPutM(self):
    2215          """Level (monitored):
    2216          test monitors with 'yield (put, self, level),(waitevent, self, event)"""
    2217          initialize()
    2218          l = Level(capacity = 1, monitored = True)
    2219          trig = SimEvent()
    2220          t = TBELevPut()
    2221          activate(t, t.tbe(level = l, trigger = trig))
    2222          tr = TBEtriggerLevPut()
    2223          activate(tr, tr.fire(trigger = trig))
    2224          simulate(until = 10)
    2225          'First put succeeds, second reneges at t = 5.5?'
    2226          assert l.putQMon == [[0, 0],[0, 1],[5.5, 0]],'putQMon wrong: %s'\
    2227                                                  %l.putQMon
    2228          '1 unit added at t = 0, renege at t = 5 before 2nd unit added?'
    2229          assert l.bufferMon == [[0, 0],[0, 1]],'bufferMon wrong: %s'%l.bufferMon
    2230
    2231 -def makeLevelCompSuite():
    2232      suite = unittest.TestSuite()
    2233      ## Unmonitored Levels
    2234      testBasicTime  = makeLevelCompTestcase('testBasicTime')
    2235      testBasicEvent = makeLevelCompTestcase('testBasicEvent')
    2236      testBasicTimePut = makeLevelCompTestcase('testBasicTimePut')
    2237      testBasicEventPut = makeLevelCompTestcase('testBasicEventPut')
    2238      ## Monitored Levels
    2239      testBasicEventM = makeLevelCompTestcase('testBasicEventM')
    2240      testBasicEventPutM = makeLevelCompTestcase('testBasicEventPutM')
    2241
    2242      suite.addTests([testBasicTime,
    2243                      testBasicEvent,
    2244                      testBasicTimePut,
    2245                      testBasicEventPut,
    2246                      testBasicEventM,
    2247                      testBasicEventPutM])
    2248      return suite
    2249
    2250  if __name__ == '__main__':
    2251      alltests = unittest.TestSuite((makeSSuite(),makeRSuite(),
    2252                                     makeMSuite(),#makeHSuite(),
    2253                                     makeISuite(),makePSuite(),
    2254                                     makeESuite(),makeWSuite(),
    2255                                     makeTOSuite(),makeEvtRenegeSuite(),
    2256                                     makeLevelSuite(),
    2257                                     makeStoreSuite(),
    2258                                     makeStoreCompSuite(),
    2259                                     makeLevelCompSuite()
    2260                                  ))
    2261      runner = unittest.TextTestRunner()
    2262      runner.run(alltests)
    2263