Symbolic methods for efficient mutation testing (work in progress)

39
Symbolic methods for efficient mutation testing (work in progress) ebastien Bardin CEA-LIST, Laboratoire de Sˆ uret´ e Logicielle Paris area, France joint work with Fran¸cois Cheynier Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 1/ 27

Transcript of Symbolic methods for efficient mutation testing (work in progress)

Page 1: Symbolic methods for efficient mutation testing (work in progress)

Symbolic methods for efficient mutation testing

(work in progress)

Sebastien Bardin

CEA-LIST, Laboratoire de Surete LogicielleParis area, France

joint work with Francois Cheynier

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 1/ 27

Page 2: Symbolic methods for efficient mutation testing (work in progress)

Starting point

Dynamic Symbolic Execution [sage, pex, klee, pathcrawler, osmose, . . . ]

X very powerful approach to (white box) test generation

× but tools often target very basic coverage criteria(instructions, decisions)

Mutation coverage criterion

X very powerful coverage criterion

× but lacks automation

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 2/ 27

Page 3: Symbolic methods for efficient mutation testing (work in progress)

Two main goals

Use symbolic methods to automate mutation testing

test data generation

equivalent mutant detection

efficient mutant-coverage computation [not so easy with mutants]

Leverage DSE methods to more powerful coverage criteria

Approach : try to reuse symbolic tools in a blackbox manner

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 3/ 27

Page 4: Symbolic methods for efficient mutation testing (work in progress)

Current results

identify which part of (weak) mutations can be efficientlyautomated

leverage DSE to mutation testing (blackbox)

◮ need careful instrumentation and incremental use of DSE◮ achieve high-level mutation coverage with reasonable overhead

[on a few examples]

explore other sources of automation :

◮ very efficient mutant-coverage computation (low overhead)◮ effective detection of equivalent mutants

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 4/ 27

Page 5: Symbolic methods for efficient mutation testing (work in progress)

Outline

Introduction

Mutation testing

From mutants to programs with labels

DSE and mutants

Other results

Conclusion

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 5/ 27

Page 6: Symbolic methods for efficient mutation testing (work in progress)

Mutation testing in a nutshell

Mutant M = syntactic modification of program P

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 6/ 27

Page 7: Symbolic methods for efficient mutation testing (work in progress)

Mutation testing in a nutshell

Mutant M = syntactic modification of program PCovering M = finding a DT t such that P(t) 6= M(t)

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 6/ 27

Page 8: Symbolic methods for efficient mutation testing (work in progress)

Difficulties for automation

Automatic mutant coverage

have to reason on two different traces on two (slighty)different programs

quite far from usual invariance / reachability problems

Efficient mutant-coverage computation (wrt. test set T )

|M| compilations and |T | × (|M|+ 1) executions

// standard D-coverage : 1 compilation, |T | executions

Problem of equivalent mutants

cannot be distinguished from P

waste ressources trying to cover them

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 7/ 27

Page 9: Symbolic methods for efficient mutation testing (work in progress)

Weak mutations

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 8/ 27

Page 10: Symbolic methods for efficient mutation testing (work in progress)

Weak mutations

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 8/ 27

Page 11: Symbolic methods for efficient mutation testing (work in progress)

Weak mutations

empirically : almost as powerful as strong mutations

weak mutant coverage looks like predicate reachability

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 8/ 27

Page 12: Symbolic methods for efficient mutation testing (work in progress)

Outline

Introduction

Mutation testing

From mutants to programs with labels

DSE and mutants

Other results

Conclusion

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 9/ 27

Page 13: Symbolic methods for efficient mutation testing (work in progress)

From weak mutants to labels

Push forward the (weak mutant ↔ predicate reachability) analogy

Hope = reuse verification tools for mutation testing

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 10/ 27

Page 14: Symbolic methods for efficient mutation testing (work in progress)

From weak mutants to labels

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 10/ 27

Page 15: Symbolic methods for efficient mutation testing (work in progress)

From weak mutants to labels (2)

A few definitions

