Skip to content

Commit

Permalink
fix(modem): Detect serial ports properly
Browse files Browse the repository at this point in the history
  • Loading branch information
david-cermak committed Nov 29, 2024
1 parent 1284f66 commit 0cb59ff
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/modem__target-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ jobs:
name: modem_target_bin_${{ matrix.idf_target }}_${{ matrix.idf_ver }}_${{ matrix.test.app }}
path: ${{ env.TEST_DIR }}/build
- name: Run Example Test on target
working-directory: ${{ env.TEST_DIR }}
env:
PIP_EXTRA_INDEX_URL: "https://dl.espressif.com/pypi/"
run: |
python -m pip install -r $GITHUB_WORKSPACE/ci/requirements.txt
python -m venv .venv
source .venv/bin/activate
pip install --prefer-binary cryptography pytest-embedded pytest-embedded-serial-esp pytest-embedded-idf pytest-custom_exit_code esptool
pip install -r $GITHUB_WORKSPACE/ci/requirements.txt
cd ${{ env.TEST_DIR }}
python -m pytest --log-cli-level DEBUG --target=${{ matrix.idf_target }}
36 changes: 32 additions & 4 deletions components/esp_modem/test/target/pytest_pppd.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@
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, server_ip, client_ip, auth, auth_user, auth_password):
print('Starting PPP server on port: {}'.format(port))
try:
Expand Down Expand Up @@ -66,13 +80,27 @@ def test_examples_protocol_pppos_connect(dut):
)
raise

# the PPP test env uses two ttyUSB's: one for ESP32 board, another one for ppp server
# use the other port for PPP server than the DUT/ESP
port = '/dev/ttyUSB0' if dut.serial.port == '/dev/ttyUSB1' else '/dev/ttyUSB1'
# the PPP test env uses three ttyUSB's: two for ESP32 board and another one for the ppp server
# we need to detect the server_port (for PPPD)
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

# Start the PPP server
server_stop = Event()
t = Thread(target=run_server,
args=(server_stop, port, server_ip, client_ip, auth, auth_user, auth_password))
args=(server_stop, server_port, server_ip, client_ip, auth, auth_user, auth_password))
t.start()
try:
ppp_server_timeout = time.time() + 30
Expand Down

0 comments on commit 0cb59ff

Please sign in to comment.