Main Content

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

For an atomic subsystem, you can use SIL/PIL simulation in the current release to verify code that was generated for that subsystem in a previous release. You do not have to regenerate the code, which saves test harness generation time. You cannot reuse generated code for test harnesses for whole models or Model blocks.

Note

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

Reuse Generated Code

In an earlier release, if you created a test harness that generated code and verified it using SIL/PIL, you can reuse that code, rather than regenerating it, in the current release. To reuse generated code, you must know the location of the folder that contains the code. The steps for reusing generated code and verifying it using SIL/PIL are:

  1. Right-click an atomic subsystem in your model and select Test Harness > Create for '<subsystem_name>'.

  2. In the Advanced Properties tab of the Create Test Harness dialog box:

    • Set Select Verification Mode to Software-in-the-Loop (SIL) or Processor-in-the-Loop (PIL).

    • Select Use generated code to create SIL/PIL block.

    • In the Build folder text box, enter the full path to the folder that contains the previously generated code.

  3. Click OK to create the test harness using the generated code.

  4. Create another normal or SIL/PIL mode test harness for the model that does not use generated code.

  5. Create a test case and run the test.

  6. Analyze the test results and verify that the results match the results produced by the same code in the earlier release.

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.

SIL Verification of a Subsystem using Code Generated from an Earlier Release

This example shows how to use code that was generated in a previous release to verify that the model in the current release continues to work as expected. In the current release you can create a test harness using the previously generated code, rather than having to regenerate it.

The model in this example is sldemo_fuelsys_ex, which represents a fuel control system for a gasoline engine. The system under test is the fuel_rate_control subsystem. A normal mode simulation in the current release is compared to a SIL mode simulation from an earlier release.

Open the Fuel Control System Model

sldemo_fuelsys_ex

Create the Normal Test Harness and Select the Signal to Log

1. Right-click the fuel_rate_control subsystem and select Test Harness > Create for 'fuel_rate_control'. The Create Test Harness dialog box opens.

2. Change the Name of the harness to sldemo_fuelsys_harness_normal and click OK to create the normal mode harness.

3. Select the signal exiting the subsystem in the test harness. Pause on the ellipsis to open the action bar and select Enable Data Logging.

4. Close the sldemo_fuelsys_harness_normal harness. You do not need to explicitly save the harness.

Create the SIL Test Harness and Select the Signal to Log

1. Right-click the fuel_rate_control subsystem again and select Test Harness > Create for 'fuel_rate_control' to open the Create Test Harness dialog box.

2. Change the Name of the harness to sldemo_fuelsys_harness_sil.

3. On the Advanced Properties tab, set the harness as a SIL harness that verified code generated in an earlier release.

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

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

  3. In Build folder, enter fuel_rate_control_ert_rtw, which is the name of the folder that contains the code verified using the SIL subsystem in the earlier release.

4. Click OK to create the SIL harness.

5. Select the signal exiting the subsystem in the test harness. Pause on the ellipsis to open the action bar and select Enable Data Logging.

Create an Equivalence Test Case

1. Use sltestmgr to open the Test Manager.

2. Click New > Test File. Right-click on the test file and change its name to 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 System Under Test section for Simulation 1,

  1. Set the Model to sldemo_fuelsys.

  2. Under Test Harness > Harness, select sldemo_fuelsys_harness_normal.

  3. Under Simulation Settings Overrides, select Stop Time and set it to 10.

7. For Simulation 2,

  1. Set the Model to sldemo_fuelsys.

  2. Under Test Harness > Harness, select sldemo_fuelsys_harness_sil.

  3. Under Simulation Settings Overrides, leave Release as Current. Set Stop Time and set it to 10.

Specify the Harness Inputs

For both simulations, in the Inputs sections, click Add and, in the Add Input dialog box, in the File field, enter harnessInputs.mat. Click Map Inputs and then click Add to set up the inputs.

Run the Test and View the Output and Results

Click Run to run the equivalence test. In the Results and Artifacts pane, expand Equivalence Criteria Result to view the output.

The upper plot shows the output of both test harnesses. The lower plot shows that the difference between fuel_rate_control:1 (Baseline) and fuel_rate_control:1 (Sim Output) is zero. This difference means that the two results plots match exactly. This matching indicates that the code verified using SIL from the earlier release and the code generated in the current release produce the same results.

See Also

| | (Embedded Coder)

Related Topics