WISE: Automated Test Generation for Worst-Case Complexity Jacob - - PowerPoint PPT Presentation

wise automated test generation for worst case complexity
SMART_READER_LITE
LIVE PREVIEW

WISE: Automated Test Generation for Worst-Case Complexity Jacob - - PowerPoint PPT Presentation

WISE: Automated Test Generation for Worst-Case Complexity Jacob Burnim Sudeep Juvekar Koushik Sen Performance-Directed Testing Automated tested has focused on correctness bugs. Goal: Apply to software performance. Find performance


slide-1
SLIDE 1

WISE: Automated Test Generation for Worst-Case Complexity

Jacob Burnim Sudeep Juvekar Koushik Sen

slide-2
SLIDE 2

Performance-Directed Testing

 Automated tested has focused on

correctness bugs.

 Goal: Apply to software performance.

 Find performance bottlenecks.  Security: Algorithmic denial-of-service.

 Today: Computational complexity testing.

 How slow is an operation in the worst case?  Does a function meet its algorithmic

complexity spec?

slide-3
SLIDE 3

Performance-Directed Testing

 Example: Performance bug in Jar

 Reported by Sun on May 15, 2009  update method O(N2) instead of O(N)  O(N) look-up on every file, rather than O(1)  wasted 75% of run-time building rt.jar

slide-4
SLIDE 4

Goal of WISE

 Worst-case Inputs from Symbolic Execution

Input

InsertionSort() Input Size: N

// insertion sort for(i = 0 .. N-1) for(j = i .. 1)

if (A[j] < A[j-1]) swap(A[j], A[j-1]) else break

Size: N

slide-5
SLIDE 5

Goal of WISE

 Worst-case Inputs from Symbolic Execution

Input Output

InsertionSort() Input Size: N 1: 1 2: 2 1 3: 3 2 1 N: N … 2 1

// insertion sort for(i = 0 .. N-1) for(j = i .. 1)

if (A[j] < A[j-1]) swap(A[j], A[j-1]) else break

WISE …

Size: N

slide-6
SLIDE 6

Worst-Cast Empirical Complexity

100 200 300 3 6 9 12 15

# Basic Blocks Input Size 5 4 3 2 1

slide-7
SLIDE 7

Worst-Cast Empirical Complexity

100 200 300 3 6 9 12 15

# Basic Blocks Input Size 10 9 … 2 1

slide-8
SLIDE 8

Worst-Cast Empirical Complexity

100 200 300 3 6 9 12 15

# Basic Blocks Input Size 15 14 … 2 1

slide-9
SLIDE 9

Worst-Cast Empirical Complexity

100 200 300 3 6 9 12 15

# Basic Blocks Input Size

N2 + N - 1 basic blocks.

slide-10
SLIDE 10

Overview of WISE

 Uses symbolic test generation to explore

possible program executions.

 Widely used in automated software testing.

(DART, CUTE, SAGE, EXE, KLEE, JPF, …)

 Key Idea:

Learn from executions on small inputs.

 In Quicksort, pivot should be smaller than

all elements to which it’s compared.

slide-11
SLIDE 11

Outline

 Motivation + Goal of WISE  Background: Symbolic Test Generation  Naïve Algorithm for Finding Complexity  WISE Algorithm  Evaluation  Conclusions + Future Work

slide-12
SLIDE 12

Symbolic Test Generation

 Goal: A test input for every program path.

f(int x, int y) {

z = 2*x; if (z == x) if (x > y + 8) print(“Hi”)

}

x > y + 8 2*y == x

T F

Computation Tree

T F

slide-13
SLIDE 13

Symbolic Test Generation

 Depth-first search of computation tree.

f(int x, int y) {

z = 2*x; if (z == x) if (x > y + 8) print(“Hi”)

}

x > y + 8 2*y == x

T F

Computation Tree

T F

slide-14
SLIDE 14

2*y == x

Symbolic Test Generation

 Depth-first search of computation tree.

f(int x, int y) {

z = 2*x; if (z == x) if (x > y + 8) print(“Hi”)

}

Φ(path): 2y ≠ x

Input: x = 0, y = 1

x > y + 8

T F T F

x > y + 8 2*y == x

slide-15
SLIDE 15

Symbolic Test Generation

 Depth-first search of computation tree.

f(int x, int y) {

z = 2*x; if (z == x) if (x > y + 8) print(“Hi”)

}

x > y + 8 2*y == x

T F

Φ(path): 2y = x ∧ x ≤ y+8

Input: x = 1, y = 2

T F

x > y + 8 2*y == x

slide-16
SLIDE 16

Symbolic Test Generation

 Depth-first search of computation tree.

f(int x, int y) {

z = 2*x; if (z == x) if (x > y + 8) print(“Hi”)

}

x > y + 8 2*y == x

T F

Φ(path): 2y = x ∧ x > y+8

Input: x = -10, y = -20

T F

x > y + 8 2*y == x

slide-17
SLIDE 17

Symbolic Test Generation

 Depth-first search of computation tree.

f(int x, int y) {

z = 2*x; if (z == x) if (x > y + 8) print(“Hi”)

}

x > y + 8 2*y == x

T F

Φ(path): 2y = x ∧ x > y+8

Input: x = -10, y = -20

T F

x > y + 8 2*y == x

slide-18
SLIDE 18

Outline

 Motivation + Goal of WISE  Background: Symbolic Test Generation  Naïve Algorithm for Finding Complexity  WISE Algorithm  Evaluation  Conclusions + Future Work

slide-19
SLIDE 19

Symbolic Execution for Complexity

 Naïve Algorithm:

 Generate every execution on N inputs.  Return input for longest execution.

slide-20
SLIDE 20

Symbolic Execution for Complexity

 Naïve Algorithm:

N=2:

F F T F

slide-21
SLIDE 21

Symbolic Execution for Complexity

 Naïve Algorithm:

N=2:

F F T F

Longest Execution (4 basic blocks)

slide-22
SLIDE 22

Symbolic Execution for Complexity

 Naïve Algorithm:

N=2:

F F T F

Worst-case Input: 2 1

slide-23
SLIDE 23

Symbolic Execution for Complexity

 Naïve Algorithm:

N=3:

F F T F F T T F F F T T F F

slide-24
SLIDE 24

Symbolic Execution for Complexity

 Naïve Algorithm:

N=3:

F F T F F T T F F F T T F F

Longest Execution (7 basic blocks)

slide-25
SLIDE 25

Symbolic Execution for Complexity

 Naïve Algorithm:

N=3:

F F T F F T T F F F T T F F

Worst-Case Input:

3 2 1

slide-26
SLIDE 26

Symbolic Execution for Complexity

 Naïve Algorithm:

N=3:

F F T F F T T F F F T T F F

Worst-Case Input:

3 2 1

slide-27
SLIDE 27

Path Space Explosion

 Naïve algorithm does not scale.  1.6×1025 paths  Longest has only

121 basic blocks N=15:

slide-28
SLIDE 28

Path Space Explosion

 Naïve algorithm does not scale.  1.6×1025 paths  Longest has only

121 basic blocks N=15:

slide-29
SLIDE 29

Outline

 Motivation + Goal of WISE  Background: Symbolic Test Generation  Naïve Algorithm for Finding Complexity  WISE Algorithm  Evaluation  Conclusions + Future Work

slide-30
SLIDE 30

 Step 1: From executions on small inputs,

learn oracle for longest paths.

Overview of WISE

slide-31
SLIDE 31

 Step 1: From executions on small inputs,

learn oracle for longest paths.

Overview of WISE

F

N=1

F F T F

N=2 N=3

slide-32
SLIDE 32

 Step 1: From executions on small inputs,

learn oracle for longest paths.

Overview of WISE

F

F F T F

N=1 N=2 N=3

slide-33
SLIDE 33

 Step 1: From executions on small inputs,

learn oracle for longest paths.

 Step 2: For large inputs, only examine

paths generated by oracle.

Overview of WISE

F

N=1

F F T F

N=2 N=3

slide-34
SLIDE 34

 Step 1: From executions on small inputs,

learn oracle for longest paths.

 Step 2: For large inputs, only examine

paths generated by oracle.

Overview of WISE

F

N=1 N=15

F F T F

N=2 N=3

slide-35
SLIDE 35

 Step 1: From executions on small inputs,

learn oracle for longest paths.

 Step 2: For large inputs, only examine

paths generated by oracle.

Overview of WISE

F

N=1 N=15

F F T F

N=2 N=3

slide-36
SLIDE 36

 Step 1: From executions on small inputs,

learn oracle for longest paths.

 Step 2: For large inputs, only examine

paths generated by oracle.

Overview of WISE

F

N=1 N=15

F F T F

N=2 N=3

slide-37
SLIDE 37

Oracles for Longest Paths

 Goal: Prune search of computation tree.

F F T F F T T F F F T T F F

slide-38
SLIDE 38

Oracles for Longest Paths

 Goal: Prune search of computation tree.

F F T F F T T F F F T T F F

slide-39
SLIDE 39

Branch Policy Oracles

 Classify each conditional in P:

 Free: Must explore true or false branch.  Biased: When feasible, only explore true

(resp. false) branch.

slide-40
SLIDE 40

Branch Policy Oracles

 Each conditional in P classified as:

F T F Free: Biased:

slide-41
SLIDE 41

Branch Policy Oracles

 Each conditional in P classified as:

F T F Free: Biased:

slide-42
SLIDE 42

Branch Policy Oracles

 Each conditional in P classified as:

F T F Free: Biased (true): F T F

slide-43
SLIDE 43

Branch Policy Oracles

 Each conditional in P classified as:

F T F Free: Biased (true): F T F

slide-44
SLIDE 44

Example: Searching w/ Branch Policy

 N insertions into empty sorted list:

// list with sentinel INT_MAX insert(list* p, int x) { while (x > p->data) { p = p->next; } p->next = new list(p->data,
 p->next); p->data = x; }

slide-45
SLIDE 45

Example: Searching w/ Branch Policy

 N insertions into empty sorted list:

// list with sentinel INT_MAX insert(list* p, int x) { while (x > p->data) { p = p->next; } p->next = new list(p->data,
 p->next); p->data = x; }

Biased to true branch.

slide-46
SLIDE 46

Example: Searching w/ Branch Policy

F F T F F T T F F F T T F F

∞  sorted list:

insert(list, x1); insert(list, x2); insert(list, x3);

slide-47
SLIDE 47

Example: Searching w/ Branch Policy

F F T F F T T F F F T T F F

∞  x: x1 p:  sorted list:

while (x > p->data) { p = p->next; } x1 > ∞

slide-48
SLIDE 48

Example: Searching w/ Branch Policy

F F T F F T T F F F T T F F

x1  ∞  x: x2 p:  sorted list:

while (x > p->data) { p = p->next; } x2 > x1

slide-49
SLIDE 49

Example: Searching w/ Branch Policy

F F T F F T T F F F T T F F

x1  ∞  x: x2 p:  sorted list:

while (x > p->data) { p = p->next; } x2 > ∞

slide-50
SLIDE 50

Example: Searching w/ Branch Policy

F F T F F T T F F F T T F F

x1  ∞  x2  x: x3 p:  sorted list:

while (x > p->data) { p = p->next; } x3 > x1

slide-51
SLIDE 51

Example: Searching w/ Branch Policy

F F T F F T T F F F T T F F

x1  ∞  x2  x: x3 p:  sorted list:

while (x > p->data) { p = p->next; } x3 > x2

slide-52
SLIDE 52

Example: Searching w/ Branch Policy

F F T F F T T F F F T T F F

x1  ∞  x2  x: x3 p:  sorted list:

while (x > p->data) { p = p->next; } x3 > ∞

slide-53
SLIDE 53

Example: Searching w/ Branch Policy

F F T F F T T F F F T T F F

