Skip to content

Commit

Permalink
test_apps: Test multicore app can be run by unicore bootloader
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstantinKondrashov committed Mar 28, 2023
1 parent 975c138 commit 444c27e
Show file tree
Hide file tree
Showing 10 changed files with 122 additions and 0 deletions.
5 changes: 5 additions & 0 deletions tools/test_apps/.build-test-rules.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
6 changes: 6 additions & 0 deletions tools/test_apps/system/unicore_bootloader/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions tools/test_apps/system/unicore_bootloader/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
| Supported Targets | ESP32 | ESP32-S3 |
| ----------------- | ----- | -------- |
4 changes: 4 additions & 0 deletions tools/test_apps/system/unicore_bootloader/README.txt
Original file line number Diff line number Diff line change
@@ -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.
52 changes: 52 additions & 0 deletions tools/test_apps/system/unicore_bootloader/conftest.py
Original file line number Diff line number Diff line change
@@ -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)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
idf_component_register(SRCS "main.c")
12 changes: 12 additions & 0 deletions tools/test_apps/system/unicore_bootloader/main/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* SPDX-FileCopyrightText: 2023 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <stdio.h>

void app_main(void)
{
printf("App is running\n");
}
Original file line number Diff line number Diff line change
@@ -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')
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CONFIG_FREERTOS_UNICORE=y

0 comments on commit 444c27e

Please sign in to comment.