test generation for higher order test generation for
play

Test Generation For Higher-Order Test Generation For Higher-Order - PowerPoint PPT Presentation

Test Generation For Higher-Order Test Generation For Higher-Order Functions In Dynamic Languages Functions In Dynamic Languages Marija Selakovic Marija Selakovic , Michael Pradel, Rezwana Karim, Frank Tip , Michael Pradel, Rezwana Karim, Frank


  1. Test Generation For Higher-Order Test Generation For Higher-Order Functions In Dynamic Languages Functions In Dynamic Languages Marija Selakovic Marija Selakovic , Michael Pradel, Rezwana Karim, Frank Tip , Michael Pradel, Rezwana Karim, Frank Tip OOPSLA 2018 OOPSLA 2018

  2. Automatic Test Generation Automatic Test Generation Testing 1

  3. Automatic Test Generation Automatic Test Generation Testing Limited resources 1

  4. Automatic Test Generation Automatic Test Generation Testing 1

  5. Automatic Test Generation Automatic Test Generation Testing Generates test cases in an automated way Reduces manual effort Effective in finding programming erros 1

  6. Automatic Test Generation Automatic Test Generation Testing Generates test cases in an automated way Reduces manual effort Effective in finding programming erros 1

  7. Example Example Function: Tests: includes('car','a'); // true function includes(str, s) { if (s === '') return true; includes('car',''); // true includes('car', 'km'); //false return str.indexOf(s) != -1; }; size([1,2,3]); // 3 function size(arr) { size(undefined); // 0 if (!arr) return 0; size([]); //0 return arr.length; }; 2

  8. Higher-Order Functions (HOF) Higher-Order Functions (HOF) HOF: takes other functions as inputs that are called back Function: Test case: hof(x,cb){ var r = cb(x); ? if (r && x.a){ ..... } .... } 3

  9. Challenges Challenges Goal: Generate Effective Tests for Higher-Order Functions hof(x,cb){ var r = cb(x); if (r && x.a){ ..... } ? .... } 4

  10. Challenges Challenges Goal: Generate Effective Tests for Higher-Order Functions Challenge 1: callback position? hof(x,cb){ var r = cb(x); if (r && x.a){ ..... } ? .... } 4

  11. Challenges Challenges Goal: Generate Effective Tests for Higher-Order Functions Challenge 1: callback position? hof(x,cb){ Challenge 2: callback that var r = cb(x); interacts with program? if (r && x.a){ ..... cb(x){ } ? .... } } 4

  12. Challenges Challenges Goal: Generate Effective Tests for Higher-Order Functions Challenge 1: callback position? hof(x,cb){ Challenge 2: callback that var r = cb(x); interacts with program? if (r && x.a){ ..... cb(x){ } ? .... } } Challenge 3: Chaining multiple calls? 4

  13. Challenges Challenges Goal: Generate Effective Tests for Higher-Order Functions Challenge 1: callback position? hof(x,cb){ Challenge 2: callback that var r = cb(x); interacts with program? if (r && x.a){ ..... cb(x){ } ? .... } } Challenge 3: Chaining multiple calls? Challenge 4: Callback related differences? 4

  14. LambdaTester: Framework For LambdaTester: Framework For Testing Higher-Order Functions Testing Higher-Order Functions Functions + setup code Inference of Generate Execute test callback position method call feedback Store test Tests 5

  15. Inference of Callback Positions Inference of Callback Positions higherOrderFunction(arg 1 , arg 2 ,...,arg n ) Is callback executed? Positions 6

  16. Inference of Callback Positions Inference of Callback Positions callback? higherOrderFunction(arg 1 , arg 2 ,...,arg n ) Is callback executed? Positions Yes [1] 6

  17. Inference of Callback Positions Inference of Callback Positions callback? higherOrderFunction(arg 1 , arg 2 ,...,arg n ) callback? Is callback executed? Positions Yes [1] Yes [1, 2] 6

  18. Inference of Callback Positions Inference of Callback Positions callback? callback? higherOrderFunction(arg 1 , arg 2 ,...,arg n ) callback? Is callback executed? Positions Yes [1] Yes [1, 2] No [1, 2] 6

  19. Background: Feedback-Directed Background: Feedback-Directed Test Generation Test Generation Add method call 1 Feedback : Execute sequence no crash return values crash or no max size? yes Store test [1] Carlos Pacheco, Shuvendu K. Lahiri, Thomas Ball, Michael D. Ernst. Feedback-Directed Random Test Generation , ICSE '07 7

  20. Background: Feedback-Directed Background: Feedback-Directed Test Generation Test Generation Test : Setup code + Sequence of method calls Add method call 1 Feedback : Execute sequence no crash return values crash or no max size? yes Store test [1] Carlos Pacheco, Shuvendu K. Lahiri, Thomas Ball, Michael D. Ernst. Feedback-Directed Random Test Generation , ICSE '07 7

  21. Callback Generation Approaches Callback Generation Approaches function () { function () { return 17; } } 2 cb-empty cb-quick function (err) { if (err) throw err; } cb-mined cb-writes 8 [2] Koen Claessen and John Hughes. 2011. QuickCheck: A Lightweight Tool for Random Testing of Haskell Programs . SIGPLAN Not. 46

  22. Callback Generation Approaches Callback Generation Approaches no computation function () { no return value } cb-empty function (err) { if (err) throw err; } cb-mined 8

  23. Callback Generation Approaches Callback Generation Approaches returns random values function () { no additional computation return 17; } 2 cb-quick cb-writes 8 [2] Koen Claessen and John Hughes. 2011. QuickCheck: A Lightweight Tool for Random Testing of Haskell Programs . SIGPLAN Not. 46

  24. Callback Generation Approaches Callback Generation Approaches function () { } cb-empty extracted from existing code function (err) { function expressions passed to if (err) throw err; methods with the same name } cb-mined 8

  25. Callback Generation Approaches Callback Generation Approaches function () { function () { return 17; } } cb-empty cb-quick function (err) { if (err) throw err; } cb-mined cb-writes 8

  26. Dynamic Analysis Dynamic Analysis hof(x,cb){ cb(x){ ... ? var r = cb(x); if (r && x.a){ } ... } ... } 9

  27. Dynamic Analysis Dynamic Analysis Analysis of memory reads after callback executes hof(x,cb){ cb(x){ ... ? var r = cb(x); if (r && x.a){ } ... } ... } 9

  28. Dynamic Analysis Dynamic Analysis Analysis of memory reads after callback executes hof(x,cb){ cb(x){ ... ? var r = cb(x); if (r && x.a){ } ... } ... } 9

  29. Dynamic Analysis Dynamic Analysis Analysis of memory reads after callback executes hof(x,cb){ cb(x){ ... ? var r = cb(x); if (r && x.a){ } ... } ... } r x.a 9

  30. Dynamic Analysis Dynamic Analysis Analysis of memory reads after callback executes hof(x,cb){ cb(x){ cb(x){ ... x.a = true; ? var r = cb(x); if (r && x.a){ return 23; } ... } } ... } r x.a 9

  31. Application: Differential Application: Differential Testing of Polyfills Testing of Polyfills Functions + Tests LambdaTester setup code 10

  32. Application: Differential Application: Differential Testing of Polyfills Testing of Polyfills Polyfill : implementation of an API not supported by older browsers Differential testing : testing the same program on different implementations Differential Testing Functions + Tests LambdaTester of Polyfills setup code Behavioral differences 10

  33. Application: Differential Application: Differential Testing of Polyfills Testing of Polyfills Polyfill : implementation of an API not supported by older browsers Differential testing : testing the same program on different implementations Differential Testing Functions + Tests LambdaTester of Polyfills setup code Oracles: Behavioral Error messages differences Non-termination Standard output Receiver and return object Callback arguments Number of callback invocations 10

  34. Evaluation Evaluation Setup: Polyfill.io, es5shim, mozilla and 10 Promise libraries Base approach: unaware of callbacks 1000 generated tests for each polyfill/approach combination Research Questions: Effectiveness? LambdaTester finds differences in 12 libraries Coverage? LambdaTester achieves on average 75% statement coverage Efficiency? Time to generate single test ranges between 0.12 and 12 seconds 11

  35. Effectiveness Effectiveness In how many libraries LambdaTester finds behavioral differences? 12 10 Number of libraries 8 6 4 2 0 b c c c c b b b b a s - - - - e q m w e m u r i i n i c t p e e k t d s y 12

  36. Effectiveness Effectiveness In how many libraries LambdaTester finds behavioral differences? 12 10 Number of libraries 8 6 4 2 0 b c c c c b b b b a s - - - - e q m w e m u r i i n i c t p e e k t d s y cb-writes finds behavioral differences in 12 out of 13 libraries 12

  37. Behavioral Differences Behavioral Differences What types of behavioral differences LambdaTester finds? 800 cb-empty 700 Number of differences cb-quick 600 cb-mined 500 cb-writes 400 300 200 100 0 errors stout non-term receiver return c. arg c. inv 13

  38. Example: Q library Example: Q library var Promise = require('q'); var p1 = Promise.resolve(18); var p2 = Promise.reject(17); var r1 = p1.then(function(){ return null; }, null); var r2 = p2.then(function(){ return r1; }); var r3 = r2.catch(function(){ return p2; }); var r4 = r1.then(function(){ return r4; }); //non-termination 14

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend