MATLAB Examples

Testing AUTOSAR Compositions

Test AUTOSAR Composition models. Copyright 2017 The MathWorks, Inc.

Contents

This example demontrates test harness features and back-to-back testing workflows for an AUTOSAR composition model. Switch to a directory with write permissions.

The example uses a model of a throttle position controller for an automobile. It is based closely on a shipping Embedded Coder® Support Package for AUTOSAR Standard example called Import AUTOSAR Composition to Simulink. For details, see ImportAUTOSARCompositionToSimulinkSpkgExample.

Open the AUTOSAR Composition Model

AUTOSAR composition models contain a network of interconnected Model blocks, each of which represents an atomic AUTOSAR software component (ASWC). The throttle position controller composition was created by an AUTOSAR authoring tool (AAT) and imported into Simulink using an ARXML file that describes the composition.

The composition model contains six component models, one for each atomic software component in the composition. Simulink inports and outports represent AUTOSAR ports and signal lines represent AUTOSAR component connectors.

filePath = fullfile(matlabroot,'toolbox','simulinktest','simulinktestdemos');
open_system(fullfile(filePath,'sltestThrottlePositionControlCompositionExample'));

Open Test Harness

A test harness for the model has been generated and can be opened using the perspective control in the lower right corner of the editor canvas. Alternately, use:

sltest.harness.open('sltestThrottlePositionControlCompositionExample','BasicSchedulerTest');

A Test Sequence block is used as the source. The component under test requires the accelerator pedal position sensor input APP_HwIO_Value, which is modeled in the Test Sequence block using a simple three step sequence:

The Initialize step sets the input to a nominal value and the Run step models a steady acceleration command for 950 ms. The acceleration command is reset to the nominal value in the Terminate step. The component under test requires two additional inputs that capture the primary and secondary throttle position sensor readouts. These inputs are modeled using an external timeseries input and are directly fed through the Test Sequence block without modification. This modeling style is useful when some stimulus inputs can be modeled and others are only available as externally captured data.

Test Harnesses for Export Functions

The component under test is the AUTOSAR composition model, which uses the export-function modeling style. When you create a test harness for an export-function model, the harness will contain a Test Sequence block configured to call each root-level Simulink Function block and send a trigger event to each function-call subsystem in the model. The generated Test Sequence block can be used as a convenient starting point for modeling a scheduler.

In this example, since the input signal data is also being generated by a Test Sequence source block, the code to send the trigger events has been consolidated into a single Test Sequence block and embedded in each step after the stimulus waverforms have been generated. The call order of the trigger events are computed using compiled information from the composition model.

  1. send(TPS_Primary_Run_0005)
  2. send(TPS_Secondary_Run_0005)
  3. send(Monitor_Run_0005)
  4. send(APPSnsr_Run_0005)
  5. send(Controller_Run_0005)
  6. send(Actuator_Run_0005)

Simulate the model to see the throttle command output from the component under test.

sim('BasicSchedulerTest');
open_system('BasicSchedulerTest/Scope');

Back-to-back Testing

The test manager can be used to lock down simulation behavior and verify equivalence in software-in-the-loop (SIL) mode. Open the test file and run the equivalance test.

filePath = fullfile(matlabroot,'toolbox','simulinktest','simulinktestdemos','sltestThrottlePositionControlTests.mldatx');
open(filePath);
sltest.testmanager.run;

The test case verifies the open-loop behavior of the Throttle Position Controller ASWC within the composition model. The first part of the equivalence test case runs the test harness containing the composition in normal simulation mode. The second part of the test uses the Post-Load callback to switch the Throttle Position Controller ASWC to software-in-the-loop (SIL) mode with Top model code interface. The results of both simulations show that the behavior is equivalent.

close_system('sltestThrottlePositionControlCompositionExample.slx',0);
clear sltestThrottlePositionControlData HBridgeCmd_LkupTbl SensorSelection SetpointPercent_LkupTbl TPSPrimaryPercent_LkupTbl TPSSecondaryPercent_LkupTbl TPSPercent_LkupTbl tout logsout filePath;

sltest.testmanager.clear;
sltest.testmanager.clearResults;