pytest-embedded-jtag

2.7.0 · active · verified Thu Apr 16

pytest-embedded-jtag is a plugin for pytest-embedded that enables interaction with JTAG-connected devices, providing services for OpenOCD and GDB utilities. It allows for advanced embedded testing scenarios by integrating debugging and flashing tools directly into pytest tests. The current version is 2.7.0, and it follows the release cadence of the broader pytest-embedded project.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic pytest test using the `dut`, `openocd`, and `gdb` fixtures provided by `pytest-embedded-jtag`. To run this test, you need an embedded target, OpenOCD, and GDB configured. Save the code as `test_jtag.py` and execute with `pytest -s --embedded-services jtag` to enable the JTAG services and see stdout. The `openocd` and `gdb` fixtures are instances of their respective classes, allowing direct interaction.

import pytest
from pytest_embedded import Dut

def test_jtag_connection(dut: Dut, openocd, gdb):
    # To enable these fixtures, run pytest with --embedded-services jtag
    # The 'openocd' and 'gdb' fixtures are automatically provided when 'jtag' service is active.
    # 'openocd' is an instance of pytest_embedded_jtag.openocd.OpenOcd
    # 'gdb' is an instance of pytest_embedded_jtag.gdb.Gdb
    
    print(f"OpenOCD instance: {openocd}")
    print(f"GDB instance: {gdb}")
    
    # Example: Send a command to OpenOCD (requires OpenOCD to be running and connected)
    # In a real test, you'd interact with OpenOCD or GDB to flash, debug, or verify state.
    try:
        openocd.write("version") # Assuming 'version' is a valid OpenOCD command
        version_output = dut.expect("Open On-Chip Debugger").group(0)
        print(f"OpenOCD version output: {version_output}")
    except Exception as e:
        print(f"Could not interact with OpenOCD: {e}")
    
    # Example: Basic DUT interaction (from pytest-embedded)
    dut.expect_exact("Hello from target") # Replace with expected output from your embedded target
    print("Target responded 'Hello from target'")

view raw JSON →