
Speck – A small unit testing framework for C - apfohl
https://github.com/compiler-dept/speck
======
TickleSteve
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).

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

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

~~~
davidw
[https://en.m.wikipedia.org/wiki/Tyrolean_Speck](https://en.m.wikipedia.org/wiki/Tyrolean_Speck)

------
crystalmeph
I use minunit,
[http://www.jera.com/techinfo/jtns/jtn002.html](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.

------
2bluesc
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](http://github.com/kylemanna/nanotest)

------
DanWaterworth
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.

------
fijal
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)

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

[http://www.jera.com/techinfo/jtns/jtn002.html](http://www.jera.com/techinfo/jtns/jtn002.html)

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

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

~~~
apfohl
Yes, indeed.
[http://embedded.fm/episodes/103](http://embedded.fm/episodes/103)

------
78666cdc
What is the target user base?

