Eclat: Automatic Generation and Classification of Test Inputs - - PowerPoint PPT Presentation

eclat automatic generation and
SMART_READER_LITE
LIVE PREVIEW

Eclat: Automatic Generation and Classification of Test Inputs - - PowerPoint PPT Presentation

Eclat: Automatic Generation and Classification of Test Inputs Carlos Pacheco and Michael Ernst Program Analysis Group MIT The Problem Suppose you have a program that works It passes an existing test suite Its observable behavior


slide-1
SLIDE 1

Eclat: Automatic Generation and Classification of Test Inputs

Carlos Pacheco and Michael Ernst Program Analysis Group MIT

slide-2
SLIDE 2

The Problem

  • Suppose you have a program that works

– It passes an existing test suite – Its observable behavior appears correct

  • You want improved confidence in the program's

reliability

– Ensure that the program works on different inputs

  • If program’s operation incorrect on some input, fix the

program and add a new test case to test suite

slide-3
SLIDE 3

Input Generation

  • Can automatically generate test inputs

– Random generation [Klaessen & Hughes 2002, …] – Bounded exhaustive testing [Boyapati et al. 2002] – Constraint solving [Korel 1996, Gupta 1998, …] – Many more…

  • Without automatic tool support, must inspect each

resulting input (unless executable spec/oracle exists)

– Is the input fault-revealing? – Is the input useful?

slide-4
SLIDE 4

Research Goal

  • Help the user select from a large number of

inputs, a small “promising” subset:

– Inputs exhibiting new program behavior – Inputs likely to reveal faults

slide-5
SLIDE 5

model of correct operation normal illegal fault candidate inputs True faults False alarms

The Technique

execution (e.g. test suite) program potentially fault revealing inputs Model generator Classifier Input generator Reducer

slide-6
SLIDE 6

model of correct operation normal illegal fault candidate inputs True faults False alarms

The Technique

execution (e.g. test suite) program potentially fault revealing inputs Model generator Classifier Input generator Reducer

slide-7
SLIDE 7

model of correct operation normal illegal fault candidate inputs True faults False alarms

The Technique

execution (e.g. test suite) program potentially fault revealing inputs Model generator Classifier Input generator Reducer

slide-8
SLIDE 8

model of correct operation normal illegal fault candidate inputs True faults False alarms

The Technique

execution (e.g. test suite) program potentially fault revealing inputs Model generator Classifier Input generator Reducer

slide-9
SLIDE 9

model of correct operation normal illegal fault candidate inputs True faults False alarms

The Technique

execution (e.g. test suite) program potentially fault revealing inputs Model generator Classifier Input generator Reducer

slide-10
SLIDE 10

model of correct operation normal illegal fault candidate inputs True faults False alarms

The Technique

execution (e.g. test suite) program potentially fault revealing inputs Model generator Classifier Input generator Reducer

slide-11
SLIDE 11

model of correct operation normal illegal fault candidate inputs True faults False alarms

The Technique

execution (e.g. test suite) program potentially fault revealing inputs Model generator Classifier Input generator Reducer

slide-12
SLIDE 12

model of correct operation normal illegal fault candidate inputs True faults False alarms

The Technique

execution (e.g. test suite) program potentially fault revealing inputs Model generator Classifier Input generator Reducer

slide-13
SLIDE 13

model of correct operation normal illegal fault candidate inputs True faults False alarms

The Technique

execution (e.g. test suite) program potentially fault revealing inputs Model generator Classifier Input generator Reducer

slide-14
SLIDE 14
  • Our technique uses a model generator to produce

a model of correct program operation, derived from observing a correct execution

[Ernst et al. 2001, Ammons et al. 2002, Hankel and Diwan 2003, …]

  • Our technique requires

– Set of properties hold at component boundaries – The properties can be evaluated

Model Generator

slide-15
SLIDE 15

Example: bounded stack

[Stotts et al. 2002, Xie and Notkin 2003, Csallner and Amaragdakis 2004]

public class StackTest { ... } public class Stack { private int[] elems; private int topOfStack; private int capacity; public Stack() { ... } public void push(int k) { ... } public void pop() { topOfStack --; } public boolean isMember(int i) { ... } ... }

slide-16
SLIDE 16

