mirror of
https://github.com/ratspeak/C6-Reticulum-ASM
synced 2026-08-12 18:07:18 -04:00
Completes the ADR-0004 log primitive set (log_init + log_str shipped
in the previous commit). Each is a leaf or single-call wrapper:
log_hex — width hex digits, MSB first, lowercase a-f
log_u32 — unsigned decimal, no leading zeros, special-case 0
log_bytes — space-separated 2-digit pairs
log_event — <ts8hex>\t<tag>\r\n with the timestamp placeholder
at 0 until clock_get_freq lands; the wire format is
final, only the sampled value will change
_main now calls log_init then log_event("boot\tready") instead
of writing a hard-coded banner. The qemu output is byte-identical
(00000000\tboot\tready\r\n) so test__main.py is unchanged; the
refactor proves the log chain works end-to-end.
108 tests, all green.
43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
"""Tests for src/log/log_bytes.S — loop calling log_hex per byte."""
|
|
|
|
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, "log_bytes") > 0
|
|
|
|
|
|
def test_calls_log_hex(artifacts: build.BuildArtifacts) -> None:
|
|
body = build.objdump_disassemble(artifacts.elf, symbol="log_bytes")
|
|
assert "log_hex" in body, body
|
|
|
|
|
|
def test_emits_space_separator(artifacts: build.BuildArtifacts) -> None:
|
|
body = build.objdump_disassemble(artifacts.elf, symbol="log_bytes")
|
|
# ASCII space = 32; passed via a0 to uart_tx_byte.
|
|
assert re.search(r"\bli\b\s+a0,\s*32\b", body), body
|
|
assert "uart_tx_byte" in body, body
|
|
|
|
|
|
def test_handles_empty_buffer(artifacts: build.BuildArtifacts) -> None:
|
|
body = build.objdump_disassemble(artifacts.elf, symbol="log_bytes")
|
|
# The early `beqz s1, .Ldone` short-circuit covers len=0 without
|
|
# touching the cursor.
|
|
assert re.search(r"\bbeqz\b\s+s1", body), body
|
|
|
|
|
|
def test_two_digit_width(artifacts: build.BuildArtifacts) -> None:
|
|
body = build.objdump_disassemble(artifacts.elf, symbol="log_bytes")
|
|
# log_hex is called with width=2 (a1 = 2) — two `li a1, 2`.
|
|
assert len(re.findall(r"\bli\b\s+a1,\s*2\b", body)) >= 1, body
|