Automated Fixing of Programs with Contracts Yi Wei, Yu Pei, Carlo - - PowerPoint PPT Presentation

automated fixing of programs with contracts
SMART_READER_LITE
LIVE PREVIEW

Automated Fixing of Programs with Contracts Yi Wei, Yu Pei, Carlo - - PowerPoint PPT Presentation

Automated Fixing of Programs with Contracts Yi Wei, Yu Pei, Carlo A. Furia, Lucas S. Silva, Stefan Buchholz, Bertrand Meyer, Andreas Zeller Presented by Christine Zeller Motivation Programming is not just about writing code Find errors


slide-1
SLIDE 1

Automated Fixing of Programs with Contracts

Yi Wei, Yu Pei, Carlo A. Furia, Lucas S. Silva, Stefan Buchholz, Bertrand Meyer, Andreas Zeller

Presented by Christine Zeller

slide-2
SLIDE 2

Motivation

 Programming is not just about writing code

 Find errors  Fix errors

 Automating these steps is helpful

 Automatic testing tools help finding errors  What about fixing them?

2

slide-3
SLIDE 3

Background

3

 AutoTest

  • B. Meyer, A. Fiva, I. Ciupa, A. Leitner, Y. Wei, E. Stapf (2009)

 Automated Testing Framework  Paper will be presented in this seminar

 Pachika

V.Dallmeier, A. Zeller, B.Meyer (2009)

 Tool to generate potential fixes for bugs  Used with failing testcases for Java Programs

slide-4
SLIDE 4

AutoFix-E

4

 Find fixes using

 Contracts  Boolean Query Abstraction

 Plan:

 1) Assess Object State  2) Construct Fault Profile and Behavioral Model  3) Generate Candidate Fixes  4) Validate Fixes

slide-5
SLIDE 5

Example

5

 TWO_WAY_SORTED_SET

duplicate(n: INTEGER):like Current local pos: CURSOR counter: INTEGER do pos := cursor Result := new_chain Result.finish Result.forth from until (counter = n) or else after loop Result.put_left(item) forth counter := counter + 1 end go_to(pos) end

item has precondition not before and not after

slide-6
SLIDE 6

Workflow

6

Eiffel Class Test Suite AutoTest Fault Profile Behavioral Model Candidate Fixes Valid Fixes non-valid fixes AutoFix-E

slide-7
SLIDE 7

Object State

7

 Predicate set P

 Boolean queries  Complex predicates (implications)  Mutations of complex predicates

 Collection Π = P ∪ not p p ∈ 𝑄  Remove redundancies in P using Z3

is_empty  after A  B ¬ A  B ¬ A  ¬ B A  ¬ B

slide-8
SLIDE 8

Fault Profile

8

 State invariant  Consider all passing runs

 Infer state invariant 𝐽ℓ

+ for each location ℓ

 Consider all failing runs

 Infer state invariant 𝐽ℓ

− for each location ℓ

 Only up to location of failure

𝐽ℓ = 𝑞 𝑞 ∈ Π ∧ 𝑞 ℎ𝑝𝑚𝑒𝑡 𝑏𝑢 𝑚𝑝𝑑𝑏𝑢𝑗𝑝𝑜 ℓ

slide-9
SLIDE 9

Fault Profile: Example

9

 Construct fault profile

 Use tool called Daikon

 Example:

Φℓ = 𝑞 𝑞 ∈ 𝐽ℓ

+ ∧ 𝑞 ∉ 𝐽ℓ − before and off before implies not off hold only in failing runs Fault Profile

slide-10
SLIDE 10

Behavioral Model

10

 Finite-state automaton representing class’ behaviour  Extract model from passing runs  Idea

pre state post state routine m Failed state Fixed state Sequence

  • f mutators
slide-11
SLIDE 11

Behavioral Model: Example

11

is_empty before not after is_empty not before after forth not is_empty before not after not is_empty not before not after forth

slide-12
SLIDE 12

Candidate Fixes

12

 Put everything together  Predefined templates:

(a) snippet

  • ld_stmt

(b) if fail then snippet end

  • ld_stmt

(c) if not fail then

  • ld_stmt

end (d) if fail then snippet else

  • ld_stmt

end

slide-13
SLIDE 13

Candidate Fixes: Example

13

duplicate(n: INTEGER):like Current ... from until (counter = n) or else after loop Result.put_left(item) forth counter := counter + 1 end go_to(pos) end

slide-14
SLIDE 14

Candidate Fixes: Example

14

duplicate(n: INTEGER):like Current ... from until (counter = n) or else after loop if before then forth else Result.put_left(item) forth counter := counter + 1 end end go_to(pos) end

snippet

slide-15
SLIDE 15

Fix Validation

15

 Run all testcases on fixes

 A fix is valid if it passes all failing and passing runs

 Additionally: Ranking

 Static metrics

 Textual change  Branches introduced

 Dynamic metrics

 Runtime behaviour

slide-16
SLIDE 16

Improvement

16

 Linearly constrained assertions

 E.g.  Require special techniques for fix generation  Specific schema for candidate fixes i > 1 and i < count if not constraint then new_stmt else old_stmt end

slide-17
SLIDE 17

Experimental Evaluation

17

 42 Faults from EiffelBase and Gobo  Average fixing time: 2.6 minutes  Small study with programmers

 4 of 6 proposed valid fixes were same as programmers’

slide-18
SLIDE 18

Future Work

18

 Improve behavior model  Different fault types  Find faults in contracts  Languages without contracts  Improving ranking metric  ...

slide-19
SLIDE 19

Conclusion

19

 Limitation: all classes used data structure related  Status from 2010

 New Version of AutoFix developed in 2011  Different approach: code-based instead of model-based

 Still an open field of research