Skip to content

Commit f68c240

Browse files
committedMar 10, 2016
test_spi: drain errors and be more strict on where we expect errors
1 parent 579168f commit f68c240

File tree

1 file changed

+47
-9
lines changed

1 file changed

+47
-9
lines changed
 

Diff for: ‎artiq/test/coredevice/test_spi.py

+47-9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
from artiq.test.hardware_testbench import ExperimentCase
33

44

5+
class WrongError(Exception):
6+
pass
7+
8+
59
class Collision(EnvExperiment):
610
def build(self):
711
self.setattr_device("core")
@@ -11,7 +15,10 @@ def build(self):
1115
def run(self):
1216
self.core.break_realtime()
1317
t = now_mu()
14-
self.spi0.set_config_mu()
18+
try:
19+
self.spi0.set_config_mu()
20+
except RTIOBusy:
21+
raise WrongError()
1522
at_mu(t)
1623
self.spi0.set_config_mu()
1724

@@ -24,18 +31,49 @@ def build(self):
2431

2532
@kernel
2633
def run(self):
27-
self.core.break_realtime()
28-
t = now_mu()
29-
self.spi0.set_config_mu()
30-
at_mu(t + self.spi0.ref_period_mu)
31-
self.spi0.set_config_mu() # causes the error
32-
self.led.on()
33-
self.led.sync() # registers the error
34-
self.core.break_realtime()
34+
try:
35+
self.core.break_realtime()
36+
self.spi0.set_config_mu()
37+
t = now_mu()
38+
self.spi0.set_config_mu()
39+
at_mu(t + self.spi0.ref_period_mu)
40+
self.spi0.set_config_mu() # causes the error
41+
self.led.on()
42+
self.led.sync() # registers the error
43+
self.core.break_realtime()
44+
except RTIOBusy:
45+
raise WrongError() # we don't expect RTIOBusy so far
3546
self.spi0.set_config_mu() # raises the error
3647

3748

49+
class DrainErrors(EnvExperiment):
50+
def build(self):
51+
self.setattr_device("core")
52+
self.setattr_device("spi0")
53+
self.setattr_device("led")
54+
55+
@kernel
56+
def run(self):
57+
while True:
58+
try:
59+
self.core.break_realtime()
60+
delay(100*us)
61+
self.spi0.set_config_mu()
62+
self.led.on()
63+
self.led.sync()
64+
self.core.break_realtime()
65+
self.spi0.set_config_mu()
66+
self.led.off()
67+
return
68+
except:
69+
pass
70+
71+
3872
class SPITest(ExperimentCase):
73+
def tearDown(self):
74+
self.execute(DrainErrors)
75+
ExperimentCase.tearDown(self)
76+
3977
def test_collision(self):
4078
with self.assertRaises(RTIOCollision):
4179
self.execute(Collision)

0 commit comments

Comments
 (0)