Skip to content

Commit

Permalink
test_spi: drain errors and be more strict on where we expect errors
Browse files Browse the repository at this point in the history
jordens committed Mar 10, 2016
1 parent 579168f commit f68c240
Showing 1 changed file with 47 additions and 9 deletions.
56 changes: 47 additions & 9 deletions artiq/test/coredevice/test_spi.py
Original file line number Diff line number Diff line change
@@ -2,6 +2,10 @@
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 @@ def build(self):
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 @@ def build(self):

@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)

0 comments on commit f68c240

Please sign in to comment.