Questions tagged [cmocka]

Cmocka is a C unit testing framework

Cmocka is a C unit testing framework

50 questions
5
votes
1 answer

Cmocka unit testing with C: mocking nested function calls

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.…
5
votes
2 answers

How to mock functions in headerfiles?

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…
eDeviser
  • 942
  • 9
  • 33
5
votes
3 answers

How to mock function in C when its caller function is defined in same file?

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…
4
votes
1 answer

Cmocka - Error: No Entries for symbol

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…
User_MK
  • 43
  • 5
4
votes
1 answer

visual studio c linker wrap option?

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…
pogorman
  • 1,481
  • 2
  • 20
  • 34
4
votes
1 answer

"undefined reference to `_cmocka_run_group_tests'" when running sample CMocka test

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) { …
neo post modern
  • 1,164
  • 10
  • 27
4
votes
2 answers

Correct way to temporarily enable and disable function wrapping in cmocka?

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…
satur9nine
  • 11,950
  • 3
  • 68
  • 107
3
votes
2 answers

cmocka malloc testing OOM and gcov

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…
3
votes
2 answers

How to get CMocka report in JUnit format?

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…
Divya Y
  • 173
  • 1
  • 9
3
votes
1 answer

How to handle problems with RPATH on Mac OS X while installing cmocka?

I am trying to install and run cmocka library for unit testing on Mac OSX Yosemite 10.10.3, but I've got some problems with the RPATH settings. Update: Thanks to @baf, I was able to include cmocka.h in my CMakeLists.txt manually like…
Mateusz Piotrowski
  • 6,087
  • 9
  • 44
  • 71
2
votes
1 answer

How to setup a cmocka example with arm-none-eabi-gcc + cmake?

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…
Stefan Jaritz
  • 1,529
  • 7
  • 24
  • 51
2
votes
2 answers

Creating Fixtures in cmocka

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…
Alan Storm
  • 157,413
  • 86
  • 367
  • 554
2
votes
2 answers

Cmocka: checking a structure passed as a parameter

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…
Mawg says reinstate Monica
  • 34,839
  • 92
  • 281
  • 509
2
votes
2 answers

How can Cmocka test that my (void) callback function was called with the correct parameters?

I am using Cmocka for unit test and that cannot be changed. I am testing part of my software which invokes callback functions, if a value changes, indicating which data item changed and what the new value is. The callback functions have this…
Mawg says reinstate Monica
  • 34,839
  • 92
  • 281
  • 509
1
vote
0 answers

Cmocka: printing context on test failure

I am using CMocka to write some unit tests. Some of my tests loop though a list of cases which are stored in a struct to avoid repetition: typedef struct { char* test_arg; int expected; } TestCase; const static TestCase cases[] = { {"1",…
Inductiveload
  • 5,320
  • 3
  • 24
  • 47
1
2 3 4