execute
Class: matlabtest.coder.MATLABCoderTester
Namespace: matlabtest.coder
Description
execute(
executes the generated C/C++ code specified by tester
,testCase
)tester
with the same
inputs that were specified when generating the C/C++ code in the test case
testCase
. The function stores the execution results in the ExecutionResults
property of tester
.
execute(___,
specifies
options using one or more name-value arguments in addition to the input arguments in
previous syntaxes.Name=Value
)
Input Arguments
tester
— Equivalence tester
matlabtest.coder.MATLABCoderTester
object
Equivalence tester, specified as a matlabtest.coder.MATLABCoderTester
object.
testCase
— Test case
matlab.unittest.TestCase
object
Test case, specified as a matlab.unittest.TestCase
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 your generated C/C++ code has multiple entry-point functions.
Example: EntryPoint="myAdd"
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 the equivalence tester matlabtest.coder.MATLABCoderTester
.
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 matlab.unittest.TestCase
. The test case in the methods
block defines a test case that:
Imports the equivalence tester
matlabtest.coder.MATLABCoderTester
and the constraintmatlabtest.constraints.ExecutionMatchesMATLAB
.Instantiates the tester for a MEX build target for the
helloWorld
function.Builds C code from the
helloWorld
function.Executes the C code with no inputs.
Verifies the execution of the C code against the execution of the MATLAB function
helloWorld
.
classdef tEquivalence < matlab.unittest.TestCase methods(Test) function tHelloWorld(testCase) import matlabtest.coder.MATLABCoderTester import matlabtest.constraints.ExecutionMatchesMATLAB tester = MATLABCoderTester.forMEXCoderConfiguration( ... "helloWorld"); build(tester,testCase); execute(tester,testCase); verifyThat(testCase,tester,ExecutionMatchesMATLAB); 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.7680 Details: [1×1 struct] Totals: 1 Passed, 0 Failed, 0 Incomplete. 2.768 seconds testing time.
Generate C Code from Multiple Functions and Test for Equivalence
This example shows how to generate C code from multiple MATLAB functions and test the functions for equivalence by using matlabtest.coder.MATLABCoderTester
.
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
The function mySubtract
takes two numbers as inputs, subtracts them, and outputs the result.
function y = mySubtract(a,b) %#codegen y = b-a; end
This class definition file defines an equivalence test case that inherits from matlab.unittest.TestCase
. The test case in the methods
block defines a test case that:
Imports the equivalence tester
matlabtest.coder.MATLABCoderTester
and the constraintmatlabtest.constraints.ExecutionMatchesMATLAB
Instantiates the tester for a MEX build target for the entry-point function
myAdd
with the build-time inputs set to(0,0)
Adds the entry-point function
mySubtract
with the build-time inputs set to(0,0)
Builds C code from the
myAdd
andmySubtract
functionsExecutes the C code for the entry-point function
myAdd
with the inputs set to(5,5)
Verifies the execution of the C code against the execution of the MATLAB function
myAdd
classdef tEquivalence < matlab.unittest.TestCase methods(Test) function tMyMath(testCase) import matlabtest.coder.MATLABCoderTester import matlabtest.constraints.ExecutionMatchesMATLAB tester = MATLABCoderTester.forMEXCoderConfiguration( ... "myAdd",Inputs={0,0}); addEntryPointFunction(tester,"mySubtract",{0,0}); build(tester,testCase); execute(tester,testCase,Inputs={5,5}, ... EntryPoint="myAdd"); verifyThat(testCase,tester,ExecutionMatchesMATLAB) end end end
Run the tMyMath
test.
runtests("tEquivalence", ... procedureName="tMyMath")
Running tMyMath .. Done tMyMath __________ ans = TestResult with properties: Name: 'tEquivalence/tMyMath' Passed: 1 Failed: 0 Incomplete: 0 Duration: 2.7680 Details: [1×1 struct] Totals: 1 Passed, 0 Failed, 0 Incomplete. 2.768 seconds testing time.
Version History
Introduced in R2023a
MATLAB 명령
다음 MATLAB 명령에 해당하는 링크를 클릭했습니다.
명령을 실행하려면 MATLAB 명령 창에 입력하십시오. 웹 브라우저는 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)