requirements traceability for matlab code
you can associate requirements with matlab® code and plain-text external code, such as c code, by creating selection-based links with the requirements editor or by creating links programmatically at the matlab command line. you can also create links to matlab code in (simulink) blocks. you can verify requirements with matlab code by creating links to matlab unit tests and running the tests. you can then view and edit links to code in the matlab editor or requirements editor.
create links to matlab code or plain-text external code
you can create links to matlab code or plain-text external code programmatically or by using the .
when you create links to code, requirements toolbox™ creates objects that correspond to the selected lines. these
slreq.textrange
objects are referred to as line
ranges.
to create links programmatically, create the slreq.textrange
object,
then use the object as a link source when you create the link. when you create multiple
slreq.textrange
objects in the same matlab code file or plain-text external code file, the line numbers for the
slreq.textrange
objects cannot overlap.
create links by using the requirements editor
to create selection-based links to code by using the requirements editor:
in the matlab editor, open the matlab code file or plain-text external code file.
note
you cannot create links to matlab code in mlx files.
select the lines of code that you want to link.
in the requirements editor, load the requirement set that you want to link.
select the requirement to link.
in the links section, click add link > link from selection in matlab editor.
alternatively, in the matlab editor, right-click the selected code range and select requirements > link to selection in requirements browser.
create links programmatically
suppose that you want to programmatically create links to a matlab function called
myadd
.
function y = myadd(u,v) y = u v; end
to create links at the matlab command line:
use to create an object that represents the lines of code that you want to link to.
lr = slreq.createtextrange("myadd.m",2);
use , , or to get a handle to the requirement that you want to link.
req = slreq.find(type="requirement",summary="add u and v");
use to create the link.
mylink = slreq.createlink(lr,req);
create links to matlab function blocks
use the (simulink) to create links to lines of code in matlab function blocks:
in the requirements editor, load the requirement set that you want to link to.
select the requirement to link.
in the simulink® model, open the matlab function block.
select the lines of code that you want to link.
right-click the selected code range and select requirements > link to selection in requirements browser.
note
requirements linked to matlab code lines inside a matlab function block appear in html requirements traceability reports, but do not appear the simulink report generator™ web view. see create and use web views of models (simulink report generator).
create links to requirements in external documents
to create links from matlab code to requirements in external documents:
select a requirement in one of these external documents:
microsoft® word
microsoft excel®
ibm® rational® doors®
ibm doors next
in the matlab editor, open the matlab code file or plain-text external code file.
note
you cannot create links to matlab code in mlx files.
select the lines of code that you want to link.
right-click the selected code range and select requirements. depending on the type of your requirements document, select one of these options:
link to selection in word
link to selection in excel
link to selection in doors
link to selected item(s) in doors next
for more information about configuring requirements toolbox to work with these third-party products, see and .
verify requirements with matlab tests
you can verify requirements with matlab code by creating links to class-based and function-based tests, then running the tests.
when you create a link from a requirement to a matlab unit test, requirements toolbox sets the link type to verify
, which enables the
software to verify the requirement. for more information, see .
to verify the requirement, run the test at the matlab command line or by using the requirements editor. to view the verification status in the requirements editor, select columns > verification status.
note
test results from the and (matlab test) do not affect the verification status in the requirements editor.
run tests by using the requirements editor
to run matlab unit tests for a requirement set, for a parent requirement and all of its descendants, or for a single requirement by using the requirements editor:
in the requirements editor, right-click a requirement set, a parent requirement, or a child requirement that has links to tests and select run tests.
in the run tests dialog box, confirm that you want to run the linked tests. to omit tests from the run, clear the selection.
click run tests.
the verification status of the requirements updates after you run the tests.
run tests at the matlab command line
supposed that you want to verify the requirements in the
shortestpath
project by running matlab tests programmatically.
to run tests linked to a requirement set programmatically:
open the
shortestpath
project.slreqshortestpathprojectstart
load the
shortest_path_tests_reqs
requirement set and open it in the requirements editor.rs = slreq.open("shortest_path_tests_reqs");
run the tests that are linked to the requirement set by using .
results = runtests(rs);
view the verification status in the requirements editor. alternatively, view the verification status at the command line by using .
status = getverificationstatus(rs)
status = total: 14 passed: 13 failed: 0 unexecuted: 0 justified: 0 none: 1
view and edit links and linked line ranges
you can view linked code ranges in the matlab editor by enabling requirements highlighting. right-click in the matlab editor and select requirements > enable requirements highlighting.
to edit links, use the requirements editor. for more information, see view and edit links.
you can also edit the starting and ending lines for a linked line range in the matlab editor or at the matlab command line.
edit linked line ranges in the matlab editor
to edit the line numbers for a linked line range in the matlab editor:
right-click a highlighted line range and select adjust line range.
in the adjust range dialog box, use the and - buttons to change the first and last lines of the line range. alternatively, enter the line number in the field.
click ok. the matlab editor updates the highlighting.
edit linked line ranges programmatically
to edit the lines for an object at the matlab command line:
open the matlab code file or plain-text external code file in the matlab editor.
open("myadd.m");
get the existing object in the matlab code file by passing the file name and the line numbers for the start and end of the line range to the function.
lr = slreq.gettextrange("myadd.m",[1 2]);
modify the line range by using .
setlinerange(lr,1);
the matlab editor updates the code range highlighting. alternatively, you can confirm the changes by using , , or .
save links
to save the changes to a link set when you create or edit links to lines of matlab code or external code, use one of these approaches:
in the matlab editor, right-click and select requirements > save links.
in the requirements editor, click show links. select the link set, and click save.
at the matlab command line, use .
delete links and unused line ranges
you can delete links to matlab code in the matlab editor, the requirements editor, or at the matlab command line.
if you delete links to code ranges in the matlab editor, you can delete the unused line ranges in the matlab editor or at the matlab command line.
delete links
to delete links in the matlab editor, right-click a highlighted code range and select requirements > delete all links. this deletes all incoming and outgoing links to this code range.
to delete links from the requirements editor, see delete links and link sets.
to delete links at the matlab command line, get a handle to an object and use . alternatively, ensure that the file containing the code range is open in the matlab editor, then get an object by using . delete the links to the object by using .
delete unused line ranges
to delete unused line ranges in the matlab editor, right-click the line containing the line range and select requirements > delete line range.
note
if a line range does not have outgoing links, the matlab editor does not highlight the code line. note the line number before you delete the link so that you can delete the unused line range. alternatively, you can use the matlab command line to get the line ranges in a file and then delete the unused line ranges.
to delete line ranges at the command line, ensure that the file containing the code range is open in the matlab editor, then get an object by using . delete the code range by using .
see also
| |