Package SimPy :: Module testSimPyRT |
[hide private]
[frames] | no frames]

# Source Code for Module SimPy.testSimPyRT

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