Skip to content

attribute_multiple_values and tol parameter typing #608

@threexc

Description

@threexc

Hi @tfcollins,

I'm currently working on AD7625 support in pyadi-iio (the driver isn't quite merged upstream yet, but it will be soon). One of the planned tests in test/test_ad7625.py is to test setting the sampling_frequency attribute to multiple different values. The problem I'm running into while testing with actual hardware is that, due to hardware limitations, there is some rounding that occurs, and the resulting values for sampling_frequency may exceed or fall under the expected ones by different percentages.

For example, with a test like:

#########################################                                                                                                                                                                                                                     
@pytest.mark.iio_hardware(hardware)                                                                                                                                                                                                                           
@pytest.mark.parametrize("classname", [(classname)])                                                                                                                                                                                                          
@pytest.mark.parametrize(                                                                                                                                                                                                                                     
    "attr, val",                                                                                                                                                                                                                                              
    [                                                                                                                                                                                                                                                         
        (                                                                                                                                                                                                                                                     
            "sampling_frequency",                                                                                                                                                                                                                             
            [10000, 50000, 100000, 200000, 500000, 1000000, 2000000, 6000000],                                                                                                                                                                                
        ),                                                                                                                                                                                                                                                    
    ],                                                                                                                                                                                                                                                        
)                                                                                                                                                                                                                                                             
def test_ad7625_attr(test_attribute_multiple_values, iio_uri, classname, attr, val):                                                                                                                                                                          
    test_attribute_multiple_values(iio_uri, classname, attr, val, 1)

I see:

Failed to set: sampling_frequency
Set: 50000
Got: 50005.0

If I boost the tol value I can make this go away, but later values in the list need higher tolerances, and since this parameter is a static integer there comes a point where the set tolerance value is actually larger than the target value, meaning it'll never actually fail. For comparison, here's the expected versus rounded value at the top end:

Failed to set: sampling_frequency
Set: 6000000
Got: 5952381.0

I can set a tol value of around 50000 to make this one work, but obviously that makes most of the other values guaranteed to pass the test even if the actual value deviates significantly from the expected.

Where I am going with this: should the API for attribute_multiple_values() (and the dev_interface() function underneath) be rewritten to test with a percentage, rather than a flat integer? Maybe we need to add a variant that takes a percentage instead of an integer (absolute value)?

For now, I am thinking that I may have to write some separate tests for max/min sampling rates with separate tolerance values.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions