54
A Brief Intro to Automated Test Generaon CMPT 473 Soſtware Quality Assurance Nick Sumner

A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

A Brief Intro toAutomated Test Generation

CMPT 473Software Quality Assurance

Nick Sumner

Page 2: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

Our Test Suites Are Still Limited

● There is only so much we can include● Even covering interesting interactions is a challenge

Page 3: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

Our Test Suites Are Still Limited

● There is only so much we can include● Even covering interesting interactions is a challenge

Our first naive solution may not have been naive!for test in allPossibleInputs: run_program(test)

Page 4: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

Our Test Suites Are Still Limited

● There is only so much we can include● Even covering interesting interactions is a challenge

Our first naive solution may not have been naive!for test in allPossibleInputs: run_program(test)

How might this be pragmatically useful?

Page 5: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

Automated Test Generation

● We can continuously run new tests

Page 6: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

Automated Test Generation

● We can continuously run new tests– But manual testing this way won't work!

Page 7: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

Automated Test Generation

● We can continuously run new tests– But manual testing this way won't work!

● Automated Test Generation– Use program analysis to derive new tests without the

user

Page 8: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

Automated Test Generation

● We can continuously run new tests– But manual testing this way won't work!

● Automated Test Generation– Use program analysis to derive new tests without the

user● 2 approaches are increasingly common

Page 9: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

Automated Test Generation

● We can continuously run new tests– But manual testing this way won't work!

● Automated Test Generation– Use program analysis to derive new tests without the

user● 2 approaches are increasingly common

– Fuzz Testing

Page 10: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

Automated Test Generation

● We can continuously run new tests– But manual testing this way won't work!

● Automated Test Generation– Use program analysis to derive new tests without the

user● 2 approaches are increasingly common

– Fuzz Testing– Symbolic Execution

Page 11: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

Fuzz Testing

● An approach for generating test inputs

Page 12: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

Fuzz Testing

● An approach for generating test inputs● Originally just feeding large random inputs to

programs [Miller 1990]

./grep “02d6…” RandomFile

Page 13: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

Fuzz Testing

● An approach for generating test inputs● Originally just feeding large random inputs to

programs [Miller 1990]

./grep “02d6…” RandomFile

It was distressingly effective at findingbuffer overflows (25%-33% of programs).

Page 14: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

Fuzz Testing

● An approach for generating test inputs● Originally just feeding large random inputs to

programs [Miller 1990]

● Now 2 main types

Page 15: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

Fuzz Testing

● An approach for generating test inputs● Originally just feeding large random inputs to

programs [Miller 1990]

● Now 2 main types1) Generational (model based)

● Creates entirely new inputs

Page 16: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

Fuzz Testing

● An approach for generating test inputs● Originally just feeding large random inputs to

programs [Miller 1990]

● Now 2 main types1) Generational (model based)

● Creates entirely new inputs● Needs a model for the input

Page 17: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

Fuzz Testing

● An approach for generating test inputs● Originally just feeding large random inputs to

programs [Miller 1990]

● Now 2 main types1) Generational (model based)

● Creates entirely new inputs● Needs a model for the input

a*bc(d|e)c*

Page 18: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

Fuzz Testing

● An approach for generating test inputs● Originally just feeding large random inputs to

programs [Miller 1990]

● Now 2 main types1) Generational (model based)

● Creates entirely new inputs● Needs a model for the input

a*bc(d|e)c* A → aAbA → cAA → ε

Page 19: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

Fuzz Testing

● An approach for generating test inputs● Originally just feeding large random inputs to

programs [Miller 1990]

● Now 2 main types1) Generational (model based)

● Creates entirely new inputs● Needs a model for the input

a*bc(d|e)c* A → aAbA → cAA → ε…

Page 20: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

Fuzz Testing

● An approach for generating test inputs● Originally just feeding large random inputs to

programs [Miller 1990]

● Now 2 main types1) Generational (model based)2) Mutational (heuristic change based)

● Modify an existing test suite

Page 21: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

Fuzz Testing

● An approach for generating test inputs● Originally just feeding large random inputs to

programs [Miller 1990]

● Now 2 main types1) Generational (model based)2) Mutational (heuristic change based)

● Modify an existing test suite● Seeing a resurgance via AFL & libFuzzer

Page 22: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

American Fuzzy Lop

● Increasingly used mutational fuzzer– Effective at finding buffer overflows

Page 23: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

American Fuzzy Lop

● Increasingly used mutational fuzzer– Effective at finding buffer overflows

Page 24: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

24

Symbolic Execution

● An approach for generating test inputs.

x ← input()y ← input()

if x == 2*y

Cadar & Sen, 2013

if x > y+10

Page 25: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

25

Symbolic Execution

● An approach for generating test inputs.

● Replace the concrete inputs of a program with symbolic values

x ← symbolic()y ← symbolic()

if x == 2*y

Cadar & Sen, 2013

if x > y+10

Page 26: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

26

Symbolic Execution

● An approach for generating test inputs.

● Replace the concrete inputs of a program with symbolic values

● Execute the program along a path using the symbolic values to build a formula over the input symbols.

x ← symbolic()y ← symbolic()

if x == 2*y

Cadar & Sen, 2013

if x > y+10

Page 27: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

27

Symbolic Execution

● An approach for generating test inputs.

● Replace the concrete inputs of a program with symbolic values

● Execute the program along a path using the symbolic values to build a formula over the input symbols.

x ← symbolic()y ← symbolic()

if x == 2*y

Cadar & Sen, 2013

if x > y+10

x = 2*yy > 10

Path Constraint

Page 28: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

28

Symbolic Execution

● An approach for generating test inputs.

● Replace the concrete inputs of a program with symbolic values

● Execute the program along a path using the symbolic values to build a formula over the input symbols.

● Solve for the symbolic symbols to find inputs that yield the path.

x ← symbolic()y ← symbolic()

if x == 2*y

Cadar & Sen, 2013

if x > y+10

x=30y=15

Page 29: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

29

Symbolic Execution

● An approach for generating test inputs.

● Replace the concrete inputs of a program with symbolic values

● Execute the program along a path using the symbolic values to build a formula over the input symbols.

● Solve for the symbolic symbols to find inputs that yield the path.

x ← symbolic()y ← symbolic()

if x == 2*y

Cadar & Sen, 2013

if x > y+10

x=30y=15

x=2y=1

Page 30: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

30

Symbolic Execution

● An approach for generating test inputs.

● Replace the concrete inputs of a program with symbolic values

● Execute the program along a path using the symbolic values to build a formula over the input symbols.

● Solve for the symbolic symbols to find inputs that yield the path.

x ← symbolic()y ← symbolic()

if x == 2*y

Cadar & Sen, 2013

if x > y+10

x=30y=15

x=2y=1

x=0y=1

Page 31: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

31

How Can We Solve Constraints?

● SMT Solvers– Satisfiability Modulo Theories– SAT with extra logic– Standard interfaces through SMTLIB2

Page 32: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

32

How Can We Solve Constraints?

● SMT Solvers– Satisfiability Modulo Theories– SAT with extra logic– Standard interfaces through SMTLIB2

(declare-const x Int)(declare-const y Int)(assert (= x (* 2 y)))(assert (> y 10))(check-sat)(get-model)

x = 2*yy > 10

Page 33: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

33

How Can We Solve Constraints?

● SMT Solvers– Satisfiability Modulo Theories– SAT with extra logic– Standard interfaces through SMTLIB2

(declare-const x Int)(declare-const y Int)(assert (= x (* 2 y)))(assert (> y 10))(check-sat)(get-model)

x = 2*yy > 10

Z3

Page 34: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

34

How Can We Solve Constraints?

● SMT Solvers– Satisfiability Modulo Theories– SAT with extra logic– Standard interfaces through SMTLIB2

(declare-const x Int)(declare-const y Int)(assert (= x (* 2 y)))(assert (> y 10))(check-sat)(get-model)

x = 2*yy > 10

Z3 sat (model (define-fun y () Int 11) (define-fun x () Int 22))

x=22y=11

Page 35: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

35

How Can We Solve Constraints?

● SMT Solvers– Satisfiability Modulo Theories– SAT with extra logic– Standard interfaces through SMTLIB2

(declare-const x Int)(declare-const y Int)(assert (= x (* 2 y)))(assert (> y 10))(check-sat)(get-model)

x = 2*yy > 10

Z3 sat (model (define-fun y () Int 11) (define-fun x () Int 22))

x=22y=11

Try it online:http://www.rise4fun.com/Z3/tutorial/

Page 36: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

36

Exploring the Execution Tree

● The possible paths of a program form anexecution tree.

x ← input()y ← input()

if x == 2*y

if x > y+10

Cadar & Sen, 2013

Page 37: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

37

Exploring the Execution Tree

● The possible paths of a program form anexecution tree.

● Traversing the tree willyield tests for all paths.

x ← input()y ← input()

if x == 2*y

if x > y+10

Cadar & Sen, 2013

Page 38: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

38

Exploring the Execution Tree

● The possible paths of a program form anexecution tree.

● Traversing the tree willyield tests for all paths.

● Mechanizing the traversalyields two mainapproaches

x ← input()y ← input()

if x == 2*y

if x > y+10

Cadar & Sen, 2013

Page 39: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

39

Exploring the Execution Tree

● The possible paths of a program form anexecution tree.

● Traversing the tree willyield tests for all paths.

● Mechanizing the traversalyields two mainapproaches– Concolic (dynamic symbolic)

x ← input()y ← input()

if x == 2*y

if x > y+10

Cadar & Sen, 2013

Page 40: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

40

Exploring the Execution Tree

● The possible paths of a program form anexecution tree.

● Traversing the tree willyield tests for all paths.

● Mechanizing the traversalyields two mainapproaches– Concolic (dynamic symbolic)

x ← input()y ← input()

if x == 2*y

if x > y+10

Cadar & Sen, 2013

Page 41: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

41

Exploring the Execution Tree

● The possible paths of a program form anexecution tree.

● Traversing the tree willyield tests for all paths.

● Mechanizing the traversalyields two mainapproaches– Concolic (dynamic symbolic)

x ← input()y ← input()

if x == 2*y

if x > y+10

(x=2*y) ∧ (x>y+10)

Cadar & Sen, 2013

Page 42: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

42

Exploring the Execution Tree

● The possible paths of a program form anexecution tree.

● Traversing the tree willyield tests for all paths.

● Mechanizing the traversalyields two mainapproaches– Concolic (dynamic symbolic)

x ← input()y ← input()

if x == 2*y

if x > y+10

(x=2*y) ∧ ¬(x>y+10)

Cadar & Sen, 2013

Page 43: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

43

Exploring the Execution Tree

● The possible paths of a program form anexecution tree.

● Traversing the tree willyield tests for all paths.

● Mechanizing the traversalyields two mainapproaches– Concolic (dynamic symbolic)

x ← input()y ← input()

if x == 2*y

if x > y+10

Cadar & Sen, 2013

Page 44: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

44

Exploring the Execution Tree

● The possible paths of a program form anexecution tree.

● Traversing the tree willyield tests for all paths.

● Mechanizing the traversalyields two mainapproaches– Concolic (dynamic symbolic)

– Execution GeneratedTesting

x ← input()y ← input()

if x == 2*y

if x > y+10

Cadar & Sen, 2013

Page 45: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

45

Exploring the Execution Tree

● The possible paths of a program form anexecution tree.

● Traversing the tree willyield tests for all paths.

● Mechanizing the traversalyields two mainapproaches– Concolic (dynamic symbolic)

– Execution GeneratedTesting

x ← input()y ← input()

if x == 2*y

if x > y+10

X= ?y=10

Cadar & Sen, 2013

Page 46: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

46

Exploring the Execution Tree

● The possible paths of a program form anexecution tree.

● Traversing the tree willyield tests for all paths.

● Mechanizing the traversalyields two mainapproaches– Concolic (dynamic symbolic)

– Execution GeneratedTesting

x ← input()y ← input()

if x == 2*y

if x > y+10 X=?≠20y=10

X=20y=10

Cadar & Sen, 2013

Page 47: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

47

Exploring the Execution Tree

● The possible paths of a program form anexecution tree.

● Traversing the tree willyield tests for all paths.

● Mechanizing the traversalyields two mainapproaches– Concolic (dynamic symbolic)

– Execution GeneratedTesting

x ← input()y ← input()

if x == 2*y

if x > y+10 X=?≠20y=10

X=20y=10

Execution on this side isconcrete from this point on.

Cadar & Sen, 2013

Page 48: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

48

Symbolic Execution

● Increasingly scalable every year

Page 49: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

49

Symbolic Execution

● Increasingly scalable every year● Can automatically generate test inputs from

constraints

Page 50: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

50

Symbolic Execution

● Increasingly scalable every year● Can automatically generate test inputs from

constraints● The resulting symbolic formulae have many used

beyond just testing.

Page 51: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

51

Symbolic Execution

● Increasingly scalable every year● Can automatically generate test inputs from

constraints● The resulting symbolic formulae have many used

beyond just testing.

Try it out:https://github.com/klee/klee

Page 52: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

52

Where They Fit in the Process

● Automated test generation is a continual process.

Page 53: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

53

Where They Fit in the Process

● Automated test generation is a continual process.● Just as much a part of modern QA as continuous

integration

Page 54: A Brief Intro to Automated Test Generationwsumner/teaching/473/13-autotesting.pdf · A Brief Intro to Automated Test Generation CMPT 473 Software Quality Assurance Nick Sumner. Our

54

Where They Fit in the Process

● Automated test generation is a continual process.● Just as much a part of modern QA as continuous

integration● Especially crucial as part of maintaining security

(more on this later!)