execute
Class: matlabtest.coder.TestCase
Namespace: matlabtest.coder
Description
executes the generated C/C++ code in the build results object
executionResults
= execute(testCase
,buildResults
)buildResults
with the same inputs that were used to generate the
C/C++ code in the equivalence test case testCase
.
specifies options using one or more name-value arguments in addition to the input arguments
in previous syntaxes.executionResults
= execute(___,Name=Value
)
Input Arguments
testCase
— Test case
matlabtest.coder.TestCase
object
Test case, specified as a matlabtest.coder.TestCase
object.
buildResults
— Build results for generated C/C++ code in equivalence tests
matlabtest.coder.results.BuildResults
object
Build results for generated C/C++ code in equivalence tests, specified as a matlabtest.coder.results.BuildResults
object.
Name-Value Arguments
Specify optional pairs of arguments as
Name1=Value1,...,NameN=ValueN
, where Name
is
the argument name and Value
is the corresponding value.
Name-value arguments must appear after other arguments, but the order of the
pairs does not matter.
Example: Inputs={1,2}
Inputs
— Run-time inputs
cell array
Run-time inputs, specified as a cell array. Each element in the cell array corresponds to an input to the function. Use this argument to execute the function with different inputs than the inputs used to generate the C/C++ code.
Example: Inputs={1,2}
EntryPoint
— Entry-point function name
string scalar | character vector
Entry-point function name, specified as a string scalar or character vector. Use this argument when you execute C/C++ code that you generated outside of an equivalence test that has multiple entry-point functions.
Example: EntryPoint="myAdd"
Output Arguments
executionResults
— Execution results for generated C/C++ code in equivalence tests
matlabtest.coder.results.ExecutionResults
object
Execution results for generated C/C++ code in equivalence tests, returned as a
matlabtest.coder.results.ExecutionResults
object.
Examples
Generate C Code from Function with No Inputs and Test for Equivalence
This example shows how to generate C code from a MATLAB® function that has no inputs and test for equivalence by using MATLAB Coder™.
The function helloWorld
displays a string of text.
function y = helloWorld y = "Hello World!"; end
This class definition file defines an equivalence test case that inherits from matlabtest.coder.TestCase
. The test case in the methods
block defines a test case that:
Builds C code from the
helloWorld
functionExecutes the C code with no inputs
Verifies the execution of the C code against the execution of the MATLAB function
helloWorld
classdef tEquivalence < matlabtest.coder.TestCase methods (Test) function tHelloWorld(testCase) buildResults = build(testCase,"helloWorld"); executionResults = execute(testCase,buildResults); verifyExecutionMatchesMATLAB(testCase,executionResults) end end end
Run the tHelloWorld
test.
runtests("tEquivalence", ... procedureName="tHelloWorld")
Running tHelloWorld .. Done tHelloWorld __________ ans = TestResult with properties: Name: 'tEquivalence/tHelloWorld' Passed: 1 Failed: 0 Incomplete: 0 Duration: 2.8921 Details: [1×1 struct] Totals: 1 Passed, 0 Failed, 0 Incomplete. 2.8921 seconds testing time.
Generate and Test C Code for Equivalence
This example shows how to generate C code from a MATLAB function and test for equivalence by using MATLAB Coder.
The function myAdd
takes two numbers as inputs, adds them together, and outputs the result.
function y = myAdd(a,b) %#codegen y = a+b; end
This class definition file defines an equivalence test case that inherits from matlabtest.coder.TestCase
. The test case in the methods
block defines a test case that:
Builds C code from the
myAdd
function with inputs set to(0,0)
Executes the C code with inputs set to
(1,2)
Verifies the execution of the C code against the execution of the MATLAB function
myAdd
with the same inputs and an absolute tolerance of0.01
classdef tEquivalence< matlabtest.coder.TestCase methods (Test) function tMyAdd(testCase) buildResults = build(testCase,"myAdd", ... Inputs={0,0}); executionResults = execute(testCase,buildResults, ... Inputs={1,2}); verifyExecutionMatchesMATLAB(testCase,executionResults, ... AbsTol=0.01) end end end
Run the tMyAdd
test.
runtests("tEquivalence", ... procedureName="tMyAdd")
Running tMyAdd .. Done tMyAdd __________ ans = TestResult with properties: Name: 'tEquivalence/tMyAdd' Passed: 1 Failed: 0 Incomplete: 0 Duration: 2.6670 Details: [1×1 struct] Totals: 1 Passed, 0 Failed, 0 Incomplete. 2.667 seconds testing time.
Version History
Introduced in R2023aR2024a: (Update) Improved performance in C/C++ equivalence tests
The execute
function shows improved performance when executing
generated C/C++ code in equivalence tests in test classes that inherit from matlabtest.coder.TestCase
. For more information, see Improved performance for execute function in C/C++ equivalence tests (R2024a Update).
See Also
Classes
Functions
Comando de MATLAB
Ha hecho clic en un enlace que corresponde a este comando de MATLAB:
Ejecute el comando introduciéndolo en la ventana de comandos de MATLAB. Los navegadores web no admiten comandos de MATLAB.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)