+ All Categories
Home > Documents > A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and...

A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and...

Date post: 16-Dec-2015
Category:
Upload: myra-davidson
View: 213 times
Download: 1 times
Share this document with a friend
Popular Tags:
52
A Theory of Predicate- complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November 2-5 2004
Transcript
Page 1: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

A Theory of Predicate-complete Test Coverage and Generation

Thomas BallTesting, Verification and Measurement

Microsoft Research

FMCO SymposiumNovember 2-5 2004

Page 2: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Control-flow Coverage Criteria

• Statement/branch coverage widely used in industry

• 100% coverage ≠ a bug-free program!!

• More stringent criteria – modified-condition-decision, predicate, data-

flow, mutation, path, …

Page 3: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Beyond Statement and Branch Coverage

void partition(int a[]) { assume(a.length>2); int pivot = a[0]; int lo = 1; int hi = a.length-1; while (lo<=hi) { while (a[lo]<=pivot) lo++; while (a[hi]>pivot) hi--; if (lo<hi) swap(a,lo,hi); }}

Page 4: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Beyond Statement and Branch Coverage

void partition(int a[]) { assume(a.length>2); int pivot = a[0]; int lo = 1; int hi = a.length-1; while (lo<=hi) { while (a[lo]<=pivot) lo++; while (a[hi]>pivot) hi--; if (lo<hi) swap(a,lo,hi); }}

Page 5: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Beyond Statement and Branch Coverage

void partition(int a[]) { assume(a.length>2); int pivot = a[0]; int lo = 1; int hi = a.length-1; while (lo<=hi) { while (a[lo]<=pivot) lo++; while (a[hi]>pivot) hi--; if (lo<hi) swap(a,lo,hi); }}

Page 6: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Corrected Program

void partition(int a[]) { assume(a.length>2); int pivot = a[0]; int lo = 1; int hi = a.length-1; while (lo<=hi) { while (lo<=hi && a[lo]<=pivot) lo++; while (a[hi]>pivot) hi--; if (lo<hi) swap(a,lo,hi); }}

Page 7: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Corrected Program

void partition(int a[]) { assume(a.length>2); int pivot = a[0]; int lo = 1; int hi = a.length-1; while (lo<=hi) { while (lo<=hi && a[lo]<=pivot) lo++; while (a[hi]>pivot) hi--; if (lo<hi) swap(a,lo,hi); }}

Page 8: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.
Page 9: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.
Page 10: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Predicate-complete Testing

• Program predicates– relational expression such as (x<0)– the expression (x<0) || (y>0) has two predicates

• Program with m statements and n predicates– m x 2n possible observable states S– finest partition of behavior based on

programmer’s observations

• Goal– cover all reachable observable states R S

Page 11: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Reachable Observable States

L1: if (x<0)L2: skip; elseL3: x = -2;L4: x = x + 1;L5: if (x<0)L6: A;

Page 12: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Upper and Lower Bounds

m x 2n possible states S

Upper bound U

Reachable states R

Lower bound L

• Bound reachable observable states R

– predicate abstraction– modal transition systems– |L| / |U| defines “goodness” of abstraction

• Test generation using L

• Increase |L| / |U| ratio

Page 13: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Overview

• Upper and lower bounds

• Example

• Test case generation

• Refinement

• Discussion

• Conclusions

Page 14: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Predicate Abstraction of Infinite-state Systems

– Graf & Saïdi, CAV ’97– Abstract Interpretation, Cousot & Cousot ‘77

• Idea– Given set of predicates P = { P1, …, Pk }

• Formulas describing properties of system state

• Abstract State Space– Set of Abstract Boolean variables B = { b1, …, bk }

• bi = true Set of states where Pi holds

Page 15: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

a

a’

may

MC MA

a

a’

total

MC MA

a

a’

total &

onto

a

a’

onto

Modal Transitions [Larsen]

Page 16: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Predicate Abstraction

if Q SP(P,s)then (P,Q) onto

P

SP(P,s)Q

Q

WP(s,Q)Pif P WP(s,Q) then (P,Q) may

Q

WP(s,Q)P

if P WP(s,Q) then (P,Q) total

Page 17: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Example

Page 18: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Upper Bound: May-Reachability

a

b

c

may

a

b

c

may

Page 19: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Upper Bound: May-Reachability

a

b

c

may

a

b

c

may

Page 20: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

c

d

total

a

b

onto

Lower Bound

may

Page 21: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

c

d

a

b

Lower Bound

may

onto

total

Page 22: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

c

d

a

b

Lower Bound

may

onto

total

Page 23: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Overview

• Upper and lower bounds

• Example

• Test case generation

• Refinement

• Discussion

• Conclusions

Page 24: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

void partition(int a[]) { assume(a.length>2); int pivot = a[0]; int lo = 1; int hi = a.length-1; while (lo<=hi) { while (a[lo]<=pivot) lo++; while (a[hi]>pivot) hi--; if (lo<hi) swap(a,lo,hi); }}

Example

Page 25: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Observation Vector

[ lo<hi, lo<=hi, a[lo]<=pivot, a[hi]>pivot ]

• lo<hi lo<=hi

lo<hi lo<=hi (a[lo]<=pivot a[hi]>pivot)

(a[lo]<=pivot a[hi]>pivot)

Only 10/16 observations possible

Page 26: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

13 labels x 10 observations = 130 observable states

But, program constrains reachable observable statesgreatly.

void partition(int a[]) { assume(a.length>2); int pivot = a[0]; int lo = 1; int hi = a.length-1;

L0: while (lo<=hi) { L1: ; L2: while (a[lo]<=pivot) { L3: lo++; L4: ;} L5: while (a[hi]>pivot) { L6: hi--; L7: ;} L8: if (lo<hi) { L9: swap(a,lo,hi); LA: ;} LB: ;} LC: ;}

Page 27: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.
Page 28: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Overview

• Upper and lower bounds

• Example

• Test case generation

• Refinement

• Discussion

• Conclusions

Page 29: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Test Generation

• DFS of lower bound generates covering set of paths

• Symbolically execute paths to generate tests

• Run program on tests to find errors and compute coverage of observable states

Page 30: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.
Page 31: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.
Page 32: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

{ 0,-7,-8 }

Page 33: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Array bounds violations

Generated Inputs

(L0:TTTT,L4:FTFT) { 0,-8,1 }(L0:TTTT,L4:TTFT) { 0,-8,2,1 }(L0:TTTT,L4:TTTT) { 0,-8,-8,1 }(L0:TTTF,L4:TTFF) { 1,-7,3,0 }(L0:TTTF,L4:FTTF) { 0,-7,-8 }(L0:TTTF,L4:TTTF) { 1,-7,-7,0 }(L0:TTFT,L7:TTFF) { 0,2,-8,1 }(L0:TTFT,L7:FTFT) { 0,1,2 }(L0:TTFT,L7:TTFT) { 0,3,1,2 }(L0:TTFF,L0:TTTT) { 1,2,-1,0 }

void partition(int a[]) { assume(a.length>2); int pivot = a[0]; int lo = 1; int hi = a.length-1;

L0: while (lo<=hi) { L1: ; L2: while (a[lo]<=pivot) { L3: lo++; L4: ;} L5: while (a[hi]>pivot) { L6: hi--; L7: ;} L8: if (lo<hi) { L9: swap(a,lo,hi); LA: ;} LB: ;} LC: ;}

Page 34: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Results

• Buggy partition function– U=49, L=43, Tested=42

• Fixed partition function– U=56, L=37, Tested=43

• What about the remaining 13 states?

Page 35: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Overview

• Upper and lower bounds

• Example

• Test case generation

• Refinement

• Discussion

• Conclusions

Page 36: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Refinement

Page 37: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

New Observation Vector

[ lo<hi, lo<=hi, lo=hi+1,

a[lo]<=pivot, a[hi]>pivot,

a[lo-1]<=pivot, a[hi+1]>pivot

]

Only 48/128 observations possible

For this set of predicates, L = U

Page 38: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.
Page 39: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Overview

• Upper and lower bounds

• Example

• Test case generation

• Refinement

• Discussion

• Conclusions

Page 40: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Discussion

• Comparison to bisimulation

• Completeness of abstractions

• Related work

Page 41: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Bisimulation

Page 42: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Bisimulation

Page 43: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Abstraction Completeness

Page 44: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Abstraction Completeness

Page 45: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Related Work

• Predicate abstraction

• Modal transition systems

• Abstraction-guided test generation

• Symbolic execution/constraint satisfaction

• Test coverage criteria

Page 46: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

PCT Coverage does not imply Path Coverage

L1: if (x<0)L2: skip; elseL3: x = -2;L4: x = x + 1;L5: if (x<0)L6: A;

Page 47: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

PCT Coverage does not imply Path Coverage

L1: if (x<0)L2: skip; elseL3: x = -2;L4: x = x + 1;L5: if (x<0)L6: A;

Page 48: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

PCT Coverage does not imply Path Coverage

L1: if (x<0)L2: skip; elseL3: x = -2;L4: x = x + 1;L5: if (x<0)L6: A;

Page 49: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

PCT Coverage does not imply Path Coverage

L1: if (x<0)L2: skip; elseL3: x = -2;L4: x = x + 1;L5: if (x<0)L6: A;

Page 50: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

L1: if (p)L2: if (q) L3: x=0;L4: y=p+q;

Path Coverage does not imply PCT Coverage

Page 51: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

L1: if (p)L2: if (q) L3: x=0;L4: y=p+q;

Path Coverage does not imply PCT Coverage

Page 52: A Theory of Predicate-complete Test Coverage and Generation Thomas Ball Testing, Verification and Measurement Microsoft Research FMCO Symposium November.

Conclusions

• PCT coverage – new form of state-based coverage – similar to path coverage but finite

• Upper and lower bounds – computed using predicate abstraction and

modal transitions – use lower bound to guide test generation– refine bounds


Recommended