the search for the perfect program

29
THE SEARCH FOR THE PERFECT PROGRAM NATALLIE BAIKEVICH @ LU_A_JALLA

Upload: natallie-baikevich

Post on 30-Jun-2015

1.098 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: The Search for the Perfect Program

THE SEARCH FOR THE PERFECT PROGRAM

NATALLIE BAIKEVICH

@LU_A_JALLA

Page 2: The Search for the Perfect Program

A ‘PERFECT PROGRAM’ IS …

- Maintainable

- Efficient

- Correct

Page 3: The Search for the Perfect Program

A ‘PERFECT PROGRAM’ IS …

- Maintainable

- Efficient

- CorrectDoes anything else really matter without correctness?

Page 4: The Search for the Perfect Program

THE PLAN- Assertions

- Random Testing

- Symbolic Execution

- Types

Page 5: The Search for the Perfect Program

THE PLAN- Assertions

- Random Testing

- Symbolic Execution

- Types

1.Do something

2.Check it

3.Go to 1.

Page 6: The Search for the Perfect Program

THE FAST TRACK

Write code -> Release

Page 7: The Search for the Perfect Program

WELL, NOT THAT FAST

Dear <…>

We see XYZException!!!.............!

where n = enough for you to feel miserable

n times

Page 8: The Search for the Perfect Program

OK, LET’S TEST IT

1. Choose your favourite library

(good chances it’s .*Unit)

2. Write some tests

aand

3. XYZException has gone

Page 9: The Search for the Perfect Program

THE PROBLEM, PART 1

But…

- they only check what you think a program should do, not what it actually should do

- ... on what you think is all possible inputs

Page 10: The Search for the Perfect Program

RANDOMIZE IT

Throw the thousands of inputs into your program with

- QuickCheck (Haskell)

- FsCheck (F#)

- ScalaCheck (Scala)

- or something else

Page 11: The Search for the Perfect Program

DEMO

RANDOMIZE IT

Page 12: The Search for the Perfect Program

FSCHECK- Expressive and

easy to use

- Checks your spec

- … in a large number

- … of randomly generated cases

“500 checks can’t be wrong!” © don’t remember who said that

Page 13: The Search for the Perfect Program

THE PROBLEM, PART 2- Expressive and

easy to use

- Checks your spec

- … in a large number

- … of randomly generated cases

“500 checks can’t be wrong!” © don’t remember who said that

- Writing good tests might be tricky

- Checks your spec

- … in a large number

- … of randomly generated cases

500 checks can easily be wrong!

But:

Page 14: The Search for the Perfect Program

DEMO

RANDOMIZE IT – WHAT’S MISSING?

Page 15: The Search for the Perfect Program

I WILL BUILD MY OWN TEST GENERATOR

let f x y =

if x < 10 then x

else if x = 42 then

failwith “42”

else 1 / y

x < 10 or x >= 10

x = 42 or x <> 42

y = 0 or y <> 0

Page 16: The Search for the Perfect Program

DEMO

QUOTATIONS

Page 17: The Search for the Perfect Program

THE PROBLEM, PART 3

But it’s too complicated to do by hands:

- too many cases,

- lots of overlapping paths,

- difficult to solve when the number of variables grows,

- not everything is a quotation…

Page 18: The Search for the Perfect Program

IDEA: USE A CONSTRAINT SOLVER

- Check out Z3 homepage

- Try Z3 in your browser

- LINQ to Z3 (ch9 video and a post by Bart de Smet)

Specially for fsharpers:

- Z3Fs on github

Page 19: The Search for the Perfect Program

THERE’S A TOOL FOR THAT – MEET PEX

- Dynamic symbolic execution

- Analyses .NET instructions

- Uses constraint solver to find the inputs

Page 21: The Search for the Perfect Program

DEMO

PEX

Page 22: The Search for the Perfect Program

TEST GENERATIONStatic:

- Conditional statements

- Check the formulas satisfiability

Dynamic:

- Collect the information during the program execution

- Unknown environments

- Enhanced values generation

- Better Performance

Page 23: The Search for the Perfect Program

DYNAMIC EXECUTION EXAMPLE

int obscure(int x, int y) {

if (x == hash(y)) return -1; // error

return 0;

}

“Compositional Dynamic Test Generation”, Patrice Godefroid (paper)

Page 24: The Search for the Perfect Program

THE PROBLEM, PART 4

Limitations:

- Nondeterministic cases (e.g. native code)

- Concurrency

- Constraint solver limitations

Page 25: The Search for the Perfect Program

MORE AND LESS TYPES WITH F*

F* - an ML-like verification-oriented language

- F* project homepage

- GitHub repo

- Try F* in your browser

Page 26: The Search for the Perfect Program

DEMO

TRYING F*

Page 27: The Search for the Perfect Program

THE PROBLEM, PART 5

- currently under development

- issues on mono

- in more complex cases, the errors become quite cryptic

- you still need to come up with a way to define the requirements, at the type level

Page 28: The Search for the Perfect Program

CONCLUSION

If you don’t know where you’re going, any road’ll take you there.

Lewis Caroll

Page 29: The Search for the Perfect Program

QUESTIONS?