Skip to content

Commit

Permalink
Add cn0540 test and import statement for cn0540
Browse files Browse the repository at this point in the history
Add test for cn0540 with import statement and new attribute test

Signed-off-by: Trisha De Vera <Trisha.Devera@analog.com>
  • Loading branch information
trishaange01 committed Aug 30, 2024
1 parent 37563ff commit d0d9ae5
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 0 deletions.
21 changes: 21 additions & 0 deletions test/attr_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import adi
import numpy as np
import pytest
from adi.cn0540 import cn0540 # Add import statement for cn0540


def floor_step_size(quantity, step_size):
Expand Down Expand Up @@ -717,3 +718,23 @@ def attribute_check_range_singleval_with_depends(
)
else:
assert dev_interface(uri, classname, val, attr, tol)


def attribute_single_value_boolean_readonly(uri, classname, attr):
"""attribute_single_value_boolean: Read boolean class property
parameters:
uri: type=string
URI of IIO context of target board/system
classname: type=string
Name of pyadi interface class which contain attribute
attr: type=string
Attribute name to be written. Must be property of classname
"""
bi = eval(classname + "(uri='" + uri + "')")

if not hasattr(bi, attr):
raise AttributeError(f"no attribute named: {attr}")

rval = getattr(bi, attr)
assert type(rval) != None
1 change: 1 addition & 0 deletions test/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import adi
import numpy as np
import pytest
from adi.cn0540 import cn0540 # Add import statement for cn0540


def pytest_configure(config):
Expand Down
5 changes: 5 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,8 @@ def test_attribute_single_value_channel_readonly(request):
@pytest.fixture()
def test_attribute_check_range_singleval_with_depends(request):
yield attribute_check_range_singleval_with_depends


@pytest.fixture()
def test_attribute_single_value_boolean_readonly(request):
yield attribute_single_value_boolean_readonly
1 change: 1 addition & 0 deletions test/dma_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import adi
import numpy as np
import pytest
from adi.cn0540 import cn0540 # Add import statement for cn0540
from numpy.fft import fft, fftfreq, fftshift
from scipy import signal

Expand Down
100 changes: 100 additions & 0 deletions test/test_cn0540.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import random
from test.attr_tests import floor_step_size

import adi
import pytest
from adi.cn0540 import cn0540

hardware = "cn0540"
classname = "cn0540"


#########################################
@pytest.mark.iio_hardware(hardware, True)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize("channel", [0])
def test_cn0540_rx_data(test_dma_rx, iio_uri, classname, channel):
test_dma_rx(iio_uri, classname, channel)


#########################################
@pytest.mark.iio_hardware(hardware)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize(
"attr, val",
[("sample_rate", [256000, 128000, 64000, 32000, 16000, 8000, 4000, 2000, 1000,],),],
)
def test_cn0540_attr_multiple(
test_attribute_multiple_values, iio_uri, classname, attr, val
):
test_attribute_multiple_values(iio_uri, classname, attr, val, 0)


#########################################
@pytest.mark.iio_hardware(hardware)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize(
"attr, value",
[
("monitor_powerup", 0),
("monitor_powerup", 1),
("fda_disable_status", 0),
("fda_disable_status", 1),
("red_led_enable", 0),
("red_led_enable", 1),
("sw_cc", 0),
("sw_cc", 1),
("fda_mode", "low-power"),
("fda_mode", "full-power"),
],
)
def test_cn0540_attr_boolean(
test_attribute_single_value_boolean, iio_uri, classname, attr, value
):
test_attribute_single_value_boolean(iio_uri, classname, attr, value)


#########################################
@pytest.mark.iio_hardware(hardware)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize(
"attr", [("sw_ff_status"),],
)
def test_cn0540_attr_boolean_readonly(
test_attribute_single_value_boolean_readonly, iio_uri, classname, attr
):
test_attribute_single_value_boolean_readonly(iio_uri, classname, attr)


#########################################
@pytest.mark.iio_hardware(hardware, True)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize(
"attr, start, stop, step, repeats ", [("shift_voltage", 0, 65535, 1, 2),],
)
def test_cn0540_shift_voltage(iio_uri, classname, attr, start, stop, step, repeats):
device = cn0540(uri=iio_uri)
bi = eval(classname + "(uri='" + iio_uri + "')")

if not hasattr(bi, attr):
raise AttributeError(f"no attribute named: {attr}")

# Pick random number in operational range
numints = int((stop - start) / step)
for _ in range(repeats):
ind = random.randint(0, numints)
val = start + step * ind
if isinstance(val, float):
val = floor_step_size(val, str(step))

setattr(bi, "raw", val)
assert 0 <= device.shift_voltage <= 4997.04375


#########################################
@pytest.mark.iio_hardware(hardware, True)
def test_cn0540_readonly(iio_uri):
device = cn0540(uri=iio_uri)
attr = [device.input_voltage, device.sensor_voltage]
for _ in attr:
assert type(_) != None

0 comments on commit d0d9ae5

Please sign in to comment.