From this article Unit testing with mock objects in C:
This is done by using the --wrap linker option which takes the name of the wrapped function as an argument. If the test was compiled using gcc, the invocation might look like:
$ gcc -g…
So, toy program that duplicates the issues I am having using cmocka for developing unit tests for existing code. The issue is a nested function call does not mock, which makes the unit test dependent on the nested function call performing properly.…
I'm working on a project that's using the cmocka framework. The cmocka homepage states
Test fixtures are setup and teardown functions that can be shared across multiple test cases to provide common functions that prepare the test environment and…
I am trying to mock a function in C, mocking works fine when the function and its caller function are defined in different files. But when both functions (function itself and its caller) are defined in the same file, the mocked function does not get…
I'm just starting out with Cmocka, I've been stuck on this issue for a while now. I have a cmocka project that I'm trying to build. I'm seeing the error when I try to use 'make'.
[ ERROR ] --- No entries for symbol __wrap_i2c_read.
Also I'm…
What I am doing:
I am using cmocka to run unit tests for large embedded project.
The embedded project is compiled with a arm-gcc-compiler.
The unit tests are compiled with the normal gcc using fragments of the embedded code and the cmocka…
I installed the CMocka testing framework and tried the sample code:
#include
#include
#include
#include
/* A test case that does nothing and succeeds. */
static void null_test_success(void **state) {
…
I am using mocka to unit test a C project.
I want to mock a call to another modules made in my C function under test. This function in the other module deals with doubles, not ints. The will_return documentation says it passes integer values, and I…
I am developing firmware for stm32f4xx based systems.
For that I setup a toolchain based on the arm-none-eabi-gcc toolchain form ARM and cmake.
This toolchain works on Ubuntu. I can x-compile and debug(via openocd + eclipse IDE).
Now I like to add…
Let's say that I declare a C struct called foo, which has an int field called bar and a char * called baz.
How do I use the Cmocka expect_ and check_expected macros to check that the structure passed was correct and both fields have the expected…
I'm having a hard time finding an answer to a nitch case using cmocka, testing malloc for failure (simulating), and using gcov
Update about cmocka+gcov: I noticed I get empty gcda files as soon as I mock a function in my cmocka tests. Why? Googling…
I am able to use cmocka and getting default results on the screen. I want to get the results for the unit test in JUnit format.
CMocka supports JUnit format by using the env variable CMOCKA_MESSAGE_OUTPUT or using API…
I am using the cmocka library to test some embedded c code. According to the documentation I use the __wrap_ prefix to mock functions so I can isolate my unit tests. However once I do that all calls to the function forever go to the wrapped…
I compile the following main.c with gcc main.c -Wl,--wrap=foo -lcmocka:
#include
#include
#include
#include
#include
#include
#include
#include
typedef struct…
I'd like to write a test in cmocka and run it few times with different parameters each time (so I could test different input cases).
Something like Python's decorators @parameterized.parameters.
There are ways I can think of, like:
I can always use…