capacity == elems.length elems != null capacity == 2 topOfStack >= 0 elems  { [3,0], [3,2] } k  elems elems == orig(elems)

  • rig(k)  elems
  • bject properties

isMember: exit properties isMember: entry properties pop: entry properties

public class StackTest { ... } public class Stack { private int[] elems; private int topOfStack; private int capacity; public Stack() { ... } public void push(int k) { ... } public void pop() { topOfStack --; } public boolean isMember(int i) { ... } ... }

Example: bounded stack

slide-17
SLIDE 17

model of correct operation candidate inputs True faults False alarms

Classifier

potentially fault revealing inputs program

normal illegal fault

execution (e.g. test suite) Model generator Classifier Input generator Reducer

slide-18
SLIDE 18
  • Run program on candidate input
  • Detect set of violated model properties
  • Classify:

Classifier

yes no no yes no yes illegal normal fault Classification exit violations? entry violations? yes no normal (new)

slide-19
SLIDE 19

Classifier: normal input

Stack var1 = new Stack(); var1.push(3); var1.pop();

capacity == elems.length elems != null capacity == 2 topOfStack >= 0 elems  { [3,0], [3,2] } k  elems elems == orig(elems)

  • rig(k)  elems
  • bject properties (all methods)

isMember: exit properties isMember: entry properties pop: entry properties

yes no no yes no yes illegal normal fault exit violations?

entry violations?

yes no normal (new) Classification

slide-20
SLIDE 20

yes no no yes no yes illegal normal fault exit violations?

entry violations?

yes no normal (new)

Classifier: normal input

Stack var1 = new Stack(); var1.push(3); var1.pop();

capacity == elems.length elems != null capacity == 2 topOfStack >= 0 elems  { [3,0], [3,2] } k  elems elems == orig(elems)

  • rig(k)  elems
  • bject properties (all methods)

isMember: exit properties isMember: entry properties pop: entry properties

Classification

slide-21
SLIDE 21

Classifier: fault-revealing input

Stack var1 = new Stack(); var1.push(3); var1.pop(); var1.pop();

capacity == elems.length elems != null capacity == 2 topOfStack >= 0 elems  { [3,0], [3,2] } k  elems elems == orig(elems)

  • rig(k)  elems
  • bject properties (all methods)

isMember: exit properties isMember: entry properties pop: entry properties

yes no no yes no yes illegal normal fault exit violations?

entry violations?

yes no normal (new) Classification

slide-22
SLIDE 22

yes no no yes no yes illegal normal fault exit violations?

entry violations?

yes no normal (new)

Classifier: fault-revealing input

Stack var1 = new Stack(); var1.push(3); var1.pop() var1.pop();

capacity == elems.length elems != null capacity == 2 topOfStack >= 0 elems  { [3,0], [3,2] } k  elems elems == orig(elems)

  • rig(k)  elems
  • bject properties (all methods)

isMember: exit properties isMember: entry properties pop: entry properties

(on exit)

Classification

slide-23
SLIDE 23

Classifier: illegal input

Stack var1 = new Stack(); var1.push(0); var1.isMember(-5);

capacity == elems.length elems != null capacity == 2 topOfStack >= 0 elems  { [3,0], [3,2] } k  elems elems == orig(elems)

  • rig(k)  elems
  • bject properties (all methods)

isMember: exit properties isMember: entry properties pop: entry properties

yes no no yes no yes illegal normal fault exit violations?

entry violations?

yes no normal (new) Classification

slide-24
SLIDE 24

yes no no yes no yes illegal normal fault exit violations?

entry violations?

yes no normal (new)

Classifier: illegal input

Stack var1 = new Stack(); var1.push(0); var1.isMember(-5);

capacity == elems.length elems != null capacity == 2 topOfStack >= 0 elems  { [3,0], [3,2] } k  elems elems == orig(elems)

  • rig(k)  elems
  • bject properties (all methods)

isMember: exit properties isMember: entry properties pop: entry properties

Classification

slide-25
SLIDE 25

model of correct operation candidate inputs True faults False alarms

Reducer

potentially fault revealing inputs program

normal illegal fault

execution (e.g. test suite) Model generator Classifier Input generator Reducer

slide-26
SLIDE 26
  • Partitions inputs based on the set of properties they

violate

  • Reports one inputs from each partition
  • Inputs in same partition are likely to manifest same

faulty behavior

Reducer

slide-27
SLIDE 27

Two equivalent inputs:

Stack var1 = new Stack(); var1.push(3); var1.pop(); var1.pop();

topOfStack >= 0 (on exit)

Violation pattern:

Stack var1 = new Stack(); var1.push(0); var1.pop(); var1.push(3); var1.pop(); var1.pop();

topOfStack >= 0 (on exit)

Violation pattern:

Reducer: example

slide-28
SLIDE 28

model of correct operation candidate inputs True faults False alarms

Input Generator

potentially fault revealing inputs program

normal illegal fault

execution (e.g. test suite) Model generator Classifier Input generator Reducer

slide-29
SLIDE 29

Bottom-up Random Generator

  • 1. pool := a set of primitives (null, 0, 1, etc.)
  • 2. do N times:

2.1. create new inputs by calling methods/constructors using pool inputs as arguments 2.2. add resulting inputs to the pool

Null, 0, 1, 2, 3

slide-30
SLIDE 30

Stack var1 = new Stack(); Stack var2 = new Stack(3); Null, 0, 1, 2 3

  • 1. pool := a set of primitives (null, 0, 1, etc.)
  • 2. do N times:

2.1. create new inputs by calling methods/constructors using pool inputs as arguments 2.2. add resulting inputs to the pool

Bottom-up Random Generator

slide-31
SLIDE 31

Stack var1 = new Stack(); Stack var2 = new Stack(3); Null, 0, 1, 2 3 var1.isMember(2); var2.push(3); var1.pop();

  • 1. pool := a set of primitives (null, 0, 1, etc.)
  • 2. do N times:

2.1. create new inputs by calling methods/constructors using pool inputs as arguments 2.2. add resulting inputs to the pool

Bottom-up Random Generator

slide-32
SLIDE 32

Stack var1 = new Stack(); Stack var2 = new Stack(3); Null, 0, 1, 2 3 var1.isMember(2); var2.push(3); var1.pop(); var2.pop(); var2.push(0); var1.equals(var2);

  • 1. pool := a set of primitives (null, 0, 1, etc.)
  • 2. do N times:

2.1. create new inputs by calling methods/constructors using pool inputs as arguments 2.2. add resulting inputs to the pool

Bottom-up Random Generator

slide-33
SLIDE 33

Avoiding illegal inputs

  • It’s important that the inputs in the pool are legal

– Inputs in the pool are building blocks for other inputs

Stack s = new Stack(); s.pop(); Stack s2 = new Stack(3); s.equals(s2); Stack s = new Stack(); s.pop(); Stack s = new Stack(); s.pop(); s.isMember(1);

fault-revealing illegal illegal

Input 2 (tests equals) Input 1(tests pop) Input 3 (tests isMember)

slide-34
SLIDE 34

model of correct operation candidate inputs True faults False alarms

Using the classifier for generation

potentially fault revealing inputs program

normal illegal fault

execution (e.g. test suite) Model generator Classifier Input generator Reducer

slide-35
SLIDE 35

model of correct operation candidate inputs True faults False alarms

potentially fault revealing inputs program

normal illegal fault

execution (e.g. test suite)

Using the classifier for generation

Model generator Classifier Input generator Reducer

slide-36
SLIDE 36
  • 1. pool := a set of primitives (null, 0, 1, etc.)
  • 2. do N times:

2.1. create new inputs by calling methods/constructors using pool inputs as arguments 2.2 classify inputs 2.3 throw away illegal inputs 2.4 save away fault inputs 2.5. add normal inputs to the pool

Enhanced generator

slide-37
SLIDE 37
  • Eclat generates inputs for Java unit testing
  • Eclat uses the Daikon invariant detector to create a

model of correct execution

  • Each test input is wrapped as a JUnit test
  • Eclat proposes assertion checks based on violated

properties http://pag.csail.mit.edu/eclat

Eclat

Execution (e.g. test suite)

Java program

Eclat

Text output

  • r

XML output

  • r

JUnit tests

slide-38
SLIDE 38

Eclat’s output: example

public void test_1_integrate() { RatPoly rp1 = new RatPoly(4, 3); RatPoly rp2 = new RatPoly(1, 1); RatPoly rp3 = rp1.add(rp2); checkPreProperties(rp3); rp3.integrate(0); checkPostProperties(rp3); }

slide-39
SLIDE 39

Eclat’s output: example

public void test_1_integrate() { RatPoly rp1 = new RatPoly(4, 3); RatPoly rp2 = new RatPoly(1, 1); RatPoly rp3 = rp1.add(rp2); checkPreProperties(rp3); rp3.integrate(0); checkPostProperties(rp3); }

Assertion violation!

slide-40
SLIDE 40

Eclat’s output: example

public void test_1_integrate() { RatPoly rp1 = new RatPoly(4, 3); RatPoly rp2 = new RatPoly(1, 1); RatPoly rp3 = rp1.add(rp2); checkPreProperties(rp3); rp3.integrate(0); checkPostProperties(rp3); } public void checkPostProperties(RatPoly rp) { ... // on exit: all terms in rp always have non-zero coefficient Assert.assertTrue(!allZeroes(rp.terms)); }

Assertion violation!

slide-41
SLIDE 41

Eclat’s output: example

public void test_1_integrate() { RatPoly rp1 = new RatPoly(4, 3); RatPoly rp2 = new RatPoly(1, 1); RatPoly rp3 = rp1.add(rp2); checkPreProperties(rp3); rp3.integrate(0); checkPostProperties(rp3); }

Assertion violation!

public void checkPostProperties(RatPoly rp) { ... // on exit: all terms in rp always have non-zero coefficient Assert.assertTrue(!allZeroes(rp.terms)); }

94 inputs violate this property. Of these, 3 are shown to the user.

slide-42
SLIDE 42
  • We used Eclat to generate inputs for

– 6 families of libraries – 64 distinct interfaces – 631 implementations – 75,000 NCNB lines of code

Evaluation

slide-43
SLIDE 43

model of correct operation candidate inputs True faults False alarms

Evaluation results: generator

1338

potentially fault revealing inputs program

normal illegal fault

execution (e.g. test suite) Model generator Classifier Input generator Reducer

slide-44
SLIDE 44

model of correct operation candidate inputs True faults False alarms

Evaluation results: classifier

1338

321 normal: illegal: fault:

90% precision 12% precision 78% precision potentially fault revealing inputs program

normal illegal fault

execution (e.g. test suite)

986 31

Model generator Classifier Input generator Reducer

slide-45
SLIDE 45

model of correct operation candidate inputs True faults False alarms

Evaluation results: reducer

1338 5 1.5 3.5

30% precision potentially fault revealing inputs program

normal illegal fault

execution (e.g. test suite) Model generator Classifier Input generator Reducer

321 normal: illegal: fault:

90% precision 12% precision 78% precision

986 31

slide-46
SLIDE 46

model of correct operation candidate inputs True faults False alarms

Evaluation results: reducer

1338 5 1.5 3.5

30% precision potentially fault revealing inputs program

normal illegal fault

execution (e.g. test suite) Model generator Classifier Input generator Reducer

321 normal: illegal: fault:

90% precision 12% precision 78% precision

986 31

slide-47
SLIDE 47
  • Incorporate other classification techniques

[Podgursky et al. 2003, Brun and Ernst 2004, Bowring et al. 2004, …]

  • Incorporate other generation strategies

[ Korel 1996, Gupta 1998, Klaessen & Hughes 2002, Boyapati et al. 2002, …]

Future Directions

slide-48
SLIDE 48
  • Technique to generate new program inputs

– Inputs likely to reveal faults – Inputs not covered by an existing test suite

  • Technique is effective in uncovering errors
  • Eclat: automatically generates unit tests for Java

classes Eclat: ht http: tp:// //pag pag.csa csail. il.mi mit.e t.edu/e u/ecla clat

Conclusion

slide-49
SLIDE 49
slide-50
SLIDE 50

Related Work

  • Harder et al. Improving test suites via operational
  • abstraction. ICSE 2003.
  • Xie and Notkin. Tool-assisted unit test selection

based on operational violations. ASE 2003.

  • Csallner and Smaragdakis. JCrasher: an

automatic robustness tester for Java. Software Practice and Experience, 2004.