Commit 417558f4 authored by Federico Vaga's avatar Federico Vaga

tst: allow users to set the slot number

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 78bc0498
......@@ -3,8 +3,47 @@ SPDX-License-Identifier: LGPL-2.1-or-later
SPDX-FileCopyrightText: 2020 CERN
"""
from pathlib import Path
import pytest
from PyFmcFineDelay import FmcFineDelay
import re
def valid_slot_type(slot):
if re.search(r"(VME|PCI)\.[0-9]+-FMC\.[0-9]+", slot) is None:
raise ValueError()
return slot
def fmcfd_id_from_slot(slot):
carrier, mezzanine = slot.split("-")
carrier_bus, carrier_slot = carrier.split(".")
carrier_slot = int(carrier_slot)
mezzanine_bus, mezzanine_slot = mezzanine.split(".")
mezzanine_slot = int(mezzanine_slot)
if carrier_bus == "PCI":
with open("/run/dynpci") as f:
for line in f.readlines():
dynslot, pciid = line.strip().split(" ")
if int(dynslot) == carrier_slot:
break
pciid = f"0000:{pciid}"
pathfmc = list(Path("/sys/bus/pci/devices").joinpath(pciid) \
.glob(f"spec-*/id:*/fmc-fdelay-tdc.*.auto/fmc-slot-*.{mezzanine_slot}"))
elif carrier_bus == "VME":
pathfmc = list(Path("/sys/bus/vme/devices").joinpath(f"slot.{carrier_slot:02d}") \
.joinpath(f"vme.{carrier_slot:02d}") \
.glob(f"svec-*/svec-*/id:*/fmc-fdelay-tdc.*.auto/fmc-slot-*.{mezzanine_slot}"))
else:
raise ValueError()
assert len(pathfmc) == 1
devname = list(Path(pathfmc[0]).parent.glob("hw-fd-*/fd-*/devname"))
assert len(devname) == 1
with open(devname[0]) as f:
fd_id = int(f.read().strip().split("-")[1], 16)
return fd_id
@pytest.fixture(scope="function")
......@@ -16,13 +55,21 @@ def fmcfd():
def pytest_addoption(parser):
parser.addoption("--fd-id", type=lambda x : int(x, 16),
required=True, help="Fmc Fine-Delay Linux Identifier")
default=None, help="Fmc Fine-Delay Linux Identifier")
parser.addoption("--slot", type=valid_slot_type,
default=None, help="Fmc Fine-Delay absolute slot (works only for SPEC and SVEC)")
parser.addoption("--channel", type=int, default=[],
action="append", choices=range(FmcFineDelay.CHANNEL_NUMBER),
help="Channel(s) to be used for acquisition tests. Default all channels")
def pytest_configure(config):
pytest.fd_id = config.getoption("--fd-id")
if pytest.fd_id is None:
pytest.slot = config.getoption("--slot")
if pytest.slot is None:
print("Missing argument --fd-id or --slot")
raise Exception()
pytest.fd_id = fmcfd_id_from_slot(pytest.slot)
pytest.channels = config.getoption("--channel")
if len(pytest.channels) == 0:
pytest.channels = range(FmcFineDelay.CHANNEL_NUMBER)
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