Skip to content

Commit 2953130

Browse files
authored
Introduce CI section, move tests section (#40)
1 parent 4f506a1 commit 2953130

File tree

6 files changed

+113
-92
lines changed

6 files changed

+113
-92
lines changed
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
# Component/platform test configurations
2+
3+
Each (new) component/platform must have tests. This enables our CI system to perform a test build of the
4+
component/platform to ensure it compiles without any errors.
5+
6+
Tests should incorporate the new component/platform itself as well as all
7+
[automations](https://esphome.io/automations/actions) it implements.
8+
9+
!!! note
10+
These are **compile tests only** and do not test functionality.
11+
12+
### Overview
13+
14+
The tests aim to test compilation of the code for each processor architecture:
15+
16+
- Xtensa (ESP8266, original ESP32 and S-series)
17+
- RISC-V (ESP32 C-series)
18+
- ARM (RP2040)
19+
20+
...and for each supported framework:
21+
22+
- Arduino
23+
- [ESP-IDF](https://github.com/espressif/esp-idf/)
24+
25+
There should be *at least one test* for each framework/architecture combination. We can probably go without saying it,
26+
but some framework/architecture combinations are simply not supported/possible, so tests for those are impossible and,
27+
as such, are (naturally) omitted.
28+
29+
### General structure
30+
31+
We try to structure the tests in a way so as to minimize repetition. Let's look at the `dht12` sensor platform as an
32+
example:
33+
34+
First, you'll find a `common.yaml` file which contains this:
35+
36+
```yaml
37+
i2c:
38+
- id: i2c_dht12
39+
scl: ${scl_pin}
40+
sda: ${sda_pin}
41+
42+
sensor:
43+
- platform: dht12
44+
temperature:
45+
name: DHT12 Temperature
46+
humidity:
47+
name: DHT12 Humidity
48+
update_interval: 15s
49+
```
50+
51+
It's a shared configuration file that defines common settings used across all hardware platforms. Having a "common"
52+
file like this minimizes duplication and ensures test consistency across all platforms.
53+
54+
To use `common.yaml` in a test configuration, YAML substitutions and the insertion operator are used (see
55+
[substitutions](https://esphome.io/components/substitutions)). This allows the test YAML file to reference and include
56+
the shared configuration. For the `dht12` platform, one of the test files is named `test.esp32-ard.yaml` and it contains
57+
this:
58+
59+
```yaml
60+
substitutions:
61+
scl_pin: GPIO16
62+
sda_pin: GPIO17
63+
64+
<<: !include common.yaml
65+
```
66+
67+
By including `common.yaml`, all test configurations maintain the same structure while allowing flexibility for
68+
platform-specific substitutions such as pin assignments. This approach simplifies managing multiple test cases across
69+
different hardware platforms.
70+
71+
### Which tests do I need?
72+
73+
**We require a test for each framework/architecture combination** the component/platform supports. *Most*
74+
components/platforms include the following test files:
75+
76+
- `test.esp32-ard.yaml` - ESP32 (Xtensa)/Arduino
77+
- `test.esp32-idf.yaml` - ESP32 (Xtensa)/IDF
78+
- `test.esp32-c3-ard.yaml` - ESP32-C3 (RISC-V)/Arduino
79+
- `test.esp32-c3-idf.yaml` - ESP32-C3 (RISC-V)/IDF
80+
- `test.esp8266-ard.yaml` - ESP8266 (Xtensa)/Arduino
81+
- `test.rp2040-ard.yaml` - RP2040 (ARM)/Arduino
82+
83+
Because our test script checks for **successful compilation only**, it is not necessary to include a test for every
84+
microcontroller variant _unless different code is compiled based on the variant._ For example, the ESP32, ESP32-S2
85+
and ESP32-S3 are all based on the same Xtensa architecture and, as such, use the same tooling and configuration. Given
86+
a block of code, if it compiles for the ESP32, it will compile for the S2 and S3, as well. Therefore, spinning up a new
87+
test run for each variant within this family is not productive and we avoid doing so to minimize CI runtime.
88+
89+
If your component/platform builds different code based on the variant (for example, ESP32/S2/S3 or C3/C6), then tests
90+
should be added to/omitted from the list above as appropriate. This is often only necessary when implementing support
91+
for some specific hardware component built into the microcontroller. The
92+
[ADC](https://esphome.io/components/sensor/adc) is one example of this.
93+
94+
### Running the tests
95+
96+
You can run the tests locally simply by invoking the test script:
97+
98+
```shell
99+
script/test_build_components -e compile -c dht12
100+
```
101+
102+
Our CI will also run this script when you create or update your pull request (PR).

docs/architecture/ci/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Continuous Integration (CI)
2+
3+
ESPHome uses [GitHub Actions (GHA)](https://github.com/esphome/esphome/actions) for all continuous integration (CI).

docs/architecture/overview.md

Lines changed: 3 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -172,95 +172,7 @@ latest data from your component and publish them with the provided methods.
172172

173173
Finally, your component must have a `dump_config` method that prints the complete user configuration.
174174

175-
## Test configurations
175+
## Further reading
176176

177-
Each (new) component/platform must have tests. This enables our CI system to perform a test build of the
178-
component/platform to ensure it compiles without any errors. The test file(s) should incorporate the new
179-
component/platform itself as well as all [automations](https://esphome.io/automations/actions) it implements.
180-
181-
### Overview
182-
183-
The tests aim to test compilation of the code for each processor architecture:
184-
185-
- Xtensa (ESP8266, original ESP32 and S-series)
186-
- RISC-V (ESP32 C-series)
187-
- ARM (RP2040)
188-
189-
...and for each supported framework:
190-
191-
- Arduino
192-
- [ESP-IDF](https://github.com/espressif/esp-idf/)
193-
194-
There should be *at least one test* for each framework/architecture combination. We can probably go without saying it,
195-
but some framework/architecture combinations are simply not supported/possible, so tests for those are impossible and,
196-
as such, are (naturally) omitted.
197-
198-
### General structure
199-
200-
We try to structure the tests in a way so as to minimize repetition. Let's look at the `dht12` sensor platform as an
201-
example:
202-
203-
First, you'll find a `common.yaml` file which contains this:
204-
205-
```yaml
206-
i2c:
207-
- id: i2c_dht12
208-
scl: ${scl_pin}
209-
sda: ${sda_pin}
210-
211-
sensor:
212-
- platform: dht12
213-
temperature:
214-
name: DHT12 Temperature
215-
humidity:
216-
name: DHT12 Humidity
217-
update_interval: 15s
218-
```
219-
220-
It's a shared configuration file that defines common settings used across all hardware platforms. Having a "common"
221-
file like this minimizes duplication and ensures test consistency across all platforms.
222-
223-
To use `common.yaml` in a test configuration, YAML substitutions and the insertion operator are used (see
224-
[substitutions](https://esphome.io/components/substitutions)). This allows the test YAML file to reference and include
225-
the shared configuration. For the `dht12` platform, one of the test files is named `test.esp32-ard.yaml` and it contains
226-
this:
227-
228-
```yaml
229-
substitutions:
230-
scl_pin: GPIO16
231-
sda_pin: GPIO17
232-
233-
<<: !include common.yaml
234-
```
235-
236-
By including `common.yaml`, all test configurations maintain the same structure while allowing flexibility for
237-
platform-specific substitutions such as pin assignments. This approach simplifies managing multiple test cases across
238-
different hardware platforms.
239-
240-
### Which tests do I need?
241-
242-
We require a test for each framework/architecture combination the component/platform supports. *Most*
243-
components/platforms include the following test files:
244-
245-
- `test.esp32-ard.yaml` - ESP32 (Xtensa)/Arduino
246-
- `test.esp32-idf.yaml` - ESP32 (Xtensa)/IDF
247-
- `test.esp32-c3-ard.yaml` - ESP32-C3 (RISC-V)/Arduino
248-
- `test.esp32-c3-idf.yaml` - ESP32-C3 (RISC-V)/IDF
249-
- `test.esp32-s3-ard.yaml` - ESP32-S3 (Xtensa)/Arduino
250-
- `test.esp32-s3-idf.yaml` - ESP32-S3 (Xtensa)/IDF
251-
- `test.esp8266-ard.yaml` - ESP8266 (Xtensa)/Arduino
252-
- `test.rp2040-ard.yaml` - RP2040 (ARM)/Arduino
253-
254-
In cases where the component/platform implements support for some microcontroller-specific hardware component, tests
255-
should be added to/omitted from the list above as appropriate. The [ADC](https://esphome.io/components/sensor/adc) is
256-
one example of this.
257-
258-
### Running the tests
259-
260-
You can run the tests locally simply by invoking the test script:
261-
262-
```shell
263-
script/test_build_components -e compile -c dht12
264-
```
265-
266-
Our CI will also run this script when you create or update your pull request (PR).
177+
If you are preparing your code for [integration into ESPHome](/contributing/submitting-your-work), you'll need to
178+
create tests; please see [test configurations](/architecture/ci/component_tests) for more detail.

docs/contributing/development-environment.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ This guide will walk you through the steps to set up an environment you can use
1212

1313
## Requirements
1414

15-
- Python 3.12 or newer
15+
- Python 3.10 or newer
1616
- `pip` (Python package manager)
1717
- Familiarity with `git` and GitHub
1818

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ All project code and documentation is hosted on [GitHub](https://github.com):
2828

2929
- [Component architecture](architecture/components)
3030
- [API](architecture/api)
31+
- [CI](architecture/ci)
3132

3233
## Contributing
3334

mkdocs.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,4 +85,7 @@ nav:
8585
- Overview: architecture/api/index.md
8686
- Protocol Details: architecture/api/protocol_details.md
8787
- Logging Best Practices: architecture/logging.md
88+
- CI:
89+
- Overview: architecture/ci/index.md
90+
- Tests: architecture/ci/component_tests.md
8891
- Blog: blog/index.md

0 commit comments

Comments
 (0)