Skip to content

Commit

Permalink
Merge pull request #566 from jpineda3/ad9081-test-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tfcollins authored Aug 16, 2024
2 parents c858d4a + 4be93cc commit 764dd5b
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 14 deletions.
12 changes: 7 additions & 5 deletions adi/ad9081.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,13 @@ def _set_iio_attr_str_single(self, channel_name, attr, output, value):
# This is overridden by subclasses
return self._set_iio_attr(channel_name, attr, output, value)

def _get_iio_attr_single(self, channel_name, attr, output):
def _get_iio_attr_single(self, channel_name, attr, output, _ctrl=None):
# This is overridden by subclasses
return self._get_iio_attr(channel_name, attr, output)
return self._get_iio_attr(channel_name, attr, output, _ctrl)

def _set_iio_attr_single(self, channel_name, attr, output, value):
def _set_iio_attr_single(self, channel_name, attr, output, value, _ctrl=None):
# This is overridden by subclasses
return self._set_iio_attr(channel_name, attr, output, value)
return self._set_iio_attr(channel_name, attr, output, value, _ctrl)

def _get_iio_dev_attr_single(self, attr):
# This is overridden by subclasses
Expand Down Expand Up @@ -627,7 +627,9 @@ def adc_frequency(self):
@property
def tx_sample_rate(self):
"""tx_sampling_frequency: Sample rate before interpolation"""
return self._get_iio_attr_single("voltage0_i", "sampling_frequency", True)
return self._get_iio_attr_single(
"voltage0_i", "sampling_frequency", True, self._txdac
)

@property
def dac_frequency(self):
Expand Down
38 changes: 38 additions & 0 deletions test/attr_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,44 @@ def attribute_multiple_values(
assert dev_interface(uri, classname, val, attr, tol, sleep=sleep)


def attribute_multiple_values_error(
uri, classname, attr, values, tol, repeats=1, sleep=0, sub_channel=None
):
"""attribute_multiple_values_error: Write multiple class properties
in a loop where all values are pre-defined and expected to raise an error.
This is performed a defined number of times.
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
values: type=list
A list of values to write and check as attributes
tol: type=integer
Allowable error of written value compared to read back value
repeats: type=integer
Number of times to repeatedly write values
sleep: type=integer
Seconds to sleep between writing to attribute and reading it back
sub_channel: type=string
Name of sub channel (nested class) to be tested
"""
with pytest.raises(Exception) as e_info:
for _ in range(repeats):
for val in values:
if isinstance(val, str):
tol = 0
if sub_channel:
assert dev_interface_sub_channel(
uri, classname, sub_channel, val, attr, tol, sleep=sleep
)
else:
assert dev_interface(uri, classname, val, attr, tol, sleep=sleep)


def attribute_multiple_values_with_depends(
uri, classname, attr, depends, values, tol, repeats=1
):
Expand Down
5 changes: 5 additions & 0 deletions test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ def test_attribute_multiple_values(request):
yield attribute_multiple_values


@pytest.fixture()
def test_attribute_multiple_values_error(request):
yield attribute_multiple_values_error


@pytest.fixture()
def test_attribute_multiple_values_with_depends(request):
yield attribute_multiple_values_with_depends
Expand Down
22 changes: 15 additions & 7 deletions test/dma_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,10 +595,14 @@ def cw_loopback(uri, classname, channel, param_set, use_tx2=False, use_rx2=False
RXFS = int(getattr(sdr, attr))

A = 2 ** 15
fc = RXFS * 0.1
fc = int(fc / (RXFS / N)) * (RXFS / N)
if hasattr(sdr, "tx_sample_rate"):
FS = int(sdr.tx_sample_rate)
else:
FS = RXFS
fc = FS * 0.1
fc = int(fc / (FS / N)) * (FS / N)

ts = 1 / float(RXFS)
ts = 1 / float(FS)
t = np.arange(0, N * ts, ts)
if sdr._complex_data:
i = np.cos(2 * np.pi * t * fc) * A * 0.5
Expand Down Expand Up @@ -692,10 +696,14 @@ def t_sfdr(uri, classname, channel, param_set, sfdr_min, use_obs=False, full_sca
else:
RXFS = int(sdr.rx_sample_rate)

fc = RXFS * 0.1
fc = int(fc / (RXFS / N)) * (RXFS / N)
if hasattr(sdr, "tx_sample_rate"):
FS = int(sdr.tx_sample_rate)
else:
FS = RXFS

ts = 1 / float(RXFS)
fc = FS * 0.1
fc = int(fc / (FS / N)) * (FS / N)
ts = 1 / float(FS)
t = np.arange(0, N * ts, ts)
i = np.cos(2 * np.pi * t * fc) * 2 ** 15 * full_scale
q = np.sin(2 * np.pi * t * fc) * 2 ** 15 * full_scale
Expand All @@ -710,7 +718,7 @@ def t_sfdr(uri, classname, channel, param_set, sfdr_min, use_obs=False, full_sca
del sdr
raise Exception(e)
del sdr
val, amp, freqs = spec.sfdr(data, plot=False)
val, amp, freqs = spec.sfdr(data, fs=RXFS, plot=False)
if do_html_log:
pytest.data_log = {
"html": gen_line_plot_html(
Expand Down
2 changes: 1 addition & 1 deletion test/rf/spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def spec_est(x, fs, ref=2 ** 15, plot=False):
N = len(x)

# Apply window
window = signal.kaiser(N, beta=38)
window = signal.windows.kaiser(N, beta=8.6)
# x = multiply(x, window)

# Use FFT to get the amplitude of the spectrum
Expand Down
12 changes: 11 additions & 1 deletion test/test_ad9081.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def scale_field(param_set, iio_uri):
"attr, val",
[
("rx_nyquist_zone", ["even", "odd"]),
("loopback_mode", [2, 1, 0]),
("loopback_mode", [0]),
(
"rx_test_mode",
[
Expand Down Expand Up @@ -65,6 +65,16 @@ def test_ad9081_str_attr(test_attribute_multiple_values, iio_uri, classname, att
test_attribute_multiple_values(iio_uri, classname, attr, val, 0)


#########################################
@pytest.mark.iio_hardware(hardware, True)
@pytest.mark.parametrize("classname", [(classname)])
@pytest.mark.parametrize("attr, val", [("loopback_mode", [2, 1])])
def test_ad9081_str_attr_err(
test_attribute_multiple_values_error, iio_uri, classname, attr, val
):
test_attribute_multiple_values_error(iio_uri, classname, attr, val, 0)


#########################################
@pytest.mark.iio_hardware(hardware)
@pytest.mark.parametrize("classname", [(classname)])
Expand Down

0 comments on commit 764dd5b

Please sign in to comment.