forked from PAWPAW-Mirror/lib_xua
Add MIDI loopback test and fix app_midi_simple Tx
This commit is contained in:
60
tests/test_midi_loopback.py
Normal file
60
tests/test_midi_loopback.py
Normal file
@@ -0,0 +1,60 @@
|
||||
# Copyright 2014-2024 XMOS LIMITED.
|
||||
# This Software is subject to the terms of the XMOS Public Licence: Version 1.
|
||||
|
||||
import pytest
|
||||
import Pyxsim
|
||||
from Pyxsim import testers
|
||||
from pathlib import Path
|
||||
from uart_rx_checker import UARTRxChecker
|
||||
from midi_test_helpers import midi_expect_rx, create_midi_rx_file, create_midi_tx_file, tempdir, MIDI_RATE
|
||||
from distutils.dir_util import copy_tree # we're using python 3.7 and dirs_exist_ok=True isn't available until 3.8 :(
|
||||
|
||||
MAX_CYCLES = 15000000
|
||||
|
||||
|
||||
#####
|
||||
# This test takes the built binary, copies it to a tmp dir and runs the midi loopback test which sends some commands
|
||||
# the firmware receives them, prints and compares with the expected output
|
||||
#####
|
||||
def test_midi_loopback(capfd, build_midi):
|
||||
# Need tempdir as we use the same config files and this causes issues when using xdist
|
||||
with tempdir() as tmpdirname:
|
||||
config = "LOOPBACK"
|
||||
copy_tree(build_midi, tmpdirname)
|
||||
xe = str(Path(tmpdirname) / f"{config}/test_midi_{config}.xe")
|
||||
|
||||
midi_commands = [
|
||||
[0x90, 60, 81], #note on
|
||||
[0xc0, 15], #instr select
|
||||
[0xe0, 0, 96], #pitch bend
|
||||
[0xff], #MIDI reset
|
||||
[0x80, 60, 81], #note off
|
||||
]
|
||||
create_midi_rx_file(len(midi_commands))
|
||||
create_midi_tx_file(midi_commands)
|
||||
|
||||
expected = midi_expect_rx().expect(midi_commands)
|
||||
tester = testers.ComparisonTester(expected, ordered = True)
|
||||
|
||||
simthreads = []
|
||||
|
||||
simargs = ["--max-cycles", str(MAX_CYCLES)]
|
||||
#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"])
|
||||
|
||||
Pyxsim.run_with_pyxsim(
|
||||
xe,
|
||||
simthreads=simthreads,
|
||||
timeout=120,
|
||||
simargs=simargs,
|
||||
)
|
||||
capture = capfd.readouterr().out
|
||||
result = tester.run(capture.split("\n"))
|
||||
|
||||
# Print to console
|
||||
# with capfd.disabled():
|
||||
# print("++++", capture, "++++")
|
||||
# print("----", expected, "----")
|
||||
|
||||
|
||||
assert result
|
||||
Reference in New Issue
Block a user