Skip to content

Commit 8a2e671

Browse files
committed
feat(esp_delta_ota): Added pytest for the delta OTA example
1. Added pytest for the delta OTA example
1 parent 05ca59e commit 8a2e671

File tree

8 files changed

+542
-4
lines changed

8 files changed

+542
-4
lines changed

.github/workflows/build_and_run_apps.yml

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,61 @@ jobs:
235235
run: |
236236
python3 .github/get_pytest_args.py --target=${{ matrix.runner.target }} -v 'build_info*.json' pytest-args.txt
237237
cat pytest-args.txt
238-
pytest --suppress-no-test-exit-code $(cat pytest-args.txt) --ignore-glob '*/managed_components/*' --ignore=.github --junit-xml=${{ env.TEST_RESULT_FILE }} --target=${{ matrix.runner.target }} -m ${{ matrix.runner.marker }} --build-dir=build_${{ matrix.runner.target }} ${{ matrix.runner.pytest_args }}
238+
pytest --suppress-no-test-exit-code $(cat pytest-args.txt) --ignore-glob '*/managed_components/*' --ignore=.github --ignore=esp_delta_ota/examples/https_delta_ota/pytest_https_delta_ota.py --junit-xml=${{ env.TEST_RESULT_FILE }} --target=${{ matrix.runner.target }} -m ${{ matrix.runner.marker }} --build-dir=build_${{ matrix.runner.target }} ${{ matrix.runner.pytest_args }}
239+
- name: Upload test results
240+
uses: actions/upload-artifact@v4
241+
if: always()
242+
with:
243+
name: ${{ env.TEST_RESULT_NAME }}
244+
path: ${{ env.TEST_RESULT_FILE }}
245+
246+
run-target-delta-ota:
247+
name: Run esp_delta_ota on ESP-IDF image
248+
if: github.repository_owner == 'espressif' && needs.prepare.outputs.build_only != '1'
249+
needs: [build]
250+
strategy:
251+
fail-fast: false
252+
matrix:
253+
idf_ver:
254+
- "release-v5.1"
255+
- "release-v5.2"
256+
- "release-v5.3"
257+
- "release-v5.4"
258+
- "release-v5.5"
259+
- "latest"
260+
runner:
261+
- runs-on: "ESP32-ETHERNET-KIT"
262+
marker: "ethernet"
263+
target: "esp32"
264+
runner-labels: [self-hosted, linux, docker, "ESP32-ETHERNET-KIT"]
265+
env:
266+
TEST_RESULT_NAME: test_results_delta_ota_${{ matrix.runner.target }}_${{ matrix.runner.marker }}_${{ matrix.idf_ver }}
267+
TEST_RESULT_FILE: test_results_delta_ota_${{ matrix.runner.target }}_${{ matrix.runner.marker }}_${{ matrix.idf_ver }}.xml
268+
runs-on: ${{ matrix.runner.runner-labels }}
269+
container:
270+
image: espressif/idf:${{ matrix.idf_ver }}
271+
options: --privileged # Privileged mode has access to serial ports
272+
steps:
273+
- uses: actions/checkout@v4
274+
- uses: actions/download-artifact@v4
275+
with:
276+
pattern: app_binaries_${{ matrix.idf_ver }}_*
277+
merge-multiple: true
278+
- name: Install dependencies
279+
shell: bash
280+
run: |
281+
export IDF_PYTHON_CHECK_CONSTRAINTS=yes
282+
${IDF_PATH}/install.sh --enable-ci
283+
. ${IDF_PATH}/export.sh
284+
pip install --prefer-binary cryptography pytest-embedded pytest-embedded-serial-esp pytest-embedded-idf pytest-custom_exit_code
285+
- name: Run esp_delta_ota tests
286+
shell: bash
287+
run: |
288+
. ${IDF_PATH}/export.sh
289+
python3 .github/get_pytest_args.py --target=${{ matrix.runner.target }} -v 'build_info*.json' pytest-args.txt
290+
cat pytest-args.txt
291+
# Use build_esp*_base directory for flashing (base binary), test will find both base and new binaries for patch generation
292+
pytest --suppress-no-test-exit-code $(cat pytest-args.txt) esp_delta_ota/examples/https_delta_ota/pytest_https_delta_ota.py --ignore-glob '*/managed_components/*' --ignore=.github --junit-xml=${{ env.TEST_RESULT_FILE }} --target=${{ matrix.runner.target }} -m ${{ matrix.runner.marker }} --build-dir=build_${{ matrix.runner.target }}_base
239293
- name: Upload test results
240294
uses: actions/upload-artifact@v4
241295
if: always()
@@ -308,6 +362,7 @@ jobs:
308362
name: Publish Test results
309363
needs:
310364
- run-target
365+
- run-target-delta-ota
311366
- run-target-linux
312367
if: github.repository_owner == 'espressif' && always() && github.event_name == 'pull_request' && needs.prepare.outputs.build_only == '0'
313368
runs-on: ubuntu-22.04
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# The following lines of boilerplate have to be in your project's CMakeLists
22
# in this exact order for cmake to work correctly
3-
cmake_minimum_required(VERSION 3.5)
3+
cmake_minimum_required(VERSION 3.16)
44

