Skip to content

Commit e403f0b

Browse files
authored
ci(json): Add configuration requirements to ci.json files (#10385)
* ci(json): Add support for checking sdkconfig before running tests * docs(ci): Add explanation about requires field in JSON * fix(json): Ignore comments when searching requirements * feat(json): Add extended regex support to requires field * change(json): Move to using requirements in JSON * fix(json): Fix requirements for touch tests * refactor(json): Fix formatting of JSON files * fix(spi): Fix SPI example and JSON
1 parent 1f1de27 commit e403f0b

File tree

169 files changed

+654
-688
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

169 files changed

+654
-688
lines changed

.github/scripts/install-platformio-esp32.sh

+38-9
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ PLATFORMIO_ESP32_URL="https://github.com/platformio/platform-espressif32.git"
66
TOOLCHAIN_VERSION="12.2.0+20230208"
77
ESPTOOLPY_VERSION="~1.40501.0"
88
ESPRESSIF_ORGANIZATION_NAME="espressif"
9+
LIBS_DIR="tools/esp32-arduino-libs"
910

1011
echo "Installing Python Wheel ..."
1112
pip install wheel > /dev/null 2>&1
@@ -88,12 +89,25 @@ function count_sketches(){ # count_sketches <examples-path>
8889
local sketchname=$(basename $sketch)
8990
if [[ "${sketchdirname}.ino" != "$sketchname" ]]; then
9091
continue
92+
elif [ -f $sketchdir/ci.json ]; then
93+
# If the target is listed as false, skip the sketch. Otherwise, include it.
94+
is_target=$(jq -r '.targets[esp32]' $sketchdir/ci.json)
95+
if [[ "$is_target" == "false" ]]; then
96+
continue
97+
fi
98+
99+
# Check if the sketch requires any configuration options
100+
requirements=$(jq -r '.requires[]? // empty' $sketchdir/ci.json)
101+
if [[ "$requirements" != "null" ]] || [[ "$requirements" != "" ]]; then
102+
for requirement in $requirements; do
103+
found_line=$(grep -E "^$requirement" $LIBS_DIR/esp32/sdkconfig)
104+
if [[ "$found_line" == "" ]]; then
105+
continue 2
106+
fi
107+
done
108+
fi
91109
fi
92-
is_target=$(jq -r --arg target $target '.targets[$target]' $sketchdir/ci.json)
93-
# If the target is listed as false, skip the sketch. Otherwise, include it.
94-
if [[ "$is_target" == "false" ]]; then
95-
continue
96-
fi
110+
97111
echo $sketch >> sketches.txt
98112
sketchnum=$(($sketchnum + 1))
99113
done
@@ -163,12 +177,27 @@ function build_pio_sketches(){ # build_pio_sketches <board> <options> <examples-
163177
local sketchdir=$(dirname $sketch)
164178
local sketchdirname=$(basename $sketchdir)
165179
local sketchname=$(basename $sketch)
166-
is_target=$(jq -r --arg target $target '.targets[$target]' $sketchdir/ci.json)
167-
# If the target is listed as false, skip the sketch. Otherwise, include it.
168-
if [ "${sketchdirname}.ino" != "$sketchname" ] \
169-
|| [[ "$is_target" == "false" ]]; then
180+
if [[ "$sketchdirname.ino" != "$sketchname" ]]; then
170181
continue
182+
elif [ -f $sketchdir/ci.json ]; then
183+
# If the target is listed as false, skip the sketch. Otherwise, include it.
184+
is_target=$(jq -r '.targets[esp32]' $sketchdir/ci.json)
185+
if [[ "$is_target" == "false" ]]; then
186+
continue
187+
fi
188+
189+
# Check if the sketch requires any configuration options
190+
requirements=$(jq -r '.requires[]? // empty' $sketchdir/ci.json)
191+
if [[ "$requirements" != "null" ]] || [[ "$requirements" != "" ]]; then
192+
for requirement in $requirements; do
193+
found_line=$(grep -E "^$requirement" $LIBS_DIR/esp32/sdkconfig)
194+
if [[ "$found_line" == "" ]]; then
195+
continue 2
196+
fi
197+
done
198+
fi
171199
fi
200+
172201
sketchnum=$(($sketchnum + 1))
173202
if [ "$sketchnum" -le "$start_index" ] \
174203
|| [ "$sketchnum" -gt "$end_index" ]; then

.github/scripts/sketch_utils.sh

+31-13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/bin/bash
22

3+
LIBS_DIR="tools/esp32-arduino-libs"
4+
35
function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [extra-options]
46
while [ ! -z "$1" ]; do
57
case "$1" in
@@ -140,16 +142,25 @@ function build_sketch(){ # build_sketch <ide_path> <user_path> <path-to-ino> [ex
140142

141143
sketchname=$(basename $sketchdir)
142144

143-
# If the target is listed as false, skip the sketch. Otherwise, include it.
144145
if [ -f $sketchdir/ci.json ]; then
146+
# If the target is listed as false, skip the sketch. Otherwise, include it.
145147
is_target=$(jq -r --arg target $target '.targets[$target]' $sketchdir/ci.json)
146-
else
147-
is_target="true"
148-
fi
148+
if [[ "$is_target" == "false" ]]; then
149+
echo "Skipping $sketchname for target $target"
150+
exit 0
151+
fi
149152

150-
if [[ "$is_target" == "false" ]]; then
151-
echo "Skipping $sketchname for target $target"
152-
exit 0
153+
# Check if the sketch requires any configuration options
154+
requirements=$(jq -r '.requires[]? // empty' $sketchdir/ci.json)
155+
if [[ "$requirements" != "null" ]] || [[ "$requirements" != "" ]]; then
156+
for requirement in $requirements; do
157+
found_line=$(grep -E "^$requirement" $LIBS_DIR/$target/sdkconfig)
158+
if [[ "$found_line" == "" ]]; then
159+
echo "Target $target does not meet the requirement $requirement for $sketchname. Skipping."
160+
exit 0
161+
fi
162+
done
163+
fi
153164
fi
154165

155166
ARDUINO_CACHE_DIR="$HOME/.arduino/cache.tmp"
@@ -288,16 +299,23 @@ function count_sketches(){ # count_sketches <path> [target] [file]
288299
local sketchname=$(basename $sketch)
289300
if [[ "$sketchdirname.ino" != "$sketchname" ]]; then
290301
continue
291-
elif [[ -n $target ]]; then
302+
elif [[ -n $target ]] && [[ -f $sketchdir/ci.json ]]; then
292303
# If the target is listed as false, skip the sketch. Otherwise, include it.
293-
if [ -f $sketchdir/ci.json ]; then
294-
is_target=$(jq -r --arg target $target '.targets[$target]' $sketchdir/ci.json)
295-
else
296-
is_target="true"
297-
fi
304+
is_target=$(jq -r --arg target $target '.targets[$target]' $sketchdir/ci.json)
298305
if [[ "$is_target" == "false" ]]; then
299306
continue
300307
fi
308+
309+
# Check if the sketch requires any configuration options
310+
requirements=$(jq -r '.requires[]? // empty' $sketchdir/ci.json)
311+
if [[ "$requirements" != "null" ]] || [[ "$requirements" != "" ]]; then
312+
for requirement in $requirements; do
313+
found_line=$(grep -E "^$requirement" $LIBS_DIR/$target/sdkconfig)
314+
if [[ "$found_line" == "" ]]; then
315+
continue 2
316+
fi
317+
done
318+
fi
301319
fi
302320
echo $sketch >> sketches.txt
303321
sketchnum=$(($sketchnum + 1))

.github/scripts/tests_run.sh

+20-9
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,29 @@ function run_test() {
1010
local result=0
1111
local error=0
1212

13-
# If the target or platform is listed as false, skip the sketch. Otherwise, include it.
1413
if [ -f $sketchdir/ci.json ]; then
14+
# If the target or platform is listed as false, skip the sketch. Otherwise, include it.
1515
is_target=$(jq -r --arg target $target '.targets[$target]' $sketchdir/ci.json)
1616
selected_platform=$(jq -r --arg platform $platform '.platforms[$platform]' $sketchdir/ci.json)
17-
else
18-
is_target="true"
19-
selected_platform="true"
20-
fi
2117

22-
if [[ $is_target == "false" ]] || [[ $selected_platform == "false" ]]; then
23-
printf "\033[93mSkipping $sketchname test for $target, platform: $platform\033[0m\n"
24-
printf "\n\n\n"
25-
return 0
18+
if [[ $is_target == "false" ]] || [[ $selected_platform == "false" ]]; then
19+
printf "\033[93mSkipping $sketchname test for $target, platform: $platform\033[0m\n"
20+
printf "\n\n\n"
21+
return 0
22+
fi
23+
24+
# Check if the sketch requires any configuration options
25+
requirements=$(jq -r '.requires[]? // empty' $sketchdir/ci.json)
26+
if [[ "$requirements" != "null" ]] || [[ "$requirements" != "" ]]; then
27+
for requirement in $requirements; do
28+
found_line=$(grep -E "^$requirement" $LIBS_DIR/$target/sdkconfig)
29+
if [[ "$found_line" == "" ]]; then
30+
printf "\033[93mTarget $target does not meet the requirement $requirement for $sketchname. Skipping.\033[0m\n"
31+
printf "\n\n\n"
32+
return 0
33+
fi
34+
done
35+
fi
2636
fi
2737

2838
if [ $options -eq 0 ] && [ -f $sketchdir/ci.json ]; then
@@ -110,6 +120,7 @@ function run_test() {
110120

111121
SCRIPTS_DIR="./.github/scripts"
112122
COUNT_SKETCHES="${SCRIPTS_DIR}/sketch_utils.sh count"
123+
LIBS_DIR="tools/esp32-arduino-libs"
113124

114125
platform="hardware"
115126
wokwi_timeout=60000

docs/en/contributing.rst

+41-11
Original file line numberDiff line numberDiff line change
@@ -109,17 +109,44 @@ Also:
109109
Testing
110110
*******
111111

112-
Be sure you have tested the example in all the supported targets. If the example works only with specific targets,
113-
edit/add the ``ci.json`` in the same folder as the sketch to specify the supported targets. By default,
114-
all targets are assumed to be supported.
112+
Be sure you have tested the example in all the supported targets. If the example some specific hardware requirements,
113+
edit/add the ``ci.json`` in the same folder as the sketch to specify the regular expression for the
114+
required configurations from ``sdkconfig``.
115+
This will ensure that the CI system will run the test only on the targets that have the required configurations.
115116

116-
Here is an example of the ``ci.json`` file where the example does not support ESP32-H2 and ESP32-S2:
117+
You can check the available configurations in the ``sdkconfig`` file in the ``tools/esp32-arduino-libs/<target>`` folder.
118+
119+
Here is an example of the ``ci.json`` file where the example requires Wi-Fi to work properly:
120+
121+
.. code-block:: json
122+
123+
{
124+
"requires": [
125+
"CONFIG_SOC_WIFI_SUPPORTED=y"
126+
]
127+
}
128+
129+
.. note::
130+
131+
The list of configurations will be checked against the ``sdkconfig`` file in the target folder. If the configuration is not present in the ``sdkconfig``,
132+
the test will be skipped for that target. That means that the test will only run on the targets that have **ALL** the required configurations.
133+
134+
Also, by default, the "match start of line" character (``^``) will be added to the beginning of each configuration.
135+
That means that the configuration must be at the beginning of the line in the ``sdkconfig`` file.
136+
137+
Sometimes, the example might not be supported by some target, even if the target has the required configurations
138+
(like resources limitations or requiring a specific SoC). To avoid compilation errors, you can add the target to the ``ci.json``
139+
file so the CI system will force to skip the test on that target.
140+
141+
Here is an example of the ``ci.json`` file where the example is requires Wi-Fi to work properly but is also not supported by the ESP32-S2 target:
117142

118143
.. code-block:: json
119144
120145
{
146+
"requires": [
147+
"CONFIG_SOC_WIFI_SUPPORTED=y"
148+
],
121149
"targets": {
122-
"esp32h2": false,
123150
"esp32s2": false
124151
}
125152
}
@@ -130,17 +157,17 @@ For example, in the sketch:
130157
.. code-block:: arduino
131158
132159
/*
133-
THIS FEATURE IS SUPPORTED ONLY BY ESP32-S2 AND ESP32-C3
160+
THIS FEATURE REQUIRES WI-FI SUPPORT AND IS NOT AVAILABLE FOR ESP32-S2 AS IT DOES NOT HAVE ENOUGH RAM.
134161
*/
135162
136163
And in the ``README.md`` file:
137164

138165
.. code-block:: markdown
139166
140-
Currently, this example supports the following targets.
167+
Currently, this example requires Wi-Fi and supports the following targets.
141168
142-
| Supported Targets | ESP32 | ESP32-S2 | ESP32-C3 | ESP32-S3 |
143-
| ----------------- | ----- | -------- | -------- | -------- |
169+
| Supported Targets | ESP32 | ESP32-H2 | ESP32-S3 | ESP32-C3 | ESP32-C6 |
170+
| ----------------- | ----- | -------- | -------- | -------- | -------- |
144171
145172
Example Template
146173
****************
@@ -341,8 +368,11 @@ CI JSON File
341368

342369
The ``ci.json`` file is used to specify how the test suite and sketches will handled by the CI system. It can contain the following fields:
343370

344-
* ``targets``: A dictionary that specifies the supported targets. The key is the target name and the value is a boolean that specifies if the
345-
target is supported. By default, all targets are assumed to be supported. This field is also valid for examples.
371+
* ``requires``: A list of configurations in ``sdkconfig`` that are required to run the test suite. The test suite will only run on the targets
372+
that have the required configurations. By default, no configurations are required.
373+
* ``targets``: A dictionary that specifies the targets for which the tests will be run. The key is the target name and the value is a boolean
374+
that specifies if the test should be run for that target. By default, all targets are enabled as long as they have the required configurations
375+
specified in the ``requires`` field. This field is also valid for examples.
346376
* ``platforms``: A dictionary that specifies the supported platforms. The key is the platform name and the value is a boolean that specifies if
347377
the platform is supported. By default, all platforms are assumed to be supported.
348378
* ``extra_tags``: A list of extra tags that the runner will require when running the test suite in hardware. By default, no extra tags are required.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"targets": {
3-
"esp32h2": false
4-
}
2+
"requires": [
3+
"CONFIG_SOC_WIFI_SUPPORTED=y"
4+
]
55
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"targets": {
3-
"esp32h2": false
4-
}
2+
"requires": [
3+
"CONFIG_SOC_WIFI_SUPPORTED=y"
4+
]
55
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"targets": {
3-
"esp32h2": false
4-
}
2+
"requires": [
3+
"CONFIG_SOC_WIFI_SUPPORTED=y"
4+
]
55
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"targets": {
3-
"esp32h2": false
4-
}
2+
"requires": [
3+
"CONFIG_SOC_WIFI_SUPPORTED=y"
4+
]
55
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
2-
"targets": {
3-
"esp32": false,
4-
"esp32s2": false
5-
}
2+
"requires": [
3+
"CONFIG_SOC_BLE_50_SUPPORTED=y"
4+
]
65
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
2-
"targets": {
3-
"esp32": false,
4-
"esp32s2": false
5-
}
2+
"requires": [
3+
"CONFIG_SOC_BLE_50_SUPPORTED=y"
4+
]
65
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
2-
"targets": {
3-
"esp32": false,
4-
"esp32s2": false
5-
}
2+
"requires": [
3+
"CONFIG_SOC_BLE_50_SUPPORTED=y"
4+
]
65
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
2-
"targets": {
3-
"esp32": false,
4-
"esp32s2": false
5-
}
2+
"requires": [
3+
"CONFIG_SOC_BLE_50_SUPPORTED=y"
4+
]
65
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"targets": {
3-
"esp32s2": false
4-
}
2+
"requires": [
3+
"CONFIG_SOC_BLE_SUPPORTED=y"
4+
]
55
}

libraries/BLE/examples/Client/ci.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"targets": {
3-
"esp32s2": false
4-
}
2+
"requires": [
3+
"CONFIG_SOC_BLE_SUPPORTED=y"
4+
]
55
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
2-
"targets": {
3-
"esp32h2": false,
4-
"esp32s2": false
5-
}
2+
"requires": [
3+
"CONFIG_SOC_BLE_SUPPORTED=y"
4+
]
65
}
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
{
2-
"targets": {
3-
"esp32h2": false,
4-
"esp32s2": false
5-
}
2+
"requires": [
3+
"CONFIG_SOC_BLE_SUPPORTED=y"
4+
]
65
}

libraries/BLE/examples/Notify/ci.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"targets": {
3-
"esp32s2": false
4-
}
2+
"requires": [
3+
"CONFIG_SOC_BLE_SUPPORTED=y"
4+
]
55
}

0 commit comments

Comments
 (0)