Skip to content

Commit

Permalink
Fixup tests
Browse files Browse the repository at this point in the history
  • Loading branch information
traversaro committed Mar 1, 2022
1 parent 97e0afb commit d03c8b9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/matlab.yml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@ jobs:
- name: Test
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 .
ctest --output-on-failure -C ${{ matrix.build_type }} -VV .
18 changes: 17 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ option(BUILD_SHARED_LIBS "Build libraries as shared as opposed to static" ON)
option(OSQP_MATLAB_USES_MATLAB "Do you want to create the MATLAB bindings" ON)
option(OSQP_MATLAB_USES_OCTAVE "Do you want to create the Octave bindings" OFF)

option(BUILD_TESTING "Create tests using CMake" OFF)
if(BUILD_TESTING)
enable_testing()
endif()

set(OSQP_MATLAB_INSTALL_MATLAB_LIBDIR "mex" CACHE
STRING "Location (relative to the install prefix) in which the Matlab mex libraries are installed.")
set(OSQP_MATLAB_INSTALL_MATLAB_MFILESDIR "mex" CACHE
Expand Down Expand Up @@ -73,7 +78,8 @@ set(M_FILES ${osqp-matlab_SOURCE_DIR}/osqp.m)
set(MEX_FILES ${osqp-matlab_SOURCE_DIR}/osqp_mex.hpp ${osqp-matlab_SOURCE_DIR}/osqp_mex.cpp)

if(OSQP_MATLAB_USES_MATLAB)
find_package(Matlab REQUIRED)
find_package(Matlab REQUIRED
COMPONENTS MAIN_PROGRAM)
matlab_add_mex(
NAME osqp_mex_matlab
OUTPUT_NAME osqp_mex
Expand All @@ -89,6 +95,15 @@ if(OSQP_MATLAB_USES_MATLAB)
install(
FILES ${M_FILES}
DESTINATION ${OSQP_MATLAB_INSTALL_MATLAB_MFILESDIR})

# Enable tests
if (BUILD_TESTING)
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/run_osqp_tests_no_codegen.m.in ${CMAKE_CURRENT_BINARY_DIR}/run_osqp_tests_no_codegen.m @ONLY)
# Note: this only works if the project was installed in the correct location and can be found with MATLABPATH
add_test(NAME matlab_osqp_tests
COMMAND ${Matlab_MAIN_PROGRAM} -nodisplay -nodesktop -nojvm -batch "addpath('${CMAKE_CURRENT_BINARY_DIR}');run_osqp_tests_no_codegen;")

endif()
endif()

if(OSQP_MATLAB_USES_OCTAVE)
Expand Down Expand Up @@ -116,4 +131,5 @@ if(OSQP_MATLAB_USES_OCTAVE)
DESTINATION ${OSQP_MATLAB_INSTALL_OCTAVE_MFILESDIR})
endif()


include(AddUninstallTarget)
22 changes: 22 additions & 0 deletions run_osqp_tests_no_codegen.m.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import matlab.unittest.TestSuite;
import matlab.unittest.selectors.HasSharedTestFixture;
import matlab.unittest.selectors.HasName;
import matlab.unittest.fixtures.PathFixture;
import matlab.unittest.constraints.EndsWithSubstring;
import matlab.unittest.constraints.ContainsSubstring;

osqp_src_path = "@osqp-matlab_SOURCE_DIR@";
unittest_dir = fullfile(osqp_src_path, 'unittests');
suiteFolder = TestSuite.fromFolder(unittest_dir);

% Exclude tests that contain codegen in the name
suiteNoCodegen = selectIf(suiteFolder,~HasName(ContainsSubstring('codegen','IgnoringCase',true)));

% Run all suite
result = run(suiteNoCodegen);

% Print test results
disp(table(result))

% Return error code if test failed
assertSuccess(result)

0 comments on commit d03c8b9

Please sign in to comment.