Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality...

75
Mutation Testing Leaving the Stone Age 2017

Transcript of Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality...

Page 1: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutation TestingLeaving the Stone Age

2017

Page 2: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

whoami• iOS Developer by day

• compiler hacker by night

• https://twitter.com/1101_debian

• https://lowlevelbits.org

• https://systemundertest.org

Page 3: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Outline• Quality of Software

• Unit Testing

• Mutation Testing

• Mull

• Showcase: LLVM Test Suite

Page 4: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Quality of Software

Page 5: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Quality of Software

• Formal Verification

Page 6: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Quality of Software

• Formal Verification

• Fuzz Testing

Page 7: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Quality of Software

• Formal Verification

• Fuzz Testing

• Unit Testing + Code Coverage

Page 8: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Quality of Software

• Formal Verification

• Fuzz Testing

• Unit Testing + Code Coverage

Page 9: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Unit Testing

Page 10: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Unit Testingint sum(int a, int b) { return a + b; }

Page 11: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Unit Testingint sum(int a, int b) { return a + b; }

void test() { assert(sum(5, 10) > 0); }

Page 12: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Unit Testingint sum(int a, int b) { return a + b; }

void test() { assert(sum(5, 10) > 0); }

Failed Tests: 0

Code Coverage: 100%

Passed Tests: 1

Page 13: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutation Testing

run_test(program, test)

Page 14: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutation Testing

run_test(program, test) mutant = mutate(program)

Page 15: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutation Testing

run_test(program, test) mutant = mutate(program) result = run_test(mutant, test)

Page 16: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutation Testing

run_test(program, test) mutant = mutate(program) result = run_test(mutant, test) if (result == Failed) report_killed_mutant(mutant, test)

Page 17: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

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)

Page 18: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutation Testingint sum(int a, int b) { return a + b; }

void test() { assert(sum(5, 10) > 0); }

Page 19: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutation Testingint sum(int a, int b) { return a + b; }

void test() { assert(sum(5, 10) > 0); }

int sum'(int a, int b) { return a * b; }

Page 20: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutation Testingint sum(int a, int b) { return a + b; }

void test() { assert(sum(5, 10) > 0); }

int sum'(int a, int b) { return a * b; }

int sum''(int a, int b) { return a - b; }

Page 21: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutation Testingint sum(int a, int b) { return a + b; }

void test() { assert(sum(5, 10) > 0); }

int sum'(int a, int b) { return a * b; }

int sum''(int a, int b) { return a - b; }

test passed -> mutant survived

Page 22: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutation Testingint sum(int a, int b) { return a + b; }

void test() { assert(sum(5, 10) > 0); }

int sum'(int a, int b) { return a * b; }

int sum''(int a, int b) { return a - b; }

test passed -> mutant survived

test failed -> mutant killed

Page 23: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutation Testing

Killed Mutants: 1

Mutation Score = killed / total * 100%

Survived Mutants: 1

Total Mutants: 2

Mutation Score: 50%

Page 24: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutation Testing

• First proposed by Richard Lipton in 1971

Page 25: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutation Testing

• First proposed by Richard Lipton in 1971

• First implemented by Timothy Budd in 1980

Page 26: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

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

Page 27: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutation Testing

• Generates lots of data

Page 28: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutation Testing

• Generates lots of data

• Time consuming

Page 29: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutation Testing

• Generates lots of data

• Time consuming

• Languages are not mutation-testing-friendly

Page 30: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutation Testing

• Generates lots of data

• Time consuming

• Languages are not mutation-testing-friendly

• Problem of a Human Test Oracle

Page 31: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

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"

Page 32: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mull

Page 33: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mull

• Smart mutant selection

Page 34: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mull

• Smart mutant selection

• Control over data generation

Page 35: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mull

• Smart mutant selection

• Control over data generation

• Runtime compilation

Page 36: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mull

• Smart mutant selection

• Control over data generation

• Runtime compilation

• Operates on LLVM IR level

Page 37: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mull

• Smart mutant selection

• Control over data generation

• Runtime compilation

• Operates on LLVM IR level

• Language agnostic*

Page 38: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutant Selection

Page 39: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutant Selection

Page 40: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutant Selection

