CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha...

72
CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik Sen Darko Marinov Gul Agha University of Illinois Urbana-Champaign

Transcript of CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha...

Page 1: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

CUTE: A Concolic Unit Testing Engine for C

Technical Report

Koushik Sen Darko Marinov Gul Agha

University of Illinois Urbana-Champaign

Page 2: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

2

Page 3: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

3

Page 4: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

4

Page 5: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

5

5

Page 6: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

6

Page 7: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

7

Goal Automated Scalable Unit Testing of real-

world C Programs Generate test inputs Execute unit under test on generated test inputs

so that all reachable statements are executed Any assertion violation gets caught

Page 8: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

8

Goal Automated Scalable Unit Testing of real-

world C Programs Generate test inputs Execute unit under test on generated test inputs

so that all reachable statements are executed Any assertion violation gets caught

Our Approach: Explore all execution paths of an Unit for all

possible inputs Exploring all execution paths ensure that all reachable

statements are executed

Page 9: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

9

Execution Paths of a Program Can be seen as a binary

tree with possibly infinite depth Computation tree

Each node represents the execution of a “if then else” statement

Each edge represents the execution of a sequence of non-conditional statements

Each path in the tree represents an equivalence class of inputs

0 1

0 0

0

0

1

1

1

1

1

1

Page 10: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

10

Example of Computation Tree

void test_me(int x, int y) { if(2*x==y){

if(x != y+10){ printf(“I am fine here”);} else { printf(“I should not reach here”); ERROR;}

}}

2*x==y

x!=y+10

N Y

N Y

ERROR

Page 11: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

11

Existing Approach I Random testing

generate random inputs execute the program on

generated inputs Probability of reaching

an error can be astronomically less

test_me(int x){

if(x==94389){

ERROR;

}

}

Probability of hitting ERROR = 1/232

Page 12: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

12

Existing Approach II Symbolic Execution

use symbolic values for input variables

execute the program symbolically on symbolic input values

collect symbolic path constraints

use theorem prover to check if a branch can be taken

Does not scale for large programs

test_me(int x){if((x%10)*4!=17){

ERROR;} else {

ERROR;}

}

Symbolic execution will say both branches are reachable:

False positive

Page 13: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

13

Approach Combine concrete and symbolic execution for unit

testing Concrete + Symbolic = Concolic

In a nutshell Use concrete execution over a concrete input to guide

symbolic execution Concrete execution helps Symbolic execution to simplify

complex and unmanageable symbolic expressions by replacing symbolic values by concrete values

Achieves Scalability Higher branch coverage than random testing No false positives or scalability issue like in symbolic

execution based testing

Page 14: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

14

Exampletypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

• Random Test Driver:

• random memory graph reachable from p

• random value for x

• Probability of reaching abort( ) is extremely low

Page 15: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

15

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

p=p0, x=x0

p , x=236

NULL

Page 16: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

16

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

p=p0, x=x0

p , x=236

NULL

Page 17: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

17

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

x0>0

p=p0, x=x0

p , x=236

NULL

Page 18: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

18

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

x0>0

p=p0, x=x0

p , x=236

NULL

!(p0!=NULL)

Page 19: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

19

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

x0>0

p=p0, x=x0

p , x=236

NULL

p0=NULL

solve: x0>0 and p0NULL

Page 20: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

20

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

x0>0

p=p0, x=x0

p , x=236

NULL

p0=NULL

solve: x0>0 and p0NULL

x0=236, p0

634

NULL

Page 21: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

21

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

p=p0, x=x0,p->v =v0,

p->next=n0

p , x=236

NULL

634

Page 22: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

22

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

p=p0, x=x0,p->v =v0,

p->next=n0

p , x=236

NULL

634

x0>0

Page 23: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

23

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

p=p0, x=x0,p->v =v0,

p->next=n0

p , x=236

NULL

634

x0>0

p0NULL

Page 24: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

24

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

p=p0, x=x0,p->v =v0,

p->next=n0

p , x=236

NULL

634

x0>0

p0NULL

2x0+1v0

Page 25: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

25

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

p=p0, x=x0,p->v =v0,

p->next=n0

p , x=236

NULL

634

x0>0

p0NULL

2x0+1v0

Page 26: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

26

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

p=p0, x=x0,p->v =v0,

p->next=n0

p , x=236

NULL

634

x0>0

p0NULL

2x0+1v0

solve: x0>0 and p0NULL and 2x0+1=v0

Page 27: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

27

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

p=p0, x=x0,p->v =v0,

p->next=n0

p , x=236

NULL

634

x0>0

p0NULL

2x0+1v0

solve: x0>0 and p0NULL and 2x0+1=v0

x0=1, p0

3

NULL

Page 28: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

28

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

p=p0, x=x0,p->v =v0,

p->next=n0

p , x=1

NULL

3

Page 29: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

29

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

p=p0, x=x0,p->v =v0,

p->next=n0

p , x=1

NULL

3

x0>0

Page 30: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

30

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

p=p0, x=x0,p->v =v0,

p->next=n0

p , x=1

NULL

3

x0>0

p0NULL

Page 31: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

31

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

p=p0, x=x0,p->v =v0,

p->next=n0

p , x=1

NULL

3

x0>0

p0NULL

2x0+1=v0

Page 32: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

32

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

p=p0, x=x0,p->v =v0,

p->next=n0

p , x=1

NULL

3

x0>0

p0NULL

2x0+1=v0

n0p0

Page 33: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

33

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

p=p0, x=x0,p->v =v0,

p->next=n0

p , x=1

NULL

3

x0>0

p0NULL

2x0+1=v0

n0p0

Page 34: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

34

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

solve: x0>0 and p0NULL and 2x0+1=v0 and n0=p0

.

p=p0, x=x0,p->v =v0,

p->next=n0

p , x=1

NULL

3

x0>0

p0NULL

2x0+1=v0

n0p0

Page 35: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

35

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

solve: x0>0 and p0NULL and 2x0+1=v0 and n0=p0

x0=1, p0

3

p=p0, x=x0,p->v =v0,

p->next=n0

p , x=1

NULL

3

x0>0

p0NULL

2x0+1=v0

n0p0

Page 36: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

36

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

p=p0, x=x0,p->v =v0,

p->next=n0

p , x=1

3

Page 37: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

37

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

x0>0p=p0, x=x0,p->v =v0,

p->next=n0

p , x=1

3

Page 38: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

38

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

x0>0

p0NULLp=p0, x=x0,p->v =v0,

p->next=n0

p , x=1

3

Page 39: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

39

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

x0>0

p0NULL

2x0+1=v0

p=p0, x=x0,p->v =v0,

p->next=n0

p , x=1

3

Page 40: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

40

CUTE Approachtypedef struct cell { int v; struct cell *next;} cell;

int f(int v) { return 2*v + 1;}

int testme(cell *p, int x) { if (x > 0) if (p != NULL) if (f(x) == p->v) if (p->next == p) abort(); return 0;}

Concrete Execution

Symbolic Execution

concrete state

symbolic state

constraints

x0>0

p0NULL

2x0+1=v0

n0=p0

p=p0, x=x0,p->v =v0,

p->next=n0

p , x=1

3

Program Error

Page 41: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

42

Explicit Path (not State) Model Checking Traverse all execution paths

one by one to detect errors check for assertion

violations check for program crash combine with valgrind to

discover memory leaks detect invariants

0 1

0 0

0

0

1

1

1

1

1

1

Page 42: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

43

Explicit Path (not State) Model Checking Traverse all execution paths

one by one to detect errors check for assertion

violations check for program crash combine with valgrind to

discover memory leaks detect invariants

0 1

0 0

0

0

1

1

1

1

1

1

Page 43: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

44

Explicit Path (not State) Model Checking Traverse all execution paths

one by one to detect errors check for assertion

violations check for program crash combine with valgrind to

discover memory leaks detect invariants

0 1

0 0

0

0

1

1

1

1

1

1

Page 44: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

45

Explicit Path (not State) Model Checking Traverse all execution paths

one by one to detect errors check for assertion

violations check for program crash combine with valgrind to

discover memory leaks detect invariants

0 1

0 0

0

0

1

1

1

1

1

1

Page 45: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

46

Explicit Path (not State) Model Checking Traverse all execution paths

one by one to detect errors check for assertion

violations check for program crash combine with valgrind to

discover memory leaks detect invariants

0 1

0 0

0

0

1

1

1

1

1

1

Page 46: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

47

Explicit Path (not State) Model Checking Traverse all execution paths

one by one to detect errors check for assertion

violations check for program crash combine with valgrind to

discover memory leaks detect invariants

0 1

0 0

0

0

1

1

1

1

1

1

Page 47: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

48

Explicit Path (not State) Model Checking Traverse all execution paths

one by one to detect errors check for assertion

violations check for program crash combine with valgrind to

discover memory leaks detect invariants

0 1

0 0

0

0

1

1

1

1

1

1

Page 48: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

49

