Commit 3af1edd7 authored by Federico Vaga's avatar Federico Vaga

tst: add offset test

Signed-off-by: Federico Vaga's avatarFederico Vaga <federico.vaga@cern.ch>
parent 23f3faf5
......@@ -4,6 +4,7 @@ SPDX-FileCopyrightText: 2020 CERN
"""
import pytest
import ctypes
import random
from PyAdcLib import PyAdcConf
......@@ -22,3 +23,27 @@ class TestAdcGetterSetter(object):
conf_rb.mask_set(PyAdcConf.ADC_CONF_CHN_TERMINATION)
adc100m14b4cha.retrieve_config(conf_rb)
assert conf.value_get(PyAdcConf.ADC_CONF_CHN_TERMINATION) == conf_rb.value_get(PyAdcConf.ADC_CONF_CHN_TERMINATION)
@pytest.mark.parametrize("offset", range(-5000000, 5000000 + 1, 100000))
@pytest.mark.parametrize("channel", range(4))
def test_adc_offset(self, adc100m14b4cha, offset, channel):
"Test that we can read/write offset on all channels"
conf = PyAdcConf(PyAdcConf.ADC_CONF_TYPE_CHN, channel)
conf.value_set(PyAdcConf.ADC_CONF_CHN_OFFSET, offset)
assert conf.value_get(PyAdcConf.ADC_CONF_CHN_OFFSET) == ctypes.c_uint32(offset).value
adc100m14b4cha.apply_config(conf, 0)
conf_rb = PyAdcConf(PyAdcConf.ADC_CONF_TYPE_CHN, channel)
conf_rb.mask_set(PyAdcConf.ADC_CONF_CHN_OFFSET)
adc100m14b4cha.retrieve_config(conf_rb)
assert conf.value_get(PyAdcConf.ADC_CONF_CHN_OFFSET) == conf_rb.value_get(PyAdcConf.ADC_CONF_CHN_OFFSET)
@pytest.mark.parametrize("offset", [-5000001, 5000001])
@pytest.mark.parametrize("channel", range(4))
def test_adc_offset_invalid(self, adc100m14b4cha, offset, channel):
"Test that we can read/write offset on all channels"
conf = PyAdcConf(PyAdcConf.ADC_CONF_TYPE_CHN, channel)
conf.value_set(PyAdcConf.ADC_CONF_CHN_OFFSET, offset)
assert conf.value_get(PyAdcConf.ADC_CONF_CHN_OFFSET) == ctypes.c_uint32(offset).value
with pytest.raises(OSError):
adc100m14b4cha.apply_config(conf, 0)
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