mutation testing
play

Mutation Testing How good your tests are 2017 whoami iOS - PowerPoint PPT Presentation

Mutation Testing How good your tests are 2017 whoami iOS Developer by day compiler hacker by night https://twitter.com/1101_debian https://lowlevelbits.org https://systemundertest.org Mars Climate Orbiter Mars Climate


  1. Mutation Testing How good your tests are 2017

  2. whoami • iOS Developer by day • compiler hacker by night • https://twitter.com/1101_debian • https://lowlevelbits.org • https://systemundertest.org

  3. Mars Climate Orbiter

  4. Mars Climate Orbiter

  5. Therac-25 Jun Jul Aug Sep Oct Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Jan ‘85 ‘86 ‘87

  6. Therac-25 Injury Jun Jul Aug Sep Oct Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Jan ‘85 ‘86 ‘87

  7. Therac-25 Injury Bugfix It’s fine Jun Jul Aug Sep Oct Nov Dec Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec Jan ‘85 ‘86 ‘87

  8. More Incidents https://github.com/stanislaw/awesome-safety-critical#incidents

  9. Quality of Software

  10. Quality of Software • Formal Verification

  11. Quality of Software • Formal Verification • Fuzz Testing

  12. Quality of Software • Formal Verification • Fuzz Testing • Unit Testing + Code Coverage

  13. Quality of Software • Formal Verification • Fuzz Testing • Unit Testing + Code Coverage

  14. Unit Testing

  15. Unit Testing void test() { int sum(int a, int b) { assert(sum(5, 10) > 0); return a + b; } } Failed Tests: 0 Passed Tests: 1 Code Coverage: 100%

  16. Mutation Testing

  17. Mutation Testing run_test(program, test)

  18. Mutation Testing run_test(program, test) mutant = mutate(program)

  19. Mutation Testing run_test(program, test) mutant = mutate(program) result = run_test(mutant, test)

  20. Mutation Testing run_test(program, test) mutant = mutate(program) result = run_test(mutant, test) if (result == Failed) report_killed_mutant(mutant, test)

  21. Mutation Testing run_test(program, test) mutant = mutate(program) result = run_test(mutant, test) if (result == Failed) report_killed_mutant(mutant, test) else report_survived_mutant(mutant, test)

  22. Mutation Testing int sum(int a, int b) { void test() { return a + b; assert(sum(5, 10) > 0); } }

  23. Mutation Testing int sum(int a, int b) { void test() { return a + b; assert(sum(5, 10) > 0); } } int sum’(int a, int b) { return a * b ; }

  24. Mutation Testing int sum(int a, int b) { void test() { return a + b; assert(sum(5, 10) > 0); } } int sum’(int a, int b) { return a * b ; } int sum’’(int a, int b) { return a - b ; }

  25. Mutation Testing int sum(int a, int b) { void test() { return a + b; assert(sum(5, 10) > 0); } } int sum’(int a, int b) { test passed -> return a * b ; mutant survived } int sum’’(int a, int b) { return a - b ; }

  26. Mutation Testing int sum(int a, int b) { void test() { return a + b; assert(sum(5, 10) > 0); } } int sum’(int a, int b) { test passed -> return a * b ; mutant survived } int sum’’(int a, int b) { test failed -> return a - b ; mutant killed }

  27. Mutation Testing Total Mutants: 2 Killed Mutants: 1 Survived Mutants: 1 Mutation Score = killed / total * 100% Mutation Score: 50%

  28. Mutation Testing • First proposed by Richard Lipton in 1971

  29. Mutation Testing • First proposed by Richard Lipton in 1971 • First implemented by Timothy Budd in 1980

  30. Mutation Testing • First proposed by Richard Lipton in 1971 • First implemented by Timothy Budd in 1980 • Studies say that MT was able to detect 70%-90% of real faults

  31. Mutation Testing • Generates lots of data

  32. Mutation Testing • Generates lots of data • Time consuming

  33. Mutation Testing • Generates lots of data • Time consuming • Languages are not mutation-testing-friendly

  34. Mutation Testing • Generates lots of data • Time consuming • Languages are not mutation-testing-friendly • Problem of a Human Test Oracle

  35. Mutation Testing • Generates lots of data • Time consuming • Languages are not mutation-testing-friendly • Problem of a Human Test Oracle • "Excuse me, but I write good tests"

  36. Mull

  37. Mull • Smart mutant selection

  38. Mull • Smart mutant selection • Control over data generation

  39. Mull • Smart mutant selection • Control over data generation • Runtime compilation

  40. Mull • Smart mutant selection • Control over data generation • Runtime compilation • Operates on LLVM IR level

  41. Mull • Smart mutant selection • Control over data generation • Runtime compilation • Operates on LLVM IR level • Language agnostic*

  42. Language agnostic Frontend Backend • Clang LLVM • Rust • Swift • …

  43. Language agnostic Frontend Backend Source Machine • Clang Code Code LLVM • Rust • Swift • …

  44. Language agnostic Frontend Backend Source Machine LLVM IR • Clang Code Code LLVM • Rust • Swift • …

  45. Language agnostic Source Machine Code Code LLVM IR Frontend OS Backend

  46. Language agnostic Source Machine Code Code LLVM IR Frontend OS Backend Machine Code JIT Mull

  47. Mutant Selection

  48. Mutant Selection

  49. Mutant Selection

  50. Mutant Selection

  51. Mutant Selection

  52. Mutant Selection

  53. IRTests*: 238 tests Before: 391 modules 85 minutes * Part of LLVM’s test suite

  54. IRTests*: 238 tests Before: After: 391 modules 124 modules 85 minutes 48 minutes * Part of LLVM’s test suite

  55. Mutation Control

  56. Mutation Control

  57. IRTests*: 238 tests Distance: 2 Number of mutants: ~1.5k Real execution time: ~1 hour * Part of LLVM’s test suite

  58. IRTests*: 238 tests Distance: 2 Number of mutants: ~1.5k Real execution time: ~1 hour Distance: 29 Number of mutants: ~18k Approximate execution time: ~11 days * Part of LLVM’s test suite

  59. Mutation Control

  60. System Design

  61. System Design Mull

  62. System Design Core • Driver • Reporter • Mutation 
 Operators

  63. System Design Core Toolchain • Driver • JIT Compiler • Reporter • Object Cache • Mutation 
 Operators

  64. System Design Core Toolchain Test Framework • Driver • JIT Compiler • Test Finder • Reporter • Object Cache • Test Runner • Mutation 
 Operators

  65. System Design Core Toolchain Test Framework • Driver • JIT Compiler • Test Finder Google Test • Reporter • Object Cache • Test Runner • Test Finder • Mutation 
 Operators • Test Runner

  66. System Design Core Toolchain Test Framework • Driver • JIT Compiler • Test Finder Google Test • Reporter • Object Cache • Test Runner XCTest • Mutation 
 Operators • Test Finder • Test Runner

  67. Showcase • LLVM - compilers and dev tools, C++. • fmt - formatting library, C++. • Nom - parser combinators library, Rust. • CryptoSwift - collection of cryptographic algorithms, Swift.

  68. Example #1

  69. template < typename T> unsigned ComputeEditDistance( ArrayRef <T> FromArray, ArrayRef <T> ToArray, bool AllowReplacements = true , unsigned MaxEditDistance = 0 ) { typename ArrayRef <T>::size_type m = FromArray.size(); typename ArrayRef <T>::size_type n = ToArray.size(); const unsigned SmallBufferSize = 64 ; unsigned SmallBuffer[SmallBufferSize]; std :: unique_ptr < unsigned []> Allocated; unsigned *Row = SmallBuffer; if (n + 1 > SmallBufferSize) { Row = new unsigned [n + 1 ]; Allocated. reset (Row); } for ( unsigned i = 1 ; i <= n; ++i) Row[i] = i; for ( typename ArrayRef <T>::size_type y = 1 ; y <= m; ++y) { Row[ 0 ] = y; unsigned BestThisRow = Row[ 0 ]; unsigned Previous = y - 1 ; for ( typename ArrayRef <T>::size_type x = 1 ; x <= n; ++x) { int OldRow = Row[x]; if (AllowReplacements) { Row[x] = std ::min( Previous + (FromArray[y- 1 ] == ToArray[x- 1 ] ? 0 u : 1 u), std ::min(Row[x- 1 ], Row[x])+ 1 ); } else { if (FromArray[y- 1 ] == ToArray[x- 1 ]) Row[x] = Previous; else Row[x] = std ::min(Row[x- 1 ], Row[x]) + 1 ; } Previous = OldRow; BestThisRow = std ::min(BestThisRow, Row[x]); } if (MaxEditDistance && BestThisRow > MaxEditDistance) return MaxEditDistance + 1 ; } unsigned Result = Row[n]; return Result; }

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