Main Content

Linking to a Result File

In this workflow, you link a requirement to a test result file that is in Microsoft® Excel® format using the Outgoing Links Editor and the API. The verification status in the Simulink® Requirements™ Editor reflects the test results. These illustrations follow the workflow for including external test results in the requirement verification status. For more information, see Include Results from External Sources in Verification Status.

Linking to a Result File Using the Outgoing Links Editor

Create a requirement set called counter_req.slreqx in the Requirements Editor and save it in a writable location. This requirement set has child requirements that have requirement IDs and descriptions. For more details on how to create requirement sets, see Work with Requirements in the Simulink Editor.

The external results file is an Excel file called results.xlsx. The verification status in Simulink Requirements updates based on the values of the cells in the Excel sheet. A unique ID in the Test column identifies each result in the Status column. The Test and Status labels are contained in a header row.

Suppose you want to update the verification information for the counterSetsValue test case based on the Excel status log. Follow these steps to create and verify links to the result file:

Create and Register the Link Type

Open the template file at matlabroot/toolbox/slrequirements/linktype_examples/linktype_TEMPLATE.m. Follow these steps:

  1. Create a new MATLAB file.

  2. Copy the contents of linktype_TEMPLATE into the new file. Save the file as linktype_myexcelresults.m.

  3. In linktype_myexcelresults.m:

    1. Replace the function name linktype_TEMPLATE with linktype_myexcelresults.

    2. Set linkType.Label as 'Excel Results'.

    3. Set linkType.Extensions as {'.xlsx'}.

    4. Uncomment the command for GetResultFcn in order to use it in linktype_myexcelresults and enter:

      linktype.GetResultFcn = @GetResultFcn;
      ......
      function result = GetResultFcn(link)
          testID = link.destination.id;
          resultFile = link.destination.artifact;
          
          if ~isempty(resultFile) && isfile(resultFile)
              resultTable = readtable(resultFile);
              testRow = strcmp(resultTable.Test,testID);
              status = resultTable.Status(testRow);
              
              if status{1} == "passed"
                  result.status = slreq.verification.Status.Pass;
              elseif status{1} == "failed"
                  result.status = slreq.verification.Status.Fail;
              else
                  result.status = slreq.verification.Status.Unknown;
              end
          else
              result.status = slreq.verification.Status.Unknown;
          end
      end
      For more information about GetResultFcn, see Links and Link Types.

  4. Save linktype_myexcelresults.m.

  5. Register the link type. At the command line, enter:

    rmi register linktype_myexcelresults

    Note

    If the command returns a warning, then you must unregister the file and follow step 5 again. Unregister the file by entering:

    rmi unregister linktype_myexcelresults

Create the Link

Follow these steps to add the link manually in the Outgoing Links Editor:

  1. Open the Requirements Editor and, in the counter_req.slreqx requirement set, right-click the child requirement 1.3 and select Open Outgoing Links dialog.

  2. In the Outgoing Links Editor dialog box, in the Requirements tab, click New.

  3. Enter these details to establish the link:

    • Description: resultcounterSetsValue

    • Document Type: Excel Results

    • Document: results.xlsx

    • Location: counterSetsValue

  4. Click OK. The link is highlighted in the Links section of the Requirements Editor.

View the Verification Status

Update the verification status in the Requirements Editor. Click Refresh button to see the verification status for the requirements in the Requirements Editor. This shows the verification status for entire requirement set that passed or failed.

The requirements for counterSetsValue are fully verified. Here, the verification status shows that out of three tests, one test passed.

Linking to a Result File Using the API

Create a requirement set called counter_req.slreqx in the Requirements Editor and save it in a writable location. This requirement set has child requirements that have requirement IDs and descriptions. For more details on how to create requirement sets, see Work with Requirements in the Simulink Editor.

The external results file is an Excel file called results.xlsx. The verification status in Simulink Requirements updates based on the values of the cells in the Excel sheet. A unique ID in the Test column identifies each result in the Status column. The Test and Status labels are contained in a header row.

Suppose you want to update the verification information for the counterSetsValue test case based on the Excel status log. Follow these steps to create and verify links to the result file:

Create and Register the Link Type

Open the template file at matlabroot/toolbox/slrequirements/linktype_examples/linktype_TEMPLATE.m. Follow these steps:

  1. Create a new MATLAB file.

  2. Copy the contents of linktype_TEMPLATE into the new file. Save the file as linktype_myexcelresults.m.

  3. In linktype_myexcelresults.m:

    1. Replace the function name linktype_TEMPLATE with linktype_myexcelresults.

    2. Set linkType.Label as 'Excel Results'.

    3. Set linkType.Extensions as {'.xlsx'}.

    4. Uncomment the command for GetResultFcn in order to use it in linktype_myexcelresults and enter:

      linktype.GetResultFcn = @GetResultFcn;
      ......
      function result = GetResultFcn(link)
          testID = link.destination.id;
          resultFile = link.destination.artifact;
          
          if ~isempty(resultFile) && isfile(resultFile)
              resultTable = readtable(resultFile);
              testRow = strcmp(resultTable.Test,testID);
              status = resultTable.Status(testRow);
              
              if status{1} == "passed"
                  result.status = slreq.verification.Status.Pass;
              elseif status{1} == "failed"
                  result.status = slreq.verification.Status.Fail;
              else
                  result.status = slreq.verification.Status.Unknown;
              end
          else
              result.status = slreq.verification.Status.Unknown;
          end
      end
      For more information about GetResultFcn, see Links and Link Types.

  4. Save linktype_myexcelresults.m.

  5. Register the link type. At the command line, enter:

    rmi register linktype_myexcelresults

    Note

    If the command returns a warning, then you must unregister the file and follow step 5 again. Unregister the file by entering:

    rmi unregister linktype_myexcelresults

Create the Link

Follow these steps to create the link:

  1. From the MATLAB® command prompt, enter:

    externalSource.id = 'counterSetsValue';
    externalSource.artifact = 'results.xlsx';
    externalSource.domain = 'linktype_myexcelresults';

  2. Find the requirement related to the link by typing:

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

  3. Create the link by entering:

    link = slreq.createLink(requirement, externalSource);
    This creates the link as test case counterSetsValue for the requirement SID. In Requirements Editor, the link appears in the Links > Confirmed By section.

View the Verification Status

Update the verification status for the requirement set. At the MATLAB command prompt, type:

reqSet.updateVerificationStatus
Fetch the verification status for the requirement by entering:
status = reqSet.getVerificationStatus
This shows the verification status for entire requirement set that passed or failed. Click Refresh to see the verification status for the requirements in the Requirements Editor.

The requirements for counterSetsValue are fully verified. Here, the verification status shows that out of three tests, one test passed.

Related Topics