|
| 1 | +"""Tests for JESD204 interfaces""" |
| 2 | + |
| 3 | +from pprint import pprint |
| 4 | +from time import sleep |
| 5 | + |
| 6 | +import pytest |
| 7 | + |
| 8 | +import adi |
| 9 | + |
| 10 | +try: |
| 11 | + import adi.jesd |
| 12 | + |
| 13 | + skip_jesd = False |
| 14 | +except: |
| 15 | + skip_jesd = True |
| 16 | + |
| 17 | + |
| 18 | +def verify_links(iio_uri: str, classname: str): |
| 19 | + """Verify that the links are up in DATA mode |
| 20 | +
|
| 21 | + Args: |
| 22 | + iio_uri (str): URI of the device |
| 23 | + classname (str): Class name of the device |
| 24 | +
|
| 25 | + Exceptions: |
| 26 | + AssertionError: If the link is not in DATA mode |
| 27 | + """ |
| 28 | + if skip_jesd: |
| 29 | + pytest.skip("JESD204 interface support not available") |
| 30 | + |
| 31 | + dev = eval(classname)(uri=iio_uri, jesd_monitor=True) |
| 32 | + status = dev._jesd.get_all_link_statuses() |
| 33 | + pprint(status) |
| 34 | + |
| 35 | + # Check that all links are in DATA mode |
| 36 | + for driver in status: |
| 37 | + for lane in status[driver]: |
| 38 | + print(f"Checking {driver}/{lane}") |
| 39 | + data = status[driver][lane] |
| 40 | + pprint(data) |
| 41 | + assert ( |
| 42 | + data["CGS state"] == "DATA" |
| 43 | + ), f"Link {driver}/{lane} is not in DATA mode" |
| 44 | + |
| 45 | + |
| 46 | +def verify_links_errors_stable(iio_uri: str, classname: str): |
| 47 | + """Verify that the links are stable and not increasing errors |
| 48 | +
|
| 49 | + Args: |
| 50 | + iio_uri (str): URI of the device |
| 51 | + classname (str): Class name of the |
| 52 | +
|
| 53 | + Exceptions: |
| 54 | + AssertionError: If the link errors have increased |
| 55 | + AssertionError: If the link is not in DATA mode |
| 56 | + """ |
| 57 | + if skip_jesd: |
| 58 | + pytest.skip("JESD204 interface support not available") |
| 59 | + |
| 60 | + dev = eval(classname)(uri=iio_uri, jesd_monitor=True) |
| 61 | + |
| 62 | + # Get error count on all lanes and links |
| 63 | + def get_link_errors(status): |
| 64 | + links = {} |
| 65 | + for driver in status: |
| 66 | + for lane in status[driver]: |
| 67 | + print(f"Checking {driver}/{lane}") |
| 68 | + data = status[driver][lane] |
| 69 | + links[f"{driver}/{lane}"] = int(data["Errors"]) |
| 70 | + return links |
| 71 | + |
| 72 | + status = dev._jesd.get_all_link_statuses() |
| 73 | + pre_link_errors = get_link_errors(status) |
| 74 | + pprint(pre_link_errors) |
| 75 | + |
| 76 | + N = 5 |
| 77 | + print(f"Waiting {N} seconds") |
| 78 | + sleep(N) |
| 79 | + |
| 80 | + status = dev._jesd.get_all_link_statuses() |
| 81 | + post_link_errors = get_link_errors(status) |
| 82 | + pprint(post_link_errors) |
| 83 | + |
| 84 | + # Check that all links have not increased in errors |
| 85 | + for link in pre_link_errors: |
| 86 | + assert ( |
| 87 | + pre_link_errors[link] == post_link_errors[link] |
| 88 | + ), f"Link {link} has increased in errors" |
0 commit comments