Commit 857520ef authored by Federico Vaga's avatar Federico Vaga

tst: improve test_output_counter

This patch merges two different tests into one to speed up the entire
testing process. Then it improves the merged code.
Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 083259ec
......@@ -72,69 +72,40 @@ class TestFmcfdLoop(object):
fmcfd_tdc.flush()
assert len(fmcfd_tdc.poll(1000)) == 0
@pytest.mark.parametrize("count", [1, MAX_COUNT] +
[random.randrange(MIN_COUNT + 1,
int(MAX_COUNT / 10)) for x in range(8)])
def test_output_counter(self, fmcfd, fmcfd_chan, fmcfd_tdc, count):
"""
In pulse mode, the Fine-Delay generates the exact number of
@pytest.mark.parametrize("count, period_ps", [(i + 1, 1000000) for i in range(15)] +
[(MAX_COUNT, 4500000000)])
def test_output_counter(self, fmcfd, fmcfd_chan, fmcfd_tdc, count, period_ps):
"""In pulse mode, the Fine-Delay generates the exact number of
required pulses and we are able to read them all from the input
channel.
"""
ts = []
period_ps = 4500000000
start_s = 2
start = fmcfd.time + FmcFineDelayTime(start_s, 0, 0)
fmcfd_chan.pulse_generate(start, int(period_ps / 2), period_ps, count)
timeout = timeout_compute(start_s, period_ps, count)
while len(ts) < count and time.time() < timeout:
if len(fmcfd_tdc.poll()) == 0:
continue
try:
t = fmcfd_tdc.read(100, os.O_NONBLOCK)
except BlockingIOError:
t = fmcfd_tdc.read(100, os.O_NONBLOCK)
channel with an assigned sequential number.
assert len(t) > 0
ts = ts + t
assert len(ts) == count
assert len(fmcfd_tdc.poll(int(period_ps / 1000000000.0))) == 0
del ts
Internal TDC used a FIFO, therefore it can't handle a too fast and long
burst. Maximumg 15 pulses. On VME it is slower due to the bus: a period
of 4.5ms is the best compromise for this test.
@pytest.mark.parametrize("count", [random.randrange(1000, 10000)])
def test_input_sequence_number(self,fmcfd_chan, fmcfd_tdc, count):
"""
The input channel has time-stamps with increasing sequence number
with step 1.
We test the extremes to make the test a bit faster.
"""
period_ps = 4500000000
pending = count
ts = []
start_s = 2
start = FmcFineDelayTime(start_s, 0, 0)
fmcfd_chan.pulse_generate(fmcfd_chan.dev.time + start,
int(period_ps / 2), period_ps, count)
timeout = timeout_compute(start_s, period_ps, count)
while pending > 0 and time.time() < timeout:
if len(fmcfd_tdc.poll()) == 0:
continue
start = fmcfd.time + FmcFineDelayTime(0, 1000000, 0)
fmcfd_chan.pulse_generate(start, int(period_ps / 2), period_ps, count)
fmcfd_tdc.poll(1000)
while len(fmcfd_tdc.poll(500)) > 0:
try:
t = fmcfd_tdc.read(100, os.O_NONBLOCK)
assert len(t) > 0
ts = ts + t
except BlockingIOError:
t = fmcfd_tdc.read(100, os.O_NONBLOCK)
assert len(t) > 0
ts.extend(t)
pending -= len(t)
assert pending == 0
continue
assert len(ts) == count
assert len(fmcfd_tdc.poll(50)) == 0
prev_ts = None
for i in range(len(ts)):
if prev_ts is not None:
assert ts[i].seq_id == (prev_ts.seq_id + 1) & 0xFFFF,\
"i:{:d}, cur: {:s}, prev: {:s}".format(i, str(ts[i]),
str(prev_ts))
assert ts[i].seq_id == (prev_ts.seq_id + 1) & 0xFFFF, f"i:{i}, cur: {ts[i]}, prev: {prev_ts}"
prev_ts = ts[i]
del ts
@pytest.mark.parametrize("start_rel", [FmcFineDelayTime(0, random.randrange(1, 125000000),
0) for i in range(50)] +
......
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