33
Automated Tes,ng of Mobile Apps Mayur Naik Georgia Ins,tute of Technology Joint work with: Aravind Machiry and Rohan Tahiliani

Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

  • Upload
    others

  • View
    3

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Automated  Tes,ng  of  Mobile  Apps    

Mayur  Naik    

Georgia  Ins,tute  of  Technology    

Joint  work  with:  Aravind  Machiry  and  Rohan  Tahiliani  

       

Page 2: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

The  Growth  of  Smartphones  and  Tablets  

2  

•  1  million  new  Android  devices  ac,vated  every  day  

•  750  million  total  (March  2013)  

Page 3: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

The  Growth  of  Mobile  Apps  

3  

•  30K  new  apps  on  Google  Play  per  month  •  1  million  total  (July  2013)  

Page 4: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

The  Growth  of  Mobile  Apps  

•  1.5  billion  downloads  from  Google  Play  per  month  •  50  billion  total  (July  2013)  

4  

Page 5: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

The  Life  of  a  Mobile  App  

Development  and  tes,ng  

Pre-­‐deployment  Cer,fica,on  

Post-­‐deployment  Adapta,on  

Reliability   Security   Performance  

•  New  soTware  engineering  problems  in  all  stages          )  need  new  program  analysis-­‐based  tools    

Page 6: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Program  Analysis  for  Mobile  Apps  

•  Sta,c  Analysis  – Program  analysis  using  program  text  – Hindered  by  features  common  in  mobile  apps  

•  Large  SDK,  obfuscated  and  na,ve  code,  concurrency,  IPC,  databases,  GUIs,  …    

•  Dynamic  Analysis  – Program  analysis  using  program  runs  – Needs  test  inputs  yielding  high  app  coverage  

•  Focus  of  our  work  

6  

Page 7: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Desiderata  for  Input  Genera,on  System  

 Robust:  handles  real-­‐world  apps    

 Black-­‐box:  does  not  need  sources  or  ability  to  decompile  binaries    

 VersaAle:  exercises  important  app  func,onality  

 Automated:  reduces  manual  effort  

  Efficient:  avoids  genera,ng  redundant  inputs  

7  

Page 8: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Our  Contribu,ons  

•  Design  of  a  system  Dynodroid  sa,sfying  the  five  desired  criteria  

•  Open-­‐source  implementa,on  of  Dynodroid  on  the  dominant  Android  pla]orm  

•  Evalua,on  of  Dynodroid  on  real-­‐world  apps  against  state-­‐of-­‐the-­‐art  approaches  

8  

Page 9: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Our  Approach  

•  View  an  app  is  an  event-­‐driven  program      

 

•  Broadly  two  kinds  of  events:  – UI  event:  LongTap(245,  310),  Drag(0,  0,  245,  310),  …  –  System  event:  BaberyLow,  SmsReceived(“hello”),  ...  

•  Assump,on:  Fixed  concrete  data  in  each  event  and  environment  (sdcard,  network,  etc.)  – May  cause  loss  of  coverage  

9  

e1   e2   e3  s0   s1   s2   s3    .  .  .  

 

Page 10: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Relevant  Events  

•  Key  challenge:  Large  number  of  possible  events  –  E.g.,  108  system  events  in  Android  Gingerbread  

•  Insight  #1:  In  any  state,  few  events  are  relevant  )  vast  majority  of  events  are  no-­‐ops  

•  Insight  #2:  Can  iden,fy  relevant  events  by  lightly  instrumen,ng  SDK  once  and  for  all  ) Does  not  require  instrumen,ng  app  

10  

Page 11: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Observe-­‐Select-­‐Execute  Algorithm  

11  

s0   executor  

e1  

s1  

observer  

E1   selector  

e2  

executor   s2  

observer  

E2   selector  

e3  

•  Statelessness  does  not  cause  any  coverage  loss  in  principle  provided:  –  observer  treats  “restart  app”  event  always  relevant  –  selector  is  fair  

· · ·  

Page 12: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Event  Selec,on  Algorithms  

•  Frequency  –  Selects  event  that  has  been  selected  least  oTen  – Drawback:  determinis,c  =>  unfair  

•  UniformRandom  –  Selects  event  uniformly  at  random  – Drawback:  does  not  consider  domain  knowledge;  no  dis,nc,on  of  UI  vs.  system  events,  contexts  in  which  event  occurs,  frequent  vs.  rare  events  

•  BiasedRandom  –  Combines  benefits  of  above  without  drawbacks    

12  

Page 13: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

BiasedRandom  Event  Selec,on  Algorithm  

•  Global  map  G(e,  S)  tracks  number  of  ,mes  e  is  selected  in  context  S  –  Context  =  set  of  events  relevant  when  e  is  selected  

•  Local  map  L(e)  computed  to  select  next  event  from  relevant  set  S  –  Ini,alize:  L(e)  to  0  for  each  e  in  S  –  Repeat:  

