the yogi project software property checking via static analysis and testing aditya v. nori, sriram...

34
The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft Research India

Upload: ross-brown

Post on 18-Jan-2016

224 views

Category:

Documents


3 download

TRANSCRIPT

Page 1: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

The Yogi ProjectSoftware property checking via static analysis

and testing

Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur

Microsoft Research India

Page 2: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Synergizing Testingand Static Analysis

Idea: Combine testing and static analysis

through a “synergy” of both

New algorithms (Synergy, Dash, SMASH) to do scalable proofs using testing

Industrial strength tool (3 person years)

Synergy: Gulavani, Henzinger, Kannan, N., Rajamani, FSE 2006 Dash: Beckman, N., Rajamani, Simmons, ISSTA 2008SMASH: Godefroid, N., Rajamani, Tetali, MSR-TR-2009

Page 3: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

The problemQuestionIs error() unreachable for all possible inputs?

Input

Testing: finds bugs, but can’t prove their absenceStatic analysis: can prove the absence of bugs, but can result in false errors

Page 4: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

a↦true b↦falselimit↦2×

Testing×

a↦true b↦falselimit↦2i↦0lock↦1x=0y=0

Page 5: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

a↦true b↦falselimit↦2×

Testing×

×

×

×

×

×

×

×

×

××

×

×

Page 6: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

a↦true b↦falselimit↦2×

Testing×

×

×

×

×

×

×

×

×

××

×

×

test

Page 7: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Abstraction1

2:ρ×

×

s1s2

Page 8: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Abstraction 0

23 4

5

1

9

6 78

11 10

Page 9: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Proof

2:ρ

0

2: ¬ρ3:ρ 4: ¬ρ

5: ¬ρ

1:ρ

9:ρ

6:ρ 7: ¬ρ8: ¬ρ

11 10

9: ¬ρ

1: ¬ρ

4:ρ3: ¬ρ5:ρ

7:ρ6::¬ρ8:ρ

ρ = (lock != 1)

Page 10: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Key Ideas

Frontier: Boundary between tested and untested regions

WPα: New refinement operation that does not depend on whole program alias information

01234

789

×

××

××

××

× ×

56××

××

10

frontier

Page 11: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Key IdeasStep 1: Try to generate a

test that crosses the frontier– Perform symbolic

simulation on the path until the frontier and generate a constraint 1

– Conjoin with the condition 2 needed to cross frontier

– Is 12 satisfiable?

01234

789

×

××

××

××

× ×

56××

××

10

1

2

frontier

Page 12: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Key Ideas01234

789

×

××

××

××

× ×

56××

××

10

frontier

Step 1: Try to generate a test that crosses the frontier– Perform symbolic

simulation on the path until the frontier and generate a constraint 1

– Conjoin with the condition needed to cross frontier 2

– Is 12 satisfiable? [YES]

Step 2: run the test and extend the frontier

×

×

×

Page 13: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Key IdeasStep 1: Try to generate a

test that crosses the frontier– Perform symbolic

simulation on the path until the frontier and generate a constraint 1

– Conjoin with the condition needed to cross frontier 2

– Is 12 satisfiable? [NO]

01234

789

×

××

××

××

× ×

56××

××

10

1

2

frontier

Page 14: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Key IdeasStep 1: Try to generate a

test that crosses the frontier– Perform symbolic

simulation on the path until the frontier and generate a constraint 1

– Conjoin with the condition needed to cross frontier 2

– Is 12 satisfiable? [NO]

Step 2: use WPα to refine so that the frontier moves back!

0123

4:¬ρ789

×

××

××

××

× ×

56××

××

10

frontier

4:ρ

Page 15: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

DASH: Proofs from Tests– Algorithm uses only test case generation

operations– Maintains two data structures:

• A forest of reachable concrete states (tests)– Under-approximates executions of the

program• A region graph (an abstraction)

– Over-approximates all executions of the program

– Our goal: bug finding and proving• If a test reaches an error, we have found

bug• If we refine the abstraction so that there is

*no* path from the initial region to error region, we have a proof

– Handles the richness of C• New operator WPα uses only aliases α that

are present along concrete tests that are executed

• Algorithm uses recursive invocations to handle inter-procedural analysis

Page 16: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Can extend test beyond frontier?

Refine abstraction

Construct initial abstractionConstruct random tests

Test succeeded? Bug!

Abstractionsucceeded?

τ = error path in abstraction f = frontier of error path

yes

no

yes

no

Proof! yes

no

Input:Program P

Property ψ

The DASH Algorithm

Page 17: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Example

Can extend test beyond frontier?

Refine abstraction

Construct initial abstractionConstruct random tests

Test succeeded? Bug!

Abstractionsucceeded?

τ = error path in abstraction f = frontier of error path

yes

no

yes

no

Proof! yes

no

Input:Program P

Property ψ

Page 18: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

τ=(0,1,2,3,4,7,8,9)

Example

Symbolic execution +

Theorem proving

frontier

Can extend test beyond frontier?

Refine abstraction

Construct initial abstractionConstruct random tests

Test succeeded? Bug!

Abstractionsucceeded?

