matlabtest.coder.MATLABCoderTester.forDLLCoderConfiguration - Equivalence test class constructor for DLL code generation - MATLAB (original) (raw)

Class: matlabtest.coder.MATLABCoderTester
Namespace: matlabtest.coder

Equivalence test class constructor for DLL code generation

Since R2023a

Syntax

Description

[tester](#mw%5F2c4f92b9-5a2a-486d-80ef-d1c3d8798d81%5Fsep%5Fmw%5F91b55423-9db2-4505-8da4-7476509ee86d) = matlabtest.coder.MATLABCoderTester.forDLLCoderConfiguration([fcnName](#mw%5F2c4f92b9-5a2a-486d-80ef-d1c3d8798d81%5Fsep%5Fmw%5F20d0469d-6475-4460-b5a6-439b7edccc0c)) creates an instance of the equivalence tester tester configured to build a dynamic linked library from the function specified by fcnName with no build-time inputs.

example

[tester](#mw%5F2c4f92b9-5a2a-486d-80ef-d1c3d8798d81%5Fsep%5Fmw%5F91b55423-9db2-4505-8da4-7476509ee86d) = matlabtest.coder.MATLABCoderTester.forDLLCoderConfiguration(___,[Name=Value](#namevaluepairarguments)) specifies options using one or more name-value arguments in addition to the input arguments in previous syntaxes.

example

Input Arguments

expand all

Name of function to generate code for, specified as a string scalar or character vector.

Example: "myAdd"

Name-Value Arguments

expand all

Specify optional pairs of arguments asName1=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.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: Inputs={1,2}

Build-time inputs, specified as a cell array. Each element in the cell array corresponds to an input to the function.

Example: Inputs={1,2}

Folder to preserve generated files in, specified as a string scalar or character vector. The folder path can be relative or absolute. By default, the test case generates code in a temporary directory.

When you specify this name-value argument, MATLAB® preserves the generated files regardless of the test result.

Note

When the equivalence test fails, MATLAB preserves the generated files regardless of whether or not you use this name-value argument.

Example: PreserveInFolder="equivalenceTests\artifacts"

Example: PreserveInFolder="C:\users\jdoe\MATLAB\equivalenceTests\artifacts"

Output Arguments

Examples

expand all

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 frommatlab.unittest.TestCase. The test case in themethods block defines a test case that:

  1. Imports the equivalence tester matlabtest.coder.MATLABCoderTester and the constraint matlabtest.constraints.ExecutionMatchesMATLAB
  2. Instantiates the tester for a DLL build target for thehelloWorld function
  3. Builds C code from the helloWorld function
  4. Executes the C code with no inputs
  5. 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.forDLLCoderConfiguration( ...
            "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.

This example shows how to generate C code from multiple MATLAB functions and test them for equivalence by using the equivalence testermatlabtest.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 frommatlab.unittest.TestCase. The test case in themethods block defines a test case that:

  1. Imports the equivalence tester matlabtest.coder.MATLABCoderTester and the constraint matlabtest.constraints.ExecutionMatchesMATLAB
  2. Instantiates the tester for a DLL build target for the entry-point functionmyAdd with the build-time inputs set to(0,0)
  3. Adds the entry-point function mySubtract with the build-time inputs set to (0,0)
  4. Builds C code from the myAdd andmySubtract functions
  5. Executes the C code for the entry-point function myAdd with the inputs set to (5,5)
  6. 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.forDLLCoderConfiguration( ...
            "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

See Also

Classes

Functions

Topics