Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis:...

61
1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

Transcript of Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis:...

Page 1: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

1

Program Testing and Analysis:

Introduction and Foundations

Dr. Michael Pradel

Software Lab, TU Darmstadt

Page 2: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

2

About Me

� Michael Pradel

� At TU Darmstadt since 2014

� Before joining TUD� Master-level studies in Dresden and Paris� Master thesis at EPFL, Switzerland� PhD at ETH Zurich, Switzerland� Postdoctoral researcher at UC Berkeley, USA

Page 3: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

3

About the Software Lab

� My research group; since 2014

� Research on tools and techniques forbuilding reliable, efficient, and securesoftware� Program analysis� Test generation� Focus: JavaScript-based applications &

Concurrency

� Thesis and job opportunities

Page 4: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

4

Plan for Today

� Introduction� What the course is about� Why it is interesting� How it can help you

� Organization� Course projects� Term paper� Mid-term and final exam

� Foundations� Grammars, ASTs, CFGs, CGs, PDGs, etc.

Page 5: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

5

Program Testing & Analysis

What you probably know:

� Manual testing or semi-automatedtesting:JUnit, Selenium, etc.

� Manual ”analysis” of programs:Code inspection, debugging, etc.

Focus of this course:Automated testing and program analysis

Page 6: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

6

Why Do We Need It?

� All software has bugs� Bugs are hard to find� Bugs cause serious harm

Page 7: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

6

Why Do We Need It?

� All software has bugs� Bugs are hard to find� Bugs cause serious harm

0.5-25/KLoCin deliveredsoftware

Page 8: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

6

Why Do We Need It?

� All software has bugs� Bugs are hard to find� Bugs cause serious harm

1.5 years tofind a bug[Palix2011]

Page 9: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

6

Why Do We Need It?

� All software has bugs� Bugs are hard to find� Bugs cause serious harm

Ariane 5 Northeastblackout

Therac-25

Page 10: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

7

What is Program Analysis?

� Automated analysis of programbehavior, e.g., to� find programming errors� optimize performance� find security vulnerabilities

ProgramInput Output

Page 11: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

7

What is Program Analysis?

� Automated analysis of programbehavior, e.g., to� find programming errors� optimize performance� find security vulnerabilities

Program

Additional information

Input Output

Page 12: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

7

What is Program Analysis?

� Automated analysis of programbehavior, e.g., to� find programming errors� optimize performance� find security vulnerabilities

Program

Additional information

InputInput

InputOutputOutput

Output

Page 13: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

8

Static vs. Dynamic Analysis

Static Dynamic

� Analyse source code,byte code, or binary

� Typically:� Consider all inputs� Overapproximate

possible behavior

� Analyze programexecution

� Typically:� Consider current

input� Underapproximate

possible behavior

Page 14: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

8

Static vs. Dynamic Analysis

Static Dynamic

� Analyse source code,byte code, or binary

� Typically:� Consider all inputs� Overapproximate

possible behavior

� Analyze programexecution

� Typically:� Consider current

input� Underapproximate

possible behavior

E.g., compilers,lint-like tools

E.g., automatedtesting, profilers

Page 15: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

9

Example

// JavaScriptvar r = Math.random(); // value in [0,1)var out = "yes";if (r < 0.5)out = "no";

if (r === 1)out = "maybe"; // infeasible path

console.log(out);

Quiz: What are the possible outputs?

Page 16: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

9

Example

// JavaScriptvar r = Math.random(); // value in [0,1)var out = "yes";if (r < 0.5)out = "no";

if (r === 1)out = "maybe"; // infeasible path

console.log(out);

Overapproximation: ”yes”, ”no”, ”maybe”� Consider all paths (that are feasible based on

limited knowledge)

Page 17: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

9

Example

// JavaScriptvar r = Math.random(); // value in [0,1)var out = "yes";if (r < 0.5)out = "no";

if (r === 1)out = "maybe"; // infeasible path

console.log(out);

Underapproximation: ”yes”� Execute the program once

