Tải bản đầy đủ (.pdf) (81 trang)

A parameterized unit test framework based on Java PathFinder

Bạn đang xem bản rút gọn của tài liệu. Xem và tải ngay bản đầy đủ của tài liệu tại đây (27.87 MB, 81 trang )

ж
/К - г /
îm
A Parameterized Unit Test Framework
Based on Java PathFinder
VU THANH NHAN
Faculty of Information Technology
University of Engineering and Technology
Vietnam National University. Jirtnoi
Advisor:
TRỪỐNG ANH HOANG, Ph.D.
A th e s is s u b m i t te d in f u lf il l m e n t o f t h e r e q u ir e m e n ts f o r th e d e g r e e o f
M a s t e r o f I n f o r m a t i o n T e c h n o lo g y
D e c e m b e r , 2Ö Ü 9
C A I H O C Q U O C G iA H À N Ó I
T D IJN S ไ Ấ M T H Õ N G TIN TH Ư V IẼ N
A

ì ù ị M
Table of Contents
1 I n t r o d u c t i o n 1
1.1 丁 lie m o t i v a t i o n 3
1/2 O u r s o lili i o n 3
1.3 C o n t r ib u t i o n 5
1.4 T h e s is st i uc t u i e 5
2 A u t o m a t i c t e s t d a t a g e n e r a t i o n 7
2.1 T est. a ( l(4 |tia c y c r i t e r i a 8
2 .1 .1 D a t a -H o w o rie n te d a d e q u a c y c r it e r ia
9
2 .1 .2 C o n t r o l- f lo w o rie n te d a d e q u a c y c r i t e r i u 1Ü
2 .2 U n i t le s t a n d P a ra m e te riz e d U n it T e s t 11


2 .2.1 U n i t T e s t 11
2 .2 .2 IV u c iM ie te riz e d U n it T e s t . 13
2 .3 T e s t in p u t g e n e r a t io n b y s y m b o lic e x e c u ti o n 15
2 .3 .1 S y m b o lic e x e c u t i o n 1ช
2 .3 .2 C J o iiť ia liz e d s y m b o lic e x e c u tio n w it h la z y i n it ia liz a t io n 20
2 .3 .3 C o d e i lis t ru in e n t a t io n fo r s y m b o lic e x e c u ti o n 22
T e s t c a s e s g e n e r a t i o n w i t h J P F 2 4
3. ] T e s t D a ta G e n e r a t o i 2 6
3 .2 A ic l iit( 4 * t iu e o f S y m b o lic J a v a P a t h F i i i d i T 28
3 .2 .1 T h e I n s t r u c t io n ドm t m y 29
3 .2 .2 A t t r ib u t e s fo r s to r in g s v n ib o lic i n f o r m a t i o n 31
3 .2 .3 l i a ỉì d lin g Ы а ш іііп ц c o n d itio ijs w it 11 C liu ic c C !(sn e ra l.(> rs

3 2
3 .2 .1 Sc、w r a l e x a m p le s o f s y m b o li c e x t'( u t u)H in S y m b o lic 115 F .
.
. 3 5
3 .2 .5 J P K L is te n e r ^ 3 0
T A B L E O F C O N T E N T S
p U T F r a m e w o r k 4 2
1.1 1>1*1 F ra m e w o r k o v e r v i e w 12
1.2 M a i n c o m p o n e n ts o f І Ч Г Г Р г а и к л ѵ о г к i l
1 ,2 .] P U T R u im e i 4 4
1 .2 :2 P U T L is te n e r 48
1 .2 .3 P U T D r i v e i 5 0
L 3 C o n f ig u r e a n d e x e c u te P U T F r a m e w o r k
5 0
4. J S e v e ra l e x a m p l e s 51
E x p e r i m e n t a t i o n a n d d is c u s s i o n 5 5
5 . 1 Iix |> t vi im e n t a l r e s u l t 5 5

5 .2 R e la te d w o r k s 5 8
5 .3 F u t u r e r e s e a r c h 5 9
C o n c l u s io n s 6 1
C o r e c o m p o n e n t s o f J P F 6 3
A . l I m p le m e n t a tio n o f p с C h ü ic e C ener a t OI' fo r iiitc g e i n u m b e r

6 3
A . 2 S y m b o lic im p le m e u t a t i o ii e x a m p l e s 6 4
A .3 M e th o d s o f V M L is t. e n e r i n t e r f a c e 6 7
A . I M e t h o d s o f S e a rc h L is te n e r i n t e r f a c e
68
I m p o r t a n t P U T F r a r n e w o r k c o m p o n e n t s 6 9
B . I M a in m e th o d o f P U T R u n n e r 69
B .2 Iii ip le m e i i t a ti o n o f P U T D r i v e t 70
Ỉ * บ fr L i s te n e r a n d im p o r t a n t m e t h o d s 71
List of Figures
1.1 F r a m e w o r k o v e r v ie w 4
2.1 E x a m p le o f U T a n d P U T 12
2 2
R e la tio n s h ip b e tw e e n U T a m i P U T Ы
2 .3 E x a m p le o f s y m b o li c e x e c u ti o n 17
З Л J P F h ig h - le v e l s t r u c t u re 2 6
3 .2 A r c h it e c t li r e o f a te s t ( la ta g e n e r a t o r
*27
3 .3 B y te c o d e F a c to rie s fo r c o n c re te a n d s y m b o lic e x e c u tio n 3 0
3.1 A t t r i b u t e s t o r i n g i l l S y m b o lic J F F 3 2
3 .5 С 1 ic)i c e C e n e r a t o r s m o t iv a t io n 3 4
3 .6 J a v a P a t h F in d e i L is t e n e r p a t t e r n 3 7
3 .7 D e p th f i r s t se a rc h I iu tit ic a t iu n a u t o m a t io n 3 8
Ỉ.1 P U iT V a m e w o r k c o m p o n e n ts ' c o - o p e r a tio n 4 5

Л .1 T w o im p lc m e n t a tk m s o f
IA DU
in s t r u c t io n 64
A . 2 T w o i m p le m e n ta t io n s o f
IFGbj
.s ta te m e n t 66
Chapter 1
Introduction
T lie r o a re m a n y е х ш п р іе у o f h u g e H n a n c ia l loss e s (e .g . A r ia n e 5 flig h t 5Ü1 c r a s h ,
M a r s E x p lo r a t io n R o v t'1 S p ir it t n a liim c tio n ( V is s e i ( 't ฟ . , 2 0 0 1 a )) o r ОѴЧМІ t lie c o s t o f
lu iim in liv e s (e .g . l h e r a c - 2 5 r a d ia t io n th e r a p y ln a d iim * fa ilu r e (L e v 4 \s o n
к
T u r n e r ,
1 9 9 3 )) t h a t w e re c a u s e d b y s o ftw a re e r r o rs . T h is c o s t is as m u c h a8 m o r e u b iq u ito u s
s o ftw a r e is in th e m o d e rn life . A c c o r d in g to a r e p o r t b y th e u s N a tio n a l In s t it u te
o f S t a n d a r d s a n d T e c h n o lo g y * s o ft w a r e f a illir e z c o s t tile u s e c o n o m y $ 6 0 b illio n p e r
a n n u iíL b u t th e iin p r o v e m e n ts in s o ftw a r e te s tin g in fia 、s t r u c t u r e a re s t ill lim ite d ,
w h ile i t c :o u ld s a w o n e - th il d o f t h is c o s t ( N IS T , 2 0 0 2 ). S o ftw a r e t e s tin g is a il
im p u i ta n t p a r t o f s o ftw a r e d e v e lo p riio u t. p ro c e s s e s a n d is a b o u t h a lf o f th e t o ta l c o s t

s o ft w a r e d e v d o p u u m t; a n d m a i iit c iia t ic e (B e id e r, 1 9 9 0 ).
T e s tin g h a s m a n y d e f in it io n s , h ilt th e c o rn in o li id e a b e h in d tiie s e r e fe r s t o a
p ro c e s s o f in c r e a s in g tr u s t a b o u t th o c o rre c t ness o f a p ro g r a r iL T h e o n ly w a v to
ц и а і
iìììive
c o rr e c t 1HJSS o f a p ro g r a m is e x e c u tin g i t o n a ll p o s s ib le in p u t s , b u t t h is
IS u s u a lly im p o s s ib le . F o r fe a s ib ility , w e b u ilc l ÍỊ
iịựị
u ť iu p u t« s u t l m t th e y le a d to
tin d t i le m a x im u m n u m b e r o f e rro rs . T h e re fo r e , th e fir s t s te p o f te s tin g is s e le c tin g

Л
le p K 's e n t a tiv e se t o f in p u t s . In p u t fo r a s in g le to s t is c a lle d
test (lata
o r
test

'ĩìpiit.
A ft e r te s t (la ta s e le c tio n ,
test omeli'
is น•ร(ฟ่ t o a v a llia t e t h r c o r r e c tn e s s o f
I lu* b e h a v io u r o f th e p i o g ra n i. ты、c o in b iiia t io n o f
teat data
a n d th e ( o r r e s p o n d ijig
oraflc
m a k e s a
u:sf (.me.
A ll t) f
lest mptii
o f a lo g ic a l g r o u p o f te s ts m a k e a
test Sid

()1
test suite
( llia n to la . 2 0 0 6 ).
IV s t iu g c a n b e c m ii t n l o u t i l l s e v e ra l w a y s :
Mdììỉtal ivsfnty
c n ii b e e x t n 'ii i r lv la b o u r in te n s iv e a n d ta k e s a lo t o f t im e c ind
Hit )1 !(>>•.
1
2

C h a p te r 1. Intro d u c tio n
Randům tts iifiij
ftiM ie ra te s r a iid o m d a t a , u s u a lly u s in g a s t r e a m o f h its , w h ic h
i t s e n d s to th e p r o g r a m as in p u t p a n im e te r s . I h e m a in a tI v a n ta g e o f t h is m e t h o d
is

it s s im p lic ity , it a ls o i.c q iiiie s a li t t l e 1Ш Ч 1Ю 1Ѵ a n d o t h e r m a d ii n e re s o u rc e s . H o w e v e r ,
w it h t h is a p p ro a c h o n e p a th m a y h e e x e c u te d m a n y tim e s , a n d s o m e p a t h s a r e
( li l iic u lt to g e t e x e c u te d o r th e a ( k 、q u a < :y c r it e r ia ( Z h u e t a l. . 1 9 9 7 ) is ( lif f i ť i i l r t o
a c h ie v e .
Symbolic txccution
c a n re s o lv e th e d r a w b a c k s o f t a n d o in te s tin g . I l l th is m e th o d
th e v a ria b le s t h a t n o r m a ll V c o n ta in c o n c re te v a lu e s a r e re p la c e d b y t h e ir s y m b o lic
c o im h n .p a rts , w h ic h e x p re s s a ra n g e o f p a s s ib le v a lu e s u s in g s y m b o lic e x p r e s s io n s .
lJa ,se (l o n th is s y m b o lic d a ta , th e m o d e l c h e c k e r g e n e r a te s a n i n p u t d a t a s e t th a t
c o v e rs a ll o f p o s s ib le e x e c u tio n s o f th e p r o g r a iib I t u s u a lly In q u ir e s e x le in a l s o lv e rs
( K n ) e n iu g &: S t i ic l i n n u i , 2 0 0 8 ) t o fin d th e s o iu tio n s fo r s y m b o lic e x p re s s io n s . A u t o -
n ia t ( 、(l te s tin g h e lp s le d I ICO t h e ť o s t o ť p i o d i i d n g s o ftw a re a n d in c r e a s e s t l u 、r e l i a b i lit y
o f th e s o ftw a re .
In 2 0 0 5 ,D ire c ttH Ỉ A u t o m a t e d R a n d o m T e s tin g s - D A R T ( G o d e fr o id e t ฟ . า 2 0 0 5 )
m in k s I lie b o rn o f a n e w t e s tin g a p p ro a c h w h ic h is t il e c o m b in a t io n o f la n d o in t e s tin g
a n d s y n ib o lic e x e c 'u tio n . T h e id e a o f t h is a p p r o a c h is s t a rt i n g t h e u n d e r te s t ỊM O g ra m
w ii h ra n d o m v a lu e s o f p a ra m e te r s , ( h ir ii i g t ile e x e c u ti o n u f u n d e r te s t |> K >ftra in , t h e
p a ỉ h c o n s tra in s a n 、c o lle c t e d . A c o n s t r a in t .รบ!v e r is u s e d to s o lv e p a t h c o n s tr a in s
t o g e n e ra te v a lu e s o f [) a ia iu e t e r s t h a t fo rc e t h e u n d e r t e s t p r o g r a m e x e c u te fo llo w
(•() m \s |> o iid ia g p a th . T h is a p p ro a c h c a lle d
coricali с testing
a ls o . A n o t h e r n a m e o f
th is a p p ro a c h is d y n a m ic s y m b o lic e x e c u tio n w h ic h in t r o d u c e in S e c tio n 2 .3 .
I l l th is th e s is ,

\\v
a re c o ijc e r iio d w it h (u m b i n in g t w o fLiěaxS OÍ te s t in g : t(,\st c a se s
[і;('И {ьгм (.іоп a n d e x e c u t io n . H e n c e a [Ѵ а ш е ѵ ѵ о гк ( w e п а ш е it. p บ ï F r a m e w o r k ( T i li o n g
Ắ.* V u . 20 Ü 9 )) is p ro p o s e d t o g e n e ra te t ( 、s t ca'ses fu r J a v a |;K )^ ra m s a n d c x e r u te th e s e
te s t ca s e s a u t o m a t ic a lly . F o r te s t ca s e s g e n e r a t io n , th is f r a m e w o r k is b a « e d O lì J a v a
P a lili* in d (u (P a .s a r ra n u e t a l., 2 0 0 8 ) - a in o d o l d i e rk e i t h a t use s s y n ih u lic e x e c u 
tio n . F o r te s t c a s e s e x w u t io n . th e it r( 、lic s o n J 1/1 l i t , a n ()|)('n -s o u rc e te s t Ir a in e w o r k .
I l u u c í o n í , b e fo re i n t r o d u c i n g th e ( li't a il o f t h e fir im e w o i k , th is th e s is p re s e n ts s e v -
(ТН І ( lis c tis s io n s a b o n I s y m b o li c e x e cu îi(.)îL it s Iis a g o in .Java P a t l i F in d i 'i fo r te s t
( la ta g r iu T ü t io u . I n a d d it io n , th e th ( 、sis in t r o d u c e s d e t a il o f .J U n it a n d th e w a y t
he

f i ІП ІИЛѴО Ік uses t i l l s to o l ťo i t( vst CHSPS ^ e t i r r a t io n .
1 . 1 . T h e m o t i v a t io n
3
1.1 The motivation
A lth o u g h s o ftw a re » te s tin g te c h n iq u e s h a v e g a i n e d litig e i m p r o v e r iifu t s , d e v e lo p e rs
s t ill fa c e d iH i c u l î ic s in t h e ir w o r k s u c h as: t h e in s u t t ic ie n c y o f m o d e l c h e c k e rs fo r
( litf e r e n t p r o g r a m m in g la n g u a g e s , la c k o f e ffic ie n t t e c h n iq u e s f o r te s t ( rusi's g e n e r a tio n
a n d e x e c u tio n .
S P IN ( H o l/in a n n , 2Ü Ü 3) is th e m o s t p o p u la r m o d e l c h e c k e r fu r с la n g u a g e p r o
g ra m s a n d P R Ü M E L A ( a P R O r e s s M E t a L A u g u a g e ) s p e c ific a tio n s ( H o lz m a n n ,
2 0 0 3 ). A n o t h e r p o w e rfu l m o d e l c h e c k e r is P e x 1 ( P r o g r a m E x p lo r a t i o n ) o f M i c r o s o f t ,
w h ic h is d e v e lo p e d fo r c h e c k in g .N E T p ro g r a m s o n ly . J a v a is o n e o f th e m o s t p o p 
u la r p ro g ia iiin iin g la n g u a g e , b u t u n t il n o w th e r e is Î1Ü c o m p le t e m o d e l c h e c k e r fo r
p ro g ra m s w t i t l e n in th is U m g u a g e . W e s a y t h a t t h e re is
no
c o m p le to lĩio d e l c h e c k e r
ib i .Java p r o g r a m s b e c a u s e a lt h o u g h
Java Path Finder

is a m o d e l c h e c k e r fo r J a v a
p ro g ra m s , it ca n w o r k o n ly w it h p r i i n it i v e d a t a t y p e s , s u c h a s n u m e r ic a n d b o o le a n .
M o re o v e r, a lt h o u g h
Pararnetť.ňznl Unit Test
( P U T ) ( T iilm a n ii fc S c h u lte ' 20 0 5 :
T il lm a im & S c li u lte , 2 0 0 6 ) พล.ร p r o p o s e d f o r r e d u c in g th e m u i ib e r o f a-ssess te s t u n it s
t h a t te s te rs m u s t w rit e , a b ig p r o b le m is h o w to in s t a n t ia t e g iv e n P U T s t o a g o o d
s e t o f te s t caso s w h ic h s a tis fie s .s tiv e ra i c o d e co v e ra g e c r i t e r i a . S in c e MOW, th e r e a re
n u m e r o u s a p p ro a c h e s to r e s o lv e t h is p r o b le m b u t n o o n e h a s a c o m p le t e s o lu t io n .
A n d e v e n w h e n w e h a ve a g o o d s e t o f te s t c a s e s , t h e e x e c u t in g t h e m a n d t r a c k in g
\\พ
b u g s (lu riĩầ g the» e x e c u tio n is a. b ig p ro b le m . T h e s e w o rk s t a k n a l o t o f tim e .
ІШ Ш ІШ p m v ( T a n d m o n e y , es |)(4 :ÌH lly w h e n w o r k in g w i t h a. h u g e set. ฟ . te s t c;<uses.
1.2 Our solution
\ \ it l j th o a b o v e m o t iv a t io n s , o u r s o lu t io n c o n s is ts o f t w o p a r ts : in t r o d u c in g a w a y to
g e n e ra te g o o d Ỉ est,
Cdses
fr o m g iv e n P U T s a n d im p le m e n tin g a. to o l w h ic h e x e c u te s
g e n e ra te d te s t ca s t's a u t o m a t ic a lly . F ir s t , fo i te s t c a s e s g e n e r a t io n , w e u s e
Java

l^ itliF h id tr -
a ll u p e ii s o u rc e m o d e l chf.4 k c i HxS a v e ry p o w e rfu l to o l t o r r e s o lv in g th e
p r o b le m . St»('011(1. fo r a u to m a te d r u n n in g g e n e r a ta c i te s t causes, w e d e v e lo p a n e x 
te n s io n fo r
Java PathFindf.r
t h a t lis te n s t o e v e n ts f r o m e v e ry e x e c u tio n o f b y te c o d e
ills ! r u c tio n s , c o lle c ts th e iiif o r m a tio n ( lu rin g th e e x e c u ti o n a n d c r e a te s s ta n d ạ r d u n it
t r s t s o f J I 'n i t 2. \ V r th e n r e ly o il . l l u i t te s t ť ia n i( 4 v o r k t o 1U Ì1 t h e g e iu 'i a te d u n it
Microsoft IVx h t t p :/ / re s e a rc h .inic ru s o ft.c o m /P e x

2JU n it unit Inmæwork h tt p :/ /ju n it.o r g
4
C hapter 1. Introduc tion
r il e o v e r v ie w o f th e h a in e w o r k is s h o w n i l l F ig u re l . i . i t c o n s is ts o f th r e e m a in
(о и и р о ш л И ร:
T h e c o re o f J a v a P a t h F in d e r p la y s th e ro le o f a te s t d a ta g e n e r a t o r I n o u r w o rk ,
w e u se S y m b o lic J a v a P a t li F in d e r ( A lia n c i e t a l., 2 0 0 7 ),
1 4 J T F r a m e w o r k a c c e p ts Ja v a p r o g iiU iis u n d e r te s t, p it ᄂp ro ce s s e s th e n pass e s
th e m to J a v a P a t liF in d e i as a n in p u t o f te s t ( la ta g e n e r a t io n p ro ce s s . A ft e r
t h a t, it lis t e n s t o th e r e s u lts o f th is p ro c e s s t o c o lle c t, g e n e r a te d tc ist m e th o d s ,
r e c o n s tr u c ts th e m t o a te s t c la ss a c c o rd in g to J U n it fo r m a t . F in a lly , th is
fra m e w o rk r e lie s o il J U n i t f r a m e w o rk t o e x e c 'u to t h e g e n e r a te d te s t c la s s .
J U i l i t f r a m e w o r k ax rc c |)ts a n d e x e c u te s th e g e n e ra t (ฟ ่ te s t c la s s fr o m
PUTFmma-

work,
th e n lise s a u s e r in t e r f a c e t o p re s e n t th e n u m b e r o f te s t c a s e s a n d t h e
lis t o f te s t ca se s t h a t le a d to e r r o r s o r fa ilu re s .
K i& in e 1.1: F ia itio w o r k o v e rv ie w .
I lie re s u ltin g tr a im n v o rk c a n ỊH oc e s s ĩn a ỉ iv P L T s ii) a m il tim e , h c c s Ị) io g ia _ n u iir is
|] ( »IỈ1 rh e WOI kh )H (l o f w r i t i n g lỉií^ li c o ťl(* (4)V (4 a g e u n it t r s t s . I t a ls o a llo w s a u to M u iî -
1.3. C o ntribution
5
ic a llv e x e c u tc a ll p o s s ib le u n it, te s ts a m i n o t if y a ll c ir o r occ:uri4*u(.e.s a n d e v c ii c a ll
show th e p a th s th a t lead to the (ฯ 1ÜÏS,
1.3 Contribution
W i t h th e a b o v e p u rp o s e s , in t
hv
sc o p e o f a M a s te r s th e s is , th is พ น !,к t r ia s t o b u ild
il to o l th a t h e lp s p r u g ia m m e is to g e n e r a te a n d e x e c u te a s e t o f te s t ca s e s il l J a v a .

T h is th e s is n o t o n ly in tr o d u c e s th e b a c k g r o u n d o ť te s t in g a n d a u to m a te d te s t in p u t
g e n e r a tio n , te c h n iq u e s a n d im p r o v e m e n t s th a t a re u s e d in
JFP
a n d
Symbolic JP F

fo r a u to n ia t o d te s t i n p u t g e n e r a t io n , b u t m a k ( \s
tiw
fo llo w in g ш а ііі c o n t r ib u t io n s ,
a ls o :
- Im p le m e n t s a il e x te n s io n t o J P F f o r g e n e r a t in g u n i t te s ts in л и n i t 4 .7 f o r m a t ,
a n d r e lie s o n J U i l i t to e x e c u te th e s e u n it te s ts a u t o m a t ic a lly .
- P ro p o s e s a il im p ro v e m e n t t h a t w i l l g e n e ra te m o r e s ig n if ic a n t in p u t s e ts t h a t
re a c h t o n o t o n ly p a t h c o v e ra g e b u t c h e c k n u m e r ic : e r r o r b o u n d s a ls o ,
- P ro p o s e s s e v e ra l im p ĩo v e m e u t s t o in c re a s e J P F ’S s tr e n g t h : in te g r a t in g J P F
w it h s tr o n g t u ( ( m s t r a in t ro s o lv o rs a n d c le v e l( )Ị) iiig th e to o l to e v a lu a te th e c o v 
e r a g e o f te s t in p u t s e t.
1.4 Thesis structure
B e s id e s ťlu* I n t io c h i c t io u i l l C h a p tc T 1, th e r e s t o f t h is th e s is is o r g a n i/ 세 a s fo llo w s :
C h a p t e r 2 in tr o d u c e s a u t o m a tic to s t d a ta g e n e ra tio n , h o w to e v a lu a te t h e c o d e
c o v e ra g e ฟ . a te s t s e t, re c e n t a p p ro a c h e s to gi.m e ra .te te s t d a t a a il to m a t ie a lly ,
s tre s s in s y m b o lic e x e c u tio n a n d la 쪼у i n it ia liz a tio n te c h n iq u e s . W e a ls o i n t r o 
d u c e t w o b a s ic s c o n c e p ts o f t e s t in g : U n it T ( 、st a n d P a ia in e t c n i/e d U n it T e s t.
C h a p t e r 3 in t r o d u c e s th e a i c liit e c t u r e o f J a v a P a t h F in d e r a s a s t a n d a r d te s t ( la ta
g e n e r a to r . W e a r e c o n c e rn e d w it h S y m b o lic : J a v a P a t h F in d e i - th e n e w e s t
e x te n s io n ฟ J a v a P a tli F m d e r, w h ic h u s e s t h e c o m b in a t io n o f m o d e l c h e c k e r
a n d s y m b o lic e x e c u tio n t o 요гш л а 1(-* te s t ra s e s a iit ijm a i ic a llv .
C h a p te r 4 int nxluc^s ОШ Ị)Ì()Ị)(>S('(1 framewenk: P U T F ra m e w o r k . which accepts
USCT Plls. ^ (ฯ К ฯ a te s a l lil o x r c i ite s L i l i t I> s ts a ii lo m a t к г н ііѵ . i h is c lia p ttM is
6

C hapter 1. Introduction
c o n c e ! ІК Ч І w ir li in ti c x lu à n g t h r e e m a in с о т р о ш .'п ! ร o f t h e ііа п и ч ѵ ч я к a n d th ( 、ir
c o o p r r a ti o n s . W e a ls o cles (:r il) e h o w to c o n fis u re a n d e x e c u ite th e fi.a n ie w u i k
a n d p re s e n t a s im p le e x a m p le o f fr a m e w o r k D |)tn a tio r i.
C h a p t e r 5 rv a lu a t e s th e r e s u lt o f t h is w o r k , a n a ly s e th e in it i a l r e s u lts a n d d r a w 
b a c k s o f t he fr a m e w o r k . W e a ls o m a k e c o m p a iis o n s b e tw e e n
PUTFramcicork

a n d s e v e ra l re la te d o n e s, h i t h ť la t t e r p a r t o f t h is c h a p t e r . W(? p o in t o u t so m e
a re a 's fo r fu r t h e r s tu d y .
C h a p t e r 6 c o n c lu d a s o u r w o r k a n d s u m n ia r ix e s th e s it u a t io n o ř c u rr e n t, t e s t iì iịị
t e d in i( | iu 's , th e a d v a n ta g e s a n d l i n ii t a t i o iis o f th e m .
Chapter 2
Automatic test data generation
111 t h is c h a p t(나 w e in tr o d u c e s e v e ra l b a s ic (.Q iice p ts , w h ic h w il l b e u s e d in th e re 
m a in in g p a r t s o f t h i s th e s is . F ir s t , w e w a n t to in t r o d u c e a n o v e rv ie w o f t e s t d a ta
g e n e r a tio n . A s w e m e n t i이 le d i l l C h a p t e r 1, t h e u n iq u e w a y t o g u a ra n te e c o r r e c tn e s s
o f a p r o g r a m is to e x e c u te i t o n as m a n y in p u t c a s t's a s p o s s ib le * r h o r e fo r e , t h e te s t
d a t a g e n e r a tio n is o n e o f th e m o s t im p o r t a n t; p a r t s o f a te s t in g p ro c e s s . A g o o d te s t
d a ta g e n e r a t o r is o n e o f th e f a c to rs t h a t m a k e cl g o o d te s tin g m o d e l.
T e s t d a ta g e n e r a t io n c a n b e a p p ro a c h e d fr o m d if f e r e n t a s p e c ts :
1. H o w S(、li4 :u 、(] t e s t a fleq u a cy l(*vel c a n b e КЧКІКЧІ (i.e. a lg o rith m s fo r t h a t ) ,
2. H o w to m a k e te s t d a t a g e n e r a t io n œ m p u t a tio îi a l ly e ffic ie n t.
3 . H o w t o (T C rtte m in im a l te s t s e ts fo r t h e s o lectc icl c r it e r ia
T o a n s w e r t h e a b o v e q u e s tio n s , s e v e ra l te c h n iq u e s h a v e b e e n p ro p o s e d . T h e y
r a il b e d iv id e d ba s (、d o n s o m e ty p ic a l c a te g o iie s :
H e u r i s t i c - e x a c t : 111 g e n e r a l, lu m i i s t ic a p p ro a c h e s m ig h t in c lu d e r a n d o m n e s s a n d
a r e m o re e f fic ie n t in th e m o s t ca s e s . H o w e v e r, th o s e a p p r o a c h e s c a n lea d to a
n o t o p t i m a l o r in a d é q u a te r e s u it . O n t h e o p p o s it e s id e , e x a c t a p p ro a c h e s a re
m o ie lik e ly to fin d a ll o p t im a l r e s u lt b u ( a re t y p ic a l ly le s s (、出 (‘i r i i t -

B la c k - b o x - W h i t e - b o x : If th e t e s t in g te c h n iq u e is b a s e d o il s o u r c e c o d e , i t is
(• tille d w i l i t (*-!)<>x te s tin g . ()th (M \v is e it is Ы ж . к - І ю х t e s tin g , w h ir h is b a s e d o il
till* s p r 'c ific a t io n s o f s y s t(* n i te n tu re s .
8 C h a p te r 2. A uto m atic test d ata generation
w ІІІІС-ІЮХ น:รtiny
(a ls o k n o w a、s s t r u c t u r a l t e s tiiig ) : is t h ( 、a p p ro a c h th a t a n a ly s e s
ІІ)(Л s o il i n '
vocìi)
(if th e p ro g r a m to d e s ig n te s ts S(.) th a t th e y re a ch t o on e o f so v e ta I
a d e q i m ry c r i t e r ia ( s u d i ( ^ . e v c 'iy сч к іе lin e is e x e c u te d a t lea s t o n c e , o r e v ť iV f u n c t io n
is i n d iv id i m lly te s te d , e tc . ) . W h it (
니 )o x t e s t in g w ill be tl u ' fo e แ ร in th is th e s is .
BI(K k'-box ttíỳtnự Ị
(som etim es ( a lli'd be ha vioura l testing) is a il approach to fin d
e r r o r s in a p r o g r a m b y v n lid a t i n g its fu n c t i o n a lit ie s b a 、se(l o n til e s p e c ific a tio n o f
a s y s te m w it h o u t th e d e ta i ls o f t h e c o d e . T h e g o a l o f th is te s t in g a p p r o a c h is t o
r i f t (ฯ П 1І1К.* w h e t h e r th e s y s te m s a tis fie s it s s p e c ific a tio n . T h is ty p e o f t e s t in g is m u c h
s im p le r t h a n w h it e - b o x t e s t in g b e c a u s e it is d o n e a t a h ig h e r le v e l a n d is in c ie p e n -
d e n t. (Vo m th e d e t a il o f s t r u c t lu e s . I l l a d d i t io n , b la c k - b o x te s t in g c a n fin d in c o r r e c t
im p lr m e n ta t i o n s o f t h e p r o g r a m , b e c a u s e o f s p e c itic a tio n m is im d e r s t a n d in g , t h a t
le a d s t o in c o r r e c t b e h a v io u r .
In OUI w o rk , w e p r o p o s e a
whiit-box ttstim j
m o d e l. Ill t h is m o d e l, u s e rs w r it e
a te s t ( l i i \ •(ฯ w h ic h c o n ta in s o n e ()1 m a n y P U T ( S ), o u r ir a iiu n v o r k th e n p ro c e s s e s
th e s e P U T b y s y m b o lic e x e c u tio n fo r g e n e r a t in g U T s s u c h th a t t h e y r e a c h t o p a th
( o r น ฯ !g t І М 1 p a t h ) c o v e ra g e . ไ ,b o re fo re , in th is c h a p te r, w e in t r o d u c e d if f e ie n t test.
a d e c ỊU itc ỵ m e tl ic s ( w a y 넜 to e v a lu a te th e w o r t h o f a te s t in p u t s e t) in S e c tio n 2 .1 ,
и г a n d P U T c o n c e p ts a r e in t r o d u c e d in S e c tio n 2 .2 . S e c tio n 2 .3 lo o k s a t th e a p 
p ro a c h t o g r i ie ia t e t e s t c a s e s a u t o iu a t ic :a lly b y

symbolic (ixccution
a n d it s s u p p o r t in g
te r lm iq iie s .
2.1 Test adequacy criteria
111 1972,D jisktia claimed that
лProỊỊram testing can be uacd to show the presť.nrt

o f buys, bat ïicva- their ab^itîiœ.
l l i b d a i m c a n b e u iu le is t o o d t h a t : te s tin g
a p p r o a c h is n o t a c c e p ta b le . H o w e v e r, lio w a d a v s s o ftw a 14* te s t in o Ііа ъ a r a p id g r o w th
in b o t h р іш Ч іс е a n d e x ỊH T Ì iiie iit .s a n d h a s b e c a m e a n in d is ịx u is a b le p a r t o f s o ftw a re
d (、\ v l( ) | ) m ( * iit
.
A n d a s ig n if ic a n t m ile s t o n e o f s o ftw a re t e s tin g g r o w th is t h e r e s e a ic ii o f
G o o (l( * n (H ig li a n d G e rh a r t ( 1 9 /ช -]! ) / / ), w h ic h p o in te d o u t t h a t t i l l ' c e n tr a l q u e s tio n
o f s o ft w a re 1 t e s tin g is
w h a t
18
te s t
c riterion
г
, th a t m e a n s h o w to m e a is u re th e
a d e q u a c y o f a t e s t. S in c e t h e n , t e s t c r it e r ia b e c a m e a n a t t r a c tiv e re s e a r c h fo c u s a n d
M Ц К 'ill n im ib r r o f to s t C iite i ia h a w I )(.*en |>io p o s e c l.
Z h u e t. a l. ( Z lm e t a l 19ÍJ7) is OIK* o f m o s t c u m p id ir i is iv e ะร Ш VC v s O li s u f t w a iv
u n i t t r s t a ( h * q i u u v . I l l t l i i s М 11 Л Ѵ Ѵ . a t e s t ( l e t t a a d ( * < |u a < y (1 ì t e i i o i i is s e e n a s H
2 Л . Test adequacy criteria 9
s to p p in g
vw\v
o f th e g e n e r a tim i p ro c e s s . F o llo w in g t h is a p p ro a c h . le t

p
ỉ)e a set. o f
a ll p ro g r a m .

a set o f s p e ( ฯ í ic a tio ris .
D
a s e t o f in p u ts fo r p io g r a m il l
I \
a n d
г
IS
th e se t o f a ll te s t s e ts
[T ะ= 2l)) .
F o n n a lly , a te s t a d e q u a c y c r ite r ia is a f u n c tio n
С .
w h ic li M in |) p in g a p io g ia in . s p e c ific a tio n a n d a te s t- s e t t o a b o o le a n v a lu e , i.e .
С
:
p
X

X
T —>
0 ,1 [( Z in i et. a l 1 9 9 7 ) , |>age 3 6 8 Ị. I f th e r e s u lt is 0, m o re te s t in g is
r e q u ii4 x l, o tlie rv v is e . t ilt * U îtits
<uv
a d e q u a te e n o u g h . A t . c o id in g to t h is s u rv e y , th e re
a r e t i l 1(4' (liH e rt 'D t a p p ro a c h e s in d e v e lo p in g a u ,s t M cl(4ỊU ficy c r it e i i o u :
S t r u c t u r a l t e s t i n g : m e a s u re * h o w w e ll t h e d iH e re n t p a r ts o f th e s tr u c tu r e o f t h e
p r o g r a m o r th e s p e c ific a tio n a re c o v e re d ( l in i n g th e te s t pro c e ss .

F a u l t - b a s e d t e s t i n g : c r it e r ia a re ba w ed o i l so n ici p re d e fin e d set. o i tV u ilty p i.o g ra m s
a n d m e a s u re s h o w m a n y o f th o s e f a u l t y im p le m e n t a tio n s a re d e te c te d .
E r r o r b a s e d t e s t i n g : s p e c ify p a l t s o f p r o g r a m t h a t m a y c o n t a in m o re e r r o r s th a n
o t h ( 、is , o r id e n tif y i n g w h ic h m o r s a re m o r e lik e ly t h a n th e o th e r s . D o in g t h is
r e q u ire s s p e c ia l k n o w k n lg o OÍ te s te r s .
B e c a u s e o f its c h a r a c te r is tic s , a u t o m a t ic t e s t- d a ta g e n e r a to r s use s o m e a d e q u a c y
c r it e r ia th a t c o n s tr u c t e d m o s tly f r o m s t r u c t u r a l a n d fa u lt- b a s e te s tin g .
I l l th is w o rk , vve c o n c e rn e d a b o u t t e s t - d a ta g e n e r a tio n b a s e d o il s y m b o lic ex e 
c u tio n in .IF F . th e re fo r e , w e s e le c te d s tr u c tu r a l - t e s t in g a's t h e a p p r o a c h . W it h t h is
a p p r o a c h ,th e a c ie q u a c y c t it e ria Ь е с о ш е a m o re s im p ly fu n c tio n :
с : г X T
0 . 1
b e c a u s e w e I t u ic li t o c o v e r d iffe re n t p a r ts o f p ro g ra m s .
S t r u c t u r a l t e s tin g is ty p ic a lly b a s e d e ith e r o il (la t a o r c o n t r o l iiu w s . H o w e v e r,
n u m e r o u s re s e a r c h e s s h o w th ( ' c o m b in a t io n o f th o s e a p p r o a c h e s -
2.1.1 Data-flow oriented adequacy criteria
111 d a t a - f lo w o r ie n te d c r it e r i a , t h e e v a lu a tio n is b a s (d o n fe a t u re s , s in 'll a s: a re a ll
th e p a r t s ()(' t lie c o d e te s te d w h e re
cl
v a lu e c a ll b e as s ig n e d to a v a r ia b le (a ll d e fin i
t io n s C l i t (ฯ io n ) o r h o w is d a t a m o v e d b e t w e e n v a r ia b le s ^ T h e r e a re s e v e ra l to o ls a n d
te c h n iq u e s Ь а ы ч і o n t h is iip p io a i.h . Ш К І ( Н о п ц e t a l 2 0 0 3 : O r s o e t a l. . 2 0 0 1 ) a re e x 
a m p le s o f t h r i l l t lia t p u b lis h n l a i น ฯ t h e Z U u 's s u n r v . l) a ta - H o w o rie n t e d te c h n iq u e s
a re in tr u d u c e d c o u ip lč t e ly in t WC J s u r v e y s (Z in i (!t a l. ,lí) 9 7 ) a iid (E d v a i.d s s o n . 1 9 9 9 ) .
B e c a u s e \V(' řU í' c o n c e rn e d w it II s y m b o li c e x e c u tio n , (la t:a -tio \v o r ie n t 0(1 t.(44h iiiq iH \s
a re n o t f m t h ( 、r d isc u .sse d i l l I Ilis th e s is.
10
C hapter 2. Autom atic test data generation
2.1.2 Control-flow oriented adequacy criteria
111 tlu .、c o n t r o l- f io w o rie l it C'd a d e q u a c y c r it e r ia a p p r o a c h , w e use a c o n c e p t o l c o n t r o l

H ow ц і а р іі ( C F ( Ỉ ) as a a b s t r a c t H ? [)ie s c 'u tfitio n o f a p ro g m iiL F o m ia lly . a c o n t r o l
H ow g r a p h o f a p m g m m
p , с FC (P )
is a H n ite . e d g e -la b e l, d ir e c t e d g ra p h
G =

{.V J {.ร , e } r
L \ L),
w h e re Л is t h e s e t o f n o d e s ,
E
is th e s e t o f e d g e s (i.e .
E
=
{ ( " .
เท)\ỉt, m
e
N
บ {.ร. r } } ) .
L
is th e s e t o f la b e ls o f e d g e s , ,ร is t h e e iiU .y n o d e , e is
t i n 、(vx i t n o d e . A
i<\\ท)\
is a p a il o f <
td ,f
> 5 w h e re
('d

E. f
is a. f u n c t io n f r o m
v a lu e s o f v a ria b le s i l l

l >
in t o b o o le a n v a lu e . T ilt? v a lu e o f / is u s e d t o t e ll w h ic h
b r a n c h s lio u ld b e fo llo w e d w iie n l) ia iK lii n g is p o s s ib le , v a ille o f v a ria b le s is a v e c to r
Г. \ \ ( 、c a n see t h a t
C F G
s a tis fie s fo llo w in g re q u ir e m e n t s :


h a s e x a c tly erne s iK 'ce s s o r a n d
no
p re d e c e s s o rs , .ร is th e fir s t s t a t e m e n t o f
p 、

a n d b e c a u s e
p
is u u a n ib ig u o iis . it re q u ir e s .ร- h a s o n e a n d o n ly o n e s u c c e s s o r.

ť
h a s n o su c c e s s o rs a n d ca n h a v e m a n y p re d e c e s s o rs . T h e e x e c u tio n o f
p
is
fin is h e d il l
t\
th u s
e
m u s t h a v e n o s u c c e s s o r.
• F o r e a c h n o d e
n

N รุ

a n d e a c h in s ta n c e o f v a ria b le s v a lu e
V,
th e r ö e x is ts
e x a c t ly o n e e d g e
cd
=:<
ท. m
> w it h la b e l <
t(L f >
s u c h th a t
f(v ) = tra t.

T h a t r iie a u s , if
II
luuร o n ly o n e siK*(:e s s o i\ th e la t)o l o f re la te c i a rc is a lw a y s
true.

i f t h e r e w e re m o re t h a n o n e s u c c e s s o r, o n ly o n e a rc is
tru t
a t a t im e .
4 ’h c s e K iq u ir e m e n ts ๓ )แรш ,е th e (Ic t. e n i iin is t ic o f b r a n r h in g in a. p r o g r a m . M o r e -
OVVI ,
i l l a p a th
Ị),
i f a ll n o d (썼 e x c e p t th e la,St o n e h a v e o n ly o n e su c c e s s o r,
p
c a n b e
(•()llaj> so (l i n to a s iu g lr n o d e . A s in g le m x le o f
C F G
m u s t n o t h a v e b ra n c h i iif t in s id e .

T h a t im * a n s . th e c o n d it io n .4 л
в
( w h o r e .4 a n d

a re a t o m ic c o n d it io n s ) r a n n o t
b e p u t in to H « in g le n o d e , r i l i s c o n d itio n u iiK s t b e p u t in k ) 2 n o d e s : th e f ir s t n o d e is
.4, th e s e c o n d n o d e is
в
a n d th e a rc c o n n e c ts tw o n o d e s h a y la b e l
A

true.
N o d e
В
is n o t a lw a y s e x e c u te d , it is e v a lu a te d o n ly i f
A
is
tn i(\
( l i v e n a p i o g r a in " a n d a n in p u t
f
fo r
p.
vve c a ll
Ịx itìi(l\ t)
— <
ร. (Ị\A I
) . e >
is e x e c u tio n p a th 4 n o d e s a r e il l th e sa m e o r d e r a s th e y a re e x e c u te d il l
p [t).
A n d

e x e c u tio n p a t h s c a n 1)0
feasible path
if th e re is a t l( 、as t a n in p u t t h a t c a u s e t h a t
e x ( 4 4 it k m , o p p o n ite ' t o
itijcasiblr. palli.
W e us e fe a s ib le p a t h to (le fin e acie q u a c .v
( I i t r i ia . A c c o r d in g t o ( Z im e t a l. . 1 9 9 7 ) a n d (E tỉv a r d s s o n , 1 9 9 9 ) . t h e r e a io fo llo w in g
ін іг ф іа х .у c r i t e ria :
S t a t e m e n t c o v e r a g e : a l l s ta t e m e n ts o f C F G a rc (*xec:u te (l.
2.2. U n it Test and Param eterized U n it Test
11
B r a n c h c o v e r a g e : K u c o u iite r a ll b r a n d ie s il l the* i> io g ra m , th e Ị)1 e d ic a t(л o f a ll
ff
s ta te m e n t m u s t b e e v a lu a t o il to b o t h t r u e a n d fa ls e .
P a th cove rage ะ a ll p o s s ib le e x e c u tio n p a th s ШЧ、in c lu d e d il l th e s e t o f te s t p a th s .
H o w e v e r, t h is c o v e ra g e is n o t a lw a y s 】ea,(*hed. A p r o g r a m h a v in g lo o p s o r
rec u rs io n s c a n h a v e a n in f in i t e n u m b e r o f e x e c u tio n p a th s , t h is is A ll in f e a s ib le
r e q u ir e m e n t b e c a u s e th e te s t s e t s h o u ld b e f in ite .
L e n g t h - n p a t h c o v e r a g e : a n o th e r a d e q u a c y c r it e r io n is d e fin e d to re s o lv e th e
a b o v e p ro b le m , in t h i s c r it e r io n , a ll th e p a th s o f le n g t h

a re c o v e re d il l th e
te s t s e t.
\Y (、( a il see th a t th e s ta U u n e iit ( ove ra g e is th e w e a k e s t, i f b r a n d i c o v e ra g e is r e a d ie d ,
a ll s t iit e m e n ts o f |>i o g i a iท m u s t 1)0 e x e c u te d ( i.e . st a te m e n ts is I (in c h e d ). A n d th e
p a t h c o v e ra g e is t h e s t t o llt e s t , if t h is a d e q u a c y is re a c h e d , a ll b ra n c h o f C F G m u s t
h e e v a lu a te d to b o t h tr u e a n d fa ls e .
P a th c o v e ra g e is n o t a n im p lic it s ta te m e n t c o v e ra g e , b u t it is m e a n in g fu l in th e
p r a c tic e . T o a v o id t h e s t a t e e x p lo s io n ,
Java PathFinder

li m i t s th e d e p th o f p a th
s e a rc h in g a n d t r y t o
ivdch
t o tlic น - p a t h c o v e ra g e .
2.2 Unit Test and Parameterized Unit Test
2.2.1 Unit Test
In c o m p u t e r p r o g r a m m in g , u n it t e s t in g is a te s t in g m e t h o d , i l l w h ic h a te s te r te s ts i f
in d iv i d u a l u n its o f a s o u rc e c o d e a re f it f o r use * Л u n i t is t h e s m a lle s t te s ta b le p a r t o f
a n a p p lic a tio n . I n |)K ) c e (ỉiỉic tl p r o g r a r iim in g , a u n it m a y b e a n in d iv id u a l p ro g r a m 1
f u n c t io n , p r o c e d i m i f'tc . I l l o l) j ( 4 l- o r ie n t e d p r u g r a n m iin g . H u n it i.s a m e th o d o f il
d a s s . I - n i t t e s t in g c a n n o t e n s u r e th e c o rr e c tn e s s o f a ll p r o g r a m s b u t th e p r o p e r
e x e c u tio n o f e a ih t u iit is t h e b a s is of. c o ir e c tn e s s o f p r o g r a m .
F o r u n it t e s t in g , t e s tin g clas s e s a re w r it t e n , e a c h t e s t in g c la s s o f t e n h a s m a n y
t(\s M n g m e th o d s . I b s t i u g m e t. hoc Is a re su b -fV m c ^ io iis t h a t h a v e n o in p u t p a t a n u ite r .
ro t III 11 a v o id va lu e . It re p r e s e n ts
ii
s in g le te s t ca s e a n d t y p i c a l ly e x e c u te s a m e th o d
o t a c la s s -u ii(le r - t( 's t w it h fix e d a i^ u m e T its fo r V (M ifv iiig t h a t it K 'tu r u s t h e (、X|H 、(*te(l
r e s u lt, o r ii iu li n ^ I h e re is a n y u n - li a iid le d e x (4 、|> ti(iU ill th e ( 'X e c u l ІОІІ.
A t e s tiu g !U ('t h i)(,l c a lle d a
Unit Ihýt
(
V l')
O l f l
teĩit ease
a ls o , id e a lly ; e a c h
te s t ca s e is ІШ І이 )r ii d r n t fr o m t h e o th r i s . F o r e x a m p le ,
wv
h a v e a
и ĩtderTt>it

d a s s
12 C hap ter 2. A uto m atic test data generation
w i t h a s im p le
Add
fu n c tio n w h ic h r e tu r n s th e s u m o f a b s o lu te va lu e s o f tw o in p u t
p a m ine te is ill iu t (방 (ฯ t y p e а я follow s:
pIlk)lie class บіккм Гі/уІ {
p u b li c i l i t A tid ( I f i t X . i l i t V )
i
i f (x<0)
X = X .
i f (y<0)
V = у 1
re tu rn x-fv 1
E x a m p le U T s a n d P U T fu i te s t in g a b o v e
Add()
m e th o d
i\iv
lis te d in F i» tu e 2 .1 :
p u b i

fl .ts ๙ ÏJT te s t add (M
pubi i«. Viriti test_.ad d_l_l 0 í
i X - 1 ;
int v = 1;
аз s e rt Equal s (Add y) / 2) ;
}
publ ic v<*i«1 te s t add minus 1 1 0 {
il it
X

=ะ
-
1;
i г» t у = 1;
assert Equals (Add y)
1
2)
)
pub i ii

»id te s t
add
m i nus 1 min นร 1 0 {
Lil Í к = -1 ;
л II
\
y =
- l i
asseťtEq u als(Add <x, ỵ),2) ;
)
ptibli.t void t€St_add maxlnt 1 () ^
In
i X =
Integor.
Ш Л 'A i
7:?;
in t y = -1;
as se rt E qual s (Add (
'Л, у) ,
Int.eger. ; '• -

• ;
•'• +1) ;
}
pubi ù void test_âđd minln t 10 {
in t X =■ rainlnt ;
i lit
V
= - 1 ;
a s s e rtEquals(Add( к ,y ) ,
Integer. . +1) ;
1
piใы i с Í

1
ss
PUT test_add () (
|Mih»Ị.i«. V« >id PlJT]_add (int :ч, ііИ у) {
ưnde rTest ut = I»“ w Under Te st 0 ;
in t ш = Mat h.abs
ix.)
+ Math. abs (y) ;
assertTrue(u t. Add(X, y) == m);
}
Test class rruJi I]Ts
Tesi CÌ/ÍSS wiứt PVT
F ig l i le ^ ; ! : E x a m p le o f U T a n d P U T .
lu tlæ a b o v e e x a m p le .
I 'T J ť s tjiild
is te s t chuss a m i its m r t h o d s a re l in i t te s t s o f
I he u r i g iim l u n it

A d d ịin t ร. in t y).
T h e s o u n i t te s ts (» x a m iiie a il p o s s ib le e x e c u tio n
a 's p e rts o f th e o r ig i n a l u n it . A f t e r e x e c u tin g th o s e U ïlit te s ts , th e r e s u lts w e ro c o iv e
c a n b r clťu s s ified in t o tw o c a t( * g o iie s :
S u c c e s s f u l: W it h u n it te s t s iH .h th a t:
testM dd-LJ(), tA istjidd ^rw iu sIJiiinu sl()า

e tc , w e re c e iv e a ine s s a g e th a t, in fo r m s น.ร th a t, t h e p r o g r a m pa s s e s t h e te s t
u n it (i.e . th e a s s e rtio n is s a t is f ie d ) .
บ n h a n d ie d e x c e p t i o n is t h r o w n : w it h th e u n h a n d le d e x -
(;(*|)tio n c a u s e d
by
o v e rf lo w l i m it o f in te g e r v a lu e ( il l
A(ld()
fu n c t io n , t h e re 
t i l i 11 v a lu e =
Integer.M A
A _
VALUE
- f / ); w i t h
tr,sf」idd그r im ln L l(),
th e Ш 1-
Ь я ік ііе с і e x c e p ti o n c a u s e d in s id e o f
Add
f u n c tio n . I l l
"X =
-
x '
s ta te m e n t ,
w it h

X
=ะ
Jntcgtr.
M / A ' .
VAỈJи E.
t h a t m e a n s
X
is a n e g a t iv e n u in b e r b ill; -
In-

ị(:(Ịi:r.
Л ///Ѵ , l v i
L U E ะ= ỉn tư(Ịtì\ MA X . VA L u E
- f / , a n d

1

is o u t o f a n in te g e r
n u m b e r ’s b o u n d .
It s (*l(、a i t h a t u n it te s t s p la y a n im p o r ta n t m l i 、in s o f tw a re te s t in g , s o m e clu< -
u m e n t c la im e d t h a t u n it te s t s a re a k e y c o m p o n e n t, o f s o f tw a re e n g in e e r in g ( K in g ,
1 9 7 6 ). H o w e v e r, i t is a d if f ic u l t w o rk to g e n e ra te g o o d u n it te s ts t h a t re a c h t o on e
o f c o v e ra g e c r ite r ia .
A n d t he c o n c e p t o f
P am n u d tiiztd U nit Test {P U T )
is p ro p o s e d as a n a p p r o a c h
to re s o lv e th e p ro b le m . W e w il l in t r o d u c e
P U T
in t h e fo llo w in g s e c tio n .
2.2.2 Parameterized Unit Test

A s w e k n o w ,
unit teabỉ
a re m e t h o d s w it h o u t in p u t, p a r a m e te r s . T h e ide a , is t o g e u -
e r a liz c in a n y U T 8 il l th e fsaiiKî c a te g o r y t o a n e w m e th o d t h a t h a s in p u t p a ra iu e te r s
c a llo d
І}а гп тгіе гігЫ Unit Test
(o r
P U T
fo r s h o r t ) , t h e r e fo r e , t e s te rs h a v e t o ta k e
( a r e a b o u t o n ly o n e P U T in s te a d o f m a n y c o n c re te U T s . th e P U T a c c e p ts m a n y
d if f e re n t v a lu e s o f i n p u t p a ra m e te r s a n d e x e c u te m a n y บ I S a p p r o p r ia t e t o th e s e
v a lu e s .
A c o m p le te P U T c o n s is ts OÍ I p a r t š ( A A A A - f o r r n ) :
A s s u m e : a n a s s u iu p tio u t h a t li m it s th e r m ig f o f in p u t p a r a m e te r s .
A r r a n g e : a s s ig n v a lu e t o v a ria b le s .
A c t : se(ỊiH*iK x» o f s ta t e m e n t s .
2.2. U nit Test and Param eterized U n it Test 13
A s s e r t : the rx ỊK T tíx l a s s rrtio ii.
C hapter 2. Au to m atic test da ta generation
Wo
t l i l i ] b a r k t o th e e x a m p le in ta b le 1, Ư T s ill t r s t
vhiss teỉiLadc!
c a n n o w b e
g e lic ifiliz e d t o o n e P U T o n ly :
p u b l i c c la s s P U T .t« ? s t.a c id e x t e n d s Го л ř C a s e {
v o id te s t A iid ( l i l t X . i n t V ) {
/ Л
N.suwe
Assume. JS I'lU f ( x>() iWiเโ x< líỉ ẲCẢ: у >0 »VẢ; v < I о ) ;
/Л rranýť.


i lit
y. —
о,
Г nde-rl'est ut new u miéťTesi ( ),
//.,ใ./
z — lit Add( X 1 у ) ;
/A s s e ri
assert Kq u a!» (z . Math . abă ( x)-Ỷ- Math . abb ( v ) ) :
III te s tin g , w e c a ll g e n e r a liz e e n tir e ly iie w I^ a ia m e te r iz e d u n i t te s ts th a t, d e s c r ib e
the

b r l m v iü u r o f t h e in v o lv e d m e th o d s fo r a ll te s t a r g u m e n ts , o r g e n e ra liz e g iv e n U T s t o
P U T s o r a g a in s t, w e in s t a n t ia te g iv e n P U T s t o U T s b y p a s s in g t h e m c o n c re te v a lu e s
o f in p u t p a ra m e t e rs . T h e r e l a t io n s h ip c a n b e r e p re s e n te d b v fig u r e 2 .2 (re fe r e n c e d
t o (E d v a rd s s o n , 1 9 9 9 ))
Traditional Unit Test
Generalization : ) Instantiation
\ /
Parameterized Unit

est
Generation
Implementation
F ig lilo 2 .2 : R e la t io n s h ip b e tw e e n U T a n d P U T .
N o w , w e CrHi ร(น* I h ilt i f t h e re is a P U г g iv e n b v p io v r a , m in e r s ( c a lle d te s t d r i v e r
a ls o ), t h e te s t d a ta ^ (.ฯนฯ,a t i n g Ь е с ч я и г к a p ro c e s 유 th a l in s ta n tia t e s g iv ( 'ii P U T to
I I s t hat I.eacli to a coverage C l ilo i LOU. u lth above p ro p e rtie s . \vr ( a n th in k
ІІІНЩІ using syiiỉl>()lic rx c c u tio u гШ(І coibSfiaiu s olving to a u to m a tira lk analyse a
p i I and im ita n tia tr it fo U T s siirli tha t the set of arc!lived U T s is in in im a l am i

2.3. Test input, generation by sym bolic execution 15
re a c h to h ig h c o d e c o v e ra g e . เท í ì d d it io n . p и Fs a m 1)(' usẹ d
symbolic summaries

w h ic h c illo w
.st/rnljolic tjxca tion
lo sc a le fo r a i'b iti'c iiy a b s tr a c tio n lr v ( 、ls.
2.3 Test input generation by symbolic execution
T h e r e a n ' s e v e ra l d iffe r e n t te c lin i(iu e s Cor H iito m a tu d te s t in p u t: g iü K H a tio n , s u o li
<us ra n d o m te s t (la t a g e n e r a t io n ( J . O ff u tt & HUiyes., 1 9 9 6 ),g o a l- o r ie n te d te s t d a t a
g e n e r a tio n (K o r e l
к
A l- Y a n ii. . 1 9 9 6 ). |) a th - o ii( 'iit r 4 l te s t d a ta g c n o ia tio u (K o r e l. .
1 9 9 0 ). H H 'th o d s e q u e n c e s a n d s ta te e x p lo r a tio n ( I h a ii t o l a . 2 0 0 6 ). I l l t h is s e c tio n , w e
in tio d u c e
symbolic execution -
a to c liniq u e is m o stly used fo r Ы g e iie ra tio ii arici its
s u p p o r t in g te d m i< | 니ěs:
lazy initialization
a n d
code instrum ent
2.3.1 Symbolic execution
S y m b o lic e x e c u ti o n ( K in g , 1 9 7 6 ) is it m e th o d t h a t w a s p ro p o s e d in th e 1 9 7 0 s . i n th is
1 n e t h o d , th e p ro g r a m v a r ia b le s th a t n o r m a ll y c o n ta in c o n c re te va lu e s a re re p la c e d
b y t h e ir s y in l) o lic c o u n te rp c iv ts t liH l e x p re s s a r a n g e o f p o s s ib le v a lu e s u s in g s y m b o lic
e x p re s s io n s . In s y m b o li c e x e c u tio n , v a lu e s v a ria b le s a n d r e t u rn v a lu e s o f p r o g r a m a re
s y m b o lic e x p re s s io n s c o n s is tin g o f s y m b o lic i n p u t . D u r in g th e e x e c u tio n p ro c e s s o f
p ro g ra m
p.
i f the* va lu e o f a va riab le d e p en d s Oil the in p u t para m eters , th e tes tin g

t o o l w ill c a lc u la te a s y m b o lic v a lu e to re p la c e th e v a lu e o f th e v a ria b le . G iv e n a
v a r ia b le 1/., t h e sy m b o lic v a lu e ol .7: c a n b e expressed b y o n e o f th e fo llo w in g fo r m a te :
• A ll in p u t s y m b o l.
• A fo r m u l a w h ic h c o n s is ts o f s y m b o lic v a lu e s a n d o p e ra t o r ( s ) .
• A fo in m la w h ic h c o n s is ts o ť s y m b o lic v a lu e s a n d c o n c r e te v a l u t . a n d o p e r a -
t o r (ร ).
A n o p e r a to r in s y m b o li c e x e c u tio n c a n b e :
addition ( f ). .iubstractioji (•), m u ltipli
cation
( * ) .
ii ini Sion
( / ) . e tc . I l l tlio c x ( 4 :u tio n p io c e s s o f a p ro g m in . c o n c re te ty p e s
HVV
гер1а<чч1 w it 11 (•(ท г е у р о ік і іи д s y m b o lic ty p e s , c o n c re te o p e r a to r s a r(* l r p la r e d b y
c a lls
น)
im 4 lii)(b s t h a t iiu p k 'm r ii t c o iie s p o n d in ^ o p p ia t iu n o n s v in b o liť e x e c u tio n .
F o i s y m b o lic (\\(.4 ฯ น เ()ท . fin.* O IІЦ ІІ1НІ (c>(i(、is in s t i u m r n te d . l i l th is in s t r u m e n t , th e
v a r ia b le s in o r i g in a l d a r a ty p e s (In t e g e r fo r e x H in p U *) a re (‘h a n g e d to c o rr e s p o tK Ìia g
16
C hap ter 2. A u tom atic test data generation
lib ia r y cla.ss (In te g o i K x p n .^ s io n fo r e x a m p le th a t s u p p o r t s m a n ip u la tio n o f s y ia -
b o iic I n te g e r e x p re s s io n s ) a n d o p e ra tio n s ia v o lv iu g th e s e v a ria b le s a re re p la c e d w it h
t i|) | ) io |) i ia ie m e th o d c a lls t h a t m a n ip u la t e o b je c ts o f c o n e s p Q T id in g ty p e (i.e . In te -
g c i E x p re s s io n ) .
I l l tl io s v m h o lic e x e c u tio n p a th o f th e p ro g r a m . P C s t a n d s fo r
Path Conditi on,

t h a t is rt b o o le a n fo n n u la o v e r in p u t v a ria b le s a n d d e s c r ib e s w h ic h c o n d it io n s m u s t
he

tr u e in th e s ta to . A P C a c c iu im la te s (X ) n s tra iu ts th a t th e in p u ts m u c h s a t is fy
i l l o r d e r fo r a n e x e c u tio n to fo llo w th e p a rtic u la r p a t li . I l l ea c h b r a n c h s ta t.e m e iit.
i f th e b la n c h in g c o n d it io n d e p e n d s o n in p u t s y m b o l( ร ), th e re a re t w o P C s t h a t
c a n b e g e n e r a te d : o n e is th e f o r m u la o f t h e b r a n c h in g c o n d itio n , a n d o t h e r fo r it s
n e g a tio n . T h e n , a c o n s t r a in t s o lv e r e v a lu a te s P C s , i f a P C Ш d e t e r n iin e d a lw a y s
f u h f 、
s y m bo lic*, e x c 'c u tio n m u s t b a c k tra c k a n d c o n tin u e w it h a n o th e r b ra n c h th a t
h a s th e P C m a y b e
true.
W h e n w o r k in g w it h v a ria b le s o f a il a rr a y ty p e , P C n e e d s
to a d d я c o n d itio n to c h e c k t h a t t h e in d e x s ta y s w i t h in th e s iz e OÍ t ile a rm y .
It is e a s y to r e c o g n iz e th a t s y m b o lic e x e c u tio n d e p e n d s o n th e b ra n c h in g a n d
a s s ig n m e n t s ta te m e n t s in t h e p r o g r a m . A s ta te in s y m b o lic e x e c u tio n c o n s is ts o f
I hi'e e p a rts :
symbolic values of the variables,
a
path condition
a n d a
yroqmm counter

w h ic h in d ic a te s th e n e x t s ta te m e n t to b e e x e c u te d .
In s y m b o lic (、x (4 . u t io n ,a
Symbolic Exœution Tret
( S E l' ) is use d to ť lim a c t e r iz e
a ll e x e c u tio n p a t h s o f th e p io g r a m . Т ІН 、S E T o f a p i.o g ia m is a (p o s s ib ly i n f i n it e )
t re e w h e re n o d e s a re p r o g r a m s ta te s d u r in g s y m b o lic exe c u t io n a n d a rc s a re [p o s s ib le
t r a n s i t io n s b e tw e e n s ta te s . A l l t h e le a f n o d e s o f t h e S E T w h e r e th e P C is s a tis fia b le
n ’in v s n it d iffe r e n t e x e c u tio n p a th s . M o r e o v e r, a ll fe a s ib le e x e c u tio n |> řitlis o f th e
p r o t r a ili a re p r e s e n t(、(l ill S E T . T ile m a in p ro b le m is s o lv in g th e p a t i i c o n d itio n s , a ll
s n tis fia b le v a lu a t io n s fo r a P C ( in

Л
le a f n o d e ) w ill g iv e us a re a l in p u t a n d o x e c u t io n
p a t h s w it h a ll t ho s e in p u t ШХ1 e q u a l. Ш К І t h e 1Ц1ШІШ1 o f (’(m c r e te e x t'c n t io iis m a y b e
in fin it e .
F o r e x a m p le , w e h a v e a s im p le p r o g r a m t h a t s w a p s t w o in te g e rs a n d its c o n c re te
e x (4 ‘iit i o n a n d s y m b o lic e x e c u tio n p a t li (fig u r e 2 .3 ):
2/Л.
Test in p u t generation by symbolic execution 17
ťa lii
The concrete execution pash
f ř c て IMI« I J
ịí*» tnu Ị :
false
iPC^=X>y
|x « x ^ v

' .一

Mト ン X V| v

.
.

.
r.


|И• ^ X Vị ч- X M - \ «V
1 1
-i

fPC«X>
YJ Y хл
í^l>'
Z
ị |КГ-Х< Y<X]END Ị Ị (И; N>Y Y? XJEND Ị

. • 一
서. 1 -
FALSE Я
t fiabe
The symboìic ữcecuảon ir«e
F ig u r e 2 .3 : K x a u ip le o f s y m b o lic e x e c u tio n .
ln I ho a b o v e e x a iu p h 、. w e n e e d l o te s t th e (:0 (1(* t o d e te r m in e w h e th e r th e a s s e rtio n
( lin e 9 ) is r e a ç h a l)le o r n o t.
i l l t h e
concrete execution
fo r te s t in g th e c o d e ,
vve
c h o s e a c o n c re te v a lu e fo r X
a n d
y
( f o r e x a m p io I illic i 0 ) a n d th e c o d e is e x e c u te d in o n e p a th o n ly a n d tile
a s s H tio ii is n o t r e a c h a b le , b u t w e c a n n o t b e s u re t h a t th e a s s e rtio n is re a c h a b le
w it h o th e r p a ir s o f in p u t v a lue s .
M t'a m v h ile . in
symbolic txvmi.ioìL
t h e p ro g r a m c a n b e e x e c u te d o il a ll fe a s ib le
Ị) ỉỉth s . I. i l S t.
\\v
a s s ig n a s y m b o lic 1 Vil h ie fo r e a c h a n d

IJ
in s te a d o t c o n c re te v a lu e s
( Л НП(1 V a re .s y m b o lic o x p re s s io u s ) . T h e n , a ll s t a t e m e n ts o f th e p ro g ỉr iin th a t
il r p e m l o il .r o r ỊỊ

w ill o x e c u te d I>ase( 1 o u
X
a n d
Y ๆ
in s te a d . I hn p a t h c o n d it io n
( I }C)
h a s in i t i a l v a lu t » t h a t is
I HI E.
In o a c li b la n d i, th e tw o n e w P C s a r e g e n n a t.ix l
I
Đ Ạ I H O C Q U O C G l A H Ả N Ộ I
TPUNG TÁM THÔNG TIN THƯ VIỆN
Д -Lo/ỐQ
a Ị ) Ị ) io p r ia t e t w o p o s s ib le v a lu e s o f th e b r a n c h f o m ii ila s :
1,f{U E
a n d
FA ỉ, S E
( t h e
h is t n e w
PC
is
PC = X
<
)'.
a n d th e s e c o n d is th e n e g a tio n o f tilt* f u n n e r :

HC

X >
У ). A n d t h e r e a re tw o S \il) - i) ia n c h e s o f S b T асч о іч ііи ц t o t w o v a lu e s o f
n e w P C s .
W h e n th e s e c o n d
if
s ta te iîie n t ( lin e 8 ) is e x e c u te d , tw o n e w P C s a re g e iH iia t e d
( l b H rs t is
PC
Л < у л к < X a n d t h e se c o n d is
PC
= X > Г л У > X ) . T h e y
a re p a s s e d t o t h e c o n s t r a in t s o lv e r. T h e c o n s tr a in t s o lv e r e v a lu a te s th e s e
PC
a n d
d e te c t t h a t th e se c o n d P C is in f e a s ib le , i.e . c a n n o t tin c i a n y c o n c re t e va lu e s o f
X

a n d // t h a t s a t is f y th e P C , T h is m e a n s , s y m b o lic e x e c u t io n d o e s n o t c o n tiỈ1UC fo r t h i s
p a th a n d e v e ry s ta te m e n t t h a t fo llo w s th is s u b -tr e e o f S E T a ie u n re a d ia b le . N o w
w e c a n b e s u re t h a t th e a s s e rt io n is u n r e a c h a b le . T h e s y m b o lic e x e c u tio n b a c k tr a c k s
to e x e c u te o t h o i n il- e x a m in e d p a th s . I l l th is e x a m p le , the re * a re n o s u c h p a th s , t h e
e x e c u tio n is fin is h e d .
A s a re s u lt , w it h s y m b o lic e x e c u tio n , w c c a ll p ro v e th e a s s e rt io n is u m e a c h a h le ,
in o t h e r w o rd s , w e c a n p ro v e a p r o p e r t y o f th e p r o g ra m . In p r a c tic e , p r o v in g a
p r o p e r t y o f a p r o g r a m is a h a r d w o r k a n d n e e d s m o r e p o w e r fu l t o o ls .
F o r e a c h fe a s ib le P C o n th e le a v e s o f S E T , ạ p a ir o f c o n c r e te v a lu e s o f
Xy
a n d

у

is c h o s e n th a t s a tis fy t h is P C , th is m a k e s a n
input data mat.
S e t o f c o n c re te v a lu e s
o f X a n d
IJ
m a k e t h e
test input st't
w e ne e d f o r th e
path соѵаще.
In p r a c tic e , a f t e r r e s o lv in g a P C , w e c h o o s e a r e p r e s e n ta t iv e s e t o f in p u t v a lu e s
Ш p o s s ib le v a lu e s . A ll re p r e s e n ta tiv e in p u t v a lu e s m a k e น]) th e in p u t set. w e n e e d
fo r a r c h iv iji g th e p a th c o v e ra g e ( o r l( 4 ig th - n p a th c o v ü ia g iï) c r ite r io n . I n
./PJ \
th e
r c Ịỉre s e n ta tiv e in p u t v a lu e is c h o s e n la n d o m ly . T h e re fo re , th e in p u t s e t re a c h t o
th e p a t h co v e ra g e c r it e r io n o n ly , it is f l iH ic u lt t o g iv e a se t o f in p u t s th a t c a n Ir tis e
u n h a n d le d p x n 、p t i( ) iis s u c h as: d iv i( l( * b y z e ro , o v e r flo w o f n u m b e r lim i t , e tc . In t h i s
w o rk , w e m a k e s o m e iu ip io v e iỉie iit s t h a t h ť lp
JPF
g e n e ra ti* te s t d a ta th a t
iliv
m o r e
s ig n ific a n t , n u t o n ly fo r p a t h c o v e ia g e b u t r a is in g u n h a ii( l k 、(i e x c e p tio n s .
W e h a v e in t r o d u c e d th e o r ig in a l id e a o ť s y m b o li c ííx o c iu tio n , c a lle d
static symbolic

rxœatùm
a ls o . I l l t h is a p p ro a c h , a w h o le S E T is b u ilt l) y w h o le p ro g r a m a n a ly s is .

T h is te c h n iq m * is Iis r d in J a v a P a tliK in d e r fo r te s t in p u t g e n e r a tio n .
A n d in t h e re c e n t ye a rs , n u m e r o u s re s e a rc h e s p ro p o s e a n e w id e a o f s y m b o lic
(w en ition -
dynnntH sụmbolir ( ::!:(( ■ (ítÌOĨỈ
(Godefroid al 2U05: Xie et al 2009).
G o iie ia llv , ( ly n a i n i r s y m b u lic e x c4 :i i t i o u is th ( j c o u ib in a tio n <>l (4 )iK T e te e x w 'u t.iu ii a n d
s y n ihu lk: e x c n itk m , th is c o m b in a tІПМ a llow s for t Ili.1 pro g ra m to be exec u tt'd in a n y
18 C h apter 2. A u to m atic test data generation
tiu u * s v v U il ( lilf('iT 4 it in p u t v a lu e s .
F ir s t , tin * c iy n a m k * e x e r u t io ii s t a r t s b y c h o o s in g r a n d o m v a lu e s fo i in p u t p a ia m -
e tr is a n d a g iv e n d e p th u f S E 1 ( t h a t is u s e fu l w lu 'ii p ro g r a m c o n ta in s n x u is io n s o r
in fin ite loo p s ). T h e p m & ra u i is exe c u ted w ith thí>S(' values o f p a ia n ie te rs ill a g ive n
e x e c u lio u p a t h - t h is is th e c o iK .re te e x e c u tio n .
Ĩ 11 t l i r (.이 lc r e k 1 e x e c u tio n |)i()c e s s . i f th e re is a b ra n c h s t a t e m e n t , th e .s y m b o lic
v a lu e s o f th e c o n d itio n f o r m u la m e c a lc u la te d b a s e d 011 th e g iv e n v a lu e s o f in p u t
p a r a m e tc 'is a n d p a t h c o n s t r a in t s a re c o lle c te d b a se d o il th e se fo r m u la s v a lu e s ( li n in g
e x e c u tio n p ro c e s s . N e w c o n s tr a in ts ave g e iie r a to ii a u to m a t i c a l ly ba se d o n c o lle c te d
c o n s tra in ts . W h e n a n e w p a t h a m s t r a in t is g e n e r a l(ЧІ. H n e w n o d e is a d d l'd in t o
S E T . W h e n e x e c u tio n fin is h e s , a p a t h o f S E T is m a r k e d e x a m in e d .
W it h in it i a l c o n c re t e in p u t va lu e s , a c o n c r e te p a th o f S E T is e x a m in e d , a n d th e
le m a in iu g p a th s w ill Ішлч» n e w n o d e s a n d th e s e n o t li's
iuv
m a r k e d a、s n o n - e x a n iiĩie d .
1 lie n e w ik x U 's w ill s t o r e a p |) K )[)ria tc » c o u s t r a n its .
A ft e r a p a t h is fin is h e d , a Iio n - e x a tr iin e d n o d e is c h o s e n a n d a n t'w c o n s t r a in t is
b u ilt b y c o lle c t in g a il o f th e c o iis t r a in t s in n o d e s th a t b e lo n g t o th e p a t ii f r o l l i th e
ro o t: o f S E T t o t h e c h o s e n n o d e . T h e n e w c o n s t r a in t, is s e n t t o a c o n s t ra in t, s o lv e r .
T il e c o n s t r a in t s o lv e r w i l l d e te r m in e :
• I f th e c o n s tr a in t is n o t s a tis fie d , a n o th e r lio n - e x a m in e d is ch o s e n a n d th e a b o v e
s te p is d o n e a g a in .

• l í 1Ỉ1Ư c o n s tr a in t is s a tis H (4 Ỉ. C o n s tra in t S o lv e r w i ll g e n e ra te c o n c ia te v a lu e s
fo r in p u t p a r a m e te rs . T h e s e v a lu e s a re u s e d fo r th e n e x t c o n c re te e x e c u tio n .
• Т ІК * a lg o r ith m te r m in a te s w h e n a ll p o s s ib le p a t h s o f S E T h a v e b e e n e x a m in e d .
A l l o f th e c o n c r e t e v a liK 'S o f h i p u t p a ia n iť t e r s iU id a n a ly s is in fo i Illa t io n o f a p 
p r o p r ia t e c o n c r e te e x e c u t io n
(method nummary)
a n *
wsvd
fo r g e n e r a t in g
unit test

(11) a m ỉ n 'p o i t in g p u rp o s e . R e a d e rs c a ll re fe r to ( G o d e fro id e t a l., 2 0 0 5 ; X ie ('t a l. ,
2 0 0 9 ) lo r d e ta il o f t h is pro c 't'ss , t he p s e u d o c o d e o t D S Ë a lg o r ith m , a n e x a m in e a n d
it s a n a ly s is .
w ไ แ ฯ 1 ta lk i n g a b o u t s ta tic - a n d d y n a m ic s y m b o lic e x e c u tio n , P a sH ie a n u c la im e d
t h a t ( I v n a iu ic s y m b o lic : e x e c u tio n p e l fo rm s s y m b o lic (» x r c u tio n a lo n g c .o u n e tP c x e c u -
tio n . w hercřUS s t a t ic e x e c u tio n use s c o n c r e te e x e c u tio n t o s e t - lip s y in h o lir e x e c u tio n .
C o m p a r in g to s t a t ic s y m b o lic c x m it i o n , d y i m n ii r e x e c u tio n g iv e s us Ш О П 1 a d v a n 
2.3. Test in p u t generation by symbolic execution 19
tages:
Chapter 2. A u to m atic test data generation
• S ta r t s y m b o lic e x e c u tio n a t a n y p o in t in th e p io g r a in a n d a t a n v t im e ( lu r in g
e x e c u tio n .
• O n ly fin d fe a s ib le p a th s . A l l a rc h iv e d p a t h s arc* fe a s ib le a n d e a c h p a t h g e n e r 
a te s a set. o f in p u t v a lu e s t h a t le a d t o t h is p a th .
W it h th e iile a is a n a ly s iiig p io g ia u is w it h u n s p e c ifie d in p u ts , in th e first- tim e ,
s y n ih o iic e x e c u tio n w a s n o t d e v e lo p e d f o r t h e te s t d a ta g e n e r a t io n , b u t tb li n a i v e r i-
í ic a tio ĩỉ . A n d . it h its m a n y d ra w b a c k s s iu li a s:
• S y m b o lic e x p re s s io n s q u ic k ly Іх ч о ш е m u c h c o m p le x .
• D if f ic u l t t o h a n d le c o m p le x d a t a s tr u c t u r e s , aiT H .vs, p o iiik u s .

• D i f f ic u lt to h a n d le lo o p s a n d re c u rs io n s t h a t d e p e n d o n iĩì p u t v a ria b le s .
2.3.2 Generalized symbolic execution with lazy initializa
tion
O l i r u f t h e d r a w b a c k s o f m o d e l c h e c k in g is th a t, i t t y p ic a lly L e q u i re s a c k )s e (l s y s te m ,
І.Г ., b o u n d o n iu p u t size s . S y m b o lic e x e c u tio n is a w e ll- k n o w n p ro g r a m a n a ly s is b u t
t r a d it io u a lly s y m b o lic e x e c u tio n is o n ly u s e d f o r c h e c k in g s e q u e n tia l p ro g ra m s w i t h
a fix e d n u m b e r o f in t e g e r v a r ia b le s w h ic h is n o t u s e fu l fo r c u r r e n t s o ftw a r e a n d i t
n 'q u h e s a (ie (li( a t( 、(l to o l to p e r f o r m t h e a n a ly s e s .
T h e r e f o r e ,w (、11(:ННІ to g e n e r a liz e t h is t r a d i t i o n a l s y m b o lic e x e c u t io n fo r l ia n d lin g
C line n t co n cu rre nt ai KỈ co m plex so ftw are, th is causes th e inv e n tio n o f gen era lize d
s y m b o lic e x e c u tio n .
G e n e ra liz e d s y m b o lic e x e c u tio n is th e c o m b in a t io n o f s y m b o lic e x e c u tio n a n d
m o d e l c h e c k in g . P r o p o s e d i l l (K h u n s id e t a l., 2 0 0 3 ), i t re a ch e s to a u t c m ia tir a lly
c h e c k p i’o g m iu s t lia t in a n ip u la lข г о ш р іе х d a ta s tr u c tu r e s . T h e fr a m e w o r k in ( К І 1Ш -
s id e t a l., 2 0 0 3 ) is ru a d e o f tw o m a in p a r ts : th e f ir s t is a n o v e l s y m b o lic e x e c u tio n
a lg o r it h m t h a t h rin d le s d y n a m ic a lly a llo r a te d s tr u c tu r e s (e .g . lis t a n d tre e s ), m e th o d
p r e c o n d it io n s (e .g . a c y c lic it y o f lis t ) , ( la ta (e .g . in te g e rs a n d s t r in g s ) a n d c o n c u r 
re n c y . T o s v iu h o lk . a ll y e x e c u te a m (、t Ы к і. th e a lg o l it im i use s
lazy initialization,
i.e .,
it in it ia liz e s th e c o m p o n e n ts o f t lie m e th o d in p u t O il a il แ ร -ne e d ed** b a s is, w it h o u t
Г(Ч|ИІ1 iu g a p r io r i b o u n d o ť ІЩ Н ІІ s ize s , a n d th e se c o n d is to ( Іе іііш o f a s o u rc e t o
s o u r c e t r a n s la t io n t o in s t iim u m t a jH O ftm n i, v v iiic h e n a b le s s t a n d a r d m o d e l c liw k e r
to p e r fo r m s y in h o lii* (»xe ru tiou o f the p ro g ra m .
2.3. Test inp u t generation by symbolic execution
21
G e n e ra liz e d s y m b o lic e x e c u tio n is th e c o r e o f J P F , a n d t h e fr a m e w o rk in (K h u i>
s id et. я !., 2 0 0 3 ) is use d in e a r ly v e rs io n s OÍ Л М Л r h c r c f o r e , t h is s e c tio n in tr o d u c e s
tw o m a in p a r ts o f g e n e r a liz e d s y m b o lic e x e c u tio n : L a z y in it ia l iz a t io n a n d c o d e
i n s t i u m e n t. Ill th e C h a p t e r 3 . w e w il l in ti o d i ic e iu ip r o v e m e n ts o f

Symbolic Java

HathFindcr
th a t h e lp it to (ฯa ' n it e p ro g r a m s in s y m b o lic , s e m a n tic s w it h o u t c o d e
in s t r u m e n t .
In la z y in it ia l iz a t i o n , th e m c t.h u d is s ta rte d b y e x e c u t in g o n in p u t s w it h
urレ

initialised
fie ld s , w h e n th e y a re li
I
St a c c e s s e d ( li n in g th e m e t h o d s s y m b o lic e x e c u 
tio n . la z y in it ia l iz a t io n w ill as s ig n va lu e s t o th e s e fie ld , i.e it in it ia l iz e s fie ld s .
T h e o p iu a t io ii o f la z y iu it ia l i / a t i o n c a ll Ы 、( lí 、s (T Ílx 4 Í w it h o n e in p u t o b je c t o f a
g iv e n c la s s c , 匕 H,n im p l i c i t in p u t
thhi
p o in t e r . M e th o d s w i t h m u lt i p le p a ra m e t e rs
a re t ie a te d s iiiii b ir ly (B o y a p a t i ๙. a l., 2 0 0 2 ). E x e c iitt? a m e th o d
m
in c , th e la z y
in i t i a liz a ti o n f ir s t (T e a te s a
IR'W
o b je c t
о
o f cla s s
с
w it II
Iiib in itia li/лчі
fie ld s . N e x t,
th e a l g o ii t h i n c a lls

o.ỉĩi()
a n d th e e x e c u tio n pioc(M .4ls h y e it h e r o u r o f th re e w a y s :
F o llo w in g J a v a s e m a n tic s w i t h o p e r a tio n s o n r e fe r e n c e fie ld s .
F o llo w in g t r a d i t io n a l s y m lx jl ic e x e c u tio n fo r o p t u a tio n s O li p r i m it iv o fie ld s .
W it h u n - in itia liz e d fie ld s , th e n o v e l s y m b o lic e x e c u tio n u ses la z y in it ia l iz a t io n
algori til in AS following:
1: i f ( F is in i- i n itia liz e d ) t h e n
2: i f ( F is a r e fe re n c e H e ld o f a s e i-d e fin e d ty p e T ) th e n
3 : n o u - d e t e i in in is t ic a lly in itia liz e F t o
4: 1. n u ll
5:
2、
ri n e w o b je c t o f chuss T ( w it h n il- in i t ia liz e d fie ld v a lu e s )
(): 3. an o b je c t cre a to c i (lu r in g a p r io r in it i a liz a tio n o f a fie ld o f t y p e T
7: i f ( m e th o d p r e c o n d itio n is v io la te d ) t h e n
8: h a c k t ra < :k ( ):
9: end if
11) : end i f
I I : i f ( F is ạ p ri m i t i v e iie ld ) t h e n
i'2 : in it ia l iz e F to
i\
n e w s y m b o lic v a lu e o f a p p r o p r ia t e ty p e
Hi

end if
N : end if

×