© 2015 the mathworks, inc. - matlab€¦ · 57 software metrics produced by polyspace files lines...

59
1 © 2015 The MathWorks, Inc.

Upload: dangkhuong

Post on 20-May-2018

222 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

1© 2015 The MathWorks, Inc.

Page 2: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

2© 2015 The MathWorks, Inc.

Software Design and Verification for

Model and Code

Presenter: Sang-Ho Yoon

Senior Application Engineer

Page 3: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

3

Today’s Agenda

Introduction to V&V in Model-Based Design

Verification Activities in MBD

Model Verification

– Design Review

– Static Analysis

– Dynamic Test

Code Generation and Verification

– Code Review

– Static Analysis

– Equivalence Test

Questions and Answers

Page 4: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

4© 2015 The MathWorks, Inc.

Introduction to V&V

in Model-Based Design

Page 5: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

5

Ind. Standards

Requirements

System-Level

Specification

Subsystem

Design

Subsystem

Implementation

Subsystem

Integration & Test

System-Level

Integration & Test

Complete

Integration

& Test

C, C++

MCU DSP FPGA ASIC

HDL

Code

Verification and

Validation

Integration

testing

User Acceptance

Testing

Requirements

Physical

Components

Environment

AlgorithmsV

eri

ficati

on

an

d V

ali

dati

on

Development Process

Page 6: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

6

Source: Return on Investment for Independent

Verification & Validation, NASA, 2004.

High cost of fixing

defects detected

late

Difficult to know

when “enough”

testing is done

As design

complexity

increases, time and

cost to test does too

Test

Code

Design

Requirements

0

5

10

15

20

25

30

35

40

45

50

Relative Cost

to Fix

Phase Found

De

fec

t

Typ

e

Relative Cost to Fix Defects per Phase Found

Test Code Design Requirements

Price of Late Verification and ValidationRelative Cost to Fix Defects

Page 7: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

7

Model Verification Code Verification

Reference Workflow for Verification and

Validation in Model-Based Design

Page 8: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

8© 2015 The MathWorks, Inc.

Verification Activities in MBD

Page 9: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

9

Verification in DO-178B/C

*DO-178C Section 6.0

Page 10: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

10

Verification Activities in MBD

Model Verification– Design Review

Requirement Traceability

Report Generation

– Static Analysis Model Standards Checking

Design Error Detection

Prove Design Correctness

– Dynamic Test Simulation-based Functional Test

Coverage Analysis

Code Generation and Verification– Code Review

Code Generation Report

– Static Analysis Code Metrics and Coding Rule Checking

Formal Verification (Abstract Interpretation)

– Equivalence Test SIL(Software-In-the-Loop) and PIL(Processor-In-the-Loop)

Requirements

Model

Design

Code

Integration

User

Acceptance

1

2

Code

Page 11: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

11© 2015 The MathWorks, Inc.

Model Verification

Page 12: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

12

• Requirement Traceability

• Report Generation

Design Review

• Modeling Standard Checking

• Design Error Detection

• Prove Design Correctness

• Model Slice

Static Analysis

• Simulation-based Functional Test

• Coverage Analysis

Dynamic Test

Page 13: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

13

Algorithm Model

Functional Requirements Model

Traceability is required for

functional safety standards

Page 14: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

14

Requirements TraceabilitySimulink Verification and Validation

Traceability analysis of

models relative to

– System requirements

– Design, interface descriptions

– Change requests

– Defect reports

Standards and Certification

– ISO 26262, IEC 61508, DO

178, EN 50128

– Other industry standards

(CMMI, SPICE, etc.)

Page 15: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

15

Creating links between textual documents and model

objects

Tracing RequirementsModelSimulink Verification and Validation

Page 16: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

16

Requirements Traceability – ReportSimulink Verification and Validation

Requirements Report

provides screenshots of the

model and lists all the

associated requirements

Page 17: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

17

Report for Model ReviewSimulink Report Generator

Design and generate

reports for MBD

Interactive design

reviews

Model Comparison and

Merge

Page 18: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

18

• Requirement Traceability

• Report Generation

Design Review

• Modeling Standard Checking

• Design Error Detection

• Prove Design Correctness

• Model Slice

Static Analysis

• Simulation-based Functional Test

• Coverage Analysis

Dynamic Test

Page 19: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

19

Potential Error

Is there a potential error in this model?

– It depends…

Page 20: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

20

The Need for Static Analysis

How about now?

When generating code:• Floating-point precision

issues may lead to

incorrect comparison

results

Is this a production

model?• Implementation requires

a fixed-step, discrete

solver

• Ports do not follow

established naming

conventions

Page 21: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

21

• Requirement Traceability

• Report Generation

Design Review

