Main Content

matlabtest.coder.results.ExecutionResults Class

Namespace: matlabtest.coder.results

Generated C/C++ code execution results in equivalence tests

Since R2023a

Description

Objects of the matlabtest.coder.results.ExecutionResults class contain the results from the execution of a matlabtest.coder.results.BuildResults object in a MATLAB® Test™ generated C/C++ code equivalence test.

Creation

Create an instance of matlabtest.coder.results.ExecutionResults by using execute to execute a matlabtest.coder.results.BuildResults object in an equivalence test for generated C/C++ code.

Properties

expand all

File path of the built function, returned as a cell array.

Example: {'C:\Users\jdoe\EquivalenceTests\myAdd.m'}

Attributes:

GetAccess
public
SetAccess
immutable

File path for executed MEX function, returned as a character vector.

Example: 'C:\Users\jdoe\AppData\Local\Temp\tp68ab0c12_ae1f\codegen\mex\myAdd\myAdd_mex.mexw64'

Attributes:

GetAccess
public
SetAccess
immutable

Inputs that the function executed with, returned as a cell array. Each element in the cell array corresponds to an input to the function.

Example: {3,5}

Attributes:

GetAccess
public
SetAccess
immutable

Output of the MEX function, returned as a cell array.

Example: {[10]}

Attributes:

GetAccess
public
SetAccess
immutable

Examples

collapse all

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:

  1. Builds C code from the myAdd function with inputs set to (0,0)

  2. Executes the C code with inputs set to (1,2)

  3. Verifies the execution of the C code against the execution of the MATLAB function myAdd with the same inputs and an absolute tolerance of 0.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 R2023a