SlideShare a Scribd company logo
Property-based testing an
open source compiler, pflua
A fast and easy way to find bugs
kbarone@igalia.com ( luatime.org )
www.igalia.com
Katerina Barone-Adesi
Summary
● What is property-based testing?
● Why is it worth using?
● Property-based testing case study with pflua,
an open source compiler
● How do you implement it in an afternoon?
● What tools already exist?
Why test?
● Reliability
● Interoperability
● Avoiding regressions
● … but this is the test room, so
hopefully people already think testing
is useful and necessary
Why property-based testing?
● Writing tests by hand is slow, boring,
expensive, and usually doesn't lead to
many tests being written
● Generating tests is cheaper, faster,
more flexible, and more fun
● Covers cases humans might not
Why is it more flexible?
● Have you ever written a set of unit
tests, then had to change them all by
hand as the code changes?
● It's a lot easier and faster to change
one part of test generation instead!
What is property-based testing?
● Choose a property (a statement that
should always be true), such as:
● somefunc(x, y) < 100
● sort(sort(x)) == sort(x) (for stable sorts)
● run(expr) == run(optimize(expr))
● our_app(input) == other_app(input)
What is property-based testing not?
● A formal proof
● Exhaustive (except for very small types)
● What that means: property-based testing tries
to find counter-examples. If you find a counter-
example, something is wrong and must be
changed. If you don't, it's evidence (NOT proof)
towards that part of your program being correct.
Why not exhaustively test?
● Too difficult
● Too expensive
● Too resource-consuming (human and computer
time)
● Formal methods and state space reduction
have limitations
What is pflua?
● Pflua is a source to source compiler
● It takes libpcap's filter language (which we call
pflang), and emits lua code
● Why? This lets us run the lua code with luajit
● Performance: better than libpcap, often by a
factor of two or more
● https://github.com/Igalia/pflua/
● Apache License, Version 2.0
What is pflang?
● The input for pflua, libpcap, and other tools
● Igalia's name for it, not an official name
● A language for defining packet filters
● Examples: “ip”, “tcp”, “tcp port 80”, …
● tcp port 80 and not host 192.168.0.1
● If you've used wireshark or tcpdump,
you've used pflang
Case study: testing pflua
● Pflua already had two forms of testing,
and works in practice
● Andy Wingo and I implemented a
property-based checker in an
afternoon, with one property...
What was the test property?
● lua code generated from optimized and
unoptimized IR has the same result on the
same random packet
● It compared two paths:
● Input → IR → optimize(IR) →
compile → run()
● Input → IR → (no change) →
compile → run()
What happened?
● We found 6/7 bugs
● Some are ones we were unlikely to
find with testing by hand
● Remember: pflua is an already-tested,
working project
What were the bugs?
● Accidental comments: 8--2 is 8, not 10! (Lua)
● Invalid optimization: ntohs/ntohl
● Generating invalid lua (return must end block)
● Range analysis: range folding bug (→ inf)
● Range analysis: not setting range of len
● Range analysis: NaN (inf – inf is not your friend)
● + a Luajit bug, found later by the same test
Case study recap
● Property-based testing is useful even for
seemingly-working, seemingly-mature code
● We found 3 bugs in range analysis
● We were unlikely to have found all 3 bugs with
unit testing by hand
● This was code that appeared to work
● Typical use didn't cause any visible problem
● 4 of the 6 bugs fixed that afternoon
Property-based testing: how?
● for i = 1,100 do
local g = generate_test_case()
run_test_case(property, g)
● Conceptually, it's that simple:
Generate and run tests (handling exceptions)
● With premade tools, you need a property,
and (sometimes) a random test generator
How to generate test cases
● The simplest version is unweighted choices:
function True() return { 'true' } end
function Comparison()
return { ComparisonOp(), Arithmetic(),
Arithmetic() } end
…
function Logical()
return choose({ Conditional, Comparison,
True, False, Fail })() end
Are unweighted choices enough?
● math.random(0, 2^32-1)
● Property: 1/y <= y
● False iff y = 0
● 4 billion test cases doesn't guarantee this will
be found...
● What are other common edge case numbers?
Weighted choices
function Number()
if math.random() < 0.2
then return math.random(0, 2^32 – 1)
else
return choose({ 0, 1, 2^32-1, 2^31-1 })
end
end
Write your own checker!
for i = 1,iterations do
local packet, packet_idx = choose(packets)
local P, len = packet.packet, packet.len
random_ir = Logical()
local unopt_lua = codegen.compile(random_ir)
local optimized = optimize.optimize(random_ir)
local opt_lua = codegen.compile(optimized)
if unopt_lua(P, len) ~= opt_lua(P, len)
then print_details_and_exit() end
end
Test generation problems
● Large, hard-to-analyze test cases
● Defaults to randomly searching the
solution space; randomly testing that
plain 'false' is still 'false' after
optimization as 20% of your 1000
tests is a bit daft
What level to test?
● For a compiler: the front-end language? Various
levels of IR? Other?
● In general: input? Internal objects?
● Tradeoffs: whitebox testing with internals can
be useful, but can break systems with internals
that the system itself cannot create.
● Testing multiple levels is possible
● Tends to test edge cases of lower levels
Interaction with interface stability
● At any level, more flexible than hand unit
testing
● Interfaces change. Inputs hopefully change
rarely; internals may change often
● Property-based testing makes refactoring
cheaper and easier: less code to change when
internals change, more test coverage
It's still worth unit testing
● Use property-based testing to find bugs (and
classes of bugs)
● Use unit tests for avoiding regressions;
continue to routinely test code that has already
caused problems, to reduce the chances that
known bugs will be re-introduced
● Use unit testing if test generation is infeasible,
or for extremely rare paths
Reproducible tests
● There are some pitfalls to outputting a
random seed to re-run tests
● The RNG may not produce consistent
results across platforms or be stable
across upgrades
● (Rare) Bugs in your compiler / interpreter
/ libraries can hinder reproducibility
Existing tools: QuickCheck
● Originally in Haskell; has been widely ported to
other languages
● Better tools for test case generation
● Allows filtering test cases
● Starts with small test cases
● QuickCheck2: test case minimization
The future of test generation
● Hypothesis, by David Ritchie MacIver (Python)
● https://github.com/DRMacIver/hypothesis
● Example database is better than saving seeds - it
propagates interesting examples between tests.
● Much smarter data generation
● Adapts to conditional tests better
● Blurs the lines between fuzz testing, conventional
unit testing and property based testing.
Forward-looking Hypothesis
● The following are planned, but not implemented
● Using coverage information to drive example
generation
● Adding "combining rules" which allow you to
also express things like "set | set -> set" and
then it can test properties on those too.
● Better workflows around integrating into CI
● End-of-February 1.0 release predicted
Other stable tools
● Scalacheck
● Quviq's Quickcheck for Erlang
● Have/inspired some of the benefits of
Hypothesis, but are already mature and widely
used
Conclusions
● Property-based testing finds tricky bugs and
saves time
● You can start it in an afternoon, with no tools
● There are some pretty helpful existing tools
(QuickCheck, Hypothesis, ScalaCheck, etc)
● Start property-based testing today!
● Or Monday, at least.

