Commit 45565e3c authored by Projects's avatar Projects

tests/pulse_rejection: updated the pulse rejection module test

- different test data sets depending on the pulse duration switch
- updated to the new PyBECO version
- replaced some functions with PyBECO library calls
- shows the pulsegen command for each test
- cool down period between tests
parent 882b86cd
......@@ -9,11 +9,13 @@ Tests CONV-TTL-BLO pulse rejection module.
import os
import sys
import time
sys.path.append("../PyBECO")
from PyBECO.boards import PyConvTTL, PyConvTTLException
from PyBECO.fec import Elma, ElmaException
# crate credentials
sys.path.append("../ei2c")
import ei2cdefine as cfg
......@@ -22,45 +24,7 @@ address = cfg.HNAME if cfg.ENABLED and cfg.HNAME else raw_input("Hostname: ")
user = cfg.USER if cfg.ENABLED and cfg.USER else raw_input("User: ")
password = cfg.PWD if cfg.ENABLED and cfg.PWD else raw_input("Password: ")
slot = int(input("Slot number: "))
# array storing frequencies and number of guaranteed pulses to pass
tests = (
# {'freq': 4000, 'pulses': 10000},
{'freq': 2000000, 'pulses': 2000000},
)
##############################################
# flags for possible causes of a missed pulse
MISS_FLIMIT = 1
MISS_WDOG = 2
def missed_pulse(status, channel):
""" Checks if pulse has been missed for given channel.
:param status: PyConvTTLStatus object to be checked
:param channel: Channel number (1-6)
:returns: 0 if there were not any pulses missed
MISS_FLIMIT if at least one pulse has been missed due to frequency limit error
MISS_WDOG if at least one pulse has been missed due to frequency watchdog error
Both flags (MISS_FLIMIT & MISS_WDOG) can be set at the same time
"""
res = 0
if channel < 1 or channel > 6:
raise RuntimeException("Invalid channel %d" % channel)
if(status.error_register & (1 << (1 + channel))):
res |= MISS_FLIMIT
if(status.error_register & (1 << (7 + channel))):
res |= MISS_WDOG
return res
##############################################
cooldown_time = 6 # 6 seconds of cool down time between tests
elma = Elma(address, user, password)
convttl = PyConvTTL(slot, elma)
......@@ -69,40 +33,60 @@ convttl = PyConvTTL(slot, elma)
print(convttl.status)
# verify gateware and hardware number
# TODO uncomment
# if not convttl.status.hw_version.startswith('4'):
# print("ERROR: Expected hardware version 4.x, but it is %s" % convttl.status.hw_version)
# sys.exit(1)
if convttl.status.hw_version[0] != 4:
print("ERROR: Expected hardware version 4.x, but it is %d.%d" % convttl.status.hw_version)
# sys.exit(1) # TODO uncomment
if not convttl.status.gw_version.startswith('4'):
print("ERROR: Expected gateware version 4.x, but it is %s" % convttl.status.gw_version)
if convttl.status.gw_version[0] != 4:
print("ERROR: Expected gateware version 4.x, but it is %d.%d" % convttl.status.gw_version)
sys.exit(1)
# TODO verify if the dip switch is set correctly
# selectt the test data set depending on the pulse duration switch
if(convttl.status.switch[1]):
#print("short")
pass
# short pulse
print("Running short pulse tests")
tests = (
{'freq': 2000000, 'seconds': 1},
{'freq': 1333333, 'seconds': 6.5},
{'freq': 1000000, 'seconds': 10},
{'freq': 800000, 'seconds': 26},
{'freq': 666667, 'seconds': 36.66},
{'freq': 571428.6, 'seconds': 120} # continuous, but waiting for infinite
) # number of seconds takes too long
else:
#print("long")
pass
# long pulse
print("Running long pulse tests")
tests = (
{'freq': 104166.7, 'seconds': 1},
{'freq': 92592.5, 'seconds': 3},
{'freq': 83333.3, 'seconds': 6.5},
{'freq': 75757.8, 'seconds': 10},
{'freq': 69444.4, 'seconds': 20},
{'freq': 55555.6, 'seconds': 60},
{'freq': 52083.3, 'seconds': 120}, # continuous, but waiting for infinite
) # number of seconds takes too long
# run tests
for test in tests:
old_counters = None
pulses = test['pulses']
freq = test['freq']
pulses = test['freq'] * test['seconds']
#############################################################################################
# test if the guaranteed number of pulses is repeated
# clear counters
for ch in range(1, 7):
convttl.pulse_counter_set(ch, (0, 0))
# clear errors (including missed pulse flags)
convttl.status.clear_errors_current()
convttl.error.clear()
print("------")
print("TEST: accept %d pulses at %d Hz" % (pulses, freq))
print("Start the pulse burst generator (%d pulses)\n" % int(pulses))
print("Start the pulse burst generator (%d pulses)" % int(pulses))
print(" ./pulsegen.py -c %d -f %F" % (pulses, freq))
print("")
print("Pulse counters:")
test_run = True
......@@ -114,64 +98,85 @@ for test in tests:
old_counters = convttl.pulse_counters
for ch in range(0, 6):
if old_counters[ch][0] != 0 and old_counters[ch][1] != 0:
for ch in range(1, 7):
pulse_missed_errors = (convttl.ERRORS_MASK_FLIM_MISSED(ch),
convttl.ERRORS_MASK_FWDG_MISSED(ch))
if old_counters[ch - 1][0] != 0 and old_counters[ch - 1][1] != 0:
print("WARNING: Both pulse counters are increasing, check if it is ok")
pulse_count = max(old_counters[ch])
pulse_count = max(old_counters[ch - 1])
# check if there were any pulses missed
if missed_pulse(convttl.status, ch + 1):
if any(error in convttl.error for error in pulse_missed_errors):
if(pulse_count <= pulses):
print("TEST FAILED: channel %d missed a pulse" % ch)
print("TEST FAILED: channel %d missed a pulse (%d)" % (ch, pulse_count))
sys.exit(2)
test_run = False
break
# check if we have reached the number of guaranteed pulses
if pulse_count >= pulses:
print("TEST PASSED: repeated %d pulses at frequency %d" % (pulses, freq))
print("TEST PASSED: repeated %d pulses at frequency %d" % (pulse_count, freq))
test_run = False
break
#############################################################################################
# test if pulses are rejected after the counter threshold has been reached
print("waiting %d seconds of cool-down period" % cooldown_time)
time.sleep(cooldown_time)
# clear counters
for ch in range(1, 7):
convttl.pulse_counter_set(ch, (0, 0))
# clear errors (including missed pulse flags)
convttl.status.clear_errors_current()
convttl.error.clear()
print("")
print("------")
print("")
print("TEST: reject pulses after repeating %d pulses at %d Hz" % (pulses, freq))
print("Start the pulse burst generator (%d pulses)\n" % pulses * 2)
print("Start the pulse burst generator (%d pulses)" % (pulses * 2))
print(" ./pulsegen.py -c %d -f %F" % (pulses * 2, freq))
print("")
print("Pulse counters:")
test_run = True
passed = [False for _ in range(6)]
# test if pulses are rejected after a certain threshold
while(test_run):
if(old_counters != convttl.pulse_counters):
print(convttl.pulse_counters)
old_counters = convttl.pulse_counters
for ch in range(0, 6):
if old_counters[ch][0] != 0 and old_counters[ch][1] != 0:
for ch in range(1, 7):
pulse_missed_errors = (convttl.ERRORS_MASK_FLIM_MISSED(ch), convttl.ERRORS_MASK_FWDG_MISSED(ch))
if old_counters[ch - 1][0] != 0 and old_counters[ch - 1][1] != 0:
print("WARNING: Both pulse counters are increasing, check if it is ok")
pulse_count = max(old_counters[ch])
pulse_count = max(old_counters[ch - 1])
# check if there were any pulses missed
if missed_pulse(convttl.status, ch + 1):
if any(error in convttl.error for error in pulse_missed_errors):
if(pulse_count <= pulses):
print("TEST FAILED: channel %d missed a pulse too early" % ch)
else:
print("TEST FAILED: channel %d missed a pulse too early (%d)" % (ch, pulse_count))
sys.exit(2)
elif not passed[ch - 1]:
print("TEST PASSED: rejected %d pulse at channel %d" % (pulse_count, ch))
passed[ch - 1] = True
# even if the test was passed, wait for the end of current pulse burst
if(pulse_count >= pulses * 2):
if not any(error in convttl.error for error in pulse_missed_errors):
print("TEST FAILED: repeated %d pulses, none rejected" % (pulse_count))
sys.exit(2)
test_run = False
break
if(pulse_count == pulses * 2):
print("TEST FAILED: repeated %d pulses, none rejected" % (pulse_count))
test_run = False
print("waiting %d seconds of cool-down period" % cooldown_time)
time.sleep(cooldown_time)
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