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:
You start with opening the Requirements set counter_req.slreqx'
.
You create and register the Linktype using the API.
You create the link.
You view the Verification Status.
Open the requirements file counter_req.slreqx
in the Requirements Editor.
reqSet = slreq.open('counter_req.slreqx');
This will open the requirements set 'counter_req.slreqx'
.
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
Make the struct containing properties of the external test. Follow these steps to create the link:
externalSource.id = '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.
To update the verification status for the requirements set, type:
reqSet.updateVerificationStatus;
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 = slreq.open('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.