slide-54
SLIDE 54

Example: Searching w/ Branch Policy

F F T F F T T F F F T T F F

slide-55
SLIDE 55

 Step 1: From executions on small inputs,

learn oracle for longest paths.

 Step 2: For large inputs, only examine

paths generated by oracle.

Overview of WISE

F

N=1 N=15

F F T F

N=2 N=3

slide-56
SLIDE 56

 Step 1: From executions on small inputs,

learn oracle for longest paths.

 Step 2: For large inputs, only examine

paths generated by oracle.

Overview of WISE

F

N=1 N=15

F F T F

N=2 N=3

slide-57
SLIDE 57

Selecting a Branch Policy

 Find all executions on size-1,…,T inputs.  Pick branch policy B that:

 gives a longest path for each 1,…,T  gives fewest # paths on 1,…,T

slide-58
SLIDE 58

Selecting a Branch Policy

 Pick branch policy B that:

 gives a longest path for each 1,…,T  gives fewest # paths on 1,…,T

Policy:

?

N=1 N=2 N=3

slide-59
SLIDE 59

Selecting a Branch Policy

 Pick branch policy B that:

 gives a longest path for each 1,…,T  gives fewest # paths on 1,…,T

F T

Policy:

N=1 N=2 N=3

slide-60
SLIDE 60

Selecting a Branch Policy

 Pick branch policy B that:

 gives a longest path for each 1,…,T  gives fewest # paths on 1,…,T

F T

Policy:

N=1 N=2 N=3

slide-61
SLIDE 61

Selecting a Branch Policy

 Pick branch policy B that:

 gives a longest path for each 1,…,T  gives fewest # paths on 1,…,T

F T

N=1 N=2 N=3

Policy:

slide-62
SLIDE 62

Selecting a Branch Policy

 Pick branch policy B that:

 gives a longest path for each 1,…,T  gives fewest # paths on 1,…,T

N=1 N=2 N=3

Policy:

F T

slide-63
SLIDE 63

Selecting a Branch Policy

 Pick branch policy B that:

 gives a longest path for each 1,…,T  gives fewest # paths on 1,…,T

N=1 N=2 N=3

Policy:

F T

slide-64
SLIDE 64

Selecting a Branch Policy

 Pick branch policy B that:

 gives a longest path for each 1,…,T  gives fewest # paths on 1,…,T

N=1 N=2 N=3

Policy:

F T

slide-65
SLIDE 65

Outline

 Motivation + Goal of WISE  Background: Symbolic Test Generation  Naïve Algorithm for Finding Complexity  WISE Algorithm  Evaluation  Conclusions + Future Work

slide-66
SLIDE 66

Evaluating the WISE Algorithm

 Correctness

 Does WISE find worst-case inputs?

 Efficiency (Scalability)

 For large inputs, how well does WISE

prune the search?

slide-67
SLIDE 67

Correctness of WISE

 Does WISE find worst-case inputs?  Recall:

 Find all executions on size-1,…,T inputs.  Pick branch policy B that:

(1) gives a longest path for each 1,…,T (2) gives fewest # paths on 1,…,T

 Will B give longest paths for larger inputs?

slide-68
SLIDE 68

Correctness of WISE: The Theory

 Yes, if T is large enough.  Proposition: For any program P,

there exists a T* such that:

 Branch policy B works for 1,..,T*

B works for all input sizes.

 How to find T*? We don’t know.

 In benchmarks, 2 ≤ T* ≤ 9.

slide-69
SLIDE 69

Evaluating the WISE Algorithm

 Correctness

 Does WISE find worst-case inputs?

 Efficiency (Scalability)

 For large inputs, how well does WISE

prune the search?

slide-70
SLIDE 70

Experiments: Data Structures

Benchmark O() # Paths # Paths Searched T* Sorted List Insert O(n) n! 1 2 Heap Insert O(log n) ~ (log n)! 1 2 Red-Black Tree Search O(log n) > n! 1 8 Binary Search Tree Insert O(n) > n! 1 3

slide-71
SLIDE 71

