Skip to content

Commit

Permalink
ci: Add Zephyr CI target test
Browse files Browse the repository at this point in the history
  • Loading branch information
Dzarda7 committed Jan 3, 2025
1 parent 1d3e2f4 commit cf8b28a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 0 deletions.
15 changes: 15 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions examples/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
41 changes: 41 additions & 0 deletions examples/zephyr_example/pytest_zephyr_example.py
Original file line number Diff line number Diff line change
@@ -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!")
1 change: 1 addition & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit cf8b28a

Please sign in to comment.