More Related Content

What's hot

JProfiler8 @ OVIRT
JProfiler8 @ OVIRTJProfiler8 @ OVIRT
JProfiler8 @ OVIRT
Liran Zelkha
 
JavaCro'14 - Test Automation using RobotFramework Libraries – Stojan Peshov
JavaCro'14 - Test Automation using RobotFramework Libraries – Stojan PeshovJavaCro'14 - Test Automation using RobotFramework Libraries – Stojan Peshov
JavaCro'14 - Test Automation using RobotFramework Libraries – Stojan Peshov
HUJAK - Hrvatska udruga Java korisnika / Croatian Java User Association
 
Refactoring legacy code driven by tests - ENG
Refactoring legacy code driven by tests - ENGRefactoring legacy code driven by tests - ENG
Refactoring legacy code driven by tests - ENG
Luca Minudel
 
News In The Net40
News In The Net40News In The Net40
News In The Net40
Florin Cardasim
 
Tips and Tricks for Testing Lambda Expressions in Android
Tips and Tricks for Testing Lambda Expressions in AndroidTips and Tricks for Testing Lambda Expressions in Android
Tips and Tricks for Testing Lambda Expressions in AndroidDavid Carver
 
Refactoring to Java 8 (Devoxx UK)
Refactoring to Java 8 (Devoxx UK)Refactoring to Java 8 (Devoxx UK)
Refactoring to Java 8 (Devoxx UK)
Trisha Gee
 
Build Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPCBuild Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPC
Tim Burks
 
Integration Group - Robot Framework
Integration Group - Robot Framework Integration Group - Robot Framework
Integration Group - Robot Framework
OpenDaylight
 
Programming with Python: Week 1
Programming with Python: Week 1Programming with Python: Week 1
Programming with Python: Week 1
Ahmet Bulut
 
Robot Framework Introduction
Robot Framework IntroductionRobot Framework Introduction
Robot Framework Introduction
Pekka Klärck
 
SecureWV - APT2
SecureWV - APT2SecureWV - APT2
SecureWV - APT2
Adam Compton
 
Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++
Hong Le Van
 
POUG2019 - Test your PL/SQL - your database will love you
POUG2019 - Test your PL/SQL - your database will love youPOUG2019 - Test your PL/SQL - your database will love you
POUG2019 - Test your PL/SQL - your database will love you
Jacek Gebal
 
How to NLProc from .NET
How to NLProc from .NETHow to NLProc from .NET
How to NLProc from .NET
Sergey Tihon
 
High-Performance Python
High-Performance PythonHigh-Performance Python
High-Performance Python
Work-Bench
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummies
Harry Potter
 
Fast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPCFast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPC
Tim Burks
 
DerbyCon - APT2
DerbyCon - APT2DerbyCon - APT2
DerbyCon - APT2
Adam Compton
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
Rowan Merewood
 

What's hot (19)

JProfiler8 @ OVIRT
JProfiler8 @ OVIRTJProfiler8 @ OVIRT
JProfiler8 @ OVIRT
 
JavaCro'14 - Test Automation using RobotFramework Libraries – Stojan Peshov
JavaCro'14 - Test Automation using RobotFramework Libraries – Stojan PeshovJavaCro'14 - Test Automation using RobotFramework Libraries – Stojan Peshov
JavaCro'14 - Test Automation using RobotFramework Libraries – Stojan Peshov
 