Experiments: Data Structures

// binary search tree insert void insert(tree** t, int x) { while (*t != NULL) { if (x <= (*t)->data) { t = &(*t)->left; } else { t = &(*t)->right; } } *t = new tree(x, NULL, NULL); }

slide-72
SLIDE 72

Experiments: Data Structures

// binary search tree insert void insert(tree** t, int x) { while (*t != NULL) { if (x <= (*t)->data) { t = &(*t)->left; } else { t = &(*t)->right; } } *t = new tree(x, NULL, NULL); }

Bias to true branch.

slide-73
SLIDE 73

Experiments: Data Structures

 For sorted list, tree, and heap insert:

 At any conditional comparing a new

element to an existing one, the new element should be smaller.

 For red-black tree search:

 Search value should be smaller than all

tree elements to which it’s compared.

slide-74
SLIDE 74

Experiments: Algorithms

Benchmark O() # Paths # Paths Searched T* Insertion Sort O(n2) n! 1 3 Quicksort O(n2) n! 1 8 Mergesort O(n log n) n! ~ 2n 7 Bellman-Ford O(nm) > (2n)n 1 3 Dijsktra’s O(n2) > 4n 1 3 TSP O(n!) huge 1 5

slide-75
SLIDE 75

Experiments: Algorithms

quicksort(int A[], int l, int r) { … // partition for (i = l; i < r; i++) { if (A[i] <= pivot) { swap(A[i], A[mid++]; } } … }

slide-76
SLIDE 76

Experiments: Algorithms

quicksort(int A[], int l, int r) { … // partition for (i = l; i < r; i++) { if (A[i] <= pivot) { swap(A[i], A[mid++]; } } … }

Bias to true branch.

slide-77
SLIDE 77

Experiments: Algorithms

 For Bellman-Ford and Dijkstra’s:

 In each iteration, every edge should be

relaxed when feasible.

 For Traveling Salesman:

 The search should never be pruned by the

heuristic bound.

slide-78
SLIDE 78

Experiments: Algorithms

Benchmark O() # Paths # Paths Searched T* Insertion Sort O(n2) n! 1 3 Quicksort O(n2) n! 1 8 Mergesort O(n log n) n! ~ 2n 7 Bellman-Ford O(nm) > (2n)n 1 3 Dijsktra’s O(n2) > 4n 1 3 TSP O(n!) huge 1 5

slide-79
SLIDE 79

Limitation: Mergesort

… // merge while (i <= lenL && j <= lenR) { if (left[i] <= right[j])
 { A[k++] = left[i++]; } else { A[k++] = right[j++]; } } // copy rest of left or right

slide-80
SLIDE 80

Limitation: Mergesort

… // merge while (i <= lenL && j <= lenR) { if (left[i] <= right[j])
 { A[k++] = left[i++]; } else { A[k++] = right[j++]; } } // copy rest of left or right

Longest paths alternate.

slide-81
SLIDE 81

Outline

 Motivation + Goal of WISE  Background: Symbolic Test Generation  Naïve Algorithm for Finding Complexity  WISE Algorithm  Evaluation  Conclusions + Future Work

slide-82
SLIDE 82

Related Work

 Worst-case Execution Time (WCET)

 For real-time, embedded systems  Large body of work

 Profiling – e.g. gprof [Graham, et al., 1982]  Empirical asymptotic complexity

 [Goldsmith, Aiken, Wilkerson, FSE 07]

 Static loop bounds

 Linear ranking functions [Colon, Sipma, TACAS 01]  [Gulavani, Gulwani, CAV 08]  SPEED [Gulwani, et a., POPL 08]

slide-83
SLIDE 83

Conclusions + Future Work

 Automated testing typically for correctness

 Have adapted for performance/complexity

 Worst-case Inputs from Symbolic Execution

 Generalizes from runs on small inputs  For small functions/components

 Next: Algorithmic denial-of-service

 E.g. regular expression matching  E.g. NIDS packet matching

slide-84
SLIDE 84

QUESTIONS?