34
1 Daniel Martins Application Engineer – MathWorks [email protected] Increasing Embedded Software Confidence Model and Code Verification

Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks [email protected] Increasing Embedded Software Confidence

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

1

Daniel MartinsApplication Engineer – [email protected]

Increasing Embedded Software ConfidenceModel and Code Verification

Page 2: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

2

What is the Cost of Software Failure…

$7,500,000,000

Ariane 5

Rocket & payload lost

Page 3: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

3

What is the Cost of Software Failure…

Casualtiesdue to radiation overdose

6

Therac-25

Page 4: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

4

Where do you want to discover and fix errors?

Model

Generated Code

Vehicle TestingIn Service

Pre sales Post sales

Page 5: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

5

Using Model-Based Design

It is easier and less expensive to fix design errors early in the process when they happen.

Model-Based Design enables:

1. Early testing to increase confidence in your design

2. Delivery of higher quality software throughout the workflow

Page 6: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

6

Gaining Confidence in our Design

Effort / Time

Confidence

Ad-hoc testing

Design error detection

Functional& structural tests

Modeling standards

Model & code equivalence checks

Code integration analysis

Page 7: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

7

Application: Cruise Control

70 km/h

Control speed according to setpoint

Page 8: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

8

System

Inputs OutputsFuel Rate

Control Module

Shift Logic

Control Module

ECU

system

Legacy c

ode

ECU

Application: Cruise Control

2Cruise

Control

Module (MBD)

1

Page 9: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

9

System

Inputs OutputsFuel Rate

Control Module

Shift Logic

Control Module

ECU

system

Legacy c

ode

ECU

Application: Cruise Control

Cruise

Control

Module (MBD)

Page 10: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

10

Application: Cruise Control

Cruise_onoff

Brake

Speed

Coast set

Accel reset

Inputs

Engaged

Target speed

Outputs

Cruise

Control

Module (MBD)

Page 11: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

11

Gaining Confidence in our Design

Effort / Time

Confidence

Ad-hoc testing

Page 12: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

12

Ad-hoc Tests

New “Dashboard” blocks facilitate

early ad-hoc testing

Page 13: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

13

Gaining Confidence in our Design

Effort / Time

Confidence

Ad-hoc testing

Design error detection

Page 14: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

14

Finding Design Errors: Dead Logic

Page 15: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

15

Finding Unintended Behavior

Dead logic due to “uint8”

operation on incdec/holdrate*10

Fix change the order of

operation 10*incdec/holdrate

Condition can never be false

Page 16: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

16

Gaining Confidence in our Design

Effort / Time

Confidence

Ad-hoc testing

Design error detection

Functional& structural tests

Page 17: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

17

Simulation Testing Workflow

Structural coverage

report

Did we completely

test our model?

Did we meet

requirements?

Review functional

behavior

Design

Requirements

Page 18: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

18

Requirements Based Functional Testing with

Coverage Analysis

Page 19: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

19

Did We Completely Test our Model?

Model Coverage

Analysis

Potential causes of less

than 100% coverage:

Missing requirements

Over-specified design

Design errors

Missing tests

Page 20: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

20

Gaining Confidence in our Design

Effort / Time

Confidence

Ad-hoc testing

Design error detection

Functional& structural tests

Modeling standards

Page 21: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

21

Model Advisor – Model Standards Checking

Page 22: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

22

Gaining Confidence in our Design

Effort / Time

Confidence

Ad-hoc testing

Design error detection

Functional& structural tests

Modeling standards

Model & code equivalence checks

Page 23: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

23

Code Generation with Model-to-Code Traceability

Page 24: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

24

Equivalence Testing:

Model vs SIL or PIL Mode Testing

Model

Testing

SIL or PIL

Mode Testing

Coverage 100%

Page 25: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

25

Code Equivalence Check Results:

Model vs Code

Code Coverage

Page 26: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

26

Gaining Confidence in our Design

Effort / Time

Confidence

Ad-hoc testing

Design error detection

Functional& structural tests

Modeling standards

Model & code equivalence checks

Codeintegration analysis

Page 27: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

27

System

Inputs OutputsFuel Rate

Control Module

Shift Logic

Control Module

ECU

system

Legacy c

ode

ECU

Code Integration Analysis

Cruise

Control

Module (MBD)

Cruise

Control

Module (MBD)

1

Cruise

Control

Module (MBD)

1

Page 28: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

28

Fuel Rate

Control Module

Shift Logic

Control Module

ECU

system

Legacy c

ode

ECU

2Cruise

Control

Module (MBD)

1

Code Integration Analysis

Cruise_onoff

Brake

Speed

Coast set

Accel reset

EGO Sensor

MAP Sensor

Inputs

Gear

Engaged

Target speed

Fuel Rate

Outputs

Page 29: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

29

Fuel Rate

Control Module

Shift Logic

Control Module

ECU

system

Legacy c

ode

ECU

Cruise_onoff

Brake

Speed

Coast set

Accel reset

EGO Sensor

MAP Sensor

Inputs

Gear

Engaged

Target speed

Fuel Rate

Outputs

Inaccurate

scaling for

speed

Finding Dead Code During Integration

De

ad

co

de

Cruise

Control

Module (MBD)

2

Page 30: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

30

Finding Dead Code with Polyspace

Dead code

Maximum target speed = 90Target speed parameter

propagated to “Cruise_ctrl.c”

[0 … 40]

Page 31: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

31

Polyspace Code Analysis

static void pointer_arithmetic (void)

{

int array[100];

int *p = array;

int i;

for (i = 0; i < 100; i++) {

*p = 0;

p++;

}

if (get_bus_status() > 0) {

if (get_oil_pressure() > 0) {

*p = 5;

} else {

i++;

}

}

i = get_bus_status();

if (i >= 0) {

*(p - i) = 10;

}

}

Source code painted in green, red, gray, orange

Green: reliablesafe pointer access

Red: faultyout of bounds error

Gray: deadunreachable code

Orange: unprovenmay be unsafe for some

conditions

Purple: violationMISRA-C/C++ or JSF++

code rules

variable ‘I’ (int32): [0 .. 99]

assignment of ‘I’ (int32): [1 ..

100]

Range datatool tip

Page 32: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

32

Conclusion:

Model-Based Design Verification Workflow

Model VerificationDiscover design errors at design time

Code VerificationGain confidence in the generated code

Workflow approved by TÜV SÜD for development of safety-critical software in accordance with

ISO 26262 (automotive), IEC 61508 (industrial), EN 50128 (railway), IEC 62304 (medical devices)

Page 33: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

33

Key Takeaway

It is easier and less expensive to fix design errors early in the process when they happen.

Model-Based Design enables:

1. Early testing to increase confidence in your design

2. Delivery of higher quality software throughout the workflow

Page 34: Increasing Embedded Software Confidence Model and Code ...€¦ · 1 Daniel Martins Application Engineer –MathWorks Daniel.martins@mathworks.fr Increasing Embedded Software Confidence

34

Change the world by

Accelerating the paceof discovery, innovation, development, and learning

in engineering and science