diff --git a/artiq/test/coredevice/test_spi.py b/artiq/test/coredevice/test_spi.py index 53b1a3ec0..3686f532b 100644 --- a/artiq/test/coredevice/test_spi.py +++ b/artiq/test/coredevice/test_spi.py @@ -2,6 +2,10 @@ from artiq.experiment import * from artiq.test.hardware_testbench import ExperimentCase +class WrongError(Exception): + pass + + class Collision(EnvExperiment): def build(self): self.setattr_device("core") @@ -11,7 +15,10 @@ class Collision(EnvExperiment): def run(self): self.core.break_realtime() t = now_mu() - self.spi0.set_config_mu() + try: + self.spi0.set_config_mu() + except RTIOBusy: + raise WrongError() at_mu(t) self.spi0.set_config_mu() @@ -24,18 +31,49 @@ class Busy(EnvExperiment): @kernel def run(self): - self.core.break_realtime() - t = now_mu() - self.spi0.set_config_mu() - at_mu(t + self.spi0.ref_period_mu) - self.spi0.set_config_mu() # causes the error - self.led.on() - self.led.sync() # registers the error - self.core.break_realtime() + try: + self.core.break_realtime() + self.spi0.set_config_mu() + t = now_mu() + self.spi0.set_config_mu() + at_mu(t + self.spi0.ref_period_mu) + self.spi0.set_config_mu() # causes the error + self.led.on() + self.led.sync() # registers the error + self.core.break_realtime() + except RTIOBusy: + raise WrongError() # we don't expect RTIOBusy so far 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): + def tearDown(self): + self.execute(DrainErrors) + ExperimentCase.tearDown(self) + def test_collision(self): with self.assertRaises(RTIOCollision): self.execute(Collision)