CSC 509 Lecture Notes Week 4 Using Formal Specs to Support Testing - - PowerPoint PPT Presentation

csc 509 lecture notes week 4 using formal specs to
SMART_READER_LITE
LIVE PREVIEW

CSC 509 Lecture Notes Week 4 Using Formal Specs to Support Testing - - PowerPoint PPT Presentation

CSC509-S14-L4 Slide 1 CSC 509 Lecture Notes Week 4 Using Formal Specs to Support Testing (Monday) Class Project Proposals (Wednesday) CSC509-S14-L4 Slide 2 I. Quick Notes about "How to Read a Paper" A. A useful little ditty. B.


slide-1
SLIDE 1

CSC509-S14-L4 Slide 1

CSC 509 Lecture Notes Week 4 Using Formal Specs to Support Testing (Monday) Class Project Proposals (Wednesday)

slide-2
SLIDE 2

CSC509-S14-L4 Slide 2

  • I. Quick Notes about "How to Read a Paper"
  • A. A useful little ditty.
  • B. Particularly like observation about literature

search: "... if you are lucky, [you’ll find] a pointer to a recent survey paper [and then] you are done."

slide-3
SLIDE 3

CSC509-S14-L4 Slide 3

  • II. Very common refrains about manual test case

generation, as performed by humans:

  • A. It’s tedious.
  • B. It’s boring.
  • C. It’s error prone.
  • D. It may leave important things untested.
  • E. There’s got to be a better way.
slide-4
SLIDE 4

CSC509-S14-L4 Slide 4

  • III. Questions about the readings:
  • A. In the overall field of software testing, how signif-

icant is the subject matter in the survey paper?

  • B. How does the JML tools paper relate to the sur-

vey paper?

  • C. How does the jmlunitng paper relate to the gen-

eral JML tools paper?

slide-5
SLIDE 5

CSC509-S14-L4 Slide 5

  • IV. Answers, using a cosmologic metaphor:
  • A. literature outlined in Lecture Notes 1 covers the

galaxy of software testing.

  • B. Survey paper covers rather remote galactic

neighborhood of auto test gen from specs.

slide-6
SLIDE 6

CSC509-S14-L4 Slide 6

Software testing cosmology, cont’d

  • C. The JML tools paper talks about one small solar

system in the larger neighborhood.

  • 1. Note that in 75 pages survey paper only men-

tions Java a few times in passing.

  • 2. It never references JML specifically.
  • 3. Survey authors evidently don’t think much of

the JML solar system.

slide-7
SLIDE 7

CSC509-S14-L4 Slide 7

Software testing cosmology, cont’d

  • 4. The jmlunitng paper talks about one pretty

small planet in the JML solar system, still in its formative stages.

slide-8
SLIDE 8

CSC509-S14-L4 Slide 8

  • V. My impressions of the survey paper.
  • A. I rather disagree with their statement at the outset

that "Traditionally formal methods and software testing have been seen as rivals"

  • 1. I think this invokes some rather old "traditions".
  • 2. Authors go on to say that in a fact for some time

"these approaches are seen as complementary"

slide-9
SLIDE 9

CSC509-S14-L4 Slide 9

Impressions of survey paper, cont’d

  • B. Otherwise, I very strongly agree with the authors

statements in the paper introduction, including in particular these:

  • 1. combined formal analysis of specification and

test could provide very strong guarantees of cor- rectness

  • 2. information gathered by testing may assist when

using a formal specification

slide-10
SLIDE 10

CSC509-S14-L4 Slide 10

Impressions of survey paper, cont’d

  • 3. testing can be used in order to provide initial

confidence in a system before effort is expended in attempting to prove correctness

  • 4. Where it is not cost-effective to produce a proof
  • f conformance, the developers may gain confi-

dence in the SUT through systematic testing.

slide-11
SLIDE 11

CSC509-S14-L4 Slide 11

Impressions of survey paper, cont’d

  • 5. this might be complemented by proofs that criti-

cal properties hold

  • 6. a proof of correctness might also use information

derived during testing

slide-12
SLIDE 12

CSC509-S14-L4 Slide 12

Impressions of survey paper, cont’d

  • 7. Finally, a proof of correctness relies upon a

model of the underlying system and dynamic testing might be used to indirectly check that this model holds.

  • 8. An interesting challenge is to generate tests that

are likely to be effective in detecting errors in the assumptions inherent in a proof.

slide-13
SLIDE 13

CSC509-S14-L4 Slide 13

Impressions of survey paper, cont’d

  • C. Overall, they’re espousing one of my favorite

themes in software development -- multiple views

  • f the same artifact can be very helpful indeed
  • D. in this context we have these multiple views
  • 1. the spec
  • 2. the generated test cases
  • 3. the code
  • 4. a proof of correctness
slide-14
SLIDE 14

CSC509-S14-L4 Slide 14

  • VI. "Heavyweight" versus "Lightweight" methods.
  • A. Heavyweight methods are fully formal, based on

fully mechanized logics such as

  • 1. theorem provers
  • 2. resolution-based model checkers
  • 3. constraint solvers
slide-15
SLIDE 15

CSC509-S14-L4 Slide 15

Heavyweight versus Lightweight, cont’d

  • B. Leightweigh methods based on a formal spec, but

lec they do not employ fully or at all the mecha- nized logics of the heavyweight methods;

  • 1. instead, the lightweight approaches provide some

form of implementation that uses the specifica- tion as a data structure from which a non- exhaustive but "good" set of tests are generated.

slide-16
SLIDE 16

CSC509-S14-L4 Slide 16

  • VII. On the weightiness of the three papers
  • A. The survey is pure heavyweight stuff.
  • B. The JML tools paper talks about some moderately

heavy weight, medium weight, and lightweight tools.

  • C. The JMLUnitNG paper self describes its tool as

"extremely lightweight".

slide-17
SLIDE 17

CSC509-S14-L4 Slide 17

  • VIII. Snarky swipe at "noweight" informal testing.
  • A. Based on an ad hoc "think clearly about it" test

generation methodology.

  • B. Use an ad hoc oracle definition.
  • C. Use test coverage tools to mitigate ad hocness,
  • ften without full satisfaction.
slide-18
SLIDE 18

CSC509-S14-L4 Slide 18

  • IX. Some Highlights of the Survey Paper --
  • A. Centerpiece of the survey is the focus on five dif-

ferent styles of formal specification:

  • 1. Model-based
  • 2. State machines
  • 3. Concurrency formalisms
  • 4. Hybrid digital/analog
  • 5. Algebraic
slide-19
SLIDE 19

CSC509-S14-L4 Slide 19

  • X. Model-Based, e.g., Z, JML
  • A. Most directly relevant to software in the systems

and information processing domains typical for end-user applications.

  • B. Most accessible to programmers.
slide-20
SLIDE 20

CSC509-S14-L4 Slide 20

  • XI. FSMs, e.g., State Charts
  • A. Used in communication systems and other forms
  • f apps that can be aptly characterized using

FSMs

  • B. I personally find this form of specification obtuse,

tedious, and not relevant for many forms of end- user software.

slide-21
SLIDE 21

CSC509-S14-L4 Slide 21

  • XII. Concurrency formalisms, e.g., CSP
  • A. An essential formalism for modeling and testing

concurrent systems.

  • B. A single-thread formalism such as Z and JML

simply must have some additional mathematical representation to deal effectively with multi- threaded software architectures.

  • C. Another approach to this not mentioned in the

survey is Lamport’s temporal logic.

slide-22
SLIDE 22

CSC509-S14-L4 Slide 22

  • XIII. Hybrid math models, e.g., CHARON
  • A. As a practical mater, this style is more applicable

to systems-level and embedded software than end-user software.

  • B. Testing approaches focus on the use of simula-

tion.

  • C. The survey paper questions the practicality of this

approach in general, and I agree particularly for end-user software.

slide-23
SLIDE 23

CSC509-S14-L4 Slide 23

  • XIV. Algebraic, e.g., OBJ, Maude
  • A. This is a powerful and elegant approach to speci-

fication.

  • B. Among other things, the specification is itself

fully executable

  • 1. an execution and a proof are the same thing
  • 2. execution is performed by term reduction in

essentially the same form as term reduction is used in mechanized algebraic proofs

slide-24
SLIDE 24

CSC509-S14-L4 Slide 24

Algebraic specs, cont’d

  • C. The specification is 100% "model free", in that

are are no concrete data models defined.

  • D. Behavior is defined entirely in terms of an equal-

ity definition of operation behavior, with the only data model per se being that of a term.

slide-25
SLIDE 25

CSC509-S14-L4 Slide 25

Algebraic specs, cont’d

  • E. To test an algebraic specification, one can use the

same form of inductive partition of inputs as for model-based specification

  • F. The fundamental problem with algebraic specs is

that the mapping from the specification to a con- ventional sequentially-executing program is not at all straightforward.

slide-26
SLIDE 26

CSC509-S14-L4 Slide 26

  • 1. With model-based specs, the specification is

predicative annotation that is directly attached to the program.

  • 2. With a algebraic specification, the specification

is associated the the program at the class level.

slide-27
SLIDE 27

CSC509-S14-L4 Slide 27

Algebraic specs, cont’d

  • G. And alas, the mathematics involved in this form
  • f specification is sufficiently dense and inacces-

sible to most software developers as to render this approach to specification and subsequently test- ing impractical.

  • H. This is a shame really, giv

en the supreme ele- gance of algebraic specification.

slide-28
SLIDE 28

CSC509-S14-L4 Slide 28

  • - Quick Highlights of JML Tools Paper --
  • A. It describes what’s on offer from the JMl crowd

in addition to automated testing.

  • B. The majority of high-end research is on verifica-

tion and other forms of static and dynamic analy- sis.

slide-29
SLIDE 29

CSC509-S14-L4 Slide 29

  • - Highlights of the JMLUnitNG Paper --
  • A. Describes a tool that generates JUnit-style tests

from JML specs.

  • B. There are three aspects to such a tool, as outlined

in the survey paper and embodied in this particu- lar tool (among many others):

slide-30
SLIDE 30

CSC509-S14-L4 Slide 30

JMLUnitNG, cont’d

  • 1. Choose a spec language -- JML in this case.
  • 2. Choose a well-known test generation technique
  • - exhaustive range and input combination in

this case

  • 3. Implement in a existing spec language transla-

tion environment -- java4c in this case

slide-31
SLIDE 31

CSC509-S14-L4 Slide 31

  • - Highlights of Three Different Spec Languages --
  • XV. There’s clearly a "tower of babel" problem with

the diversity of different specification languages, all of which do the same thing

  • A. We’ll look at two model-based languages -- Z and

JML

  • B. We’ll also have a quick look at an algebraic lan-

guage -- OBJ

slide-32
SLIDE 32

CSC509-S14-L4 Slide 32

Spec language tower of babel, cont’d

  • C. There’s no question that the diversity and obtuse-

ness of spec languages is at least one important factor in the lack of wide-spread adoption.

slide-33
SLIDE 33

CSC509-S14-L4 Slide 33

  • XVI. A sample Z spec

paper handout, online at classes/509/examples/lecture4/Stack.z.pdf

  • XVII. The equivalent JML spec

paper handout, online at classes/509/examples/lecture4/Stack.java

  • XVIII. JML & Z side-by-side comparison

paper handout, online at classes/509/examples/lecture4/StackZ.java

  • XIX. The equivalent OBJ spec

paper handout, online at classes/509/examples/lecture4/Stack.obj

slide-34
SLIDE 34

CSC509-S14-L4 Slide 34

  • XX. 509 projects in this area
  • A. I continue to be interested in having an auto-test

generation tool that is usable CSC 307 and 309.

  • B. The jmlunitng tool is the closest I’ve seen to such

a tool so far.

  • C. In order to be deployable in 309, in needs some

key improvements:

slide-35
SLIDE 35

CSC509-S14-L4 Slide 35

Key improvements to jmlunitng, cont’d

  • 1. Upgrade from Java 5 to Java 7 or 8.
  • 2. Eliminate the combinatorially explosive number
  • f test cases using well-known techniques intro-

duced by Weyuker. Provide support for full oracle executability, adapting ideas from a Cal Poly MS thesis by Paul Corwin.

slide-36
SLIDE 36

CSC509-S14-L4 Slide 36

Key improvements to jmlunitng, cont’d

  • D. Summary of the approach to full execution:
  • 1. Refine jmlunitng notion of using constructor

tests to create "worlds" of test fixture objects, specifically having worlds for each defined data type.

slide-37
SLIDE 37

CSC509-S14-L4 Slide 37

Key improvements to jmlunitng, cont’d

  • 2. As in Corwin thesis, implement executability of

unbounded quantifiers by substituting a finite number of values from type-specific worlds to bound the range of any unbounded quantifier

slide-38
SLIDE 38

CSC509-S14-L4 Slide 38

Key improvements to jmlunitng, cont’d

  • 3. E.g., forall (Stack s ...) is bounded

by the number Stack objects otherwise created for test generation

  • 4. Another is program transformation of unbounded

quantification to a bounded form, using patterns employed by humans

  • 5. When such pattern-based transformation cannot

be achieved, then fall back on "finite-world" mechanism.

slide-39
SLIDE 39

CSC509-S14-L4 Slide 39

  • XXI. Review of well-know test generation rules
  • A. The rules are surprisingly straightforward.
  • B. They’re employed explicitly or implicitly by

humans when generating tests.

  • C. Mechanizing them is straightforward as well, one

you’re into the details of the spec language trans- lation environment.

  • D. An overview of the rules follows.
slide-40
SLIDE 40

CSC509-S14-L4 Slide 40

  • XXII. Black box testing rules
slide-41
SLIDE 41

CSC509-S14-L4 Slide 41

  • XXII. Black box testing rules
  • A. Provide inputs where the precondition is true,

varying inputs to exercise precond logic.

slide-42
SLIDE 42

CSC509-S14-L4 Slide 42

  • XXII. Black box testing rules
  • A. Provide inputs where the precondition is true,

varying inputs to exercise precond logic.

  • B. Provide inputs where the precond is false,

if not a by-contract method.

slide-43
SLIDE 43

CSC509-S14-L4 Slide 43

Black box rules, cont’d

  • B. For data ranges:
slide-44
SLIDE 44

CSC509-S14-L4 Slide 44

Black box rules, cont’d

  • B. For data ranges:
  • 1. Provide inputs below, within, above each pre-

cond range.

slide-45
SLIDE 45

CSC509-S14-L4 Slide 45

Black box rules, cont’d

  • B. For data ranges:
  • 1. Provide inputs below, within, above each pre-

cond range.

  • 2. Provide inputs that produce outputs at bottom,

within, at top of each postcond range.

slide-46
SLIDE 46

CSC509-S14-L4 Slide 46

Black box rules, cont’d

slide-47
SLIDE 47

CSC509-S14-L4 Slide 47

Black box rules, cont’d

  • C. With and/or logic, provide test cases that fully

exercise logic.

slide-48
SLIDE 48

CSC509-S14-L4 Slide 48

Black box rules, cont’d

  • C. With and/or logic, provide test cases that fully

exercise logic.

  • 1. Provide an input that makes each clause both

true and false.

slide-49
SLIDE 49

CSC509-S14-L4 Slide 49

Black box rules, cont’d

  • C. With and/or logic, provide test cases that fully

exercise logic.

  • 1. Provide an input that makes each clause both

true and false.

  • 2. This means 2n test cases, where n is number of

logical terms.

slide-50
SLIDE 50

CSC509-S14-L4 Slide 50

Black box rules, cont’d

slide-51
SLIDE 51

CSC509-S14-L4 Slide 51

Black box rules, cont’d

  • D. For collection classes:
slide-52
SLIDE 52

CSC509-S14-L4 Slide 52

Black box rules, cont’d

  • D. For collection classes:
  • 1. Test empty collection.
slide-53
SLIDE 53

CSC509-S14-L4 Slide 53

Black box rules, cont’d

  • D. For collection classes:
  • 1. Test empty collection.
  • 2. Test with one, two elements.
slide-54
SLIDE 54

CSC509-S14-L4 Slide 54

Black box rules, cont’d

  • D. For collection classes:
  • 1. Test empty collection.
  • 2. Test with one, two elements.
  • 3. Add substantial number of elements.
slide-55
SLIDE 55

CSC509-S14-L4 Slide 55

Black box rules, cont’d

  • D. For collection classes:
  • 1. Test empty collection.
  • 2. Test with one, two elements.
  • 3. Add substantial number of elements.
  • 4. Delete each element.
slide-56
SLIDE 56

CSC509-S14-L4 Slide 56

Black box rules, cont’d

  • D. For collection classes:
  • 1. Test empty collection.
  • 2. Test with one, two elements.
  • 3. Add substantial number of elements.
  • 4. Delete each element.
  • 5. Repeat add/del sequence.
slide-57
SLIDE 57

CSC509-S14-L4 Slide 57

Black box rules, cont’d

  • D. For collection classes:
  • 1. Test empty collection.
  • 2. Test with one, two elements.
  • 3. Add substantial number of elements.
  • 4. Delete each element.
  • 5. Repeat add/del sequence.
  • 6. Stress test with order of magnitude greater than

expected size.

slide-58
SLIDE 58

CSC509-S14-L4 Slide 58

  • XXIII. 509 Projects in Spec-Based Testing
  • A. Recap of improvements to JMLUnit[NG]:
  • 1. Reduce combintorially explosive number of test

cases by applying preceding rules.

  • 2. Improve postcond executability (Corwin thesis).
  • 3. Memoize test execution results (Bolef thesis).
slide-59
SLIDE 59

CSC509-S14-L4 Slide 59

  • B. Other ideas for a 509 projects in this area:
  • 1. Provide "syntactically sugared" GUI.
  • 2. Provide testing of both spec and code.
  • 3. Generate tests for multiple languages.
slide-60
SLIDE 60

CSC509-S14-L4 Slide 60

Other ideas, cont’d

  • 4. Translate pseudo-code test cases into compilable

xUnit code (IBM Rex Tool)

  • 5. Generate specs from test cases (requires AI).
  • 6. Generate specs from descriptions (requires

mucho AI, NLP).

slide-61
SLIDE 61

CSC509-S14-L4 Slide 61

A sample UI for a spec-based testing tool

slide-62
SLIDE 62

CSC509-S14-L4 Slide 62

Delete Case

Operation: Test Plan: Precondition: Postcondition:

Validate Case Validate All

Description:

Edit Case ... New Case ... Inputs Outputs Remarks Results Case

Spec Validator

Spec file: none Load Spec ... Load Tests ... Save Browse ...

slide-63
SLIDE 63

CSC509-S14-L4 Slide 63

Delete Case

Operation: Test Plan: Precondition: Postcondition:

Validate Case Validate All

Description:

Edit Case ... New Case ... Inputs Outputs Remarks Results Case

Spec Validator

Spec file: none Load Spec ... Load Tests ... Save Browse ...

Enter complete spec here Generate complete tests here

slide-64
SLIDE 64

CSC509-S14-L4 Slide 64

Delete Case

Operation: Test Plan: Precondition: Postcondition:

Validate Case Validate All

Description:

Edit Case ... New Case ... Inputs Outputs Remarks Results Case

Spec Validator

Spec file: none Load Spec ... Load Tests ... Save Browse ...

Generate complete spec here Enter complete tests here

slide-65
SLIDE 65

CSC509-S14-L4 Slide 65

Delete Case

Operation: Test Plan: Precondition: Postcondition:

Validate Case Validate All

Description:

Edit Case ... New Case ... Inputs Outputs Remarks Results Case

Spec Validator

Spec file: none Load Spec ... Load Tests ... Save Browse ...

Enter formalized description here Generate completish spec here Generate completish tests here

slide-66
SLIDE 66

CSC509-S14-L4 Slide 66

  • XXIV. Additional reading for 509 project.
  • A. We

yruker paper

  • B. Corwin thesis
  • C. Korat paper
  • D. Executable JML specs paper
slide-67
SLIDE 67

CSC509-S14-L4 Slide 67