Explicit Path (not State) Model Checking Traverse all execution paths

one by one to detect errors check for assertion

violations check for program crash combine with valgrind to

discover memory leaks detect invariants

0 1

0 0

0

0

1

1

1

1

1

1

Page 49: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

50

CUTE in a Nutshell Generate concrete inputs one by one

each input leads program along a different path

Page 50: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

51

CUTE in a Nutshell Generate concrete inputs one by one

each input leads program along a different path On each input execute program both concretely and

symbolically

Page 51: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

52

CUTE in a Nutshell Generate concrete inputs one by one

each input leads program along a different path On each input execute program both concretely and

symbolically Both cooperate with each other

concrete execution guides the symbolic execution

Page 52: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

53

CUTE in a Nutshell Generate concrete inputs one by one

each input leads program along a different path On each input execute program both concretely and

symbolically Both cooperate with each other

concrete execution guides the symbolic execution concrete execution enables symbolic execution to

overcome incompleteness of theorem prover replace symbolic expressions by concrete values if

symbolic expressions become complex resolve aliases for pointer using concrete values handle arrays naturally

Page 53: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

54

CUTE in a Nutshell Generate concrete inputs one by one

each input leads program along a different path On each input execute program both concretely and

symbolically Both cooperate with each other

concrete execution guides the symbolic execution concrete execution enables symbolic execution to

overcome incompleteness of theorem prover replace symbolic expressions by concrete values if

symbolic expressions become complex resolve aliases for pointer using concrete values handle arrays naturally

symbolic execution helps to generate concrete input for next execution increases coverage

Page 54: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

55

Testing Data-structures of CUTE itself Unit tested several non-standard data-

structures implemented for the CUTE tool cu_depend (used to determine dependency

during constraint solving using graph algorithm) cu_linear (linear symbolic expressions) cu_pointer (pointer symbolic expressions)

Discovered a few memory leaks and a couple of segmentation faults these errors did not show up in other uses of

CUTE for memory leaks we used CUTE in conjunction

with Valgrind

Page 55: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

56

SGLIB: popular library for C data-structures Used in Xrefactory a commercial tool for refactoring

C/C++ programs Found two bugs in sglib 1.0.1

reported them to authors fixed in sglib 1.0.2

Bug 1: doubly-linked list library

segmentation fault occurs when a non-zero length list is concatenated with a zero-length list

discovered in 140 iterations ( < 1second)

Bug 2: hash-table

an infinite loop in hash table is member function 193 iterations (1 second)

Page 56: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

57

Simultaneous Symbolic & Concrete Executionvoid again_test_me(int x,int y){

z = x*x*x + 3*x*x + 9;

if(z != y){

printf(“Good branch”);

} else {

printf(“Bad branch”);

abort();

}

}

Let initially x = -3 and y = 7 generated by random test-driver

Page 57: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

58

Simultaneous Symbolic & Concrete Executionvoid again_test_me(int x,int y){

z = x*x*x + 3*x*x + 9;

if(z != y){

printf(“Good branch”);

} else {

printf(“Bad branch”);

abort();

}

}

Let initially x = -3 and y = 7 generated by random test-driver

concrete z = 9 symbolic z = x*x*x + 3*x*x+9 take then branch with

constraint x*x*x+ 3*x*x+9 != y

Page 58: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

59

Simultaneous Symbolic & Concrete Executionvoid again_test_me(int x,int y){

z = x*x*x + 3*x*x + 9;

if(z != y){

printf(“Good branch”);

} else {

printf(“Bad branch”);

abort();

}

}

Let initially x = -3 and y = 7 generated by random test-driver

concrete z = 9 symbolic z = x*x*x + 3*x*x+9 take then branch with

constraint x*x*x+ 3*x*x+9 != y solve x*x*x+ 3*x*x+9 = y to

take else branch Don’t know how to solve !!

Stuck ?

Page 59: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

60

Simultaneous Symbolic & Concrete Executionvoid again_test_me(int x,int y){

z = x*x*x + 3*x*x + 9;

if(z != y){

printf(“Good branch”);

} else {

printf(“Bad branch”);

abort();

}

}

Let initially x = -3 and y = 7 generated by random test-driver

concrete z = 9 symbolic z = x*x*x + 3*x*x+9 take then branch with

constraint x*x*x+ 3*x*x+9 != y solve x*x*x+ 3*x*x+9 = y to

take else branch Don’t know how to solve !!

Stuck ? NO : CUTE handles this

smartly

Page 60: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

61

