verification of automatically generated code · 19 what have i learned … start verification...

18
1 © 2015 The MathWorks, Inc. Verification of Automatically Generated Code Richard Anderson

Upload: others

Post on 17-Oct-2020

1 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Verification of Automatically Generated Code · 19 What have I learned … Start verification early, using the power of MATLAB and Simulink Reuse your simulation tests to verify the

1© 2015 The MathWorks, Inc.

Verification of Automatically

Generated Code

Richard Anderson

Page 2: Verification of Automatically Generated Code · 19 What have I learned … Start verification early, using the power of MATLAB and Simulink Reuse your simulation tests to verify the

2

Development Lifecycle

Requirements

Models

Source Code

Object Code

Simulink & Stateflow

Embedded Coder

Compiler/IDE

And which tools

should I use?

When should I start

verification?

Page 3: Verification of Automatically Generated Code · 19 What have I learned … Start verification early, using the power of MATLAB and Simulink Reuse your simulation tests to verify the

3

Verification with MATLAB and Simulink

Requirements

Models

Source Code

Object Code

Refine Requirements

Iterate Design

simOut = sim(‘myModel’);

Model AdvisorSimulation Data Inspector (SDI)

Simulink & Stateflow

Embedded Coder

Compiler/IDE

Page 4: Verification of Automatically Generated Code · 19 What have I learned … Start verification early, using the power of MATLAB and Simulink Reuse your simulation tests to verify the

4

Verification with Embedded Coder

Requirements

Models

Source Code

Object Code

Software-in-the-Loop

(SIL)

Processor-in-the-Loop

(PIL)

Requirements

Based Testing

With PIL

Simulink & Stateflow

Embedded Coder

Compiler/IDE

Page 5: Verification of Automatically Generated Code · 19 What have I learned … Start verification early, using the power of MATLAB and Simulink Reuse your simulation tests to verify the

5

Automated Dynamic TestingSoftware-in-the-Loop (SIL) and Processor-in-the-Loop (PIL)

• Verify numerical equivalence

• Assess execution time

• Assess code coverage

• Create certification artifacts

Page 6: Verification of Automatically Generated Code · 19 What have I learned … Start verification early, using the power of MATLAB and Simulink Reuse your simulation tests to verify the

6

Demo – SIL/PIL with Emulator (QEMU)

Page 7: Verification of Automatically Generated Code · 19 What have I learned … Start verification early, using the power of MATLAB and Simulink Reuse your simulation tests to verify the

8

Extend Model Coverage to Code Coverage

Collect Code Coverage during SIL/PIL Simulations

Using LDRA Testbench

Using Simulink Verification and Validation (R2016b)

Page 8: Verification of Automatically Generated Code · 19 What have I learned … Start verification early, using the power of MATLAB and Simulink Reuse your simulation tests to verify the

9

Dynamic Verification Workflow

Use Simulink simulation to verify your models and your code

– Requirements based tests

– Functional tests

– Coverage Tests

Use Processor-in-the-Loop to

– Assess numerical behaviour

Using full target toolchain and libraries

– Gather performance metrics

– Demonstrate testing coverage

Page 9: Verification of Automatically Generated Code · 19 What have I learned … Start verification early, using the power of MATLAB and Simulink Reuse your simulation tests to verify the

10

But it’s not just Simulink based

Page 10: Verification of Automatically Generated Code · 19 What have I learned … Start verification early, using the power of MATLAB and Simulink Reuse your simulation tests to verify the

12

Have I missed anything?

Requirements

Models

Source Code

Object Code

Polyspace

Bug Finder

Simulink & Stateflow

Embedded Coder

Compiler/IDE

Model

Advisor

Does the code meet

my company coding

standard?

MISRA C Checker { 2012, 2004 }

MISRA AC AGC Subset– application of MISRA-C for generated code

MISRA C++ Checker

JSF++ Checker

Page 11: Verification of Automatically Generated Code · 19 What have I learned … Start verification early, using the power of MATLAB and Simulink Reuse your simulation tests to verify the

13

Does the code match my design?

Requirements

Models

Source Code

Object Code

Simulink & Stateflow

Embedded Coder

Compiler/IDE

Simulink Code Inspector

Demonstrate that model and

source code match structurally

and functionally

Provide modelcode

traceability data

Reduce manual code reviews for

DO-178 software

Page 12: Verification of Automatically Generated Code · 19 What have I learned … Start verification early, using the power of MATLAB and Simulink Reuse your simulation tests to verify the

14

Are there any runtime errors in the system?

Requirements

Models

Source Code

Object Code

Polyspace

Code Prover

Simulink & Stateflow

Embedded Coder

Compiler/IDE

Polyspace Bug Finder

& Code Prover

Simulink Design

Verifier

Page 13: Verification of Automatically Generated Code · 19 What have I learned … Start verification early, using the power of MATLAB and Simulink Reuse your simulation tests to verify the

15

Polyspace in action

Page 14: Verification of Automatically Generated Code · 19 What have I learned … Start verification early, using the power of MATLAB and Simulink Reuse your simulation tests to verify the

16

Polyspace product family for C/C++

Polyspace Bug Finder

– Quickly find bugs in embedded software

– Check code compliance for MISRA and JSF

– Intended for every day use by software engineers

Polyspace Code Prover

– Proves code to be safe and dependable

– Deep verification of software components

– Perform QA signoff for production ready code

Ada language also supported for proving code

Page 15: Verification of Automatically Generated Code · 19 What have I learned … Start verification early, using the power of MATLAB and Simulink Reuse your simulation tests to verify the

17

• Re-generate and re-verify the code

• Reuse and manually integrate the existing code

with newly generated code

Upgrading to a New Release

Multiple benefits:

New features or products

Latest advances in code generation

But, you have already verified code from previous release(s)

Page 16: Verification of Automatically Generated Code · 19 What have I learned … Start verification early, using the power of MATLAB and Simulink Reuse your simulation tests to verify the

18

Code Reuse Across Releases (R2016b)

• Avoid re-verifying code spanning MATLAB releases

• Support simulation workflows via SIL/PIL

• Automate integration with newly generated code as part of Build action

Existing code from a prior release

10a 15b

16b

New code

Page 17: Verification of Automatically Generated Code · 19 What have I learned … Start verification early, using the power of MATLAB and Simulink Reuse your simulation tests to verify the

19

What have I learned …

Start verification early, using the power of MATLAB and Simulink

Reuse your simulation tests to verify the code on real hardware with PIL

– Gather code coverage metrics

– Capture execution time

– Demonstrate numerical equivalence to design

Use static analysis to

– Ensure code standards conformance

– Spot weaknesses in your design

– Prove the absence of runtime errors

Page 18: Verification of Automatically Generated Code · 19 What have I learned … Start verification early, using the power of MATLAB and Simulink Reuse your simulation tests to verify the

20

Questions?