Skip to content

Commit 0cb59ff

Browse files
committed
fix(modem): Detect serial ports properly
1 parent 1284f66 commit 0cb59ff

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

.github/workflows/modem__target-test.yml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,12 @@ jobs:
8080
name: modem_target_bin_${{ matrix.idf_target }}_${{ matrix.idf_ver }}_${{ matrix.test.app }}
8181
path: ${{ env.TEST_DIR }}/build
8282
- name: Run Example Test on target
83-
working-directory: ${{ env.TEST_DIR }}
83+
env:
84+
PIP_EXTRA_INDEX_URL: "https://dl.espressif.com/pypi/"
8485
run: |
85-
python -m pip install -r $GITHUB_WORKSPACE/ci/requirements.txt
86+
python -m venv .venv
87+
source .venv/bin/activate
88+
pip install --prefer-binary cryptography pytest-embedded pytest-embedded-serial-esp pytest-embedded-idf pytest-custom_exit_code esptool
89+
pip install -r $GITHUB_WORKSPACE/ci/requirements.txt
90+
cd ${{ env.TEST_DIR }}
8691
python -m pytest --log-cli-level DEBUG --target=${{ matrix.idf_target }}

components/esp_modem/test/target/pytest_pppd.py

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,20 @@
99
import netifaces
1010

1111

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+
1226
def run_server(server_stop, port, server_ip, client_ip, auth, auth_user, auth_password):
1327
print('Starting PPP server on port: {}'.format(port))
1428
try:
@@ -66,13 +80,27 @@ def test_examples_protocol_pppos_connect(dut):
6680
)
6781
raise
6882

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+
72100
# Start the PPP server
73101
server_stop = Event()
74102
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))
76104
t.start()
77105
try:
78106
ppp_server_timeout = time.time() + 30

0 commit comments

Comments
 (0)