Hacker News new | past | comments | ask | show | jobs | submit login

One of my favorite features recently while developing C for embedded systems has been the --wrap linker flag that allows me to effectively test code that interacts with hardware without modifying the source.

By passing -Wl,--wrap=some_function at link time with test code we can then define

  __wrap_some_function
that will be called instead of some function. Within __wrap_some_function one can also call __real_some_function which will resolve to the original version if you still want to call the original one. This is especially useful if trying to observe certain function calls in tests that interact with hardware.

Do you have any other recommendations/preferences to help with unit-testing C code?




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

Search: