Skip to content

Commit a22c3da

Browse files
authored
Merge pull request #762 from david-cermak/fix/examples_target_tests
[examples]: Test the SLIP netif example on target as well
2 parents 5d0fd5c + 2db11bb commit a22c3da

File tree

4 files changed

+156
-1
lines changed

4 files changed

+156
-1
lines changed

.github/workflows/examples_build-host-test.yml

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,15 @@ jobs:
1313
name: Build examples
1414
strategy:
1515
matrix:
16-
idf_ver: ["latest", "release-v5.1", "release-v5.2", "release-v5.3"]
16+
idf_ver: ["latest", "release-v5.1", "release-v5.2", "release-v5.3", "release-v5.4"]
1717
include:
1818
- idf_ver: "latest"
1919
warning: "Warning: The smallest app partition is nearly full"
2020
runs-on: ubuntu-22.04
2121
container: espressif/idf:${{ matrix.idf_ver }}
22+
env:
23+
TARGET_TEST: examples/esp_netif/slip_custom_netif/
24+
TARGET_TEST_DIR: build_esp32c3_target
2225
steps:
2326
- name: Checkout esp-protocols
2427
uses: actions/checkout@v4
@@ -31,6 +34,16 @@ jobs:
3134
python -m pip install idf-build-apps
3235
# Build default configs for all targets
3336
python ./ci/build_apps.py examples -m examples/.build-test-rules.yml -d -c
37+
# Build target tests
38+
python ./ci/build_apps.py ${TARGET_TEST} -r sdkconfig.ci=target
39+
cd ${TARGET_TEST}
40+
${GITHUB_WORKSPACE}/ci/clean_build_artifacts.sh `pwd`/${TARGET_TEST_DIR}
41+
zip -qur artifacts.zip ${TARGET_TEST_DIR}
42+
- uses: actions/upload-artifact@v4
43+
with:
44+
name: slip_target_${{ matrix.idf_ver }}
45+
path: ${{ env.TARGET_TEST }}/artifacts.zip
46+
if-no-files-found: error
3447

