Hacker News new | past | comments | ask | show | jobs | submit login
Speck – A small unit testing framework for C (github.com/compiler-dept)
40 points by apfohl on Oct 16, 2015 | hide | past | favorite | 12 comments



The way I tend to approach testing (I develop embedded s/w) is to use host-based unit testing on the majority of the code . Any h/w layers (read drivers) can only really be tested via system-level testing. It is more critical to have system-level testing on any real-time time-sensitive software; you can't really separate the behaviour of the s/w from the behaviour of the h/w.

...so, while nice to have another framework, most unit testing for embedded code can be performed on the host (i.e Linux or Windows).


So you write it as Speck, but you pronounce it as bacon? Nice.


I suspect that that's a joke. The author is German and "Speck" is the German word for "bacon".



I use minunit, http://www.jera.com/techinfo/jtns/jtn002.html, in my embedded projects. The tricky part when unit testing embedded stuff is separating stuff that works on "pure data" from stuff that has a dependency on the hardware. For example, if a function uses a hardware sensor input to calculate a value, you either have to encapsulate that input into a function you can mock, or pass it as a parameter and avoid mocking altogether. The good news is that forces you to use a more well-separated design, eg with separate .c modules to read discrete and analog values, so it ends up being more maintainable.


I was looking for a small unit test framework for a micro controller (think Cortex-M0/3/4). I looked at Unity, minunit, and cmocka. All depend on dynamic allocation and that was a deal breaker.

I gave up hunting and created nanotest[0] to target and encourage embedded unit testing. Nanotest runs on desktop dev machines, cloud CI, and minimal ARM environments.

[0] http://github.com/kylemanna/nanotest


When I was writing lots of C, I found that unit testing wasn't able to test for the things that I really wanted. Looking back, I think adding -fsanitize=undefined or similar to the compiler options for my test suite would have gotten me much closer to where I'd liked to have been.


It's maybe worth noting that we (pypy team) had a huge success testing C code just with cffi, writing tests in python. It gives you the ability to write C, but with all the flexibility of python for testing and some debugging (sometimes you obviously have to use gdb)


I normally use Minunit which is 3 lines of source code.

http://www.jera.com/techinfo/jtns/jtn002.html


Have you heard the good word of Unity[0]?

[0]: https://github.com/ThrowTheSwitch/Unity



What is the target user base?




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: