automating regression verification
play

Automating Regression Verification Dennis Felsing , Sarah Grebing, - PowerPoint PPT Presentation

Automating Regression Verification Dennis Felsing , Sarah Grebing, Vladimir Klebanov, Mattias Ulbrich, Philipp R ummer 2014-07-23 1 / 16 Introduction How to prevent regressions in software development? 2 / 16 Introduction How to prevent


  1. Automating Regression Verification Dennis Felsing , Sarah Grebing, Vladimir Klebanov, Mattias Ulbrich, Philipp R¨ ummer 2014-07-23 1 / 16

  2. Introduction How to prevent regressions in software development? 2 / 16

  3. Introduction How to prevent regressions in software development? Formal Verification Formally prove correctness of software ⇒ Requires formal specification Regression Testing Discover new bugs by testing for them ⇒ Requires test cases 2 / 16

  4. Introduction How to prevent regressions in software development? Formal Verification Formally prove correctness of software ⇒ Requires formal specification Regression Testing Discover new bugs by testing for them ⇒ Requires test cases Regression Verification Formally prove there are no new bugs 2 / 16

  5. Regression Verification Formally prove there are no new bugs • Goal: Proving the equivalence of two closely related programs • No formal specification or test cases required • Instead use old program version as reference • Tools for proving function equivalence in a simple programming language using SMT solvers 3 / 16

  6. Overview 1 Overapproximation using Uninterpreted Functions 2 Approximation using Uninterpreted Predicates 3 Results and Future Work 4 / 16

  7. Overview 1 Overapproximation using Uninterpreted Functions 2 Approximation using Uninterpreted Predicates 3 Results and Future Work 5 / 16

  8. Function Equivalence Existing approach by Strichman & Godlin Equivalent? Function f Function g (val n 1 ; ret r 1 ) (val n 2 ; ret r 2 ) Uninterpreted Function U for recursive calls in both f and g Function f Function g without recursion without recursion Static Single Static Single Assignment S f Assignment S g ( n 1 = n 2 ∧ S f ∧ S g ) → r 1 = r 2 SMT Solver Valid / Invalid 6 / 16

  9. Our Contribution: Extensions Equivalent? Function f Function g (val n 1 ; ret r 1 ) (val n 2 ; ret r 2 ) S f S g Single Static Assignment Form ( n 1 = n 2 ∧ S f ∧ S g ) → r 1 = r 2 SMT Solver Valid / Invalid 7 / 16

  10. Our Contribution: Extensions Equivalent? Function f Function g (val n 1 ; ret r 1 ) (val n 2 ; ret r 2 ) S f S g Single Static Assignment Form ( n 1 = n 2 ∧ S f ∧ S g ) → r 1 = r 2 SMT Solver Valid / Invalid Equivalent! 7 / 16

  11. Our Contribution: Extensions Equivalent? Function f Function g (val n 1 ; ret r 1 ) (val n 2 ; ret r 2 ) S f S g Single Static Assignment Form ( n 1 = n 2 ∧ S f ∧ S g ) → r 1 = r 2 SMT Solver Valid / Invalid Equivalent! Counterexample: r 1 = − 1 n = 0: r 2 = − 3 7 / 16

  12. Our Contribution: Extensions Equivalent? Function f Function g (val n 1 ; ret r 1 ) (val n 2 ; ret r 2 ) S f S g Single Static Assignment Form ( n 1 = n 2 ∧ S f ∧ S g ) → r 1 = r 2 SMT Solver f (0) = g (0) = 0 Valid / Invalid Execute Equivalent! Counterexample: r 1 = − 1 n = 0: r 2 = − 3 7 / 16

  13. Our Contribution: Extensions Equivalent? Function f Function g (val n 1 ; ret r 1 ) (val n 2 ; ret r 2 ) S f S g Single Static Assignment Form ( n 1 = n 2 ∧ S f ∧ S g ∧ U (0) = 0 ) → r 1 = r 2 Add rerun SMT Solver f (0) = g (0) = 0 Valid / Invalid Execute Equivalent! Counterexample: r 1 = − 1 n = 0: r 2 = − 3 7 / 16

  14. Overapproximation using uninterpreted functions Approach • Run the programs with input gathered from counterexamples • Detect whether CE is spurious or not • If spurious: Add additional constraints to the uninterpreted function ⇒ Is a simple form of Counter Example Guided Abstraction Refinement (CEGAR) Successful when • Finite number of constraints on the uninterpreted function imply equivalence • These are often the “base cases” of recursive implementations 8 / 16

  15. Overview 1 Overapproximation using Uninterpreted Functions 2 Approximation using Uninterpreted Predicates 3 Results and Future Work 9 / 16

  16. Approximation using Uninterpreted Predicates First approach (just shown) • Overapproximate recursion by uninterpreted Function U : ∀ U . constraints ( U ) ∧ S f ∧ S g ∧ ... → r 1 = r 2 New approach • Infer a predicate C which couples recursive calls: ∃ C . ( C ( ... ) ∧ ... → r 1 = r 2 ) ∧ “ C couples f and g ” • Use state-of-the-art SMT solvers (Eldarica, Z3) to automatically find such a C or prove that is does not exist ⇒ Example will show loops with coupling loop invariants 10 / 16

  17. Automatic Invariant Inference int f1 ( int n) { r = 0; int (n == 0) 1; i f return (n > 0) { while n /= 10; r++; } r ; return } 11 / 16

  18. Automatic Invariant Inference int f1 ( int n) { int f2 ( int n) { r = 0; r = 1; int int (n == 0) 1; i f return (n > 0) { ( true ) { while while n /= 10; r++; i f (n < 10) r ; return i f (n < 100) r +1; return i f (n < 1000) r +2; return i f (n < 10000) r +3; return } n /= 10000; r ; r += 4; return } } } 11 / 16

  19. Automatic Invariant Inference Loop synchronisation • To show: Equal input f1 f2 gives equal output 12 / 16

  20. Automatic Invariant Inference Loop synchronisation • To show: Equal input = f1 f2 gives equal output = 12 / 16

  21. Automatic Invariant Inference Loop synchronisation • To show: Equal input = f1 f2 gives equal output • Loops are synchronised = 12 / 16

  22. Automatic Invariant Inference Loop synchronisation • To show: Equal input = f1 f2 gives equal output • Loops are synchronised = = 12 / 16

  23. Automatic Invariant Inference Loop synchronisation • To show: Equal input = f1 f2 gives equal output • Loops are synchronised • ... at least loosely = synchronised = 12 / 16

  24. Automatic Invariant Inference Loop synchronisation • To show: Equal input = f1 f2 gives equal output • Loops are synchronised • ... at least loosely synchronised C = 12 / 16

  25. Automatic Invariant Inference Loop synchronisation • To show: Equal input = f1 f2 gives equal output • Loops are synchronised • ... at least loosely synchronised C ⇒ Use C as loop invariant for both programs. = ( → coupling invariant ) 12 / 16

  26. Automatic Invariant Inference Loop synchronisation • To show: Equal input = f1 f2 gives equal output • Loops are synchronised • ... at least loosely synchronised C ⇒ Use C as loop invariant for both programs. = ( → coupling invariant ) 12 / 16

  27. Automatic Invariant Inference Loop synchronisation • To show: Equal input = f1 f2 gives equal output • Loops are synchronised • ... at least loosely C synchronised ⇒ Use C as loop invariant for both programs. ( → coupling invariant ) 12 / 16

  28. Automatic Invariant Inference Loop synchronisation • To show: Equal input = f1 f2 gives equal output • Loops are synchronised • ... at least loosely C synchronised C ⇒ Use C as loop invariant for both programs. ( → coupling invariant ) 12 / 16

  29. Automatic Invariant Inference Loop synchronisation • To show: Equal input = f1 f2 gives equal output • Loops are synchronised • ... at least loosely C synchronised C ⇒ Use C as loop invariant C for both programs. ( → coupling invariant ) = 12 / 16

  30. Automatic Invariant Inference Loop synchronisation • To show: Equal input = f1 f2 gives equal output • Loops are synchronised • ... at least loosely C synchronised C ⇒ Use C as loop invariant C for both programs. ( → coupling invariant ) = Automatic Regression Verification: Do not specify C but infer it automatically. 12 / 16

  31. Automatic Invariant Inference Three cases to consider: 1 Initially coupling loop invariant C holds 2 After both loop steps (or one if other finished), C holds 3 After both loops finished, C implies equality of results 13 / 16

  32. Automatic Invariant Inference Three cases to consider: 1 Initially coupling loop invariant C holds 2 After both loop steps (or one if other finished), C holds 3 After both loops finished, C implies equality of results Automatically inferred coupling loop invariant: (Using Eldarica) ( n 1 > 0 → ( n 1 = n 2 ∧ r 1 + 1 = r 2 )) ∧ ( n 2 ≤ 0 → return 2 = r 1 ) ∧ n 1 ≥ n 2 13 / 16

  33. Automatic Invariant Inference Three cases to consider: 1 Initially coupling loop invariant C holds 2 After both loop steps (or one if other finished), C holds 3 After both loops finished, C implies equality of results Automatically inferred coupling loop invariant: (Using Eldarica) ( n 1 > 0 → ( n 1 = n 2 ∧ r 1 + 1 = r 2 )) ∧ ( n 2 ≤ 0 → return 2 = r 1 ) ∧ n 1 ≥ n 2 • Compare to loop invariant: n = n 0 10 r • Coupling invariant is not trivial, but linear and inferable! 13 / 16

  34. Overview 1 Overapproximation using Uninterpreted Functions 2 Approximation using Uninterpreted Predicates 3 Results and Future Work 14 / 16

  35. Evaluation and Results Approaches implemented for a subset of C: simplRV, Rˆ eve Usable with webinterface: http://formal.iti.kit.edu/ improve/deduktionstreffen2014/ Rˆ eve evaluation (uninterpreted predicates) • 32 short benchmarks of integer programs (10-50 lines) • Collected from literature • Good performance on most equivalent programs • Finds counterexample for non-equivalent programs as well 15 / 16

  36. Conclusion Regression Verification • Initial approach limited to strongly coupled recursions or user feedback • Automatic Invariant Inference: More powerful, using recent techniques in SMT solvers like Eldarica and Z3 Future Work • More examples (larger) • Support arrays, heaps, objects 16 / 16

Recommend


More recommend