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

Hardware tests #23

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
22 changes: 14 additions & 8 deletions JenkinsfileHW
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Pipeline
lock(label: 'adgt_test_harness_boards') {
@Library('sdgtt-lib@adgt-test-harness') _ // Not necessary when we turn on global libraries :)
lock('nuc04') {
@Library('sdgtt-lib@nuc4-libm2k') _ // Not necessary when we turn on global libraries :)
def hdlBranch = "NA"
def linuxBranch = "NA"
def bootPartitionBranch = "2021_r2"
Expand All @@ -17,7 +17,8 @@ lock(label: 'adgt_test_harness_boards') {
// harness.set_env('telemetry_repo', 'http://gateway.englab:3000/mirrors/telemetry.git')
// harness.set_env('telemetry_branch', 'master')
harness.set_env('matlab_repo', 'https://github.com/analogdevicesinc/PrecisionToolbox.git') // Not necessary when using checkout scm
harness.set_env('matlab_release','R2021b')
harness.set_env('matlab_branch','main')
harness.set_env('matlab_release','R2022b')
harness.set_matlab_timeout('30m')

//Update nebula config from netbox
Expand All @@ -26,18 +27,21 @@ lock(label: 'adgt_test_harness_boards') {
harness.set_env('netbox_ip','primary.englab')
harness.set_env('netbox_port','8000')
harness.set_env('netbox_base_url','netbox')
harness.set_env('netbox_token','0123456789abcdef0123456789abcdef01234567')
harness.set_env('netbox_devices_tag','active')
withCredentials([string(credentialsId: 'netbox_token', variable: 'TOKEN')]) {
harness.set_env('netbox_token', TOKEN)
}
harness.set_env('netbox_devices_tag','precision')

//Update agent with required deps
harness.set_required_agent(["sdg-nuc-01"])
harness.set_required_agent(["sdg-nuc-04"])
harness.set_env('update_container_lib', true)
harness.set_env('update_lib_requirements', true)
harness.update_agents()

//Set other test parameters
harness.set_env('docker_image', 'tfcollins/test-harness-ci:libm2k')
harness.set_nebula_debug(true)
harness.set_enable_docker(true)
harness.set_enable_docker(false)
harness.set_docker_host_mode(false)
harness.set_send_telemetry(false)
harness.set_log_jira(false)
Expand All @@ -50,7 +54,9 @@ lock(label: 'adgt_test_harness_boards') {
// "zynq-zed-ad4030",
// "zynq-zed-ad4630-16",
// "zynq-zed-ad4630-24"])
harness.set_required_hardware(["zynq-zed-adv7511-ad7768-1-evb"])
harness.set_required_hardware(["zynq-zed-adv7511-ad7768-1-evb-precision",
"zynq-zed-adv7511-ad4630-24-precision",
"zynq-zed-adv7511-ad7768-axi-adc-precision"])
harness.set_docker_args(['Vivado', 'MATLAB'])
harness.set_nebula_local_fs_source_root("artifactory.analog.com")

Expand Down
141 changes: 135 additions & 6 deletions test/AD4630_24Tests.m
Original file line number Diff line number Diff line change
@@ -1,29 +1,158 @@
classdef AD4630_24Tests < HardwareTests

properties(TestParameter)
end
properties
uri = 'ip:analog-2.local';
author = 'ADI';
end


properties(TestParameter)
% start frequency, stop frequency, step, tolerance, repeats
signal_test = {{10000,250000,2500,0.05,10}};
signal_vpp = {0.1, 0.3, 0.5};

sample_rate = {'10000', '50000', '100000', ...
'200000', '500000', '1000000', ...
'1760000', '2000000'};

sample_averaging_length = { ...
'2', '4', '8', '16', '32', '64', '128', '256', ...
'512', '1024', '2048', '4096', '8192', '16384', ...
'32768', '65536'};
end

methods(TestClassSetup)
% Check hardware connected
function CheckForHardware(testCase)
Device = @()adi.AD4630_24.Rx;
Device = @()adi.AD4630_24.Rx('uri',testCase.uri);
testCase.CheckDevice('ip',Device,testCase.uri(4:end),false);
end
end

methods (Static)
function freq = estFrequencyMax(data,fs)
nSamp = length(data);
FFTRxData = fftshift(10*log10(abs(fft(data))));
df = fs/nSamp; freqRangeRx = (0:df:fs/2-df).';
% Disregard DC
[~,ind] = maxk(FFTRxData(end-length(freqRangeRx)+1:end,:),2);
freq = max(freqRangeRx(ind));
end
end

methods (Test)

function testAD4630_24Smoke(testCase)
adc = adi.AD4630_24.Rx('uri',testCase.uri);
data = adc();
[data,valid] = adc();
adc.release();
testCase.assertTrue(valid);
testCase.assertTrue(sum(abs(double(data)))>0);
end


function testAD4630_24AttrSampleRate(testCase,sample_rate)
% '1750000' is set as '1754386'
adc = adi.AD4630_24.Rx('uri',testCase.uri);
adc.uri = testCase.uri;
val = sample_rate;
adc.SampleRate = val;
[data,valid] = adc();
ret_val = adc.getDeviceAttributeRAW('sampling_frequency',9);
adc.release();
testCase.assertTrue(valid);
testCase.assertTrue(sum(abs(double(data)))>0);
% testCase.assertTrue(strcmp(val,string(ret_val)), ...
% 'Sample rate unexpected')
testCase.verifyEqual(str2double(ret_val),str2double(val), ...
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

based on the comment on line 53, should the tolerance be a non-zero value?

'RelTol',0,'Sample rate unexpected')
end

% function testAD4630_24AttrSampleAveragingLength(testCase,sample_averaging_length)
% % The average mode works only with the output data mode set to 30-bit average
% % Skip test for now since it causes ERROR:READ LINE: -32 in iio_info
% adc = adi.AD4630_24.Rx('uri',testCase.uri);
% val = sample_averaging_length;
% adc.SampleAveragingLength = val;
% [data,valid] = adc();
% ret_val = adc.getDeviceAttributeRAW('sample_averaging',8);
% adc.release();
% testCase.assertTrue(valid);
% testCase.assertTrue(sum(abs(double(data)))>0);
% testCase.assertTrue(strcmp(val,string(ret_val)));
% end

function testAD4630_24DifferentialInputRMS(testCase,signal_vpp)
% Signal source setup
m2k_class = instr_m2k();
m2k = m2k_class.connect(getenv('M2K_URI'), false);
siggen = m2k_class.create_instr(m2k, "siggen");
% ADC setup
adc = adi.AD4630_24.Rx('uri',testCase.uri);
fs = str2double(adc.SampleRate);

% Set channel 1 to 50KHz, 500mHz and minimize channel 2 amplitude
signal_frequency = 5e4;
m2k_class.control(siggen, 0, [signal_frequency, signal_vpp, 0, 0]);
m2k_class.control(siggen, 1, [signal_frequency, 0.000001, 0, 0]);
for k = 1:5
[data,valid] = adc();
end
data = double(data);
% Generate same signal in channel 2 to double signal at differential inputs
m2k_class.control(siggen, 1, [signal_frequency, signal_vpp, 0, 0]);
for k = 1:5
[data1,valid1] = adc();
end
data1 = double(data1);

% Clean up
adc.release();
m2k_class.contextClose();

% Assertions
testCase.assertTrue(valid & valid1);
testCase.verifyEqual(rms(data1),rms(data)*2,'RelTol',0.3)
end

function testAD4630_24DifferentialInputSweep(testCase,signal_test)
% Signal source setup
m2k_class = instr_m2k();
m2k = m2k_class.connect(getenv('M2K_URI'), false);
siggen = m2k_class.create_instr(m2k, "siggen");
% ADC setup
adc = adi.AD4630_24.Rx('uri',testCase.uri);
adc.EnabledChannels = [1,2];
fs = str2double(adc.SampleRate);

start = signal_test{1};
stop = signal_test{2};
step = signal_test{3};
tol = signal_test{4};
repeats = signal_test{5};
numints = round((stop-start)/step);
for ii = 1:repeats
ind = randi([0, numints]);
frequency = start+(step*ind);
m2k_class.control(siggen, 0, [frequency, 0.5, 0, 0]);
m2k_class.control(siggen, 1, [frequency, 0.5, 0, 0]);
for k = 1:5
[data,valid] = adc();
end
data = double(data);
freq = estFrequencyMax(double(data),fs);

% Assertions
testCase.assertTrue(valid);
testCase.verifyEqual(freq(1),freq(2),'RelTol',tol)
testCase.verifyEqual(mean(freq),frequency,'RelTol',tol,...
'Frequency of signal unexpected')
end

% Clean up
adc.release();
m2k_class.contextClose();


end
end

end
Expand Down
58 changes: 55 additions & 3 deletions test/AD7768Tests.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
classdef AD7768Tests < HardwareTests

properties(TestParameter)
end

properties
uri = 'ip:analog-2.local';
author = 'ADI';
end

properties(TestParameter)
% start frequency. stop frequency, step, tolerance, repeats
signal_test = {{1000,100000,2500,0.025,10}};
sample_rate = {'256000', '128000', '64000', ...
'32000', '16000', '8000', '4000', ...
'2000', '1000'};
end

methods(TestClassSetup)
% Check hardware connected
Expand All @@ -14,6 +20,17 @@ function CheckForHardware(testCase)
testCase.CheckDevice('ip',Device,testCase.uri(4:end),false);
end
end

methods (Static)
function freq = estFrequencyMax(data,fs)
nSamp = length(data);
FFTRxData = fftshift(10*log10(abs(fft(data))));
df = fs/nSamp; freqRangeRx = (0:df:fs/2-df).';
% Disregard DC
[~,ind] = maxk(FFTRxData(end-length(freqRangeRx)+1:end,:),2);
freq = max(freqRangeRx(ind));
end
end

methods (Test)

Expand All @@ -23,6 +40,41 @@ function testAD7768Smoke(testCase)
adc.release();
testCase.assertTrue(sum(abs(double(data)))>0);
end

function testAD7768Signal(testCase,signal_test)
% Signal source setup
m2k_class = instr_m2k();
m2k = m2k_class.connect(getenv('M2K_URI'), false);
siggen = m2k_class.create_instr(m2k, "siggen");
% ADC setup
adc = adi.AD7768.Rx;
adc.uri = testCase.uri;
adc.EnabledChannels = [1 2 3 4 5 6 7 8];

start = signal_test{1};
stop = signal_test{2};
step = signal_test{3};
tol = signal_test{4};
repeats = signal_test{5};
numints = round((stop-start)/step);
for ii = 1:repeats
ind = randi([0, numints]);
frequency = start+(step*ind);
m2k_class.control(siggen, 0, [frequency, 0.5, 0.5, 0]);
m2k_class.control(siggen, 1, [frequency, 0.5, 0.5, 0]);
for k = 1:5
data = adc();
end
for ch = adc.EnabledChannels
freqEst = testCase.estFrequencyMax(data(:,ch),str2double(adc.SampleRate));
testCase.assertTrue(sum(abs(double(data(:,ch))))>0);
testCase.verifyEqual(freqEst,frequency,'RelTol',tol,...
'Frequency of signal unexpected')
end
end
adc.release();
m2k_class.contextClose();
end

end

Expand Down
Loading
Loading