Page 41: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutant Selection

Page 42: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutant Selection

Page 43: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutant Selection

Page 44: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

IRTests: 238 testsBefore:

391 modules

85 minutes

Page 45: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

IRTests: 238 testsBefore:

391 modules

After:

85 minutes

124 modules

48 minutes

Page 46: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutation Control

Page 47: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutation Control

Page 48: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

IRTests: 238 testsDistance: 2 Number of mutants: ~1.5k Real execution time: ~1 hour

Page 49: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

IRTests: 238 testsDistance: 2 Number of mutants: ~1.5k Real execution time: ~1 hour

Distance: 29 Number of mutants: ~18k Approximate execution time: ~11 days

Page 50: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Mutant Control

Page 51: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

System Design

Page 52: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

System Design

Mull

Page 53: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

System Design

Core

• Driver

• Reporter

• MutationOperators

Page 54: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

System Design

Core

• Driver

• Reporter

• MutationOperators

Toolchain

• JIT Compiler

• Object Cache

Page 55: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

System Design

Core

• Driver

• Reporter

• MutationOperators

Toolchain

• JIT Compiler

• Object Cache

Test Framework

• Test Finder

• Test Runner

Page 56: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

System Design

Core

• Driver

• Reporter

• MutationOperators

Toolchain

• JIT Compiler

• Object Cache

Test Framework

• Test Finder

• Test Runner

• Test Finder

• Test Runner

Google Test

Page 57: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

System Design

Core

• Driver

• Reporter

• MutationOperators

Toolchain

• JIT Compiler

• Object Cache

Test Framework

• Test Finder

• Test Runner

• Test Finder

• Test Runner

Google Test

• Test Finder

• Test Runner

XCTest

Page 58: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Showcase

• IRTests

• ADTTests

Page 59: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

IRTests

Number of tests: 238

Number of mutants: 1.5k

Mutation score: 43%

https://lowlevelbits.org/IRTests/

Page 60: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

ADTTests

Number of tests: 465

Number of mutants: 1.5k

Mutation score: 66%

http://lowlevelbits.org/ADTTests/

Page 61: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

TripleTests.*

Number of tests: 13

Number of mutants: 624

Mutation score: 83%

Page 62: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

TripleTests.*

T.setArch(Triple::mips64); EXPECT_EQ(Triple::mips64el, T.getLittleEndianArchVariant().getArch());

Page 63: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •
Page 64: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

TripleTests.*

T.setArch(Triple::mips64); EXPECT_EQ(Triple::mips64el, T.getLittleEndianArchVariant().getArch());

T.setArch(Triple::tce); EXPECT_EQ(Triple::tcele, T.getLittleEndianArchVariant().getArch());

r294095, r294096

Page 65: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

TripleTests.*

Triple T = Triple(""); T.setObjectFormat(Triple::ELF); EXPECT_EQ(Triple::ELF, T.getObjectFormat());

Page 66: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

TripleTests.*

Triple T = Triple(""); // T.setObjectFormat(Triple::ELF); EXPECT_EQ(Triple::ELF, T.getObjectFormat());

Page 67: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

TripleTests.*

Triple T = Triple(""); T.setObjectFormat(Triple::ELF); EXPECT_EQ(Triple::ELF, T.getObjectFormat());

T.setObjectFormat(Triple::MachO); EXPECT_EQ(Triple::MachO, T.getObjectFormat());

r294104

Page 68: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

IRTests

if (foobar) { fastVersion(); } else { slowVersion(); }

Page 69: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Open Questions

Page 70: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Open Questions

• Integration

Page 71: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Open Questions

• Integration

• UX

Page 72: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Open Questions

• Integration

• UX

• Next Language

Page 73: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Open Questions

• Integration

• UX

• Next Language

• Many unknowns

Page 74: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Project: https://github.com/mull-project/mull

Contact: [email protected]

Updates: https://twitter.com/1101_debian

Page 75: Mutation Testing - FOSDEM · • Mutation Testing • Mull • Showcase: LLVM Test Suite. Quality of Software. Quality of Software • Formal Verification. Quality of Software •

Project: https://github.com/mull-project/mull

Contact: [email protected]

Updates: https://twitter.com/1101_debian

Questions?