• Modeling Standard Checking

• Design Error Detection

• Prove Design Correctness

• Model Slice

Static Analysis

• Simulation-based Functional Test

• Coverage Analysis

Dynamic Test

Page 22: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

22

Modeling Guidelines

MAAB Style Guides

– First version released in April, 2001

– Collaboration by industry leaders in US,

Japan, Europe: GM, Ford, Chrysler,

Toyota, Daimler, John Deere, Delphi,

Ricardo and others

Modeling Guidelines for High-Integrity

Systems

– Leverage industry-best practices and

MathWorks tool expertise when

developing high-integrity systems

– ISO 26262, IEC 61508, DO-178B/C,

and MISRA-C

Page 23: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

23

Modeling Standards Checking in SimulinkSimulink Verification and Validation

Analysis Engine

– Model Advisor (Simulink)

Checks– Readability and Semantics

– Performance and Efficiency

– Change and Configuration

Management

– Potential runtime errors

Model Advisor Interface

Page 24: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

24

• Requirement Traceability

• Report Generation

Design Review

• Modeling Standard Checking

• Design Error Detection

• Prove Design Correctness

• Model Slice

Static Analysis

• Simulation-based Functional Test

• Coverage Analysis

Dynamic Test

Page 25: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

25

Design Error Detection with Formal MethodsSimulink Design Verifier

Detect hard-to-find design errors before simulation

Dead logic

Division by zero

Range violation

Integer overflow

Assertion violation

Out of bound

array access

Page 26: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

26

• Requirement Traceability

• Report Generation

Design Review

• Modeling Standard Checking

• Design Error Detection

• Prove Design Correctness

• Model Slice

Static Analysis

• Simulation-based Functional Test

• Coverage Analysis

Dynamic Test

Page 27: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

27

Verifying Design Against RequirementsSimulink Design Verifier

Algorithm

(System)

Functional and

Non-Functional

Requirement

informal formal

1

Formal model

(System)

Formal Property2

3Improve algorithm,

or requirements

Formal

Methods

Engine

Page 28: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

28

Example of Properties

Simple True / False– Simple logic blocks

– Truth table

Temporal logic– Temporal Logic blocks (part of SLDV demo)

Example of using basic templates as building blocks for complex property.

– Imply blocks (part of SLDV blockset) ~A or B

– Stateflow / Embedded MATLAB Functions

Page 29: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

29

Requirements Proving

Design model

Specified properties

Proof

OR

Counterexample

Formal

Methods

Page 30: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

30

• Requirement Traceability

• Report Generation

Design Review

• Modeling Standard Checking

• Design Error Detection

• Prove Design Correctness

• Model Slice

Static Analysis

• Simulation-based Functional Test

• Coverage Analysis

Dynamic Test

Page 31: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

31

Model Slicer: Test and Debug Complex ModelsSimulink Design Verifier

Can you show me just what

I really care about?

Signal of

interest

Time window of

interestDesign Model

Page 32: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

32

Model Slicer Highlighting

Propagates signals and data of interest through you design:

– Forward

– Backward

– Bidirectional

Shows effect of a simulation time window

Supports interactive selecting or excluding blocks/signals

Page 33: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

33

Creating Model Slices

I found the important part of my model, now how

can I isolate that for simulation, debugging, etc.?

Model Slices

Reduce your original design model to just the

necessary and sufficient parts for the area of

interest.

Page 34: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

34

Slice Model Generation

Eliminates:

– Unneeded blocks

– Unused ports

– Unnecessary signals

Simplifies hierarchy and

signal flow

Resulting Models

Easier to understand

Simpler to analyze

Simplifies

and

expands

trivial

subsystems

Replace

switches

with lines

Removes

unneeded

content

Page 35: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

35

• Requirement Traceability

• Report Generation

Design Review

• Modeling Standard Checking

• Design Error Detection

• Prove Design Correctness

• Model Slice

Static Analysis

• Simulation-based Functional Test

• Coverage Analysis

Dynamic Test

Page 36: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

36

Test-Harness

Test Cases

(Signal Builder)

Output Check

(Assertion Block)

Model

(Model Block)

Module Test-Harness

Page 37: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

37

Test Cases Signal Builder

Test Cases to Signal Builder

Page 38: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

38

Model Coverage ReportSimulink Verification and Validation

Coverage metrics identifies untested portions of your

model

Page 39: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

39

Improving Test SuiteSimulink Design Verifier

Generating tests to

reach coverage criteria

Test generation from model

Test inputs that ensure complete

coverage

Test Generation

Page 40: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

40

Relational Boundary Coverage (R2014b)

Verify testing around boundary points (Part of DO-178C)

Integer Relation Floating-point Relation

Lhs just < Rhs

