Continuous testing for Arduino libraries using PlatformIO and Travis CI

Posted by Ryan on 13 March 2017
Tags: arduino

At Pololu we maintain around thirty open-source Arduino libraries, and we keep adding new ones whenever we make a new carrier board or Arduino shield. People typically use these libraries with Arduino-compatible boards, such as our A-Star programmable controllers or Arduinos. We also have Arduino libraries for our user-programmable robot kits like the Romi 32U4 robot, Balboa 32U4 robot and Zumo 32U4 robot.

Sometimes we need to make changes to a lot of libraries at once, like when we wanted to add all of our libraries to the Arduino Library Manager. For us, library manager compatibility requires changing the directory layout, but doesn’t require changing the library or example code. With this many libraries to change, there is a risk of potentially breaking a working library by misspelling or moving a file incorrectly. Fortunately, customer Walt Sorensen introduced us to PlatformIO and Travis CI, which let us test compiling Arduino libraries every time they are pushed to GitHub.

Setting this up is easy enough that we encourage you to do it on your Arduino libraries! First, sign up for Travis CI (a testing service, free for open-source projects) and enable it for the GitHub repository you want to test. Now, every time you push new code to your repository, Travis CI will try to see if there is a .travis.yml file in the top level with instructions for running tests.

If your project has the structure of an Arduino Library Manager project and you have at least one example sketch, our short .travis.yml file should work. This file instructs Travis CI to compile the library and its examples against all the supported Arduino boards (specified in the “env” list of the .travis.yml file). The results can be seen on Travis CI’s website (for example, here is Pololu’s Travis CI page). The Arduino compiler is provided by PlatformIO, an open source ecosystem for internet-of-things development, which supports a long list of Arduino-compatible boards.

You can share your Travis CI build status by embedding a badge into your GitHub readme page:

Of course, for most library changes, we still have to test on actual hardware, but now every time we update our libraries (or a contributor submits a pull request), we can be sure they will at least compile on every supported board.

2 comments

Continuous Integration sure revolutionized the industry when it came into widespread use! I'm glad you're seeing the value, too.
The next step up is Continuous Testing. One could say that "it links cleanly" is a kind of smoke test, I guess?
I've found it worthwhile for my longer projects to go further, and build a "dummy" software version of my hardware devices, and build and link against a library that implements a simulated device.
I can do this on a full host (Windows or Linux) and then run a full-software simulation, against which I can then write acceptance tests.
It's actually pretty easy to write a fake "Wiring.h" library and provide fake serial port objects and such. I highly recommend it as a next step!
Hey Jon W., I generally like that approach. For some of our proprietary firmware, we like to run the firmware in a simulator and run automated tests against the simulation. When testing 8-bit PIC firmware, we use a tool we made called RPicSim so that we can write our tests in Ruby.

Post a comment

Using your Pololu account allows you to customize your avatar and manage your comments; you can also post anonymously.

New Products

150:1 Micro Metal Gearmotor MP 6V with 12 CPR Encoder, Back Connector
A5984 Stepper Motor Driver Carrier, Fixed 1A@5V / 660mA@3.3V, Blue Edition
ACS37220LEZATR-100B5 Current Sensor Compact Carrier -100A to +100A, 5V
ACS72981LLRATR-050B3 Current Sensor Compact Carrier -50A to +50A, 3.3V
CT432-HSWF65MR TMR Current Sensor Compact Carrier -65A to +65A, 5V
5V, 100mA Step-Down Voltage Regulator D45V1E2F5
ACS72981KLRATR-150B5 Current Sensor Compact Carrier -150A to +150A, 5V
ACS37220LEZATR-150B5 Current Sensor Compact Carrier -150A to +150A, 5V
1.4-7V, 3.8A Fine-Adjust Step-Down Voltage Regulator w/ Adjustable Low-Voltage Cutoff D30V33MALCMA
CT433-HSWF50DR TMR Current Sensor Large Carrier 0A to 50A, 3.3V
Log In
Pololu Robotics & Electronics
Shopping cart
(702) 262-6648
Same-day shipping, worldwide
Menu
Shop Blog Forum Support
My account Comments or questions? About Pololu Contact Ordering information Distributors