Integrating results from a custom authored MATLAB script as a test

In this example, you link a requirement to a MATLAB script. The verification status in the Simulink Requirements Editor reflects the test results.


You have a MATLAB script called runmytests.m which runs a test for Counter class in Counter.m. The test script contains custom methods that write results in a TAP format to a file named results.tap. Assume that you have run the test and it has produced the results.tap file that contains the results of the test. You want to link the results of the test to a requirement in counter_req.slreqx. Follow these steps to create and view the verification status with a test case called counterStartsAtZero in runmytests.m script:

  1. You start with opening the Requirements set counter_req.slreqx'.

  2. You create and register the Linktype using the API.

  3. You create the link.

  4. You view the Verification Status.

Section 1 : Open the Requirements Set

Open the requirements file counter_req.slreqx in the Requirements Editor.

reqSet ='counter_req.slreqx');

This will open the requirements set 'counter_req.slreqx'.

Section 2 : Create and Register Custom Linktype

The domain registration needed for this example is written in 'linktype_mymscripttap.m'. The template file for domain registrations is available at: matlabroot/toolbox/slrequirements/linktype_examples/linktype_TEMPLATE.m. Take a look at the implementation of GetResultFcn in the domain registration file:

edit linktype_mymscripttap;

Register the custom linktype:

rmi register linktype_mymscripttap;

If the command returns any warning, then you must unregister the file and follow the command again. Unregister the file by entering: rmi unregister linktype_mymscripttap

Section 3: Create the Link

Make the struct containing properties of the external test. Follow these steps to create the link: = 'counterStartsAtZero';
externalSource.artifact = 'runmytests.m';
externalSource.domain = 'linktype_mymscripttap';

Find the requirement related to the link by typing:

requirement = reqSet.find('Type', 'Requirement', 'SID', 2);

Create the link by entering:

link = slreq.createLink(requirement, externalSource);

This creates the link as test case counterStartsAtZero to the requirement 'SID'. In Requirements Editor, the link appears in the Links Confirmed by section.

Section 4: View the Verification Status

To update the verification status for the requirements set, type:


Fetch the verification status for the requirement:

status = reqSet.getVerificationStatus;

The Requirements Editor shows the verification status for entire requirements set that are passes or failed.

The verification status for the requirements for the counterStartsAtZero is fully verified. The Requirements Editor shows the overall verfication statuses for all the other requirements links associated with counter_req.slreqx.

reqSet ='counter_req.slreqx');

Click on the Refresh button if you are unable to see the verification status for the requirements in the Requirements Editor. The verification status shows that out of three tests, one test passed.

Clear the requirements once the simulation is completed.