Refactoring legacy code driven by tests - ENG
Refactoring legacy code driven by tests - ENGRefactoring legacy code driven by tests - ENG
Refactoring legacy code driven by tests - ENG
 
News In The Net40
News In The Net40News In The Net40
News In The Net40
 
Tips and Tricks for Testing Lambda Expressions in Android
Tips and Tricks for Testing Lambda Expressions in AndroidTips and Tricks for Testing Lambda Expressions in Android
Tips and Tricks for Testing Lambda Expressions in Android
 
Refactoring to Java 8 (Devoxx UK)
Refactoring to Java 8 (Devoxx UK)Refactoring to Java 8 (Devoxx UK)
Refactoring to Java 8 (Devoxx UK)
 
Build Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPCBuild Great Networked APIs with Swift, OpenAPI, and gRPC
Build Great Networked APIs with Swift, OpenAPI, and gRPC
 
Integration Group - Robot Framework
Integration Group - Robot Framework Integration Group - Robot Framework
Integration Group - Robot Framework
 
Programming with Python: Week 1
Programming with Python: Week 1Programming with Python: Week 1
Programming with Python: Week 1
 
Robot Framework Introduction
Robot Framework IntroductionRobot Framework Introduction
Robot Framework Introduction
 
SecureWV - APT2
SecureWV - APT2SecureWV - APT2
SecureWV - APT2
 
Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++Test driven development and unit testing with examples in C++
Test driven development and unit testing with examples in C++
 
POUG2019 - Test your PL/SQL - your database will love you
POUG2019 - Test your PL/SQL - your database will love youPOUG2019 - Test your PL/SQL - your database will love you
POUG2019 - Test your PL/SQL - your database will love you
 
How to NLProc from .NET
How to NLProc from .NETHow to NLProc from .NET
How to NLProc from .NET
 
High-Performance Python
High-Performance PythonHigh-Performance Python
High-Performance Python
 
Google mock for dummies
Google mock for dummiesGoogle mock for dummies
Google mock for dummies
 
Fast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPCFast and Reliable Swift APIs with gRPC
Fast and Reliable Swift APIs with gRPC
 
DerbyCon - APT2
DerbyCon - APT2DerbyCon - APT2
DerbyCon - APT2
 
Living With Legacy Code
Living With Legacy CodeLiving With Legacy Code
Living With Legacy Code
 

Viewers also liked

Pairing WebKit and Wayland for Linux-Based Embedded Web Content Presentation ...
Pairing WebKit and Wayland for Linux-Based Embedded Web Content Presentation ...Pairing WebKit and Wayland for Linux-Based Embedded Web Content Presentation ...
Pairing WebKit and Wayland for Linux-Based Embedded Web Content Presentation ...
Igalia
 
Recent Improvements in Epiphany and WebKitGTK+ (GUADEC 2015)
Recent Improvements in Epiphany and WebKitGTK+ (GUADEC 2015)Recent Improvements in Epiphany and WebKitGTK+ (GUADEC 2015)
Recent Improvements in Epiphany and WebKitGTK+ (GUADEC 2015)
Igalia
 
How to test OpenGL drivers using Free Software (FOSDEM 2015)
How to test OpenGL drivers using Free Software (FOSDEM 2015)How to test OpenGL drivers using Free Software (FOSDEM 2015)
How to test OpenGL drivers using Free Software (FOSDEM 2015)
Igalia
 
A Short Introduction to Servo (Web Engines Hackfest 2014)
A Short Introduction to Servo (Web Engines Hackfest 2014)A Short Introduction to Servo (Web Engines Hackfest 2014)
A Short Introduction to Servo (Web Engines Hackfest 2014)
Igalia
 
Self-hosted JS (ffconf 2014)
Self-hosted JS (ffconf 2014)Self-hosted JS (ffconf 2014)
Self-hosted JS (ffconf 2014)
Igalia
 
GStreamer support in WebKit. What's new? (GStreamer Conference 2015)
GStreamer support in WebKit. What's new? (GStreamer Conference 2015)GStreamer support in WebKit. What's new? (GStreamer Conference 2015)
GStreamer support in WebKit. What's new? (GStreamer Conference 2015)
Igalia
 
CSS Grid Layout is Just Around the Corner (CSSConf US 2015)
CSS Grid Layout is Just Around the Corner (CSSConf US 2015)CSS Grid Layout is Just Around the Corner (CSSConf US 2015)
CSS Grid Layout is Just Around the Corner (CSSConf US 2015)
Igalia
 
New interoperability features in LibreOffice
New interoperability features in LibreOfficeNew interoperability features in LibreOffice
New interoperability features in LibreOffice
Igalia
 
CSS Grid Layout. Specification overview. Implementation status and roadmap (B...
CSS Grid Layout. Specification overview. Implementation status and roadmap (B...CSS Grid Layout. Specification overview. Implementation status and roadmap (B...
CSS Grid Layout. Specification overview. Implementation status and roadmap (B...
Igalia
 
Efficient multimedia support in QtWebKit on Raspberry Pi (GStreamer Conferenc...
Efficient multimedia support in QtWebKit on Raspberry Pi (GStreamer Conferenc...Efficient multimedia support in QtWebKit on Raspberry Pi (GStreamer Conferenc...
Efficient multimedia support in QtWebKit on Raspberry Pi (GStreamer Conferenc...
Igalia
 
GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...
GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...
GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...
Igalia
 
Spelunking through JPEG with Racket (Sixth RacketCon)
Spelunking through JPEG with Racket (Sixth RacketCon)Spelunking through JPEG with Racket (Sixth RacketCon)
Spelunking through JPEG with Racket (Sixth RacketCon)
Igalia
 

Viewers also liked (12)

Pairing WebKit and Wayland for Linux-Based Embedded Web Content Presentation ...
Pairing WebKit and Wayland for Linux-Based Embedded Web Content Presentation ...Pairing WebKit and Wayland for Linux-Based Embedded Web Content Presentation ...
Pairing WebKit and Wayland for Linux-Based Embedded Web Content Presentation ...
 
Recent Improvements in Epiphany and WebKitGTK+ (GUADEC 2015)
Recent Improvements in Epiphany and WebKitGTK+ (GUADEC 2015)Recent Improvements in Epiphany and WebKitGTK+ (GUADEC 2015)
Recent Improvements in Epiphany and WebKitGTK+ (GUADEC 2015)
 
How to test OpenGL drivers using Free Software (FOSDEM 2015)
How to test OpenGL drivers using Free Software (FOSDEM 2015)How to test OpenGL drivers using Free Software (FOSDEM 2015)
How to test OpenGL drivers using Free Software (FOSDEM 2015)
 
A Short Introduction to Servo (Web Engines Hackfest 2014)
A Short Introduction to Servo (Web Engines Hackfest 2014)A Short Introduction to Servo (Web Engines Hackfest 2014)
A Short Introduction to Servo (Web Engines Hackfest 2014)
 
Self-hosted JS (ffconf 2014)
Self-hosted JS (ffconf 2014)Self-hosted JS (ffconf 2014)
Self-hosted JS (ffconf 2014)
 
GStreamer support in WebKit. What's new? (GStreamer Conference 2015)
GStreamer support in WebKit. What's new? (GStreamer Conference 2015)GStreamer support in WebKit. What's new? (GStreamer Conference 2015)
GStreamer support in WebKit. What's new? (GStreamer Conference 2015)
 
CSS Grid Layout is Just Around the Corner (CSSConf US 2015)
CSS Grid Layout is Just Around the Corner (CSSConf US 2015)CSS Grid Layout is Just Around the Corner (CSSConf US 2015)
CSS Grid Layout is Just Around the Corner (CSSConf US 2015)
 
New interoperability features in LibreOffice
New interoperability features in LibreOfficeNew interoperability features in LibreOffice
New interoperability features in LibreOffice
 
CSS Grid Layout. Specification overview. Implementation status and roadmap (B...
CSS Grid Layout. Specification overview. Implementation status and roadmap (B...CSS Grid Layout. Specification overview. Implementation status and roadmap (B...
CSS Grid Layout. Specification overview. Implementation status and roadmap (B...
 
Efficient multimedia support in QtWebKit on Raspberry Pi (GStreamer Conferenc...
Efficient multimedia support in QtWebKit on Raspberry Pi (GStreamer Conferenc...Efficient multimedia support in QtWebKit on Raspberry Pi (GStreamer Conferenc...
Efficient multimedia support in QtWebKit on Raspberry Pi (GStreamer Conferenc...
 
GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...
GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...
GStreamer-VAAPI: Hardware-accelerated encoding and decoding on Intel hardware...
 
Spelunking through JPEG with Racket (Sixth RacketCon)
Spelunking through JPEG with Racket (Sixth RacketCon)Spelunking through JPEG with Racket (Sixth RacketCon)
Spelunking through JPEG with Racket (Sixth RacketCon)
 

Similar to Property-based testing an open-source compiler, pflua (FOSDEM 2015)

Performance optimization techniques for Java code
Performance optimization techniques for Java codePerformance optimization techniques for Java code
Performance optimization techniques for Java code
Attila Balazs
 
Creating a Mature Puppet System
Creating a Mature Puppet SystemCreating a Mature Puppet System
Creating a Mature Puppet System
Puppet
 
Creating a mature puppet system
Creating a mature puppet systemCreating a mature puppet system
Creating a mature puppet systemrkhatibi
 
Unit testing (eng)
Unit testing (eng)Unit testing (eng)
Unit testing (eng)
Anatoliy Okhotnikov
 
May 2021 Spark Testing ... or how to farm reputation on StackOverflow
May 2021 Spark Testing ... or how to farm reputation on StackOverflowMay 2021 Spark Testing ... or how to farm reputation on StackOverflow
May 2021 Spark Testing ... or how to farm reputation on StackOverflow
Adam Doyle
 
Continuous testing and deployment in Perl (London.pm Technical Meeting Octobe...
Continuous testing and deployment in Perl (London.pm Technical Meeting Octobe...Continuous testing and deployment in Perl (London.pm Technical Meeting Octobe...
Continuous testing and deployment in Perl (London.pm Technical Meeting Octobe...
Alex Balhatchet
 
Beyond unit tests: Deployment and testing for Hadoop/Spark workflows
Beyond unit tests: Deployment and testing for Hadoop/Spark workflowsBeyond unit tests: Deployment and testing for Hadoop/Spark workflows
Beyond unit tests: Deployment and testing for Hadoop/Spark workflows
DataWorks Summit
 
The Popper Experimentation Protocol and CLI tool
The Popper Experimentation Protocol and CLI toolThe Popper Experimentation Protocol and CLI tool
The Popper Experimentation Protocol and CLI tool
Ivo Jimenez
 
Write unit test from scratch
Write unit test from scratchWrite unit test from scratch
Write unit test from scratch
Wen-Shih Chao
 
Gatling
Gatling Gatling
Gatling
Gaurav Shukla
 
Performance Test Automation With Gatling
Performance Test Automation  With GatlingPerformance Test Automation  With Gatling
Performance Test Automation With Gatling
Knoldus Inc.
 
Functional Programming - Worth the Effort
Functional Programming - Worth the EffortFunctional Programming - Worth the Effort
Functional Programming - Worth the Effort
BoldRadius Solutions
 
Scripting Recipes for Testers
Scripting Recipes for TestersScripting Recipes for Testers
Scripting Recipes for Testers
Adam Goucher
 
NovaProva, a new generation unit test framework for C programs
NovaProva, a new generation unit test framework for C programsNovaProva, a new generation unit test framework for C programs
NovaProva, a new generation unit test framework for C programs
Greg Banks
 
Ui Testing with Ghost Inspector
Ui Testing with Ghost InspectorUi Testing with Ghost Inspector
Ui Testing with Ghost Inspector
Harvard Web Working Group
 
Making Strongly-typed NETCONF Usable
Making Strongly-typed NETCONF UsableMaking Strongly-typed NETCONF Usable
Making Strongly-typed NETCONF Usable
Open Networking Summit
 
Go fundamentals
Go fundamentalsGo fundamentals
Go fundamentals
Ron Barabash
 
TAP In Depth
TAP In DepthTAP In Depth
TAP In Depth
Michael Peters
 
Test all the things! Automated testing with Drupal 8
Test all the things! Automated testing with Drupal 8Test all the things! Automated testing with Drupal 8
Test all the things! Automated testing with Drupal 8
Sam Becker
 

Similar to Property-based testing an open-source compiler, pflua (FOSDEM 2015) (20)

Performance optimization techniques for Java code
Performance optimization techniques for Java codePerformance optimization techniques for Java code
Performance optimization techniques for Java code
 
Creating a Mature Puppet System
Creating a Mature Puppet SystemCreating a Mature Puppet System
Creating a Mature Puppet System
 
Creating a mature puppet system
Creating a mature puppet systemCreating a mature puppet system
Creating a mature puppet system
 
Unit testing (eng)
Unit testing (eng)Unit testing (eng)
Unit testing (eng)
 
UPC Plone Testing Talk
UPC Plone Testing TalkUPC Plone Testing Talk
UPC Plone Testing Talk
 
May 2021 Spark Testing ... or how to farm reputation on StackOverflow
May 2021 Spark Testing ... or how to farm reputation on StackOverflowMay 2021 Spark Testing ... or how to farm reputation on StackOverflow
May 2021 Spark Testing ... or how to farm reputation on StackOverflow
 
Continuous testing and deployment in Perl (London.pm Technical Meeting Octobe...
Continuous testing and deployment in Perl (London.pm Technical Meeting Octobe...Continuous testing and deployment in Perl (London.pm Technical Meeting Octobe...
Continuous testing and deployment in Perl (London.pm Technical Meeting Octobe...
 
Beyond unit tests: Deployment and testing for Hadoop/Spark workflows
Beyond unit tests: Deployment and testing for Hadoop/Spark workflowsBeyond unit tests: Deployment and testing for Hadoop/Spark workflows
Beyond unit tests: Deployment and testing for Hadoop/Spark workflows
 
The Popper Experimentation Protocol and CLI tool
The Popper Experimentation Protocol and CLI toolThe Popper Experimentation Protocol and CLI tool
The Popper Experimentation Protocol and CLI tool
 
Write unit test from scratch
Write unit test from scratchWrite unit test from scratch
Write unit test from scratch
 
Gatling
Gatling Gatling
Gatling
 
Performance Test Automation With Gatling
Performance Test Automation  With GatlingPerformance Test Automation  With Gatling
Performance Test Automation With Gatling
 
Functional Programming - Worth the Effort
Functional Programming - Worth the EffortFunctional Programming - Worth the Effort
Functional Programming - Worth the Effort
 
Scripting Recipes for Testers
Scripting Recipes for TestersScripting Recipes for Testers
Scripting Recipes for Testers
 
NovaProva, a new generation unit test framework for C programs
NovaProva, a new generation unit test framework for C programsNovaProva, a new generation unit test framework for C programs
NovaProva, a new generation unit test framework for C programs
 
Ui Testing with Ghost Inspector
Ui Testing with Ghost InspectorUi Testing with Ghost Inspector
Ui Testing with Ghost Inspector
 
Making Strongly-typed NETCONF Usable
Making Strongly-typed NETCONF UsableMaking Strongly-typed NETCONF Usable
Making Strongly-typed NETCONF Usable
 
Go fundamentals
Go fundamentalsGo fundamentals
Go fundamentals
 
TAP In Depth
TAP In DepthTAP In Depth
TAP In Depth
 
Test all the things! Automated testing with Drupal 8
Test all the things! Automated testing with Drupal 8Test all the things! Automated testing with Drupal 8
Test all the things! Automated testing with Drupal 8
 

More from Igalia

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
Igalia
 
Building End-user Applications on Embedded Devices with WPE
Building End-user Applications on Embedded Devices with WPEBuilding End-user Applications on Embedded Devices with WPE
Building End-user Applications on Embedded Devices with WPE
Igalia
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Igalia
 
Automated Testing for Web-based Systems on Embedded Devices
Automated Testing for Web-based Systems on Embedded DevicesAutomated Testing for Web-based Systems on Embedded Devices
Automated Testing for Web-based Systems on Embedded Devices
Igalia
 
Embedding WPE WebKit - from Bring-up to Maintenance
Embedding WPE WebKit - from Bring-up to MaintenanceEmbedding WPE WebKit - from Bring-up to Maintenance
Embedding WPE WebKit - from Bring-up to Maintenance
Igalia
 
Optimizing Scheduler for Linux Gaming.pdf
Optimizing Scheduler for Linux Gaming.pdfOptimizing Scheduler for Linux Gaming.pdf
Optimizing Scheduler for Linux Gaming.pdf
Igalia
 
Running JS via WASM faster with JIT
Running JS via WASM      faster with JITRunning JS via WASM      faster with JIT
Running JS via WASM faster with JIT
Igalia
 
To crash or not to crash: if you do, at least recover fast!
To crash or not to crash: if you do, at least recover fast!To crash or not to crash: if you do, at least recover fast!
To crash or not to crash: if you do, at least recover fast!
Igalia
 
Implementing a Vulkan Video Encoder From Mesa to GStreamer
Implementing a Vulkan Video Encoder From Mesa to GStreamerImplementing a Vulkan Video Encoder From Mesa to GStreamer
Implementing a Vulkan Video Encoder From Mesa to GStreamer
Igalia
 
8 Years of Open Drivers, including the State of Vulkan in Mesa
8 Years of Open Drivers, including the State of Vulkan in Mesa8 Years of Open Drivers, including the State of Vulkan in Mesa
8 Years of Open Drivers, including the State of Vulkan in Mesa
Igalia
 
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por IgaliaIntroducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Igalia
 
2023 in Chimera Linux
2023 in Chimera                    Linux2023 in Chimera                    Linux
2023 in Chimera Linux
Igalia
 
Building a Linux distro with LLVM
Building a Linux distro        with LLVMBuilding a Linux distro        with LLVM
Building a Linux distro with LLVM
Igalia
 
turnip: Update on Open Source Vulkan Driver for Adreno GPUs
turnip: Update on Open Source Vulkan Driver for Adreno GPUsturnip: Update on Open Source Vulkan Driver for Adreno GPUs
turnip: Update on Open Source Vulkan Driver for Adreno GPUs
Igalia
 
Graphics stack updates for Raspberry Pi devices
Graphics stack updates for Raspberry Pi devicesGraphics stack updates for Raspberry Pi devices
Graphics stack updates for Raspberry Pi devices
Igalia
 
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOSDelegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
Igalia
 
MessageFormat: The future of i18n on the web
MessageFormat: The future of i18n on the webMessageFormat: The future of i18n on the web
MessageFormat: The future of i18n on the web
Igalia
 
Replacing the geometry pipeline with mesh shaders
Replacing the geometry pipeline with mesh shadersReplacing the geometry pipeline with mesh shaders
Replacing the geometry pipeline with mesh shaders
Igalia
 
I'm not an AMD expert, but...
I'm not an AMD expert, but...I'm not an AMD expert, but...
I'm not an AMD expert, but...
Igalia
 
Status of Vulkan on Raspberry
Status of Vulkan on RaspberryStatus of Vulkan on Raspberry
Status of Vulkan on Raspberry
Igalia
 

More from Igalia (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Building End-user Applications on Embedded Devices with WPE
Building End-user Applications on Embedded Devices with WPEBuilding End-user Applications on Embedded Devices with WPE
Building End-user Applications on Embedded Devices with WPE
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Automated Testing for Web-based Systems on Embedded Devices
Automated Testing for Web-based Systems on Embedded DevicesAutomated Testing for Web-based Systems on Embedded Devices
Automated Testing for Web-based Systems on Embedded Devices
 
Embedding WPE WebKit - from Bring-up to Maintenance
Embedding WPE WebKit - from Bring-up to MaintenanceEmbedding WPE WebKit - from Bring-up to Maintenance
Embedding WPE WebKit - from Bring-up to Maintenance
 
Optimizing Scheduler for Linux Gaming.pdf
Optimizing Scheduler for Linux Gaming.pdfOptimizing Scheduler for Linux Gaming.pdf
Optimizing Scheduler for Linux Gaming.pdf
 
Running JS via WASM faster with JIT
Running JS via WASM      faster with JITRunning JS via WASM      faster with JIT
Running JS via WASM faster with JIT
 
To crash or not to crash: if you do, at least recover fast!
To crash or not to crash: if you do, at least recover fast!To crash or not to crash: if you do, at least recover fast!
To crash or not to crash: if you do, at least recover fast!
 
Implementing a Vulkan Video Encoder From Mesa to GStreamer
Implementing a Vulkan Video Encoder From Mesa to GStreamerImplementing a Vulkan Video Encoder From Mesa to GStreamer
Implementing a Vulkan Video Encoder From Mesa to GStreamer
 
8 Years of Open Drivers, including the State of Vulkan in Mesa
8 Years of Open Drivers, including the State of Vulkan in Mesa8 Years of Open Drivers, including the State of Vulkan in Mesa
8 Years of Open Drivers, including the State of Vulkan in Mesa
 
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por IgaliaIntroducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
 
2023 in Chimera Linux
2023 in Chimera                    Linux2023 in Chimera                    Linux
2023 in Chimera Linux
 
Building a Linux distro with LLVM
Building a Linux distro        with LLVMBuilding a Linux distro        with LLVM
Building a Linux distro with LLVM
 
turnip: Update on Open Source Vulkan Driver for Adreno GPUs
turnip: Update on Open Source Vulkan Driver for Adreno GPUsturnip: Update on Open Source Vulkan Driver for Adreno GPUs
turnip: Update on Open Source Vulkan Driver for Adreno GPUs
 
Graphics stack updates for Raspberry Pi devices
Graphics stack updates for Raspberry Pi devicesGraphics stack updates for Raspberry Pi devices
Graphics stack updates for Raspberry Pi devices
 
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOSDelegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
 
MessageFormat: The future of i18n on the web
MessageFormat: The future of i18n on the webMessageFormat: The future of i18n on the web
MessageFormat: The future of i18n on the web
 
Replacing the geometry pipeline with mesh shaders
Replacing the geometry pipeline with mesh shadersReplacing the geometry pipeline with mesh shaders
Replacing the geometry pipeline with mesh shaders
 
I'm not an AMD expert, but...
I'm not an AMD expert, but...I'm not an AMD expert, but...
I'm not an AMD expert, but...
 
Status of Vulkan on Raspberry
Status of Vulkan on RaspberryStatus of Vulkan on Raspberry
Status of Vulkan on Raspberry
 

Recently uploaded

Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
g2nightmarescribd
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
Ana-Maria Mihalceanu
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
Jemma Hussein Allen
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
DanBrown980551
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Tobias Schneck
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
Dorra BARTAGUIZ
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
Product School
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
91mobiles
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 

Recently uploaded (20)

Generating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using SmithyGenerating a custom Ruby SDK for your web service or Rails API using Smithy
Generating a custom Ruby SDK for your web service or Rails API using Smithy
 
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdfFIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
FIDO Alliance Osaka Seminar: FIDO Security Aspects.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Monitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR EventsMonitoring Java Application Security with JDK Tools and JFR Events
Monitoring Java Application Security with JDK Tools and JFR Events
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
The Future of Platform Engineering
The Future of Platform EngineeringThe Future of Platform Engineering
The Future of Platform Engineering
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
LF Energy Webinar: Electrical Grid Modelling and Simulation Through PowSyBl -...
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
Kubernetes & AI - Beauty and the Beast !?! @KCD Istanbul 2024
 
Elevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object CalisthenicsElevating Tactical DDD Patterns Through Object Calisthenics
Elevating Tactical DDD Patterns Through Object Calisthenics
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
From Siloed Products to Connected Ecosystem: Building a Sustainable and Scala...
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdfSmart TV Buyer Insights Survey 2024 by 91mobiles.pdf
Smart TV Buyer Insights Survey 2024 by 91mobiles.pdf
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 

Property-based testing an open-source compiler, pflua (FOSDEM 2015)

  • 1. Property-based testing an open source compiler, pflua A fast and easy way to find bugs kbarone@igalia.com ( luatime.org ) www.igalia.com Katerina Barone-Adesi
  • 2. Summary ● What is property-based testing? ● Why is it worth using? ● Property-based testing case study with pflua, an open source compiler ● How do you implement it in an afternoon? ● What tools already exist?
  • 3. Why test? ● Reliability ● Interoperability ● Avoiding regressions ● … but this is the test room, so hopefully people already think testing is useful and necessary
  • 4. Why property-based testing? ● Writing tests by hand is slow, boring, expensive, and usually doesn't lead to many tests being written ● Generating tests is cheaper, faster, more flexible, and more fun ● Covers cases humans might not
  • 5. Why is it more flexible? ● Have you ever written a set of unit tests, then had to change them all by hand as the code changes? ● It's a lot easier and faster to change one part of test generation instead!
  • 6. What is property-based testing? ● Choose a property (a statement that should always be true), such as: ● somefunc(x, y) < 100 ● sort(sort(x)) == sort(x) (for stable sorts) ● run(expr) == run(optimize(expr)) ● our_app(input) == other_app(input)
  • 7. What is property-based testing not? ● A formal proof ● Exhaustive (except for very small types) ● What that means: property-based testing tries to find counter-examples. If you find a counter- example, something is wrong and must be changed. If you don't, it's evidence (NOT proof) towards that part of your program being correct.
  • 8. Why not exhaustively test? ● Too difficult ● Too expensive ● Too resource-consuming (human and computer time) ● Formal methods and state space reduction have limitations
  • 9. What is pflua? ● Pflua is a source to source compiler ● It takes libpcap's filter language (which we call pflang), and emits lua code ● Why? This lets us run the lua code with luajit ● Performance: better than libpcap, often by a factor of two or more ● https://github.com/Igalia/pflua/ ● Apache License, Version 2.0
  • 10.
  • 11. What is pflang? ● The input for pflua, libpcap, and other tools ● Igalia's name for it, not an official name ● A language for defining packet filters ● Examples: “ip”, “tcp”, “tcp port 80”, … ● tcp port 80 and not host 192.168.0.1 ● If you've used wireshark or tcpdump, you've used pflang
  • 12. Case study: testing pflua ● Pflua already had two forms of testing, and works in practice ● Andy Wingo and I implemented a property-based checker in an afternoon, with one property...
  • 13. What was the test property? ● lua code generated from optimized and unoptimized IR has the same result on the same random packet ● It compared two paths: ● Input → IR → optimize(IR) → compile → run() ● Input → IR → (no change) → compile → run()
  • 14. What happened? ● We found 6/7 bugs ● Some are ones we were unlikely to find with testing by hand ● Remember: pflua is an already-tested, working project
  • 15. What were the bugs? ● Accidental comments: 8--2 is 8, not 10! (Lua) ● Invalid optimization: ntohs/ntohl ● Generating invalid lua (return must end block) ● Range analysis: range folding bug (→ inf) ● Range analysis: not setting range of len ● Range analysis: NaN (inf – inf is not your friend) ● + a Luajit bug, found later by the same test
  • 16. Case study recap ● Property-based testing is useful even for seemingly-working, seemingly-mature code ● We found 3 bugs in range analysis ● We were unlikely to have found all 3 bugs with unit testing by hand ● This was code that appeared to work ● Typical use didn't cause any visible problem ● 4 of the 6 bugs fixed that afternoon
  • 17. Property-based testing: how? ● for i = 1,100 do local g = generate_test_case() run_test_case(property, g) ● Conceptually, it's that simple: Generate and run tests (handling exceptions) ● With premade tools, you need a property, and (sometimes) a random test generator
  • 18. How to generate test cases ● The simplest version is unweighted choices: function True() return { 'true' } end function Comparison() return { ComparisonOp(), Arithmetic(), Arithmetic() } end … function Logical() return choose({ Conditional, Comparison, True, False, Fail })() end
  • 19. Are unweighted choices enough? ● math.random(0, 2^32-1) ● Property: 1/y <= y ● False iff y = 0 ● 4 billion test cases doesn't guarantee this will be found... ● What are other common edge case numbers?
  • 20. Weighted choices function Number() if math.random() < 0.2 then return math.random(0, 2^32 – 1) else return choose({ 0, 1, 2^32-1, 2^31-1 }) end end
  • 21. Write your own checker! for i = 1,iterations do local packet, packet_idx = choose(packets) local P, len = packet.packet, packet.len random_ir = Logical() local unopt_lua = codegen.compile(random_ir) local optimized = optimize.optimize(random_ir) local opt_lua = codegen.compile(optimized) if unopt_lua(P, len) ~= opt_lua(P, len) then print_details_and_exit() end end
  • 22. Test generation problems ● Large, hard-to-analyze test cases ● Defaults to randomly searching the solution space; randomly testing that plain 'false' is still 'false' after optimization as 20% of your 1000 tests is a bit daft
  • 23. What level to test? ● For a compiler: the front-end language? Various levels of IR? Other? ● In general: input? Internal objects? ● Tradeoffs: whitebox testing with internals can be useful, but can break systems with internals that the system itself cannot create. ● Testing multiple levels is possible ● Tends to test edge cases of lower levels
  • 24. Interaction with interface stability ● At any level, more flexible than hand unit testing ● Interfaces change. Inputs hopefully change rarely; internals may change often ● Property-based testing makes refactoring cheaper and easier: less code to change when internals change, more test coverage
  • 25. It's still worth unit testing ● Use property-based testing to find bugs (and classes of bugs) ● Use unit tests for avoiding regressions; continue to routinely test code that has already caused problems, to reduce the chances that known bugs will be re-introduced ● Use unit testing if test generation is infeasible, or for extremely rare paths
  • 26. Reproducible tests ● There are some pitfalls to outputting a random seed to re-run tests ● The RNG may not produce consistent results across platforms or be stable across upgrades ● (Rare) Bugs in your compiler / interpreter / libraries can hinder reproducibility
  • 27. Existing tools: QuickCheck ● Originally in Haskell; has been widely ported to other languages ● Better tools for test case generation ● Allows filtering test cases ● Starts with small test cases ● QuickCheck2: test case minimization
  • 28. The future of test generation ● Hypothesis, by David Ritchie MacIver (Python) ● https://github.com/DRMacIver/hypothesis ● Example database is better than saving seeds - it propagates interesting examples between tests. ● Much smarter data generation ● Adapts to conditional tests better ● Blurs the lines between fuzz testing, conventional unit testing and property based testing.
  • 29. Forward-looking Hypothesis ● The following are planned, but not implemented ● Using coverage information to drive example generation ● Adding "combining rules" which allow you to also express things like "set | set -> set" and then it can test properties on those too. ● Better workflows around integrating into CI ● End-of-February 1.0 release predicted
  • 30. Other stable tools ● Scalacheck ● Quviq's Quickcheck for Erlang ● Have/inspired some of the benefits of Hypothesis, but are already mature and widely used
  • 31. Conclusions ● Property-based testing finds tricky bugs and saves time ● You can start it in an afternoon, with no tools ● There are some pretty helpful existing tools (QuickCheck, Hypothesis, ScalaCheck, etc) ● Start property-based testing today! ● Or Monday, at least.