From 2e4ee444abfa125af3c6189bde1ce7af47b1c32f Mon Sep 17 00:00:00 2001 From: Trisha De Vera Date: Thu, 21 Mar 2024 07:42:06 +0800 Subject: [PATCH 1/3] Add attribute tests --- test/attr_tests.py | 51 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/test/attr_tests.py b/test/attr_tests.py index 7e73d7014..25155684e 100644 --- a/test/attr_tests.py +++ b/test/attr_tests.py @@ -625,3 +625,54 @@ 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_single_value: + Write and read back integer class property + 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 + 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) \ No newline at end of file From 6578902af41d49b5ef5525b1a2653a93cf72d61a Mon Sep 17 00:00:00 2001 From: Trisha De Vera Date: Thu, 21 Mar 2024 07:43:20 +0800 Subject: [PATCH 2/3] Modify cn0511 test Add attribute test --- test/attr_tests.py | 7 +++++-- test/conftest.py | 5 +++++ test/test_cn0511_p.py | 37 +++++++++++++++++++++++++++++++------ 3 files changed, 41 insertions(+), 8 deletions(-) diff --git a/test/attr_tests.py b/test/attr_tests.py index 25155684e..7fca4be9d 100644 --- a/test/attr_tests.py +++ b/test/attr_tests.py @@ -630,8 +630,8 @@ def attribute_single_value_channel_readonly(uri, classname, channel, attr): def attribute_check_range_singleval_with_depends( uri, classname, attr, depends, start, stop, step, tol, repeats=1, sub_channel=None ): - """attribute_single_value: - Write and read back integer class property + """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 @@ -642,6 +642,9 @@ def attribute_check_range_singleval_with_depends( 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 diff --git a/test/conftest.py b/test/conftest.py index ea227e5e2..f8e0fd292 100644 --- a/test/conftest.py +++ b/test/conftest.py @@ -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 diff --git a/test/test_cn0511_p.py b/test/test_cn0511_p.py index 22a5b6318..095d41191 100644 --- a/test/test_cn0511_p.py +++ b/test/test_cn0511_p.py @@ -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( @@ -24,10 +23,36 @@ 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 ) From e6b7da8fbafd4c0a04a01db92c72c0ebcfbedbcf Mon Sep 17 00:00:00 2001 From: Trisha De Vera Date: Thu, 13 Jun 2024 09:58:22 +0800 Subject: [PATCH 3/3] Fix lint --- test/attr_tests.py | 2 +- test/test_cn0511_p.py | 18 ++++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/test/attr_tests.py b/test/attr_tests.py index 7fca4be9d..bf9e0a1a8 100644 --- a/test/attr_tests.py +++ b/test/attr_tests.py @@ -678,4 +678,4 @@ def attribute_check_range_singleval_with_depends( uri, classname, sub_channel, val, attr, tol ) else: - assert dev_interface(uri, classname, val, attr, tol) \ No newline at end of file + assert dev_interface(uri, classname, val, attr, tol) diff --git a/test/test_cn0511_p.py b/test/test_cn0511_p.py index 095d41191..188f704cc 100644 --- a/test/test_cn0511_p.py +++ b/test/test_cn0511_p.py @@ -35,24 +35,22 @@ def test_cn0511_attr( @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), - ], + [("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 + depends, + start, + stop, + step, + tol, + repeats, ): test_attribute_check_range_singleval_with_depends( - iio_uri, classname, attr,depends, start, stop, step, tol, repeats + iio_uri, classname, attr, depends, start, stop, step, tol, repeats )