Skip to content

Commit

Permalink
Merge pull request #260 from horw/fix/qemu-qmp-port-allocation
Browse files Browse the repository at this point in the history
  • Loading branch information
hfudev authored Jan 15, 2024
2 parents 40681ff + f6e135f commit 1207d2f
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ jobs:
apt update && apt install -y socat zip
pip install -U pip
export PIP_EXTRA_INDEX_URL="https://dl.espressif.com/pypi"
pip install cryptography --only-binary :all:
pip install cryptography --prefer-binary
pip install -r requirements.txt
bash foreach.sh install
- name: Check ports
Expand Down
9 changes: 6 additions & 3 deletions pytest-embedded-qemu/pytest_embedded_qemu/qemu.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import asyncio
import os
import shlex
import socket
import typing as t

from pytest_embedded.log import DuplicateStdoutPopen
Expand Down Expand Up @@ -28,7 +29,7 @@ class Qemu(DuplicateStdoutPopen):
QEMU_STRAP_MODE_FMT = '-global driver=esp32.gpio,property=strap_mode,value={}'
QEMU_SERIAL_TCP_FMT = '-serial tcp::{},server,nowait'

QEMU_DEFAULT_QMP_FMT = '-qmp tcp:localhost:{},server,wait=off'
QEMU_DEFAULT_QMP_FMT = '-qmp tcp:127.0.0.1:{},server,wait=off'

def __init__(
self,
Expand Down Expand Up @@ -75,8 +76,10 @@ def __init__(
qemu_cli_args[i + 1] = ','.join(cmd)
break
else:
self.qmp_addr = 'localhost'
self.qmp_port = 4488 + dut_index
self.qmp_addr = '127.0.0.1'
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.bind((self.qmp_addr, 0))
_, self.qmp_port = s.getsockname()
qemu_cli_args += shlex.split(self.QEMU_DEFAULT_QMP_FMT.format(self.qmp_port))

super().__init__(
Expand Down
2 changes: 1 addition & 1 deletion pytest-embedded-qemu/tests/test_qemu.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ def test_pexpect_by_qemu(dut):
'-s',
'--embedded-services', 'idf,qemu',
'--app-path', os.path.join(testdir.tmpdir, 'hello_world_esp32'),
'--qemu-cli-args="-qmp tcp:localhost:4488,server,wait=off -machine esp32 -nographic"',
'--qemu-cli-args="-machine esp32 -nographic"',
)

result.assert_outcomes(passed=1)
Expand Down

0 comments on commit 1207d2f

Please sign in to comment.