Skip to content

Commit dbc9b2c

Browse files
remove fixture
1 parent d12b030 commit dbc9b2c

File tree

16 files changed

+374
-159
lines changed

16 files changed

+374
-159
lines changed

.github/actions/target-pytest/action.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ runs:
2626
- name: Run apps
2727
shell: bash
2828
run: |
29-
pytest ${{inputs.app_path}} --ignore-glob '*/managed_components/*' --ignore=.github --target=${{ inputs.target }} --embedded-services esp,idf --build-dir build_esp32_default -m ethernet -v
29+
pytest ${{inputs.app_path}} --target=${{ inputs.target }}
3030
# - name: Upload test results
3131
# uses: actions/upload-artifact@v4
3232
# if: always()

.github/workflows/publish-connect.yml

Lines changed: 119 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,18 @@ env:
1010
target: esp32
1111
idf_version: latest
1212
app_name: publish_connect_test
13-
app_path: $IDF_PATH/tools/test_apps/protocols/mqtt/publish_connect_test
13+
app_path: test/publish_connect_test
1414

1515
jobs:
1616
build:
17+
if: false
1718
name: Build Test App
1819
runs-on: ubuntu-22.04
1920
env:
20-
EXAMPLE_MQTT_BROKER_SSL: "mqtt.eclipseprojects.io:1883"
21-
EXAMPLE_MQTT_BROKER_TCP: "mqtt.eclipseprojects.io:8883"
22-
EXAMPLE_MQTT_BROKER_WS: "mqtt.eclipseprojects.io"
23-
EXAMPLE_MQTT_BROKER_WSS: "mqtt.eclipseprojects.io"
21+
EXAMPLE_MQTT_BROKER_TCP: "mqtt.eclipseprojects.io:1883"
22+
EXAMPLE_MQTT_BROKER_SSL: "mqtt.eclipseprojects.io:8883"
23+
EXAMPLE_MQTT_BROKER_WS: "mqtt.eclipseprojects.io:80"
24+
EXAMPLE_MQTT_BROKER_WSS: "mqtt.eclipseprojects.io:443"
2425
outputs:
2526
build_path: ${{steps.build.outputs.artifacts_path}}
2627
container: espressif/idf:latest
@@ -52,10 +53,39 @@ jobs:
5253
${{steps.build.outputs.artifacts_path}}/build_*/*.bin
5354
${{steps.build.outputs.artifacts_path}}/build_*/flasher_args.json
5455
${{steps.build.outputs.artifacts_path}}/build_*/config/sdkconfig.json
55-
${{steps.build.outputs.artifacts_path}}/*.py
5656
if-no-files-found: error
57+
- name: Output env
58+
shell: bash
59+
run: |
60+
echo ${EXAMPLE_MQTT_BROKER_TCP}
61+
echo ${EXAMPLE_MQTT_BROKER_SSL}
62+
echo ${EXAMPLE_MQTT_BROKER_WS}
63+
echo ${EXAMPLE_MQTT_BROKER_WSS}
64+
65+
get_ip:
66+
# if: github.repository == 'espressif/esp-mqtt'
67+
name: Get Ip
68+
runs-on: [self-hosted, linux, docker, ESP32-ETHERNET-KIT]
69+
steps:
70+
# - name: Add node for local tests
71+
# if: ${{ env.ACT }}
72+
# shell: bash
73+
# run: |
74+
# curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
75+
# apt-get install -y nodejs
76+
- name: Install iproute2
77+
shell: bash
78+
run: apt-get update && apt-get install -y iproute2
79+
- name: Get runner IP
80+
id: get_ip
81+
shell: bash
82+
run: |
83+
IP=$(ip route get 1| awk '{print $7; exit}')
84+
echo $IP
85+
echo "RUNNER_IP=$IP" >> $GITHUB_ENV
5786
5887
run-on-target:
88+
if: false
5989
# if: github.repository == 'espressif/esp-mqtt'
6090
name: Publish and Connect target test
6191
needs: build
@@ -84,10 +114,23 @@ jobs:
84114
# TEST_RESULT_NAME: test_results_${{ matrix.runner.target }}_${{ matrix.runner.marker }}_${{ matrix.idf_ver }}
85115
# TEST_RESULT_FILE: test_results_${{ matrix.runner.target }}_${{ matrix.runner.marker }}_${{ matrix.idf_ver }}.xml
86116
# runs-on: [self-hosted, linux, docker, "${{ matrix.runner.runs-on }}"]
87-
container:
88-
image: python:3.11-bookworm
89-
options: --privileged # Privileged mode has access to serial ports
90-
runs-on: [self-hosted, linux, docker, ESP32-ETHERNET-KIT]
117+
# container:
118+
# image: python:3.11-bookworm
119+
# options: --privileged # Privileged mode has access to serial ports
120+
# runs-on: [self-hosted, linux, docker, ESP32-ETHERNET-KIT]
121+
runs-on: ubuntu-22.04
122+
services:
123+
mqtt-test-broker:
124+
image: eclipse-mosquitto:latest
125+
ports:
126+
- 42351:42351
127+
- 42352:42352
128+
- 42353:42353
129+
- 42354:42354
130+
volumes:
131+
- ${{ github.workspace }}/ci/broker/config:/mosquitto/config
132+
- ${{ github.workspace }}/ci/broker/certs:/mosquitto/certfiles
133+
- ${{ github.workspace }}/ci/broker/.mosquitto.log:/var/log/mosquitto.log
91134

92135
strategy:
93136
matrix:
@@ -107,22 +150,76 @@ jobs:
107150
run: |
108151
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
109152
apt-get install -y nodejs
153+
- name: Install Python packages
154+
shell: bash
155+
env:
156+
PIP_EXTRA_INDEX_URL: "https://dl.espressif.com/pypi/"
157+
run: pip install --prefer-binary paho-mqtt
158+
- name: Install dependencies
159+
shell: bash
160+
run: apt-get update && apt-get install -y iproute2
110161
- uses: actions/checkout@v4
111162
- name: Download artifacts
112163
uses: actions/download-artifact@v4
113164
id: artifacts
114165
with:
115166
name: mqtt_bin_${{env.target}}_${{ env.idf_version }}_${{ env.app_name }}
116-
path: test
117-
- name: Check artifacts
167+
path: test/publish_connect_test
168+
- name: Get runner IP
169+
id: get_ip
118170
shell: bash
119-
run: ls test/
120-
# - name: Checkout IDF ${{inputs.idf_version}}
121-
# uses: actions/checkout@v4
122-
# with:
123-
# repository: espressif/esp-idf
124-
# path: idf
125-
# ref: master
171+
run: |
172+
IP=$(ip route get 1| awk '{print $7; exit}')
173+
echo "RUNNER_IP=$IP" >> $GITHUB_ENV
174+
- name: Run app in Docker
175+
shell: bash
176+
env:
177+
RUNNER_IP: ${{ env.RUNNER_IP }}
178+
run: |
179+
docker run --rm \
180+
-v "${{ github.workspace }}:/workspace" \
181+
-w /workspace \
182+
-e RUNNER_IP="${RUNNER_IP}" \
183+
python:3.11-bookworm \
184+
bash -c "
185+
pip install --prefer-binary cryptography pytest-embedded pytest-embedded-serial-esp pytest-embedded-idf pytest-custom_exit_code &&
186+
pytest test/publish_connect_test --target=esp32
187+
"
188+
- name: Cleanup workspace
189+
if: always()
190+
shell: bash
191+
run: |
192+
rm -rf test/publish_connect_test
193+
- name: Add node for local tests
194+
if: ${{ env.ACT }}
195+
shell: bash
196+
run: |
197+
curl -fsSL https://deb.nodesource.com/setup_18.x | bash -
198+
apt-get install -y nodejs
199+
- name: Install Python packages
200+
shell: bash
201+
env:
202+
PIP_EXTRA_INDEX_URL: "https://dl.espressif.com/pypi/"
203+
run: pip install --prefer-binary paho-mqtt
204+
- name: Install dependencies
205+
shell: bash
206+
run: apt-get update && apt-get install -y iproute2
207+
- uses: actions/checkout@v4
208+
- name: Download artifacts
209+
uses: actions/download-artifact@v4
210+
id: artifacts
211+
with:
212+
name: mqtt_bin_${{env.target}}_${{ env.idf_version }}_${{ env.app_name }}
213+
path: test/publish_connect_test
214+
# - name: Run mosquitto
215+
# shell: bash
216+
# run: mosquitto -c ci/broker/mosquitto.conf &
217+
- name: Get runner IP
218+
id: get_ip
219+
shell: bash
220+
run: |
221+
IP=$(ip route get 1| awk '{print $7; exit}')
222+
echo "RUNNER_IP=$IP" >> $GITHUB_ENV
126223
# - name: Install Python packages
127224
# shell: bash
128225
# env:
@@ -139,4 +236,6 @@ jobs:
139236
with:
140237
target: esp32
141238
app_name: publish_connnect_test
142-
app_path: test
239+
app_path: test/publish_connect_test
240+
env:
241+
RUNNER_IP: ${{ env.RUNNER_IP }}

ci/broker/README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
### Prerequisites
2+
* installed docker-compose (https://docs.docker.com/compose/install/)
3+
4+
### Rebuild and run one-line command
5+
```
6+
docker-compose up -d
7+
```
8+
9+
### Rebuild and run with output to console, for some debug
10+
```
11+
docker-compose up
12+
```
13+
14+
### (Example) Successful state
15+
```
16+
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
17+
407b9ccb85b9 eclipse-mosquitto:latest "/docker-entrypoin..." 14 minutes ago Up 4 seconds 0.0.0.0:42351->42351/tcp mqtt-tcp-server
18+
5204c0cb11ef eclipse-mosquitto:latest "/docker-entrypoin..." 14 minutes ago Up 4 seconds 0.0.0.0:42352->42352/tcp mqtt-ssl-server
19+
cc8aa247c32e eclipse-mosquitto:latest "/docker-entrypoin..." 14 minutes ago Up 4 seconds 0.0.0.0:42353->42353/tcp mqtt-websockets-tcp-server
20+
41e189081c47 eclipse-mosquitto:latest "/docker-entrypoin..." 14 minutes ago Up 4 seconds 0.0.0.0:42354->42354/tcp mqtt-websockets-ssl-server
21+
```

ci/broker/config/mosquitto.conf

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# General configuration
2+
log_type all
3+
connection_messages true
4+
allow_anonymous true
5+
6+
# TCP Listener
7+
listener 42351
8+
protocol mqtt
9+
10+
# WebSocket Listener
11+
listener 42353
12+
protocol websockets
13+
14+
# SSL Listener
15+
listener 42352
16+
protocol mqtt
17+
cafile /mosquitto/certfiles/server.crt
18+
certfile /mosquitto/certfiles/server.crt
19+
keyfile /mosquitto/certfiles/server.key
20+
21+
# WebSocket over SSL
22+
listener 42354
23+
protocol websockets
24+
cafile /mosquitto/certfiles/server.crt
25+
certfile /mosquitto/certfiles/server.crt
26+
keyfile /mosquitto/certfiles/server.key
27+

ci/broker/docker-compose.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
version: "3"
2+
services:
3+
mqtt-test-broker:
4+
image: eclipse-mosquitto:latest
5+
container_name: mqtt-test-broker
6+
ports:
7+
- 42351:42351
8+
- 42352:42352
9+
- 42353:42353
10+
- 42354:42354
11+
volumes:
12+
- ./config/:/mosquitto/config
13+
- ./certs/:/mosquitto/certfiles
14+
- .mosquitto.log:/var/log/mosquitto.log

conftest.py

Lines changed: 67 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,81 @@
11
import pytest
2+
import typing as t
3+
import os
4+
import logging as logger
25
from pytest_embedded.plugin import multi_dut_argument
36
from pytest_embedded.plugin import multi_dut_fixture
47
from _pytest.fixtures import FixtureRequest
58

6-
def pytest_configure(config):
7-
for plugin in config.pluginmanager.list_name_plugin():
8-
print("Loaded plugins", plugin)
9-
109
@pytest.fixture
1110
@multi_dut_argument
1211
def config(request: FixtureRequest) -> str:
1312
return getattr(request, 'param', None) or 'default' # type: ignore
1413

1514
@pytest.fixture
1615
@multi_dut_fixture
17-
def target(request: FixtureRequest, dut_total: int, dut_index: int) -> str:
18-
plugin = request.config.stash[pytest.StashKey['IdfPytestEmbedded']]
16+
def build_dir(
17+
request: FixtureRequest,
18+
app_path: str,
19+
target: t.Optional[str],
20+
config: t.Optional[str],
21+
) -> str:
22+
"""Find a valid build directory based on priority rules.
23+
24+
Checks local build directories in the following order:
25+
26+
1. build_<target>_<config>
27+
2. build_<target>
28+
3. build_<config>
29+
4. build
30+
31+
:param request: Pytest fixture request
32+
:param app_path: Path to the application
33+
:param target: Target being used
34+
:param config: Configuration being used
35+
36+
:returns: Valid build directory name
37+
38+
:raises ValueError: If no valid build directory is found
39+
"""
40+
check_dirs = []
41+
build_dir_arg = request.config.getoption('build_dir')
42+
43+
if build_dir_arg:
44+
check_dirs.append(build_dir_arg)
45+
if target is not None and config is not None:
46+
check_dirs.append(f'build_{target}_{config}')
47+
if target is not None:
48+
check_dirs.append(f'build_{target}')
49+
if config is not None:
50+
check_dirs.append(f'build_{config}')
51+
check_dirs.append('build')
52+
53+
for check_dir in check_dirs:
54+
binary_path = os.path.join(app_path, check_dir)
55+
if os.path.isdir(binary_path):
56+
logger.info(f'Found valid binary path: {binary_path}')
57+
return check_dir
58+
59+
logger.warning('Checking binary path: %s... missing... trying another location', binary_path)
60+
61+
raise ValueError(
62+
'No valid build directory found. '
63+
f'Please build the binary via "idf.py -B {check_dirs[0]} build" and run pytest again'
64+
)
65+
66+
@pytest.fixture
67+
def log_performance(record_property: t.Callable[[str, object], None]) -> t.Callable[[str, str], None]:
68+
"""
69+
log performance item with pre-defined format to the console
70+
and record it under the ``properties`` tag in the junit report if available.
71+
"""
1972

20-
if dut_total == 1:
21-
return plugin.target[0] # type: ignore
73+
def real_func(item: str, value: str) -> None:
74+
"""
75+
:param item: performance item name
76+
:param value: performance value
77+
"""
78+
logger.info('[Performance][%s]: %s', item, value)
79+
record_property(item, value)
2280

23-
return plugin.target[dut_index] # type: ignore
81+
return real_func

pytest.ini

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ addopts =
99
--skip-check-coredump y
1010
--logfile-extension ".txt"
1111
--check-duplicates y
12-
--ignore-glob managed_components/*
13-
--ignore pytest-embedded
12+
--ignore-glob **/managed_components/*
13+
--ignore=.github

test/publish_connect_test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ idf_build_set_property(MINIMAL_BUILD ON)
77

88
project(mqtt_publish_connect_test)
99

10-
target_add_binary_data(mqtt_publish_connect_test.elf "main/mqtt_eclipseprojects_io.pem" TEXT)
10+
target_add_binary_data(mqtt_publish_connect_test.elf "../../ci/broker/certs/server.crt" TEXT)
1111
target_add_binary_data(mqtt_publish_connect_test.elf "ca.crt" TEXT)
1212
target_add_binary_data(mqtt_publish_connect_test.elf "ca.der" TEXT)
1313
target_add_binary_data(mqtt_publish_connect_test.elf "client_pwd.key" TEXT)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import socket
2+
import logging
3+
from typing import Any
4+
from pytest_embedded import Dut
5+
6+
def get_host_ip4_by_dest_ip(dest_ip: str = '') -> str:
7+
if not dest_ip:
8+
dest_ip = '8.8.8.8'
9+
s1 = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
10+
s1.connect((dest_ip, 80))
11+
host_ip = s1.getsockname()[0]
12+
s1.close()
13+
assert isinstance(host_ip, str)
14+
print(f'Using host ip: {host_ip}')
15+
return host_ip
16+
17+
def get_runner_ip(dut: Dut) -> Any:
18+
dut_ip = dut.expect(r'IPv4 address: (\d+\.\d+\.\d+\.\d+)[^\d]', timeout=30).group(1).decode()
19+
logging.info('Got IP={}'.format(dut_ip))
20+
return get_host_ip4_by_dest_ip(dut_ip)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
idf_component_register(SRCS "publish_test.c" "connect_test.c" "publish_connect_test.c"
22
INCLUDE_DIRS "."
33
REQUIRES mqtt nvs_flash console esp_netif)
4-
target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")
4+
# target_compile_options(${COMPONENT_LIB} PRIVATE "-Wno-format")

0 commit comments

Comments
 (0)