Package SimPy :: Module testRT_Behavior_OO

[hide private]
[frames] | no frames]

# Source Code for Module SimPy.testRT_Behavior_OO

     1  #!/usr / bin / env python

     2  # coding=utf-8

     3  from SimPy.SimulationRT import *
     4  """testRT_Behavior_OO.py

     5  Tests SimulationRT for degree to which simulation time

     6  and wallclock time can be synchronized.

     7

     8  OO API.

     9  """
    10  # $Revision: 419 $ $Date: 2010-03-29 16:03:43 +0200 (Mon, 29 Mar 2010) $

    11

    12  print "Under test: SimulationRT.py %s"% version
    13  __version__ = '2.1 $Revision: 419 $ $Date: 2010-03-29 16:03:43 +0200 (Mon, 29 Mar 2010) $ '
    14  print 'testRT_Behavior.py %s'%__version__
    15

    16 -class Ticker(Process):
    17 -    def tick(self):
    18          self.timing = []
    19          while True:
    20              yield hold,self,1
    21              tSim = self.sim.now()
    22              tRT = self.sim.rtnow()
    23              self.timing.append((tSim,tRT))
    24

    25  s=SimulationRT()
    26  s.initialize()
    27  t=Ticker(sim=s)
    28  s.activate(t,t.tick())
    29  s.simulate(until=10,real_time=True,rel_speed=1)
    30

    31  print "Speed ratio set: 1"
    32  print "------------------"
    33  for tSim,tRT in t.timing:
    34      print "tSim:%s, tRT:%s, speed ratio:%s"%(tSim,tRT,tSim/tRT)
    35

    36  s1=SimulationRT()
    37  s1.initialize()
    38  t=Ticker(sim=s1)
    39  s1.activate(t,t.tick())
    40  s1.simulate(until=10,real_time=True,rel_speed=5)
    41

    42  print
    43  print "Speed ratio set: 5"
    44  print "------------------"
    45  for tSim,tRT in t.timing:
    46      print "tSim:%s, tRT:%s, speed ratio:%s"%(tSim,tRT,tSim/tRT)
    47