What unit test framework can I use for a c based mcu project?
There are a lot of variables which will determine the best unit testing framework to use in you situation. Some items which may affect your choice will be:
- The target language.
- What library support is available. eg libc or a cut down version thereof.
- The operating system of the target. eg None, FreeRTOS, custom.
Most of the xUnit type frameworks will provide some base level of functionality which may be useful. I've used Cunit with some success in the past. (libcunit1-dev package on Ubuntu/Debian). Most frameworks will require libc to be available, some will require additional OS support.
Another altermative which is just 3 lines long is Minunit.
I've found unit testing using the microcontroller as the target to be quite cumbersome as you need to be able to present an environment suitable for downloading tests, running them and then getting results back. Just getting the platform in place which will enable you to do this is a big task.
Another approach that I've taken which has worked for me is to do unit testing on the host, implementing an abstraction layer between the drivers and application code. Since you're using gcc for the target, the code should also compile on the host.
Testing on the compile host is generally so much easier as you have the complete support of the host OS and all its tools. For example, when testing on the host, I have a mocked version of my wireless driver with the same interface as the real driver which runs on the target. The host version uses UDP packets to simulate wireless packet transfer, with the mock driver supporting the ability to drop packets so I can test my protocols.
In the product I was working on, a threaded OS was being used, so the abstraction layer for testing on the host OS used pthreads instead.
While not perfect, the easier it is for you to write and run tests, the more likely you are to implement more test cases. Another benefit of have the code run on different platforms is to test that the code is portable. You'll quickly pick up endian mistakes if the target and host architectures differ.
I'm now a bit off topic, but feel these ideas may help with your choice of test framework and test methods.
Check out CppUTest, and James Grenning's excellent http://pragprog.com/book/jgade/test-driven-development-for-embedded-c
CppUTest has support for C and C++, and it's got a nice set of Makefile templates that got me started pretty quickly.