Simultaneous Symbolic & Concrete Executionvoid again_test_me(int x,int y){

z = x*x*x + 3*x*x + 9;

if(z != y){

printf(“Good branch”);

} else {

printf(“Bad branch”);

abort();

}

}

Let initially x = -3 and y = 7 generated by random test-driver

Page 61: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

62

Simultaneous Symbolic & Concrete Executionvoid again_test_me(int x,int y){

z = x*x*x + 3*x*x + 9;

if(z != y){

printf(“Good branch”);

} else {

printf(“Bad branch”);

abort();

}

}

Let initially x = -3 and y = 7 generated by random test-driver

concrete z = 9 symbolic z = x*x*x + 3*x*x+9

cannot handle symbolic value of z

Page 62: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

63

Simultaneous Symbolic & Concrete Executionvoid again_test_me(int x,int y){

z = x*x*x + 3*x*x + 9;

if(z != y){

printf(“Good branch”);

} else {

printf(“Bad branch”);

abort();

}

}

Let initially x = -3 and y = 7 generated by random test-driver

concrete z = 9 symbolic z = x*x*x + 3*x*x+9

cannot handle symbolic value of z

make symbolic z = 9 and proceed

Page 63: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

64

Simultaneous Symbolic & Concrete Executionvoid again_test_me(int x,int y){

z = x*x*x + 3*x*x + 9;

if(z != y){

printf(“Good branch”);

} else {

printf(“Bad branch”);

abort();

}

}

Let initially x = -3 and y = 7 generated by random test-driver

concrete z = 9 symbolic z = x*x*x + 3*x*x+9

cannot handle symbolic value of z

make symbolic z = 9 and proceed

take then branch with constraint 9 != y

Page 64: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

65

Simultaneous Symbolic & Concrete Executionvoid again_test_me(int x,int y){

z = x*x*x + 3*x*x + 9;if(z != y){

printf(“Good branch”);} else {

printf(“Bad branch”);abort();

}}

Let initially x = -3 and y = 7 generated by random test-driver

concrete z = 9 symbolic z = x*x*x + 3*x*x+9

cannot handle symbolic value of z

make symbolic z = 9 and proceed

take then branch with constraint 9 != y

solve 9 = y to take else branch

execute next run with x = -3 and y= 9 got error (reaches abort)

Page 65: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

66

Simultaneous Symbolic & Concrete Executionvoid again_test_me(int x,int y){

z = x*x*x + 3*x*x + 9;if(z != y){

printf(“Good branch”);} else {

printf(“Bad branch”);abort();

}}

Let initially x = -3 and y = 7 generated by random test-driver

concrete z = 9 symbolic z = x*x*x + 3*x*x+9

cannot handle symbolic value of z

make symbolic z = 9 and proceed

take then branch with constraint 9 != y

solve 9 = y to take else branch

execute next run with x = -3 and y= 9 got error (reaches abort)

Replace symbolic expression by concrete value when

symbolic expression becomes unmanageable (i.e. non-linear)

Page 66: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

67

Simultaneous Symbolic & Concrete Executionvoid again_test_me(int x,int y){

z = x*x*x + 3*x*x + 9;

if(z != y){

printf(“Good branch”);

} else {

printf(“Bad branch”);

abort();

}

}

void again_test_me(int x,int y){

z = black_box_fun(x);

if(z != y){

printf(“Good branch”);

} else {

printf(“Bad branch”);

abort();

}

}

Page 67: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

68

Related Work “DART: Directed Automated Random Testing” by

Patrice Godefroid, Nils Klarlund, and Koushik Sen (PLDI’05) handles only arithmetic constraints

CUTE Supports C with

pointers, data-structures Highly efficient constraint solver

100 -1000 times faster arithmetic, pointers Provides Bounded Depth-First Search and Random Search

strategies Publicly available tool that works on ALL C programs

Page 68: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

69

Discussion CUTE is

light-weight dynamic analysis (compare with static analysis)

ensures no false alarms concrete execution and symbolic execution run

simultaneously symbolic execution consults concrete execution whenever

dynamic analysis becomes intractable real tool that works on all C programs

completely automatic

Requires actual code that can be fully compiled Can sometime reduce to Random Testing Complementary to Static Analysis Tools

Page 69: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

70

Current WorkConcurrency Support

dynamic pruning to avoid exploring equivalent interleaving

Application to find Dolev-Yao attacks in security protocols

Page 70: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

71

Page 71: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

72

Page 72: CUTE: A Concolic Unit Testing Engine for C Technical Report Koushik SenDarko MarinovGul Agha University of Illinois Urbana-Champaign.

73