label l = pair (loc , pred)

program with label = < P , L >, with L a set of labels

a test data t covers l : P(t) reaches loc and satisfies pred

TS |=C P denotes ”TS fully covers criterion C on P”

Theorem

For all program P and side-effect free mutation operator op, wecan deduce an annotated program < P , L > such that :for any test set TS, TS |=L P iff TS |=M(op) P

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 11/ 27

Page 16: Symbolic methods for efficient mutation testing (work in progress)

A systematic transformation

Mutation inside a statement

lhs := e 7→ lhs := e’

add label : e 6= e′

Mutation inside a decision

if (cond) ... 7→ if (cond’) ...

add label : cond ⊕ cond ′

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 12/ 27

Page 17: Symbolic methods for efficient mutation testing (work in progress)

A systematic transformation (2)

We can use simpler transformations in many cases

x 7→ -x : add label x 6= 0

x+y 7→ x-y : add label y 6= 0

x >= y 7→ x > y : add label x = y

...

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 13/ 27

Page 18: Symbolic methods for efficient mutation testing (work in progress)

Labels and weak mutations

Strong analogies

Weak mutant ←→ LabelWeakly killed (covered) mutant ←→ Covered label

Mutation score ←→ Label coverage rateEquivalent mutant ←→ Uncoverable labels

But label coverage is easier to automatize

≈ predicate reachability

instrumentation + reuse of verification tools

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 14/ 27

Page 19: Symbolic methods for efficient mutation testing (work in progress)

Toward automatic mutation testing

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 15/ 27

Page 20: Symbolic methods for efficient mutation testing (work in progress)

Toward automatic mutation testing

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 15/ 27

Page 21: Symbolic methods for efficient mutation testing (work in progress)

Direct instrumentation

covering label p ≡ covering branch True

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 16/ 27

Page 22: Symbolic methods for efficient mutation testing (work in progress)

Outline

Introduction

Mutation testing

From mutants to programs with labels

DSE and mutants

Other results

Conclusion

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 17/ 27

Page 23: Symbolic methods for efficient mutation testing (work in progress)

Direct instrumentation is not good enough

• Launch the PathCrawler tool (PC) on a few instrumented P’

• Compare with speed of PC launch on P

PC on P PC on P’(basic) (instrumentation)

Trityp50 LOC141 labels

0 s14TC

100%466 s

63TC

Replace100 LOC79 labels

2 s121TC

98%1 745 s275TC

TCas124 LOC111 labels

4 s164TC

96%228 767 s249TC

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 18/ 27

Page 24: Symbolic methods for efficient mutation testing (work in progress)

Direct instrumentation is not good enough

• Launch the PathCrawler tool (PC) on a few instrumented P’

• Compare with speed of PC launch on P

PC on P PC on P’(basic) (instrumentation)

Trityp50 LOC141 labels

0 s14TC

100%466 s

63TC

Replace100 LOC79 labels

2 s121TC

98%1 745 s275TC

TCas124 LOC111 labels

4 s164TC

96%228 767 s249TC

X Achieve high mutation coverage

× Very significant overhead ! ! !

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 18/ 27

Page 25: Symbolic methods for efficient mutation testing (work in progress)

Direct instrumentation is not good enough (2)

P’ has exponentially more paths than P

Paths in P’ are much more more complex than needed

at each “label”, an execution σ is required to cover p or ¬p

an execution σ1σ2 . . . σn in P can becomeσ1(l1)σ2(¬l2) . . . (ln)σn in P’

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 19/ 27

Page 26: Symbolic methods for efficient mutation testing (work in progress)

Direct instrumentation is not good enough (2)

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 19/ 27

Page 27: Symbolic methods for efficient mutation testing (work in progress)

Direct instrumentation is not good enough (2)

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 19/ 27

Page 28: Symbolic methods for efficient mutation testing (work in progress)

Optim 1 : smarter instrumentation

X Paths in P” have at most one “label constraint”

X P” has exponentially less paths than P’

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 20/ 27

