Real-time Java API Specifications for High Coverage Test Generation - - PowerPoint PPT Presentation

real time java api specifications for high coverage test
SMART_READER_LITE
LIVE PREVIEW

Real-time Java API Specifications for High Coverage Test Generation - - PowerPoint PPT Presentation

Real-time Java API Specifications for High Coverage Test Generation Wolfgang Ahrendt Wojciech Gabriele Paganelli Mostowski Chalmers Technical Chalmers Technical University University University of Twente Contributions JML Formalisation


slide-1
SLIDE 1

Real-time Java API Specifications for High Coverage Test Generation

Wolfgang Ahrendt Chalmers Technical University

Wojciech Mostowski University of Twente

Gabriele Paganelli Chalmers Technical University

slide-2
SLIDE 2

Contributions

JML Formalisation of Real-Time Specification for Java (RTSJ) A test-case generator (KeYTestGen) using formal specification and source code Test industrial code using KeYTestGen and formal specification

slide-3
SLIDE 3

KeYTestGen

  • A Theorem Proving Based Test Case

Generator

  • Input: source code and specifications
  • An eclipse plugin
  • Aiming to be a push-button technology
slide-4
SLIDE 4

KeYTestGen

Test code generation

Constraint solving Symbolic Execution

Java+JML Runnable Test Suite

slide-5
SLIDE 5

KeYTestGen

Test code generation

Constraint solving Symbolic Execution

Java+JML Runnable Test Suite Set of constraints Describing paths inside the code

slide-6
SLIDE 6

KeYTestGen

Test code generation

Constraint solving Symbolic Execution

Java+JML Runnable Test Suite Concrete values: Test inputs Set of constraints Describing paths inside the code

slide-7
SLIDE 7

KeYTestGen

Test code generation

Constraint solving Symbolic Execution

Java+JML Runnable Test Suite Concrete values: Test inputs Set of constraints Describing paths inside the code Postcondition: decides test pass/fail

slide-8
SLIDE 8

Symbolic execution

  • Execution of a program with symbolic values
  • Advantage

– all executions (runs) can be expressed

slide-9
SLIDE 9

Symbolic execution

  • It is similar to developing an algebraic

expression with literals

– a*(b+c) →

slide-10
SLIDE 10

Symbolic execution

  • It is similar to developing an algebraic

expression with literals

– a*(b+c) →

a*b + a*c

slide-11
SLIDE 11

Symbolic execution

  • It is similar to developing an algebraic

expression with literals

– a*(b+c) →

  • One can substitute a,b,c with any value (e.g.

in N )

– The result will still be correct

I

a*b + a*c

slide-12
SLIDE 12

Constraint solvers

  • Input:

– Logical formula F containing variables V

  • Numerical
  • Boolean
  • Output:

– An assignment to V making F true, if it exists – Unknown/unsatisfiable otherwise

slide-13
SLIDE 13

KeYTestGen

  • Based on KeY, a theorem prover for dynamic

logic (DL)

– A DL formula is built from specification+code

Java Code Path Constraint Side Effects

slide-14
SLIDE 14

x = z; if(x > y){return x;} else {return 34;}... a>0

slide-15
SLIDE 15

x = z; if(x > y){return x;} else {return 34;}... a>0 if(x > y){return x;} else {return 34;}... a>0 x := z

slide-16
SLIDE 16

x = z; if(x > y){return x;} else {return 34;}... a>0 return x; a>0 z > y x := z if(x > y){return x;} else {return 34;}... a>0 x := z return 34; a>0 z ≤ y x := z

slide-17
SLIDE 17

Path constraints

  • Finding a satisfying assignment for the path

constraint gives a test input

  • Constraints are solved with

external solvers

– Simplify – Microsoft

slide-18
SLIDE 18

Specification matters: why?

slide-19
SLIDE 19

Specification matters: why?

slide-20
SLIDE 20

Specification matters: why?

method() invocation

slide-21
SLIDE 21

Specification matters: why?

method() invocation

slide-22
SLIDE 22

Specification matters: why?

method() invocation Library Method libmethod() invocation

slide-23
SLIDE 23

Specification matters: why?

method() invocation Library Method libmethod() invocation

?

slide-24
SLIDE 24

Specification in Theorem Proving based test case generation

public void underTest(){ } OtherMethod(); LibraryMethod();

slide-25
SLIDE 25

Specification in Theorem Proving based test case generation

public void underTest(){ } OtherMethod(); LibraryMethod();

Conjectural use

Assume the precondition holds. Is the postcondition satisfied?

  • Encodes the tests
slide-26
SLIDE 26

Specification in Theorem Proving based test case generation

public void underTest(){ } OtherMethod(); LibraryMethod(); OtherMethod(); LibraryMethod();

Conjectural use Axiomatic use

Assume the precondition holds. Is the postcondition satisfied? Does the precondition hold at this point? Then assume the postcondition to hold.

  • Replaces code
  • Keeps the method feasible
  • Encodes the tests
slide-27
SLIDE 27

Formalization Of RTSJ

slide-28
SLIDE 28

Formalization Of RTSJ

Limitations of KTG+Solvers:

  • Quantifiers
slide-29
SLIDE 29

Formalization Of RTSJ

Limitations of KTG+Solvers:

  • Quantifiers

Modularity requirements:

  • Do not refer to implementation

details (use specification-only fields)

slide-30
SLIDE 30

Formalization Of RTSJ

Limitations of KTG+Solvers:

  • Quantifiers

Modularity requirements:

  • Do not refer to implementation

details (use specification-only fields) Testing Requirements:

  • Contracts preconditions have to cover all input

space of methods

slide-31
SLIDE 31

AsyncEventHandler specification

/ @ ∗ normal behavior requires true; ensures handler == null || !handledBy(handler); assignable this._handlers[ ]; @ / ∗ ∗

public void removeHandler( / @ nullable @ / ∗ ∗ AsyncEventHandler handler);

slide-32
SLIDE 32

Evaluation

  • Formal RTSJ used for evaluating:

– Verification

  • Collision detector benchmark (CDx)

– Functional Testing of

  • client code (Lightgun driver)
  • API implementation (JamaicaVM)
slide-33
SLIDE 33

Evaluation: Testing Lightgun driver

  • A small application ~ 700 loc

– Driver for a CRT-compatible lightgun – Realtime: syncing with the screen refresh

  • Tested (semiautomatically) easily with

KeYTestGen

  • Coverage: MC/DC (DO178B/C)

– Achieved thanks to

Symbolic Execution

slide-34
SLIDE 34

Evaluation:

Verifying correctness of RTSJ code

  • CDx Real-Time Java Benchmark
  • A collision detector for aerial traffic
  • Proofs (with KeY) can be hard

– Some automatic – Others require user input

  • Which is the norm
slide-35
SLIDE 35

Evaluation: Testing of API implementation

  • JamaicaVM implementation
  • Tested against the API specification
  • Our method found a problem

automatically

slide-36
SLIDE 36

absolute() method

  • public AbsoluteTime absolute(Clock clock)

– Return a copy of this modified if necessary to have

the specified clock association. A new object is allocated for the result. This method is the implementation of the abstract method of the HighResolutionTime base class. No conversion into AbsoluteTime is needed in this case. The clock association of the result is with the clock passed as a

  • parameter. If clock is null the association is made with

the real-time clock.

slide-37
SLIDE 37

absolute() method

AbsoluteTime

.absolute( )

slide-38
SLIDE 38

AbsoluteTime

absolute() method

AbsoluteTime

slide-39
SLIDE 39

absolute() method

/*@ ensures clock != null ==> \result.getClock() == clock; ensures clock == null ==> \result.getClock() == Clock.getRealtimeClock(); */ public AbsoluteTime absolute(Clock clock);

slide-40
SLIDE 40

The inconsistency

  • KeYTestGen showed (automatically) that:
  • If a clock is passed as argument, the reference

to it is not set

/*@ ensures clock != null ==> \result.getClock() == clock; ensures clock == null ==> \result.getClock() == Clock.getRealtimeClock(); */ public AbsoluteTime absolute(Clock clock);

slide-41
SLIDE 41

The inconsistency

  • If a clock is passed as argument, the

reference to it is not set

  • This was intentional
  • There is no way to add a clock; RTSJ does not

tell how to do this

slide-42
SLIDE 42

Challenges and future+related work

  • Quantifiers

– Gladisch proposes an algorithm to handle them

  • Concrete instantiation of reference type

– Specification & solutions to constraints tells just

what the result is, but not how to build it

– Practice:

  • Quickcheck
  • JMLUnitNG (caching of constructors)
slide-43
SLIDE 43

Questions

KeYTestGen Formal Specification Evaluation

Symbolic execution Constraint solving Code generation Code generation from specification Replacement of missing/unknown code Feasibility of the approach

1 2

Verification: collision detector Test case generation: JamaicaVM, Ligthgun Driver Dual usage of specification

slide-44
SLIDE 44

Links

  • CDx benchmark

– http://sss.cs.purdue.edu/projects/cdx/

  • KeY

– http://www.key-project.org

  • KeYTestGen eclipse update site

– http://www.cse.chalmers.se/~gabpag

  • JMLUnitNG

– http://formalmethods.insttech.washington.edu/software/jmlunitng/

  • QuickCheck

– http://java.net/projects/quickcheck/pages/Home

  • JML formalized RTSJ API

– http://wwwhome.ewi.utwente.nl/~mostowskiwi/