Skip to content

[UNVERIFIED-needs-MATLAB] test: skip MATLAB runtime tests when no MATLAB is installed#76

Closed
ChrisRackauckas-Claude wants to merge 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix-skip-tests-without-matlab
Closed

[UNVERIFIED-needs-MATLAB] test: skip MATLAB runtime tests when no MATLAB is installed#76
ChrisRackauckas-Claude wants to merge 1 commit into
SciML:masterfrom
ChrisRackauckas-Claude:fix-skip-tests-without-matlab

Conversation

@ChrisRackauckas-Claude

Copy link
Copy Markdown
Member

Root cause

On master, test/runtests.jl (lines 12-44) unconditionally ran the runtime ODE-solving tests:

sol = solve(prob, MATLABDiffEq.ode45())

solve reaches __solve at src/MATLABDiffEq.jl:118, which calls put_variable(get_default_msession(), ...). get_default_msession() constructs a MATLAB.MSession, which does ccall(eng_open[], ...) (MATLAB/engine.jl:48).

When no MATLAB is installed (every CI runner here, since there is no MATLAB license), MATLAB.jl is built with dummy deps (libmx_size == 0, the documented CI/AutoMerge path in MATLAB.jl's deps/build.jl). With libmx_size == 0, MATLAB.jl's __init__ deliberately skips binding all the engine/mxarray function-pointer Refs (if libmx_size > 0 ... end). So eng_open[] is an unassigned Ref{Ptr{Cvoid}}, and dereferencing it throws:

ERROR: LoadError: UndefRefError: access to undefined reference
  [1] MATLAB.MSession(...)        @ MATLAB engine.jl:48
  [3] get_default_msession        @ MATLAB engine.jl:124
  [4] __solve                     @ MATLABDiffEq src/MATLABDiffEq.jl:118
  ...                             @ test/runtests.jl:20
ERROR: Package MATLABDiffEq errored during testing

This is not a MATLAB.jl API regression and not a ModelingToolkit v11 glue bug: the modelingtoolkitize + build_function(::MATLABTarget()) code generation at lines 107-115 runs fine on ModelingToolkit v11.26.8 / Symbolics v7.26.0. The failure is solely that the suite tries to open a MATLAB engine that does not exist.

Fix

Gate the runtime ODE-solving tests on a real MATLAB being present, using MATLAB.libmx_size > 0 — the exact flag MATLAB.jl itself uses to decide whether to load its native libraries. When MATLAB is present the tests run for real (now with explicit @test assertions on the returned solution, which the old code lacked). When absent, they are skipped with an informative @info message. The MATLAB-free interface and JET/static-analysis tests always run.

No assertions were loosened, skipped, @test_broken-ed, or wrapped in error-swallowing try/catch. The runtime tests are gated on a genuine environment-capability flag, not silenced.

What was verified

Reproduced and fixed locally with an isolated depot on Julia 1.10.11, with CI=true so MATLAB.jl builds the dummy deps exactly as on CI (no MATLAB on the machine).

  • Unmodified master (reproduction): suite errors at test/runtests.jl:20 with UndefRefError (matches the failing CI logs). Interface (40/40) and Static Analysis (38/38) testsets passed before the error.
  • With this fix: suite passes.
    [ Info: No MATLAB installation detected (MATLAB.libmx_size == 0); skipping the MATLAB runtime solving tests...
    Test Summary:           | Pass  Total  Time
    Interface Compatibility |   40     40  0.1s
    Test Summary:         | Pass  Total  Time
    Static Analysis Tests |   38     38  0.8s
    Testing MATLABDiffEq tests passed
    

What could NOT be verified

There is no MATLAB on this machine, so the HAS_MATLAB == true branch (the actual ODE solves and their new assertions) was not executed. That path is unchanged in behavior from the original tests aside from the added @tests; it still needs a run on a machine with a MATLAB license to confirm end-to-end. Marking this PR UNVERIFIED-needs-MATLAB for that reason.

Runic: ran the Runic.jl formatter on test/runtests.jl (already formatted, no changes).

Ignore until reviewed by @ChrisRackauckas.

🤖 Generated with Claude Code

The runtime ODE-solving block in test/runtests.jl unconditionally called
solve(prob, MATLABDiffEq.ode45()), which opens a MATLAB engine session. When
no MATLAB is installed (e.g. CI without a license), MATLAB.jl is built with
dummy deps (libmx_size == 0) and __init__ never binds the engine function
pointers, so get_default_msession() -> MSession() -> ccall(eng_open[], ...)
throws `UndefRefError: access to undefined reference`. This errored the whole
test suite even though the interface and static-analysis tests passed.

Gate the runtime tests on MATLAB.libmx_size > 0 (the same flag MATLAB.jl uses
to decide whether to load the native libraries). When MATLAB is present the
tests run for real with added @test assertions on the returned solution; when
absent they are skipped with an informative @info message. The non-MATLAB
interface/JET tests always run.

Co-Authored-By: Chris Rackauckas <accounts@chrisrackauckas.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ChrisRackauckas-Claude ChrisRackauckas-Claude changed the title test: skip MATLAB runtime tests when no MATLAB is installed [UNVERIFIED-needs-MATLAB] test: skip MATLAB runtime tests when no MATLAB is installed Jun 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants