Skip to content

Commit fb91955

Browse files
jordenssbourdeauducq
authored andcommittedApr 3, 2015
tests: make hardware-in-the loop flags positive logic
Explicitly having to disable unittests that require hardware (ARTIQ_NO_HARDWARE) is cumbersome. There is not even a sensible default for the device or serial number of the devices requiring additional variables (ARTIQ_LDA_DEVICE etc). This patch reverts the logic by skipping unittests that can not automatically determine whether the required hardware is present and where it is.
1 parent 2995f0a commit fb91955

File tree

4 files changed

+23
-32
lines changed

4 files changed

+23
-32
lines changed
 

Diff for: ‎.travis.yml

-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ env:
77
- PATH=$HOME/miniconda/bin:/usr/local/llvm-or1k/bin:$PATH
88
- CC=gcc-4.7
99
- CXX=g++-4.7
10-
- ARTIQ_NO_HARDWARE=1
1110
- BUILD_SOC=1
1211
- secure: "DUk/Ihg8KbbzEgPF0qrHqlxU8e8eET9i/BtzNvFddIGX4HP/P2qz0nk3cVkmjuWhqJXSbC22RdKME9qqPzw6fJwJ6dpJ3OR6dDmSd7rewavq+niwxu52PVa+yK8mL4yf1terM7QQ5tIRf+yUL9qGKrZ2xyvEuRit6d4cFep43Ws="
1312
before_install:

Diff for: ‎artiq/test/full_stack.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
from artiq.sim import devices as sim_devices
1010

1111

12-
no_hardware = bool(os.getenv("ARTIQ_NO_HARDWARE"))
12+
core_device = os.getenv("ARTIQ_CORE_DEVICE")
1313

1414

1515
def _run_on_device(k_class, **parameters):
16-
comm = comm_serial.Comm()
16+
comm = comm_serial.Comm(serial_dev=core_device)
1717
try:
1818
coredev = core.Core(comm=comm)
1919
k_inst = k_class(core=coredev, **parameters)
@@ -199,7 +199,7 @@ def catch(self):
199199
self.success = True
200200

201201

202-
@unittest.skipIf(no_hardware, "no hardware")
202+
@unittest.skipUnless(core_device, "no hardware")
203203
class ExecutionCase(unittest.TestCase):
204204
def test_primes(self):
205205
l_device, l_host = [], []
@@ -208,7 +208,7 @@ def test_primes(self):
208208
self.assertEqual(l_device, l_host)
209209

210210
def test_misc(self):
211-
comm = comm_serial.Comm()
211+
comm = comm_serial.Comm(serial_dev=core_device)
212212
try:
213213
coredev = core.Core(comm=comm)
214214
uut = _Misc(core=coredev)
@@ -249,7 +249,7 @@ def test_exceptions(self):
249249
self.assertEqual(t_device, t_host)
250250

251251
def test_rpc_exceptions(self):
252-
comm = comm_serial.Comm()
252+
comm = comm_serial.Comm(serial_dev=core_device)
253253
try:
254254
uut = _RPCExceptions(core=core.Core(comm=comm))
255255
with self.assertRaises(_MyException):
@@ -306,13 +306,13 @@ def run(self):
306306
self.o.pulse(25*us)
307307

308308

