Professional Documents
Culture Documents
Tutorial 2012
Tutorial 2012
with PathCrawler
A Tutorial
Nicky.WILLIAMS@cea.fr, Nikolai.KOSMATOV@cea.fr,
CEA, LIST, Software Safety Lab
Saclay (Paris), France
2012
…….
PathCrawler
1
Outline
…….
PathCrawler
2
Outline
…….
PathCrawler
3
Structural vs. functional testing
Specification Analysis
Functional: specified properties functional tests activate
specified behaviour
Oracle
test results Implementation
verdict
Specification Analysis
Structural: specified properties structural tests activate
implemented behaviour
Oracle
test results Implementation
verdict
…….
PathCrawler
4
Unit structural testing is useful
…….
PathCrawler
5
Unit structural testing can be mandatory
…….
PathCrawler
6
CFG and code coverage by example
C code control-flow graph (CFG) statement coverage
1 int f(int x){ x<0? x<0
+
2 if(x < 0) x=x+1
- x=x+1
3 x = x + 1; x != 1
4 if(x != 1) x != 1 ? + x = 2*x
5 x = 2*x; - x = 2*x
6 return x; }
x == 1
…….
PathCrawler
7
Path predicate (path condition) by example
C code control-flow graph (CFG) path predicate
1 int f(int x){ x<0? +
+
2 if(x < 0)
- x=x+1
3 x = x + 1; +
4 if(x != 1) x != 1 ? +
5 x = 2*x; - x = 2*x
6 return x; }
x0< 0 /\ (x0 + 1) ≠ 1
+
- infeasible path
- - unsatisfiable path
predicate
x0 >= 0 /\ x0 = 1 x0 < 0 /\ (x0 + 1) = 1
…….
PathCrawler
8
Automated structural testing… Why?
…….
PathCrawler
9
Outline
…….
PathCrawler
10
PathCrawler tool
…….
PathCrawler
11
PathCrawler explores the tree of feasible paths
…….
PathCrawler
12
PathCrawler explores the tree of feasible paths
…….
PathCrawler
13
PathCrawler explores the tree of feasible paths
…….
PathCrawler
14
PathCrawler explores the tree of feasible paths
-2 x0 ≥ 0
…….
PathCrawler
15
PathCrawler explores the tree of feasible paths
test2: x = 25 -2 +4 x0 ≥ 0 /\ x0 ≠ 1
x0 ≠ 1
x1 = 2x0
…….
PathCrawler
16
PathCrawler explores the tree of feasible paths
test2: x = 25 -2 +4 x0 ≥ 0 /\ x0 ≠ 1
x0 ≠ 1
x1 = 2x0
-4 x0 ≥ 0 /\ x0 = 1
…….
PathCrawler
17
PathCrawler explores the tree of feasible paths
test2: x = 25 -2 +4 x0 ≥ 0 /\ x0 ≠ 1
x0 ≠ 1
x1 = 2x0
test3: x = 1 -4 x0 ≥ 0 /\ x0 = 1
…….
PathCrawler
18
pathcrawler-online.com
…….
PathCrawler
19
Example 1. Robust implementation of Tritype
…….
PathCrawler
20
PathCrawler outputs
…….
PathCrawler
21
Outline
…….
PathCrawler
22
Example 2. Non robust implementation of Tritype
…….
PathCrawler
23
Exercise 3. Customize test parameters for Tritype
…….
PathCrawler
24
Example 4. C Precondition for Tritype
…….
PathCrawler
25
Test parameters
…….
PathCrawler
26
Example 5. Merge with default parameters
…….
PathCrawler
27
Exercise 6. Quantified precondition for Merge
If the input arrays t1 and t2 are not ordered, Merge does not work!
…….
PathCrawler
28
Example 7. Merge with pointer inputs
…….
PathCrawler
29
Exercise 8. Input arrays (pointers) size
t1, t2, t3 should contain resp. l1, l2, l1+l2 allocated elements.
Wrong input array size => Runtime errors while executing tests!
Exercise. Start from Example 7. “Customize test parameters”
- Specify domains for dim(t1), dim(t2) , dim(t3)
0 <= dim(t3) <= 6
0 <= dim(t2) <= 3
0 <= dim(t1) <= 3
- Add three unquantified preconditions:
dim(t1) == l1
dim(t2) == l2
dim(t3) == l1 + l2
- Confirm parameters and check the results.
How many test cases are generated?
…….
PathCrawler
30
Partial test coverage : k-path criterion
…….
PathCrawler
32
Outline
…….
PathCrawler
33
Oracle
Role of an oracle:
• examines the inputs and outputs of each test
• decides whether the implementation has given the expected
results
• provides a verdict (success, failure)
…….
PathCrawler
34
Example 10a. Oracle and debugging
…….
PathCrawler
35
Example 10b. Oracle and debugging
…….
PathCrawler
36
Example 10c. Oracle and debugging
…….
PathCrawler
37
Outline
…….
PathCrawler
38
Structural test for other properties or purposes
PathCrawler explores the implementation and can also be used to check:
• for runtime errors during program execution (seen in Ex.7)
• for anomalies detected during analysis of the covered paths:
• uninitialised variables
• buffer overflow
• integer overflow
• …
• whether the implementation performs unnecessary computation
• the effective execution time of each path (at least for one set of inputs),
by running the generated tests on a platform which can measure
execution time
• for unreachable or “dead” code: check infeasible partial paths.
If all paths leading to the code are infeasible then the code is
unreachable (for the given precondition): is this intentional ?
…….
PathCrawler
39
Runtime error or anomaly: search space is pruned
TC_1 TC_1
TC_2 TC_2
TC_3 TC_3
incomplete coverage
error during test execution or
TC_4
anomaly detected by analysis
…….
PathCrawler
40
Example Uninit. Uninitialised variable
…….
PathCrawler
41
Example UC. Unnecessary computation
…….
PathCrawler
43
Dichotomic search: structural vs. other strategies
Example: dichotomic search for a value int x in a sorted array int A[10].
Random testing: Unlikely to construct cases in which x equals one of the
elements of A and to detect false negatives (x not detected when present)
Functional testing: Constructs
• many cases in which x is present (probably from 1 to 10?) and
• fewer cases in which x is absent (1 or 2 ?)
Structural testing: Constructs a case
• for each position in A for which x can be detected and
• for each relation to elements of A for which absence of x is detected.
Structural test constructs more presence cases than random, more absence
cases than functional, rarely constructs cases where x is present by chance.
…….
PathCrawler
44
Example Chance. Failures by chance?
…….
PathCrawler
46
Limitations of structural testing
Path testing is
• effective when a bug is always revealed by a path,
• less so when only some of the values which activate
the path cause the bug to be revealed
…….
PathCrawler
47
Outline
…….
PathCrawler
48
Cross-checking conformity with a specification
x0<0 + x1≠1 +
x1 = x0+1 imp = 2x1
- x0≠1 +
imp = 2x0
-
imp = x0
implementation
int f(int x){
if(x < 0)
x = x + 1;
if(x != 1)
x = 2*x;
return x; }
…….
PathCrawler
49
Cross-checking conformity with a specification
x0<0 + x1≠1 +
x1 = x0+1 imp = 2x1
- x0≠1 +
imp = 2x0
-
imp = x0
implementation specification
int f(int x){
if(x < 0) If x is less than 1 then
x = x + 1;
if(x != 1)
the result should be 2(x + 1)
x = 2*x; else the result should be 2x
return x; }
…….
PathCrawler
50
Cross-checking conformity with a specification
x0<0 + x1≠1 + x0<1 +
x1 = x0+1 imp = 2x1 spec = 2(x0+1)
- + -
x0≠1 spec = 2x0
imp = 2x0
-
imp = x0
implementation specification
int f(int x){ int spec_f(int x){
if(x < 0) if(x < 1)
x = x + 1; x = 2*(x + 1);
if(x != 1) else
x = 2*x; x = 2*x;
return x; } return x; }
…….
PathCrawler
51
Cross-checking conformity with a specification
x0<0 + x1≠1 + x0<1 + imp=spec + OK
x1 = x0+1 imp = 2x1 spec = 2(x0+1)
- + - - BUG
x0≠1 spec = 2x0
imp = 2x0
-
imp = x0
…….
PathCrawler
52
Cross-checking conformity with a specification
x0<0 + x1≠1 + x0<1 + imp=spec + OK
x1 = x0+1 imp = 2x1 spec = 2(x0+1)
- + - - BUG
x0≠1 spec = 2x0
imp = 2x0
-
imp = x0
-
spec = 2x0
…….
PathCrawler
53
Cross-checking conformity with a specification
x0<0 + x1≠1 + x0<1 + imp=spec + OK
x1 = x0+1 imp = 2x1 spec = 2(x0+1)
- + - - BUG
x0≠1 spec = 2x0
imp = 2x0
-
imp = x0
x0<0 + x1≠1 + +
x0<1 x0 < 0 /\ (x0+ 1) ≠ 1 /\ x0 < 1 → x0 < 0
x1 = x0+1 imp = 2x1 spec = 2(x0+1)
x0 < 0 /\ (x0+ 1) ≠ 1 /\ x0 ≥ 1
…….
PathCrawler
54
Cross-checking conformity with a specification
x0<0 + x1≠1 + x0<1 + imp=spec + OK
x1 = x0+1 imp = 2x1 spec = 2(x0+1)
- + - - BUG
x0≠1 spec = 2x0
imp = 2x0
-
imp = x0
…….
PathCrawler
55
Cross-checking conformity with a specification
x0<0 + x1≠1 + x0<1 + imp=spec + OK
x1 = x0+1 imp = 2x1 spec = 2(x0+1)
- + - - BUG
x0≠1 spec = 2x0
imp = 2x0
-
imp = x0
…….
PathCrawler
56
Cross-checking conformity with a specification
x0<0 + x1≠1 + x0<1 + imp=spec + OK
x1 = x0+1 imp = 2x1 spec = 2(x0+1)
- + - - BUG
x0≠1 spec = 2x0
imp = 2x0
-
imp = x0
- x0 ≥ 0 /\ x0 ≠ 1 /\ x0 ≥ 1 → x0 > 1
spec = 2x0
…….
PathCrawler
57
Cross-checking conformity with a specification
x0<0 + x1≠1 + x0<1 + imp=spec + OK
x1 = x0+1 imp = 2x1 spec = 2(x0+1)
- + - - BUG
x0≠1 spec = 2x0
imp = 2x0
-
imp = x0
- + + x0 = 0 /\ 2x0 = 2(x0+1)
x0≠1 x0<1 imp=spec OK
imp = 2x0 spec = 2(x0+1) - BUG x0 = 0 /\ 2x0 ≠ 2(x0+1)
- imp=spec + OK x0 > 1 /\ 2x0 = 2x0
spec = 2x0
BUG
x0 > 1 /\ 2x0 ≠ 2x0
…….
PathCrawler
58
Cross-checking conformity with a specification
x0<0 + x1≠1 + x0<1 + imp=spec + OK
x1 = x0+1 imp = 2x1 spec = 2(x0+1)
- + - - BUG
x0≠1 spec = 2x0
imp = 2x0
-
imp = x0
…….
PathCrawler
59
Example 12. Testing conformity with a specification
…….
PathCrawler
61
Searching for run-time errors or anomalies
…….
PathCrawler
62
Example 13. Searching for run-time errors (1)
…….
PathCrawler
63
Example 14. Searching for run-time errors (2)
…….
PathCrawler
64
The SANTE method: Static ANalysis and TEsting
…….
PathCrawler
65
Conclusion
…….
PathCrawler
66
Extra exercises
…….
PathCrawler
67