55
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
6-
set(COMPONENTS main)
6+
set(COMPONENTS main esp_eth)
77
project(https_delta_ota)
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
idf_component_register(SRCS "main.c"
22
INCLUDE_DIRS "."
33
EMBED_TXTFILES ca_cert.pem
4-
PRIV_REQUIRES esp_http_client esp_partition nvs_flash app_update esp_timer esp_wifi console)
4+
PRIV_REQUIRES esp_http_client esp_partition nvs_flash app_update esp_timer esp_wifi console esp_eth)

esp_delta_ota/examples/https_delta_ota/main/Kconfig.projbuild

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,15 @@ menu "Example Configuration"
2424
help
2525
Maximum time for reception
2626

27+
config EXAMPLE_FIRMWARE_UPG_URL_FROM_STDIN
28+
bool
29+
default y if EXAMPLE_FIRMWARE_UPG_URL = "FROM_STDIN"
30+
31+
config EXAMPLE_TEST_DELTA_OTA
32+
bool "Enable test delta OTA success message"
33+
default n
34+
help
35+
When enabled, app_main will log "OTA performed successfully" message.
36+
This is used for testing delta OTA functionality.
37+
2738
endmenu

esp_delta_ota/examples/https_delta_ota/main/main.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#define BUFFSIZE 1024
3737
#define PATCH_HEADER_SIZE 64
3838
#define DIGEST_SIZE 32
39+
#define OTA_URL_SIZE 256
3940
static uint32_t esp_delta_ota_magic = 0xfccdde10;
4041

4142
static const char *TAG = "https_delta_ota_example";
@@ -156,6 +157,20 @@ static void ota_example_task(void *pvParameter)
156157
config.skip_cert_common_name_check = true;
157158
#endif
158159

160+
#ifdef CONFIG_EXAMPLE_FIRMWARE_UPG_URL_FROM_STDIN
161+
char url_buf[OTA_URL_SIZE];
162+
if (strcmp(config.url, "FROM_STDIN") == 0) {
163+
example_configure_stdin_stdout();
164+
fgets(url_buf, OTA_URL_SIZE, stdin);
165+
int len = strlen(url_buf);
166+
url_buf[len - 1] = '\0';
167+
config.url = url_buf;
168+
} else {
169+
ESP_LOGE(TAG, "Configuration mismatch: wrong firmware upgrade image url");
170+
abort();
171+
}
172+
#endif
173+
159174
esp_http_client_handle_t client = esp_http_client_init(&config);
160175
if (client == NULL) {
161176
ESP_LOGE(TAG, "Failed to initialise HTTP connection");
@@ -262,6 +277,9 @@ static void ota_example_task(void *pvParameter)
262277

263278
void app_main(void)
264279
{
280+
#ifdef CONFIG_EXAMPLE_TEST_DELTA_OTA
281+
ESP_LOGI(TAG, "OTA performed successfully");
282+
#endif
265283
ESP_LOGI(TAG, "Initialising WiFi Connection...");
266284

267285
ESP_ERROR_CHECK(nvs_flash_init());

0 commit comments

Comments
 (0)