26
Formal Model-Based Test for AUTOSAR multicore RTOS AUTOSAR multicore RTOS Ling Fang 2012.04.19 Formal Model-Based Test for AUTOSAR multicore RTOS 1/27

Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

  • Upload
    others

  • View
    7

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

Formal Model-Based Test for AUTOSAR multicore RTOSAUTOSAR multicore RTOS

Ling Fang2012.04.19

Formal Model-Based Test for AUTOSAR multicore RTOS 1/27

Page 2: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

Outline1. Abstract

– Motivation– System outline– Related work

2. Preliminaries– LTL and SPIN– AUTOSAR RTOS

3. Formal model of AUTOSAR RTOS– Construct model

* Abstract model* Abstract model* Concrete model

– Verify the model4. Use the formal model for test

– Test suite generation * Extract a test case set* Test selection strategies

– Test program generation– Bug analysis

5. Experiments, conclusion and future work– Experiment results– Conclusion and future work

Formal Model-Based Test for AUTOSAR multicore RTOS Outline 2/27

Page 3: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

Motivation• AUTOSAR multicore RTOS

– Safety-critical and high quality is required – Correctness is confused by concurrency

• Multi-core and multi-task– Conventional test is the main method for detecting the bugs: low

coverage and high cost• Difficult to ensure a perfect coverage• The manual design is an inherently time-cost process• Must be carried out for every system with a different configuration• Must be carried out for every system with a different configuration• Bug analysis usually also consumes much time

• Our proposal– A formal model of AUTOSAR RTOS – Test automation

• A test suite generator • A test program generator

– Advantage• It improves the coverage• It is completely automatic, saves cost and development time• Bug analysis also becomes easy

Formal Model-Based Test for AUTOSAR multicore RTOS Motivation/Introduction 3/27

Page 4: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

System outline• A formal model-based test method

– A complete test suite generator– Automation of the test

AUTOSAR formal model

Test suite

Test case generator

Entire test

cases

Model checking Filtering

Test programs

ECU

Model checking

Test sequences

Test program generator

4/34Formal Model-Based Test for AUTOSAR multicore RTOS System outline/Introduction 4/27

Page 5: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

Related work • Test case generation for RTOS

– With model checking to find test cases• G. Hamon: iteratively extended already discovered tests and

thus extended additional goals • Hong: enumerates the state wherein the user must provide a

CTL formula for every state to be covered. – Use formal specification language to describe test

scenarioscenario• Toppers project: used a formal specification for a test

scenario, which needed analysis manually on about 59 thousand lines.

– Classification Tree Model• Krupp A: Generate test cases with constrain conditions

• Formal RTOS development– FreeRTOS: developed with the B method– OpenComRTOS: concurrently with a formal model to

certify that implementation meets its specificationFormal Model-Based Test for AUTOSAR multicore RTOS Related work/Introduction 5/27

Page 6: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

LTL and SPIN • Linear Temporal logic (LTL)

– Kripke Structure: 4-tuple M = � S0, S, R, L�• S� is a set of states, S0� initial state, R� a transition between

