Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix cn0511 test #574

Merged
merged 3 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions test/attr_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,3 +625,57 @@ def attribute_single_value_channel_readonly(uri, classname, channel, attr):
except Exception as e:
del sdr
raise Exception(e)


def attribute_check_range_singleval_with_depends(
uri, classname, attr, depends, start, stop, step, tol, repeats=1, sub_channel=None
):
"""attribute_check_range_singleval_with_depends:
Write and read back integer class property with dependent write properties
This is performed a defined number of times and the value written
is randomly determined based in input parameters

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
depends: type=dict
Dictionary of properties to write before value is written. Keys
are properties and values are values to be written
start: type=integer
Lower bound of possible values attribute can be
stop: type=integer
Upper bound of possible values attribute can be
step: type=integer
Difference between successive values attribute can be
tol: type=integer
Allowable error of written value compared to read back value
repeats: type=integer
Number of random values to tests. Generated from uniform distribution
sub_channel: type=string
Name of sub channel (nested class) to be tested
"""
# Set custom dependencies for the attr being tested
for p in depends.keys():
if isinstance(depends[p], str):
assert dev_interface(uri, classname, depends[p], p, 0)
else:
assert dev_interface(uri, classname, depends[p], p, tol)

# 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))
# Check hardware
if sub_channel:
assert dev_interface_sub_channel(
uri, classname, sub_channel, val, attr, tol
)
else:
assert dev_interface(uri, classname, val, attr, tol)
5 changes: 5 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,8 @@ def test_attribute_multiple_values_available_readonly(request):
@pytest.fixture
def test_attribute_single_value_channel_readonly(request):
yield attribute_single_value_channel_readonly


@pytest.fixture()
def test_attribute_check_range_singleval_with_depends(request):
yield attribute_check_range_singleval_with_depends
35 changes: 29 additions & 6 deletions test/test_cn0511_p.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
@pytest.mark.iio_hardware(hardware, True)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize(
"attr, start, stop, step, tol, param_set",
"attr, start, stop, step, tol, repeats",
[
("frequency", 1, 2949120000, 1, 8, dict(sample_rate=5898240000)),
("raw", 1, 2 ** 15 - 1, 1, 8, None),
("sample_rate", 4915200000, 5775360000, 122880000, 8, None),
("raw", 1, 2 ** 15 - 1, 1, 8, 1),
("sample_rate", 4915200000, 5775360000, 122880000, 8, 1),
],
)
def test_cn0511_attr(
Expand All @@ -24,10 +23,34 @@ def test_cn0511_attr(
stop,
step,
tol,
param_set,
repeats,
):
test_attribute_single_value(
iio_uri, classname, attr, start, stop, step, tol, param_set
iio_uri, classname, attr, start, stop, step, tol, repeats
)


#########################################
@pytest.mark.iio_hardware(hardware)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize(
"attr, depends, start, stop, step, tol, repeats",
[("frequency", dict(sample_rate=5898240000), 1, 2949120000, 1, 8, 2),],
)
def test_cn0511_attr_with_depends(
test_attribute_check_range_singleval_with_depends,
iio_uri,
classname,
attr,
depends,
start,
stop,
step,
tol,
repeats,
):
test_attribute_check_range_singleval_with_depends(
iio_uri, classname, attr, depends, start, stop, step, tol, repeats
)


Expand Down
Loading