From cf8b28abeacab9f1e934b5b28eb6378460e4f4a3 Mon Sep 17 00:00:00 2001 From: Jaroslav Burian Date: Thu, 2 Jan 2025 09:22:36 +0100 Subject: [PATCH] ci: Add Zephyr CI target test --- .gitlab-ci.yml | 15 +++++++ examples/conftest.py | 2 + .../zephyr_example/pytest_zephyr_example.py | 41 +++++++++++++++++++ pytest.ini | 1 + 4 files changed, 59 insertions(+) create mode 100644 examples/zephyr_example/pytest_zephyr_example.py diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 876224a..ffcf4b2 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -198,6 +198,13 @@ build_stm32: build_zephyr: stage: build image: espressif/idf:latest + artifacts: + paths: + - "**/build*/zephyr/*.bin" + - "**/build*/zephyr/*.elf" + - "**/build*/zephyr/*.map" + when: always + expire_in: 3 days tags: - build - internet @@ -322,6 +329,14 @@ test_esp2: - pytest --target=esp32 --port=/dev/serial_ports/ESP32_ESP32 -k 'not test_esp32_sdio_load_ram_example' - pytest --target=esp32s3 --port=/dev/serial_ports/ESP32S3_ESP32C3 -k 'not test_esp32_usb_cdc_acm_example' +test_zephyr: + extends: .test_template + tags: + - ESF-RPI-03 + script: + - cd $CI_PROJECT_DIR + - pytest --target=zephyr --port=/dev/serial_ports/ESP32_ESP32 + test_stm32: extends: .test_template tags: diff --git a/examples/conftest.py b/examples/conftest.py index f618a4e..4a1b3ac 100644 --- a/examples/conftest.py +++ b/examples/conftest.py @@ -17,6 +17,8 @@ def pytest_configure(config): pass elif "pi_pico" in target: config.option.embedded_services = "serial" + elif "zephyr" in target: + config.option.embedded_services = "serial" else: config.option.embedded_services = "esp,idf" diff --git a/examples/zephyr_example/pytest_zephyr_example.py b/examples/zephyr_example/pytest_zephyr_example.py new file mode 100644 index 0000000..ff829c3 --- /dev/null +++ b/examples/zephyr_example/pytest_zephyr_example.py @@ -0,0 +1,41 @@ +import pytest +from pytest_embedded import Dut +from esptool.cmds import detect_chip + +FLASH_ADDRESS = 0x1000 +BIN_FILE = "/zephyr/zephyr.bin" + + +# This fixture is used to specify the path to the Zephyr app as it is not in the examples directory. +# It is used by conftest.py to find the app path to build directory. +@pytest.fixture +def app_path() -> str: + return "zephyrproject-rtos/zephyr/" + + +@pytest.fixture(autouse=True) +def flash_zephyr(app_path: str, build_dir: str, port: str) -> None: + with detect_chip(port) as esp: + esp = esp.run_stub() + path = app_path + build_dir + BIN_FILE + with open(path, "rb") as binary: + binary_data = binary.read() + total_size = len(binary_data) + + esp.flash_begin(total_size, FLASH_ADDRESS) + for i in range(0, total_size, esp.FLASH_WRITE_SIZE): + block = binary_data[i : i + esp.FLASH_WRITE_SIZE] + # Pad the last block + block = block + bytes([0xFF]) * (esp.FLASH_WRITE_SIZE - len(block)) + esp.flash_block(block, i + FLASH_ADDRESS) + esp.flash_finish() + print("Flashed successfully") + + esp.hard_reset() + + +@pytest.mark.zephyr +def test_zephyr_example(dut: Dut) -> None: + for i in range(3): + dut.expect("Finished programming") + dut.expect("Hello world!") diff --git a/pytest.ini b/pytest.ini index 1bf2aa6..e92bbd0 100644 --- a/pytest.ini +++ b/pytest.ini @@ -21,6 +21,7 @@ markers = stm32: support stm32 target raspberry: support raspberry target pi_pico: support pi_pico target + zephyr: support zephyr target # log related log_cli = True