309-
@unittest.skipIf(no_hardware, "no hardware")
309+
@unittest.skipUnless(core_device, "no hardware")
310310
class RTIOCase(unittest.TestCase):
311311
# Connect channels 0 and 1 together for this test
312312
# (C11 and C13 on Papilio Pro)
313313
def test_loopback(self):
314314
npulses = 4
315-
comm = comm_serial.Comm()
315+
comm = comm_serial.Comm(serial_dev=core_device)
316316
try:
317317
coredev = core.Core(comm=comm)
318318
uut = _RTIOLoopback(
@@ -327,7 +327,7 @@ def test_loopback(self):
327327
comm.close()
328328

329329
def test_underflow(self):
330-
comm = comm_serial.Comm()
330+
comm = comm_serial.Comm(serial_dev=core_device)
331331
try:
332332
coredev = core.Core(comm=comm)
333333
uut = _RTIOUnderflow(
@@ -340,7 +340,7 @@ def test_underflow(self):
340340
comm.close()
341341

342342
def test_sequence_error(self):
343-
comm = comm_serial.Comm()
343+
comm = comm_serial.Comm(serial_dev=core_device)
344344
try:
345345
coredev = core.Core(comm=comm)
346346
uut = _RTIOSequenceError(

Diff for: ‎artiq/test/lda.py

+4-12
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@
55
from artiq.language.units import dB
66

77

8-
no_hardware = bool(os.getenv("ARTIQ_NO_HARDWARE")) \
9-
or bool(os.getenv("ARTIQ_NO_PERIPHERALS"))
8+
lda_serial = os.getenv("ARTIQ_LDA_SERIAL")
109

1110

1211
class GenericLdaTest:
@@ -20,18 +19,11 @@ def test_attenuation(self):
2019
self.assertEqual(i, self.cont.get_attenuation())
2120

2221

23-
@unittest.skipIf(no_hardware, "no hardware")
22+
@unittest.skipUnless(lda_serial, "no hardware")
2423
class TestLda(GenericLdaTest, unittest.TestCase):
2524
def setUp(self):
26-
device = os.getenv("ARTIQ_LDA_DEVICE")
27-
serial = os.getenv("ARTIQ_LDA_SERIAL")
28-
args = dict()
29-
if device is not None:
30-
args["product"] = device
31-
if serial is not None:
32-
args["serial"] = serial
33-
34-
self.cont = Lda(**args)
25+
product = os.getenv("ARTIQ_LDA_PRODUCT")
26+
self.cont = Lda(serial=lda_serial, product=product)
3527

3628

3729
class TestLdaSim(GenericLdaTest, unittest.TestCase):

Diff for: ‎artiq/test/thorlabs_tcube.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
from artiq.language.units import V
77

88

9-
no_hardware = bool(os.getenv("ARTIQ_NO_HARDWARE")) \
10-
or bool(os.getenv("ARTIQ_NO_PERIPHERALS"))
11-
12-
139
class GenericTdcTest:
1410
def test_pot_parameters(self):
1511
test_vector = 1, 2, 3, 4, 5, 6, 7, 8
@@ -135,23 +131,27 @@ def test_tpz_io_settings(self):
135131
self.assertEqual(test_vector, self.cont.get_tpz_io_settings())
136132

137133

138-
@unittest.skipIf(no_hardware, "no hardware")
134+
tdc_serial = os.getenv("ARTIQ_TDC_SERIAL")
135+
136+
137+
@unittest.skipUnless(tdc_serial, "no hardware")
139138
class TestTdc(unittest.TestCase, GenericTdcTest):
140139
def setUp(self):
141-
serial_dev = os.getenv("ARTIQ_TDC001_SERIAL", "/dev/ttyUSB0")
142-
self.cont = Tdc(serial_dev=serial_dev)
140+
self.cont = Tdc(serial_dev=tdc_serial)
143141

144142

145143
class TestTdcSim(unittest.TestCase, GenericTdcTest):
146144
def setUp(self):
147145
self.cont = TdcSim()
148146

149147

150-
@unittest.skipIf(no_hardware, "no hardware")
148+
tpz_serial = os.getenv("ARTIQ_TPZ_SERIAL")
149+
150+
151+
@unittest.skipUnless(tpz_serial, "no hardware")
151152
class TestTpz(unittest.TestCase, GenericTpzTest):
152153
def setUp(self):
153-
serial_dev = os.getenv("ARTIQ_TPZ001_SERIAL", "/dev/ttyUSB0")
154-
self.cont = Tpz(serial_dev=serial_dev)
154+
self.cont = Tpz(serial_dev=tpz_serial)
155155

156156

157157
class TestTpzSim(unittest.TestCase, GenericTpzTest):

0 commit comments

Comments
 (0)
Please sign in to comment.