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

Add GitHub Action job to run MATLAB tests #917

Merged
merged 4 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from 3 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
93 changes: 93 additions & 0 deletions .github/workflows/matlab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
name: MATLAB Tests Workflow

on:
push:
pull_request:
schedule:
# * is a special character in YAML so you have to quote this string
# Execute a "nightly" build at 2 AM UTC
- cron: '0 2 * * *'

jobs:
build-matlab-tests:
name: '[matlab:${{ matrix.matlab_version }}:${{ matrix.os }}]'
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
build_type: [Release]
os: [ubuntu-20.04]
matlab_version: [R2020a, R2020b, R2021a, latest]

steps:
- uses: actions/checkout@v2

- uses: conda-incubator/setup-miniconda@v2
with:
miniforge-variant: Mambaforge
miniforge-version: latest
channels: conda-forge,robotology

- name: Setup MATLAB
uses: matlab-actions/setup-matlab@v1
with:
release: ${{ matrix.matlab_version }}

# workaround for https://github.com/robotology/robotology-superbuild/issues/64
- name: Do not use MATLAB's stdc++ to avoid incompatibilities with other libraries
if: contains(matrix.os, 'ubuntu')
run:
echo 'LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libstdc++.so.6' >> $GITHUB_ENV

- name: Dependencies
shell: bash -l {0}

Choose a reason for hiding this comment

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

To avoid specifying that each shell is login you can set a default shell.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done in 695d813 .

run: |
# Workaround for https://github.com/conda-incubator/setup-miniconda/issues/186
conda config --remove channels defaults
# Compilation related dependencies
mamba install cmake compilers make ninja pkg-config
# Actual dependencies
mamba install eigen libxml2 assimp ipopt qt irrlicht osqp-eigen

# Additional dependencies useful only on Linux
- name: Dependencies [Conda/Linux]
if: contains(matrix.os, 'ubuntu')
shell: bash -l {0}
run: |
# Additional dependencies only useful on Linux
# See https://github.com/robotology/robotology-superbuild/issues/477
mamba install expat-cos6-x86_64 freeglut libselinux-cos6-x86_64 libxau-cos6-x86_64 libxcb-cos6-x86_64 libxdamage-cos6-x86_64 libxext-cos6-x86_64 libxfixes-cos6-x86_64 libxxf86vm-cos6-x86_64 mesalib mesa-libgl-cos6-x86_64

- name: Configure
if: contains(matrix.os, 'macos') || contains(matrix.os, 'ubuntu')
shell: bash -l {0}
run: |
mkdir build
cd build
cmake -GNinja -DCMAKE_INSTALL_PREFIX=${CONDA_PREFIX} -DCMAKE_BUILD_TYPE=${{ matrix.build_type }} -DMATLAB_FIND_DEBUG:BOOL=ON -DIDYNTREE_USES_MATLAB:BOOL=ON -DIDYNTREE_COMPILE_TESTS:BOOL=ON -DIDYNTREE_USES_QT5:BOOL=ON -DIDYNTREE_USES_ASSIMP:BOOL=ON -DIDYNTREE_USES_IPOPT:BOOL=ON -DIDYNTREE_USES_IRRLICHT:BOOL=ON -DIDYNTREE_USES_YARP:BOOL=OFF -DIDYNTREE_USES_ICUB_MAIN:BOOL=OFF -DIDYNTREE_USES_OSQPEIGEN:BOOL=ON ..

- name: Build
shell: bash -l {0}
run: |
cd build
cmake --build . --config ${{ matrix.build_type }}

- name: Inspect libraries linked by iDynTreeMEX.mexa64 [Conda/Linux]
if: contains(matrix.os, 'ubuntu')
shell: bash -l {0}
run: |
cd build
ldd ./lib/iDynTreeMEX.mexa64

- name: Test [Conda]
shell: bash -l {0}
run: |
cd build
# Only run matlab tests as the rest of tests are already run by other jobs
ctest --output-on-failure -C ${{ matrix.build_type }} -R "matlab" -VV .

- name: Install [Conda]
shell: bash -l {0}
run: |
cd build
cmake --install . --config ${{ matrix.build_type }}
2 changes: 1 addition & 1 deletion bindings/matlab/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ if (IDYNTREE_USES_MATLAB AND NOT IDYNTREE_DISABLE_MATLAB_TESTS)
find_package(Matlab REQUIRED
COMPONENTS MAIN_PROGRAM)
add_test(NAME matlab_idyntree_tests
COMMAND ${Matlab_MAIN_PROGRAM} -nodisplay -nodesktop -nojvm -r "addpath('$<TARGET_FILE_DIR:${mexname}>');addpath('${MEX_BINDINGS_SOURCE_DIR}');addpath('${MATLAB_WRAPPERS_BINDINGS_SOURCE_DIR}');addpath('${CMAKE_CURRENT_SOURCE_DIR}/');addpath(genpath('${IDYNTREE_INTERNAL_MOXUNIT_PATH}'));success=moxunit_runtests('${CMAKE_CURRENT_SOURCE_DIR}','-verbose');exit(~success);")
COMMAND ${Matlab_MAIN_PROGRAM} -nodisplay -nodesktop -nojvm -batch "addpath('$<TARGET_FILE_DIR:${mexname}>');addpath('${MEX_BINDINGS_SOURCE_DIR}');addpath('${MATLAB_WRAPPERS_BINDINGS_SOURCE_DIR}');addpath('${CMAKE_CURRENT_SOURCE_DIR}/');addpath(genpath('${IDYNTREE_INTERNAL_MOXUNIT_PATH}'));success=moxunit_runtests('${CMAKE_CURRENT_SOURCE_DIR}','-verbose');exit(~success);")
endif()