3548
build_and_run_on_host:
3649
if: contains(github.event.pull_request.labels.*.name, 'examples') || github.event_name == 'push'
@@ -51,3 +64,38 @@ jobs:
5164
python ./ci/build_apps.py examples/mqtt -l -t linux
5265
timeout 5 ./examples/mqtt/build_linux_default/esp_mqtt_demo.elf | tee test.log || true
5366
grep 'MQTT_EVENT_DATA' test.log
67+
68+
run_on_target:
69+
# Skip running on forks since it won't have access to secrets
70+
if: |
71+
github.repository == 'espressif/esp-protocols' &&
72+
( contains(github.event.pull_request.labels.*.name, 'examples') || github.event_name == 'push' )
73+
name: Slip example target test
74+
needs: build_all_examples
75+
strategy:
76+
matrix:
77+
idf_ver: ["release-v5.4", "latest"]
78+
runs-on:
79+
- self-hosted
80+
- modem
81+
env:
82+
TARGET_TEST: examples/esp_netif/slip_custom_netif/
83+
TARGET_TEST_DIR: build_esp32c3_target
84+
steps:
85+
- uses: actions/checkout@v4
86+
- uses: actions/download-artifact@v4
87+
with:
88+
name: slip_target_${{ matrix.idf_ver }}
89+
path: ${{ env.TARGET_TEST }}/ci/
90+
- name: Run Test
91+
working-directory: ${{ env.TARGET_TEST }}
92+
run: |
93+
python -m venv .venv
94+
source .venv/bin/activate
95+
pip install --prefer-binary cryptography pytest-embedded pytest-embedded-serial-esp pytest-embedded-idf pytest-custom_exit_code esptool netifaces
96+
unzip ci/artifacts.zip -d ci
97+
for dir in `ls -d ci/build_*`; do
98+
rm -rf build sdkconfig.defaults
99+
mv $dir build
100+
python -m pytest --log-cli-level DEBUG --target=esp32c3
101+
done
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
2+
# SPDX-License-Identifier: Unlicense OR CC0-1.0
3+
from __future__ import print_function, unicode_literals
4+
5+
import subprocess
6+
import time
7+
from threading import Event, Thread
8+
9+
import netifaces
10+
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+
26+
def run_server(server_stop, port):
27+
print('Launching SLIP netif on port: {}'.format(port))
28+
try:
29+
arg_list = ['sudo', 'slattach', '-v', '-L', '-s', '115200','-p', 'slip', port]
30+
p = subprocess.Popen(arg_list, stdout=subprocess.PIPE, bufsize=1)
31+
while not server_stop.is_set():
32+
if p.poll() is not None:
33+
if p.poll() == 16:
34+
print('[SLIP:] Terminated: hang-up received')
35+
break
36+
else:
37+
raise ValueError(
38+
'ENV_TEST_FAILURE: SLIP terminated unexpectedly with {}'
39+
.format(p.poll()))
40+
time.sleep(0.1)
41+
except Exception as e:
42+
print(e)
43+
raise ValueError('ENV_TEST_FAILURE: Error running SLIP netif')
44+
finally:
45+
p.terminate()
46+
print('SLIP netif stopped')
47+
48+
49+
def test_examples_protocol_slip(dut):
50+
51+
# 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
52+
server_port = None
53+
for i in ['/dev/ttyUSB0', '/dev/ttyUSB1', '/dev/ttyUSB2']:
54+
if i == dut.serial.port:
55+
print(f'DUT port: {i}')
56+
elif is_esp32(i):
57+
print(f'Some other ESP32: {i}')
58+
else:
59+
print(f'Port for SLIP: {i}')
60+
server_port = i
61+
if server_port is None:
62+
print('ENV_TEST_FAILURE: Cannot locate SLIP port')
63+
raise
64+
# Attach to the SLI netif
65+
server_stop = Event()
66+
t = Thread(target=run_server, args=(server_stop, server_port))
67+
t.start()
68+
try:
69+
# Setups the SLIP interface
70+
ppp_server_timeout = time.time() + 30
71+
while 'sl0' not in netifaces.interfaces():
72+
print(
73+
"SLIP netif hasn't appear yet, list of active netifs:{}"
74+
.format(netifaces.interfaces()))
75+
time.sleep(0.5)
76+
if time.time() > ppp_server_timeout:
77+
raise ValueError(
78+
'ENV_TEST_FAILURE: SLIP netif failed to setup sl0 interface within timeout'
79+
)
80+
# Configure the SLIP interface with IP addresses of both ends
81+
cmd = ['sudo', 'ifconfig', 'sl0', '10.0.0.1', 'dstaddr', '10.0.0.2']
82+
try:
83+
subprocess.run(cmd, check=True)
84+
print('SLIP interface configured successfully.')
85+
except subprocess.CalledProcessError as e:
86+
print(f'Failed to configure SLIP interface: {e}')
87+
# Ping the SLIP interface with 5 packets and 10 seconds timeout
88+
cmd = ['ping', '10.0.0.2', '-c', '5', '-W', '10']
89+
try:
90+
subprocess.run(cmd, check=True)
91+
print('Pinging SLIP interface successfully.')
92+
except subprocess.CalledProcessError as e:
93+
print(f'Failed to ping SLIP interface: {e}')
94+
raise
95+
96+
finally:
97+
server_stop.set()
98+
t.join()
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CONFIG_IDF_TARGET="esp32c3"
2+
CONFIG_LWIP_PPP_SUPPORT=y
3+
CONFIG_LWIP_SLIP_SUPPORT=y
4+
CONFIG_EXAMPLE_IPV4=y
5+
CONFIG_EXAMPLE_UART_TX_PIN=6
6+
CONFIG_EXAMPLE_UART_RX_PIN=7
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# Override some defaults to enable SLIP
22
CONFIG_LWIP_SLIP_SUPPORT=y
3+
# Workaround: Enable PPP to let esp_netif know that lwip's netif->state
4+
# will be occupied (by SLIP netif info)
5+
CONFIG_LWIP_PPP_SUPPORT=y

0 commit comments

Comments
 (0)