τ = error path in abstraction f = frontier of error path

yes

no

yes

no

Proof! yes

no

Input:Program P

Property ψ

01234

56

789

×

× ×

× ×

× ×

× ×

×

×

× ×

×

10×

y = 1

Page 19: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Refinement 01234

56

789

×

× ×

× ×

× ×

× ×

×

×

× ×

×

10×

8:¬ρ 8:ρ9

89

ρ= (lock.state != L)

× ×refine

Page 20: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Refinement

8:¬ρ 8:ρ9

89

ρ= (lock.state != L)

× ×

01234

56

78 :¬ρ

9

×

× ×

× ×

× ×

× ×

×

×

× ×

×

10×

8:ρ

refine

Page 21: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Example

τ=(0,1,2,3,4,7,<8,p>,9)

01234

56

78 :¬ρ

9

×

× ×

× ×

× ×

× ×

×

×

× ×

×

10×

8:ρ Can extend test beyond frontier?

Refine abstraction

Construct initial abstractionConstruct random tests

Test succeeded? Bug!

Abstractionsucceeded?

τ = error path in abstraction f = frontier of error path

yes

no

yes

no

Proof! yes

no

Input:Program P

Property ψ

frontier

Page 22: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Correct, the program is0123

4⋀¬s5⋀¬s6⋀¬r

9

×

× ×

× ×

× ×

××

×

×

7⋀¬q×

8⋀¬p×

4⋀s5⋀s6⋀r7⋀q

8⋀p×

10

Page 23: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Handling procedure calls

Key ideaPerform a recursive Dash query on the called procedure and usethe result to either generate a test or compute WPα

Sk-1

Sk

×

Sk-2 T×

CALL(foo(i, j)) frontier

Page 24: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Interprocedural analysis

Sk-1

Sk

×

Sk-2 T×

CALL(foo(i, j)) Dash[assume(φ1), foo(i, j), assert(¬φ2)]- pass: perform refinement- fail: generate test

12

Page 25: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Correctness• Theorem. If Dash terminates on (P, φ), then

either of the following is true:– If Dash returns (“pass”, Σ≃), then Σ≃ is a proof that P

cannot reach ¬φ– If Dash returns (“fail”, t), then t certifies that P reaches ¬φ

• Theorem. Every Dash iteration entails exactly one theorem prover call

• However … Dash need not terminate! Thus, usefulness is based on empirical evidence

Page 26: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Locked

do { //get the write lock

KeAcquireSpinLock(&devExt->writeListLock);nPacketsOld = nPackets; request = devExt->WriteListHeadVa;

if(request && request->status){devExt->WriteListHeadVa = request->Next;

KeReleaseSpinLock(&devExt->writeListLock);

irp = request->irp;if(request->status > 0){

irp->IoStatus.Status = STATUS_SUCCESS;irp->IoStatus.Information = request->Status;}

else{irp->IoStatus.Status = STATUS_UNSUCCESSFUL;irp->IoStatus.Information = request->Status;

}SmartDevFreeBlock(request);IoCompleteRequest(irp, IO_NO_INCREMENT);nPackets++;

}} while (nPackets != nPacketsOld);

KeReleaseSpinLock(&devExt->writeListLock);

LL

Windows Device Drivers

Unlocked

Error

UU

Page 27: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft
Page 28: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Source Code

TestingDevelopment

API Usage Rules(SLIC)

Software Model Checking

Read forunderstanding

New API rules

Drive testingtools

Defects

100% pathcoverage

Rules

Static Driver Verifier

Page 29: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Source Code

TestingDevelopment

API Usage Rules(SLIC)

Software Model Checking

Read forunderstanding

New API rules

Drive testingtools

Defects

100% pathcoverage

Rules

Static Driver Verifier

Page 30: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Architecture of Yogi

Yogi IR (yir)

C Program slamcl

Slam.li database

sliccSLIC property

Instrumented Slam.li database

li2yir

Test case that exposes a

bug

Proof that program satisfies property

Alias and mod-ref information

Z3 theorem prover

YAbsManYSim

polymorphic

region graphs

initialfunctions

summaries

Page 31: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Implementation

• ~6K lines of F#• Z3 theorem prover• Integrated with SDV for Windows• Engineering effort: 3 person years

Page 32: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Static Driver Verifier Runs• #drivers = 69, #properties = 85• largest driver = ~30 KLOCs• #KLOCs = ~350 KLOCS• Yogi works on 129 runs where SLAM “gives up”• Yogi takes ~12 hours whereas SLAM takes ~42 hours

Page 33: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

Thanks to …

• Nels Beckman (CMU)• Bhargav Gulavani (IIT

Bombay)• Thomas Henzinger

(EPFL)• Yamini Kannan

(Berkeley)• Robert Simmons

(CMU)

• Leonardo de Moura (MSR Redmond)

• Nikolaj Bjorner (MSR Redmond)

Page 34: The Yogi Project Software property checking via static analysis and testing Aditya V. Nori, Sriram K. Rajamani, Sai Deep Tetali, Aditya V. Thakur Microsoft

http://research.microsoft.com/yogi