Main Content

Configure Code Coverage Programmatically

For a software-in-the-loop (SIL) or processor-in-the-loop (PIL) simulation, you can configure third-party code coverage analysis by using command-line APIs.

Set Up Third Party Code Coverage From Command Line

For BullseyeCoverage, you can use this workflow:

  1. Using get_param, retrieve the object containing coverage settings for the current model. For example:

    covSettings = get_param(gcs, 'CodeCoverageSettings')
    
    
    covSettings = 
    
      CodeCoverageSettings with properties:
    
               TopModelCoverage: 'off'
        ReferencedModelCoverage: 'off'
                   CoverageTool: 'None'
    

    The property TopModelCoverage determines whether the software generates code coverage data for just the top model, while ReferencedModelCoverage determines whether the software generates coverage data for models referenced by the top model. If neither property is 'on', the code generator does not produce code coverage data during a SIL or PIL simulation.

    When you save your model, the properties TopModelCoverage, ReferencedModelCoverage, and CoverageTool are also saved.

  2. Check the class of covSettings.

    class(covSettings)
    ans = 
    
        'coder.coverage.CodeCoverageSettings'
    

  3. Turn on BullseyeCoverage code coverage analysis for the top model and referenced models.

    covSettings.TopModelCoverage='on';
    covSettings.ReferencedModelCoverage='on';
    covSettings.CoverageTool='BullseyeCoverage';
    To specify the LDRA tool suite as the code coverage tool, set the property CoverageTool to 'LDRAcover or LDRA tool suite'.

  4. Using set_param, apply the new coverage settings to the model.

    set_param(gcs,'CodeCoverageSettings', covSettings);
  5. Assuming the third-party code coverage tool is installed, specify the installation path.

    coder.coverage.BullseyeCoverage.setPath('C:\Program Files\BullseyeCoverage')

    For the LDRA tool suite, use coder.coverage.LDRA.setPath('C:\...).

  6. Check that the path is saved as a preference.

    coder.coverage.BullseyeCoverage.getPath

    For the LDRA tool suite, use coder.coverage.LDRA.getPath.

Code Coverage for Model That Uses Configuration Reference

If your model uses a configuration set that is not attached to the model, for example, a configuration reference, then the Configure button is dimmed in the Configuration Parameters dialog box. You cannot open the Code Coverage Settings dialog box and you must use line commands to specify code coverage settings.

To configure third-party code coverage analysis for a model that uses a configuration reference:

  1. Get the active configuration set from the model.

    cs = getActiveConfigSet(gcs)

  2. Retrieve the current code coverage settings.

    covSettings = get_param(cs, 'CodeCoverageSettings')

  3. Specify the code coverage settings that you require. For example:

    covSettings.TopModelCoverage = 'on';
    covSettings.ReferencedModelCoverage='on';
    covSettings.CoverageTool='BullseyeCoverage';

  4. Get the configuration set that is specified by the configuration reference.

    csBase = cs.getRefConfigSet

  5. Apply the required code coverage settings to the referenced configuration set.

    set_param(csBase, 'CodeCoverageSettings', covSettings);
    The active configuration set for the model contains the code coverage settings that you require.

Related Topics