Skip to content

Commit 9162de1

Browse files
committed
fix(mosq): Remove temp modification of IDF files
1 parent dbd164d commit 9162de1

File tree

3 files changed

+54
-13
lines changed

3 files changed

+54
-13
lines changed

.github/workflows/mosq__build.yml

+7-13
Original file line numberDiff line numberDiff line change
@@ -123,25 +123,18 @@ jobs:
123123
run: |
124124
. ${IDF_PATH}/export.sh
125125
pip install idf-component-manager idf-build-apps --upgrade
126-
export OVERRIDE_PATH=`pwd`/components/mosquitto
127-
echo ${OVERRIDE_PATH}
128-
sed -i '/espressif\/mosquitto:/a \ \ \ \ override_path: "${OVERRIDE_PATH}"' ${IDF_PATH}/${{matrix.test.path}}/main/idf_component.yml
129-
cat ${IDF_PATH}/${{matrix.test.path}}/main/idf_component.yml
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
130129
export PEDANTIC_FLAGS="-DIDF_CI_BUILD -Werror -Werror=deprecated-declarations -Werror=unused-variable -Werror=unused-but-set-variable -Werror=unused-function"
131130
export EXTRA_CFLAGS="${PEDANTIC_FLAGS} -Wstrict-prototypes"
132131
export EXTRA_CXXFLAGS="${PEDANTIC_FLAGS}"
133132
cd ${IDF_PATH}/${{matrix.test.path}}
134-
sed -i 's/4096, /5\*1024, /' main/publish_connect_test.c
135-
cat main/publish_connect_test.c
136133
idf-build-apps find --config sdkconfig.ci.local_broker -vv --target ${{ matrix.idf_target }} --build-dir=${TARGET_TEST_DIR}
137134
idf-build-apps build --config sdkconfig.ci.local_broker -vv --target ${{ matrix.idf_target }} --build-dir=${TARGET_TEST_DIR}
138135
${GITHUB_WORKSPACE}/ci/clean_build_artifacts.sh `pwd`/${TARGET_TEST_DIR}
139-
sed '/@pytest.mark.parametrize.*config.*/{
140-
s/@pytest.mark.parametrize.*config.*local_broker.*/@pytest.mark.protocols/
141-
t
142-
d
143-
}' pytest_mqtt_publish_app.py > ${TARGET_TEST_DIR}/pytest_local_mosq.py
144-
cat ${TARGET_TEST_DIR}/pytest_local_mosq.py
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
145138
zip -qur ${GITHUB_WORKSPACE}/artifacts.zip ${TARGET_TEST_DIR}
146139
- uses: actions/upload-artifact@v4
147140
with:
@@ -179,5 +172,6 @@ jobs:
179172
rm -rf build sdkconfig.defaults
180173
mv $dir build
181174
mv build/*.py .
182-
python -m pytest --log-cli-level DEBUG --junit-xml=./results_esp32_${{ matrix.idf_ver }}_${dir#"ci/build_"}.xml --target=esp32 -m protocols
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
183177
done

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)