Run Polyspace on AUTOSAR Code
This topic describes a component-based approach to verifying AUTOSAR code with Polyspace. For an integration analysis approach, see Choose Between Component-Based and Integration Analysis of AUTOSAR Code with Polyspace.
Polyspace® for AUTOSAR runs static program analysis on code implementation of AUTOSAR software components. The analysis looks for possible run-time errors or mismatch with specifications in the AUTOSAR XML (ARXML).
To run Polyspace on code implementation of AUTOSAR software components, provide this information:
ARXML folder: This folder contains all the
.arxml
files that define your AUTOSAR model. The files specify the data types, runnables, events and other information about the software components in your AUTOSAR model.Note that Polyspace can parse an AUTOSAR XML schema only for releases 4.0 and later.
Source code folder: This folder contains the C code implementation of the software components. The
.c
files in this folder contain functions implementing the AUTOSAR runnables and other called functions. The folder can also contain header files referenced in your source files.If you reference header files located in another folder, you can provide that location separately.
The analysis parses your ARXML files, reads your source files and creates a Polyspace project with a separate module for each software component. Polyspace Code Prover™ then checks each module for run-time errors or violations of data constraints in the ARXML at run-time.
This topic shows how to run Polyspace on code implementation of AUTOSAR software components. You can run Polyspace from the user interfaces of the Polyspace desktop products or the command line:
In the user interfaces, the analysis happens in two steps: creating a Polyspace project from the ARXML and code folders and running Code Prover on the project.
At the command line, the analysis can be done by using the
polyspace-autosar
command.
Example Files
To follow the steps in this tutorial, use the demo files in
.
Here, polyspaceroot
\polyspace\examples\doc_cxx\polyspace_autosar
is the Polyspace installation folder, for instance, polyspacroot
C:\Program
Files\Polyspace\R2024b
.
Run Analysis in Polyspace Desktop User Interface
In the older Polyspace desktop user interface, you can create a Polyspace project in the user interface. Each module in the project contains the source files implementing one software component. You can run verification on a single module or all modules together.
Read ARXML and Sources
Specify upfront that the project must be created from AUTOSAR specifications.
Select File > New. In the Project-Properties window, select Create from AUTOSAR specification.
In the field Specify AUTOSAR ARXML folder, specify the top level folder containing your ARXML files. In the section Specify AUTOSAR source folder, specify all the folders containing C/C++ source files.
If you use the files in the tutorial, enter the following paths:
ARXML folder:
polyspaceroot
\polyspace\examples\doc_cxx\polyspace_autosar\arxmlSource folder:
polyspaceroot
\polyspace\examples\doc_cxx\polyspace_autosar\code
In the Advanced settings field, enter the option
-generate-autosar-headers
so that the analysis generates AUTOSARRte_
headers.In your regular workflow, you can use your own
Rte_
headers instead of the generated ones. You might also have to specify other information such as additional paths to include folders, additional macro definitions or advanced options to troubleshoot errors.To specify paths to include files that are not directly under the source folder, use the field Specify additional include folders.
This field corresponds to the option
-I
ofpolyspace-autosar
.To specify data type and macro definitions that are not in your source files, use the field Specify additional macro definitions. Specify a file with the definitions.
This field corresponds to the option
-include
ofpolyspace-autosar
.To specify advanced command-line options associated with
polyspace-autosar
, use the field Advanced settings.For instance:
You might want to specify a compiler and target architecture. By default, compilation of projects created from AUTOSAR specifications use the gnu4.7 compiler and i386 architecture.
To specify a visual11.0 compiler with x86_64 architecture, enter this option:
See also-extra-project-options "-compiler visual11.0 -target x86_64"
Compiler (-compiler)
andTarget processor type (-target)
.
You might want to specify that the analysis generate the AUTOSAR headers (
Rte_
headers,Os.h
,Compiler.h
, etc.) instead of using the ones found in the source headers. In this case, use the option-generate-autosar-headers
.
Click Start. The software parses your ARXML specifications and C code implementation and creates a Polyspace project. Follow the progress of the project creating process in Command output.
After the project is successfully created, you can check the status of the AUTOSAR project by clicking
See this AUTOSAR project status
in the Project status pane. The filepsar_project.xhtml
shows a summary of the project creation process in your web browser. In the window Create project from AUTOSAR information, click Close to complete creating the project. The modules corresponding to individual software component are grouped together in the project. The module names correspond to the fully qualified name of the software component, as specified in the ARXML. See Benefits of Polyspace for AUTOSAR.
The software parses your ARXML specifications and C code implementation and creates a Polyspace project. Each module in the project references C files that implement one software component. The module name corresponds to the fully qualified name of the software component, as specified in the ARXML. See Benefits of Polyspace for AUTOSAR.
If the software fails to parse your ARXML specifications or runs into compilation issues with your code, see additional details in the Command output or Project status tab. Investigate the issue further and fix your ARXML files or code accordingly. See Troubleshoot Polyspace Analysis of AUTOSAR Code.
Configure Project
Once a project is created, you can change some of the default analysis options. For instance, you can generate a report after analysis using the options in the Reporting section. For details on how to specify options, see Specify Polyspace Analysis Options.
You do not need the options in these sections for a project generated from an AUTOSAR description:
Inputs and Stubbing: External data constraints in your ARXML files are extracted automatically when you create a Polyspace project. You cannot explicitly specify external constraints.
Multitasking: You cannot perform a multitasking analysis with the Polyspace project because each module analyzes the implementation of one software component. To detect data races, create a separate project for the entire application and explicitly add your source folders. Specify the ARXML files relevant for multitasking and run Bug Finder. For more information, see
ARXML files selection (-autosar-multitasking)
.Code Prover Verification: A
main
function is generated (in the filepsar_prove_main.c
) when you create a Polyspace project from an AUTOSAR description. Themain
function calls functions that implement runnable entities in the software components. The generatedmain
is needed for the Code Prover analysis. You cannot change the properties of thismain
function.
Verify Code
Verify each module individually or all the modules.
To verify a single module, select the module and click Run Code Prover.
To verify all modules, from the drop down list beside Run Code Prover, select Run All Modules.
The verification of a module checks the code implementation of the corresponding software component against the ARXML specifications and also checks for run-time errors. See Benefits of Polyspace for AUTOSAR.
Update Project for Later Changes
If you update your code or ARXML specifications, you can reanalyze the modules. To begin, right-click your project and select Update AUTOSAR Project. Recreate your project and rerun verification on the modules.
If you change the code only for specific software components, only the affected modules are recreated. The modules corresponding to the other software components remain unchanged.
Run Analysis in Polyspace Platform User Interface
In the Polyspace platform user interface, you can create a Polyspace project corresponding to each software component of the AUTOSAR model. The projects are contained in a Polyspace workspace. Each project in the workspace contains the source files implementing one software component. You can analyze each software component separately with their own configurations.
For more details about workspaces, see Manage Related Projects in Polyspace Platform User Interface Using Workspaces.
Read ARXML and Sources
Specify upfront that the project must be created from AUTOSAR specifications.
In the Project toolstrip, select New > Project from AUTOSAR. The window Create project from AUTOSAR information opens.
Enter a name for your project in Project name.
If you choose to not use the default location, uncheck Use default location and specify the path to an empty folder in Location. The project creation fails if the specified folder is not empty.
In Specify AUTOSAR ARXML folder, specify the top level folder containing your ARXML files. In the section Specify AUTOSAR source folder, specify all the folders containing C/C++ source files.
If you use the files in the tutorial, enter the following paths:
ARXML folder:
polyspaceroot
\polyspace\examples\doc_cxx\polyspace_autosar\arxmlSource folder:
polyspaceroot
\polyspace\examples\doc_cxx\polyspace_autosar\code
Select Generate AUTOSAR headers so that the analysis generates AUTOSAR
Rte_
headers.In your regular workflow, you can use your own
Rte_
headers instead of the generated ones. You might also have to specify other information such as additional paths to include folders, additional macro definitions or advanced options to troubleshoot errors.To specify paths to include files that are not directly under the source folder, use the field Specify additional include folders.
This field corresponds to the option
-I
ofpolyspace-autosar
.To specify data type and macro definitions that are not in your source files, use the field Specify additional macro definitions. Specify a file with the definitions.
This field corresponds to the option
-include
ofpolyspace-autosar
.To specify advanced command-line options associated with
polyspace-autosar
, use the field Advanced settings.For example, you might want to specify a compiler and target architecture. By default, compilation of projects created from AUTOSAR specifications use the gnu4.7 compiler and i386 architecture. To specify a visual11.0 compiler with x86_64 architecture, enter this option:
See also-extra-project-options "-compiler visual11.0 -target x86_64"
Compiler (-compiler)
andTarget processor type (-target)
.
Click Start. The software parses your ARXML specifications and C code implementation and creates a Polyspace workspace. Follow the progress of the project creating process in Command output.
After the workspace is successfully created, you can check the status of the AUTOSAR project by clicking See this AUTOSAR project status. The file
psar_project.xhtml
shows a summary of the project creation process in your web browser. In the window Create project from AUTOSAR information, click Close to complete creating the workspace. The projects () corresponding to individual software component are grouped together in a workspace. The project names correspond to the fully qualified name of the software component, as specified in the ARXML. See Benefits of Polyspace for AUTOSAR.
If the software fails to parse your ARXML specifications or runs into compilation issues with your code, see additional details in the Command output or Status fields in the Progress tab. Investigate the issue further and fix your ARXML files or code accordingly. See Troubleshoot Polyspace Analysis of AUTOSAR Code.
Configure Project
Once the projects are created, you can change some of the default analysis options. For instance, you can generate a report after analysis using the options in the Reporting section. For details on how to specify options in the Polyspace Platform user interface, see Polyspace Code Prover Options in Polyspace Platform User Interface.
You do not need the options in these sections for a project generated from an AUTOSAR description:
Inputs and Stubbing: External data constraints in your ARXML files are extracted automatically when you create a Polyspace project. You cannot explicitly specify external constraints.
Multitasking: You cannot perform a multitasking analysis with the Polyspace project because each module analyzes the implementation of one software component. To detect data races, create a separate project for the entire application and explicitly add your source folders. Specify the ARXML files relevant for multitasking and run Bug Finder. For more information, see
ARXML files selection (-autosar-multitasking)
.Code Prover Verification: A
main
function is generated (in the filepsar_prove_main.c
) when you create a Polyspace project from an AUTOSAR description. Themain
function calls functions that implement runnable entities in the software components. The generatedmain
is needed for the Code Prover analysis. You cannot change the properties of thismain
function.
Verify Code
Verify each project individually with their individual set of configurations. To verify a project, right-click the project and select Prove Absence of RTEs. The verification of a project checks the code implementation of the corresponding software component against the ARXML specifications and also checks for run-time errors. See Benefits of Polyspace for AUTOSAR.
Run Polyspace Using Scripts
Run the polyspace-autosar
command with paths to your ARXML and source code
folder. The command parses the ARXML and source files, creates a Polyspace project (.psprj
or .psprjx
) and
analyzes all modules in the project for run-time errors or violation of data
constraints in the ARXML.
In the first run, specify the path to your ARXML and source files explicitly. In
later runs, specify the file psar_project.xhtml
created in the
previous run. The analysis detects changes in the ARXML and source files since the
last run and reanalyzes only those modules where the software component
implementation changed. If the ARXML specification changed since the previous
analysis, the new analysis reanalyzes all modules.
For example, you can run these commands in a .bat
script. In
the first run, this script looks for the ARXML specifications in a folder
arxml
in the current folder, and C source files in a folder
code
. The results are stored in a folder
polyspace
in the current folder. In later runs, the analysis
reuses the result from the previous run through the file
psar_project.xhtml
and updates the results only for the
software components modified since the last
run.
echo off set POLYSPACE_AUTOSAR_PATH=C:\Program Files\Polyspace\R2024b\polyspace\bin set POLYSPACE_EXAMPLE_PATH=C:\Program Files\Polyspace\R2024b\polyspace\examples\doc_cxx\polyspace_autosar IF NOT EXIST polyspace\psar_project.xhtml ( "%POLYSPACE_AUTOSAR_PATH%\polyspace-autosar" -create-project polyspace -arxml-dir "%POLYSPACE_EXAMPLE_PATH%\arxml" -sources-dir "%POLYSPACE_EXAMPLE_PATH%\code" -generate-autosar-headers ) ELSE ( "%POLYSPACE_AUTOSAR_PATH%\polyspace-autosar" -update-project polyspace\psar_project.xhtml ) Pause
.psprj
project file
where the software components specified in the ARXML file correspond to individual
modules in the project. If you want to create a workspace
(.pswks
) where the software components correspond to individual
projects, use these commands:echo off set POLYSPACE_AUTOSAR_PATH=C:\Program Files\Polyspace\R2024b\polyspace\bin set POLYSPACE_EXAMPLE_PATH=C:\Program Files\Polyspace\R2024b\polyspace\examples\doc_cxx\polyspace_autosar IF NOT EXIST polyspace\psar_project.xhtml ( "%POLYSPACE_AUTOSAR_PATH%\polyspace-autosar" -create-project polyspace -arxml-dir "%POLYSPACE_EXAMPLE_PATH%\arxml" -sources-dir "%POLYSPACE_EXAMPLE_PATH%\code" -generate-autosar-headers -output-platform-project ) ELSE ( "%POLYSPACE_AUTOSAR_PATH%\polyspace-autosar" -update-project polyspace\psar_project.xhtml ) Pause
You can also run Code Prover on code implementation of AUTOSAR software components
with MATLAB® scripts. See polyspaceAutosar
.
Review Polyspace results on AUTOSAR Code
After you run the analysis, review the results directly in the use interface. Polyspace Code Prover checks for various issues in AUTOSAR software components, including:
In the Results List pane, red green, and yellow checks of identified issues are listed. In the Result Details pane, each check is linked to the parameter specification.
Alternately, review the summary in the file psar_project.xhtml
.
For the complete workflow of reviewing Polyspace results on AUTOSAR code, see Review Polyspace Results on AUTOSAR Code.
See Also
AUTOSAR
runnable not implemented
| Invalid
result of AUTOSAR runnable implementation
| Invalid use
of AUTOSAR runtime environment function
| polyspaceAutosar
| polyspace-autosar