From 438c24d43615c4767892afbb34335822f9bf95b3 Mon Sep 17 00:00:00 2001 From: xross Date: Tue, 5 Jul 2022 12:05:31 +0100 Subject: [PATCH 01/17] Moved legacy tests into tests --- {legacy_tests => tests}/app_test_i2s_loopback/Makefile | 0 {legacy_tests => tests}/app_test_i2s_loopback/debug_conf.h | 0 .../app_test_i2s_loopback/hid_report_descriptor.h | 0 {legacy_tests => tests}/app_test_i2s_loopback/main.xc | 0 {legacy_tests => tests}/app_test_i2s_loopback/simulation.xc | 0 {legacy_tests => tests}/app_test_i2s_loopback/usb_device.h | 0 {legacy_tests => tests}/app_test_i2s_loopback/usb_device.xc | 0 .../app_test_i2s_loopback/xk_216_mc/audiohw.xc | 0 {legacy_tests => tests}/app_test_i2s_loopback/xk_216_mc/cs2100.h | 0 {legacy_tests => tests}/app_test_i2s_loopback/xk_216_mc/cs4384.h | 0 {legacy_tests => tests}/app_test_i2s_loopback/xk_216_mc/cs5368.h | 0 .../app_test_i2s_loopback/xk_216_mc/gpio_access.c | 0 .../app_test_i2s_loopback/xk_216_mc/gpio_access.h | 0 .../app_test_i2s_loopback/xk_216_mc/xk-audio-216-mc.xn | 0 {legacy_tests => tests}/app_test_i2s_loopback/xua_conf.h | 0 {legacy_tests => tests}/pass.expect | 0 {legacy_tests => tests}/runtests.py | 0 {legacy_tests => tests}/test_i2s_loopback.py | 0 18 files changed, 0 insertions(+), 0 deletions(-) rename {legacy_tests => tests}/app_test_i2s_loopback/Makefile (100%) rename {legacy_tests => tests}/app_test_i2s_loopback/debug_conf.h (100%) rename {legacy_tests => tests}/app_test_i2s_loopback/hid_report_descriptor.h (100%) rename {legacy_tests => tests}/app_test_i2s_loopback/main.xc (100%) rename {legacy_tests => tests}/app_test_i2s_loopback/simulation.xc (100%) rename {legacy_tests => tests}/app_test_i2s_loopback/usb_device.h (100%) rename {legacy_tests => tests}/app_test_i2s_loopback/usb_device.xc (100%) rename {legacy_tests => tests}/app_test_i2s_loopback/xk_216_mc/audiohw.xc (100%) rename {legacy_tests => tests}/app_test_i2s_loopback/xk_216_mc/cs2100.h (100%) rename {legacy_tests => tests}/app_test_i2s_loopback/xk_216_mc/cs4384.h (100%) rename {legacy_tests => tests}/app_test_i2s_loopback/xk_216_mc/cs5368.h (100%) rename {legacy_tests => tests}/app_test_i2s_loopback/xk_216_mc/gpio_access.c (100%) rename {legacy_tests => tests}/app_test_i2s_loopback/xk_216_mc/gpio_access.h (100%) rename {legacy_tests => tests}/app_test_i2s_loopback/xk_216_mc/xk-audio-216-mc.xn (100%) rename {legacy_tests => tests}/app_test_i2s_loopback/xua_conf.h (100%) rename {legacy_tests => tests}/pass.expect (100%) rename {legacy_tests => tests}/runtests.py (100%) rename {legacy_tests => tests}/test_i2s_loopback.py (100%) diff --git a/legacy_tests/app_test_i2s_loopback/Makefile b/tests/app_test_i2s_loopback/Makefile similarity index 100% rename from legacy_tests/app_test_i2s_loopback/Makefile rename to tests/app_test_i2s_loopback/Makefile diff --git a/legacy_tests/app_test_i2s_loopback/debug_conf.h b/tests/app_test_i2s_loopback/debug_conf.h similarity index 100% rename from legacy_tests/app_test_i2s_loopback/debug_conf.h rename to tests/app_test_i2s_loopback/debug_conf.h diff --git a/legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h b/tests/app_test_i2s_loopback/hid_report_descriptor.h similarity index 100% rename from legacy_tests/app_test_i2s_loopback/hid_report_descriptor.h rename to tests/app_test_i2s_loopback/hid_report_descriptor.h diff --git a/legacy_tests/app_test_i2s_loopback/main.xc b/tests/app_test_i2s_loopback/main.xc similarity index 100% rename from legacy_tests/app_test_i2s_loopback/main.xc rename to tests/app_test_i2s_loopback/main.xc diff --git a/legacy_tests/app_test_i2s_loopback/simulation.xc b/tests/app_test_i2s_loopback/simulation.xc similarity index 100% rename from legacy_tests/app_test_i2s_loopback/simulation.xc rename to tests/app_test_i2s_loopback/simulation.xc diff --git a/legacy_tests/app_test_i2s_loopback/usb_device.h b/tests/app_test_i2s_loopback/usb_device.h similarity index 100% rename from legacy_tests/app_test_i2s_loopback/usb_device.h rename to tests/app_test_i2s_loopback/usb_device.h diff --git a/legacy_tests/app_test_i2s_loopback/usb_device.xc b/tests/app_test_i2s_loopback/usb_device.xc similarity index 100% rename from legacy_tests/app_test_i2s_loopback/usb_device.xc rename to tests/app_test_i2s_loopback/usb_device.xc diff --git a/legacy_tests/app_test_i2s_loopback/xk_216_mc/audiohw.xc b/tests/app_test_i2s_loopback/xk_216_mc/audiohw.xc similarity index 100% rename from legacy_tests/app_test_i2s_loopback/xk_216_mc/audiohw.xc rename to tests/app_test_i2s_loopback/xk_216_mc/audiohw.xc diff --git a/legacy_tests/app_test_i2s_loopback/xk_216_mc/cs2100.h b/tests/app_test_i2s_loopback/xk_216_mc/cs2100.h similarity index 100% rename from legacy_tests/app_test_i2s_loopback/xk_216_mc/cs2100.h rename to tests/app_test_i2s_loopback/xk_216_mc/cs2100.h diff --git a/legacy_tests/app_test_i2s_loopback/xk_216_mc/cs4384.h b/tests/app_test_i2s_loopback/xk_216_mc/cs4384.h similarity index 100% rename from legacy_tests/app_test_i2s_loopback/xk_216_mc/cs4384.h rename to tests/app_test_i2s_loopback/xk_216_mc/cs4384.h diff --git a/legacy_tests/app_test_i2s_loopback/xk_216_mc/cs5368.h b/tests/app_test_i2s_loopback/xk_216_mc/cs5368.h similarity index 100% rename from legacy_tests/app_test_i2s_loopback/xk_216_mc/cs5368.h rename to tests/app_test_i2s_loopback/xk_216_mc/cs5368.h diff --git a/legacy_tests/app_test_i2s_loopback/xk_216_mc/gpio_access.c b/tests/app_test_i2s_loopback/xk_216_mc/gpio_access.c similarity index 100% rename from legacy_tests/app_test_i2s_loopback/xk_216_mc/gpio_access.c rename to tests/app_test_i2s_loopback/xk_216_mc/gpio_access.c diff --git a/legacy_tests/app_test_i2s_loopback/xk_216_mc/gpio_access.h b/tests/app_test_i2s_loopback/xk_216_mc/gpio_access.h similarity index 100% rename from legacy_tests/app_test_i2s_loopback/xk_216_mc/gpio_access.h rename to tests/app_test_i2s_loopback/xk_216_mc/gpio_access.h diff --git a/legacy_tests/app_test_i2s_loopback/xk_216_mc/xk-audio-216-mc.xn b/tests/app_test_i2s_loopback/xk_216_mc/xk-audio-216-mc.xn similarity index 100% rename from legacy_tests/app_test_i2s_loopback/xk_216_mc/xk-audio-216-mc.xn rename to tests/app_test_i2s_loopback/xk_216_mc/xk-audio-216-mc.xn diff --git a/legacy_tests/app_test_i2s_loopback/xua_conf.h b/tests/app_test_i2s_loopback/xua_conf.h similarity index 100% rename from legacy_tests/app_test_i2s_loopback/xua_conf.h rename to tests/app_test_i2s_loopback/xua_conf.h diff --git a/legacy_tests/pass.expect b/tests/pass.expect similarity index 100% rename from legacy_tests/pass.expect rename to tests/pass.expect diff --git a/legacy_tests/runtests.py b/tests/runtests.py similarity index 100% rename from legacy_tests/runtests.py rename to tests/runtests.py diff --git a/legacy_tests/test_i2s_loopback.py b/tests/test_i2s_loopback.py similarity index 100% rename from legacy_tests/test_i2s_loopback.py rename to tests/test_i2s_loopback.py From 476e3d9f2f4c2f4ce2eed359bd95e333dcb02ff2 Mon Sep 17 00:00:00 2001 From: xross Date: Tue, 5 Jul 2022 12:30:13 +0100 Subject: [PATCH 02/17] app_test_i2s_loopback: Update makefile --- tests/app_test_i2s_loopback/Makefile | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/app_test_i2s_loopback/Makefile b/tests/app_test_i2s_loopback/Makefile index c3e3ab403..7fb0bb123 100644 --- a/tests/app_test_i2s_loopback/Makefile +++ b/tests/app_test_i2s_loopback/Makefile @@ -45,25 +45,25 @@ BUILD_FLAGS_i2s_slave_8in_8out_192khz = $(BUILD_FLAGS) \ -D DEFAULT_FREQ=192000 -DCODEC_MASTER=1 \ -O2 # optimisations to meet timing -BUILD_FLAGS_tdm_master_8in_8out_48khz = $(BUILD_FLAGS) -D I2S_MODE_TDM=1 \ +BUILD_FLAGS_tdm_master_8in_8out_48khz = $(BUILD_FLAGS) -D XUA_PCM_FORMAT=XUA_PCM_FORMAT_TDM \ -D ADAT_RX=0 -D ADAT_TX=0 -D SPDIF_RX=0 -D SPDIF_TX=0 -D MIDI=0 \ -D NUM_USB_CHAN_IN=8 -D NUM_USB_CHAN_OUT=8 -D I2S_CHANS_ADC=8 -D I2S_CHANS_DAC=8 \ -D DEFAULT_FREQ=48000 \ -O2 # optimisations to meet timing -BUILD_FLAGS_tdm_slave_8in_8out_48khz = $(BUILD_FLAGS) -D I2S_MODE_TDM=1 \ +BUILD_FLAGS_tdm_slave_8in_8out_48khz = $(BUILD_FLAGS) -D XUA_PCM_FORMAT=XUA_PCM_FORMAT_TDM \ -D ADAT_RX=0 -D ADAT_TX=0 -D SPDIF_RX=0 -D SPDIF_TX=0 -D MIDI=0 \ -D NUM_USB_CHAN_IN=8 -D NUM_USB_CHAN_OUT=8 -D I2S_CHANS_ADC=8 -D I2S_CHANS_DAC=8 \ -D DEFAULT_FREQ=48000 -DCODEC_MASTER=1 \ -O2 # optimisations to meet timing -BUILD_FLAGS_tdm_master_16in_16out_48khz = $(BUILD_FLAGS) -D I2S_MODE_TDM=1 \ +BUILD_FLAGS_tdm_master_16in_16out_48khz = $(BUILD_FLAGS) -D XUA_PCM_FORMAT=XUA_PCM_FORMAT_TDM \ -D ADAT_RX=0 -D ADAT_TX=0 -D SPDIF_RX=0 -D SPDIF_TX=0 -D MIDI=0 \ -D NUM_USB_CHAN_IN=16 -D NUM_USB_CHAN_OUT=16 -D I2S_CHANS_ADC=16 -D I2S_CHANS_DAC=16 \ -D DEFAULT_FREQ=48000 \ -O2 # optimisations to meet timing -BUILD_FLAGS_tdm_slave_16in_16out_48khz = $(BUILD_FLAGS) -D I2S_MODE_TDM=1 \ +BUILD_FLAGS_tdm_slave_16in_16out_48khz = $(BUILD_FLAGS) -D XUA_PCM_FORMAT=XUA_PCM_FORMAT_TDM \ -D ADAT_RX=0 -D ADAT_TX=0 -D SPDIF_RX=0 -D SPDIF_TX=0 -D MIDI=0 \ -D NUM_USB_CHAN_IN=16 -D NUM_USB_CHAN_OUT=16 -D I2S_CHANS_ADC=16 -D I2S_CHANS_DAC=16 \ -D DEFAULT_FREQ=48000 -DCODEC_MASTER=1 \ From 9401bfff83177b2348e0d713985afa7f31849dec Mon Sep 17 00:00:00 2001 From: xross Date: Tue, 5 Jul 2022 18:14:05 +0100 Subject: [PATCH 03/17] - Rename app_test_i2s_loopback to test_i2s_loopback - Port test_i2s_loopback from xmostest to pytest and test_support --- .gitignore | 1 + tests/conftest.py | 9 + tests/test_i2s_loopback.py | 198 +++++++++++++----- .../Makefile | 0 .../debug_conf.h | 0 .../hid_report_descriptor.h | 0 .../main.xc | 2 +- .../simulation.xc | 0 .../usb_device.h | 0 .../usb_device.xc | 0 .../xk_216_mc/audiohw.xc | 0 .../xk_216_mc/cs2100.h | 0 .../xk_216_mc/cs4384.h | 0 .../xk_216_mc/cs5368.h | 0 .../xk_216_mc/gpio_access.c | 0 .../xk_216_mc/gpio_access.h | 0 .../xk_216_mc/xk-audio-216-mc.xn | 0 .../xua_conf.h | 19 +- 18 files changed, 171 insertions(+), 58 deletions(-) create mode 100644 tests/conftest.py rename tests/{app_test_i2s_loopback => test_i2s_loopback}/Makefile (100%) rename tests/{app_test_i2s_loopback => test_i2s_loopback}/debug_conf.h (100%) rename tests/{app_test_i2s_loopback => test_i2s_loopback}/hid_report_descriptor.h (100%) rename tests/{app_test_i2s_loopback => test_i2s_loopback}/main.xc (99%) rename tests/{app_test_i2s_loopback => test_i2s_loopback}/simulation.xc (100%) rename tests/{app_test_i2s_loopback => test_i2s_loopback}/usb_device.h (100%) rename tests/{app_test_i2s_loopback => test_i2s_loopback}/usb_device.xc (100%) rename tests/{app_test_i2s_loopback => test_i2s_loopback}/xk_216_mc/audiohw.xc (100%) rename tests/{app_test_i2s_loopback => test_i2s_loopback}/xk_216_mc/cs2100.h (100%) rename tests/{app_test_i2s_loopback => test_i2s_loopback}/xk_216_mc/cs4384.h (100%) rename tests/{app_test_i2s_loopback => test_i2s_loopback}/xk_216_mc/cs5368.h (100%) rename tests/{app_test_i2s_loopback => test_i2s_loopback}/xk_216_mc/gpio_access.c (100%) rename tests/{app_test_i2s_loopback => test_i2s_loopback}/xk_216_mc/gpio_access.h (100%) rename tests/{app_test_i2s_loopback => test_i2s_loopback}/xk_216_mc/xk-audio-216-mc.xn (100%) rename tests/{app_test_i2s_loopback => test_i2s_loopback}/xua_conf.h (77%) diff --git a/.gitignore b/.gitignore index a10bd6ad0..9ba242e90 100644 --- a/.gitignore +++ b/.gitignore @@ -23,6 +23,7 @@ _build* **/.vscode/** **.egg-info *.pdf +*/logs/* # waf build files .lock-waf_* diff --git a/tests/conftest.py b/tests/conftest.py new file mode 100644 index 000000000..c302dd8d6 --- /dev/null +++ b/tests/conftest.py @@ -0,0 +1,9 @@ +import pytest + +def pytest_addoption(parser): + parser.addoption("--enabletracing", action="store_true", default=False, help="Enable xsim tracing") + + +@pytest.fixture +def options(request): + yield request.config.option diff --git a/tests/test_i2s_loopback.py b/tests/test_i2s_loopback.py index 3e65e2f60..dc521d547 100644 --- a/tests/test_i2s_loopback.py +++ b/tests/test_i2s_loopback.py @@ -1,51 +1,147 @@ -#!/usr/bin/env python -# Copyright 2018-2021 XMOS LIMITED. -# This Software is subject to the terms of the XMOS Public Licence: Version 1. -import xmostest - -def runtest_one_config(env, format, i2s_role, num_chans_in, num_chans_out, sample_rate): - testlevel = 'smoke' - resources = xmostest.request_resource('xsim') - - binary = 'app_test_i2s_loopback/bin/{env}_{format}_{i2s_role}_{num_chans_in}in_{num_chans_out}out_{sample_rate}/app_test_i2s_loopback_{env}_{format}_{i2s_role}_{num_chans_in}in_{num_chans_out}out_{sample_rate}.xe'.format(env=env, format=format, i2s_role=i2s_role, num_chans_in=num_chans_in, num_chans_out=num_chans_out, sample_rate=sample_rate) - tester = xmostest.ComparisonTester(open('pass.expect'), - 'lib_xua', - 'i2s_loopback_sim_tests', - 'i2s_loopback', - {'env':env, - 'format':format, - 'i2s_role':i2s_role, - 'num_chans_in':num_chans_in, - 'num_chans_out':num_chans_out, - 'sample_rate':sample_rate}) - tester.set_min_testlevel(testlevel) - loopback_args= '-port tile[0] XS1_PORT_1M 1 0 -port tile[0] XS1_PORT_1I 1 0 ' + \ - '-port tile[0] XS1_PORT_1N 1 0 -port tile[0] XS1_PORT_1J 1 0 ' + \ - '-port tile[0] XS1_PORT_1O 1 0 -port tile[0] XS1_PORT_1K 1 0 ' + \ - '-port tile[0] XS1_PORT_1P 1 0 -port tile[0] XS1_PORT_1L 1 0 ' + \ - '-port tile[0] XS1_PORT_1A 1 0 -port tile[0] XS1_PORT_1F 1 0 ' - if i2s_role == 'slave': - loopback_args += '-port tile[0] XS1_PORT_1B 1 0 -port tile[0] XS1_PORT_1H 1 0 ' #bclk - loopback_args += '-port tile[0] XS1_PORT_1C 1 0 -port tile[0] XS1_PORT_1G 1 0 ' #lrclk - - max_cycles = 1500000 #enough to reach the 10 skip + 100 test in sim at 48kHz - xmostest.run_on_simulator(resources['xsim'], binary, tester=tester, simargs=['--max-cycles', str(max_cycles), '--plugin', 'LoopbackPort.dll', loopback_args]) - -def runtest(): - runtest_one_config('simulation', 'i2s', 'master', 2, 2, '48khz') - runtest_one_config('simulation', 'i2s', 'slave', 2, 2, '48khz') - - runtest_one_config('simulation', 'i2s', 'master', 2, 2, '192khz') - runtest_one_config('simulation', 'i2s', 'slave', 2, 2, '192khz') - - runtest_one_config('simulation', 'i2s', 'master', 8, 8, '48khz') - runtest_one_config('simulation', 'i2s', 'slave', 8, 8, '48khz') - - runtest_one_config('simulation', 'i2s', 'master', 8, 8, '192khz') - runtest_one_config('simulation', 'i2s', 'slave', 8, 8, '192khz') - - runtest_one_config('simulation', 'tdm', 'master', 8, 8, '48khz') - runtest_one_config('simulation', 'tdm', 'slave', 8, 8, '48khz') - - runtest_one_config('simulation', 'tdm', 'master', 16, 16, '48khz') - runtest_one_config('simulation', 'tdm', 'slave', 16, 16, '48khz') +import pytest +import Pyxsim +from Pyxsim import testers +import os +import sys + + +@pytest.fixture() +def test_file(request): + return str(request.node.fspath) + + +def create_if_needed(folder): + if not os.path.exists(folder): + os.makedirs(folder) + return folder + + +def get_sim_args(testname, desc, options): + sim_args = [] + + if options.enabletracing: + log_folder = create_if_needed("logs") + + filename = "{log}/xsim_trace_{test}_{desc}".format( + log=log_folder, + test=testname, + desc=desc, + ) + + sim_args += [ + "--trace-to", + "{0}.txt".format(filename), + "--enable-fnop-tracing", + ] + + vcd_args = "-o {0}.vcd".format(filename) + vcd_args += ( + " -tile tile[0] -ports -ports-detailed -instructions" + " -functions -cycles -clock-blocks -pads -cores -usb" + ) + + sim_args += ["--vcd-tracing", vcd_args] + + return sim_args + + +def run_on_simulator(xe, simthreads, **kwargs): + for k in ["do_xe_prebuild", "build_env", "clean_before_build"]: + if k in kwargs: + kwargs.pop(k) + + Pyxsim.run_with_pyxsim(xe, simthreads, **kwargs) + + +def do_test(pcm_format, i2s_role, channel_count, sample_rate, test_file, capfd, options): + + build_options = [] + output = [] + testname, _ = os.path.splitext(os.path.basename(test_file)) + + desc = f"simulation_{pcm_format}_{i2s_role}_{channel_count}in_{channel_count}out_{sample_rate}" + binary = f"{testname}/bin/{desc}/{testname}_{desc}.xe" + + build_success, _ = Pyxsim._build( + binary, do_clean=False, build_options=build_options + ) + + if build_success: + + tester = testers.ComparisonTester( + open("pass.expect"), + "lib_xua", + "xua_sim_tests", + testname, + { + "speed": "500MHz", + "arch": "XS2", + }, # TODO run tests on XS3 and other core freqs + ) + + loopback_args = ( + "-port tile[0] XS1_PORT_1M 1 0 -port tile[0] XS1_PORT_1I 1 0 " + + "-port tile[0] XS1_PORT_1N 1 0 -port tile[0] XS1_PORT_1J 1 0 " + + "-port tile[0] XS1_PORT_1O 1 0 -port tile[0] XS1_PORT_1K 1 0 " + + "-port tile[0] XS1_PORT_1P 1 0 -port tile[0] XS1_PORT_1L 1 0 " + + "-port tile[0] XS1_PORT_1A 1 0 -port tile[0] XS1_PORT_1F 1 0 " + ) + if i2s_role == "slave": + loopback_args += ( + "-port tile[0] XS1_PORT_1B 1 0 -port tile[0] XS1_PORT_1H 1 0 " # bclk + ) + loopback_args += ( + "-port tile[0] XS1_PORT_1C 1 0 -port tile[0] XS1_PORT_1G 1 0 " # lrclk + ) + + max_cycles = 1500000 # enough to reach the 10 skip + 100 test in sim at 48kHz + + simargs = get_sim_args(testname, desc, options) + simargs = simargs + [ + "--max-cycles", + str(max_cycles), + "--plugin", + "LoopbackPort.dll", + loopback_args, + ] + + simthreads = [] + run_on_simulator(binary, simthreads, simargs=simargs) + + cap_output, err = capfd.readouterr() + output.append(cap_output.split("\n")) + + sys.stdout.write("\n") + + results = Pyxsim.run_tester(output, [tester]) + + return results + + else: + print("Build Failed") + + return [False] + + +@pytest.mark.parametrize("i2s_role", ["master", "slave"]) +@pytest.mark.parametrize("pcm_format", ["i2s", "tdm"]) +@pytest.mark.parametrize("channel_count", [2, 8, 16]) +@pytest.mark.parametrize("sample_rate", ["48khz", "192khz"]) +def test_i2s_loopback( + i2s_role, pcm_format, channel_count, sample_rate, test_file, capfd, options +): + + if pcm_format == "i2s" and channel_count == 16: + pytest.skip("Invalid parameter combination") + + if pcm_format == "tdm" and channel_count == 2: + pytest.skip("Invalid parameter combination") + + if pcm_format == "tdm" and sample_rate == "192khz": + pytest.skip("Invalid parameter combination") + + results = do_test( + pcm_format, i2s_role, channel_count, sample_rate, test_file, capfd, options + ) + + assert results[0] diff --git a/tests/app_test_i2s_loopback/Makefile b/tests/test_i2s_loopback/Makefile similarity index 100% rename from tests/app_test_i2s_loopback/Makefile rename to tests/test_i2s_loopback/Makefile diff --git a/tests/app_test_i2s_loopback/debug_conf.h b/tests/test_i2s_loopback/debug_conf.h similarity index 100% rename from tests/app_test_i2s_loopback/debug_conf.h rename to tests/test_i2s_loopback/debug_conf.h diff --git a/tests/app_test_i2s_loopback/hid_report_descriptor.h b/tests/test_i2s_loopback/hid_report_descriptor.h similarity index 100% rename from tests/app_test_i2s_loopback/hid_report_descriptor.h rename to tests/test_i2s_loopback/hid_report_descriptor.h diff --git a/tests/app_test_i2s_loopback/main.xc b/tests/test_i2s_loopback/main.xc similarity index 99% rename from tests/app_test_i2s_loopback/main.xc rename to tests/test_i2s_loopback/main.xc index bfef1fd16..73a24db1e 100644 --- a/tests/app_test_i2s_loopback/main.xc +++ b/tests/test_i2s_loopback/main.xc @@ -203,7 +203,7 @@ void slave_mode_clk_setup(const unsigned samFreq, const unsigned chans_per_frame #endif -#if I2S_MODE_TDM +#if XUA_PCM_FORMAT == XUA_PCM_FORMAT_TDM const int i2s_tdm_mode = 8; #else const int i2s_tdm_mode = 2; diff --git a/tests/app_test_i2s_loopback/simulation.xc b/tests/test_i2s_loopback/simulation.xc similarity index 100% rename from tests/app_test_i2s_loopback/simulation.xc rename to tests/test_i2s_loopback/simulation.xc diff --git a/tests/app_test_i2s_loopback/usb_device.h b/tests/test_i2s_loopback/usb_device.h similarity index 100% rename from tests/app_test_i2s_loopback/usb_device.h rename to tests/test_i2s_loopback/usb_device.h diff --git a/tests/app_test_i2s_loopback/usb_device.xc b/tests/test_i2s_loopback/usb_device.xc similarity index 100% rename from tests/app_test_i2s_loopback/usb_device.xc rename to tests/test_i2s_loopback/usb_device.xc diff --git a/tests/app_test_i2s_loopback/xk_216_mc/audiohw.xc b/tests/test_i2s_loopback/xk_216_mc/audiohw.xc similarity index 100% rename from tests/app_test_i2s_loopback/xk_216_mc/audiohw.xc rename to tests/test_i2s_loopback/xk_216_mc/audiohw.xc diff --git a/tests/app_test_i2s_loopback/xk_216_mc/cs2100.h b/tests/test_i2s_loopback/xk_216_mc/cs2100.h similarity index 100% rename from tests/app_test_i2s_loopback/xk_216_mc/cs2100.h rename to tests/test_i2s_loopback/xk_216_mc/cs2100.h diff --git a/tests/app_test_i2s_loopback/xk_216_mc/cs4384.h b/tests/test_i2s_loopback/xk_216_mc/cs4384.h similarity index 100% rename from tests/app_test_i2s_loopback/xk_216_mc/cs4384.h rename to tests/test_i2s_loopback/xk_216_mc/cs4384.h diff --git a/tests/app_test_i2s_loopback/xk_216_mc/cs5368.h b/tests/test_i2s_loopback/xk_216_mc/cs5368.h similarity index 100% rename from tests/app_test_i2s_loopback/xk_216_mc/cs5368.h rename to tests/test_i2s_loopback/xk_216_mc/cs5368.h diff --git a/tests/app_test_i2s_loopback/xk_216_mc/gpio_access.c b/tests/test_i2s_loopback/xk_216_mc/gpio_access.c similarity index 100% rename from tests/app_test_i2s_loopback/xk_216_mc/gpio_access.c rename to tests/test_i2s_loopback/xk_216_mc/gpio_access.c diff --git a/tests/app_test_i2s_loopback/xk_216_mc/gpio_access.h b/tests/test_i2s_loopback/xk_216_mc/gpio_access.h similarity index 100% rename from tests/app_test_i2s_loopback/xk_216_mc/gpio_access.h rename to tests/test_i2s_loopback/xk_216_mc/gpio_access.h diff --git a/tests/app_test_i2s_loopback/xk_216_mc/xk-audio-216-mc.xn b/tests/test_i2s_loopback/xk_216_mc/xk-audio-216-mc.xn similarity index 100% rename from tests/app_test_i2s_loopback/xk_216_mc/xk-audio-216-mc.xn rename to tests/test_i2s_loopback/xk_216_mc/xk-audio-216-mc.xn diff --git a/tests/app_test_i2s_loopback/xua_conf.h b/tests/test_i2s_loopback/xua_conf.h similarity index 77% rename from tests/app_test_i2s_loopback/xua_conf.h rename to tests/test_i2s_loopback/xua_conf.h index a1120f497..dc381a653 100644 --- a/tests/app_test_i2s_loopback/xua_conf.h +++ b/tests/test_i2s_loopback/xua_conf.h @@ -1,17 +1,24 @@ -// Copyright 2016-2021 XMOS LIMITED. +// Copyright 2016-2022 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. -#ifndef __custom_defines_h__ -#define __custom_defines_h__ +#ifndef _XUA_CONF_H_ +#define _XUA_CONF_H_ #define EXCLUDE_USB_AUDIO_MAIN #define XUA_NUM_PDM_MICS 0 #define XUD_TILE 1 #define AUDIO_IO_TILE 0 #define MIXER 0 + +#ifndef MCLK_441 #define MCLK_441 (512 * 44100) +#endif + +#ifndef MCLK_48 #define MCLK_48 (512 * 48000) -#define MIN_FREQ 44100 -#define MAX_FREQ 192000 +#endif + +#define MIN_FREQ (44100) +#define MAX_FREQ (192000) #define SPDIF_TX_INDEX 0 #define VENDOR_STR "XMOS" #define VENDOR_ID 0x20B1 @@ -26,4 +33,4 @@ #define MIC_DUAL_ENABLED 1 //Use single thread, dual PDM mic #define XUA_MIC_FRAME_SIZE 240 -#endif // __custom_defines_h__ +#endif From 36dedc494c3b7834eb3bacdfa75d540e9c5bfb40 Mon Sep 17 00:00:00 2001 From: xross Date: Thu, 21 Jul 2022 13:10:38 +0100 Subject: [PATCH 04/17] Update to latest test_support api --- tests/conftest.py | 3 +- tests/runtests.py | 23 ------- tests/test_i2s_loopback.py | 132 +++++++++---------------------------- 3 files changed, 34 insertions(+), 124 deletions(-) delete mode 100755 tests/runtests.py diff --git a/tests/conftest.py b/tests/conftest.py index c302dd8d6..3bd56ac4f 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,7 +1,8 @@ import pytest + def pytest_addoption(parser): - parser.addoption("--enabletracing", action="store_true", default=False, help="Enable xsim tracing") + pass @pytest.fixture diff --git a/tests/runtests.py b/tests/runtests.py deleted file mode 100755 index 0fbc7f5d7..000000000 --- a/tests/runtests.py +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env python2.7 -# Copyright 2018-2021 XMOS LIMITED. -# This Software is subject to the terms of the XMOS Public Licence: Version 1. -import xmostest -import os.path - -if __name__ == "__main__": - - - xmostest.init() - - xmostest.register_group("lib_xua", - "i2s_loopback_sim_tests", - "I2S loopback simulator tests", - - """ -Tests are performed by running the audiohub code connected to a -loopback plugin -""") - - xmostest.runtests() - - xmostest.finish() diff --git a/tests/test_i2s_loopback.py b/tests/test_i2s_loopback.py index dc521d547..1dff4101b 100644 --- a/tests/test_i2s_loopback.py +++ b/tests/test_i2s_loopback.py @@ -10,50 +10,9 @@ def test_file(request): return str(request.node.fspath) -def create_if_needed(folder): - if not os.path.exists(folder): - os.makedirs(folder) - return folder - - -def get_sim_args(testname, desc, options): - sim_args = [] - - if options.enabletracing: - log_folder = create_if_needed("logs") - - filename = "{log}/xsim_trace_{test}_{desc}".format( - log=log_folder, - test=testname, - desc=desc, - ) - - sim_args += [ - "--trace-to", - "{0}.txt".format(filename), - "--enable-fnop-tracing", - ] - - vcd_args = "-o {0}.vcd".format(filename) - vcd_args += ( - " -tile tile[0] -ports -ports-detailed -instructions" - " -functions -cycles -clock-blocks -pads -cores -usb" - ) - - sim_args += ["--vcd-tracing", vcd_args] - - return sim_args - - -def run_on_simulator(xe, simthreads, **kwargs): - for k in ["do_xe_prebuild", "build_env", "clean_before_build"]: - if k in kwargs: - kwargs.pop(k) - - Pyxsim.run_with_pyxsim(xe, simthreads, **kwargs) - - -def do_test(pcm_format, i2s_role, channel_count, sample_rate, test_file, capfd, options): +def do_test( + pcm_format, i2s_role, channel_count, sample_rate, test_file, options, capfd +): build_options = [] output = [] @@ -62,65 +21,38 @@ def do_test(pcm_format, i2s_role, channel_count, sample_rate, test_file, capfd, desc = f"simulation_{pcm_format}_{i2s_role}_{channel_count}in_{channel_count}out_{sample_rate}" binary = f"{testname}/bin/{desc}/{testname}_{desc}.xe" - build_success, _ = Pyxsim._build( - binary, do_clean=False, build_options=build_options - ) + tester = testers.ComparisonTester(open("pass.expect")) - if build_success: - - tester = testers.ComparisonTester( - open("pass.expect"), - "lib_xua", - "xua_sim_tests", - testname, - { - "speed": "500MHz", - "arch": "XS2", - }, # TODO run tests on XS3 and other core freqs + loopback_args = ( + "-port tile[0] XS1_PORT_1M 1 0 -port tile[0] XS1_PORT_1I 1 0 " + + "-port tile[0] XS1_PORT_1N 1 0 -port tile[0] XS1_PORT_1J 1 0 " + + "-port tile[0] XS1_PORT_1O 1 0 -port tile[0] XS1_PORT_1K 1 0 " + + "-port tile[0] XS1_PORT_1P 1 0 -port tile[0] XS1_PORT_1L 1 0 " + + "-port tile[0] XS1_PORT_1A 1 0 -port tile[0] XS1_PORT_1F 1 0 " + ) + if i2s_role == "slave": + loopback_args += ( + "-port tile[0] XS1_PORT_1B 1 0 -port tile[0] XS1_PORT_1H 1 0 " # bclk ) - - loopback_args = ( - "-port tile[0] XS1_PORT_1M 1 0 -port tile[0] XS1_PORT_1I 1 0 " - + "-port tile[0] XS1_PORT_1N 1 0 -port tile[0] XS1_PORT_1J 1 0 " - + "-port tile[0] XS1_PORT_1O 1 0 -port tile[0] XS1_PORT_1K 1 0 " - + "-port tile[0] XS1_PORT_1P 1 0 -port tile[0] XS1_PORT_1L 1 0 " - + "-port tile[0] XS1_PORT_1A 1 0 -port tile[0] XS1_PORT_1F 1 0 " + loopback_args += ( + "-port tile[0] XS1_PORT_1C 1 0 -port tile[0] XS1_PORT_1G 1 0 " # lrclk ) - if i2s_role == "slave": - loopback_args += ( - "-port tile[0] XS1_PORT_1B 1 0 -port tile[0] XS1_PORT_1H 1 0 " # bclk - ) - loopback_args += ( - "-port tile[0] XS1_PORT_1C 1 0 -port tile[0] XS1_PORT_1G 1 0 " # lrclk - ) - max_cycles = 1500000 # enough to reach the 10 skip + 100 test in sim at 48kHz + max_cycles = 1500000 # enough to reach the 10 skip + 100 test in sim at 48kHz - simargs = get_sim_args(testname, desc, options) - simargs = simargs + [ - "--max-cycles", - str(max_cycles), - "--plugin", - "LoopbackPort.dll", - loopback_args, - ] + simargs = [ + "--max-cycles", + str(max_cycles), + "--plugin", + "LoopbackPort.dll", + loopback_args, + ] - simthreads = [] - run_on_simulator(binary, simthreads, simargs=simargs) - - cap_output, err = capfd.readouterr() - output.append(cap_output.split("\n")) - - sys.stdout.write("\n") - - results = Pyxsim.run_tester(output, [tester]) - - return results - - else: - print("Build Failed") + result = Pyxsim.run_on_simulator( + binary, simthreads=[], tester=tester, simargs=simargs, capfd=capfd + ) - return [False] + return result @pytest.mark.parametrize("i2s_role", ["master", "slave"]) @@ -128,7 +60,7 @@ def do_test(pcm_format, i2s_role, channel_count, sample_rate, test_file, capfd, @pytest.mark.parametrize("channel_count", [2, 8, 16]) @pytest.mark.parametrize("sample_rate", ["48khz", "192khz"]) def test_i2s_loopback( - i2s_role, pcm_format, channel_count, sample_rate, test_file, capfd, options + i2s_role, pcm_format, channel_count, sample_rate, test_file, options, capfd ): if pcm_format == "i2s" and channel_count == 16: @@ -140,8 +72,8 @@ def test_i2s_loopback( if pcm_format == "tdm" and sample_rate == "192khz": pytest.skip("Invalid parameter combination") - results = do_test( - pcm_format, i2s_role, channel_count, sample_rate, test_file, capfd, options + result = do_test( + pcm_format, i2s_role, channel_count, sample_rate, test_file, options, capfd ) - assert results[0] + assert result From a0f5591e0bc945675d1bc041cde7e094474f4265 Mon Sep 17 00:00:00 2001 From: xross Date: Thu, 21 Jul 2022 13:10:47 +0100 Subject: [PATCH 05/17] Auto-format via black --- tests/xua_unit_tests/conftest.py | 72 +++++++++++------- .../xua_unit_tests/generate_unity_runners.py | 76 +++++++++++-------- 2 files changed, 88 insertions(+), 60 deletions(-) diff --git a/tests/xua_unit_tests/conftest.py b/tests/xua_unit_tests/conftest.py index e2e1a54a1..aa9612b08 100644 --- a/tests/xua_unit_tests/conftest.py +++ b/tests/xua_unit_tests/conftest.py @@ -6,16 +6,17 @@ import pytest import subprocess -target = os.environ.get('TARGET', 'all_possible') +target = os.environ.get("TARGET", "all_possible") print("target = ", target) + def pytest_collect_file(parent, path): - if(path.ext == ".xe"): - if(target == 'all_possible'): + if path.ext == ".xe": + if target == "all_possible": return UnityTestSource.from_parent(parent, fspath=path) - if(target == 'XCOREAI' and ('xcoreai' in path.basename)): + if target == "XCOREAI" and ("xcoreai" in path.basename): return UnityTestSource.from_parent(parent, fspath=path) - if(target == 'XCORE200' and ('xcore200' in path.basename)): + if target == "XCORE200" and ("xcore200" in path.basename): return UnityTestSource.from_parent(parent, fspath=path) @@ -31,7 +32,7 @@ def collect(self): # |-- src/ <- Unity test functions # `-- wscript <- Build system file used to generate/build runners xe_name = ((os.path.basename(self.name)).split("."))[0] + ".xe" - test_bin_path = os.path.join('bin', xe_name) + test_bin_path = os.path.join("bin", xe_name) yield UnityTestExecutable.from_parent(self, name=self.name) @@ -46,12 +47,16 @@ def runtest(self): simulator_fail = False test_output = None try: - if('xcore200' in self.name): + if "xcore200" in self.name: print("run axe for executable ", self.name) - test_output = subprocess.check_output(['axe', self.name], text=True) + test_output = subprocess.check_output(["axe", self.name], text=True) else: print("run xrun for executable ", self.name) - test_output = subprocess.check_output(['xrun', '--io', '--id', '0', self.name], text=True, stderr=subprocess.STDOUT) + test_output = subprocess.check_output( + ["xrun", "--io", "--id", "0", self.name], + text=True, + stderr=subprocess.STDOUT, + ) except subprocess.CalledProcessError as e: # Unity exits non-zero if an assertion fails simulator_fail = True @@ -59,10 +64,10 @@ def runtest(self): # Parse the Unity output unity_pass = False - test_output = test_output.split('\n') + test_output = test_output.split("\n") for line in test_output: - if 'test' in line: - test_report = line.split(':') + if "test" in line: + test_report = line.split(":") # Unity output is as follows: # :::PASS # :::FAIL: @@ -71,34 +76,43 @@ def runtest(self): test_case = test_report[2] result = test_report[3] failure_reason = None - print(('\n {}()'.format(test_case)), end=' ') - if result == 'PASS': + print(("\n {}()".format(test_case)), end=" ") + if result == "PASS": unity_pass = True continue - if result == 'FAIL': + if result == "FAIL": failure_reason = test_report[4] - print('') # Insert line break after test_case print - raise UnityTestException(self, {'test_source': test_source, - 'line_number': line_number, - 'test_case': test_case, - 'failure_reason': - failure_reason}) + print("") # Insert line break after test_case print + raise UnityTestException( + self, + { + "test_source": test_source, + "line_number": line_number, + "test_case": test_case, + "failure_reason": failure_reason, + }, + ) if simulator_fail: raise Exception(self, "Simulation failed.") if not unity_pass: raise Exception(self, "Unity test output not found.") - print('') # Insert line break after final test_case which passed + print("") # Insert line break after final test_case which passed def repr_failure(self, excinfo): if isinstance(excinfo.value, UnityTestException): - return '\n'.join([str(self.parent).strip('<>'), - '{}:{}:{}()'.format( - excinfo.value[1]['test_source'], - excinfo.value[1]['line_number'], - excinfo.value[1]['test_case']), - 'Failure reason:', - excinfo.value[1]['failure_reason']]) + return "\n".join( + [ + str(self.parent).strip("<>"), + "{}:{}:{}()".format( + excinfo.value[1]["test_source"], + excinfo.value[1]["line_number"], + excinfo.value[1]["test_case"], + ), + "Failure reason:", + excinfo.value[1]["failure_reason"], + ] + ) else: return str(excinfo.value) diff --git a/tests/xua_unit_tests/generate_unity_runners.py b/tests/xua_unit_tests/generate_unity_runners.py index f2fe0f047..9b3ccf0da 100644 --- a/tests/xua_unit_tests/generate_unity_runners.py +++ b/tests/xua_unit_tests/generate_unity_runners.py @@ -5,36 +5,39 @@ import subprocess import sys -UNITY_TEST_DIR = 'src' -UNITY_TEST_PREFIX = 'test_' -UNITY_RUNNER_DIR = 'runners' -UNITY_RUNNER_SUFFIX = '_Runner' -project_root = os.path.join('..', '..', '..') +UNITY_TEST_DIR = "src" +UNITY_TEST_PREFIX = "test_" +UNITY_RUNNER_DIR = "runners" +UNITY_RUNNER_SUFFIX = "_Runner" +project_root = os.path.join("..", "..", "..") + def get_ruby(): """ Check ruby is avaliable and return the command to invoke it. """ - interpreter_name = 'ruby' + interpreter_name = "ruby" try: - dev_null = open(os.devnull, 'w') + dev_null = open(os.devnull, "w") # Call the version command to check the interpreter can be run - subprocess.check_call([interpreter_name, '--version'], - stdout=dev_null, - close_fds=True) + subprocess.check_call( + [interpreter_name, "--version"], stdout=dev_null, close_fds=True + ) except OSError as e: print("Failed to run Ruby interpreter: {}".format(e), file=sys.stderr) exit(1) # TODO: Check this is the correct way to kill xwaf on error return interpreter_name + def get_unity_runner_generator(project_root_path): """ Check the Unity generate_test_runner script is avaliable, and return the path to it. """ unity_runner_generator = os.path.join( - project_root_path, 'Unity', 'auto', 'generate_test_runner.rb') + project_root_path, "Unity", "auto", "generate_test_runner.rb" + ) if not os.path.exists(unity_runner_generator): print("Unity repo not found in workspace", file=sys.stderr) exit(1) # TODO: Check this is the correct way to kill xwaf on error @@ -52,32 +55,41 @@ def get_file_type(filename): """ Return the extension from the filename. """ - return filename.rsplit('.')[-1:][0] + return filename.rsplit(".")[-1:][0] -def generate_unity_runner(project_root_path, unity_test_path, unity_runner_dir, - unity_runner_suffix): +def generate_unity_runner( + project_root_path, unity_test_path, unity_runner_dir, unity_runner_suffix +): """ Invoke the Unity runner generation script for the given test file, and return the path to the generated file. The output directory will be created if it does not already exist. """ - runner_path = os.path.join(os.path.join(unity_runner_dir, get_test_name(unity_test_path))) + runner_path = os.path.join( + os.path.join(unity_runner_dir, get_test_name(unity_test_path)) + ) if not os.path.exists(runner_path): os.makedirs(runner_path) unity_runner_path = os.path.join( - runner_path, get_test_name(unity_test_path) + unity_runner_suffix - + '.' + 'c') + runner_path, get_test_name(unity_test_path) + unity_runner_suffix + "." + "c" + ) try: - subprocess.check_call([get_ruby(), - get_unity_runner_generator(project_root_path), - unity_test_path, - unity_runner_path]) + subprocess.check_call( + [ + get_ruby(), + get_unity_runner_generator(project_root_path), + unity_test_path, + unity_runner_path, + ] + ) except OSError as e: - print("Ruby generator failed for {}\n\t{}".format(unity_test_path, e), - file=sys.stderr) + print( + "Ruby generator failed for {}\n\t{}".format(unity_test_path, e), + file=sys.stderr, + ) exit(1) # TODO: Check this is the correct way to kill xwaf on error @@ -86,7 +98,7 @@ def find_unity_test_paths(unity_test_dir, unity_test_prefix): Return a list of all file paths with the unity_test_prefix found in the unity_test_dir. """ - return glob.glob(os.path.join(unity_test_dir, unity_test_prefix+'*')) + return glob.glob(os.path.join(unity_test_dir, unity_test_prefix + "*")) def find_unity_tests(unity_test_dir, unity_test_prefix): @@ -95,25 +107,27 @@ def find_unity_tests(unity_test_dir, unity_test_prefix): unity_test_prefix found in the unity_test_dir. """ unity_test_paths = find_unity_test_paths(unity_test_dir, unity_test_prefix) - print('unity_test_paths = ', unity_test_paths) - return {get_test_name(path): get_file_type(path) - for path in unity_test_paths} + print("unity_test_paths = ", unity_test_paths) + return {get_test_name(path): get_file_type(path) for path in unity_test_paths} + def find_unity_test_paths(unity_test_dir, unity_test_prefix): """ Return a list of all file paths with the unity_test_prefix found in the unity_test_dir. """ - return glob.glob(os.path.join(unity_test_dir, unity_test_prefix+'*')) + return glob.glob(os.path.join(unity_test_dir, unity_test_prefix + "*")) def generate_runners(): UNITY_TESTS = find_unity_tests(UNITY_TEST_DIR, UNITY_TEST_PREFIX) - print('UNITY_TESTS = ',UNITY_TESTS) + print("UNITY_TESTS = ", UNITY_TESTS) unity_test_paths = find_unity_test_paths(UNITY_TEST_DIR, UNITY_TEST_PREFIX) - print('unity_test_paths = ',unity_test_paths) + print("unity_test_paths = ", unity_test_paths) for unity_test_path in unity_test_paths: - generate_unity_runner(project_root, unity_test_path, UNITY_RUNNER_DIR, UNITY_RUNNER_SUFFIX) + generate_unity_runner( + project_root, unity_test_path, UNITY_RUNNER_DIR, UNITY_RUNNER_SUFFIX + ) if __name__ == "__main__": From 9fdacb290341a1f79d66ab8a53d3bb7ec324a085 Mon Sep 17 00:00:00 2001 From: xross Date: Thu, 28 Jul 2022 14:15:16 +0100 Subject: [PATCH 06/17] Remove some use of global resources --- lib_xua/src/core/audiohub/xua_audiohub.xc | 5 ++--- lib_xua/src/core/ports/audioports.c | 7 +++---- lib_xua/src/core/ports/audioports.h | 13 ++++++++----- lib_xua/src/core/ports/audioports.xc | 10 ++++------ 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/lib_xua/src/core/audiohub/xua_audiohub.xc b/lib_xua/src/core/audiohub/xua_audiohub.xc index 5c9ce4e5a..7cec6750b 100755 --- a/lib_xua/src/core/audiohub/xua_audiohub.xc +++ b/lib_xua/src/core/audiohub/xua_audiohub.xc @@ -789,12 +789,11 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk, null, p_dsd_clk, #endif - divide, curSamFreq, dsdMode); + p_mclk_in, clk_audio_bclk, divide, curSamFreq, dsdMode); } else #endif { - ConfigAudioPortsWrapper( #if (I2S_CHANS_DAC != 0) p_i2s_dac, @@ -813,7 +812,7 @@ void XUA_AudioHub(chanend ?c_aud, clock ?clk_audio_mclk, clock ?clk_audio_bclk, p_bclk, #endif #endif - divide, curSamFreq, dsdMode); + p_mclk_in, clk_audio_bclk, divide, curSamFreq, dsdMode); } diff --git a/lib_xua/src/core/ports/audioports.c b/lib_xua/src/core/ports/audioports.c index 64795ba0b..6c86344bb 100644 --- a/lib_xua/src/core/ports/audioports.c +++ b/lib_xua/src/core/ports/audioports.c @@ -1,4 +1,4 @@ -// Copyright 2013-2021 XMOS LIMITED. +// Copyright 2013-2022 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #include @@ -6,7 +6,6 @@ #include #undef __ASSEMBLER__ #include "audioports.h" -#include #include "xua.h" /* Note since DSD ports could be reused for I2S ports we do all the setup manually in C */ @@ -46,7 +45,7 @@ void ConfigAudioPortsWrapper( port p_lrclk, port p_bclk, #endif -unsigned int divide, unsigned curSamFreq, unsigned int dsdMode) + port p_mclk_in, clock clk_audio_bclk, unsigned int divide, unsigned curSamFreq, unsigned int dsdMode) { ConfigAudioPorts( #if (I2S_CHANS_DAC != 0) || (DSD_CHANS_DAC != 0) @@ -61,6 +60,6 @@ unsigned int divide, unsigned curSamFreq, unsigned int dsdMode) p_lrclk, p_bclk, #endif - divide, curSamFreq); + p_mclk_in, clk_audio_bclk, divide, curSamFreq); } diff --git a/lib_xua/src/core/ports/audioports.h b/lib_xua/src/core/ports/audioports.h index 5f01fd9c7..d0db02125 100644 --- a/lib_xua/src/core/ports/audioports.h +++ b/lib_xua/src/core/ports/audioports.h @@ -1,9 +1,12 @@ -// Copyright 2011-2021 XMOS LIMITED. +// Copyright 2011-2022 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef _AUDIOPORTS_H_ #define _AUDIOPORTS_H_ #include +#ifdef __STDC__ +typedef unsigned clock; +#endif #include "xua.h" #ifdef __XC__ @@ -28,7 +31,7 @@ void ConfigAudioPorts( in port p_bclk, #endif #endif - unsigned int divide, unsigned int curSamFreq); + in port p_mclk_in, clock clk_audio_bclk, unsigned int divide, unsigned int curSamFreq); #else void ConfigAudioPorts( @@ -51,7 +54,7 @@ void ConfigAudioPorts( port p_bclk, #endif #endif - unsigned int divide, unsigned int curSamFreq); + port p_mclk_in, clock clk_audio_bclk, unsigned int divide, unsigned int curSamFreq); #endif /* __XC__*/ @@ -76,7 +79,7 @@ void ConfigAudioPortsWrapper( buffered in port:32 p_bclk, #endif #endif - unsigned int divide, unsigned curSamFreq, unsigned int dsdMode); + in port p_mclk_in, clock clk_audio_bclk, unsigned int divide, unsigned curSamFreq, unsigned int dsdMode); #else void ConfigAudioPortsWrapper( @@ -92,7 +95,7 @@ void ConfigAudioPortsWrapper( port p_lrclk, port p_bclk, #endif - unsigned int divide, unsigned curSamFreq, unsigned int dsdMode); + port p_mclk_in, clock clk_audio_bclk, unsigned int divide, unsigned curSamFreq, unsigned int dsdMode); #endif /* __XC__*/ diff --git a/lib_xua/src/core/ports/audioports.xc b/lib_xua/src/core/ports/audioports.xc index 1f40b89e8..cf282747c 100644 --- a/lib_xua/src/core/ports/audioports.xc +++ b/lib_xua/src/core/ports/audioports.xc @@ -1,4 +1,4 @@ -// Copyright 2011-2021 XMOS LIMITED. +// Copyright 2011-2022 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #include #include @@ -6,11 +6,9 @@ #include "xua.h" #include "audioports.h" - - -extern in port p_mclk_in; +//extern in port p_mclk_in; extern clock clk_audio_mclk; -extern clock clk_audio_bclk; +//extern clock clk_audio_bclk; void ConfigAudioPorts( #if (I2S_CHANS_DAC != 0) || (DSD_CHANS_DAC != 0) @@ -32,7 +30,7 @@ void ConfigAudioPorts( in port p_bclk, #endif #endif -unsigned int divide, unsigned curSamFreq) + in port p_mclk_in, clock clk_audio_bclk, unsigned int divide, unsigned curSamFreq) { #if (I2S_CHANS_DAC != 0) || (I2S_CHANS_ADC != 0) From 4f36ce4df7a5d26c980042cf893fac5f9de94b8a Mon Sep 17 00:00:00 2001 From: xross Date: Wed, 3 Aug 2022 15:11:26 +0100 Subject: [PATCH 07/17] * Sync mode: added basic move to internal clock when SOF clock not available (not change over on plug event is not smooth) * Sync mode: Removed use of float --- lib_xua/src/core/buffer/ep/ep_buffer.xc | 31 ++++++++++++++++++++----- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/lib_xua/src/core/buffer/ep/ep_buffer.xc b/lib_xua/src/core/buffer/ep/ep_buffer.xc index d5d4db320..ec96c1f3e 100644 --- a/lib_xua/src/core/buffer/ep/ep_buffer.xc +++ b/lib_xua/src/core/buffer/ep/ep_buffer.xc @@ -3,8 +3,7 @@ #include "xua.h" #if XUA_USB_EN #include -#include - +#include #ifdef MIDI #include "usb_midi.h" @@ -357,7 +356,17 @@ void XUA_Buffer_Ep(register chanend c_aud_out, #endif #endif - timer tmr; +#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) +#define LOCAL_CLOCK_INCREMENT 100000 /* 500Hz */ +#define LOCAL_CLOCK_MARGIN 1000 + int sofClockValid = 0; + timer t_sofCheck; + unsigned timeLastEdge; + unsigned timeNextEdge; + t_sofCheck :> timeLastEdge; + timeNextEdge + LOCAL_CLOCK_INCREMENT; + i_pll_ref.toggle(); +#endif while(1) { @@ -501,6 +510,14 @@ void XUA_Buffer_Ep(register chanend c_aud_out, SET_SHARED_GLOBAL(g_freqChange_flag, cmd); /* Set Flag */ } break; +#if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) + case t_sofCheck when timerafter(timeNextEdge) :> void: + i_pll_ref.toggle(); + timeLastEdge = timeNextEdge; + timeNextEdge += LOCAL_CLOCK_INCREMENT; + break; +#endif + } #define MASK_16_13 (7) /* Bits that should not be transmitted as part of feedback */ @@ -517,12 +534,11 @@ void XUA_Buffer_Ep(register chanend c_aud_out, int framesPerSec; GET_SHARED_GLOBAL(usbSpeed, g_curUsbSpeed); static int sofCount = 0; - static unsigned syncPinVal = 0; framesPerSec = (usbSpeed == XUD_SPEED_HS) ? 8000 : 1000; - float float_clocks = (float) sampleFreq/framesPerSec ; - clocks = (unsigned) (float_clocks * (1 << 16)); + clocks = ((int64_t) sampleFreq << 16) / framesPerSec; + asm volatile("stw %0, dp[g_speed]"::"r"(clocks)); sofCount += 1000; @@ -530,7 +546,9 @@ void XUA_Buffer_Ep(register chanend c_aud_out, { /* Port is accessed via interface to allow flexibilty with location */ i_pll_ref.toggle(); + t_sofCheck :> timeLastEdge; sofCount = 0; + timeNextEdge = timeLastEdge + LOCAL_CLOCK_INCREMENT + LOCAL_CLOCK_MARGIN; } #else @@ -889,6 +907,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out, case XUD_SetData_Select(c_hid, ep_hid, result): hid_ready_flag = 0U; unsigned reportTime; + timer tmr; tmr :> reportTime; hidCaptureReportTime(hid_ready_id, reportTime); hidCalcNextReportTime(hid_ready_id); From 2b679d157245c9e279c2925a747cef3cf1dc0e9f Mon Sep 17 00:00:00 2001 From: xross Date: Wed, 3 Aug 2022 15:11:49 +0100 Subject: [PATCH 08/17] Slight tidy to clockgen --- lib_xua/src/core/clocking/clockgen.xc | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/lib_xua/src/core/clocking/clockgen.xc b/lib_xua/src/core/clocking/clockgen.xc index cf3137c78..855ad2301 100644 --- a/lib_xua/src/core/clocking/clockgen.xc +++ b/lib_xua/src/core/clocking/clockgen.xc @@ -490,20 +490,14 @@ void clockGen (streaming chanend ?c_spdif_rx, chanend ?c_adat_rx, client interfa timeNextClockDetection = timeNextEdge + (LOCAL_CLOCK_INCREMENT/2); timeNextEdge += LOCAL_CLOCK_INCREMENT; - /* If we are in an external clock mode and this fire, then clock invalid */ - + /* If we are in an external clock mode and this fire, then clock invalid + * reset counters in case we are moved to digital clock - we want a well timed + * first edge */ #if (XUA_SPDIF_RX_EN) - // if(clkMode == CLOCK_SPDIF) - { - /* We must have lost valid S/PDIF stream, reset counters, so we dont produce a double edge */ - spdifCounters.receivedSamples = 0; - } + spdifCounters.receivedSamples = 0; #endif #if ADAT_RX - //if(clkMode == CLOCK_ADAT) - { - adatCounters.receivedSamples = 0; - } + adatCounters.receivedSamples = 0; #endif #ifdef CLOCK_VALIDITY_CALL From 43c561c831321b679becfd0489fb51ee0c404428 Mon Sep 17 00:00:00 2001 From: xross Date: Wed, 3 Aug 2022 15:12:12 +0100 Subject: [PATCH 09/17] Add tracing related options to conftest --- tests/conftest.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 3bd56ac4f..f91274406 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -2,8 +2,19 @@ def pytest_addoption(parser): - pass - + parser.addoption( + "--enabletracing", + action="store_true", + default=False, + help="Run tests with instruction tracing", + ) + + parser.addoption( + "--enablevcdtracing", + action="store_true", + default=False, + help="Run tests with vcd tracing", + ) @pytest.fixture def options(request): From 2b1909757b08dab378b08981784d7e01c63d1d28 Mon Sep 17 00:00:00 2001 From: xross Date: Wed, 3 Aug 2022 16:45:15 +0100 Subject: [PATCH 10/17] Sync related timing defines can now be overridden --- lib_xua/src/core/buffer/ep/ep_buffer.xc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/lib_xua/src/core/buffer/ep/ep_buffer.xc b/lib_xua/src/core/buffer/ep/ep_buffer.xc index ec96c1f3e..73ee2768b 100644 --- a/lib_xua/src/core/buffer/ep/ep_buffer.xc +++ b/lib_xua/src/core/buffer/ep/ep_buffer.xc @@ -357,8 +357,12 @@ void XUA_Buffer_Ep(register chanend c_aud_out, #endif #if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) -#define LOCAL_CLOCK_INCREMENT 100000 /* 500Hz */ -#define LOCAL_CLOCK_MARGIN 1000 +#ifndef LOCAL_CLOCK_INCREMENT +#define LOCAL_CLOCK_INCREMENT (100000) /* 500Hz */ +#endif +#ifndef LOCAL_CLOCK_MARGIN +#define LOCAL_CLOCK_MARGIN (1000) +#endif int sofClockValid = 0; timer t_sofCheck; unsigned timeLastEdge; @@ -510,6 +514,7 @@ void XUA_Buffer_Ep(register chanend c_aud_out, SET_SHARED_GLOBAL(g_freqChange_flag, cmd); /* Set Flag */ } break; + } #if (XUA_SYNCMODE == XUA_SYNCMODE_SYNC) case t_sofCheck when timerafter(timeNextEdge) :> void: i_pll_ref.toggle(); @@ -518,8 +523,6 @@ void XUA_Buffer_Ep(register chanend c_aud_out, break; #endif - } - #define MASK_16_13 (7) /* Bits that should not be transmitted as part of feedback */ #define MASK_16_10 (127) /* For Audio 1.0 we use a mask 1 bit longer than expected to avoid Windows LSB issues */ /* (previously used 63 instead of 127) */ From 2c01f440fd15a07cce152c3b2cd483953d095ea2 Mon Sep 17 00:00:00 2001 From: xross Date: Wed, 3 Aug 2022 16:50:28 +0100 Subject: [PATCH 11/17] Added basic test for PLL reference generation on Sync mode --- .gitignore | 4 + tests/test_sync.py | 49 +++++++++ tests/test_sync/Makefile | 9 ++ tests/test_sync/src/debug_conf.h | 9 ++ tests/test_sync/src/main.xc | 160 ++++++++++++++++++++++++++++ tests/test_sync/src/test_xs3_600.xn | 24 +++++ tests/test_sync/src/usb_device.h | 25 +++++ tests/test_sync/src/xua_conf.h | 44 ++++++++ 8 files changed, 324 insertions(+) create mode 100644 tests/test_sync.py create mode 100644 tests/test_sync/Makefile create mode 100644 tests/test_sync/src/debug_conf.h create mode 100644 tests/test_sync/src/main.xc create mode 100644 tests/test_sync/src/test_xs3_600.xn create mode 100644 tests/test_sync/src/usb_device.h create mode 100644 tests/test_sync/src/xua_conf.h diff --git a/.gitignore b/.gitignore index 979a2930d..0cffca237 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,7 @@ build/ .build* *.pyc xscope.xmt + +# Traces +*.gtkw +*.vcd diff --git a/tests/test_sync.py b/tests/test_sync.py new file mode 100644 index 000000000..45c9ae22e --- /dev/null +++ b/tests/test_sync.py @@ -0,0 +1,49 @@ +import pytest +import Pyxsim +from Pyxsim import testers +import os +import sys + + +@pytest.fixture() +def test_file(request): + return str(request.node.fspath) + + +def do_test(test_file, options, capfd): + + testname, _ = os.path.splitext(os.path.basename(test_file)) + + binary = f"{testname}/bin/{testname}.xe" + + tester = testers.ComparisonTester(open("pass.expect")) + + loopback_args = ( + "-port tile[0] XS1_PORT_1M 1 0 -port tile[0] XS1_PORT_1I 1 0 " + + "-port tile[0] XS1_PORT_1N 1 0 -port tile[0] XS1_PORT_1J 1 0 " + + "-port tile[0] XS1_PORT_1O 1 0 -port tile[0] XS1_PORT_1K 1 0 " + + "-port tile[0] XS1_PORT_1P 1 0 -port tile[0] XS1_PORT_1L 1 0 " + + "-port tile[0] XS1_PORT_1A 1 0 -port tile[0] XS1_PORT_1B 1 0 " + ) + + + max_cycles = 15000000 # enough to reach the 10 skip + 100 test in sim at 48kHz + + simargs = [ + "--max-cycles", + str(max_cycles), + "--plugin", + "LoopbackPort.dll", + loopback_args, + ] + + result = Pyxsim.run_on_simulator(binary, tester=tester, simargs=simargs, capfd=capfd, instTracing=options.enabletracing, vcdTracing=options.enablevcdtracing) + + return result + + +def test_sync(test_file, options, capfd): + + result = do_test(test_file, options, capfd) + + assert result diff --git a/tests/test_sync/Makefile b/tests/test_sync/Makefile new file mode 100644 index 000000000..e175efbae --- /dev/null +++ b/tests/test_sync/Makefile @@ -0,0 +1,9 @@ + +XCC_FLAGS = -O3 -g -DXUD_CORE_CLOCK=600 -save-temps -DUSB_TILE=tile[0] -DLOCAL_CLOCK_INCREMENT=10000 -DLOCAL_CLOCK_MARGIN=100 + +TARGET = test_xs3_600.xn + +USED_MODULES = lib_xua lib_xud lib_logging + +XMOS_MAKE_PATH ?= ../.. +-include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common diff --git a/tests/test_sync/src/debug_conf.h b/tests/test_sync/src/debug_conf.h new file mode 100644 index 000000000..aadb00147 --- /dev/null +++ b/tests/test_sync/src/debug_conf.h @@ -0,0 +1,9 @@ +// Copyright 2016-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. +#ifndef __debug_conf_h__ +#define __debug_conf_h__ + +#define DEBUG_PRINT_ENABLE_MAIN 1 +#define DEBUG_PRINT_ENABLE_AUDIO_IO 0 + +#endif // __debug_conf_h__ diff --git a/tests/test_sync/src/main.xc b/tests/test_sync/src/main.xc new file mode 100644 index 000000000..12c6509d0 --- /dev/null +++ b/tests/test_sync/src/main.xc @@ -0,0 +1,160 @@ +// Copyright 2022 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. + +/* Simples test to ensure reference clock to CS2100 device continues when SOF clock not available + * Note, this test uses "nice" numbers and it doesn't check for graceful change over from internal to SOF clock + */ + +#include "platform.h" +#include "xua.h" +#include "uac_hwresources.h" +#include "print.h" + +#define EP_COUNT_IN 3 +#define EP_COUNT_OUT 3 + +out port p_pll_ref = XS1_PORT_1A; +in port p_off_mclk = XS1_PORT_1M; +in port p_pll_loop = XS1_PORT_1B; + +/* Purely for debug/viewing on VCD */ +out port p_test = XS1_PORT_1C; + +/* To speed this test up we divide all delays by 10. This is also the case for the delays in the clock generation code */ +#define SOF_PERIOD_TICKS (12500/10) + +void exit(int); + +void delay(unsigned d) +{ + timer t; + unsigned time; + t :> time; + t when timerafter(time + d) :> int x; +} + +/* From lib_xud */ +void SetupEndpoints(chanend c_ep_out[], int noEpOut, chanend c_ep_in[], int noEpIn, XUD_EpType epTypeTableOut[], XUD_EpType epTypeTableIn[]); + +void AudioHwInit() +{ + return; +} + +void AudioHwConfig(unsigned samFreq, unsigned mClk, unsigned dsdMode, + unsigned sampRes_DAC, unsigned sampRes_ADC) +{ + return; +} + +void driveSofs(chanend c_sof, int count) +{ + static int sof = 0; + for(int i = 0; i < count; i++) + { + outuint(c_sof, sof++); + delay(SOF_PERIOD_TICKS); + } +} + +void fake_xud(chanend c_out[], chanend c_in[], chanend c_sof) +{ + timer t; + unsigned time; + + p_test <: 1; + + /* Makes traces a bit nicer to look at */ + t :> time; + t when timerafter(SOF_PERIOD_TICKS * 2) :> int x; + + /* Endpoint type tables */ + XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_ISO, XUD_EPTYPE_DIS}; + XUD_EpType epTypeTableIn[EP_COUNT_IN] = {XUD_EPTYPE_CTL, XUD_EPTYPE_ISO, XUD_EPTYPE_ISO}; + + SetupEndpoints(c_out, EP_COUNT_OUT, c_in, EP_COUNT_IN, epTypeTableOut, epTypeTableIn); + + driveSofs(c_sof, 24); + + p_test <: 0; + /* Sim missing SOFs */ + delay(SOF_PERIOD_TICKS*8); + p_test <: 1; + + driveSofs(c_sof, 16); + + p_test <: 0; +} + +extern XUD_BusSpeed_t g_curUsbSpeed; + +#define MARGIN (1500/10) +#define EXPECTED_PERIOD (100000/10) // Test runs as HS - so 8 * 125000 + +void checker() +{ + timer t; + unsigned t0, t1; + unsigned x = 0; + + int fail = 0; + + p_pll_loop when pinseq(1) :> x; + p_pll_loop when pinseq(0) :> x; + p_pll_loop when pinseq(1) :> x; + + for(int i = 0; i < 8; i++) + { + p_pll_loop when pinsneq(x) :> x; + t :> t0; + p_pll_loop when pinsneq(x) :> x; + t :> t1; + + int period = t1-t0; + + if(period > (EXPECTED_PERIOD + MARGIN)) + { + printstr("Period too long: "); + printintln(period); + fail = 1; + } + else if(period < (EXPECTED_PERIOD - MARGIN)) + { + printstr("Period too short: "); + printintln(period); + fail = 1; + } + } + if(!fail) + printstrln("PASS"); + + exit(0); +} + + +int main() +{ + chan c_out[EP_COUNT_OUT]; + chan c_in[EP_COUNT_IN]; + chan c_sof; + chan c_aud_ctl; + + interface pll_ref_if i_pll_ref; + + par + { + PllRefPinTask(i_pll_ref, p_pll_ref); + + { + g_curUsbSpeed = XUD_SPEED_HS; + XUA_Buffer_Ep(c_out[1], /* USB Audio Out*/ + c_in[1], /* USB Audio In */ + c_sof, c_aud_ctl, p_off_mclk, i_pll_ref + ); + } + + fake_xud(c_out, c_in, c_sof); + + checker(); + } +} diff --git a/tests/test_sync/src/test_xs3_600.xn b/tests/test_sync/src/test_xs3_600.xn new file mode 100644 index 000000000..20e8eeb65 --- /dev/null +++ b/tests/test_sync/src/test_xs3_600.xn @@ -0,0 +1,24 @@ + + + + tileref tile[2] + + + + + + + + + + + + + + + + + + diff --git a/tests/test_sync/src/usb_device.h b/tests/test_sync/src/usb_device.h new file mode 100644 index 000000000..1f5aaa895 --- /dev/null +++ b/tests/test_sync/src/usb_device.h @@ -0,0 +1,25 @@ +// Copyright 2016-2021 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. +#ifndef __usb_device_h__ +#define __usb_device_h__ + +#include +#include +#include "usb_std_requests.h" +#include "xud.h" + +XUD_Result_t USB_GetSetupPacket(XUD_ep ep_out, XUD_ep ep_in, REFERENCE_PARAM(USB_SetupPacket_t, sp)); + +XUD_Result_t USB_StandardRequests(XUD_ep ep_out, XUD_ep ep_in, + NULLABLE_ARRAY_OF(unsigned char, devDesc_hs), int devDescLength_hs, + NULLABLE_ARRAY_OF(unsigned char, cfgDesc_hs), int cfgDescLength_hs, + NULLABLE_ARRAY_OF(unsigned char, devDesc_fs), int devDescLength_fs, + NULLABLE_ARRAY_OF(unsigned char, cfgDesc_fs), int cfgDescLength_fs, +#ifdef __XC__ + char * unsafe strDescs[], +#else + char * strDescs[], +#endif + int strDescsLength, REFERENCE_PARAM(USB_SetupPacket_t, sp), XUD_BusSpeed_t usbBusSpeed); + +#endif // __usb_device_h__ diff --git a/tests/test_sync/src/xua_conf.h b/tests/test_sync/src/xua_conf.h new file mode 100644 index 000000000..616262b77 --- /dev/null +++ b/tests/test_sync/src/xua_conf.h @@ -0,0 +1,44 @@ +// Copyright 2016-2022 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. +#ifndef _XUA_CONF_H_ +#define _XUA_CONF_H_ + +#define NUM_USB_CHAN_OUT (2) +#define NUM_USB_CHAN_IN (2) +#define I2S_CHANS_DAC (2) +#define I2S_CHANS_ADC (2) + +#define XUA_SYNCMODE XUA_SYNCMODE_SYNC +#define UAC_FORCE_FEEDBACK_EP (0) + +#define EXCLUDE_USB_AUDIO_MAIN +#define XUA_NUM_PDM_MICS 0 +#define XUD_TILE 1 +#define AUDIO_IO_TILE 0 +#define MIXER 0 + +#ifndef MCLK_441 +#define MCLK_441 (512 * 44100) +#endif + +#ifndef MCLK_48 +#define MCLK_48 (512 * 48000) +#endif + +#define MIN_FREQ (44100) +#define MAX_FREQ (192000) +#define SPDIF_TX_INDEX 0 +#define VENDOR_STR "XMOS" +#define VENDOR_ID 0x20B1 +#define PRODUCT_STR_A2 "Test device" +#define PRODUCT_STR_A1 "Test device" +#define PID_AUDIO_1 1 +#define PID_AUDIO_2 2 +#define AUDIO_CLASS 2 +#define AUDIO_CLASS_FALLBACK 0 +#define BCD_DEVICE 0x1234 +#define XUA_DFU_EN 0 +#define MIC_DUAL_ENABLED 1 //Use single thread, dual PDM mic +#define XUA_MIC_FRAME_SIZE 240 + +#endif From 3a9f2fff3a3c9762f262cf42004e19c3a04c9038 Mon Sep 17 00:00:00 2001 From: xross Date: Wed, 3 Aug 2022 17:25:32 +0100 Subject: [PATCH 12/17] * Renamed test_sync to test_sync_clk_basic * Authored test for known issue in sync mode, test_sync_clk_plugin * Removed some unrequired test related files --- tests/test_sync/src/debug_conf.h | 9 ---- tests/test_sync/src/usb_device.h | 25 ----------- .../{test_sync.py => test_sync_clk_basic.py} | 2 +- .../Makefile | 6 ++- .../src/main.xc | 13 ++++-- .../src/test_xs3_600.xn | 0 .../src/xua_conf.h | 0 tests/test_sync_clk_plugin.py | 19 ++++++++ tests/test_sync_clk_plugin/Makefile | 3 ++ tests/test_sync_clk_plugin/src/main.xc | 2 + .../test_sync_clk_plugin/src/test_xs3_600.xn | 24 ++++++++++ tests/test_sync_clk_plugin/src/xua_conf.h | 44 +++++++++++++++++++ 12 files changed, 107 insertions(+), 40 deletions(-) delete mode 100644 tests/test_sync/src/debug_conf.h delete mode 100644 tests/test_sync/src/usb_device.h rename tests/{test_sync.py => test_sync_clk_basic.py} (95%) rename tests/{test_sync => test_sync_clk_basic}/Makefile (62%) rename tests/{test_sync => test_sync_clk_basic}/src/main.xc (91%) rename tests/{test_sync => test_sync_clk_basic}/src/test_xs3_600.xn (100%) rename tests/{test_sync => test_sync_clk_basic}/src/xua_conf.h (100%) create mode 100644 tests/test_sync_clk_plugin.py create mode 100644 tests/test_sync_clk_plugin/Makefile create mode 100644 tests/test_sync_clk_plugin/src/main.xc create mode 100644 tests/test_sync_clk_plugin/src/test_xs3_600.xn create mode 100644 tests/test_sync_clk_plugin/src/xua_conf.h diff --git a/tests/test_sync/src/debug_conf.h b/tests/test_sync/src/debug_conf.h deleted file mode 100644 index aadb00147..000000000 --- a/tests/test_sync/src/debug_conf.h +++ /dev/null @@ -1,9 +0,0 @@ -// Copyright 2016-2021 XMOS LIMITED. -// This Software is subject to the terms of the XMOS Public Licence: Version 1. -#ifndef __debug_conf_h__ -#define __debug_conf_h__ - -#define DEBUG_PRINT_ENABLE_MAIN 1 -#define DEBUG_PRINT_ENABLE_AUDIO_IO 0 - -#endif // __debug_conf_h__ diff --git a/tests/test_sync/src/usb_device.h b/tests/test_sync/src/usb_device.h deleted file mode 100644 index 1f5aaa895..000000000 --- a/tests/test_sync/src/usb_device.h +++ /dev/null @@ -1,25 +0,0 @@ -// Copyright 2016-2021 XMOS LIMITED. -// This Software is subject to the terms of the XMOS Public Licence: Version 1. -#ifndef __usb_device_h__ -#define __usb_device_h__ - -#include -#include -#include "usb_std_requests.h" -#include "xud.h" - -XUD_Result_t USB_GetSetupPacket(XUD_ep ep_out, XUD_ep ep_in, REFERENCE_PARAM(USB_SetupPacket_t, sp)); - -XUD_Result_t USB_StandardRequests(XUD_ep ep_out, XUD_ep ep_in, - NULLABLE_ARRAY_OF(unsigned char, devDesc_hs), int devDescLength_hs, - NULLABLE_ARRAY_OF(unsigned char, cfgDesc_hs), int cfgDescLength_hs, - NULLABLE_ARRAY_OF(unsigned char, devDesc_fs), int devDescLength_fs, - NULLABLE_ARRAY_OF(unsigned char, cfgDesc_fs), int cfgDescLength_fs, -#ifdef __XC__ - char * unsafe strDescs[], -#else - char * strDescs[], -#endif - int strDescsLength, REFERENCE_PARAM(USB_SetupPacket_t, sp), XUD_BusSpeed_t usbBusSpeed); - -#endif // __usb_device_h__ diff --git a/tests/test_sync.py b/tests/test_sync_clk_basic.py similarity index 95% rename from tests/test_sync.py rename to tests/test_sync_clk_basic.py index 45c9ae22e..1b01b0493 100644 --- a/tests/test_sync.py +++ b/tests/test_sync_clk_basic.py @@ -42,7 +42,7 @@ def do_test(test_file, options, capfd): return result -def test_sync(test_file, options, capfd): +def test_sync_clk_basic(test_file, options, capfd): result = do_test(test_file, options, capfd) diff --git a/tests/test_sync/Makefile b/tests/test_sync_clk_basic/Makefile similarity index 62% rename from tests/test_sync/Makefile rename to tests/test_sync_clk_basic/Makefile index e175efbae..274573d69 100644 --- a/tests/test_sync/Makefile +++ b/tests/test_sync_clk_basic/Makefile @@ -1,9 +1,11 @@ -XCC_FLAGS = -O3 -g -DXUD_CORE_CLOCK=600 -save-temps -DUSB_TILE=tile[0] -DLOCAL_CLOCK_INCREMENT=10000 -DLOCAL_CLOCK_MARGIN=100 +TEST_FLAGS ?= + +XCC_FLAGS = -O3 -g -DXUD_CORE_CLOCK=600 -save-temps -DUSB_TILE=tile[0] -DLOCAL_CLOCK_INCREMENT=10000 -DLOCAL_CLOCK_MARGIN=100 $(TEST_FLAGS) TARGET = test_xs3_600.xn -USED_MODULES = lib_xua lib_xud lib_logging +USED_MODULES = lib_xua XMOS_MAKE_PATH ?= ../.. -include $(XMOS_MAKE_PATH)/xcommon/module_xcommon/build/Makefile.common diff --git a/tests/test_sync/src/main.xc b/tests/test_sync_clk_basic/src/main.xc similarity index 91% rename from tests/test_sync/src/main.xc rename to tests/test_sync_clk_basic/src/main.xc index 12c6509d0..658644218 100644 --- a/tests/test_sync/src/main.xc +++ b/tests/test_sync_clk_basic/src/main.xc @@ -15,7 +15,7 @@ out port p_pll_ref = XS1_PORT_1A; in port p_off_mclk = XS1_PORT_1M; -in port p_pll_loop = XS1_PORT_1B; +in port p_pll_loop = XS1_PORT_1B; /* Note, this is externally looped back using the loopback plugin */ /* Purely for debug/viewing on VCD */ out port p_test = XS1_PORT_1C; @@ -23,6 +23,10 @@ out port p_test = XS1_PORT_1C; /* To speed this test up we divide all delays by 10. This is also the case for the delays in the clock generation code */ #define SOF_PERIOD_TICKS (12500/10) +#ifndef MISSING_SOFS +#define MISSING SOFS (8) +#endif + void exit(int); void delay(unsigned d) @@ -74,11 +78,13 @@ void fake_xud(chanend c_out[], chanend c_in[], chanend c_sof) SetupEndpoints(c_out, EP_COUNT_OUT, c_in, EP_COUNT_IN, epTypeTableOut, epTypeTableIn); - driveSofs(c_sof, 24); + driveSofs(c_sof, 32); p_test <: 0; + /* Sim missing SOFs */ - delay(SOF_PERIOD_TICKS*8); + delay(SOF_PERIOD_TICKS*MISSING_SOFS); + p_test <: 1; driveSofs(c_sof, 16); @@ -112,6 +118,7 @@ void checker() int period = t1-t0; + /* Check the period of the reference clock we are generating */ if(period > (EXPECTED_PERIOD + MARGIN)) { printstr("Period too long: "); diff --git a/tests/test_sync/src/test_xs3_600.xn b/tests/test_sync_clk_basic/src/test_xs3_600.xn similarity index 100% rename from tests/test_sync/src/test_xs3_600.xn rename to tests/test_sync_clk_basic/src/test_xs3_600.xn diff --git a/tests/test_sync/src/xua_conf.h b/tests/test_sync_clk_basic/src/xua_conf.h similarity index 100% rename from tests/test_sync/src/xua_conf.h rename to tests/test_sync_clk_basic/src/xua_conf.h diff --git a/tests/test_sync_clk_plugin.py b/tests/test_sync_clk_plugin.py new file mode 100644 index 000000000..628484e81 --- /dev/null +++ b/tests/test_sync_clk_plugin.py @@ -0,0 +1,19 @@ +import pytest +import Pyxsim +from Pyxsim import testers +import os +import sys + +from test_sync_clk_basic import do_test + +@pytest.fixture() +def test_file(request): + return str(request.node.fspath) + +def test_sync_clk_plugin(test_file, options, capfd): + + #pytest.xfail("This is a known failure due to issue #275") + + result = do_test(test_file, options, capfd) + + assert result diff --git a/tests/test_sync_clk_plugin/Makefile b/tests/test_sync_clk_plugin/Makefile new file mode 100644 index 000000000..e02143c8b --- /dev/null +++ b/tests/test_sync_clk_plugin/Makefile @@ -0,0 +1,3 @@ +TEST_FLAGS = -DMISSING_SOFS=4 + +include ../test_sync_clk_basic/Makefile diff --git a/tests/test_sync_clk_plugin/src/main.xc b/tests/test_sync_clk_plugin/src/main.xc new file mode 100644 index 000000000..b968732b9 --- /dev/null +++ b/tests/test_sync_clk_plugin/src/main.xc @@ -0,0 +1,2 @@ + +#include "../test_sync_clk_basic/src/main.xc" diff --git a/tests/test_sync_clk_plugin/src/test_xs3_600.xn b/tests/test_sync_clk_plugin/src/test_xs3_600.xn new file mode 100644 index 000000000..20e8eeb65 --- /dev/null +++ b/tests/test_sync_clk_plugin/src/test_xs3_600.xn @@ -0,0 +1,24 @@ + + + + tileref tile[2] + + + + + + + + + + + + + + + + + + diff --git a/tests/test_sync_clk_plugin/src/xua_conf.h b/tests/test_sync_clk_plugin/src/xua_conf.h new file mode 100644 index 000000000..616262b77 --- /dev/null +++ b/tests/test_sync_clk_plugin/src/xua_conf.h @@ -0,0 +1,44 @@ +// Copyright 2016-2022 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. +#ifndef _XUA_CONF_H_ +#define _XUA_CONF_H_ + +#define NUM_USB_CHAN_OUT (2) +#define NUM_USB_CHAN_IN (2) +#define I2S_CHANS_DAC (2) +#define I2S_CHANS_ADC (2) + +#define XUA_SYNCMODE XUA_SYNCMODE_SYNC +#define UAC_FORCE_FEEDBACK_EP (0) + +#define EXCLUDE_USB_AUDIO_MAIN +#define XUA_NUM_PDM_MICS 0 +#define XUD_TILE 1 +#define AUDIO_IO_TILE 0 +#define MIXER 0 + +#ifndef MCLK_441 +#define MCLK_441 (512 * 44100) +#endif + +#ifndef MCLK_48 +#define MCLK_48 (512 * 48000) +#endif + +#define MIN_FREQ (44100) +#define MAX_FREQ (192000) +#define SPDIF_TX_INDEX 0 +#define VENDOR_STR "XMOS" +#define VENDOR_ID 0x20B1 +#define PRODUCT_STR_A2 "Test device" +#define PRODUCT_STR_A1 "Test device" +#define PID_AUDIO_1 1 +#define PID_AUDIO_2 2 +#define AUDIO_CLASS 2 +#define AUDIO_CLASS_FALLBACK 0 +#define BCD_DEVICE 0x1234 +#define XUA_DFU_EN 0 +#define MIC_DUAL_ENABLED 1 //Use single thread, dual PDM mic +#define XUA_MIC_FRAME_SIZE 240 + +#endif From 5690442a4b2e2408c5c241dc7d4bd80fc05acd16 Mon Sep 17 00:00:00 2001 From: xross Date: Thu, 4 Aug 2022 19:54:29 +0100 Subject: [PATCH 13/17] - test_sync_clk_basic and test_sync_clk_plugin now run at FS & HS - test_sync_clk_plugin marked as known failure (now fails as expected for HS and FS) --- tests/conftest.py | 3 +- tests/test_sync_clk_basic.py | 19 ++++-- tests/test_sync_clk_basic/Makefile | 8 ++- tests/test_sync_clk_basic/src/main.xc | 83 +++++++++++++++++--------- tests/test_sync_clk_plugin.py | 19 ++---- tests/test_sync_clk_plugin/Makefile | 3 +- tests/test_sync_clk_plugin/src/main.xc | 4 ++ 7 files changed, 89 insertions(+), 50 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index f91274406..c444de09e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -8,7 +8,7 @@ def pytest_addoption(parser): default=False, help="Run tests with instruction tracing", ) - + parser.addoption( "--enablevcdtracing", action="store_true", @@ -16,6 +16,7 @@ def pytest_addoption(parser): help="Run tests with vcd tracing", ) + @pytest.fixture def options(request): yield request.config.option diff --git a/tests/test_sync_clk_basic.py b/tests/test_sync_clk_basic.py index 1b01b0493..8332f6c66 100644 --- a/tests/test_sync_clk_basic.py +++ b/tests/test_sync_clk_basic.py @@ -10,11 +10,11 @@ def test_file(request): return str(request.node.fspath) -def do_test(test_file, options, capfd): +def do_test(bus_speed, test_file, options, capfd): testname, _ = os.path.splitext(os.path.basename(test_file)) - binary = f"{testname}/bin/{testname}.xe" + binary = f"{testname}/bin/{bus_speed}/{testname}_{bus_speed}.xe" tester = testers.ComparisonTester(open("pass.expect")) @@ -25,7 +25,6 @@ def do_test(test_file, options, capfd): + "-port tile[0] XS1_PORT_1P 1 0 -port tile[0] XS1_PORT_1L 1 0 " + "-port tile[0] XS1_PORT_1A 1 0 -port tile[0] XS1_PORT_1B 1 0 " ) - max_cycles = 15000000 # enough to reach the 10 skip + 100 test in sim at 48kHz @@ -37,13 +36,21 @@ def do_test(test_file, options, capfd): loopback_args, ] - result = Pyxsim.run_on_simulator(binary, tester=tester, simargs=simargs, capfd=capfd, instTracing=options.enabletracing, vcdTracing=options.enablevcdtracing) + result = Pyxsim.run_on_simulator( + binary, + tester=tester, + simargs=simargs, + capfd=capfd, + instTracing=options.enabletracing, + vcdTracing=options.enablevcdtracing, + ) return result -def test_sync_clk_basic(test_file, options, capfd): +@pytest.mark.parametrize("bus_speed", ["FS", "HS"]) +def test_sync_clk_basic(bus_speed, test_file, options, capfd): - result = do_test(test_file, options, capfd) + result = do_test(bus_speed, test_file, options, capfd) assert result diff --git a/tests/test_sync_clk_basic/Makefile b/tests/test_sync_clk_basic/Makefile index 274573d69..513f26140 100644 --- a/tests/test_sync_clk_basic/Makefile +++ b/tests/test_sync_clk_basic/Makefile @@ -1,7 +1,13 @@ TEST_FLAGS ?= -XCC_FLAGS = -O3 -g -DXUD_CORE_CLOCK=600 -save-temps -DUSB_TILE=tile[0] -DLOCAL_CLOCK_INCREMENT=10000 -DLOCAL_CLOCK_MARGIN=100 $(TEST_FLAGS) +XCC_FLAGS_HS = -O3 -g -DXUD_CORE_CLOCK=600 -save-temps -DUSB_TILE=tile[0] -DLOCAL_CLOCK_INCREMENT=10000 -DLOCAL_CLOCK_MARGIN=100 \ + -DBUS_SPEED=2 \ + $(TEST_FLAGS) + +XCC_FLAGS_FS = -O3 -g -DXUD_CORE_CLOCK=600 -save-temps -DUSB_TILE=tile[0] -DLOCAL_CLOCK_INCREMENT=10000 -DLOCAL_CLOCK_MARGIN=100 \ + -DBUS_SPEED=1 \ + $(TEST_FLAGS) TARGET = test_xs3_600.xn diff --git a/tests/test_sync_clk_basic/src/main.xc b/tests/test_sync_clk_basic/src/main.xc index 658644218..6a7531e82 100644 --- a/tests/test_sync_clk_basic/src/main.xc +++ b/tests/test_sync_clk_basic/src/main.xc @@ -1,30 +1,44 @@ // Copyright 2022 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. -/* Simples test to ensure reference clock to CS2100 device continues when SOF clock not available - * Note, this test uses "nice" numbers and it doesn't check for graceful change over from internal to SOF clock +/* Simple test to ensure reference clock to CS2100 device continues when SOF clock not available + * Note, this test uses "nice" numbers (i.e. MISSIG_SOFS %8 == 0) and therefore doesn't check + * for a graceful change over from internal to SOF clock */ #include "platform.h" #include "xua.h" -#include "uac_hwresources.h" #include "print.h" +#include "xud.h" -#define EP_COUNT_IN 3 -#define EP_COUNT_OUT 3 +#define EP_COUNT_IN (3) +#define EP_COUNT_OUT (3) -out port p_pll_ref = XS1_PORT_1A; -in port p_off_mclk = XS1_PORT_1M; -in port p_pll_loop = XS1_PORT_1B; /* Note, this is externally looped back using the loopback plugin */ +out port p_pll_ref = XS1_PORT_1A; +in port p_off_mclk = XS1_PORT_1M; +in port p_pll_loop = XS1_PORT_1B; /* Note, this is externally looped back using the loopback plugin */ /* Purely for debug/viewing on VCD */ -out port p_test = XS1_PORT_1C; +out port p_test0 = XS1_PORT_1C; +out port p_test1 = XS1_PORT_1D; + +#ifndef BUS_SPEED +#error BUS_SPEED should be defined +#endif /* To speed this test up we divide all delays by 10. This is also the case for the delays in the clock generation code */ -#define SOF_PERIOD_TICKS (12500/10) +#if(BUS_SPEED == 2) // XUD_SPEED_HS + #define SOF_PERIOD_TICKS (12500/10) + #define SOF_DIVIDE (1) +#else + #define SOF_PERIOD_TICKS ((12500*8)/10) + #define SOF_DIVIDE (8) +#endif -#ifndef MISSING_SOFS -#define MISSING SOFS (8) +#ifndef MISSING_SOF_PERIOD +/* By default skip a whole number of SOF periods (easy case) + * Note, app_test_sync_plugin/Makefiles sets this to something more nasty */ +#define MISSING_SOF_PERIOD (8 * SOF_PERIOD_TICKS) #endif void exit(int); @@ -45,18 +59,19 @@ void AudioHwInit() return; } -void AudioHwConfig(unsigned samFreq, unsigned mClk, unsigned dsdMode, - unsigned sampRes_DAC, unsigned sampRes_ADC) +void AudioHwConfig(unsigned samFreq, unsigned mClk, unsigned dsdMode, unsigned sampRes_DAC, unsigned sampRes_ADC) { return; } void driveSofs(chanend c_sof, int count) { - static int sof = 0; + static int frame = 0; + + /* For HS frame should only increment every 8 SOFs, but this is a "dont care" */ for(int i = 0; i < count; i++) { - outuint(c_sof, sof++); + outuint(c_sof, frame++); delay(SOF_PERIOD_TICKS); } } @@ -66,11 +81,12 @@ void fake_xud(chanend c_out[], chanend c_in[], chanend c_sof) timer t; unsigned time; - p_test <: 1; /* Makes traces a bit nicer to look at */ t :> time; t when timerafter(SOF_PERIOD_TICKS * 2) :> int x; + + p_test0 <: 1; /* Endpoint type tables */ XUD_EpType epTypeTableOut[EP_COUNT_OUT] = {XUD_EPTYPE_CTL, XUD_EPTYPE_ISO, XUD_EPTYPE_DIS}; @@ -78,38 +94,48 @@ void fake_xud(chanend c_out[], chanend c_in[], chanend c_sof) SetupEndpoints(c_out, EP_COUNT_OUT, c_in, EP_COUNT_IN, epTypeTableOut, epTypeTableIn); - driveSofs(c_sof, 32); + driveSofs(c_sof, 32/SOF_DIVIDE); - p_test <: 0; + p_test0 <: 0; /* Sim missing SOFs */ - delay(SOF_PERIOD_TICKS*MISSING_SOFS); + delay(MISSING_SOF_PERIOD); + + p_test0 <: 1; + + driveSofs(c_sof, 16/SOF_DIVIDE); - p_test <: 1; + p_test0 <: 0; - driveSofs(c_sof, 16); + delay(MISSING_SOF_PERIOD); + + p_test0 <: 1; + + driveSofs(c_sof, 16/SOF_DIVIDE); + + p_test0 <: 0; - p_test <: 0; } extern XUD_BusSpeed_t g_curUsbSpeed; #define MARGIN (1500/10) -#define EXPECTED_PERIOD (100000/10) // Test runs as HS - so 8 * 125000 +#define EXPECTED_PERIOD (100000/10) void checker() { timer t; unsigned t0, t1; unsigned x = 0; - int fail = 0; + p_test1 <: 1; + p_pll_loop when pinseq(1) :> x; p_pll_loop when pinseq(0) :> x; p_pll_loop when pinseq(1) :> x; - for(int i = 0; i < 8; i++) + for(int i = 0; i < 12; i++) { p_pll_loop when pinsneq(x) :> x; t :> t0; @@ -135,6 +161,8 @@ void checker() if(!fail) printstrln("PASS"); + p_test1 <: 0; + exit(0); } @@ -153,7 +181,8 @@ int main() PllRefPinTask(i_pll_ref, p_pll_ref); { - g_curUsbSpeed = XUD_SPEED_HS; + g_curUsbSpeed = BUS_SPEED; + XUA_Buffer_Ep(c_out[1], /* USB Audio Out*/ c_in[1], /* USB Audio In */ c_sof, c_aud_ctl, p_off_mclk, i_pll_ref diff --git a/tests/test_sync_clk_plugin.py b/tests/test_sync_clk_plugin.py index 628484e81..8da6c8c2d 100644 --- a/tests/test_sync_clk_plugin.py +++ b/tests/test_sync_clk_plugin.py @@ -1,19 +1,10 @@ import pytest -import Pyxsim -from Pyxsim import testers -import os -import sys - from test_sync_clk_basic import do_test +from test_sync_clk_basic import test_file -@pytest.fixture() -def test_file(request): - return str(request.node.fspath) - -def test_sync_clk_plugin(test_file, options, capfd): - - #pytest.xfail("This is a known failure due to issue #275") - - result = do_test(test_file, options, capfd) +@pytest.mark.parametrize("bus_speed", ["FS", "HS"]) +def test_sync_clk_plugin(bus_speed, test_file, options, capfd): + pytest.xfail("This is a known failure due to issue #275") + result = do_test(bus_speed, test_file, options, capfd) assert result diff --git a/tests/test_sync_clk_plugin/Makefile b/tests/test_sync_clk_plugin/Makefile index e02143c8b..08eec76a0 100644 --- a/tests/test_sync_clk_plugin/Makefile +++ b/tests/test_sync_clk_plugin/Makefile @@ -1,3 +1,4 @@ -TEST_FLAGS = -DMISSING_SOFS=4 + +TEST_FLAGS = -DMISSING_SOF_PERIOD=7500 include ../test_sync_clk_basic/Makefile diff --git a/tests/test_sync_clk_plugin/src/main.xc b/tests/test_sync_clk_plugin/src/main.xc index b968732b9..f6e3d50a2 100644 --- a/tests/test_sync_clk_plugin/src/main.xc +++ b/tests/test_sync_clk_plugin/src/main.xc @@ -1,2 +1,6 @@ +/* This tests for a smooth transition from internal to SOF clock. + * Unlike test_sync_clk_basic it does not use a "nice" value for MISSING_SOFS + */ + #include "../test_sync_clk_basic/src/main.xc" From b17cc0de6d6841ae707b41b3e8a26d5372aad382 Mon Sep 17 00:00:00 2001 From: xross Date: Mon, 8 Aug 2022 11:15:50 +0100 Subject: [PATCH 14/17] Copyright and licence comments --- tests/conftest.py | 2 ++ tests/test_i2s_loopback.py | 2 ++ tests/test_i2s_loopback/debug_conf.h | 2 +- tests/test_i2s_loopback/usb_device.h | 2 +- tests/test_i2s_loopback/usb_device.xc | 2 +- tests/test_i2s_loopback/xk_216_mc/cs2100.h | 2 +- tests/test_i2s_loopback/xk_216_mc/cs4384.h | 2 +- tests/test_i2s_loopback/xk_216_mc/cs5368.h | 2 +- tests/test_i2s_loopback/xk_216_mc/gpio_access.c | 2 +- tests/test_i2s_loopback/xk_216_mc/gpio_access.h | 2 +- tests/test_sync_clk_basic.py | 2 ++ tests/test_sync_clk_plugin.py | 2 ++ tests/test_sync_clk_plugin/src/main.xc | 2 ++ tests/xua_unit_tests/conftest.py | 2 +- tests/xua_unit_tests/generate_unity_runners.py | 2 +- 15 files changed, 20 insertions(+), 10 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index c444de09e..f5cca7f75 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -1,3 +1,5 @@ +# Copyright 2022 XMOS LIMITED. +# This Software is subject to the terms of the XMOS Public Licence: Version 1. import pytest diff --git a/tests/test_i2s_loopback.py b/tests/test_i2s_loopback.py index 1dff4101b..48693d610 100644 --- a/tests/test_i2s_loopback.py +++ b/tests/test_i2s_loopback.py @@ -1,3 +1,5 @@ +# Copyright 2018-2022 XMOS LIMITED. +# This Software is subject to the terms of the XMOS Public Licence: Version 1. import pytest import Pyxsim from Pyxsim import testers diff --git a/tests/test_i2s_loopback/debug_conf.h b/tests/test_i2s_loopback/debug_conf.h index aadb00147..11cedc164 100644 --- a/tests/test_i2s_loopback/debug_conf.h +++ b/tests/test_i2s_loopback/debug_conf.h @@ -1,4 +1,4 @@ -// Copyright 2016-2021 XMOS LIMITED. +// Copyright 2016-2022 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef __debug_conf_h__ #define __debug_conf_h__ diff --git a/tests/test_i2s_loopback/usb_device.h b/tests/test_i2s_loopback/usb_device.h index 1f5aaa895..9d21df47f 100644 --- a/tests/test_i2s_loopback/usb_device.h +++ b/tests/test_i2s_loopback/usb_device.h @@ -1,4 +1,4 @@ -// Copyright 2016-2021 XMOS LIMITED. +// Copyright 2016-2022 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef __usb_device_h__ #define __usb_device_h__ diff --git a/tests/test_i2s_loopback/usb_device.xc b/tests/test_i2s_loopback/usb_device.xc index 7a2057350..4f755d1cd 100644 --- a/tests/test_i2s_loopback/usb_device.xc +++ b/tests/test_i2s_loopback/usb_device.xc @@ -1,4 +1,4 @@ -// Copyright 2018-2021 XMOS LIMITED. +// Copyright 2018-2022 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #if 0 #include diff --git a/tests/test_i2s_loopback/xk_216_mc/cs2100.h b/tests/test_i2s_loopback/xk_216_mc/cs2100.h index bc5a0cdda..9e2938a78 100644 --- a/tests/test_i2s_loopback/xk_216_mc/cs2100.h +++ b/tests/test_i2s_loopback/xk_216_mc/cs2100.h @@ -1,4 +1,4 @@ -// Copyright 2018-2021 XMOS LIMITED. +// Copyright 2018-2022 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #define CS2100_I2C_DEVICE_ADDR (0x9c>>1) diff --git a/tests/test_i2s_loopback/xk_216_mc/cs4384.h b/tests/test_i2s_loopback/xk_216_mc/cs4384.h index 6de83e811..34ccbc6c9 100644 --- a/tests/test_i2s_loopback/xk_216_mc/cs4384.h +++ b/tests/test_i2s_loopback/xk_216_mc/cs4384.h @@ -1,4 +1,4 @@ -// Copyright 2017-2021 XMOS LIMITED. +// Copyright 2017-2022 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef CS4384_H_ #define CS4384_H_ diff --git a/tests/test_i2s_loopback/xk_216_mc/cs5368.h b/tests/test_i2s_loopback/xk_216_mc/cs5368.h index d2de278da..ce7ed892e 100644 --- a/tests/test_i2s_loopback/xk_216_mc/cs5368.h +++ b/tests/test_i2s_loopback/xk_216_mc/cs5368.h @@ -1,4 +1,4 @@ -// Copyright 2017-2021 XMOS LIMITED. +// Copyright 2017-2022 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef _CS5368_H_ #define _CS5368_H_ diff --git a/tests/test_i2s_loopback/xk_216_mc/gpio_access.c b/tests/test_i2s_loopback/xk_216_mc/gpio_access.c index 6d302c550..64f31c44a 100644 --- a/tests/test_i2s_loopback/xk_216_mc/gpio_access.c +++ b/tests/test_i2s_loopback/xk_216_mc/gpio_access.c @@ -1,4 +1,4 @@ -// Copyright 2016-2021 XMOS LIMITED. +// Copyright 2016-2022 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifdef HARDWARE #include diff --git a/tests/test_i2s_loopback/xk_216_mc/gpio_access.h b/tests/test_i2s_loopback/xk_216_mc/gpio_access.h index 93f66fee9..3856619bd 100644 --- a/tests/test_i2s_loopback/xk_216_mc/gpio_access.h +++ b/tests/test_i2s_loopback/xk_216_mc/gpio_access.h @@ -1,4 +1,4 @@ -// Copyright 2016-2021 XMOS LIMITED. +// Copyright 2016-2022 XMOS LIMITED. // This Software is subject to the terms of the XMOS Public Licence: Version 1. #ifndef __gpio_access_h__ #define __gpio_access_h__ diff --git a/tests/test_sync_clk_basic.py b/tests/test_sync_clk_basic.py index 8332f6c66..cd2c99c44 100644 --- a/tests/test_sync_clk_basic.py +++ b/tests/test_sync_clk_basic.py @@ -1,3 +1,5 @@ +# Copyright 2022 XMOS LIMITED. +# This Software is subject to the terms of the XMOS Public Licence: Version 1. import pytest import Pyxsim from Pyxsim import testers diff --git a/tests/test_sync_clk_plugin.py b/tests/test_sync_clk_plugin.py index 8da6c8c2d..b580ece97 100644 --- a/tests/test_sync_clk_plugin.py +++ b/tests/test_sync_clk_plugin.py @@ -1,3 +1,5 @@ +# Copyright 2022 XMOS LIMITED. +# This Software is subject to the terms of the XMOS Public Licence: Version 1. import pytest from test_sync_clk_basic import do_test from test_sync_clk_basic import test_file diff --git a/tests/test_sync_clk_plugin/src/main.xc b/tests/test_sync_clk_plugin/src/main.xc index f6e3d50a2..e66994eaa 100644 --- a/tests/test_sync_clk_plugin/src/main.xc +++ b/tests/test_sync_clk_plugin/src/main.xc @@ -1,3 +1,5 @@ +// Copyright 2022 XMOS LIMITED. +// This Software is subject to the terms of the XMOS Public Licence: Version 1. /* This tests for a smooth transition from internal to SOF clock. * Unlike test_sync_clk_basic it does not use a "nice" value for MISSING_SOFS diff --git a/tests/xua_unit_tests/conftest.py b/tests/xua_unit_tests/conftest.py index aa9612b08..2128a9b7e 100644 --- a/tests/xua_unit_tests/conftest.py +++ b/tests/xua_unit_tests/conftest.py @@ -1,4 +1,4 @@ -# Copyright 2021 XMOS LIMITED. +# Copyright 2021-2022 XMOS LIMITED. # This Software is subject to the terms of the XMOS Public Licence: Version 1. from __future__ import print_function from builtins import str diff --git a/tests/xua_unit_tests/generate_unity_runners.py b/tests/xua_unit_tests/generate_unity_runners.py index 9b3ccf0da..7276d9695 100644 --- a/tests/xua_unit_tests/generate_unity_runners.py +++ b/tests/xua_unit_tests/generate_unity_runners.py @@ -1,4 +1,4 @@ -# Copyright 2021 XMOS LIMITED. +# Copyright 2021-2022 XMOS LIMITED. # This Software is subject to the terms of the XMOS Public Licence: Version 1. import glob import os.path From 5a32d60c29c09e39313a949eab1500f2b18fc131 Mon Sep 17 00:00:00 2001 From: xross Date: Mon, 8 Aug 2022 11:23:04 +0100 Subject: [PATCH 15/17] Move Jenkinsfile from xmostest to pytest --- Jenkinsfile | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Jenkinsfile b/Jenkinsfile index 047815029..63ffbd45e 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -32,7 +32,13 @@ pipeline { parallel { stage('Legacy tests') { steps { - runXmostest("${REPO}", 'legacy_tests') + dir("${REPO}/tests"){ + viewEnv(){ + withVenv{ + runPytest('--numprocesses=4') + } + } + } } } stage('Unit tests') { From dfc406e32288c23e5132c3598ca51f095865b035 Mon Sep 17 00:00:00 2001 From: xross Date: Mon, 8 Aug 2022 11:28:30 +0100 Subject: [PATCH 16/17] Update Jenkinsfile testing --- Jenkinsfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Jenkinsfile b/Jenkinsfile index 63ffbd45e..bb6f57210 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -27,10 +27,10 @@ pipeline { xcoreLibraryChecks("${REPO}") } } - stage('XS2 Tests') { + stage('Testing') { failFast true parallel { - stage('Legacy tests') { + stage('Tests') { steps { dir("${REPO}/tests"){ viewEnv(){ @@ -41,7 +41,7 @@ pipeline { } } } - stage('Unit tests') { + stage('Unity tests') { steps { dir("${REPO}") { dir('tests') { From 80e6f047ab9090e06c220bb756ac0b6cf382d3a8 Mon Sep 17 00:00:00 2001 From: xross Date: Mon, 8 Aug 2022 12:02:41 +0100 Subject: [PATCH 17/17] Add test_support to requirements --- requirements.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/requirements.txt b/requirements.txt index a9ebc4e93..b7e17c799 100644 --- a/requirements.txt +++ b/requirements.txt @@ -34,3 +34,4 @@ pytest-xdist==1.34.0 # of its own setup.py file, then this list must include an entry for that # setup.py file, e.g., '-e .' or '-e ./python' (without the quotes). -e ./python +-e ./../test_support