Main Content

Run Quality Checks on S-Functions

This example shows how to use S-Function analyzer programmatic interfaces to check S-functions for potential problems and improvements.

The S-Function analyzer programmatic interface consists of:

  • Simulink.sfunction.Analyzer - Object used to launch S-function analyzer and get analysis results.

  • Simulink.sfunction.analyzer.BuildInfo - Object used to create an object to specify the build information for an S-function.

  • Simulink.sfunction.analyzer.Options - Object used to specify the running options for S-function analyzer.

  • Simulink.sfunction.analyzer.findSfunctions - Function to return all feasible S-functions in a model or library for S-function analyzer.

Specify Input Model or Library

The S-Function analyzer requires a model or a library on the MATLAB® path that contains the S-Function blocks to be analyzed.

model = 'slexSfunctionCheckExample';

Specify Build Information for S-functions

S-function analyzer checks the source code of S-functions when they are available. Heuristics are applied to automatically locate the source code based on S-function names. For example, if S-function source code and the input model are in the same folder, the source code is included in the analysis automatically. Otherwise, the build information has to be specified using a Simulink.sfunction.analyzer.BuildInfo object. If no source code is available, you do not need to complete this step.

To specify the build information, first determine the eligible S-functions in the input model. Then, create a Simulink.sfunction.analyzer.BuildInfo object for each S-function. For the S-function slexBadSFcn, there are two associated source files: slexBadSFcn.c and slexBadSFcn_wrapper.c

sfunctions= Simulink.sfunction.analyzer.findSfunctions(model);
bdInfo= Simulink.sfunction.analyzer.BuildInfo('slexBadSFcn.c',...
                                              'ExtraSrcFileList',{'slexBadSFcn_wrapper.c'});

Specify Running Options for S-Function Analyzer

You can configure the execution options for S-function analyzer, such as whether to enable Polyspace checks and parameter robustness checks, the simulation timeout, and the output path for the result report, using a Simulink.sfunction.analyzer.Options object. If you do not need to modify options from their default values, you can skip this step.

opts = Simulink.sfunction.analyzer.Options;
opts.EnableRobustness = 1;

Run S-Function Analyzer and View Results

Create a Simulink.sfunction.Analyzer object that captures the specified build information and options. Then, run the S-function analyzer with that configuration using the run function and generate a report of the analysis results using the generateReport function.

sfunAnalyzer = Simulink.sfunction.Analyzer(model,'BuildInfo',{bdInfo},'Options',opts);
analysisResult=run(sfunAnalyzer);
generateReport(sfunAnalyzer);