-
Notifications
You must be signed in to change notification settings - Fork 150
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(examples): Test the SLIP netif example on target as well
- Loading branch information
1 parent
87e96b4
commit 4c62544
Showing
3 changed files
with
152 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD | ||
# SPDX-License-Identifier: Unlicense OR CC0-1.0 | ||
from __future__ import print_function, unicode_literals | ||
|
||
import subprocess | ||
import time | ||
from threading import Event, Thread | ||
|
||
import netifaces | ||
|
||
|
||
def is_esp32(port): | ||
""" | ||
Check if the given port is connected to an ESP32 using esptool. | ||
""" | ||
try: | ||
result = subprocess.run( | ||
['esptool.py', '--port', port, 'chip_id'], | ||
stdout=subprocess.PIPE, stderr=subprocess.PIPE, check=True, text=True | ||
) | ||
return 'ESP32' in result.stdout | ||
except subprocess.CalledProcessError: | ||
return False | ||
|
||
|
||
def run_server(server_stop, port): | ||
print('Launching SLIP netif on port: {}'.format(port)) | ||
try: | ||
arg_list = ['sudo', 'slattach', '-v', '-L', '-s', '115200','-p', 'slip', port] | ||
p = subprocess.Popen(arg_list, stdout=subprocess.PIPE, bufsize=1) | ||
while not server_stop.is_set(): | ||
if p.poll() is not None: | ||
if p.poll() == 16: | ||
print('[SLIP:] Terminated: hang-up received') | ||
break | ||
else: | ||
raise ValueError( | ||
'ENV_TEST_FAILURE: SLIP terminated unexpectedly with {}' | ||
.format(p.poll())) | ||
line = p.stdout.readline() | ||
if line: | ||
print('[SLIP:]{}'.format(line.rstrip())) | ||
time.sleep(0.1) | ||
except Exception as e: | ||
print(e) | ||
raise ValueError('ENV_TEST_FAILURE: Error running SLIP netif') | ||
finally: | ||
p.terminate() | ||
print('SLIP netif stopped') | ||
|
||
|
||
def test_examples_protocol_slip(dut): | ||
|
||
# the PPP test env is reused for SLIP test and it uses three ttyUSB's: two for ESP32 board and another one for the ppp server | ||
server_port = None | ||
for i in ['/dev/ttyUSB0', '/dev/ttyUSB1', '/dev/ttyUSB2']: | ||
if i == dut.serial.port: | ||
print(f'DUT port: {i}') | ||
elif is_esp32(i): | ||
print(f'Some other ESP32: {i}') | ||
else: | ||
print(f'Port for PPPD: {i}') | ||
server_port = i | ||
if server_port is None: | ||
print( | ||
'ENV_TEST_FAILURE: Cannot locate PPPD port' | ||
) | ||
raise | ||
# Attach to the SLI netif | ||
server_stop = Event() | ||
t = Thread(target=run_server, args=(server_stop, server_port)) | ||
t.start() | ||
try: | ||
ppp_server_timeout = time.time() + 30 | ||
while 'sl0' not in netifaces.interfaces(): | ||
print( | ||
"SLIP netif haven't appear yet, list of active netifs:{}" | ||
.format(netifaces.interfaces())) | ||
time.sleep(0.5) | ||
if time.time() > ppp_server_timeout: | ||
raise ValueError( | ||
'ENV_TEST_FAILURE: SLIP netif failed to setup sl0 interface within timeout' | ||
) | ||
|
||
cmd = ['sudo', 'ifconfig', 'sl0', '10.0.0.1', 'dstaddr', '10.0.0.2'] | ||
try: | ||
subprocess.run(cmd, check=True) | ||
print('SLIP interface configured successfully.') | ||
except subprocess.CalledProcessError as e: | ||
print(f'Failed to configure SLIP interface: {e}') | ||
cmd = ['ping', '10.0.0.2'] | ||
try: | ||
subprocess.run(cmd, check=True) | ||
print('Pinging SLIP interface successfully.') | ||
except subprocess.CalledProcessError as e: | ||
print(f'Failed to ping SLIP interface: {e}') | ||
|
||
finally: | ||
server_stop.set() | ||
t.join() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
CONFIG_IDF_TARGET="esp32c3" | ||
CONFIG_LWIP_PPP_SUPPORT=y | ||
CONFIG_LWIP_SLIP_SUPPORT=y | ||
CONFIG_EXAMPLE_IPV4=y | ||
CONFIG_EXAMPLE_UART_RX_PIN=6 | ||
CONFIG_EXAMPLE_UART_RX_PIN=7 |