addEntryPointFunction
Class: matlabtest.coder.MATLABCoderTester
Namespace: matlabtest.coder
Add entry-point function or signature to formal generated C/C++ equivalence tester
Since R2023a
Description
addEntryPointFunction(
adds the entry-point function tester,entryPoint)entryPoint to the equivalence tester
tester. Use this syntax if your entry-point function has
no inputs.
addEntryPointFunction(
adds the entry-point function with the function signature defined by
tester,entryPoint,buildInputs)buildInputs.
Input Arguments
Equivalence tester, specified as a matlabtest.coder.MATLABCoderTester object.
Entry-point function name, specified as a string scalar or character vector.
Example: "myAdd"
Build-time inputs, specified as a cell array. Each element in the cell array corresponds to an input to the function.
Example: {1,2}
Examples
This example shows how to generate C code from multiple MATLAB® functions with different signatures and test them for equivalence by using
the equivalence tester 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 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, the constraintmatlabtest.constraints.ExecutionMatchesMATLAB, and the constraintmatlab.unittest.constraints.AbsoluteToleranceInstantiates the tester for a MEX build target for the entry-point function
myAddwith the build-time inputs set to(0,0)Adds the entry-point function
helloWorldwith no inputs.Builds C code from the
myAddandhelloWorldfunctionsExecutes the C code for the entry-point function
myAddwith the inputs set to(5,5)Instantiates the constraint
matlabtest.constraints.ExecutionMatchesMATLABwith the absolute tolerance set to0.05Verifies the execution of the C code against the execution of the MATLAB function
myAddwith the constraint
classdef tEquivalence < matlab.unittest.TestCase methods(Test) function tMyFunctions(testCase) import matlabtest.coder.MATLABCoderTester import matlabtest.constraints.ExecutionMatchesMATLAB import matlab.unittest.constraints.AbsoluteTolerance tester = MATLABCoderTester.forMEXCoderConfiguration( ... "myAdd",Inputs={0,0}); addEntryPointFunction(tester,"helloWorld"); build(tester,testCase); execute(tester,testCase,Inputs={5,5},EntryPoint="myAdd"); c = ExecutionMatchesMATLAB(Within=AbsoluteTolerance(0.05)); verifyThat(testCase,tester,c); end end end
Run the tMyFunctions test.
runtests("tEquivalence", ... procedureName="tMyFunctions")
Running tMyFunctions
..
Done tMyFunctions
__________
ans =
TestResult with properties:
Name: 'tEquivalence/tMyFunctions'
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.
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.MATLABCoderTesterand the constraintmatlabtest.constraints.ExecutionMatchesMATLABInstantiates the tester for a MEX build target for the entry-point function
myAddwith the build-time inputs set to(0,0)Adds the entry-point function
mySubtractwith the build-time inputs set to(0,0)Builds C code from the
myAddandmySubtractfunctionsExecutes the C code for the entry-point function
myAddwith 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.
This example shows how to generate C code from a single MATLAB function for multiple function signatures and test for equivalence by using
the equivalence tester 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
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, the constraintmatlabtest.constraints.ExecutionMatchesMATLAB, and the constraintmatlab.unittest.constraints.AbsoluteToleranceInstantiates the tester for a MEX build target for the entry-point function
myAddwith the build-time inputs set to(0,0)so that it can accept inputs of typedoubleSpecifies a second function signature for
myAddso that it can accept inputs of typeint8Builds C code from
myAddwith the specified function signaturesExecutes the C code for the entry-point function
myAddwith the inputs set to(5,5)Instantiates the constraint
matlabtest.constraints.ExecutionMatchesMATLABwith the absolute tolerance set to0.05Verifies the execution of the C code against the execution of the MATLAB function
myAddwith the constraint
classdef tEquivalence < matlab.unittest.TestCase methods(Test) function tMyAdd(testCase) import matlabtest.coder.MATLABCoderTester; import matlabtest.constraints.ExecutionMatchesMATLAB; tester = MATLABCoderTester.forMEXCoderConfiguration( ... "myAdd.m",Inputs={0,0}); addEntryPointFunction(tester,"myAdd.m",{int8(0),int8(0)}); build(tester,testCase); execute(tester,testCase,Inputs={5,5}); verifyThat(testCase,tester,ExecutionMatchesMATLAB); execute(tester,testCase,Inputs={int8(2),int8(3)}); verifyThat(testCase,tester,ExecutionMatchesMATLAB); 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.7680
Details: [1×1 struct]
Totals:
1 Passed, 0 Failed, 0 Incomplete.
2.768 seconds testing time.
Version History
Introduced in R2023a
See Also
Classes
Functions
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Seleziona un sito web
Seleziona un sito web per visualizzare contenuto tradotto dove disponibile e vedere eventi e offerte locali. In base alla tua area geografica, ti consigliamo di selezionare: .
Puoi anche selezionare un sito web dal seguente elenco:
Come ottenere le migliori prestazioni del sito
Per ottenere le migliori prestazioni del sito, seleziona il sito cinese (in cinese o in inglese). I siti MathWorks per gli altri paesi non sono ottimizzati per essere visitati dalla tua area geografica.
Americhe
- América Latina (Español)
- Canada (English)
- United States (English)
Europa
- 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)