Commit 2b418a0c authored by Federico Vaga's avatar Federico Vaga

tst: add regression test for flat channel

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 7f4ea5bd
"""
SPDX-License-Identifier: GPL-3.0-or-later
SPDX-FileCopyrightText: 2022 CERN
"""
import os
import pytest
from PySPEC import PySPEC
import re
def get_carrier(dev_id):
sys_dev_path = os.path.join("/sys/bus/zio/devices/",
"adc-100m14b-{:04x}".format(dev_id))
r = re.search(r".*/(spec)", os.readlink(sys_dev_path))
if r is None:
Exception("Can't understand carrier type. Supported: 'spec'")
return r.group(1)
class FmcAdc100M():
def __init__(self, dev_id):
self.dev_id = dev_id
self.sys_dev_path = os.path.join("/sys/bus/zio/devices/",
"adc-100m14b-{:04x}".format(self.dev_id))
path = os.path.abspath(os.path.join(os.path.dirname(self.sys_dev_path),
os.readlink(self.sys_dev_path)))
r = re.search(r"/sys/devices/.*/(spec|svec-vme)[-.](([0-9a-f]{4}:([0-9a-f]{2}:[0-9a-f]{2}.[0-9a-f]))|[0-9]+)/",
path)
if r is None:
Exception("Can't understand carrier type. Supported: 'spec'")
if r.group(1) == "spec":
self.carrier = PySPEC(r.group(4))
elif r.group(1) == "svec-vme":
Exception("TODO implement SVEC support")
else:
Exception("Can't understand carrier type. Bad regular expression")
@pytest.fixture(scope="module")
def fmc_adc_100m():
dev = FmcAdc100M(pytest.dev_id)
yield dev
def pytest_addoption(parser):
parser.addoption("--adc-id", type=lambda x: int(x, 0),
required=True, help="ADC Identifier")
parser.addoption("--bitstream",
default=None, help="SPEC bitstream to be tested")
def pytest_configure(config):
pytest.dev_id = config.getoption("--adc-id")
pytest.cfg_bitstream = config.getoption("--bitstream")
pytest.is_spec = get_carrier(pytest.dev_id) == "spec"
# SPDX-License-Identifier: GPL-3.0-or-later
# SPDX-FileCopyrightText: 2022 CERN
[pytest]
addopts = -v -p no:cacheprovider
"""
SPDX-License-Identifier: GPL-3.0-or-later
SPDX-FileCopyrightText: 2020 CERN
"""
import os
import pytest
import time
from PySPEC import PySPEC
@pytest.mark.skipif(pytest.cfg_bitstream is None,
reason="We need a bitstream to reflash")
class TestReprogramming(object):
"""
Collection of regression tests involving carrier reflashing
"""
@pytest.mark.skipif(pytest.is_spec is False,
reason="We need a bitstream to reflash")
@pytest.mark.repeat(100)
@pytest.mark.parametrize("size", [100000])
def test_flat_signal_after_configuration_spec(self, fmc_adc_100m, size):
"""
The SPEC FPGA could be misconfgured an leading to not acquiring data
from one of the channels. The problem shows itself with a channel
delivering only zeros.
"""
spec = fmc_adc_100m.carrier
spec.program_fpga(pytest.cfg_bitstream)
for chan in range(4):
path = os.path.join(fmc_adc_100m.sys_dev_path,
"cset0/chan{:d}/current-value".format(chan))
sum = 0
with open(path) as file:
for i in range(size):
file.seek(0)
sum += int(file.read())
# Should we sleep? It is not the end of the
# world if we read twice the same value: the real issue
# is that everything is zero
assert sum != 0, "Missing data on channel {:d}".format(chan)
pytest
pytest-repeat
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