|
9 | 9 | import netifaces
|
10 | 10 |
|
11 | 11 |
|
| 12 | +def is_esp32(port): |
| 13 | + """ |
| 14 | + Check if the given port is connected to an ESP32 using esptool. |
| 15 | + """ |
| 16 | + try: |
| 17 | + result = subprocess.run( |
| 18 | + ['esptool.py', '--port', port, 'chip_id'], |
| 19 | + stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, text=True |
| 20 | + ) |
| 21 | + return 'ESP32' in result.stdout |
| 22 | + except subprocess.CalledProcessError: |
| 23 | + return False |
| 24 | + |
| 25 | + |
12 | 26 | def run_server(server_stop, port, server_ip, client_ip, auth, auth_user, auth_password):
|
13 | 27 | print('Starting PPP server on port: {}'.format(port))
|
14 | 28 | try:
|
@@ -66,13 +80,27 @@ def test_examples_protocol_pppos_connect(dut):
|
66 | 80 | )
|
67 | 81 | raise
|
68 | 82 |
|
69 |
| - # the PPP test env uses two ttyUSB's: one for ESP32 board, another one for ppp server |
70 |
| - # use the other port for PPP server than the DUT/ESP |
71 |
| - port = '/dev/ttyUSB0' if dut.serial.port == '/dev/ttyUSB1' else '/dev/ttyUSB1' |
| 83 | + # the PPP test env uses three ttyUSB's: two for ESP32 board and another one for the ppp server |
| 84 | + # we need to detect the server_port (for PPPD) |
| 85 | + server_port = None |
| 86 | + for i in ['/dev/ttyUSB0', '/dev/ttyUSB1', '/dev/ttyUSB2']: |
| 87 | + if i == dut.serial.port: |
| 88 | + print(f'DUT port: {i}') |
| 89 | + elif is_esp32(i): |
| 90 | + print(f'Some other ESP32: {i}') |
| 91 | + else: |
| 92 | + print(f'Port for PPPD: {i}') |
| 93 | + server_port = i |
| 94 | + if server_port is None: |
| 95 | + print( |
| 96 | + 'ENV_TEST_FAILURE: Cannot locate PPPD port' |
| 97 | + ) |
| 98 | + raise |
| 99 | + |
72 | 100 | # Start the PPP server
|
73 | 101 | server_stop = Event()
|
74 | 102 | t = Thread(target=run_server,
|
75 |
| - args=(server_stop, port, server_ip, client_ip, auth, auth_user, auth_password)) |
| 103 | + args=(server_stop, server_port, server_ip, client_ip, auth, auth_user, auth_password)) |
76 | 104 | t.start()
|
77 | 105 | try:
|
78 | 106 | ppp_server_timeout = time.time() + 30
|
|
0 commit comments