From 7acd4ffe9968c302a07a642e8b733bfa4397dcf2 Mon Sep 17 00:00:00 2001 From: Ed Date: Fri, 26 Apr 2024 13:05:52 +0100 Subject: [PATCH] Tx test supports multiple MIDI commands --- tests/test_midi_loopback.py | 2 +- tests/test_midi_rx.py | 3 +-- tests/test_midi_tx.py | 36 +++++++++++++++++++++++++++++++----- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/tests/test_midi_loopback.py b/tests/test_midi_loopback.py index 992e7a51..fec656fe 100644 --- a/tests/test_midi_loopback.py +++ b/tests/test_midi_loopback.py @@ -59,4 +59,4 @@ def test_midi_loopback(capfd, build_midi): print("CAPTURE:", capture) print("EXPECTED:", expected) - assert result \ No newline at end of file + assert result diff --git a/tests/test_midi_rx.py b/tests/test_midi_rx.py index f3ec5ef5..49af60f8 100644 --- a/tests/test_midi_rx.py +++ b/tests/test_midi_rx.py @@ -43,7 +43,6 @@ def test_rx(capfd, config, build_midi): stop = 1 midi_commands_flattened = [item for row in midi_commands for item in row] - # midi_commands_flattened.append(0x00) # send a null afterwards to give RXChecker to complete simthreads = [ UARTRxChecker(tx_port, rx_port, parity, baud, stop, bpb, midi_commands_flattened, debug=False) @@ -69,4 +68,4 @@ def test_rx(capfd, config, build_midi): print("EXPECTED:", expected) - assert result, f"expected: {expected}\n capture: {capture}" \ No newline at end of file + assert result, f"expected: {expected}\n capture: {capture}" diff --git a/tests/test_midi_tx.py b/tests/test_midi_tx.py index ade525d6..1932a587 100644 --- a/tests/test_midi_tx.py +++ b/tests/test_midi_tx.py @@ -23,11 +23,23 @@ def test_tx(capfd, config, build_midi): copy_tree(build_midi, tmpdirname) xe = str(Path(tmpdirname) / f"{config}/test_midi_{config}.xe") - midi_commands = [[0x90, 60, 81]] + # midi_commands = [[0x90, 0x91, 0x90],# Invalid and should be discarded + # [0x90, 60, 81], # Note on + # [0x80, 60, 81]] # Note off + + midi_commands = [ + [0x90, 60, 81], # Note on + [0x80, 60, 81]] # Note off + + + # midi_command_expected = midi_commands[1:] # should skip invalid first message + # Make a 1D list from the 2D list + midi_command_expected = [[item for row in midi_commands for item in row]] + create_midi_tx_file(midi_commands) create_midi_rx_file() - expected = midi_expect_tx().expect(midi_commands) + expected = midi_expect_tx().expect(midi_command_expected) tester = testers.ComparisonTester(expected, ordered = True) tx_port = "tile[1]:XS1_PORT_4C" @@ -42,9 +54,9 @@ def test_tx(capfd, config, build_midi): ] - simargs = ["--max-cycles", str(MAX_CYCLES)] + simargs = ["--max-cycles", str(MAX_CYCLES), "-o", "trace.txt"] #This is just for local debug so we can capture the traces if needed. It slows xsim down so not needed - # simargs.extend(["--trace-to", "trace.txt", "--vcd-tracing", "-tile tile[1] -ports -o trace.vcd"]) + # simargs.extend(["--vcd-tracing", "-tile tile[1] -ports -o trace.vcd"]) # with capfd.disabled(): # use to see xsim and tester output Pyxsim.run_with_pyxsim( @@ -56,4 +68,18 @@ def test_tx(capfd, config, build_midi): capture = capfd.readouterr().out result = tester.run(capture.split("\n")) - assert result, f"expected: {expected}\n capture: {capture}" \ No newline at end of file + # Print to console + with capfd.disabled(): + print("CAPTURE:", capture) + print("EXPECTED:", expected) + + # Show tail of trace if there is an error + if not result: + with capfd.disabled(): + print("Simulator trace tail:") + with open("trace.txt") as trace: + output = trace.readlines() + print("".join(output[-25:])) + + + assert result, f"expected: {expected}\n capture: {capture}"