From 772d32fd778fb289e6368230c9456d918ada9b22 Mon Sep 17 00:00:00 2001 From: wuzhenghui Date: Sun, 29 Jan 2023 11:15:07 +0800 Subject: [PATCH] ci: add ci workaround for gdb_loadable_elf since flash config parameters are no longer generated when APP_BUILD_TYPE_RAM is enabled, this will cause load_ram in pytest_embedded_idf to fail --- .../system/gdb_loadable_elf/conftest.py | 22 ++++++++ .../loadable_app_serial.py | 53 +++++++++++++++++++ 2 files changed, 75 insertions(+) create mode 100644 tools/test_apps/system/gdb_loadable_elf/conftest.py create mode 100644 tools/test_apps/system/gdb_loadable_elf/test_gdb_loadable_elf_util/loadable_app_serial.py diff --git a/tools/test_apps/system/gdb_loadable_elf/conftest.py b/tools/test_apps/system/gdb_loadable_elf/conftest.py new file mode 100644 index 0000000000..6cf51977a3 --- /dev/null +++ b/tools/test_apps/system/gdb_loadable_elf/conftest.py @@ -0,0 +1,22 @@ +# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Apache-2.0 + +# pylint: disable=W0621 # redefined-outer-name + +import pytest +from _pytest.fixtures import FixtureRequest +from _pytest.monkeypatch import MonkeyPatch +from test_gdb_loadable_elf_util.loadable_app_serial import LoadableAppSerial + + +@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.serial.IdfSerial', LoadableAppSerial) + monkeypatch_module.setattr('pytest_embedded_idf.IdfSerial', LoadableAppSerial) diff --git a/tools/test_apps/system/gdb_loadable_elf/test_gdb_loadable_elf_util/loadable_app_serial.py b/tools/test_apps/system/gdb_loadable_elf/test_gdb_loadable_elf_util/loadable_app_serial.py new file mode 100644 index 0000000000..2d38453fbe --- /dev/null +++ b/tools/test_apps/system/gdb_loadable_elf/test_gdb_loadable_elf_util/loadable_app_serial.py @@ -0,0 +1,53 @@ +# SPDX-FileCopyrightText: 2022-2023 Espressif Systems (Shanghai) CO LTD +# SPDX-License-Identifier: Unlicense OR CC0-1.0 +import logging +from typing import Any, Optional + +import esptool +from pytest_embedded_idf.app import IdfApp +from pytest_embedded_serial_esp.serial import EspSerial, EsptoolArgs + + +class LoadableAppSerial(EspSerial): + def __init__( + self, + app: IdfApp, + target: Optional[str] = None, + **kwargs: Any, + ) -> None: + self.app = app + + if not hasattr(self.app, 'target'): + raise ValueError(f'Idf app not parsable. Please check if it\'s valid: {self.app.binary_path}') + + if target and self.app.target and self.app.target != target: + raise ValueError(f'Targets do not match. App target: {self.app.target}, Cmd target: {target}.') + + super().__init__( + target=target or app.target, + **kwargs, + ) + + def _start(self) -> None: + self.load_ram() + + @EspSerial.use_esptool(hard_reset_after=False, no_stub=True) + def load_ram(self) -> None: + if not self.app.bin_file: + logging.error('No image file detected. Skipping load ram...') + return + + f_bin_file = open(self.app.bin_file, 'rb') + + default_kwargs = { + 'filename': f_bin_file, + 'chip': self.esp.CHIP_NAME.lower().replace('-', ''), + } + + load_ram_args = EsptoolArgs(**default_kwargs) + + try: + self.esp.change_baud(460800) + esptool.load_ram(self.esp, load_ram_args) + finally: + f_bin_file.close()