SLIDE 1
Chaining Test Cases for Reactive System Testing Peter Schrammel, Tom - - PowerPoint PPT Presentation
Chaining Test Cases for Reactive System Testing Peter Schrammel, Tom - - PowerPoint PPT Presentation
Chaining Test Cases for Reactive System Testing Peter Schrammel, Tom Melham and Daniel Kroening first.lastname@cs.ox.ac.uk The 25th IFIP International Conference on Testing Software and Systems (ICTSS13) Nov 13-15, 2013, Istanbul, Turkey
SLIDE 2
SLIDE 3
Model-Based Testing
requirements design model implementation check check
SLIDE 4
Model-Based Testing
requirements design model implementation check check check
SLIDE 5
Model-Based Testing
requirements design model implementation test suite generator test suite check check check
SLIDE 6
Model-Based Testing
requirements design model implementation test suite generator test suite check check check
SLIDE 7
Model-Based Testing
textual requirements Simulink/ Stateflow formalised properties generated C code implementation check check
SLIDE 8
Model-Based Testing
textual requirements Simulink/ Stateflow formalised properties generated C code implementation test suite generator test suite check check
SLIDE 9
Model-Based Testing
textual requirements Simulink/ Stateflow formalised properties generated C code implementation test suite generator test suite check check
SLIDE 10
Example: Cruise Control
OFF,0,FALSE OFF,1,FALSE OFF,0,TRUE ON,1,TRUE DIS,2,TRUE DIS,0,TRUE OFF,2,FALSE OFF,2,TRUE brake ∨ dec brake ∨ dec brake ∨ dec gas ∨ acc gas ∨ acc gas ∨ acc acc ∨ dec gas ∨ acc brake ∨ dec button button button button button button button gas ∨ acc gas ∨ acc brake gas ∨ acc brake ∨ dec brake ∨ dec brake ∨ dec
SLIDE 11
Example: Generated C Code from Simulink
void i n i t ( s t a t e t ∗s ) { s− >mode = OFF ; s− >speed = 0; s− >enable = FALSE ; } void compute( i o t ∗i , s t a t e t ∗s ) { mode = s− >mode ; switch (mode) { case ON: i f ( i− >gas | | i− >brake ) s− >mode=DIS ; break ; case DIS : i f ( ( s− >speed==2 && ( i− >dec | | i− >brake ) ) | | ( s− >speed==0 && ( i− >acc | | i− >gas ) ) ) s− >mode=ON; break ; case OFF : i f ( s− >speed==0 && s− >enable && ( i− >gas | | i− >acc ) | | s− >speed==1 && i− >button | | s− >speed==2 && s− >enable && ( i− >brake | | i− >dec ) ) s− >mode=ON; break ; } i f ( i− >button ) s− >enable = ! s− >enable ; i f ( ( i− >gas | | mode!=ON && i− >acc ) && s− >speed<2) s− >speed ++; i f ( ( i− >brake | | mode!=ON && i− >dec ) && s− >speed>0) s− >speed−−; }
SLIDE 12
Example: Generated C Code from Simulink
void i n i t ( s t a t e t ∗s ) { s− >mode = OFF ; s− >speed = 0; s− >enable = FALSE ; } void compute( i o t ∗i , s t a t e t ∗s ) { mode = s− >mode ; switch (mode) { case ON: i f ( i− >gas | | i− >brake ) s− >mode=DIS ; break ; case DIS : i f ( ( s− >speed==2 && ( i− >dec | | i− >brake ) ) | | ( s− >speed==0 && ( i− >acc | | i− >gas ) ) ) s− >mode=ON; break ; case OFF : i f ( s− >speed==0 && s− >enable && ( i− >gas | | i− >acc ) | | s− >speed==1 && i− >button | | s− >speed==2 && s− >enable && ( i− >brake | | i− >dec ) ) s− >mode=ON; break ; } i f ( i− >button ) s− >enable = ! s− >enable ; i f ( ( i− >gas | | mode!=ON && i− >acc ) && s− >speed<2) s− >speed ++; i f ( ( i− >brake | | mode!=ON && i− >dec ) && s− >speed>0) s− >speed−−; }
Formalised properties: p1: G
- mode = ON ∧ speed = 1 ∧ dec ⇒ X(speed = 1)
- p2: G
- mode = DIS ∧ speed = 2 ∧ dec ⇒ X(mode = ON)
- p3: G
- mode = ON ∧ brake ⇒ X(mode = DIS)
- p4: G
- mode = OFF ∧ speed = 2 ∧ ¬enable ∧ button ⇒ X enable
SLIDE 13
Example
I = F OFF,0,FALSE OFF,1,FALSE OFF,0,TRUE ON,1,TRUE DIS,2,TRUE DIS,0,TRUE OFF,2,FALSE OFF,2,TRUE brake ∨ dec brake ∨ dec brake ∨ dec gas ∨ acc gas ∨ acc gas ∨ acc acc ∨ dec (p1) gas ∨ acc brake ∨ dec button button button button button (p4) button button button gas ∨ acc gas ∨ acc brake (p3) gas ∨ acc gas brake ∨ dec brake ∨ dec(p2) brake ∨ dec
SLIDE 14
Example
I = F OFF,0,FALSE OFF,1,FALSE OFF,0,TRUE ON,1,TRUE DIS,2,TRUE DIS,0,TRUE OFF,2,FALSE OFF,2,TRUE brake ∨ dec brake ∨ dec brake ∨ dec gas ∨ acc gas ∨ acc gas ∨ acc acc ∨ dec (p1) gas ∨ acc brake ∨ dec button button button button button (p4) button button button gas ∨ acc gas ∨ acc brake (p3) gas ∨ acc gas brake ∨ dec brake ∨ dec(p2) brake ∨ dec
SLIDE 15
Preliminaries
Program: State space Σ, input space Υ Initial states I ⊆ Σ Transition relation T ⊆ Σ × Υ × Σ
SLIDE 16
Preliminaries
Program: State space Σ, input space Υ Initial states I ⊆ Σ Transition relation T ⊆ Σ × Υ × Σ Bounded Model Checking: Check the existence of a path s0, s1, . . . , sK of increasing length K from φ to φ′ φ(s0) ∧
- 1≤k≤K
T(sk−1, ik−1, sk) ∧ φ′(sK) If SAT: satisfying assignment aka counterexample (s0, i0, s1, i1, . . . , sK−1, iK−1, sK)
SLIDE 17
Preliminaries
Program: State space Σ, input space Υ Initial states I ⊆ Σ Transition relation T ⊆ Σ × Υ × Σ Bounded Model Checking: Check the existence of a path s0, s1, . . . , sK of increasing length K from φ to φ′ φ(s0) ∧
- 1≤k≤K
T(sk−1, ik−1, sk) ∧ φ′(sK) If SAT: satisfying assignment aka counterexample (s0, i0, s1, i1, . . . , sK−1, iK−1, sK) Test case generation: φ = I and test goal φ′ Test case: input sequence i0, . . . , iK−1, expected outcome
SLIDE 18
Chaining Test Cases
Temporal logic safety specification: Set of properties, e.g., of type G
- mode = ON ∧ speed = 1 ∧ dec
- assumption ϕ
⇒ X(speed = 1)
SLIDE 19
Chaining Test Cases
Temporal logic safety specification: Set of properties, e.g., of type G
- mode = ON ∧ speed = 1 ∧ dec
- assumption ϕ
⇒ X(speed = 1)
- Test goals: set of assumptions ϕ (finite paths)
SLIDE 20
Chaining Test Cases
Temporal logic safety specification: Set of properties, e.g., of type G
- mode = ON ∧ speed = 1 ∧ dec
- assumption ϕ
⇒ X(speed = 1)
- Test goals: set of assumptions ϕ (finite paths)
Test chain: from initial states I via all ϕs to final states F
SLIDE 21
Chaining Test Cases
Temporal logic safety specification: Set of properties, e.g., of type G
- mode = ON ∧ speed = 1 ∧ dec
- assumption ϕ
⇒ X(speed = 1)
- Test goals: set of assumptions ϕ (finite paths)
Test chain: from initial states I via all ϕs to final states F Approach
1
Abstraction: property reachability graph
2
Optimisation: shortest path
3
Concretisation: compute concrete test case
SLIDE 22
Abstraction: Property Reachability Graph
Weighted, directed graph: Nodes: test goals ϕ Edges:
from I to all ϕs from all ϕs to F pairwise links between ϕs
Edge weights: number of execution steps Incrementally build graph by reachability queries:
ϕ1 ϕ3 I F ϕ2 ϕ4
SLIDE 23
Abstraction: Property Reachability Graph
Weighted, directed graph: Nodes: test goals ϕ Edges:
from I to all ϕs from all ϕs to F pairwise links between ϕs
Edge weights: number of execution steps Incrementally build graph by reachability queries: K = 1
ϕ1 ϕ3 I F ϕ2 ϕ4 1 1 1
SLIDE 24
Abstraction: Property Reachability Graph
Weighted, directed graph: Nodes: test goals ϕ Edges:
from I to all ϕs from all ϕs to F pairwise links between ϕs
Edge weights: number of execution steps Incrementally build graph by reachability queries: K = 2
ϕ1 ϕ3 I F ϕ2 ϕ4 2 2 1 1 2 2 2 2 2 2 1
SLIDE 25
Existence of a Covering Path
Covering path: path that visits all nodes at least once. There is a covering path from I to F iff (1) all nodes are reachable from I, (2) F is reachable from all nodes, and (3) for all pairs of nodes (v1, v2),
(a) v2 is reachable from v1 or (b) v1 is reachable from v2.
ϕ1 I F ϕ2 Reachability can be decided in constant time on the transitive closure of the graph.
SLIDE 26
Existence of a Covering Path
Covering path: path that visits all nodes at least once. There is a covering path from I to F iff (1) all nodes are reachable from I, (2) F is reachable from all nodes, and (3) for all pairs of nodes (v1, v2),
(a) v2 is reachable from v1 or (b) v1 is reachable from v2.
ϕ1 I F ϕ2 Reachability can be decided in constant time on the transitive closure of the graph.
SLIDE 27
Existence of a Covering Path
Covering path: path that visits all nodes at least once. There is a covering path from I to F iff (1) all nodes are reachable from I, (2) F is reachable from all nodes, and (3) for all pairs of nodes (v1, v2),
(a) v2 is reachable from v1 or (b) v1 is reachable from v2.
ϕ1 I F ϕ2 Reachability can be decided in constant time on the transitive closure of the graph.
SLIDE 28
Optimisation: Shortest Path Computation
Find a covering path from I to F: Reduce to asymmetric travelling salesman problem (ATSP):
Tour that visits all nodes of a weighted directed graph exactly
- nce
Transitive closure
ϕ1 ϕ3 I F ϕ2 ϕ4 2 2 1 1 2 2 2 2 2 2 1
SLIDE 29
Optimisation: Shortest Path Computation
Find a covering path from I to F: Reduce to asymmetric travelling salesman problem (ATSP):
Tour that visits all nodes of a weighted directed graph exactly
- nce
Transitive closure
ϕ1 ϕ3 I F ϕ2 ϕ4 2 2 1 1 2 2 2 2 2 2 1 4 4 3 4 6 4 4
SLIDE 30
Optimisation: Shortest Path Computation
Find a covering path from I to F: Reduce to asymmetric travelling salesman problem (ATSP):
Tour that visits all nodes of a weighted directed graph exactly
- nce
Transitive closure
ϕ1 ϕ3 I F ϕ2 ϕ4 2 2 1 1 2 2 2 2 2 2 1 4 4 3 4 6 4 4
SLIDE 31
Optimisation: Shortest Path Computation
Find a covering path from I to F: Reduce to asymmetric travelling salesman problem (ATSP):
Tour that visits all nodes of a weighted directed graph exactly
- nce
Transitive closure
ϕ1 ϕ3 I F ϕ2 ϕ4 2 2 1 1 2 2 2 2 2 2 1 4 4 3 4 6 4 4
ATSP result: ϕ2, ϕ3, F, I, ϕ4, ϕ1 Shortest path: I, ϕ4, ϕ1, ϕ2, ϕ3, F
SLIDE 32
Concretisation: Computing the Test Chain
I
2
− → ϕ4
2
− → ϕ1
2
− → ϕ2
1
− → ϕ3
2
− → F I(s0) ∧T(s0, i0, s1) ∧ T(s1, i1, s2)∧ϕ4(s2, i2) ∧T(s2, i2, s3) ∧ T(s3, i3, s4)∧ϕ1(s4, i4) ∧T(s4, i4, s5) ∧ T(s5, i5, s6)∧ϕ2(s6, i6) ∧T(s6, i6, s7)∧ϕ3(s7, i7) ∧T(s7, i7, s8) ∧ T(s8, i8, s9)∧ F(s9) i0, . . . , i8 = gas, acc, button, dec, dec, gas, dec, brake, button
SLIDE 33
Concretisation: Computing the Test Chain
I = F OFF,0,FALSE OFF,1,FALSE OFF,0,TRUE ON,1,TRUE DIS,2,TRUE DIS,0,TRUE OFF,2,FALSE OFF,2,TRUE brake ∨ dec brake ∨ dec brake ∨ dec gas ∨ acc gas ∨ acc gas ∨ acc acc ∨ dec (p1) gas ∨ acc brake ∨ dec button button button button button (p4) button button button gas ∨ acc gas ∨ acc brake (p3) gas ∨ acc gas brake ∨ dec brake ∨ dec(p2) brake ∨ dec
SLIDE 34
Optimality
The test case chain is minimal if (1) the program and the properties admit a test chain, (2) all test goals are singleton sets, and (3) the test chain visits each property once in the K-reachability graph.
SLIDE 35
Optimality
The test case chain is minimal if (1) the program and the properties admit a test chain, (2) all test goals are singleton sets, and (3) the test chain visits each property once in the K-reachability graph. ϕ1 ϕ3 ϕ2 w1 w2
SLIDE 36
Optimality
The test case chain is minimal if (1) the program and the properties admit a test chain, (2) all test goals are singleton sets, and (3) the test chain visits each property once in the K-reachability graph. ϕ1 ϕ3 ϕ2 w1 w2 w < w1 + w2
SLIDE 37
Optimality
The test case chain is minimal if (1) the program and the properties admit a test chain, (2) all test goals are singleton sets, and (3) the test chain visits each property once in the K-reachability graph. ϕ1 ϕ3 ϕ2 w1 w2 w < w1 + w2 Reachability diameter d = length of maximum, shortest path between any two states There is a K ≤ d such that, under the preconditions (1) and (2), the test chain is minimal. In practice, fix a bound K and obtain minimised chain.
SLIDE 38
Optimality
The test case chain is minimal if (1) the program and the properties admit a test chain, (2) all test goals are singleton sets, and (3) the test chain visits each property once in the K-reachability graph. ϕ1 ϕ3 ϕ2 w1 w2 w < w1 + w2 Reachability diameter d = length of maximum, shortest path between any two states There is a K ≤ d such that, under the preconditions (1) and (2), the test chain is minimal. In practice, fix a bound K and obtain minimised chain.
SLIDE 39
Multi-State Test Goals
I ϕ1 ϕ2 F 1 2 2 2 2 p1 : G
- mode = OFF ∧ ¬enable ∧ button ⇒ X enable
- p2 : G
- mode = ON ∧ brake ⇒ X(mode = DIS)
SLIDE 40
Multi-State Test Goals
I ϕ1 ϕ2 F 1 2 2 2
- 2
Broken chain
SLIDE 41
Multi-State Test Goals
I ϕ1 ϕ2 F 1 1 2 2 2 2 Broken chain Path I, ϕ1, ϕ2 not feasible in a single step, but requires two steps.
SLIDE 42
Multi-State Test Goals
I ϕ1 ϕ2 F 1 1 2 2 2 2 Broken chain Path I, ϕ1, ϕ2 not feasible in a single step, but requires two steps. Chain repair Systematically increase edge weights of failed subpath Minimality lost
SLIDE 43
Multi-State Test Goals
I ϕ1 ϕ2 F 1 1 2 2 2 2 Broken chain Path I, ϕ1, ϕ2 not feasible in a single step, but requires two steps. Chain repair Systematically increase edge weights of failed subpath Minimality lost Completeness Succeeds if path admits chain in concrete program If for each test goal the states are strongly connected In practice: many systems are (almost) strongly connected.
SLIDE 44
General Case
Completeness Not strongly connected systems:
Abstraction refinement
SLIDE 45
Abstraction Refinement
I ϕ1 ϕ2 F 1 2 2 2 2
SLIDE 46
Abstraction Refinement
I ϕ1 ϕ2 F 1 2 2 2 2 Abstraction refinement: I ϕ1 ϕ2 F 1 2 2 2 2 2 2
SLIDE 47
Abstraction Refinement
I ϕ1 ϕ2 F 1 2 2 2 2 Abstraction refinement: Find any path I ϕ1 ϕ2 F 1 2 2 2 2 2 2
SLIDE 48
Abstraction Refinement
I ϕ1 ϕ2 F 1 2 2 2 2 Abstraction refinement: Optimise with TSP solver I ϕ1 ϕ2 F 1 2 2 2 2 2
SLIDE 49
Abstraction Refinement
I ϕ1 ϕ2 F 1 2 2 2 2 Abstraction refinement: Optimise with TSP solver I ϕ1 ϕ2 F 1 2 2 2 2 2
SLIDE 50
General Case
Completeness Not strongly connected systems:
Abstraction refinement
SLIDE 51
General Case
Completeness Not strongly connected systems:
Abstraction refinement More general solver than TSP solver, e.g. ASP solver
SLIDE 52
General Case
Completeness Not strongly connected systems:
Abstraction refinement More general solver than TSP solver, e.g. ASP solver
Multiple chains :
Partitioning by graph colouring
SLIDE 53
General Case
Completeness Not strongly connected systems:
Abstraction refinement More general solver than TSP solver, e.g. ASP solver
Multiple chains :
Partitioning by graph colouring
Optimality Would require to optimise over concrete system In practice, minimised rather than minimal solutions relevant
SLIDE 54
Implementation
reactive system model C code generator static analyser properties ChainCover test suite
SLIDE 55
Implementation
Properties specified as C functions:
void p 1 ( i o t ∗ i , s t a t e t ∗ s ) { CPROVER assume( s− >mode== ON && s− >speed==1 && i− >dec ) ; compute ( i , s ) ; as s er t ( s− >speed ==1); }
Woven into program during test case generation. BMC engine of Cbmc Property reachability graph construction Exploits incremental SAT solving Chain repair by concrete chaining Lkh travelling salesman problem solver Clingo answer set programming solver
SLIDE 56
Benchmarks and Comparison
Benchmarks Cruise control model Window controller Car alarm system Elevator model Robot arm model Comparison with FShell: a BMC-based test generator with test suite minimisation Random case generator with test suite minimisation Klee: a test case generator based on symbolic execution
SLIDE 57
Results: Test Case Length
ut ut ut ut ut ut ut ut ut ut ut ut ut
* * * * * * * * * * * * *
ld ld ld ld ld ld ld ld ld ld ld rs rs rs rs rs rs rs
50 100 150 200 250 300 350 400 450 500 550 600 650 1 2 3 4 5 6 7 8 9 10 11 12 Number of benchmarks Accumulated test case lengths
KLEE ♦ RANDOMTEST
∗ FSHELL
△ CHAINCOVER
SLIDE 58
Results: Test Case Generator Runtime
1000 2000 3000 4000 5000 1 2 3 4 5 6 7 8 9 10 11 12
ut ut ut ut ut ut ut ut ut ut ut ut
* * * * * * * * * * * *
ld ld ld ld ld ld ld ld ld ld rs rs rs rs rs rs
Accumulated runtimes Number of benchmarks
KLEE ♦ RANDOMTEST
∗ FSHELL
△ CHAINCOVER
SLIDE 59
Summary and Current Work
Summary Test chain for reactive systems
Test goals from requirements, specification model, code coverage criteria
Minimal test chain for single-state test goals, otherwise heuristics Experimental evaluation Application: on-target testing, acceptance testing Current work Integrate acceleration to handle deep loops Test chains for code coverage criteria, e.g. MC/DC Further questions Incremental test chain generation
In the case of model modifications When test execution gets stuck due to a failed test goal
SLIDE 60