states, L: a mapping from the states to atomic propositions, L(s): a set of atomic propositions that holds for a state s, Path: π� s_0,s_1,... �(∀i≥ 0:(si,si+1 ∊ R)

– LTL Syntax:π,ψ::= true | false | P |φ∨ψ | π∧ψ | �φ | ○φ | �φ | Iφ

P: atomic proposition, ○�next, ��future, I�global.

⊧ ∊

∨ ∧P: atomic proposition, ○�next, ��future, I�global.

– LTL Semantics:π⊧ P iff P ∊ L(π0)π⊧�φ iff not π ⊧ φπ⊧ φ ∧ ψ iff π ⊧ φ and π ⊧ ψπ⊧ φ ∨ ψ iff π ⊧ φor π ⊧ ψπ⊧ ○φ iff π1 ⊧ φπ⊧�φ iff πi ⊧ φ for some i ≥ 0π⊧ I φiff πi ⊧ φ for any i ≥ 0

• SPIN model checker– SPIN is the most mature tool for LTL

Formal Model-Based Test for AUTOSAR multicore RTOS LTL and SPIN/Preliminaries 6/27

Page 7: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

AUTOSAR RTOS: Configurable RTOS

Configurationfile

USERApplication

System Generator

User provide oil(OSEK Implementation Language) file for application code and system information.

System generator gives a static

SGOutputFiles

Compiler

LinkerTargetExecuteFile

System generator gives a static information with configuration file.

Development tool such as compiler and linker does not depend on the component of kernel.

KernelCode

Formal Model-Based Test for AUTOSAR multicore RTOS AUTOSAR RTOS/Preliminaries 7/27

Page 8: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

Concepts of RTOS • Task and SVC:

– Task: Basic unit of programming controlled by an RTOS, refers to an execution context of RTOS management or applications

– SVC: Request service to the RTOS, activateTask, TerminateTask, ChainTask,…

• Interrupt Service Routine (ISR):– ISR category 1 (ISR1) has no effect on the OS– ISR category 2 (ISR2) calls API functions and rescheduling is – ISR category 2 (ISR2) calls API functions and rescheduling is

initiated by the generated ISR2 epilogue• Event:

– Provide a method for the synchronization of different tasks, or ISR2• Resource:

– Used to ensure the shared access• Critical section and Lock:

– Critical section means the way of arranging things so that a modification of shared data structure appears atomic

– Lock is a binary semaphore used to implement critical section

AUTOSAR RTOS/Preliminaries 8/27Formal Model-Based Test for AUTOSAR multicore RTOS

Page 9: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

task0 priority=3core0

resource0 priority=2

ISR2

ISR1

rsuspended

ready(re)

running(r)

waiting(w)

w r

e p e

e

core0act wait set

Typical behavior of RTOS

resource0 priority=2

core1

execute(e)

pending(p)

r re r

r re r

r

re

task1 priority=2

task2 priority=1

task3 priority=0

core0

core0

core0

act

getResource

chainact:activateTask

ter:terminateTask

chain:chainTask

wait:waitEvent

set:setEventter

Formal Model-Based Test for AUTOSAR multicore RTOS AUTOSAR RTOS/Preliminaries 9/27

Page 10: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

API test case

• API test– The system states before and after API process

processbefore after

process

task0: suspended

task1: running

task2: suspended

task0: running

task1: ready

task2: suspended

task1 activate task0

Formal Model-Based Test for AUTOSAR multicore RTOS AUTOSAR RTOS/Preliminaries 10/27

Page 11: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

Construct a configurable RTOS model

USERApplication

System Generator

User provide oil(OSEK Implementation Language) file for application code and system information.

System generator

Configurationfile

SGOutputFiles

Compiler

LinkerTargetExecuteFile

System generator gives a static information with configuration file.

Development tool such as compiler and linker does not depend on the component of kernel.

KernelCode

Formal Model-Based Test for AUTOSAR multicore RTOS Formal model of AUTOSAR RTOS 11/27

Abstract modelConcrete model

Page 12: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

Abstract model of AUTOSAR RTOS• Definition is performed in two steps:

– Define states and transition condition labels for each transition systems– Define the interaction communication between the transition systems

• Asynchronous communication• Synchronous communication

run

suswait

waitEvent

preempt start

terminate

activateSetEvent

occupied

put get

free Lock

task

task core

CPU

Resource

readyactivate

run

ready

suswait

waitEvent

preempt start

terminate

activatesetEvent

occupied

put get

free

core

: transition : state : channel

Formal Model-Based Test for AUTOSAR multicore RTOS Abstract model/Formal model of AUTOSAR 12/27

Page 13: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

Concrete model • The concrete model must be created with the system

configuration. Target model is concrete containing the information of numbers, identities, priorities, accessibilities of tasks, resources, ISR2, events, and etc. – Abstract model can be reused for any RTOS conforming

AUTOSAR requirementAUTOSAR requirement– Test cases from target concrete model correspond the concrete

system, so they are executable

Formal Model-Based Test for AUTOSAR multicore RTOS Concrete model/Formal model of AUTOSAR 13/27

task[0].priority = 3task[0].coreID = 0task[0].preemptive = preemptivetask[0].status = suspended…

Configuration file

Page 14: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

Verify the model • Deadlock and livelock:

– Be detected with a model checker automatically• LTL formula:

– Reachability– Safety

�(taski.state=ready∧taskj..state=running) ∧(taski..priority>taskj.. priority)

• Assertion:

Count-example of

• LTL formula inversion

Count-example of model checking• Deadlock & livelock• LTL formula inversion

model Model checker

• Assertion• LTL formula• Assertion

OK

NG

Formal Model-Based Test for AUTOSAR multicore RTOS Verify the model/Formal model of AUTOSAR 14/27

Page 15: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

Use the formal model for test

• With the test case generator– Extract the heuristic test case set from the

formal model – Filter the feasible and entire test suite with

coverage criteriacoverage criteria• With the test program generator

– Calculate the test sequences with model checking for the test cases

– Translate the test sequences into the executable test programs

Formal Model-Based Test for AUTOSAR multicore RTOS Use the formal model for test 15/27

Page 16: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

t0:runt1:ready

……

Generate heuristic test case setCircle: end point of critical section, a complete transition for SVC (must be atomic)

Diamond: state inside critical section

t0:sust1:runt2:sus

t1:readyt2:sus

……

… … …

Formal Model-Based Test for AUTOSAR multicore RTOS

t1 activate t0

Generate test suite/Use the formal model for test 16/27

Page 17: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

Generate heuristic test case set

• A heuristic and finite test case set can be extracted from the formal model – Counterexample: task0=claim (claim is not a

normal state of task) normal state of task) – At the end of critical section

