Run test replacing calls to MATLAB functions with calls to MEX functions
coder.runTest(
runs test
,fcn
)test
replacing
calls to fcn
with calls to the compiled version
of fcn
. test
is the file
name for a MATLAB® function, script, or class-based unit test
that calls the MATLAB function fcn
. The
compiled version of fcn
must be in a MEX function
that has the default name. The default name is the name specified
by fcn
followed by _mex
.
coder.runTest(
replaces
a call to a MATLAB function with a call to the compiled version
of the function when the compiled version of the function is in test
,mexfile
)mexfile
. mexfile
includes
the platform-specific file extension. If mexfile
does
not contain the compiled version of a function, coder.runTest
runs
the original MATLAB function. If you do not want to specify the
individual MATLAB functions to replace, use this syntax.
coder.runTest
does not return
outputs. To see test results, in the test, include code that displays
the results.
To compare MEX and MATLAB function behavior:
Run the test in MATLAB.
Use codegen
to generate a MEX
function.
Use coder.runTest
to run the
test replacing the call to the original function with a call to the
compiled version in the MEX function.
Before using coder.runTest
to
test multiple functions, compile the MATLAB functions into a
single MEX function.
If you use the syntax coder.runTest(test,
mexfile)
, use mexext
to get the platform-specific
MEX file name extension. For example:
coder.runTest('my_test', ['mymexfun.', mexext])
If errors occur during the test, you can debug the code using call stack information.
You can combine MEX generation and testing in one
step by running codegen
with the -test
option.
For example, the following code generates a MEX function for myfunction
and
calls the test file myfunction_test
, replacing
calls to myfunction
with calls to myfunction_mex
.
codegen myfunction -test myfunction_test