1
WODA 2008 July 21, 2008
Random Testing and Model Checking: Building a Common Framework for Nondeterministic Exploration
Alex Groce and Rajeev Joshi
Jet Propulsion Laboratory, California Institute of Technology
Random Testing and Model Checking: Building a Common Framework for - - PowerPoint PPT Presentation
Random Testing and Model Checking: Building a Common Framework for Nondeterministic Exploration Jet Propulsion Laboratory, California Institute of Technology Alex Groce and Rajeev Joshi WODA 2008 July 21, 2008 1 Background &
1
WODA 2008 July 21, 2008
Jet Propulsion Laboratory, California Institute of Technology
2
WODA 2008 July 21, 2008
3
WODA 2008 July 21, 2008
4
WODA 2008 July 21, 2008
5
WODA 2008 July 21, 2008
6
WODA 2008 July 21, 2008
7
WODA 2008 July 21, 2008
Our focus in this talk (dynamic: like testing) (“static”)
8
WODA 2008 July 21, 2008
State already visited! Backtrack and try a different operation Done with test! Backtrack and try a different operation CFG State already visited! Backtrack and try a different operation Will explore, as a side-effect, many executions (like random testing) but the goal is to explore states
m kdi r / a m kdi r / a m kdi r / b m kdi r / b m kdi r / c m kdi r / c m kdi r / a m kdi r / a r m di r / a r m di r / a
9
WODA 2008 July 21, 2008
10
WODA 2008 July 21, 2008
Execute C code until control returns to SPIN Push tracked & matched state on stack Has state been visited before? Store matched state in state table Backtrack: pop stack & restore tracked & matched state Y N
11
WODA 2008 July 21, 2008
Execute C code until control returns to SPIN Push tracked & matched state on stack Has state been visited before? Store matched state in state table Backtrack: pop stack & restore tracked & matched state Y N
12
WODA 2008 July 21, 2008
13
WODA 2008 July 21, 2008
Test engineer using a model checker on a C program?
14
WODA 2008 July 21, 2008
15
WODA 2008 July 21, 2008
16
WODA 2008 July 21, 2008
17
WODA 2008 July 21, 2008
18
WODA 2008 July 21, 2008
i nt i nt x; x; i nt i nt y; y; act i ve p t i ve pr oct ype m r oct ype m ai n ( ai n ( ) { { i f i f : : : : x = 1 x = 1 : : : : x = 2 x = 2 f i ; f i ; asser t ( ser t ( x = == y y) ; }
Start simple This model has 7 states What are they? State = (PC, x, y) 1 2 3 5 7 SPIN’s nondeterministic choice construct Picks any one of the choices that is enabled How do we guard a choice? i f i f : : : : ( x < 10) ( x < 10) - > y = 1
: : : : ( x < 5) ( x < 5) - >
y = 3 : : : : ( x > 1) ( x > 1) - >
y = 4 f i ; f i ; Not mutually exclusive!
19
WODA 2008 July 21, 2008
i nt x; i nt x; i nt y; i nt y; act i ve pr oct ype m ai n ( ) act i ve pr oct ype m ai n ( ) { i f i f : : x = : : x = 1 : : x = : : x = 2 f i ; f i ; i f i f : : y = : : y = 1 : : y = : : y = 2 f i ; f i ; i f i f : : x > y - > x = y : : x > y - > x = y : : y > x - > y = x : : y > x - > y = x : : el se - > ski p : : el se - > ski p f i ; f i ; asser t asser t ( x == y) ; ( x == y) ; }
This model has 17 states What are they? State = (PC, x, y) 1 2 3 5 7 9 13 14 15 17 Er… Don’t worry about state-counting too much – SPIN has various automatic reductions and atomicity choices that can make that difficult
20
WODA 2008 July 21, 2008
i nt i nt x; x; act i ve p t i ve pr oct ype m r oct ype m ai n ( ai n ( ) { { x = x = 0; 0; do do : : ( x < : : ( x < 10) - > x++ 10) - > x++ : : br eak : : br eak
/ * H / * Her e, x er e, x i s a anyt hi ng b nyt hi ng bet ween et ween 0 a and nd 9 i i ncl usi ve ncl usi ve * /
Only a couple more PROMELA constructs to learn for building test harnesses: the do do loop Like i f i f , except it introduces a loop to the top – br eak br eak choice can exit the loop This nondeterministically assigns x a value in the range 0…9
21
WODA 2008 July 21, 2008
i nl i ne p l i ne pi ck ( i ck ( var , M var , M AX) AX) var var = = 0; 0; do do : : ( var < : : ( var < M AX) - > var ++ M AX) - > var ++ : : br eak : : br eak
i nl i ne i nl i ne gives us a macro facility As you can imagine, this is a useful macro for building a test harness!
22
WODA 2008 July 21, 2008
: : choi ce == UNLI NK - > / * unl i nk * / pi ck( pat hi ndex, NUM _PATHS) ; / * Choose a pat h * / c_code { c_code {
nvf s_unl i nk ( pat h[ now. pat hi ndex] ) ; } ; } ; nvf s_er r no = nvf s_er r no = c_expr { er r no} ; c_expr { er r no} ; check_r eset ( ) ; / * Check f or syst em r eset and r ei ni t i f needed * / i f : : ( r es < 0) && ( nvf s_er r no == ENO SPC) - > / * I f out - of - space er r or * / check_space( ) ; : : ( ( ! di d_r eset ) | | ( r es ! = - 1) ) && ! ( ( r es < 0) && ( nvf s_er r no == ENO SPC) ) - > c_code{ c_code{
f s_r es =
f s_r es = r am f s_unl i r am f s_unl i nk ( pat h[ now. pat hi ndex] ) ; nk ( pat h[ now. pat hi ndex] ) ; } ; } ; r am f s_er r no = r am f s_er r no = c_expr { er r no} ; c_expr { er r no} ; : : el se - > ski p f i ; . . . asser t ( r es == r am f s_r es) ; asser t ( nvf s_er r no == r am f s_er r no) ;
Finally, we want to be able to call the C program we are testing
23
WODA 2008 July 21, 2008
24
WODA 2008 July 21, 2008
i nl i ne p l i ne pi ck ( i ck ( var , M var , M AX) AX) var var = = 0; 0; do do : : ( var < : : ( var < M AX) - > var ++ M AX) - > var ++ : : br eak : : br eak
What if we change pick?
25
WODA 2008 July 21, 2008
i nl i ne p l i ne pi ck ( i ck ( var , M var , M AX) { AX) { i f i f : : ! ! i ni t i al i zed - ni t i al i zed - > nondet _pi ck( seed, S
E) ; EED_RANG E) ; c_code{ _code{ pr i nt f ( r i nt f ( “ Test w “ Test wi t h s i t h seed % eed % d\ n” , d\ n” ,
sr andom ( now. seed) ; r andom ( now. seed) ; } ; } ; i ni t i al i zed = ni t i al i zed = 1 : : el se : : el se - > ski p
f i ; f i ; var r = c c_expr { r andom ( ) } _expr { r andom ( ) } % M M AX; AX; }
To this?
26
WODA 2008 July 21, 2008
27
WODA 2008 July 21, 2008
78 79 80 81 82 83 84 85 86 87 50 100 150 200
Minutes % Coverage
Model Checking Random Testing
28
WODA 2008 July 21, 2008
75.2 75.25 75.3 75.35 75.4 75.45 75.5 75.55 50 100 150 200
Minutes % Coverage
Model Checking Random Testing
29
WODA 2008 July 21, 2008
10 20 30 40 50 60 70 50 100 150 200
Minutes Abstract states covered
Model Checking Random Testing
30
WODA 2008 July 21, 2008
5 10 15 20 25 30 35 40 50 100 150 200
Minutes Abstract states covered
Model Checking Random Testing
31
WODA 2008 July 21, 2008
32
WODA 2008 July 21, 2008