Page 18: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

9

Example

// JavaScriptvar r = Math.random(); // value in [0,1)var out = "yes";if (r < 0.5)out = "no";

if (r === 1)out = "maybe"; // infeasible path

console.log(out);

Sound and complete: ”yes”, ”no”� For this example: Can explore both feasible paths

Page 19: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

10

Another Example

// JavaScriptvar r = Math.random(); // value in [0,1)var out = r * 2;console.log(out);

Page 20: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

10

Another Example

// JavaScriptvar r = Math.random(); // value in [0,1)var out = r * 2;console.log(out);

Overapproximation: Any value� Consider all paths (that are feasible based on

limited knowledge about random())

Page 21: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

10

Another Example

// JavaScriptvar r = Math.random(); // value in [0,1)var out = r * 2;console.log(out);

Underapproximation:Some number in [0,2), e.g., 1.234� Execute the program once

Page 22: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

10

Another Example

// JavaScriptvar r = Math.random(); // value in [0,1)var out = r * 2;console.log(out);

Sound and complete?� Exploring all possible outputs:

Practically impossible� This is the case for most real-world programs

Page 23: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

11

Over- vs. Underapproximation

Handwritten notes...

Page 24: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

2

Page 25: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

12

Test Generation

� Dynamic analysis:Requires input to run the program

� Test generation:Creates inputs automatically

� Examples� Generate JUnit tests:

Input = sequence of method calls� UI-level test generation:

Input = sequence UI events� Fuzz-test a compiler: Input = program

Page 26: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

13

How Does All This Help Me?

Improve the quality of your code� Fewer bugs� Better performance� More secure software

Save time during manual testing

Become a better developer� Get better understanding of program’s behavior� Avoid common pitfalls� Learn to use and write tools

Page 27: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

14

Plan for Today

� Introduction� What the course is about� Why it is interesting� How it can help you

� Organization� Course projects� Term paper� Mid-term and final exam

� Foundations� Grammars, ASTs, CFGs, CGs, PDGs, etc.

Page 28: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

15

Organization

� Weekly lectures

� Weekly reading material

� Throughout the semester:� Course project� Term paper

� End of November: Mid-term exam

� End of semester: Final exam

Page 29: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

16

Grading

� Weekly lectures

� Weekly reading material

� Throughout the semester:� Course project� Term paper

� End of November: Mid-term exam

� End of semester: Final exam

33%33%

33%

+10%

Page 30: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

16

Grading

� Weekly lectures

� Weekly reading material

� Throughout the semester:� Course project� Term paper

� End of November: Mid-term exam

� End of semester: Final exam

33%33%

33%

+10%

relevant for

Page 31: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

16

Grading

� Weekly lectures

� Weekly reading material

� Throughout the semester:� Course project� Term paper

� End of November: Mid-term exam

� End of semester: Final exam

33%33%

33%

+10%

relevant for

Must pass all three to pass the course

Page 32: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

17

A Friendly Warning

� Read regularly (otherwise, you won’t be able tocatch up)

� Work regularly on the course project� Schedule enough time to work on the term

paper

This is not going to bean easy course!

Page 33: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

18

Programming Language

Most concepts taught in this course:Language-independent

Course projects and most examples:JavaScript (specifically: ECMAScript 5)

� Very popular� Client-side web applications, but also for server,

mobile, and desktop applications� Various interesting research challenges

Page 34: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

19

Piazza

Platform for discussions, in-classquizzes, and sharing additional material

� Please register and enroll for the class� Use for all questions related to the course� Starting from next week, messages sent to all

students go via Piazza (not TUCaN!)

Page 35: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

20

Learning Material

There is no script or single book thatcovers everything

� Slides and hand-written nodes:Available after lecture

� Pointers to papers, book chapters, and webresources

Page 36: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

21

Course Project

� Independent research project

� Design, implement, and evaluate aprogram analysis and/or testgenerator

� Teams of 2 or 3 students� One team, one grade

Page 37: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

22

Course Project: Tools

Based on existing frameworks and tools

� Jalangi: Dynamic analysis framework

� WebAppWalker: UI-level test generationframework

� Esprima & Escodegen: ASTs, parsing, codegeneration

Page 38: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

23

Course Project: Organization

Timeline� Oct 19: Register teams and preferred projects� Week of Oct 26–30: Meeting with mentor� Week of Dec 1–4: Meeting with mentor� Week of Jan 18–22: Meeting with mentor� Feb 8: Presentation of results� Feb 19: Final submission

(There are office hours for additional meetings.)

Project proposals will be available viaPiazza

Page 39: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

24

Course Project: Deliverables

1) Implementation and results� Source code and everything needed to reproduce

the results� Packaged as VM image

2) Report� 10 pages maximum, English� Written like a scientific paper

Due on Feb 19

Page 40: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

25

Term Paper

Write a scientific article that summarizesand compares three existing papers

� Topic & papers: Based on lecture content

� Individual work

� 6 pages maximum, English

� Peer reviewing

Page 41: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

25

Term Paper

Write a scientific article that summarizesand compares three existing papers

� Topic & papers: Based on lecture content

� Individual work

� 6 pages maximum, English

� Peer reviewing

Grading: 23· final paper + 1

3· reviews

Page 42: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

26

Term Paper: Some Advice

� Don’t waste space on basics

� Examples are your secret weapon

� Most important part:Comparison of the three papers

� Bad English distracts from goodcontent

� Revise, revise, revise

Page 43: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

27

Term Paper: Rules

� No verbatim copying of text(exception: quotes)

� You may copy figures (e.g., resultgraphs)

� You must use your own example(s)

Page 44: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

28

Term Paper: Reviews

� Imitates peer reviewing process

� Each student reviews three termpapers

� Revise your term paper after gettingreviews� Grade will be for final term paper

� Plain text format� About 1 page, English

Page 45: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

29

Reviews: Some Advice

� Be constructive

� Be polite

� Your reviews contribute to your grade,not to the reviewee’s grade

Page 46: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

30

Term Paper: Organization

Timeline

� Nov 2: Register with preferred topics� Jan 11: Submit paper for peer review� Feb 1: Reviews due� Feb 19: Final version of paper due

Page 47: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

31

Exams

Mid-term exam (written)� Advisable but not mandatory� Can improve overall grade up to 10%� Last week of November

Final exam (written)� After the last lecture (exact date TBD)

Page 48: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

31

Exams

Mid-term exam (written)� Advisable but not mandatory� Can improve overall grade up to 10%� Last week of November

Final exam (written)� After the last lecture (exact date TBD)

For both:� Open book: Bring books, papers, etc.� Corollary: Will test your understanding, not your

memory!

Page 49: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

32

Academic Integrity

� Work you submit must be yourown/your team’s work

� Unauthorized group efforts and anyform of plagiarism are consideracademic dishonesty and will bepunished

� Allowed to discuss the problem withyour peers, but not to copy or reuseany part of an existing solution

Page 50: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

33

Plan for Today

� Introduction� What the course is about� Why it is interesting� How it can help you

� Organization� Course projects� Term paper� Mid-term and final exam

� Foundations� Grammars, ASTs, CFGs, CGs, PDGs, etc.

Page 51: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

34

Foundations

Hand-written notes ...

Page 52: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

3

Page 53: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

4

Page 54: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

5

Page 55: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

6

Page 56: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

7

Page 57: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

8

Page 58: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

9

Page 59: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

10

Page 60: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

11

Page 61: Introduction and Foundations Program Testing and Analysis€¦ · 1 Program Testing and Analysis: Introduction and Foundations Dr. Michael Pradel Software Lab, TU Darmstadt

35

Outlook� Operational semantics� Manual testing� Random and fuzz testing� Search-based testing� Symbolic and concolic testing� Testing concurrent programs� Path profiling� Program slicing� Information flow analysis� Differential testing� Specification mining� Performance profiling