Software Engineering
- Prof. Dr. Bertrand Meyer
March 2007 – June 2007
Chair of Softw are Engineering
Static program checking and verification
Slides: Based on KSE06 – With kind permission of Peter Müller
Static program checking and verification Correctness class ArraySet - - PowerPoint PPT Presentation
Chair of Softw are Engineering Software Engineering Prof. Dr. Bertrand Meyer March 2007 June 2007 Slides: Based on KSE06 With kind permission of Peter Mller Static program checking and verification Correctness class ArraySet
March 2007 – June 2007
Chair of Softw are Engineering
Slides: Based on KSE06 – With kind permission of Peter Müller
Software Engineering, lecture 20: Static program checking and verification 2
class ArraySet implements Set { private int[ ] array; private int next; … public void insert( int i ) { for ( int j = 0; j < next; j-- ) if array[ j ] == i then return true; return false; } } class ArraySet implements Set { private int[ ] array; private int next; … public void insert( int i ) { for ( int j = 0; j < next; j-- ) if array[ j ] == i then return true; return false; } } class ArraySet implements Set { private int[ ] array; private int next; … public void insert( int i ) { for ( int j = 0; j < next; j-- ) if array[ j ] == i then return true; return false; } } class ArraySet implements Set { private int[ ] array; private int next; … public void insert( int i ) { for ( int j = 0; j < next; j-- ) if array[ j ] == i then return true; return false; } } class ArraySet implements Set { private int[ ] array; private int next; … public void insert( int i ) { for ( int j = 0; j < next; j-- ) if array[ j ] == i then return true; return false; } }
Software Engineering, lecture 20: Static program checking and verification 3
Software Engineering, lecture 20: Static program checking and verification 4
Detect bugs
White box test Black box test
Successful test does not
Prove correctness
Formal verification based
Symbolic execution
Expensive Formal specification of
Software Engineering, lecture 20: Static program checking and verification 5
Software Engineering, lecture 20: Static program checking and verification 6
Absence of runtime exceptions and common mistakes
e.g. null dereference, array bounds, type cast errors, deadlocks
Simple user-specified contracts
invariants, pre/postconditions, loop invariants, assertions
Program with Program with specifications specifications Error Error messages messages
Bag.java:18: Array index possibly too large
Software Engineering, lecture 20: Static program checking and verification 7
Fully automated reasoning As little annotation overhead as possible Performance
Errors may be missed
Warnings do not always report errors (false alarms)
Cost-effective tool Find source of possible bugs quickly
Software Engineering, lecture 20: Static program checking and verification 8
Translator Translator Annotated Java program Annotated Java program Verification condition Verification condition Counterexample context Counterexample context Warning messages Warning messages Automatic Theorem Prover Automatic Theorem Prover Post Processor Post Processor
Valid Resource exhausted
Software Engineering, lecture 20: Static program checking and verification 9
If this is possible, a counterexample is found, and we
If it fails to satisfy ¬ϕ then ϕ is considered to be
Software Engineering, lecture 20: Static program checking and verification 10
Each procedure that proves all valid formulas loops
When time limit is reached, counterexample is
Longer computation might show that returned
Spurious counterexamples lead to spurious warnings
Software Engineering, lecture 20: Static program checking and verification 11
Software Engineering, lecture 20: Static program checking and verification 12
non-null types pre- and postconditions
more type checking compiler-emitted run-time checks static program verification fully integrated into Visual Studio .NET 2005
type checking static verification run-time checks degree of checking, effort into the future C# contracts everywhere
Software Engineering, lecture 20: Static program checking and verification 13
Architecture Full automation (even theorem prover is the same) Essential contract language
Spec# is sound Spec# does modular reasoning
Software Engineering, lecture 20: Static program checking and verification 14
Software Engineering, lecture 20: Static program checking and verification 15
Software Engineering, lecture 20: Static program checking and verification 16
Software Engineering, lecture 20: Static program checking and verification 18
Flanagan et al.: Extended Static Checking for Java
http://secure.ucd.ie/products/opensource/ESCJava2
Barnett et al.: Boogie: A Modular Reusable Verifier for
Object-Oriented Programs
http://research.microsoft.com/specsharp
http://research.microsoft.com/~leino/talks.html