Questions tagged [cmocka]

Cmocka is a C unit testing framework

Cmocka is a C unit testing framework

66 questions
1
vote
0 answers

compiling cmocka with the xc8 compiler from microchip howto?

Good afternoon devs, When I checkout the latest cmocka version and try to compile cmocka with the xc8 compiler version 1.41 the code wont compile syntaxis error. It isnt recommend or the solution to change this cmocka source, because in the future…
RkingDev
  • 31
  • 1
  • 2
1
vote
0 answers

Configuring Cmake file for library dependency

I have a C project that I am trying to compile using CMake. This is my project structure: root ├─ CMakeLists.txt ├─ docs ├─ build └─ src ├─ main.c ├─ library1.h ├─ library2.h ├─ ... The project needs unit tests for which I'm using…
Tomy
  • 439
  • 1
  • 5
  • 13
1
vote
1 answer

Allocated memory in multiple cmocka unit tests

I'm trying to unit test some source code using cmocka. Basically the (relevant) source code looks similar to Source.c. The unit test calls each function separately. When testing the Add() function this function will eventually call util_malloc()…
Maartn
  • 15
  • 7
1
vote
2 answers

Mock/Wrap static functions called by a non-static function under test

I would like to test some functions by implementing unit tests with cmocka framework. For example I have a non-static function under test which calls two static functions. Because of the fact that these static functions interact with hardware I want…
Iniesta8
  • 399
  • 2
  • 15
1
vote
1 answer

Wrapping function in c

I got task to write unit tests(using cunit and cmocka) for existing project(written in C), and a met following problem. When I wrap function that is defined in tested file, only original function is called. Additional, a can't change source of…
mmichal10
  • 322
  • 2
  • 13
1
vote
0 answers

GCC's linker --wrap will not wrap over static library function

I am trying to mock C functions using CMocka and GCC's --wrap linker option. So far this technique has worked well for mocking stdlib functions such as fgets, popen, pclose, etc. However now I am trying to mock functions that are in a static library…
MicroJoe
  • 267
  • 3
  • 12
1
vote
0 answers

Unit testing in syntax not working

I have been trying to learn cmocka to perform unitest. After looking at various examples on internet, I am confused as to how I should do unit testing, specifically I am unable to understand following syntax: static int functionname(void **state) { …
1
vote
0 answers

Attempting to mock `abort` using CMocka and `gcc -Wl,wrap...`

I am building unit tests with CMocka. My function char some_func(some_enum e) maps valid values of e to a char. It uses assert to check e is valid, which by definition calls abort if not. Mocking abort is proving to be hard. Following this example…
Martin Cowie
  • 2,788
  • 7
  • 38
  • 74
1
vote
1 answer

How to use cmocka with FreeRTOS?

I am using cmocka on an embedded arm microcontroller (stm32) which is running FreeRTOS. Well, cmocka seems to have some problems when it is running as a FreeRTOS Task. In line 2953 some signals are initialized and this causes an stack overflow in…
eDeviser
  • 1,605
  • 2
  • 17
  • 44
1
vote
1 answer

GCC linker : passing multiple --wrap=

I am adding quite a few mocks, using cmocka, which require me to alias them using the GC Clinker opetion --wrap= I am passing a linker option of the format -Wl,--wrap=foo,--wrap=bar,--wrap=baz,--wrap= ... Is there any way to shorten…
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
1
vote
1 answer

Should I check the input variables (pointers) in a mock function?

I am writing a series of mock functions in C using CMocka Some of these take pointers as input variables and I am not sure whether I should check them (ptr != NULL) or not. In general, is the mock function responsible to perform input checking? If…
Muffo
  • 1,733
  • 2
  • 19
  • 29
1
vote
1 answer

CTest pull test names from cmocka source

I'm using CTest to run tests written with cmocka. I'd like to know if it's possible to have CTest read the test names from my cmocka source and give them to me on the output. For example, if my test source contains 3 tests: test_order_correct,…
Lily Mara
  • 3,859
  • 4
  • 29
  • 48
1
vote
1 answer

How do I link with cmocka?

I am using Eclipse under Ubuntu. I just installed cmocka: Install the project... -- Install configuration: "Debug" -- Installing: /usr/lib/pkgconfig/cmocka.pc -- Installing: /usr/lib/cmake/cmocka/cmocka-config.cmake -- Installing:…
Mawg says reinstate Monica
  • 38,334
  • 103
  • 306
  • 551
0
votes
0 answers

Cmocka: How to get a list of all failed tests at the end of the session?

I would like to print a list of all the tests that have failed to be used at the end of the session. In CMocka framework failed tests are shown after each cmocka_run_group_tests call. Is there a standard solution to show all failed tests after…
0
votes
1 answer

What happens if I cast a pointer that is NULL to something else?

I have this piece of code here: assert_ptr_equals(get_data(hm,key_three),NULL); assert_true((int*)get_data(hm,key_three)==NULL); The get_data function returns a void pointer. The first assert is true but second one fails. Any idea why? Here…
Cristian Cutitei
  • 120
  • 3
  • 12