This post describes how to use GitHub, Travis CI, and PlatformIO to automatically test build Arduino libraries.
Modern languages and frameworks typically have mature, well-developed facilities for performing unit, integration, and functional testing. The Arduino/C++ platform is not as well-developed in terms of automated testing. Developers traditionally rely on manual testing of libraries (build via Arduino IDE) which is slow, prone to human error, and limit the ability to test against multiple hardware architectures.
The following are required:
- GitHub account
- Travis CI account
- You can sign in with your GitHub account
- Arduino library
- Mac OS X:
brew install platformio(v3.0.1 used)
- Mac OS X:
In the following example, the ModbusMaster Arduino library code is hosted on GitHub and Travis CI is configured to run for each push to the repository.
make is used to build the example sketches included with the library for each of 5 commonly used Arduino boards. During development, the command may be run from the console in order to build against individual boards or the entire set. The
Makefile in the root directory of the library defines the build process and is configured to parallelize the Travis CI builds for multiple hardware architectures.
Makefile settings: adjust, as required; they are identical for all my projects.
FIND- points to bash
DIR- location of examples to build; this directory will be recursively searched for source files
CRITERIA- search for
BUILD- points to bash
LIB- location of library to include in build
Makefile targets: run from the console for all or specific board testing.
make all- runs
make uno- sets
make due- sets
make huzzah- sets
make genuino101- sets
make teensy31- sets
Makefile targets: call from Travis CI to conduct builds in parallel.
make build- iterates through example directory, building each one in series
.travis.yml configures Travis CI. In this example, Travis CI will run 5 parallel builds–1 for each
While developing the library, run
make from the console to build all examples against all boards configured in the
When code is pushed to the GitHub repository, Travis CI will automatically build all examples against each hardware architecture. Failed builds will be flagged in Pull Requests / commits so they may be resolved prior to merge.
GitHub, Travis CI, and PlatformIO provide an effective platform for continuous integration test building of Arduino libraries. This integration assures the developer that their library compiles cleanly against selected hardware platforms.
((( - )))
kyab / travis-test-arduino - inspiration for my use of PlatformIO
4-20ma / ModbusMaster - example library illustrating Arduino continuous integration
PlatformIO / PlatformIO - open source ecosystem for IoT development
Arduino Reference / Libraries
Gnu / Introduction to Makefiles
Wikipedia / make
Wikipedia / Makefile