You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docs(contrib): Add instructions on how to test changes (#10221)
* docs(contrib): Add instructions on how to test changes
* fix(path): Fix file path
* Remove manual hooks as they do not exist anymore in the repo
* Fix typo
Copy file name to clipboardExpand all lines: docs/en/contributing.rst
+288-22
Original file line number
Diff line number
Diff line change
@@ -15,7 +15,8 @@ Before Contributing
15
15
16
16
Before sending us a Pull Request, please consider this:
17
17
18
-
* Is the contribution entirely your own work, or is it already licensed under an LGPL 2.1 compatible Open Source License? If not, cannot accept it.
18
+
* Is the contribution entirely your own work, or is it already licensed under an LGPL 2.1 compatible Open Source License?
19
+
If not, cannot accept it.
19
20
20
21
* Is the code adequately commented and can people understand how it is structured?
21
22
@@ -25,9 +26,10 @@ Before sending us a Pull Request, please consider this:
25
26
26
27
* Example contributions are also welcome.
27
28
28
-
* If you are contributing by adding a new example, please use the `Arduino style guide`_and the example guideline below.
29
+
* If you are contributing by adding a new example, please use the `Arduino style guide`_and the example guideline below.
29
30
30
-
* If the contribution contains multiple commits, are they grouped together into logical changes (one major change per pull request)? Are any commits with names like "fixed typo" `squashed into previous commits <https://eli.thegreenplace.net/2014/02/19/squashing-github-pull-requests-into-a-single-commit/>`_?
31
+
* If the contribution contains multiple commits, are they grouped together into logical changes (one major change per pull request)?
32
+
Are any commits with names like "fixed typo" `squashed into previous commits <https://eli.thegreenplace.net/2014/02/19/squashing-github-pull-requests-into-a-single-commit/>`_?
31
33
32
34
If you're unsure about any of these points, please open the Pull Request anyhow and then ask us for feedback.
33
35
@@ -49,20 +51,22 @@ Checklist
49
51
* Check if your example proposal has no similarities to the project (**already existing examples**)
50
52
* Use the `Arduino style guide`_
51
53
* Add the header to all source files
52
-
* Add the `README.md`file
54
+
* Add the ``README.md`` file
53
55
* Add inline comments if needed
54
56
* Test the example
55
57
56
58
Header
57
59
******
58
60
59
-
All the source files must include the header with the example name and license, if applicable. You can change this header as you wish, but it will be reviewed by the community and may not be accepted.
61
+
All the source files must include the header with the example name and license, if applicable. You can change this header as you wish,
62
+
but it will be reviewed by the community and may not be accepted.
60
63
61
-
Ideally, you can add some description about the example, links to the documentation, or the author's name. Just have in mind to keep it simple and short.
64
+
Ideally, you can add some description about the example, links to the documentation, or the author's name.
65
+
Just have in mind to keep it simple and short.
62
66
63
67
**Header Example**
64
68
65
-
.. code-block::arduino
69
+
.. code-block::arduino
66
70
67
71
/* Wi-Fi FTM Initiator Arduino Example
68
72
@@ -77,9 +81,9 @@ Ideally, you can add some description about the example, links to the documentat
77
81
README file
78
82
***********
79
83
80
-
The **README.md** file should contain the example details.
84
+
The ``README.md`` file should contain the example details.
81
85
82
-
Please see the recommended **README.md** file in the `example template folder <https://github.com/espressif/arduino-esp32/tree/master/libraries/ESP32/examples/Template/ExampleTemplate>`_.
86
+
Please see the recommended ``README.md`` file in the `example template folder <https://github.com/espressif/arduino-esp32/tree/master/libraries/ESP32/examples/Template/ExampleTemplate>`_.
83
87
84
88
Inline Comments
85
89
***************
@@ -88,37 +92,50 @@ Inline comments are important if the example contains complex algorithms or spec
88
92
89
93
Brief and clear inline comments are really helpful for the example understanding and it's fast usage.
90
94
91
-
**Example**
95
+
See the `FTM example <https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/FTM/FTM_Initiator/FTM_Initiator.ino>`_
96
+
as a reference:
92
97
93
-
See the `FTM example <https://github.com/espressif/arduino-esp32/blob/master/libraries/WiFi/examples/FTM/FTM_Initiator/FTM_Initiator.ino>`_ as a reference.
94
-
95
-
.. code-block:: arduino
98
+
.. code-block:: arduino
96
99
97
100
// Number of FTM frames requested in terms of 4 or 8 bursts (allowed values - 0 (No pref), 16, 24, 32, 64)
98
101
99
-
and
102
+
Also:
100
103
101
-
.. code-block::arduino
104
+
.. code-block::arduino
102
105
103
106
const char * WIFI_FTM_SSID = "WiFi_FTM_Responder"; // SSID of AP that has FTM Enabled
104
107
const char * WIFI_FTM_PASS = "ftm_responder"; // STA Password
105
108
106
109
Testing
107
110
*******
108
111
109
-
Be sure you have tested the example in all the supported targets. If the example works only with specific targets, add this information in the **README.md** file on the **Supported Targets** and in the example code as an inline comment.
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.
115
+
116
+
Here is an example of the ``ci.json`` file where the example does not support ESP32-H2 and ESP32-S2:
117
+
118
+
.. code-block:: json
110
119
111
-
**Example**
120
+
{
121
+
"targets": {
122
+
"esp32h2": false,
123
+
"esp32s2": false
124
+
}
125
+
}
112
126
113
-
.. code-block:: arduino
127
+
You also need to add this information in the ``README.md`` file, on the **Supported Targets**, and in the example code as an inline comment.
128
+
For example, in the sketch:
129
+
130
+
.. code-block:: arduino
114
131
115
132
/*
116
133
THIS FEATURE IS SUPPORTED ONLY BY ESP32-S2 AND ESP32-C3
117
134
*/
118
135
119
-
and
136
+
And in the ``README.md`` file:
120
137
121
-
.. code-block::markdown
138
+
.. code-block::markdown
122
139
123
140
Currently, this example supports the following targets.
124
141
@@ -128,11 +145,260 @@ and
128
145
Example Template
129
146
****************
130
147
131
-
The example template can be found `here <https://github.com/espressif/arduino-esp32/tree/master/libraries/ESP32/examples/Template/ExampleTemplate>`_ and can be used as a reference.
148
+
The example template can be found `here <https://github.com/espressif/arduino-esp32/tree/master/libraries/ESP32/examples/Template/ExampleTemplate>`_
149
+
and can be used as a reference.
150
+
151
+
Documentation
152
+
-------------
153
+
154
+
If you are contributing to the documentation, please follow the instructions described in the
155
+
`documentation guidelines <guides/docs_contributing>`_ to properly format and test your changes.
156
+
157
+
Testing and CI
158
+
--------------
159
+
160
+
After you have made your changes, you should test them. You can do this in different ways depending on the type of change you have made.
161
+
162
+
Examples
163
+
********
164
+
165
+
The easiest way to test an example is to load it into the Arduino IDE and run it on your board. If you have multiple boards,
166
+
you should test it on all of them to ensure that the example works on all supported targets.
167
+
168
+
You can refer to the `Example Contribution Guideline`_ section for more information on how to write and test examples.
169
+
170
+
Library Changes
171
+
***************
172
+
173
+
If you have made changes to a library, you should test it on all supported targets. You can do this by loading the library examples (or creating new ones)
174
+
into the Arduino IDE and running them on your board. If you have multiple boards, you should test it on all of them to ensure that the library
175
+
works as expected on all targets.
176
+
177
+
You can also add a new test suite to automatically check the library. You can refer to the `Adding a New Test Suite`_ section for more information.
178
+
179
+
Core Changes
180
+
************
181
+
182
+
If you have made changes to the core, it is important to ensure that the changes do not break the existing functionality. You can do this by running the
183
+
tests on all supported targets. You can refer to the `Runtime Tests`_ section for more information.
184
+
185
+
CI
186
+
**
187
+
188
+
In our repository, we have a Continuous Integration (CI) system that runs tests and fixes on every Pull Request. This system will run the tests
189
+
on all supported targets and check if everything is working as expected.
190
+
191
+
We have many types of tests and checks, including:
192
+
193
+
* Compilation tests;
194
+
* Runtime tests;
195
+
* Documentation checks;
196
+
* Code style checks;
197
+
* And more.
198
+
199
+
Let's go deeper into each type of test in the CI system:
200
+
201
+
Compilation Tests
202
+
^^^^^^^^^^^^^^^^^
203
+
204
+
The compilation tests are the first type of tests in the CI system. They check if the code compiles on all supported targets.
205
+
If the code does not compile, the CI system will fail the test and the Pull Request will not be merged.
206
+
This is important to ensure that the code is compatible with all supported targets and no broken code is merged.
207
+
208
+
It will go through all the sketches in the repository and check if they compile on all supported targets. This process is automated and controlled
209
+
by GitHub Actions. The CI system will run the ``arduino-cli`` tool to compile the sketches on all supported targets.
210
+
211
+
Testing it locally using the CI scripts would be too time consuming, so we recommend running the tests locally using the Arduino IDE with
212
+
a sketch that uses the changes you made (you can also add the sketch as an example if your change is not covered by the existing ones).
213
+
Make sure to set ``Compiler Warnings`` to ``All`` in the Arduino IDE to catch any potential issues.
214
+
215
+
Runtime Tests
216
+
^^^^^^^^^^^^^
217
+
218
+
Another type of test is the runtime tests. They check if the code runs and behaves as expected on all supported targets. If the
219
+
code does not run as expected, the CI system will fail the test and the Pull Request will not be merged. This is important to ensure that the code
220
+
works as expected on all supported targets and no unintended crashes or bugs are introduced.
221
+
222
+
These tests are specialized sketches that run on the target board and check if the code behaves as expected. This process is automated and
223
+
controlled by the ``pytest_embedded`` tool. You can read more about this tool in its
=============================================================================================== test session starts ================================================================================================
277
+
platform darwin -- Python 3.12.3, pytest-8.2.2, pluggy-1.5.0
-------------------------------------------------------------------------------------------------- live log setup --------------------------------------------------------------------------------------------------
285
+
2024-08-22 11:49:30 INFO Target: esp32c3, Port: /dev/cu.usbserial-2120
286
+
PASSED [100%]
287
+
------------------------------------------------------------------------------------------------ live log teardown -------------------------------------------------------------------------------------------------
288
+
2024-08-22 11:49:52 INFO Created unity output junit report: /private/var/folders/vp/g9wctsvn7b91k3pv_7cwpt_h0000gn/T/pytest-embedded/2024-08-22_14-49-30-392993/test_uart/dut.xml
289
+
290
+
291
+
---------------------------------------------- generated xml file: /Users/lucassvaz/Espressif/Arduino/hardware/espressif/esp32/tests/validation/uart/esp32c3/uart.xml ----------------------------------------------
292
+
======================================================================================== 1 passed, 14 deselected in 22.18s =========================================================================================
293
+
294
+
After the test is finished, you can check the output in the terminal and the generated XML file in the test folder.
295
+
Additionally, for performance tests, you can check the generated JSON file in the same folder.
296
+
297
+
You can also run the tests in `Wokwi <https://docs.wokwi.com/>`_ or `Espressif's QEMU <https://github.com/espressif/esp-toolchain-docs/tree/main/qemu>`_
298
+
by using the ``-W <timeout_in_ms>`` and ``-Q`` flags respectively. You will need to have the Wokwi and/or QEMU installed in your system
299
+
and set the ``WOKWI_CLI_TOKEN`` and/or ``QEMU_PATH`` environment variables. The ``WOKWI_CLI_TOKEN`` is the CI token that can be obtained from the
300
+
`Wokwi website <https://wokwi.com/dashboard/ci>`_ and the ``QEMU_PATH`` is the path to the QEMU binary.
301
+
302
+
For example, to run the ``uart`` test using Wokwi, you would run:
Not all tests are supported by Wokwi and QEMU. QEMU is only supported for ESP32 and ESP32-C3 targets.
317
+
Wokwi support depends on the `currently implemented peripherals <https://docs.wokwi.com/guides/esp32#simulation-features>`_.
318
+
319
+
Adding a New Test Suite
320
+
#######################
321
+
322
+
If you want to add a new test suite, you can create a new folder inside ``tests/validation`` or ``tests/performance`` with the name of the test suite.
323
+
You can use the ``hello_world`` test suite as a starting point and the other test suites as a reference.
324
+
325
+
A test suite contains the following files:
326
+
327
+
* ``test_<test_name>.py``: The test file that contains the test cases. Required.
328
+
* ``<test_name>.ino``: The sketch that will be tested. Required.
329
+
* ``ci.json``: The file that specifies how the test suite will be run in the CI system. Optional.
330
+
* ``diagram.<target>.json``: The diagram file that specifies the connections between the components in Wokwi. Optional.
331
+
* ``scenario.yaml``: The scenario file that specifies how Wokwi will interact with the components. Optional.
332
+
* Any other files that are needed for the test suite.
333
+
334
+
You can read more about the test python API in the `pytest-embedded documentation <https://docs.espressif.com/projects/pytest-embedded/en/latest/usages/expecting.html>`_.
335
+
For more information about the Unity testing framework, you can check the `Unity documentation <https://github.com/ThrowTheSwitch/Unity>`_.
336
+
337
+
After creating the test suite, make sure to test it locally and run it in the CI system to ensure that it works as expected.
338
+
339
+
CI JSON File
340
+
############
341
+
342
+
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:
343
+
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.
346
+
* ``platforms``: A dictionary that specifies the supported platforms. The key is the platform name and the value is a boolean that specifies if
347
+
the platform is supported. By default, all platforms are assumed to be supported.
348
+
* ``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.
349
+
* ``fqbn``: A dictionary that specifies the FQBNs that will be used to compile the sketch. The key is the target name and the value is a list
350
+
of FQBNs. The `default FQBNs <https://github.com/espressif/arduino-esp32/blob/a31a5fca1739993173caba995f7785b8eed6b30e/.github/scripts/sketch_utils.sh#L86-L91>`_
351
+
are used if this field is not specified.
352
+
353
+
The ``wifi`` test suite is a good example of how to use the ``ci.json`` file:
Then, you can run the pre-commit hooks staging your changes and running:
380
+
381
+
.. code-block:: bash
382
+
383
+
pre-commit run
384
+
385
+
To run a specific hook, you can use the hook name as an argument. For example, to run the ``codespell`` hook, you would run:
386
+
387
+
.. code-block:: bash
388
+
389
+
pre-commit run codespell
390
+
391
+
If you want to run the pre-commit hooks automatically against the changed files on every ``git commit``,
392
+
you can install the pre-commit hooks by running:
393
+
394
+
.. code-block:: bash
395
+
396
+
pre-commit install
132
397
133
398
Legal Part
134
399
----------
135
400
136
-
Before a contribution can be accepted, you will need to sign our contributor agreement. You will be prompted for this automatically as part of the Pull Request process.
401
+
Before a contribution can be accepted, you will need to sign our contributor agreement. You will be prompted for this automatically as part of
0 commit comments