Formal Model-Based Test for AUTOSAR multicore RTOS Generate test suite/Use the formal model for test 17/27

Page 18: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

Test selection strategiesThe classification tree is used to find all the possible combinations of the conditions from

the heuristic test case set, in other words, to group the heuristic set with the criteria and select one case from each group as the member of the target test suite. For example:

C1 : executor and affected task are on the same core.C2 : executor and affected task are on the different cores.C3 : executor is activated for several times.C4 : executor is activated for single time.…Case4: T0 activate T1 : T0.run, T1.sus → T0.run, T1.readyCase5: T0 activate T2 : T0.run, T2.sus → T0.run, T2.readyCase5: T0 activate T2 : T0.run, T2.sus → T0.run, T2.readyCase6: T0 activate T1 : T0.run, T1.sus, T2.sus → T0.run, T1.ready, T2.susCase7: T0 activate T1 : T0.run, T1.sus, T2.ready → T0.run, T1.ready, T2.ready

Formal Model-Based Test for AUTOSAR multicore RTOS Generate test suite/Use the formal model for test 18/27

C1 C2 C3 C4 C5 C6 C7 C8

Page 19: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

Test program generation • Find a sequence of operations to set up the internal state

before the test case can be applied – Test case is used as counterexample– Model checking for finding appropriate paths (test sequences)

Formal Model-Based Test for AUTOSAR multicore RTOS

The entire test case setThe complete and useful test suite

Test program generation/The formal model for test 19/27

Page 20: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

Test program generation • Translate the path from model checker to the

program which can be executed on ECU

Formal Model-Based Test for AUTOSAR multicore RTOS Test program generation/The formal model for test 20/27

Page 21: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

Bug analysis• When bugs exist, the user can analyze

them with a trace along the test sequence step-by-step

Action: task1 ActivateTask task_3task0: suspended task3: suspendedtask0: suspended task3: runningtask0: running task3: runningtask status: 0:sus 1:run 2:sus 3:sus 4:sus 5:sus

Action:task1 TerminateTasktask status: 0:run 1:ready 2:sus 3:run 4:sus 5:susDifference: task1 is ready in model, but is sus in ECUAction: task3 ActivateTask task0task status: 0:sus 1:run 2:sus 3:run 4:sus 5:sus

task0: suspended

task1: running

task2: suspended

task3: suspended

task4: suspended

task5: suspended

core0 core1

task0: suspended

task1: running

task2: suspended

task3: running

task4: suspended

task5: suspended

core0 core1

task0: running

task1: ready

task2: suspended

task3: running

task4: suspended

task5: suspended

core0 core1

Formal Model-Based Test for AUTOSAR multicore RTOS Bug analysis/The formal model for test 21/27

TerminateTask task1 ??

Page 22: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

Experiment results • 20 new cases were found

– Almost all cases when the executor and affected tasks were on different cores– Several complicate cases when the executor and affected tasks were on the same core

Formal Model-Based Test for AUTOSAR multicore RTOS Experiment results/Experiments and conclusion 22/27

Page 23: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

before afterProcess

task0: running

task1: ready

task3: suspended

task4: running

task0 Terminate

(task0 is multi-activated)

task0: running

task1: ready

task3: suspended

task4: running

Typical new test cases

23

task4: running task4: running

before after

task0: running

task1: ready

task3: suspended

task4: running

task0 chain task3

(4 task’s state changed )

task0: suspended

task1: running

task3: running

task4: ready

Process

Formal Model-Based Test for AUTOSAR multicore RTOS Experiment results/Experiments and conclusion 23/27

Page 24: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

before afterprocess

task0: running

task1: suspended

task3: suspended

task4: running

task0 activate task3

(task4 is preempted)

task0: running

task1: suspended

task3: running

task4: ready

24

before afterprocess

task0: running

task1: suspended

task3: suspended

task4: running

task0 activate task3

(task4 is non-preempted)

task0: running

task1: suspended

task3: ready

task4: running

2/34Formal Model-Based Test for AUTOSAR multicore RTOS Experiment results/Experiments and conclusion 24/27

Page 25: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

Contribution and future work• Contribution

– Greatly improve the quality• It extracts test cases from a model more completely• It is based on the behavior of the system, it does not need to

consider complex test scenarios

– Greatly cut the cost• It includes automatic test case generation and test execution • It includes automatic test case generation and test execution

completely automatically• Easy to be reused• Easy to be changed• Easy for bug analysis

• Future work– Complete the model for timing features– A smart performance test is desired by industry

Formal Model-Based Test for AUTOSAR multicore RTOS Originalities and future work/Experiments and conclusion 25/27

Page 26: Formal Model-Based Test for AUTOSAR multicore RTOSicst2012.soccerlab.polymtl.ca/Presentation_Slides/...Formal Model-Based Test for AUTOSAR multicore RTOS LingFang 2012.04.19 Formal

END

Please contact me if you have any questions.

[email protected] (I changed my work from Japan to China)