-
Notifications
You must be signed in to change notification settings - Fork 320
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Travis F. Collins <travis.collins@analog.com>
- Loading branch information
Showing
10 changed files
with
370 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
name: Test MATLAB Bindings | ||
|
||
on: [push] | ||
|
||
env: | ||
LD_LIBRARY_PATH: /lib/x86_64-linux-gnu/libstdc++.so.6 | ||
|
||
jobs: | ||
build: | ||
name: Test MATLAB Bindings | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Set up Python 3.10 | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.10' | ||
- name: Set up MATLAB | ||
uses: matlab-actions/setup-matlab@v2 | ||
with: | ||
release: R2023b | ||
- name: Check out repository | ||
uses: actions/checkout@v3 | ||
with: | ||
submodules: recursive | ||
- name: Install dependencies | ||
run: | | ||
sudo apt-get -qq update | ||
sudo apt-get install -y git cmake graphviz libavahi-common-dev libavahi-client-dev libaio-dev libusb-1.0-0-dev libxml2-dev rpm tar bzip2 gzip flex bison git libzstd-dev | ||
# Change LD_LIBRARY PATH TO USE MATLAB GLIBC | ||
# Find location of libstdc++.so.6 of MATLAB | ||
#LDLIBMATLAB=$(find /opt/hostedtoolcache/MATLAB/ -name libstdc++.so.6 | grep -v orig) | ||
#echo "LDLIBMATLAB=$LDLIBMATLAB" | ||
echo "IIO_EMU_PREFIX='LD_LIBRARY_PATH=/lib/x86_64-linux-gnu/libstdc++.so.6'" >> $GITHUB_ENV | ||
#export LIBRARY_PATH=$LDLIBMATLAB:$LD_LIBRARY_PATH | ||
# export LD_LIBRARY_PATH=$LDLIBMATLAB | ||
cmake . -DHAVE_DNS_SD=OFF -DPYTHON_BINDINGS=ON -DCMAKE_CROSSCOMPILING=ON | ||
make | ||
sudo make install | ||
sudo make clean | ||
cd bindings/python | ||
ls | ||
sudo rm -rf pylibiio.egg-info | ||
pip install . | ||
cd ../.. | ||
mkdir edeps | ||
cd edeps | ||
git clone https://github.com/analogdevicesinc/libtinyiiod.git | ||
cd libtinyiiod | ||
mkdir build && cd build | ||
cmake -DBUILD_EXAMPLES=OFF .. | ||
make | ||
sudo make install | ||
sudo ldconfig | ||
cd ../.. | ||
git clone -b v0.1.0 https://github.com/analogdevicesinc/iio-emu.git | ||
cd iio-emu | ||
mkdir build && cd build | ||
cmake .. | ||
make | ||
sudo make install | ||
sudo ldconfig | ||
cd ../.. | ||
cd .. | ||
- name: Install pytest-libiio interface | ||
run: | | ||
pip install pytest pyyaml lxml click | ||
git clone https://github.com/tfcollins/pytest-libiio.git -b tfcollins/glibc | ||
mv pytest-libiio/pytest_libiio bindings/matlab/ | ||
cd bindings/matlab | ||
python -c 'import pytest_libiio.plugin' | ||
cd ../.. | ||
- name: Run Tests | ||
uses: matlab-actions/run-command@v2 | ||
with: | ||
command: addpath(genpath('include'));cd('bindings/matlab');addpath(genpath('.'));runTests;exit() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
classdef common < handle | ||
% Common class implementation for the libiio library | ||
% | ||
% This class is a common parent class for all libiio classes. It | ||
% provides a common constructor and destructor for all classes. | ||
% | ||
% See also: Context, Device, Channel, Attribute, Buffer, BufferData | ||
% | ||
% ---------------------------------------------------------------------------- | ||
|
||
properties (SetAccess = protected) | ||
% Pointer to the C++ object | ||
pImpl | ||
end | ||
|
||
methods (Access = protected) | ||
function obj = common() | ||
% Constructor | ||
% | ||
% This function creates a new instance of the common class. | ||
% | ||
% See also: delete | ||
% | ||
% ---------------------------------------------------------------------------- | ||
obj.pImpl = []; | ||
end | ||
|
||
function delete(obj) | ||
% Destructor | ||
% | ||
% This function deletes the instance of the common class. | ||
% | ||
% See also: common | ||
% | ||
% ---------------------------------------------------------------------------- | ||
if ~isempty(obj.pImpl) | ||
delete(obj.pImpl); | ||
end | ||
end | ||
|
||
end | ||
|
||
methods (Access = protected, Static) | ||
|
||
function libname = getLibraryName(~) | ||
% Get the library name | ||
% | ||
% This function returns the name of the libiio library. | ||
% | ||
% ---------------------------------------------------------------------------- | ||
libname = 'libiio'; | ||
end | ||
|
||
function checkLibraryLoaded(~) | ||
if ~libisloaded('libiio') | ||
context.loadLibrary() | ||
% error('libiio library not loaded'); | ||
end | ||
end | ||
|
||
function loadLibrary(~) | ||
% Load the libiio library | ||
% | ||
% This function loads the libiio library. | ||
% | ||
libName = 'libiio'; | ||
libiiowrapperh = 'iio-wrapper.h'; | ||
iioh = 'iio.h'; | ||
fp = fileparts(which(iioh)); | ||
loadlibraryArgs = {libiiowrapperh,'includepath',fp,... | ||
'addheader',iioh}; | ||
if ~libisloaded(libName) | ||
msgID = 'MATLAB:loadlibrary:StructTypeExists'; | ||
warnStruct = warning('off',msgID); | ||
[~, ~] = loadlibrary(libName, loadlibraryArgs{:}); | ||
warning(warnStruct); | ||
end | ||
end | ||
|
||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
classdef context < common | ||
% Context class implementation for the libiio library | ||
|
||
|
||
methods (Static) | ||
|
||
function ctx = iio_create_context(params, uri) | ||
% Create a new context | ||
% | ||
% This function creates a new context. | ||
context.checkLibraryLoaded(); | ||
if isempty(params) | ||
params = libpointer; | ||
end | ||
ctx = calllib(context.getLibraryName(), 'iio_create_context', params, uri); | ||
end | ||
|
||
function name = iio_context_get_name(ctx) | ||
context.checkLibraryLoaded(); | ||
name = calllib(context.getLibraryName(), 'iio_context_get_name', ctx); | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
#ifndef MATLAB_LOADLIBRARY | ||
#define MATLAB_LOADLIBRARY | ||
#include <iio/iio.h> | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
classdef TestContext < matlab.unittest.TestCase | ||
|
||
properties | ||
uri = 'ip:pluto.local'; | ||
end | ||
|
||
properties(Hidden) | ||
emu = []; | ||
end | ||
|
||
methods(TestClassSetup) | ||
% Start emulation context | ||
function startEmulation(testCase) | ||
%% Start the emulation context | ||
% checkIIOEMU; | ||
[folder,~,~] = fileparts(mfilename('fullpath')); | ||
% folder = strsplit(filepath, filesep); | ||
% folder = fullfile(folder{end}); | ||
% Load python virtual environment | ||
pe = getenv('PYTHON_EXE'); | ||
if ~isempty(pe) | ||
p = pyenv(ExecutionMode="OutOfProcess",Version=pe); | ||
else | ||
p = pyenv(ExecutionMode="OutOfProcess"); | ||
end | ||
disp(p); | ||
% Start background process | ||
xmlfile = fullfile(folder, 'pluto.xml'); | ||
testCase.emu = py.pytest_libiio.plugin.iio_emu_manager(xmlfile); | ||
disp(testCase.emu.uri) | ||
testCase.emu.start(); | ||
disp('iio-emu started'); | ||
% Wait for the emulation to start | ||
pause(5); | ||
% Set uri to be loopback | ||
testCase.uri = char(testCase.emu.uri); | ||
end | ||
end | ||
|
||
methods(TestClassTeardown) | ||
function shutdownEmulation(testCase) | ||
testCase.emu.stop(); | ||
disp('Emulation stop') | ||
end | ||
end | ||
|
||
methods(Test) | ||
% Test methods | ||
|
||
function testThunkGen(testCase) | ||
generateThunkFiles; | ||
end | ||
|
||
function testCreateContext(testCase) | ||
ctx = context.iio_create_context([],testCase.uri); | ||
name = context.iio_context_get_name(ctx); | ||
disp(name); | ||
assert(ctx); | ||
end | ||
|
||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
% Verify iio-emu executable is in the path | ||
[status, r] = system('iio-emu -l'); | ||
% Check error code | ||
assert(~status, 'iio-emu executable not found in the path'); |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
libName = 'libiio'; | ||
libiiowrapperh = 'iio-wrapper.h'; | ||
iioh = 'iio.h'; | ||
fp = fileparts(which(iioh)); | ||
if isempty(fp) | ||
error('Cannot find %s', iioh); | ||
end | ||
loadlibraryArgs = {libiiowrapperh,'includepath',fp,... | ||
'addheader',iioh}; | ||
|
||
|
||
if ~libisloaded(libName) | ||
msgID = 'MATLAB:loadlibrary:StructTypeExists'; | ||
warnStruct = warning('off',msgID); | ||
[~, ~] = loadlibrary(libName, loadlibraryArgs{:}); | ||
warning(warnStruct); | ||
end | ||
|
||
if isunix | ||
rext = '.so'; | ||
elseif ispc | ||
rext = '.dll'; | ||
else | ||
rext = '.dylib'; | ||
end | ||
|
||
mkdir 'thunks' | ||
searchdir = [tempdir,filesep,'tp*']; | ||
files = dir(searchdir); | ||
for fileIndx = 1:length(files) | ||
disp(files(fileIndx).name) | ||
if files(fileIndx).isdir | ||
folder = [files(fileIndx).folder,filesep,files(fileIndx).name]; | ||
filesInFolder = dir(folder); | ||
for i = 1:length(filesInFolder) | ||
if ~filesInFolder(i).isdir | ||
[~,~,ext] = fileparts(filesInFolder(i).name); | ||
if strcmpi(ext,rext) | ||
fullpath = fullfile(... | ||
folder,... | ||
filesInFolder(i).name); | ||
fprintf('Found thunk: %s\n', fullpath); | ||
copyfile(fullpath, 'thunks'); | ||
end | ||
end | ||
end | ||
end | ||
end | ||
|
||
unloadlibrary(libName); |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
function runTests() | ||
|
||
import matlab.unittest.TestRunner; | ||
import matlab.unittest.TestSuite; | ||
import matlab.unittest.plugins.TestReportPlugin; | ||
import matlab.unittest.plugins.XMLPlugin | ||
import matlab.unittest.plugins.ToUniqueFile; | ||
import matlab.unittest.plugins.TAPPlugin; | ||
import matlab.unittest.plugins.DiagnosticsValidationPlugin | ||
import matlab.unittest.parameters.Parameter | ||
|
||
runParallel = false; | ||
|
||
suite = testsuite({'TestContext'}); | ||
|
||
try | ||
|
||
runner = matlab.unittest.TestRunner.withTextOutput('OutputDetail',4); | ||
runner.addPlugin(DiagnosticsValidationPlugin) | ||
|
||
xmlFile = 'BindingsTests.xml'; | ||
plugin = XMLPlugin.producingJUnitFormat(xmlFile); | ||
runner.addPlugin(plugin); | ||
|
||
if runParallel | ||
try %#ok<UNRCH> | ||
parpool(2); | ||
results = runInParallel(runner,suite); | ||
catch ME | ||
disp(ME); | ||
results = runner.run(suite); | ||
end | ||
else | ||
results = runner.run(suite); | ||
end | ||
|
||
t = table(results); | ||
disp(t); | ||
disp(repmat('#',1,80)); | ||
for test = results | ||
if test.Failed | ||
disp(test.Name); | ||
end | ||
end | ||
catch e | ||
disp(getReport(e,'extended')); | ||
bdclose('all'); | ||
exit(1); | ||
end | ||
|
||
try | ||
poolobj = gcp('nocreate'); | ||
delete(poolobj); | ||
catch ME | ||
disp(ME) | ||
end | ||
|
||
save(['BSPTest_',datestr(now,'dd_mm_yyyy-HH:MM:SS'),'.mat'],'t'); | ||
bdclose('all'); | ||
exit(any([results.Failed])); |