matlabtest.compiler.TestCase.execute - Execute deployed code artifacts in equivalence tests - MATLAB (original) (raw)

Class: matlabtest.compiler.TestCase
Namespace: matlabtest.compiler

Execute deployed code artifacts in equivalence tests

Since R2023a

Syntax

Description

[executionResults](#mw%5Fd502651a-f612-49d4-87ea-7ca1ce8d08c0) = execute([testCase](#mw%5F5274cedb-6ffc-48c3-85f3-aac6fa771d80%5Fsep%5Fmw%5F749a5a23-a3ff-402c-a105-186d6548ef7c),[buildResults](#mw%5F2b7c75ec-73b6-4b7b-97de-86ff6d872101)) executes the function in the build results object buildResults with no inputs by using MATLAB® Compiler SDK™ in the equivalence test case testCase. Use this syntax if your function has no inputs.

example

[executionResults](#mw%5Fd502651a-f612-49d4-87ea-7ca1ce8d08c0) = execute([testCase](#mw%5F5274cedb-6ffc-48c3-85f3-aac6fa771d80%5Fsep%5Fmw%5F749a5a23-a3ff-402c-a105-186d6548ef7c),[buildResults](#mw%5F2b7c75ec-73b6-4b7b-97de-86ff6d872101),[inputs](#mw%5F346557d5-6f54-407a-a564-8441ac02aacc)) executes the function in the build results object with the inputs specified byinputs.

example

[executionResults](#mw%5Fd502651a-f612-49d4-87ea-7ca1ce8d08c0) = execute([testCase](#mw%5F5274cedb-6ffc-48c3-85f3-aac6fa771d80%5Fsep%5Fmw%5F749a5a23-a3ff-402c-a105-186d6548ef7c),[buildResults](#mw%5F2b7c75ec-73b6-4b7b-97de-86ff6d872101),[inputs](#mw%5F346557d5-6f54-407a-a564-8441ac02aacc),[fcnName](#mw%5F5fc97858-e5bf-454b-9188-f8fb37ffc186)) executes the function specified by fcnName. Use this syntax if your deployed code artifact contains multiple functions.

example

[executionResults](#mw%5Fd502651a-f612-49d4-87ea-7ca1ce8d08c0) = execute(___,PreservingOnFailure=true) preserves after a test failure the files that the test creates when it executes the deployed code artifact.

example

Input Arguments

expand all

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

Example: {3,5}

Name of the function to execute, specified as a string scalar or character vector.

Example: "makesquare"

Output Arguments

Examples

expand all

This example shows how to generate a Python® package from a MATLAB function that has no inputs and test it for equivalence.

The function called helloWorld takes no inputs:

function y = helloWorld y = 'Hello World!'; end

This class definition file defines an equivalence test case that inherits frommatlabtest.compiler.TestCase. The test case in themethods block defines a test case that:

  1. Builds the Python package from the helloWorld function
  2. Executes the Python package with no inputs
  3. Verifies the execution of the Python package against the execution of the MATLAB function helloWorld

classdef tDeployment < matlabtest.compiler.TestCase methods(Test) function pythonEquivalence(testCase) buildResults = build(testCase,"helloWorld.m", ... "pythonPackage"); executionResults = execute(testCase,buildResults); verifyExecutionMatchesMATLAB(testCase,executionResults); end end end

Run the pythonEquivalence test.

runtests("tDeployment", ... ProcedureName="pythonEquivalence")

Running pythonEquivalence .. Done pythonEquivalence


ans =

TestResult with properties:

      Name: 'tDeployment/pythonEquivalence'
    Passed: 1
    Failed: 0
Incomplete: 0
  Duration: 78.4746
   Details: [1×1 struct]

Totals: 1 Passed, 0 Failed, 0 Incomplete. 78.4746 seconds testing time.

This example shows how to generate a Python package from MATLAB source code and test for equivalence by using MATLAB Compiler SDK.

The function makesquare generates an_n_-by-n matrix:

function y = makesquare(x) y = magic(x); end

This class definition file defines an equivalence test case that inherits from matlabtest.compiler.TestCase. The test case in the methods block defines a test case that:

  1. Builds the Python package from the makesquare function
  2. Executes the Python package with input set to 5
  3. Verifies the execution of the Python package against the execution of the MATLAB function makesquare with the same input

classdef tDeployment < matlabtest.compiler.TestCase methods(Test) function pythonEquivalence(testCase) buildResults = build(testCase,"makesquare.m", ... "pythonPackage"); executionResults = execute(testCase,buildResults,{5}); verifyExecutionMatchesMATLAB(testCase,executionResults); end end end

Run the pythonEquivalence test.

runtests("tDeployment", ... ProcedureName="pythonEquivalence")

Running pythonEquivalence .. Done pythonEquivalence


ans =

TestResult with properties:

      Name: 'tDeployment/pythonEquivalence'
    Passed: 1
    Failed: 0
Incomplete: 0
  Duration: 93.1237
   Details: [1×1 struct]

Totals: 1 Passed, 0 Failed, 0 Incomplete. 93.1237 seconds testing time.

This example shows how to generate a Python package from MATLAB source code and test for equivalence by using MATLAB Compiler SDK.

The function makesquare generates an_n_-by-n matrix and the functionmyAdd takes two inputs and adds them together:

function y = makesquare(x) y = magic(x); end

function y = myAdd(a,b) y = a + b; end

This class definition file:

classdef tDeployment < matlabtest.compiler.TestCase methods(Test) function pythonEquivalence(testCase) functionsToDeploy = ["makesquare.m","myAdd.m"]; buildResults = build(testCase,functionsToDeploy, ... "pythonPackage",PreservingOnFailure=true);
preserveOnFailure=true; executionResults = execute(testCase,buildResults,{5}, ... "makesquare",PreservingOnFailure=preserveOnFailure); verifyExecutionMatchesMATLAB(testCase,executionResults, ... AbsTol=0.0001); end end end

Run the pythonEquivalence test.

runtests("tDeployment", ... ProcedureName="pythonEquivalence")

Running pythonEquivalence .. Done pythonEquivalence


ans =

TestResult with properties:

      Name: 'tDeployment/pythonEquivalence'
    Passed: 1
    Failed: 0
Incomplete: 0
  Duration: 93.1237
   Details: [1×1 struct]

Totals: 1 Passed, 0 Failed, 0 Incomplete. 93.1237 seconds testing time.

Limitations

Version History

Introduced in R2023a

expand all

Execute deployable C++ shared libraries in equivalence tests by specifying the buildResults input argument as a compiler.build.Results (MATLAB Compiler SDK) object that has the BuildType property set to cppSharedLibrary.

Execute deployable archives in equivalence tests by specifying the buildResults input argument as a compiler.build.Results (MATLAB Compiler SDK) object that has the BuildType property set to productionServerArchive.