C6-Reticulum-ASM/tests/uart/test_uart_rx_available.py
DeFiDude 27e75f5281 uart_rx_byte + uart_rx_available: verified
Polled NS16550A receive primitives. uart_rx_byte spins on LSR.DR
(bit 0) until a byte arrives, then reads RBR. uart_rx_available
returns 1/0 of the same DR bit, non-blocking.

Both stay as the polled fall-back even after uart_isr lands; the
IRQ-driven ring-buffer path will become the production hot path
on the C6, the polled forms keep working on qemu-virt where qemu
does not model the PLIC for our IRQ wiring.
2026-05-01 22:54:33 -06:00

33 lines
1.1 KiB
Python

"""Tests for src/uart/uart_rx_available.S — non-blocking RX-ready check."""
from __future__ import annotations
import re
import pytest
from harness import build
@pytest.fixture(scope="module")
def artifacts() -> build.BuildArtifacts:
return build.build("qemu-virt")
def test_function_exists(artifacts: build.BuildArtifacts) -> None:
assert build.symbol_address(artifacts.elf, "uart_rx_available") > 0
def test_returns_dr_bit(artifacts: build.BuildArtifacts) -> None:
body = build.objdump_disassemble(artifacts.elf, symbol="uart_rx_available")
# `lbu t1, 5(t0)` then `andi a0, t1, 1` — the DR bit becomes a0.
assert re.search(r"\blbu\b\s+t1,\s*5\(t0\)", body), body
assert re.search(r"\bandi\b\s+a0,\s*t1,\s*1\b", body), body
def test_no_branches(artifacts: build.BuildArtifacts) -> None:
"""Non-blocking — no loop, no branches."""
body = build.objdump_disassemble(artifacts.elf, symbol="uart_rx_available")
for line in body.splitlines():
assert not re.search(r"\b(beq|bne|blt|bge|bltu|bgeu|beqz|bnez|j|jal)\s", line) \
or "ret" in line or "jalr" in line, line