•  Pick  an  e  in  S  uniformly  at  random  •  If  L(e)  =  G(e,  S)  increment  G(e,  S)  and  return  e  else  increment  L(e)  

•  Hallmark:  No  starva,on  13  

Page 14: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Implementa,on  of  Dynodroid  

•  Implemented  for  Android  2.3.4  (Gingerbread)  –  Covers  50%  of  all  Android  devices  (March  2013)  

•  Modified  ~  50  lines  of  the  SDK  ) Easy  to  port  to  other  Android  versions  

•  Heavily  used  off-­‐the-­‐shelf  tools  –  HierarchyViewer  to  observe  UI  events  – MonkeyRunner  to  execute  UI  events  –  Ac,vityManager  (am)  to  execute  system  events  –  Emma  to  measure  source  code  coverage  

•  Comprises  16  KLOC  of  Java  

•  Open-­‐source:  hbp://dyno-­‐droid.googlecode.com      

14  

Page 15: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Demo:  Dynodroid  on  Photostream  App  

   

 

Demo  

15  

Page 16: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Evalua,on  Study  1:  App  Code  Coverage  

•  50  open-­‐source  apps  from  F-­‐Droid  – SLOC  ranging  from  16  to  22K,  mean  of  2.7K  

•  Evaluated  Approaches:  – Dynodroid  (various  configura,ons)  – Monkey  fuzz  tes,ng  tool  

– Expert  human  users  •  Ten  graduate  students  at  Georgia  Tech  •  All  familiar  with  Android  development  

16  

Page 17: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Tes,ng  Approaches  Used  in  Our  Evalua,on  

Approach   #Events   #Runs  

Dynodroid  -­‐  Frequency   2,000   1  

Dynodroid  -­‐  UniformRandom   2,000   3  

Dynodroid  -­‐  BiasedRandom   2,000   3  

Monkey   10,000   3  

Humans   No  limit   >=  2  

17  

Page 18: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Dynodroid  vs.  Monkey  

18  

0

20

40

60

80

100

% A

pp

Co

de C

overa

ge

App ID

common Dynodroid Monkey

   47%                                              8%                                            6%  

Dynodroid  achieves  higher  coverage  than  Monkey  for  30  of  the  50  apps.  

Page 19: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Dynodroid  vs.  Humans  

19  

0

20

40

60

80

100

% A

pp

Co

de C

overa

ge

App ID

common Dynodroid Human

   51%                                              4%                                            7%  

Automa,on  Degree  =  C(Dynodroid  Å  Human)  /C(Human)    

Range  =  8-­‐100%,      Average  =  83%,      S.D.  =  21%  

Page 20: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Sample  Feedback  from  Par,cipants  

•  “Tried  to  cancel  download  to  raise  excep,on.”  

•  “Human  cannot  trigger  change  to  AudioFocus.”  

•  “Many,  many  op,ons  and  lots  of  clicking  but  no  ac,ons  really  involved  human  intelligence.”  

•  “There  are  too  many  combina,ons  of  state  changes  (play  -­‐>  pause,  etc.)  for  a  human  to  track.”  

20  

Page 21: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

0

20

40

60

80

100

% A

pp

Co

de C

overa

ge

App ID

common Dynodroidw/o system

Dynodroid

Dynodroid  without  vs.  with  System  Events  

21  

     47%                                                  2%                                                    8.3%  

Page 22: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Dynodroid  without  System  Events  vs.  Monkey  

22  

0

20

40

60

80

100

% A

pp

Co

de C

ov

era

ge

App ID

common Dynodroidw/o system

Monkey

   43%                                                  6%                                                10%  

Page 23: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Minimum  Number  of  Events  to  Peak  Coverage  

23  

•  Monkey  requires  20X  more  events  than  BiasedRandom  •  Frequency  and  UniformRandom  require  2X  more  events  

than  BiasedRandom  

Page 24: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

•  1,000  most  popular  free  apps  from  Google  Play      

 

 

 

   

 

 

•  Conserva,ve  no,on  of  bug:  FATAL  EXCEPTION  (app  forcibly  terminated)  

Evalua,on  Study  2:  Bugs  Found  in  Apps  

24  

Page 25: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Bugs  Found  in  50  F-­‐Droid  Apps  

App  Name   Bugs   Kind   DescripAon  

PasswordMakerProForAndroid   1   Null   Improper handling of user data.  

com.morphoss.acal   1   Null   Dereferencing null returned by an online service.  

hu.vsza.adsdroid   2   Null   Dereferencing null returned by an online service.  

cri.sanity   1   Null   Improper handling of user data.  

com.zoffcc.applications.aagtl   2   Null   Dereferencing null returned by an online service.  

org.beide.bomber   1   Array   Game indexes an array with improper index.  

com.addi   1   Null   Improper handling of user data.  

25  