if (IDYNTREE_USES_OCTAVE)
Expand Down
4 changes: 4 additions & 0 deletions bindings/matlab/tests/EKFTest.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
function test_suite=EKFTest
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
test_functions=localfunctions();
catch % no problem; early Matlab versions can use initTestSuite fine
end
initTestSuite

function test_span
Expand Down
4 changes: 4 additions & 0 deletions bindings/matlab/tests/InertiaUnitTest.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
function test_suite=InertiaUnitTest
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
test_functions=localfunctions();
catch % no problem; early Matlab versions can use initTestSuite fine
end
initTestSuite

function test_momentum_invariance
Expand Down
4 changes: 4 additions & 0 deletions bindings/matlab/tests/JointUnitTest.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
function test_suite=JointUnitTest
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
test_functions=localfunctions();
catch % no problem; early Matlab versions can use initTestSuite fine
end
initTestSuite

function test_joint_constructor
Expand Down
4 changes: 4 additions & 0 deletions bindings/matlab/tests/MatrixUnitTest.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
function test_suite=MatrixUnitTest
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
test_functions=localfunctions();
catch % no problem; early Matlab versions can use initTestSuite fine
end
initTestSuite

function test_sparse_matrices
Expand Down
4 changes: 4 additions & 0 deletions bindings/matlab/tests/PositionUnitTest.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
function test_suite=PositionUnitTest
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
test_functions=localfunctions();
catch % no problem; early Matlab versions can use initTestSuite fine
end
initTestSuite
test_sum_of_positions

Expand Down
4 changes: 4 additions & 0 deletions bindings/matlab/tests/TransformUnitTest.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
function test_suite=TransformUnitTest
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
test_functions=localfunctions();
catch % no problem; early Matlab versions can use initTestSuite fine
end
initTestSuite

function test_pos_twist_wrench_invariance
Expand Down
4 changes: 4 additions & 0 deletions bindings/matlab/tests/highLevelWrappersSmokeTest.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
function test_suite = highLevelWrappersSmokeTest
try % assignment of 'localfunctions' is necessary in Matlab >= 2016
test_functions=localfunctions();
catch % no problem; early Matlab versions can use initTestSuite fine
end
initTestSuite

function test__high_level_wrappers
Expand Down
44 changes: 44 additions & 0 deletions extern/MOxUnit/.github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: CI

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "unit-tests"
unit-tests:
# The type of runner that the job will run on
runs-on: ubuntu-latest

# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2

# Use A Github Action to perform tests
- name: run unit tests and documentation tests, generate coverage report
uses: joergbrech/moxunit-action@v1.1
with:
tests: tests
src: MOxUnit
with_coverage: true
doc_tests: true
cover_xml_file: coverage.xml

# Store the coverage report as an artifact
- name: Store Coverage report as artifact
uses: actions/upload-artifact@v1
with:
name: coverage_xml_file
path: coverage.xml

## Use a Github Action to publish coverage reports
#- name: Publish coverage report to codecov.io
# uses: codecov/codecov-action@v1
# with:
# file: ./coverage.xml
14 changes: 14 additions & 0 deletions extern/MOxUnit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
*.DS_Store
*.swp
*.css
*.m~
data
datadb
datadb.zip
.git.bfg-report
*.md.sw?
octave-workspace
git_log.txt
git_summary.txt
*.pyc
*.asv
82 changes: 82 additions & 0 deletions extern/MOxUnit/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# vim ft=yaml
# travis-ci.org definition for MOxUnit build (based on CoSMoMVPA,
# which is based on PyMVPA, which is based on nipype configuration,
# which in turn was based on nipy)

language: minimal
os: linux

cache:
- apt

env:
matrix:
- WITH_COVERAGE=
- WITH_COVERAGE=true
- RUN_DOC_TEST=true

before_install:
# to prevent IPv6 being used for APT
- sudo bash -c "echo 'Acquire::ForceIPv4 \"true\";' > /etc/apt/apt.conf.d/99force-ipv4"
- travis_retry sudo apt-get -y -qq update
- travis_retry sudo apt-get install -y -qq software-properties-common python-software-properties
- travis_retry sudo apt-add-repository -y ppa:octave/stable
- travis_retry sudo apt-get -y -qq update
# get Octave 4,0
- travis_retry sudo apt-get -y -qq install octave liboctave-dev
# install MOcov
- cd ..
- rm -rf MOcov
- git clone https://github.com/MOcov/MOcov.git
- make -C MOcov install
# retrieve MOdox
- rm -rf MOdox
- travis_retry git clone -v git://github.com/MOdox/MOdox.git
- make -C MOdox install
# go back to original directory
- cd MOxUnit
# prevent shippable from re-using old test results
- if [[ "$SHIPPABLE" == "true" ]]; then
if [[ "$WITH_COVERAGE" != "true" ]]; then
rm -f ${SHIPPABLE_BUILD_DIR}/shippable/testresults/*.xml;
fi;
fi

script:
- if [[ "$WITH_COVERAGE" == "true" ]]; then
TEST_ARGS=WITH_COVERAGE=true;
COVER_ARGS=COVER=`pwd`/MOxUnit;

if [[ "$SHIPPABLE" == "true" ]]; then
OUTPUT_ARGS=COVER_XML_FILE=${SHIPPABLE_BUILD_DIR}/shippable/codecoverage/coverage.xml;
AFTER_SCRIPT="find ${SHIPPABLE_BUILD_DIR}/shippable/;cat ${SHIPPABLE_BUILD_DIR}/shippable/codecoverage/coverage.xml;which reports";
elif [[ "$TRAVIS" == "true" ]]; then
OUTPUT_ARGS=COVER_JSON_FILE=`pwd`/coveralls.json;
AFTER_SCRIPT="curl --verbose -F json_file=@`pwd`/coveralls.json https://coveralls.io/api/v1/jobs";
fi;
elif [[ "$SHIPPABLE" == "true" ]]; then
RESULT_ARGS=JUNIT_XML_FILE=${SHIPPABLE_BUILD_DIR}/shippable/testresults/test_results.xml;
elif [[ "$RUN_DOC_TEST" == "true" ]]; then
TEST_ARGS=RUN_DOC_TEST=true;
fi;

- echo Test arguments $TEST_ARGS $COVER_ARGS $OUTPUT_ARGS $RESULT_ARGS
- make test $TEST_ARGS $COVER_ARGS $OUTPUT_ARGS $RESULT_ARGS
- eval $AFTER_SCRIPT

jobs:
include:
- language: matlab
matlab: R2020a

# No need to do anything, but the 'before_install' key is inherited from teh enclosing scope and has to be reset to something insubstantial
before_install:
- echo 'noop'
# Could also clear 'env' but, as is, the only environment variable inhereted fromthe scope is $WITH_COVERAGE which does nothing here

script:
- if [[ "$SHIPPABLE" == "true" ]]; then
echo 'No Matlab testing on Shippable';
else
matlab -batch 'back=cd("./MOxUnit/"); moxunit_set_path(); cd(back); moxunit_runtests tests -verbose; exit(double(~ans))';
fi;
2 changes: 1 addition & 1 deletion extern/MOxUnit/COPYING
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
(The MIT License)

Copyright (c) 2015 Nikolaas N. Oosterhof
Copyright (c) 2015-2017 Nikolaas N. Oosterhof

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
Expand Down
42 changes: 39 additions & 3 deletions extern/MOxUnit/MOxUnit/@MOxUnitFunctionHandleTestCase/run.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,19 @@
%
% NNO 2015

original_warning_state=warning('query');
warning_state_resetter=onCleanup(@()warning(original_warning_state));

start_tic = tic;

try
passed=false;
try
obj.function_handle();
if nargin(obj.function_handle) > 0
obj.function_handle(obj);
else
obj.function_handle();
end
passed=true;
catch
e=lasterror();
Expand All @@ -39,7 +46,11 @@
test_outcome_args={reason};
else
test_outcome_constructor=@MOxUnitFailedTestOutcome;
test_outcome_args={e};

% trim the stack so that all test case machinery is
% removed from the stack
e_trimmed=trim_stack(e);
test_outcome_args={e_trimmed};
end
end

Expand All @@ -56,4 +67,29 @@
test_outcome = test_outcome_constructor(obj, toc(start_tic), ...
test_outcome_args{:});

report = reportTestOutcome(report, test_outcome);
report = reportTestOutcome(report, test_outcome);


function e_trimmed=trim_stack(e)
% trim the stack from e.stack, so that everything up to and including the
% first (nearest to the calling root) entry is removed
stack=e.stack;

n_stack=numel(stack);

this_file=sprintf('%s.m',mfilename('fullpath'));

for pos=n_stack:-1:1
if strcmp(stack(pos).file,this_file)
% found first match with this filename, now trim this function
% and their callig functions
trimmed_stack=stack(1:(pos-1));

e_trimmed=e;
e_trimmed.stack=trimmed_stack;
return;
end
end

assert(false,'This should not happen');

Loading