Package SimPy :: Module testSimPyTrace

[hide private]
[frames] | no frames]

# Source Code for Module SimPy.testSimPyTrace

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