Page 26: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Bugs  Found  in  1,000  Google  Play  Apps  

App  Name   Bugs   Kind   DescripAon  

com.ibm.events.android.usopen   1   Null   Null pointer check missed in onCreate() of an activity.  

com.nullsoft.winamp   2   Null   Improper handling of RSS feeds read from online service.  

com.almalence.night   1   Null   Null pointer check missed in onCreate() of an activity.  

com.avast.android.mobilesecurity   1   Null   Receiver callback fails to check for null in optional data.  

com.aviary.android.feather   1   Null   Receiver callback fails to check for null in optional data.  

26  

Page 27: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Limita,ons  

•  Does  not  exercise  inter-­‐app  communica,on  –  Communica,on  via  key-­‐value  maps  (“Bundle”  objects)  –  Could  synthesize  such  maps  symbolically  

•  Uses  fixed,  concrete  data  for  events  –  E.g.,  geo-­‐loca,on,  touch-­‐screen  coordinates,  etc.  –  Could  randomize  or  symbolically  infer  such  data  

•  Requires  instrumen,ng  the  pla]orm  SDK  )  Limited  to  par,cular  SDK  version  –  But  lightweight  enough  to  implement  for  other  versions  

27  

Page 28: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Related  Work  

•  Model-­‐based  Tes,ng  – GUITAR  [ASE’12],  EXSYST  [ICSE’12],  …  

•  Fuzz  Tes,ng  – Monkey,  …  

•  Symbolic  Execu,on  – Acteve  [FSE’12],  Symdroid,  …  

28  

Page 29: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

New  Challenges:  Client-­‐Driven  

•  App  code  typically  has  far  fewer  paths  than  framework  and  third-­‐party  libraries  

•  Most  clients  care  only  about  paths  in  app  code  

private  void  doTranslate()  {            Language  from  =  (Language)  fromBubon.getTag();            Language  to  =  (Language)  toBubon.getTag();            String  fromName  =  from.getShortName();            String  toName  =  to.getShortName();            String  input  =  fromEditText.getText().toString();            String  result  =  translateService.translate(input,                            fromName,  toName);            if  (result  !=  null)                          setOutputText(result);            else                          throw  new  Excep,on(…);  }  

Calls  3rd  party  library  

Called  by  framework  

Page 30: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

New  Challenges:  Mixing  Sta,c  &  Dynamic  

             public  void  onClick(View  target)  {                                if  (target  ==  play)                                            startService(new  Intent(ACTION_PLAY));                              else  if  (target  ==  pause)                                            startService(new  Intent(ACTION_PAUSE));                              else  if  (target  ==  skip)  

                                         startService(new  Intent(ACTION_SKIP));                            else  if  (target  ==  rewind)                                            startService(new  Intent(ACTION_REWIND));                            else  if  (target  ==  stop)                                            startService(new  Intent(ACTION_STOP));  

                         else  if  (target  ==  eject)                                            showUrlDialog();                }  

Fabricate  “target”;  not  used  subsequently  

Page 31: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

New  Challenges:  Mixing  Sta,c  &  Dynamic  

Cursor  c  =  query(Account.ID_PROJECTION);  int  numAccounts  =  c.getCount();  if  (numAccounts  ==  0)  

             ac,onNewAccount();  else  if  (numAccounts  ==  1)  {                c.moveToPosi,on(0);                long  accountId  =  c.getLong(Account.ID_CONTENT);              ac,onHandleAccount(accountId);  

}  else              ac,onShowAccounts();      public  class  Cursor  {              public  boolean  moveToPosi,on(int  pos)  {                          //  Check  posi,on  isn't  past  end  of  cursor  

                       int  count  =  getCount();                          if  (pos  >=  count)  return  false;                          return  true;              }  }  

Concretely  takes  this  branch  

Fabricated  to  take  this  branch  

Symbolic  state  prevents  taking  this  branch:  (c.getCount()  ==  1  ∧  0  >=  c.getCount())  is  unsat  

Page 32: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Conclusion  

•  Proposed  a  prac,cal  system  for  genera,ng  relevant  inputs  to  mobile  apps  – Sa,sfying  the  five  desirable  criteria  we  iden,fied:  robust,  black-­‐box,  versa,le,  automated,  efficient  

•  Showed  its  effec,veness  on  real-­‐world  apps  –  Significantly  automates  tasks  that  users  consider  tedious  

–  Yields  significantly  more  concise  inputs  than  fuzz  tes,ng  

–  Exposed  handful  of  crashing  bugs  

32  

Page 33: Automated)Tes,ng)of)Mobile)Apps))mei/MobileAppChallenges/... · 2013. 11. 28. · BugsFoundin1,000GooglePlayApps App)Name) Bugs Kind Descripon) com.ibm.events.android.usopen ) 1 )

Thank  You!  

hbp://pag.gatech.edu/dynodroid    

33