def testQueingPort(): class myThread1(vSimpleProg): def __init__(self, sim): super().__init__(sim=sim, objName='Thread', parentObj=None) self.createPorts('QueingIn', ['inP1']) def getAllMsg(self): lstMsg = [] while True: try: msg = self.inP1.readMsg() lstMsg.append(msg) except BufferError: break self.addAnnotation(lstMsg) def runVThread(self): cycle = 0 while True: cycle += 1 self.busy(33, cycle, busyAppearance) self.getAllMsg() print(self.wait(20, [self.inP1])) self.getAllMsg() class stimThread(vSimpleProg): def __init__(self, sim): super().__init__(sim=sim, objName='Stim', parentObj=None) self.createPorts('out', ['toT1Port']) def runVThread(self): count = 0 while True: count += 1 self.wait(15, []) self.toT1Port.send('hello%d' % count, 5) simu = sim() t1 = myThread1(simu) stim = stimThread(simu) stim.toT1Port.bind(t1.inP1) simu.run(200) moddyGenerateSequenceDiagram(sim=simu, fileName="sched.html", fmt="svgInHtml", showPartsList=[stim, t1], excludedElementList=['allTimers'], timePerDiv=10, pixPerDiv=30)
def testSamplingPort(): class myThread1(vSimpleProg): def __init__(self, sim): super().__init__(sim=sim, objName='Thread', parentObj=None) self.createPorts('SamplingIn', ['inP1']) def showMsg(self): msg = self.inP1.readMsg(default='No message') self.addAnnotation(msg) def runVThread(self): cycle = 0 while True: cycle += 1 self.showMsg() self.busy(18, cycle, busyAppearance) self.showMsg() self.busy(14, cycle, busyAppearance) self.wait(20, [self.inP1]) class stimThread(vSimpleProg): def __init__(self, sim): super().__init__(sim=sim, objName='Stim', parentObj=None) self.createPorts('out', ['toT1Port']) def runVThread(self): count = 0 while True: count += 1 self.wait(15) self.toT1Port.send('hello%d' % count, 5) simu = sim() t1 = myThread1(simu) stim = stimThread(simu) stim.toT1Port.bind(t1.inP1) simu.run(200) moddyGenerateSequenceDiagram(sim=simu, fileName="sched.html", fmt="svgInHtml", showPartsList=[stim, t1], excludedElementList=['allTimers'], timePerDiv=10, pixPerDiv=30)
def testVtTimer(): class myThread1(vThread): def __init__(self, sim): super().__init__(sim=sim, objName='Thread', parentObj=None) self.createVtTimers(['tmr1']) def runVThread(self): cycle = 0 while True: cycle += 1 self.tmr1.start(16) self.busy(18, cycle, busyAppearance) self.addAnnotation("A Fired " + str(self.tmr1.hasFired())) self.tmr1.start(20) rv = self.wait(100, [self.tmr1]) self.addAnnotation("B rv " + rv) self.tmr1.start(20) rv = self.wait(30, []) self.addAnnotation("C rv " + rv) self.tmr1.start(40) rv = self.wait(30, [self.tmr1]) self.addAnnotation("D Fired " + str(self.tmr1.hasFired()) + " rv " + rv) self.tmr1.stop() simu = sim() sched = vtSchedRtos(sim=simu, objName="sched", parentObj=None) t1 = myThread1(simu) sched.addVThread(t1, 0) simu.run(200) moddyGenerateSequenceDiagram(sim=simu, fileName="sched.html", fmt="svgInHtml", showPartsList=[t1], excludedElementList=['allTimers'], timePerDiv=10, pixPerDiv=30)
def ucPortRecv(self, port, msg): pass class Sensor(simPart): def __init__(self, sim, objName, parentObj = None): super().__init__(sim, objName, parentObj) self.createPorts('out', ['outPort']) self.createPorts('in', ['pwrPort']) def pwrPortRecv(self, port, msg): pass simu = sim() cpu = Cpu(simu,"CPU") ecm = EcMaster(simu,"ECM") ecDev1 = EcDevice(simu,"DEV1") ecDev2 = EcDevice(simu,"DEV2") sensor = Sensor(simu,"SENSOR") cpu.app1.ecmPort.bind(ecm.appPort) ecm.ecPort._outPort.bind(ecDev1.ecPort._inPort) ecDev1.ecPort._outPort.bind(ecDev2.ecPort._inPort) ecDev2.ecPort._outPort.bind(ecm.ecPort._inPort) sensor.outPort.bind(ecDev1.uc.sensPort) sensor.outPort.bind(ecDev2.uc.sensPort) # sensless, but test that a peer-to-peer port can be bound to an additional input port ecDev1.uc.fpgaPort._outPort.bind(sensor.pwrPort)
def testScheduling(): class myThread1(vThread): def __init__(self, sim): super().__init__(sim=sim, objName='hiThread', parentObj=None) def runVThread(self): print(" VtHi1") self.busy(50, '1', busyAppearance) print(" VtHi2") self.wait(20, []) print(" VtHi3") self.busy(10, '2', busyAppearance) print(" VtHi4") self.wait(100, []) print(" VtHi5") self.wait(100, []) while True: print(" VtHi5") self.busy(10, '3', busyAppearance) self.wait(5, []) class myThread2(vThread): def __init__(self, sim): super().__init__(sim=sim, objName='lowThreadA', parentObj=None) def runVThread(self): print(" VtLoA1") self.busy(50, '1', busyAppearance) print(" VtLoA2") self.wait(20, []) print(" VtLoA3") self.busy(20, '2', busyAppearance) print(" VtLoA4") self.busy(250, '3', busyAppearance) class myThread3(vThread): def __init__(self, sim): super().__init__(sim=sim, objName='lowThreadB', parentObj=None) def runVThread(self): print(" VtLoB1") self.busy(50, '1', busyAppearance) print(" VtLoB2") self.wait(20, []) print(" VtLoB3") self.busy(100, '2', busyAppearance) print(" VtLoB4") self.busy(250, '3', busyAppearance) simu = sim() sched = vtSchedRtos(sim=simu, objName="sched", parentObj=None) t1 = myThread1(simu) t2 = myThread2(simu) t3 = myThread3(simu) sched.addVThread(t1, 0) sched.addVThread(t2, 1) sched.addVThread(t3, 1) simu.run(400) moddyGenerateSequenceDiagram(sim=simu, fileName="sched.html", fmt="svgInHtml", showPartsList=[t1, t2, t3], excludedElementList=['allTimers'], timePerDiv=10, pixPerDiv=30)