Main Content

Use SIL/PIL to Verify Generated Code from an Earlier Release

If you generate code for an atomic subsystem and verify it using SIL/PIL simulation in an earlier release, then you can verify that the model continues to work as expected in the current release by reusing that code. Reusing the generated code saves test harness generation time because you do not have to regenerate the code.

Note

  • You cannot reuse generated code for test harnesses for whole models or Model blocks.

  • You can reuse generated code from only the previous eight releases. Trying to reuse generated code from earlier releases produces an error.

  • You must have an Embedded Coder® license to reuse generated code from an earlier release.

Create Test Harness That Reuses Generated Code

To reuse generated code from an earlier release, create a test harness for SIL or PIL verification:

  1. Right-click the atomic subsystem in your model for which you generated code in the earlier release and select Test Harness > Create for <subsystem>.

  2. In the Create Test Harness dialog box, specify a Name for the harness.

  3. In the Advanced Properties tab, set the harness as a SIL or PIL harness that verifies existing generated code:

    1. Change the Verification Mode to Software-in-the-Loop (SIL) or Processor-in-the-Loop (PIL).

    2. Select Use existing generated code to create SIL/PIL block.

    3. In the Build folder box, enter the full path to the folder that contains the generated code from the earlier release. For example, if you configured the system target file to be ert.tlc, the folder name ends in "_ert_rtw".

  4. Click OK to create the test harness.

  5. Select the signal exiting the subsystem in the test harness. Point to the ellipsis to open the action bar and select Log Selected Signal.

  6. Close the harness. You do not need to explicitly save the harness.

To use previously generated code verified using a SIL/PIL subsystem programmatically, use the ExistingBuildFolder property of sltest.harness.create or sltest.harness.set to specify the location of the generated code.

Create Test Harness for Normal Simulation

To test the behavior of the subsystem in the current release, create a test harness for normal simulation:

  1. Right-click the atomic subsystem in your model for which you generated code in the earlier release and select Test Harness > Create for <subsystem>.

  2. In the Create Test Harness dialog box, specify a Name for the harness.

  3. Click OK to create the test harness.

  4. Select the signal exiting the subsystem in the test harness. Point to the ellipsis to open the action bar and select Log Selected Signal.

  5. Close the harness.

Create Equivalence Test Case

To verify that the model in the current release continues to work as expected, create an equivalence test that compares the normal simulation in the current release and the SIL/PIL mode simulation from the earlier release:

  1. Open the Test Manager.

    sltest.testmanager.view
  2. Click New > Test File. Name the test file SIL reuse.

  3. Delete New Test Case 1.

  4. Highlight New Test Suite 1 and click New > Test Case > Equivalence Test.

  5. Change the name of New Test Case 1 to SIL equivalence test case.

  6. In the Simulation 1 section, under System Under Test:

    1. Specify the Model.

    2. Under Test Harness > Harness, specify the test harness for normal simulation.

    3. Under Simulation Settings and Release Overrides, specify the Start Time and Stop Time. Leave Release as Current.

  7. In the Simulation 2 section, under System Under Test:

    1. Specify the Model.

    2. Under Test Harness > Harness, specify the test harness that uses the generated code.

    3. Under Simulation Settings and Release Overrides, specify the Start Time and Stop Time. Leave Release as Current.

  8. For both simulations, in the Inputs sections, specify the inputs that you used to verify the system in the previous release. For example, if you saved the inputs in a MAT file:

    1. Under External Inputs, click Add.

    2. In the Add Input dialog box, specify the name of the file.

    3. Click Map Inputs and then click Add.

Run Test and Analyze Results

To verify that the results match the results produced by the same code in the earlier release, run the equivalence test by clicking Run. To view the output and analyze the test results, in the Results and Artifacts pane, expand Equivalence Criteria Result.

The upper plot shows the output of both test harnesses. The lower plot shows the difference between these outputs. If the difference is zero, the two results plots match exactly so the code verified in the earlier release and the code generated in the current release produce the same results.

See Also

| | (Embedded Coder)

Topics