Lukas Schwab lschwab@student.ethz.ch April 28th 2009
Dynamic Symbolic Execution for Invariant Inference
Seminar in Software Engineering
DySy Dynamic Symbolic Execution for Invariant Inference April 28th - - PowerPoint PPT Presentation
Seminar in Software Engineering DySy Dynamic Symbolic Execution for Invariant Inference April 28th 2009 Lukas Schwab lschwab@student.ethz.ch The authors Christoph Csallner - College of Computing, Georgia Tech Nikolai Tillmann -
Lukas Schwab lschwab@student.ethz.ch April 28th 2009
Dynamic Symbolic Execution for Invariant Inference
Seminar in Software Engineering
2
3
from someone
to know
(1) preconditions (2) postconditions (3) class invariants
int foo(int x, int y) { int prod = x*y; if (prod <= 0) throw new Exception(); if (x < y) { int tmp = x; x = y; y = tmp; } int sqry = y*y; return prod - sqry; }
(1) (2)
4
Input
Output
Invariants = {preconditions, postconditions, class invariants}
Source code Test suite Dynamic invariant inference system Invariants
invariant inference system
invariant templates, e.g.
5
6
invariants which evaluate to false
f(x) = 2*x = r f(x) = 2*x = r
Postconditions (fr
Input x Result r Constant Order Linear
Inferred postcondition: r = 2*x
1 f(1) = 2 r = 2 r > x r = 2*x + 0 2 f(2) = 4 r = 2 r > x r = 2*x + 0
f(-3) = -6 r > x r = 2*x + 0
7
concrete values
properties which the input must satisfy in
particular associated path.“
8
9
int foo(int x, int y) { int prod = x*y; if (prod <= 0) throw new Exception(); if (x < y) { int tmp = x; x = y; y = tmp; } int sqry = y*y; return prod - sqry; }
1 2 3
Value alue Variable Concrete Symbolic
x 3
2
6 x*y sqry 4 y*y result 2 x*y - y*y 2 x*y > 0 3 x*y > 0 ∧ x >= y
Pos Path condition
1 True
system
simultaneously with its concrete execution.
and the result
10
int foo(int x, int y) { int prod = x*y; if (prod <= 0) throw new Exception(); if (x < y) { int tmp = x; x = y; y = tmp; } int sqry = y*y; return prod - sqry; }
Input x=3, y=2 Path condition x*y>0 ∧ x>=y Result x*y - y*y Input x=2, y=3 Path condition x*y>0 ∧ x<y Result x*y - x*x
11
Postcondition: if (x*y>0 ∧ x>=y) x*y - y*y else if (x*y>0 ∧ x<y) x*y - x*x Precondition: (x*y>0 ∧ x>=y) ∨ (x*y>0 ∧ x<y)
int foo(int x, int y) { int prod = x*y; if (prod <= 0) throw new Exception(); if (x < y) { int tmp = x; x = y; y = tmp; } int sqry = y*y; return prod - sqry; }
Input x=3, y=2 Path condition x*y>0 ∧ x>=y Result x*y - y*y Input x=2, y=3 Path condition x*y>0 ∧ x<y Result x*y - x*x
12
Postcondition: if (x>=y) x*y - y*y else x*y - x*x Precondition: x*y>0
13
execution
steps
„array.IsEmpty“
14
implied by all final path conditions.
15
result under that PC on the right
simplify
16
Postcondition = (PC1 ⇒ Result1) ∧ (PC2 ⇒ Result2) ∧ … Precondition = PC1 ∨ PC2 …
PC = Path Condition
17
public int linSearch(int ele, int[] arr) { for (int i = 0; i < arr.Length; i++) { if (ele == arr[i]) return i; } return -1; //Not found } arr.Length == 3 && ele != arr[0] && ele != arr[1] && ele != arr[2]
variable ➟ $i
18
by human user
19
20
Goal Recognized in Recognized inv Goal inv Daikon DySy
Invariant 5 5 4 Constructor 3 3 2 push 4 2 (4) 2 (4) top 3 1 (3) 2 (3) topAndPop 4 2 (4) 2 (4) isEmpty 3 2 (3) 3 isFull 3 2 (3) 3 makeEmpty 2 2 2 Total 27 19 (27) 20 (25)
Relaxed count (Ignores deep equality of objects)
21
expressions are common across methods
infers to many invariants
Unique sub-expr Unique sub-expr Unique sub-expr Goal Daikon DySy
Invariant 26 26 16 Constructor 17 24 17 push 28 69 43 top 14 81 25 topAndPop 21 145 50 isEmpty 9 53 9 isFull 13 45 13 makeEmpty 5 47 22 Total 89 316 133
22
invariants well
for the bank account example [See slide 25]
console, generated output hard to read
23
24
25
public class BankAccount { private int _balance; public BankAccount() { _balance = 0; } public int Balance { get { return _balance; } } public void Deposit(int amount) { Balance += amount; } public void Withdraw(int amount) { if (Balance < amount) { throw new Exception("Not enough money"); } Balance -= amount; } }