Questions tagged [cmocka]

Cmocka is a C unit testing framework

Cmocka is a C unit testing framework

66 questions
8
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,641
  • 2
  • 22
  • 41
6
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.…
Jason Fisher
  • 81
  • 1
  • 5
6
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…
Alana Storm
  • 164,128
  • 91
  • 395
  • 599
6
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…
Gautam Kumar
  • 63
  • 1
  • 3
5
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
  • 63
  • 1
  • 6
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
  • 1,605
  • 2
  • 17
  • 44
5
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
  • 2,262
  • 18
  • 30
4
votes
1 answer

How do I pass a double value to my C mock function with cmocka will_return()?

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…
Tom Willis
  • 306
  • 4
  • 10
4
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,999
  • 7
  • 36
  • 60
4
votes
3 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
  • 38,334
  • 103
  • 306
  • 551
4
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…
4
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
  • 183
  • 1
  • 9
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
  • 13,927
  • 5
  • 80
  • 123
3
votes
1 answer

Wrapped function pointer parameter changes if return value struct has too many members

I compile the following main.c with gcc main.c -Wl,--wrap=foo -lcmocka: #include #include #include #include #include #include #include #include typedef struct…
karobar
  • 1,250
  • 8
  • 30
  • 61
3
votes
0 answers

c cmocka running the same test function with different parameters

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…
A-mit
  • 31
  • 1
1
2 3 4 5