Skip to content

Commit 6d19aab

Browse files
authored
Merge pull request #721 from david-cermak/feat/mosq_target_tests
[mosq]: Add IDF MQTT stress tests to mosquitto CI
2 parents a83f1b6 + 9162de1 commit 6d19aab

File tree

4 files changed

+122
-1
lines changed

4 files changed

+122
-1
lines changed

.github/workflows/mosq__build.yml

+74
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,77 @@ jobs:
101101
exit 1
102102
fi
103103
echo "Versions are consistent: $CONFIG_VERSION"
104+
105+
build_idf_tests_with_mosq:
106+
name: Build IDF tests
107+
strategy:
108+
matrix:
109+
idf_ver: ["latest"]
110+
idf_target: ["esp32"]
111+
test: [ { app: publish, path: "tools/test_apps/protocols/mqtt/publish_connect_test" }]
112+
runs-on: ubuntu-20.04
113+
container: espressif/idf:${{ matrix.idf_ver }}
114+
env:
115+
TARGET_TEST_DIR: build_esp32_local_broker
116+
steps:
117+
- name: Checkout code
118+
uses: actions/checkout@v4
119+
with:
120+
submodules: recursive
121+
- name: Build ${{ matrix.test.app }} with IDF-${{ matrix.idf_ver }} for ${{ matrix.idf_target }}
122+
shell: bash
123+
run: |
124+
. ${IDF_PATH}/export.sh
125+
pip install idf-component-manager idf-build-apps --upgrade
126+
export MOSQUITTO_PATH=`pwd`/components/mosquitto
127+
# to use the actual version of mosquitto
128+
sed -i '/espressif\/mosquitto:/a \ \ \ \ override_path: "${MOSQUITTO_PATH}"' ${IDF_PATH}/${{matrix.test.path}}/main/idf_component.yml
129+
export PEDANTIC_FLAGS="-DIDF_CI_BUILD -Werror -Werror=deprecated-declarations -Werror=unused-variable -Werror=unused-but-set-variable -Werror=unused-function"
130+
export EXTRA_CFLAGS="${PEDANTIC_FLAGS} -Wstrict-prototypes"
131+
export EXTRA_CXXFLAGS="${PEDANTIC_FLAGS}"
132+
cd ${IDF_PATH}/${{matrix.test.path}}
133+
idf-build-apps find --config sdkconfig.ci.local_broker -vv --target ${{ matrix.idf_target }} --build-dir=${TARGET_TEST_DIR}
134+
idf-build-apps build --config sdkconfig.ci.local_broker -vv --target ${{ matrix.idf_target }} --build-dir=${TARGET_TEST_DIR}
135+
${GITHUB_WORKSPACE}/ci/clean_build_artifacts.sh `pwd`/${TARGET_TEST_DIR}
136+
# to replace mqtt test configs with specific mosquitto markers
137+
python ${MOSQUITTO_PATH}/test/replace_decorators.py pytest_mqtt_publish_app.py ${TARGET_TEST_DIR}/pytest_mosquitto.py
138+
zip -qur ${GITHUB_WORKSPACE}/artifacts.zip ${TARGET_TEST_DIR}
139+
- uses: actions/upload-artifact@v4
140+
with:
141+
name: mosq_publish_esp32_${{ matrix.idf_ver }}
142+
path: artifacts.zip
143+
if-no-files-found: error
144+
145+
test_idf_ci_with_mosq:
146+
# Skip running on forks since it won't have access to secrets
147+
if: |
148+
github.repository == 'espressif/esp-protocols' &&
149+
( contains(github.event.pull_request.labels.*.name, 'mosquitto') || github.event_name == 'push' )
150+
name: Mosquitto IDF target tests
151+
needs: build_idf_tests_with_mosq
152+
strategy:
153+
matrix:
154+
idf_ver: ["latest"]
155+
runs-on:
156+
- self-hosted
157+
- ESP32-ETHERNET-KIT
158+
env:
159+
TEST_DIR: examples
160+
steps:
161+
- uses: actions/checkout@v4
162+
- uses: actions/download-artifact@v4
163+
with:
164+
name: mosq_publish_esp32_${{ matrix.idf_ver }}
165+
path: ${{ env.TEST_DIR }}/ci/
166+
- name: Run Test
167+
working-directory: ${{ env.TEST_DIR }}
168+
run: |
169+
python -m pip install pytest-embedded-serial-esp pytest-embedded-idf pytest-rerunfailures pytest-timeout pytest-ignore-test-results "paho-mqtt<2"
170+
unzip ci/artifacts.zip -d ci
171+
for dir in `ls -d ci/build_*`; do
172+
rm -rf build sdkconfig.defaults
173+
mv $dir build
174+
mv build/*.py .
175+
# Run only "test_mosquitto" marked tests
176+
python -m pytest --log-cli-level DEBUG --junit-xml=./results_esp32_${{ matrix.idf_ver }}_${dir#"ci/build_"}.xml --target=esp32 -m test_mosquitto
177+
done

components/mosquitto/README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ mosq_broker_run(&config);
2020
2121
## Memory Footprint Considerations
2222
23-
The broker primarily uses the heap for internal data, with minimal use of static/BSS memory. It consumes approximately 60 kB of program memory.
23+
The broker primarily uses the heap for internal data, with minimal use of static/BSS memory. It consumes approximately 60 kB of program memory and minimum 5kB of stack size.
2424
2525
- **Initial Memory Usage**: ~2 kB of heap on startup
2626
- **Per Client Memory Usage**: ~4 kB of heap for each connected client

components/mosquitto/test/README.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# ESP32 mosquitto tests
2+
3+
Mosquitto component doesn't have any tests yet, but we upcycle IDF mqtt tests and run them with the current version of mosquitto.
4+
For that we need to update the IDF test project's `idf_component.yml` file to reference this actual version of mosquitto.
5+
We also need to update some pytest decorators to run only relevant test cases. See the [replacement](./replace_decorators.py) script.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# SPDX-FileCopyrightText: 2025 Espressif Systems (Shanghai) CO LTD
2+
# SPDX-License-Identifier: Unlicense OR CC0-1.0
3+
4+
# This script replaces the `@pytest` decorators in the test files
5+
# based on the value of the `config` parameter in the `@pytest` decorator.
6+
# to reuse mqtt test cases for mosquitto broker.
7+
8+
import re
9+
import sys
10+
11+
12+
def replace_decorators(in_file: str, out_file: str) -> None:
13+
with open(in_file, 'r') as file:
14+
content = file.read()
15+
16+
# we replace config decorators to differentiate between local mosquitto based tests
17+
pattern = r"@pytest\.mark\.parametrize\(\s*'config'\s*,\s*\[\s*'(.*?)'\s*\]\s*,.*\)"
18+
19+
def replacement(match):
20+
config_value = match.group(1)
21+
if config_value == 'local_broker':
22+
return '@pytest.mark.test_mosquitto'
23+
else:
24+
return '@pytest.mark.test_mqtt'
25+
26+
# Replace occurrences
27+
updated_content = re.sub(pattern, replacement, content)
28+
29+
with open(out_file, 'w') as file:
30+
file.write(updated_content)
31+
32+
33+
# Main function to handle arguments
34+
if __name__ == '__main__':
35+
if len(sys.argv) != 3:
36+
print('Usage: python replace_decorators.py <in_file> <out_file>')
37+
sys.exit(1)
38+
39+
in_file = sys.argv[1]
40+
out_file = sys.argv[2]
41+
replace_decorators(in_file, out_file)
42+
print(f'Replacements completed')

0 commit comments

Comments
 (0)