Commit 2723db59 authored by Federico Vaga's avatar Federico Vaga

tst: randomize parameters and periods shortening

Values were already a random developer choice. Make it really random
insted of always testing the same numbers.

The periods are shorter in some tests otherwise it takes too long to
test.

Better use of parameters
Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 90325d5f
......@@ -8,6 +8,8 @@ import select
import time
import os
from PyFmcFineDelay import FmcFineDelay, FmcFineDelayTime
import random
@pytest.fixture(scope="function")
def fmcfd():
......@@ -17,12 +19,17 @@ def fmcfd():
yield fd
for ch in fd.chan:
ch.disable()
@pytest.fixture(scope="function", params=pytest.channels)
def fmcfd_chan(request, fmcfd):
yield fmcfd.chan[request.param]
fmcfd.chan[request.param].disable()
pulse_train = [(200000, 10000000000)]
MIN_COUNT = 1
MAX_COUNT = 0xFFFF
@pytest.fixture(scope="function")
def fmcfd_tdc(request, fmcfd):
......@@ -37,10 +44,12 @@ def fmcfd_tdc(request, fmcfd):
fmcfd.tdc.enable_input = False
fmcfd.tdc.enable_tstamp = False
def timeout_compute(start, period_ps, count):
proportional = ((count * period_ps)/1000000000000.0)
proportional = ((count * period_ps) / 1000000000000.0)
return time.time() + proportional + start + 5
class TestFmcfdLoop(object):
"""
The test needs a lemo cable (1ns) that connects all outputs
......@@ -55,31 +64,30 @@ class TestFmcfdLoop(object):
chan 4 o-------`
"""
@pytest.mark.parametrize("count", [10])
@pytest.mark.parametrize("width,period", [(200000, 400000)])
def test_output_flush(self, fmcfd, fmcfd_chan, fmcfd_tdc,
width, period, count):
def test_output_flush(self, fmcfd, fmcfd_chan, fmcfd_tdc):
period_ps = 400000
fmcfd_chan.pulse_generate(fmcfd.time + FmcFineDelayTime(2, 0, 0),
width, period, count)
int(period_ps / 2), period_ps, 1)
assert len(fmcfd_tdc.poll(4000)) > 0
fmcfd_tdc.flush()
assert len(fmcfd_tdc.poll(4000)) ==0
assert len(fmcfd_tdc.poll(4000)) == 0
@pytest.mark.parametrize("count", [1, 2, 3, 5, 7, 10,
100, 1000, 10000, 65535])
@pytest.mark.parametrize("width,period", pulse_train)
def test_output_counter(self, fmcfd, fmcfd_chan, fmcfd_tdc,
width, period, count):
@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
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, width, period, count)
timeout = timeout_compute(start_s, period, count)
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
......@@ -91,25 +99,24 @@ class TestFmcfdLoop(object):
assert len(t) > 0
ts = ts + t
assert len(ts) == count
assert len(fmcfd_tdc.poll(int(period / 1000000000.0))) == 0
assert len(fmcfd_tdc.poll(int(period_ps / 1000000000.0))) == 0
del ts
@pytest.mark.parametrize("count", [10000])
@pytest.mark.parametrize("width,period", pulse_train)
def test_input_sequence_number(self, capsys, fmcfd_chan, fmcfd_tdc,
width, period, count):
@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.
"""
period_ps = 4500000000
pending = count
ts = []
start_s = 2
start = FmcFineDelayTime(start_s, 0, 0)
fmcfd_chan.pulse_generate(fmcfd_chan.dev.time + start,
width, period, count)
int(period_ps / 2), period_ps, count)
timeout = timeout_compute(start_s, period, count)
timeout = timeout_compute(start_s, period_ps, count)
while pending > 0 and time.time() < timeout:
if len(fmcfd_tdc.poll()) == 0:
continue
......@@ -129,34 +136,24 @@ class TestFmcfdLoop(object):
"i:{:d}, cur: {:s}, prev: {:s}".format(i, str(ts[i]),
str(prev_ts))
@pytest.mark.parametrize("start_rel", [FmcFineDelayTime(0, 78125000, 0), # + 0.0625s
FmcFineDelayTime(0, 15625000, 0), # + 0.125s
FmcFineDelayTime(0, 31250000, 0), # + 0.25s
FmcFineDelayTime(0, 62500000, 0), # + 0.5s
FmcFineDelayTime(1, 0, 0), # + 1s
FmcFineDelayTime(1, 78125000, 0), # + 1.0625s
FmcFineDelayTime(1, 15625000, 0), # + 1.125s
FmcFineDelayTime(1, 31250000, 0), # + 1.25s
FmcFineDelayTime(1, 62500000, 0), # + 1.5s
FmcFineDelayTime(2, 0, 0), # + 2s
FmcFineDelayTime(60, 0, 0), # + 60s
FmcFineDelayTime(120, 0, 0), # + 120s
])
@pytest.mark.parametrize("start_rel", [FmcFineDelayTime(random.randrange(0, 60),
random.randrange(0, 125000000),
0) for i in range(10)])
@pytest.mark.parametrize("wr", [False, True])
@pytest.mark.parametrize("count", [1])
@pytest.mark.parametrize("width,period", pulse_train)
def test_output_input_start(self, fmcfd_chan, fmcfd_tdc,
wr, start_rel, width, period, count):
def test_output_input_start(self, fmcfd_chan, fmcfd_tdc, wr, start_rel):
"""
The output channel generates a pulse at a given time and the input
channel timestamps it. The two times must be almost the same excluding
the propagation time (cable length).
"""
period_ps = 1000000
count = 1
fmcfd_chan.dev.whiterabbit_mode = wr
ts = []
start = fmcfd_chan.dev.time + start_rel
fmcfd_chan.pulse_generate(start, width, period, count)
fmcfd_chan.pulse_generate(start, int(period_ps / 2), period_ps, count)
assert len(fmcfd_tdc.poll(int(float(start_rel) * 1000) + 2000)) > 0
ts = fmcfd_tdc.read(count, os.O_NONBLOCK)
assert len(ts) == count
......@@ -164,17 +161,9 @@ class TestFmcfdLoop(object):
assert ts[0].coarse - start.coarse <= 3 # there is < 3ns cable
@pytest.mark.parametrize("width,period_ps", [(200000, 1000000),
(200000, 10000000),
(200000, 100000000),
(200000, 1000000000),
(200000, 10000000000),
(200000, 100000000000),
(200000, 1000000000000),
])
@pytest.mark.parametrize("period_ps", [random.randrange(400000, 1000000000000)])
@pytest.mark.parametrize("count", [10])
def test_output_period(self, fmcfd_chan, fmcfd_tdc,
width, period_ps, count):
def test_output_period(self, fmcfd_chan, fmcfd_tdc, period_ps, count):
"""
The test produces pulses on the given channels and catch them using
the on board TDC. The period between two timestamps must be as close
......@@ -183,7 +172,7 @@ class TestFmcfdLoop(object):
ts = []
start = fmcfd_chan.dev.time + FmcFineDelayTime(2, 0, 0, 0, 0)
fmcfd_chan.pulse_generate(start, width, period_ps, count)
fmcfd_chan.pulse_generate(start, int(period_ps / 2), period_ps, count)
time.sleep(2 + (count * period_ps) / 1000000000000.0)
assert len(fmcfd_tdc.poll(10000)) > 0
ts = fmcfd_tdc.read(count, os.O_NONBLOCK)
......
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