forked from M-Labs/artiq
1
0
Fork 0

test_spi: drain errors and be more strict on where we expect errors

This commit is contained in:
Robert Jördens 2016-03-10 12:25:10 +01:00
parent 579168f06f
commit f68c24094f
1 changed files with 47 additions and 9 deletions

View File

@ -2,6 +2,10 @@ from artiq.experiment import *
from artiq.test.hardware_testbench import ExperimentCase from artiq.test.hardware_testbench import ExperimentCase
class WrongError(Exception):
pass
class Collision(EnvExperiment): class Collision(EnvExperiment):
def build(self): def build(self):
self.setattr_device("core") self.setattr_device("core")
@ -11,7 +15,10 @@ class Collision(EnvExperiment):
def run(self): def run(self):
self.core.break_realtime() self.core.break_realtime()
t = now_mu() t = now_mu()
try:
self.spi0.set_config_mu() self.spi0.set_config_mu()
except RTIOBusy:
raise WrongError()
at_mu(t) at_mu(t)
self.spi0.set_config_mu() self.spi0.set_config_mu()
@ -24,7 +31,9 @@ class Busy(EnvExperiment):
@kernel @kernel
def run(self): def run(self):
try:
self.core.break_realtime() self.core.break_realtime()
self.spi0.set_config_mu()
t = now_mu() t = now_mu()
self.spi0.set_config_mu() self.spi0.set_config_mu()
at_mu(t + self.spi0.ref_period_mu) at_mu(t + self.spi0.ref_period_mu)
@ -32,10 +41,39 @@ class Busy(EnvExperiment):
self.led.on() self.led.on()
self.led.sync() # registers the error self.led.sync() # registers the error
self.core.break_realtime() self.core.break_realtime()
except RTIOBusy:
raise WrongError() # we don't expect RTIOBusy so far
self.spi0.set_config_mu() # raises the error self.spi0.set_config_mu() # raises the error
class DrainErrors(EnvExperiment):
def build(self):
self.setattr_device("core")
self.setattr_device("spi0")
self.setattr_device("led")
@kernel
def run(self):
while True:
try:
self.core.break_realtime()
delay(100*us)
self.spi0.set_config_mu()
self.led.on()
self.led.sync()
self.core.break_realtime()
self.spi0.set_config_mu()
self.led.off()
return
except:
pass
class SPITest(ExperimentCase): class SPITest(ExperimentCase):
def tearDown(self):
self.execute(DrainErrors)
ExperimentCase.tearDown(self)
def test_collision(self): def test_collision(self):
with self.assertRaises(RTIOCollision): with self.assertRaises(RTIOCollision):
self.execute(Collision) self.execute(Collision)