Commit 55591c20 authored by Federico Vaga's avatar Federico Vaga

tst: allow multiple devices

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent ef49c269
...@@ -10,6 +10,12 @@ import re ...@@ -10,6 +10,12 @@ import re
import os import os
from PyFmcTdc import FmcTdc from PyFmcTdc import FmcTdc
def pytest_generate_tests(metafunc):
if "fd_tdc_id" in metafunc.fixturenames:
metafunc.parametrize("fd_tdc_id", pytest.fd_tdc_id)
class PulseGenerator(object): class PulseGenerator(object):
def __init__(self, id): def __init__(self, id):
self.id = id self.id = id
...@@ -99,28 +105,47 @@ class FmcFineDelay(PulseGenerator): ...@@ -99,28 +105,47 @@ class FmcFineDelay(PulseGenerator):
if sync: if sync:
time.sleep(1 + 2 * (period_ns * count) / 1000000000.0) time.sleep(1 + 2 * (period_ns * count) / 1000000000.0)
@pytest.fixture(scope="module")
def fmcfd(): @pytest.fixture(scope="function")
gen = FmcFineDelay(pytest.fd_id) def tdc_and_gen(fd_tdc_id):
yield gen fd_id, tdc_id = fd_tdc_id
gen = FmcFineDelay(fd_id)
for ch in range(FmcFineDelay.CHANNEL_NUMBER): for ch in range(FmcFineDelay.CHANNEL_NUMBER):
gen.disable(ch + 1) gen.disable(ch + 1)
@pytest.fixture(scope="function") tdc = FmcTdc(tdc_id)
def fmctdc():
tdc = FmcTdc(pytest.tdc_id)
for ch in tdc.chan: for ch in tdc.chan:
ch.enable = False ch.enable = False
ch.termination = False ch.termination = False
ch.timestamp_mode = "post" ch.timestamp_mode = "post"
ch.flush() ch.flush()
yield (gen, tdc)
for ch in range(FmcFineDelay.CHANNEL_NUMBER):
gen.disable(ch + 1)
for ch in tdc.chan:
ch.enable = False
ch.termination = False
ch.timestamp_mode = "post"
ch.flush()
@pytest.fixture(scope="function")
def fmcfd(tdc_and_gen):
fd, tdc = tdc_and_gen
yield fd
@pytest.fixture(scope="function")
def fmctdc(tdc_and_gen):
fd, tdc = tdc_and_gen
yield tdc yield tdc
def pytest_addoption(parser): def pytest_addoption(parser):
parser.addoption("--tdc-id", type=lambda x : int(x, 16), parser.addoption("--tdc-id", type=lambda x : int(x, 16), action="append",
required=True, help="Fmc TDC Linux Identifier") default=[], help="Fmc TDC Linux Identifier")
parser.addoption("--fd-id", type=lambda x : int(x, 16), default=None, parser.addoption("--fd-id", type=lambda x : int(x, 16), action="append",
help="Fmc Fine-Delay Linux Identifier") default=[], help="Fmc Fine-Delay Linux Identifier")
parser.addoption("--dump-range", type=int, default=10, parser.addoption("--dump-range", type=int, default=10,
help="Timestamps to show before and after an error") help="Timestamps to show before and after an error")
parser.addoption("--channel", type=int, default=[], parser.addoption("--channel", type=int, default=[],
...@@ -144,7 +169,7 @@ def pytest_configure(config): ...@@ -144,7 +169,7 @@ def pytest_configure(config):
print("For each --fd-id there must be a --tdc-id") print("For each --fd-id there must be a --tdc-id")
raise Exception() raise Exception()
pytest.fd_tdc_id = zip(pytest.fd_id, pytest.tdc_id) pytest.fd_tdc_id = list(zip(pytest.fd_id, pytest.tdc_id))
pytest.channels = config.getoption("--channel") pytest.channels = config.getoption("--channel")
if len(pytest.channels) == 0: if len(pytest.channels) == 0:
...@@ -155,15 +180,27 @@ def pytest_configure(config): ...@@ -155,15 +180,27 @@ def pytest_configure(config):
pytest.dump_range = config.getoption("--dump-range") pytest.dump_range = config.getoption("--dump-range")
pytest.transfer_mode = None pytest.transfer_mode = None
with open("/sys/bus/zio/devices/tdc-1n5c-{:04x}/transfer-mode".format(pytest.tdc_id)) as f_mode: modes = []
mode = int(f_mode.read().rstrip()) for tdc_id in pytest.tdc_id:
for k, v in FmcTdc.TRANSFER_MODE.items(): with open(f"/sys/bus/zio/devices/tdc-1n5c-{tdc_id:04x}/transfer-mode") as f_mode:
if mode == v: modes.append(int(f_mode.read().rstrip()))
pytest.transfer_mode = k mode = set(modes)
if len(mode) != 1:
print("Inconsistent transfer mode across devices")
raise Exception()
for k, v in FmcTdc.TRANSFER_MODE.items():
if v in mode:
pytest.transfer_mode = k
pytest.carrier = None pytest.carrier = None
full_path = os.readlink("/sys/bus/zio/devices/tdc-1n5c-{:04x}".format(pytest.tdc_id)) carrs = []
for carr in ["spec", "svec"]: for tdc_id in pytest.tdc_id:
is_carr = re.search(carr, full_path) full_path = os.readlink("/sys/bus/zio/devices/tdc-1n5c-{:04x}".format(tdc_id))
if is_carr is not None: for carr in ["spec", "svec"]:
is_carr = re.search(carr, full_path)
if is_carr is None:
continue
if pytest.carrier is not None and pytest.carrier != carr:
print("Inconsistent installation mix of SPEC and SVEC")
raise Exception()
pytest.carrier = carr pytest.carrier = carr
...@@ -39,8 +39,8 @@ fmctdc_acq_100ns_svec = [(13333, 8000), # 75 kHz ...@@ -39,8 +39,8 @@ fmctdc_acq_100ns_svec = [(13333, 8000), # 75 kHz
fmctdc_acq_100ns = fmctdc_acq_100ns_svec if pytest.transfer_mode == "fifo" else fmctdc_acq_100ns_spec fmctdc_acq_100ns = fmctdc_acq_100ns_svec if pytest.transfer_mode == "fifo" else fmctdc_acq_100ns_spec
@pytest.fixture(scope="function", params=pytest.channels) @pytest.fixture(scope="function", params=pytest.channels)
def fmctdc_chan(request): def fmctdc_chan(request, fmctdc):
tdc = FmcTdc(pytest.tdc_id) tdc = fmctdc
for ch in tdc.chan: for ch in tdc.chan:
ch.enable = False ch.enable = False
tdc.chan[request.param].termination = False tdc.chan[request.param].termination = False
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment