Updated (September 9, 2017): Updated this post use ceedling commands instead of rake commands based on recent changes to Ceedling. You want to try unit testing your embedded software but there's a problem - you've got an existing project and a whole lot of code already written. Maybe it's even embedded legacy code. You can build, load and run your application just fine from your IDE. But where do the tests go and how do you run them? And what does it mean for your existing project? Well, it turns out that you can add Ceedling to your project and run it independently from your IDE and release build.
The test code (and framework) will be isolated from your production code and won't interfere with your release builds. This allows you to experiment with unit testing. Without messing with the rest of your team. Using Ceedling like this is the quickest way to get Unity and CMock set up to test your code. Don't worry about integrating with Eclipse (or whatever IDE you're using) yet - just get your tests running from the command line first.
Typically, you have some source files that your IDE compiles into a release build that can be run on the target. These test binaries are built in their own build folder so they don't interfere with your existing release configuration. The tests are executed independently from your IDE by running just a few simple commands from the command prompt.
Start with an existing project In this exercise I'm using an example project for the development board. It's a simple little board with an ARM Cortex-M4. The example is based on TI's 'blinky' project, which just blinks an LED. We'll be modifying this code as we progress, but you can find the starting point for this exercise. The project source consists of a main loop in blinky.c and an LED driver in led.c.
The main loop just calls into the LED driver with ledturnon and ledturnoff to do the blinking. Notice here that the source files are all mixed-in with other types of files here. I am not a fan of this nonsense.
But this is pretty common especially with IDEs from embedded vendors. I much prefer the convention of putting all the source in it's own folder. This is cleaner, makes the project tree easier to understand, and also makes it easier to configure Ceedling. We'll revisit this a little later.
For now though - since we're just getting started - we'll leave everything as it is here and install Ceedling along side of it. That way we won't break anything in this existing project. Install and configure Ceedling Before you can add Ceedling to your project you'll need to install Ceedling on your system. This also requires installing Ruby and GCC.
If you need help with this, you can find some. Once Ruby, GCC and Ceedling are installed, the first step is to install Ceedling into the existing project. This is done from the command line. WARNING: This is going to dump a bunch files into your project. As with any project changes make sure you've got a backup somewhere - preferably in source control. Ceedling has a new command for creating 'new' projects.
It's not obvious, but you can also use new to install Ceedling into an existing project. Let's check it out. So from the command line, go in to the parent folder of your project.
In this case, it's the folder above our blinky project. From there you'll run ceedling new blinky (since our project is in a folder named 'blinky'). This will install Ceedling into your existing project folder by creating some new files and folders: projects ceedling new blinky Welcome to Ceedling!
Create blinky/vendor/ceedling/docs/CeedlingPacket.pdf create blinky/vendor/ceedling/docs/CExceptionSummary.pdf. Create blinky/vendor/ceedling/vendor/unity/src/unityinternals.h create blinky/project.yml Project 'blinky' created! - Tool documentation is located in vendor/ceedling/docs - Execute 'ceedling help' to view available test & build tasks Now you can drop into the blinky project folder and run Ceedling with ceedling test:all.
We've haven't created any tests yet though, so no tests are actually going to execute: projects cd blinky projects blinky ceedling test:all - OVERALL TEST SUMMARY - No tests executed. Ceedling just added these files and folders to the project:. build: This is where the tests are built.
src: This is where Ceedling expects to find your source code. test: This is where your unit tests will go. vendor: This is where the Ceedling source files are. project.yml: This is the configuration file for Ceedling.