Page 29: Symbolic methods for efficient mutation testing (work in progress)

Optim 1 : smarter instrumentation

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 20/ 27

Page 30: Symbolic methods for efficient mutation testing (work in progress)

Optim 1 : smarter instrumentation

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 20/ 27

Page 31: Symbolic methods for efficient mutation testing (work in progress)

Optim 1 : smarter instrumentation

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 20/ 27

Page 32: Symbolic methods for efficient mutation testing (work in progress)

Optim 2 : incremental DSE

Observations

we need to cover each label only once

yet, already covered labels “stay in place” in P’

◮ burden the DSE tool with “useless” paths

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 21/ 27

Page 33: Symbolic methods for efficient mutation testing (work in progress)

Optim 2 : incremental DSE

Observations

we need to cover each label only once

yet, already covered labels “stay in place” in P’

◮ burden the DSE tool with “useless” paths

Our approach : incremental DSE

Partition labels into disjoint sets L1, ..., Lk

Choose a set Lk

Launch PathCrawler on < P , Lk >

when terminates :

◮ get the generated test set TS◮ prune from all Li the labels covered by TS

loop forall Li

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 21/ 27

Page 34: Symbolic methods for efficient mutation testing (work in progress)

Results

PC on P PC on P’ PC on P”(basic) (direct) (smart)

Trityp50 LOC141 labels

0 s14TC

100%466 s

63TC

100%1 s

84TC

Replace100 LOC79 labels

2 s121TC

98%1 745 s275TC

100%50 s

393TC

TCas124 LOC111 labels

4 s164TC

96%228 767 s249TC

100%72 s

1 049TC

X higher mutation coverage

X significant speedup wrt. direct instrumentation

• yet, significant overhead (20x) wrt. uninstrumented version

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 22/ 27

Page 35: Symbolic methods for efficient mutation testing (work in progress)

Outline

Introduction

Mutation testing

From mutants to programs with labels

DSE and mutants

Other results

Conclusion

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 23/ 27

Page 36: Symbolic methods for efficient mutation testing (work in progress)

Coverage computation

• use Emma (decision coverage) and MuJava (mutation score)• 100 tests

Emma MuJavaP

(witness)P’ P + M

TCas124 LOC111 labels

0,03 s 0,03 s 5 s

Replace436 LOC607 labels

0,05 s 0,10 s 40 s

Jtopas5400 LOC610 labels

3,22 s 11,72 s 1 400 s

Results

significant speed-up (x40 - x100)

very reasonable overhead (x1 - x4)

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 24/ 27

Page 37: Symbolic methods for efficient mutation testing (work in progress)

Detection of uncoverable labels ( ≈ equiv. mutants)

We use the Frama-C framework to detect uncoverable labels

Value Analysis plugin (VA)

restricted logical reasoning (L) [ad hoc plugin]

# labels Categories of uncoveredtotal uncovered VA L M Unknown

Trityp 141 6 4 0 2 0TCas 111 13 6 3 4 0Replace 79 12 11 1 0 0

VA (resp. L) : # labels proved uncoverable through VA (resp. L)

M : # labels manually proved uncoverable

Results [direct instrumentation]

good detection rate (0.6 - 1) with generic-purpose analysis

can probably be improved

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 25/ 27

Page 38: Symbolic methods for efficient mutation testing (work in progress)

Outline

Introduction

Mutation testing

From mutants to programs with labels

DSE and mutants

Other results

Conclusion

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 26/ 27

Page 39: Symbolic methods for efficient mutation testing (work in progress)

Conclusion & future work

A subtantial subset of weak mutations can be reduced to predicatereachability

Allow to reuse the whole (symbolic) “verification machinery”

We have shown first encouraging expriments for

automatic test generation with high mutation score

automatic discovery of equivalent mutants

efficient coverage measurement

Future work

more experiments

native support for labels in PathCrawler (goal = low overhead)

dedicated mutant equivalence checking plugin in Frama-C ?

Bardin, Cheynier Symbolic methods for efficient mutation testing (work in progress) 27/ 27