"""The register-pipeline checker must retain phase and reject incomplete evidence.""" import nuked_md import pytest from check_register_latch import check_trace from conftest import ROOT # noqa: F401 def writes(): return [ nuked_md.Event(t, 0, 0xC00004, value, 18, nuked_md.EV_M68K, 14) for t, value in ((100, 0x8144), (200, 0x8104)) ] TRACE = """0 DISPLAY 0 0 0 0 HCLK1 0 0 0 0 HCLK2 0 0 0 240 HCLK1 1 0 0 244 HCLK1 0 0 0 248 HCLK2 1 1 0 252 HCLK2 0 1 0 256 DISPLAY 1 1 0 256 HCLK1 1 1 0 260 HCLK1 0 1 0 440 HCLK2 1 2 0 444 HCLK2 0 2 0 448 DISPLAY 0 2 0 448 HCLK1 1 2 0 """ def test_capture_on_hclk1_waits_until_the_following_hclk1(): assert check_trace(writes(), TRACE) == { "writes": 2, "transitions": 2, "delay_half_mclk": {48: 1, 56: 1}, } def test_half_master_clock_edges_are_not_rounded(): shifted = "\n".join( f"{int(t) + 1} {rest}" for t, rest in (line.split(" ", 1) for line in TRACE.splitlines()) ) assert check_trace(writes(), shifted)["delay_half_mclk"] == {49: 1, 57: 1} @pytest.mark.parametrize("old,new", [ ("256 DISPLAY", "255 DISPLAY"), ("256 DISPLAY 1", "256 DISPLAY 0"), ("448 DISPLAY 0 2 0\n", ""), ]) def test_incorrect_or_missing_commit_is_rejected(old, new): with pytest.raises(ValueError, match=r"display .*expected"): check_trace(writes(), TRACE.replace(old, new)) def test_missing_clocks_are_not_a_pass(): with pytest.raises(ValueError, match="missing pixel-clock"): check_trace(writes(), "\n".join(x for x in TRACE.splitlines() if "HCLK2" not in x)) with pytest.raises(ValueError, match="missing commit clock"): check_trace(writes(), TRACE.replace("448 HCLK1 1 2 0\n", "")) def test_initial_state_and_sufficient_transitions_are_required(): with pytest.raises(ValueError, match="missing initial display"): check_trace(writes(), TRACE.replace("0 DISPLAY 0 0 0\n", "")) with pytest.raises(ValueError, match="both display transitions"): check_trace([], "0 DISPLAY 0 0 0\n0 HCLK1 1 0 0\n1 HCLK2 1 0 0") def test_unsupported_bus_cycles_and_extra_transitions_are_rejected(): event = writes()[0] held = nuked_md.Event(event.t, 0, event.addr, event.data, 25, event.type, event.flags) with pytest.raises(ValueError, match="ordinary 18-MCLK word"): check_trace([held, writes()[1]], TRACE) with pytest.raises(ValueError, match="unmatched display"): check_trace(writes(), TRACE + "500 DISPLAY 1 3 0\n") @pytest.mark.parametrize("suffix", ["malformed", "500 DISPLAY 2 3 0", "1 HC 0 0 0"]) def test_invalid_signal_records_are_rejected(suffix): with pytest.raises(ValueError): check_trace(writes(), TRACE + suffix) def request_trace(): extra = [ "250 HCLK2 1 487 0", "254 HCLK2 0 487 0", "300 HCLK2 1 487 1", "300 HREQUEST 1 487 1", "304 HCLK2 0 487 1", "310 HREQUEST 0 488 1", "500 HCLK2 1 487 2", "504 HCLK2 0 487 2", ] return "\n".join(sorted(TRACE.splitlines() + extra, key=lambda line: int(line.split()[0]))) def test_scroll_request_uses_committed_display_not_bus_arrival(): assert check_trace(writes(), request_trace(), hscroll=True)["hscroll"] == { "gates": 3, "fetched": 1, "retained": 2, } def test_scroll_request_half_clock_phase_is_preserved(): shifted = "\n".join( f"{int(t) + 1} {rest}" for t, rest in (line.split(" ", 1) for line in request_trace().splitlines()) ) assert check_trace(writes(), shifted, hscroll=True)["hscroll"]["fetched"] == 1 @pytest.mark.parametrize("old,new", [ ("300 HREQUEST 1 487 1\n", ""), ("300 HREQUEST 1", "301 HREQUEST 1"), ("310 HREQUEST 0", "310 HREQUEST 1"), ("300 HREQUEST 1", "300 HREQUEST 2"), ]) def test_wrong_or_missing_scroll_request_is_rejected(old, new): with pytest.raises(ValueError, match=r"H-scroll requests differ|invalid HREQUEST"): check_trace(writes(), request_trace().replace(old, new), hscroll=True) def test_missing_scroll_gate_evidence_is_not_a_pass(): with pytest.raises(ValueError, match="missing H-scroll gate"): check_trace(writes(), TRACE, hscroll=True) @pytest.mark.parametrize("arrival,commit,fetched", [(104, 256, 1), (105, 268, 0)]) def test_one_master_clock_can_change_the_scroll_request(arrival, commit, fetched): events = [ nuked_md.Event(arrival, 0, 0xC00004, 0x8144, 18, nuked_md.EV_M68K, 14), writes()[1], ] records = [ "0 DISPLAY 0 0 0", "0 HCLK1 0 0 0", "0 HCLK2 0 0 0", "248 HCLK2 1 486 0", "252 HCLK2 0 486 0", "256 HCLK1 1 486 0", "260 HCLK1 0 486 0", "264 HCLK2 1 487 0", "266 HCLK2 0 487 0", "268 HCLK1 1 487 0", f"{commit} DISPLAY 1 487 0", "440 HCLK2 1 2 0", "444 HCLK2 0 2 0", "448 DISPLAY 0 2 0", "448 HCLK1 1 2 0", ] if fetched: records.append("264 HREQUEST 1 487 0") text = "\n".join(sorted(records, key=lambda line: int(line.split()[0]))) assert check_trace(events, text, hscroll=True)["hscroll"] == { "gates": 1, "fetched": fetched, "retained": 1 - fetched, }