Lhs just > Rhs

Lhs just < Rhs

Lhs just > Rhs

Lhs just < Rhs

Lhs just > Rhs

Lhs == Rhs

Page 41: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

41

How about Legacy Code?

Use of Legacy Code Tool for introduction of existing C

code on Simulink models

specification

External C

Function

MATLAB code

Page 42: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

42

Coverage for C-code S-Functions

C code

Coverage

Model

Design

S-Function

Page 43: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

43© 2015 The MathWorks, Inc.

Code Generation and Verification

Page 44: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

45

• Code Generation Report

Code Review

• Code Metrics and Coding Rule Checking

• Formal Verification (Abstract Interpretation)

Static Analysis

• SIL(Software-In-the-Loop)

• PIL(Processor-In-the-Loop)

Equivalence Test

Page 45: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

46

Code Generation Report

Page 46: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

47

Traceability between Model and Code

Hyperlink back

to model.

Hyperlink within

C code files.

Hyperlink from

model to code.

Page 47: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

48

Traceability Report

Page 48: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

49

Static Code Metrics Report

Integrated into generated

Simulink Coder Report

Target independent analysis

Includes

– Number of files

– Number of lines

– Estimation of global RAM

– Estimation of stack size

Page 49: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

53

• Code Generation Report

Code Review

• Code Metrics and Coding Rule Checking

• Formal Verification (Abstract Interpretation)

Static Analysis

• SIL(Software-In-the-Loop)

• PIL(Processor-In-the-Loop)

Equivalence Test

Page 50: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

55

CATEGORY OF STATIC ANALYSIS OF USING

TOOLS

Compiler Warnings

Bug Findings Formal Methods

Code Metrics, and Coding Rules

(No False negative)(False negative)

Error Prevention

Error Detection

Page 51: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

56

Polyspace PRODUCTS

Compiler Warnings

Bug Findings Formal Methods

Code Metrics, and Coding Rules

(No False negative)(False negative)

Polyspace Bug Finder

Polyspace Code Prover

Polyspace Bug Finder Polyspace Code Prover

Error Prevention

Error Detection

Page 52: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

57

Software metrics produced by Polyspace

Files

Lines

Lines of code

Comment density

Estimated function coupling

Function

Lines within body

Executable lines

Cyclomatic complexity

Language scope

Paths

Calling functions

Called functions

Call occurrences

Instructions

Call levels

Function parameters

Goto statements

Return points

Project

Files

Header files

Recursions

Protected shared variables

Non-protected shared variables

Software quality objectives

Define custom levels with thresholds to measure

achievement of a quality level

Support for HIS (Hersteller Initiative Software) metrics

Page 53: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

58

Polyspace support for code rules compliance

MISRA C:2004

– 131 rules supported

– 9 rules not statically enforceable

– 2 rules not supported

MISRA AC AGC -- application of MISRA-C:2004

for generated code

– 88 obligatory rules are supported

– 8 are not statically enforceable

– 2 are not supported

MISRA C++:2008

– 185 of the 228 rules supported

JSF++:2005

– 157 of 234 rules supported

Customization

– Turn rules off / warning / error

– Define custom naming conventions

– Mark violations as reviewed or indicate

future action

MISRA C:2012

– 6 Directives supported

– 132 rules supported

Page 54: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

59

PolyspaceFormal Methods based Static Code Analysis

Exhaustively verify code

– Detect and prove absence of runtime errors

– Precisely determines and propagates variable ranges

Languages supported

– C, C++, and Ada

Verify SW robustness

– Analyze for full range

operating conditions

OR

– Specified ranges of

parameters and inputs

Page 55: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

60

Fixing the Runtime Error in the DesignTrace and Fix Using PolySpace Model Link SL

May Overflow

(establish traceability between

PolySpace analysis and model)

Page 56: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

61

• Code Generation Report

Code Review

• Code Metrics and Coding Rule Checking

• Formal Verification (Abstract Interpretation)

Static Analysis

• SIL(Software-In-the-Loop)

• PIL(Processor-In-the-Loop)

Equivalence Test

Page 57: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

62

Software-in-the-Loop (SIL) Testing:Verify Production Controller with Software-in-the-loop

Compiled C Code

S-Function(Windows DLL)

Code

Generation

Execution

• Host/Host

• Nonreal-time

Page 58: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

63

Processor-in-the-Loop Testing:Verify Production Controller with Processor-in-the-loop

Production Processor

Code

Generation

Execution

• Host/Target

• Nonreal-time

Page 59: © 2015 The MathWorks, Inc. - MATLAB€¦ · 57 Software metrics produced by Polyspace Files Lines Lines of code Comment density Estimated function coupling Function Lines within

64

Q&A