Skip to content

Commit 1382071

Browse files
authored
Merge pull request #230 from jumpstarter-dev/dutlink-test-fix
fix and expand dutlink tests
2 parents ee4720b + 3371b1d commit 1382071

File tree

2 files changed

+62
-27
lines changed

2 files changed

+62
-27
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import pytest
2+
import usb
3+
4+
5+
def pytest_runtest_call(item):
6+
try:
7+
item.runtest()
8+
except FileNotFoundError:
9+
pytest.skip("dutlink not available")
10+
except usb.core.USBError:
11+
pytest.skip("USB not available")
12+
except usb.core.NoBackendError:
13+
pytest.skip("No USB backend")
Lines changed: 49 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,64 @@
1-
import pytest
2-
import usb
1+
from time import sleep
2+
33
from jumpstarter_driver_network.adapters import PexpectAdapter
44

5-
from jumpstarter_driver_dutlink.driver import Dutlink
5+
from jumpstarter_driver_dutlink.driver import Dutlink, DutlinkPower, DutlinkSerial, DutlinkStorageMux
66

77
from jumpstarter.common.utils import serve
88

9+
STORAGE_DEVICE = "/dev/null" # MANUAL: replace with path to block device
910

10-
def test_drivers_dutlink():
11-
try:
12-
instance = Dutlink(
13-
storage_device="/dev/null",
14-
)
15-
except FileNotFoundError:
16-
pytest.skip("dutlink not available")
17-
except usb.core.USBError:
18-
pytest.skip("USB not available")
19-
except usb.core.NoBackendError:
20-
pytest.skip("No USB backend")
11+
12+
def power_test(power):
13+
power.on() # MANUAL: led DUT_ON should be turned on
14+
sleep(1)
15+
assert next(power.read()).current != 0
16+
power.off() # MANUAL: led DUT_ON should be turned off
17+
18+
19+
def storage_test(storage):
20+
storage.write_local_file("/dev/null")
21+
22+
23+
def serial_test(serial):
24+
with PexpectAdapter(client=serial) as expect:
25+
expect.send("\x02" * 5)
26+
27+
expect.send("about\r\n")
28+
expect.expect("Jumpstarter test-harness")
29+
30+
expect.send("console\r\n")
31+
expect.expect("Entering console mode")
32+
33+
expect.send("hello")
34+
expect.expect("hello")
35+
36+
37+
def test_drivers_dutlink_power():
38+
instance = DutlinkPower()
2139

2240
with serve(instance) as client:
23-
with PexpectAdapter(client=client.console) as expect:
24-
expect.send("\x02" * 5)
41+
power_test(client)
2542

26-
expect.send("about\r\n")
27-
expect.expect("Jumpstarter test-harness")
2843

29-
expect.send("console\r\n")
30-
expect.expect("Entering console mode")
44+
def test_drivers_dutlink_storage_mux():
45+
instance = DutlinkStorageMux(storage_device=STORAGE_DEVICE)
3146

32-
client.power.off()
47+
with serve(instance) as client:
48+
storage_test(client)
3349

34-
client.storage.write_local_file("/dev/null")
35-
client.storage.dut()
3650

37-
client.power.on()
51+
def test_drivers_dutlink_serial():
52+
instance = DutlinkSerial() # MANUAL: connect tx to rx
3853

39-
expect.send("\x02" * 5)
40-
expect.expect("Exiting console mode")
54+
with serve(instance) as client:
55+
serial_test(client)
4156

42-
client.power.off()
57+
58+
def test_drivers_dutlink():
59+
instance = Dutlink(storage_device=STORAGE_DEVICE)
60+
61+
with serve(instance) as client:
62+
power_test(client.power)
63+
storage_test(client.storage)
64+
serial_test(client.console)

0 commit comments

Comments
 (0)