diff --git a/tools/test_apps/.build-test-rules.yml b/tools/test_apps/.build-test-rules.yml index 304bd93afc..d1101602d1 100644 --- a/tools/test_apps/.build-test-rules.yml +++ b/tools/test_apps/.build-test-rules.yml @@ -182,3 +182,8 @@ tools/test_apps/system/startup: tools/test_apps/system/test_watchpoint: enable: - if: IDF_TARGET in ["esp32", "esp32c3"] # Just one test per architecture + +tools/test_apps/system/unicore_bootloader: + enable: + - if: SOC_CPU_CORES_NUM > 1 + reason: the test should be run on multicore chips diff --git a/tools/test_apps/system/unicore_bootloader/CMakeLists.txt b/tools/test_apps/system/unicore_bootloader/CMakeLists.txt new file mode 100644 index 0000000000..7031a76198 --- /dev/null +++ b/tools/test_apps/system/unicore_bootloader/CMakeLists.txt @@ -0,0 +1,6 @@ +# The following lines of boilerplate have to be in your project's +# CMakeLists in this exact order for cmake to work correctly +cmake_minimum_required(VERSION 3.16) + +include($ENV{IDF_PATH}/tools/cmake/project.cmake) +project(test_unicore_bootloader) diff --git a/tools/test_apps/system/unicore_bootloader/README.md b/tools/test_apps/system/unicore_bootloader/README.md new file mode 100644 index 0000000000..5ab630aafd --- /dev/null +++ b/tools/test_apps/system/unicore_bootloader/README.md @@ -0,0 +1,2 @@ +| Supported Targets | ESP32 | ESP32-S3 | +| ----------------- | ----- | -------- | diff --git a/tools/test_apps/system/unicore_bootloader/README.txt b/tools/test_apps/system/unicore_bootloader/README.txt new file mode 100644 index 0000000000..875b2c9400 --- /dev/null +++ b/tools/test_apps/system/unicore_bootloader/README.txt @@ -0,0 +1,4 @@ +This project tests if the app can start up in a certain configuration. +Multicore app can start up even if the bootloader is unicore. + +The test is only for Multicore chips. diff --git a/tools/test_apps/system/unicore_bootloader/conftest.py b/tools/test_apps/system/unicore_bootloader/conftest.py new file mode 100644 index 0000000000..72c33c8687 --- /dev/null +++ b/tools/test_apps/system/unicore_bootloader/conftest.py @@ -0,0 +1,52 @@ +# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 + +import logging +import os + +import pytest +from _pytest.fixtures import FixtureRequest +from _pytest.monkeypatch import MonkeyPatch +from pytest_embedded_idf.app import FlashFile +from pytest_embedded_idf.serial import IdfSerial + + +# This is a custom IdfSerial class to support custom functionality +# which is required only for this test +class FlashBootloader(IdfSerial): + def bootloader_flash(self, binary_path: str) -> None: + """ + Flash bootloader. + + :return: None + """ + logging.info('Flashing bootloader') + bootloader_path = os.path.join(binary_path, 'bootloader', 'bootloader.bin') + logging.info(bootloader_path) + offs = int(self.app.sdkconfig.get('BOOTLOADER_OFFSET_IN_FLASH', 0)) + logging.info('bootloader offset is {0}'.format(hex(offs))) + prev_flash_files = self.app.flash_files + flash_files = [] + flash_files.append( + FlashFile( + offs, + bootloader_path, + False, + ) + ) + self.app.flash_files = flash_files + self.flash() + # Restore self.app.flash files to original value + self.app.flash_files = prev_flash_files + + +@pytest.fixture(scope='module') +def monkeypatch_module(request: FixtureRequest) -> MonkeyPatch: + mp = MonkeyPatch() + request.addfinalizer(mp.undo) + return mp + + +@pytest.fixture(scope='module', autouse=True) +def replace_dut_class(monkeypatch_module: MonkeyPatch) -> None: + monkeypatch_module.setattr('pytest_embedded_idf.IdfSerial', FlashBootloader) diff --git a/tools/test_apps/system/unicore_bootloader/main/CMakeLists.txt b/tools/test_apps/system/unicore_bootloader/main/CMakeLists.txt new file mode 100644 index 0000000000..34613e8e3c --- /dev/null +++ b/tools/test_apps/system/unicore_bootloader/main/CMakeLists.txt @@ -0,0 +1 @@ +idf_component_register(SRCS "main.c") diff --git a/tools/test_apps/system/unicore_bootloader/main/main.c b/tools/test_apps/system/unicore_bootloader/main/main.c new file mode 100644 index 0000000000..50c39ad016 --- /dev/null +++ b/tools/test_apps/system/unicore_bootloader/main/main.c @@ -0,0 +1,12 @@ +/* + * SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +void app_main(void) +{ + printf("App is running\n"); +} diff --git a/tools/test_apps/system/unicore_bootloader/pytest_unicore_bootloader.py b/tools/test_apps/system/unicore_bootloader/pytest_unicore_bootloader.py new file mode 100644 index 0000000000..4d8f31888c --- /dev/null +++ b/tools/test_apps/system/unicore_bootloader/pytest_unicore_bootloader.py @@ -0,0 +1,39 @@ +# SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: CC0-1.0 + +import os + +import pytest +from pytest_embedded import Dut + + +@pytest.mark.esp32 +@pytest.mark.esp32s3 +@pytest.mark.generic +@pytest.mark.parametrize('config', ['multicore'], indirect=True) +def test_multicore_app_and_unicore_bootloader(dut: Dut) -> None: + dut.expect('Multicore bootloader') + dut.expect('Multicore app') + dut.expect('App is running') + + path_to_unicore_build = os.path.join(dut.app.app_path, f'build_{dut.target}_unicore') + dut.serial.bootloader_flash(path_to_unicore_build) + dut.expect('Unicore bootloader') + dut.expect('Multicore app') + dut.expect('App is running') + + +@pytest.mark.esp32 +@pytest.mark.esp32s3 +@pytest.mark.generic +@pytest.mark.parametrize('config', ['unicore'], indirect=True) +def test_unicore_app_and_multicore_bootloader(dut: Dut) -> None: + dut.expect('Unicore bootloader') + dut.expect('Unicore app') + dut.expect('App is running') + + path_to_unicore_build = os.path.join(dut.app.app_path, f'build_{dut.target}_multicore') + dut.serial.bootloader_flash(path_to_unicore_build) + dut.expect('Multicore bootloader') + dut.expect('Unicore app') + dut.expect('App is running') diff --git a/tools/test_apps/system/unicore_bootloader/sdkconfig.ci.multicore b/tools/test_apps/system/unicore_bootloader/sdkconfig.ci.multicore new file mode 100644 index 0000000000..e69de29bb2 diff --git a/tools/test_apps/system/unicore_bootloader/sdkconfig.ci.unicore b/tools/test_apps/system/unicore_bootloader/sdkconfig.ci.unicore new file mode 100644 index 0000000000..f0b0b5e03d --- /dev/null +++ b/tools/test_apps/system/unicore_bootloader/sdkconfig.ci.unicore @@ -0,0 +1 @@ +CONFIG_FREERTOS_UNICORE=y