diff --git a/doc/source/dev/index.rst b/doc/source/dev/index.rst index d3eae7169..f7a68f95a 100644 --- a/doc/source/dev/index.rst +++ b/doc/source/dev/index.rst @@ -94,6 +94,7 @@ pyadi-iio has a large set of parameterizable fixtures for testing different devi test_attr test_dma test_generics + test_jesd Set Up Isolated Environment diff --git a/doc/source/dev/test_jesd.rst b/doc/source/dev/test_jesd.rst new file mode 100644 index 000000000..f769bd854 --- /dev/null +++ b/doc/source/dev/test_jesd.rst @@ -0,0 +1,7 @@ +JESD204 Tests +================= + +Functions used by test fixtures for evaluating JESD204 link states. + +.. automodule:: test.jesd_tests + :members: diff --git a/test/common.py b/test/common.py index 545033a21..2636a4c57 100644 --- a/test/common.py +++ b/test/common.py @@ -30,6 +30,7 @@ def pytest_configure(config): ) config.addinivalue_line("markers", "lvds_test: mark tests for LVDS") config.addinivalue_line("markers", "cmos_test: mark tests for CMOS") + config.addinivalue_line("markers", "jesd204: mark tests for JESD204") def pytest_collection_modifyitems(items): diff --git a/test/conftest.py b/test/conftest.py index 24907b0dc..4d5e6b82e 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -15,6 +15,7 @@ from test.generics import iio_attribute_single_value from test.globals import * from test.html import pytest_html_report_title, pytest_runtest_makereport +from test.jesd_tests import * import numpy as np import pytest @@ -302,3 +303,17 @@ def test_attribute_check_range_singleval_with_depends(request): @pytest.fixture() def test_attribute_single_value_boolean_readonly(request): yield attribute_single_value_boolean_readonly + + +######################################### +# JESD204 Fixtures + + +@pytest.fixture() +def test_verify_links(request): + yield verify_links + + +@pytest.fixture() +def test_verify_links_errors_stable(request): + yield verify_links_errors_stable diff --git a/test/jesd_tests.py b/test/jesd_tests.py new file mode 100644 index 000000000..6a5a10270 --- /dev/null +++ b/test/jesd_tests.py @@ -0,0 +1,88 @@ +"""Tests for JESD204 interfaces""" + +from pprint import pprint +from time import sleep + +import pytest + +import adi + +try: + import adi.jesd + + skip_jesd = False +except: + skip_jesd = True + + +def verify_links(iio_uri: str, classname: str): + """Verify that the links are up in DATA mode + + Args: + iio_uri (str): URI of the device + classname (str): Class name of the device + + Exceptions: + AssertionError: If the link is not in DATA mode + """ + if skip_jesd: + pytest.skip("JESD204 interface support not available") + + dev = eval(classname)(uri=iio_uri, jesd_monitor=True) + status = dev._jesd.get_all_link_statuses() + pprint(status) + + # Check that all links are in DATA mode + for driver in status: + for lane in status[driver]: + print(f"Checking {driver}/{lane}") + data = status[driver][lane] + pprint(data) + assert ( + data["CGS state"] == "DATA" + ), f"Link {driver}/{lane} is not in DATA mode" + + +def verify_links_errors_stable(iio_uri: str, classname: str): + """Verify that the links are stable and not increasing errors + + Args: + iio_uri (str): URI of the device + classname (str): Class name of the + + Exceptions: + AssertionError: If the link errors have increased + AssertionError: If the link is not in DATA mode + """ + if skip_jesd: + pytest.skip("JESD204 interface support not available") + + dev = eval(classname)(uri=iio_uri, jesd_monitor=True) + + # Get error count on all lanes and links + def get_link_errors(status): + links = {} + for driver in status: + for lane in status[driver]: + print(f"Checking {driver}/{lane}") + data = status[driver][lane] + links[f"{driver}/{lane}"] = int(data["Errors"]) + return links + + status = dev._jesd.get_all_link_statuses() + pre_link_errors = get_link_errors(status) + pprint(pre_link_errors) + + N = 5 + print(f"Waiting {N} seconds") + sleep(N) + + status = dev._jesd.get_all_link_statuses() + post_link_errors = get_link_errors(status) + pprint(post_link_errors) + + # Check that all links have not increased in errors + for link in pre_link_errors: + assert ( + pre_link_errors[link] == post_link_errors[link] + ), f"Link {link} has increased in errors" diff --git a/test/test_adrv9009_zu11eg.py b/test/test_adrv9009_zu11eg.py index 1ff0ac757..7b9ace77f 100644 --- a/test/test_adrv9009_zu11eg.py +++ b/test/test_adrv9009_zu11eg.py @@ -334,3 +334,21 @@ def test_adrv9009_zu11eg_buffer_size(iio_uri, rx_buffer_size, rx_enabled_channel else: for chan in data: assert len(chan) == rx_buffer_size + + +######################################### +# JESD204 Tests +@pytest.mark.jesd204 +@pytest.mark.iio_hardware(hardware) +@pytest.mark.parametrize("classname", [(classname)]) +def test_adrv9009_zu11eg_verify_links(test_verify_links, iio_uri, classname): + test_verify_links(iio_uri, classname) + + +@pytest.mark.jesd204 +@pytest.mark.iio_hardware(hardware) +@pytest.mark.parametrize("classname", [(classname)]) +def test_adrv9009_zu11eg_verify_links_errors_stable( + test_verify_links_errors_stable, iio_uri, classname +): + test_verify_links_errors_stable(iio_uri, classname)