|
1 |
| -import pytest |
2 |
| -import usb |
| 1 | +from time import sleep |
| 2 | + |
3 | 3 | from jumpstarter_driver_network.adapters import PexpectAdapter
|
4 | 4 |
|
5 |
| -from jumpstarter_driver_dutlink.driver import Dutlink |
| 5 | +from jumpstarter_driver_dutlink.driver import Dutlink, DutlinkPower, DutlinkSerial, DutlinkStorageMux |
6 | 6 |
|
7 | 7 | from jumpstarter.common.utils import serve
|
8 | 8 |
|
| 9 | +STORAGE_DEVICE = "/dev/null" # MANUAL: replace with path to block device |
9 | 10 |
|
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() |
21 | 39 |
|
22 | 40 | with serve(instance) as client:
|
23 |
| - with PexpectAdapter(client=client.console) as expect: |
24 |
| - expect.send("\x02" * 5) |
| 41 | + power_test(client) |
25 | 42 |
|
26 |
| - expect.send("about\r\n") |
27 |
| - expect.expect("Jumpstarter test-harness") |
28 | 43 |
|
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) |
31 | 46 |
|
32 |
| - client.power.off() |
| 47 | + with serve(instance) as client: |
| 48 | + storage_test(client) |
33 | 49 |
|
34 |
| - client.storage.write_local_file("/dev/null") |
35 |
| - client.storage.dut() |
36 | 50 |
|
37 |
| - client.power.on() |
| 51 | +def test_drivers_dutlink_serial(): |
| 52 | + instance = DutlinkSerial() # MANUAL: connect tx to rx |
38 | 53 |
|
39 |
| - expect.send("\x02" * 5) |
40 |
| - expect.expect("Exiting console mode") |
| 54 | + with serve(instance) as client: |
| 55 | + serial_test(client) |
41 | 56 |
|
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