Questions tagged [cmocka]

Cmocka is a C unit testing framework

cmocka
Filter by
Sorted by
Tagged with
0 votes
0 answers
34 views

Failed to run C program cmocka unit test

I tried to clone the below project and run it in my computer. https://github.com/samvrlewis/cmocka-embedded-example But got the below error. I checked the cmocka is already installed in my computer. ...
findingdori's user avatar
4 votes
2 answers
500 views

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

I am using cmocka 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 ...
Tom Willis's user avatar
0 votes
1 answer
91 views

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

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 ...
Cristian Cutitei's user avatar
0 votes
0 answers
36 views

How do I properly build cmocka unit tests with CMake [duplicate]

I have a simple test code suite set up in the C language to provide a template for the use of CMake to simultaneously build unit tests with cmocka and also build the integrated code in the main.c file....
Jon's user avatar
  • 1,721
0 votes
0 answers
53 views

Is there a possibility of unit testing database functions using cmocka?

I am trying to make some unit tests for database functions in C language, but i am not aware is it possible with cmocka? I couldn't find any example on the internet for database testing using cmocka, ...
jst's user avatar
  • 1
0 votes
0 answers
342 views

Is it possible to use "cmocka" in visual studio solution?

I have tried "cmocka" in visual studio solution, and it works fine with simple asserts. But when it comes to "mocking" I can't find a way to "mock" the functions from the ...
jst's user avatar
  • 1
0 votes
0 answers
190 views

How to get the duration time of each test cases in Cmocka?

I was learning how to work with CMocka unit-testing framework in my C project. So far everything goes well, and I can also generate a HTML report from CMocka's XML output by junit2html. When I read ...
Risusdan's user avatar
1 vote
1 answer
506 views

Cmocka - should we all be creating one executable per test for isolating static variables?

Failure Given the following cmocka test with a static variable in a dependency: main.c #include <stdarg.h> #include <stddef.h> #include <setjmp.h> #include <cmocka.h> #include &...
karobar's user avatar
  • 1,300
3 votes
1 answer
236 views

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 <stdio.h> #include <string.h> #include <stdlib.h> #include <stdint.h> #include <stdarg.h>...
karobar's user avatar
  • 1,300
2 votes
0 answers
154 views

Integrating a library in eclipse stops the debug exe from running as expected

I am trying to set up a C project with cmocka unit test framework in eclipse. Following software is used: Windows 10 gcc 9.2.0 cmocka 1.1.0 Eclipse cdt 4.22.0 I create a new default Hello World ANSI ...
UnbescholtenerBuerger's user avatar
0 votes
1 answer
359 views

set_target_properties does not work with multiple --wrap functions

#include <stdarg.h> #include <setjmp.h> #include <stddef.h> #include <cmocka.h> #include "stdint.h" typedef enum { eSTATE_STARTUP, eSTATE_ADDRESSING, ...
arda30's user avatar
  • 83
2 votes
0 answers
464 views

Cmocka: how to mock a function called as a function pointer

INT32 shellInit(shell_t *shell) { INT32 ret = ZKOS_SUCCESS; /* initialize shell device */ if (shell->dev->ops->init) { if ((ret = shell->dev->ops->init(shell-...
Wanghz's user avatar
  • 325
0 votes
0 answers
206 views

Compiling problems using mock of CMocka

I'm trying to compile the chef example from the CMocka project examples - link. When I'm compiling it without the mocking flags there are no compilation problems. When I'm trying to compile it using ...
Rony Kositsky's user avatar
0 votes
0 answers
116 views

Remove or Weaken private methods in module

I'm trying to use cmocka to test a private function in a module. The method under testing also calls other private methods in that same module. /** @file foo.c */ void foo_private(); void ...
gnac's user avatar
  • 1,593
3 votes
0 answers
446 views

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 ...
A-mit's user avatar
  • 31
0 votes
1 answer
238 views

linking with wrap directive for unit testing can be used to redefine a subroutine?

I'm using Cmocka to write a unit testing suite for a shared object written in C, but I'm having some issue. Since I cannot share the source code, I have written a minimum "not-working" ...
Gionata Benelli's user avatar
1 vote
1 answer
2k views

Mocking functions with cmocka

I'm trying to mock some functions using cmocka: void test_led_driver_NeedToImplement(void **state) { state_t current = CLEAR; will_return(led_status_toggel,SET); ...
Nesmo07's user avatar
  • 15
0 votes
1 answer
131 views

Import cmocka library in Bazel Build

I'm using cmocka with Bazel and I want to import cmocka library in my test files (for c embedded code) like <cmocka.h> but I'm always getting: cmocka.h: No such file or directory. my Build is: ...
Nesmo07's user avatar
  • 15
1 vote
1 answer
1k views

__wrap_strcpy() has remaining non-returned values

I'm new, I have a problem with unit-test using cmocka. I have the following function : #include <string.h> #include <stdlib.h> #include "function.h" void copy_ip_addr(char *...
Thanh Huy Vu's user avatar
0 votes
0 answers
1k views

How can cmocka be used to mock functions using --wrap within shared libraries?

I'm using cmocka to unit test a large code base written in C. I'd like unit tests to run at a library level, but I'm having issues mocking functions when compiled in a shared library. I believe the ...
in-the-cloud's user avatar
0 votes
1 answer
113 views

why C not support TDD. It can't mock function?

target : mock (main.c) without modified any original file (work.a) objcopy work.a --add-symbol _real_test1=.text:00000000000126ed,weak --weaken work.a 00000000000126ed is test1 address by command (nm ...
J. Allen's user avatar
1 vote
0 answers
1k views

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; } ...
diwhyyyyy's user avatar
  • 6,262
6 votes
1 answer
3k views

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 ...
Jason Fisher's user avatar
1 vote
0 answers
864 views

How can I use CMake and CPack with a dependency that overwrites my variables?

I'm trying to use CPack to package my project, but I've run into an issue with one of my dependencies. First, I am trying to use modern CMake style by relying on targets and dependencies modeled ...
Dan Nestor's user avatar
  • 2,471
0 votes
1 answer
3k views

How to run c unit testcases using CMOCKA framework?

I have recently started working on a project written in C language. To add unit test cases, I searched for C unit test frameworks and I came across this answer C-unittest-frameworks. So I chose mocka ...
Dinesh Kumar's user avatar
1 vote
2 answers
2k views

How does target_link_libraries(--wrap) work?

I want to create mock functions for C code testing and get to know that in target_link_libraries() have option to wrap the function which work similar to mock, But not understand how it will work? ...
AshishP's user avatar
  • 39
0 votes
1 answer
173 views

Test authoring with CMocka

a little background: I wish to unit test my code which gets built into a shared object file, say libabc. This code also calls libjson-c and libcurl functions. I am planning to write function-wise ...
upInCloud's user avatar
  • 989
0 votes
1 answer
839 views

How to deal with symbolic links in Yocto recipe using cmake?

I am trying to put cmocka into Embedded Linux target board. I have created rootfs using Yocto, and I have added a custom recipe for cmocka-1.1.5. The cmocka shared library gets generated using my ...
Gaurav Pathak's user avatar
1 vote
1 answer
2k views

CMake and CMocka standard assertions for compiling tests

I have a small static library project that I'm rewriting from building with Makefiles to modern CMake, which I am trying to learn. My project uses assertions quite heavily for checking preconditions, ...
Andrew's user avatar
  • 21
0 votes
1 answer
33 views

Cmocka link apache runtime functions

I am trying to unit test an Apache module with Cmocka. When I run the simple tests I get an error that it can't find function ap_rprintf. I try to build like this: gcc -o run_test mod_hello.c ...
tvlooy's user avatar
  • 1,036
0 votes
1 answer
2k views

Can I use cmocka to mock a function that returns a struct?

I have a simple structure with two data members. typedef struct { int32_t x; int32_t y; } MyStructType; And I have a function that returns the struct by value. MyStructType get_my_struct(...
Kane Anderson's user avatar
0 votes
1 answer
380 views

How could I mock void type function?

I have a void insert function and I want to test if it inserts correctly. I'm using CMocka framework for testing. I've tried to do dpl_insert(ret, "mock_value") instead of the will_return() but it ...
Joshua's user avatar
  • 67
0 votes
0 answers
637 views

cmocka.h: No such file or directory though cmocka installed -- IBM watson embedded C Client Library

I'm trying to compile Embedded C Client Library example for IBM watson. I'm referring to https://github.com/ibm-watson-iot/iot-embeddedc for instructions. While compiling I'm getting error as cmocka.h ...
APS's user avatar
  • 59
3 votes
1 answer
1k views

How to use cmocka library to mock a function from 3rd party library which cannot be modified?

I am trying to write a test case in c using cmocka library.My testcase is testing a function which then internally calls a function from a 3rd party library (cannot modify the library).This function ...
user2156513's user avatar
1 vote
0 answers
76 views

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 ...
RkingDev's user avatar
1 vote
0 answers
65 views

Configuring Cmake file for library dependency [duplicate]

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 ├─ ... ...
Tomy's user avatar
  • 499
4 votes
1 answer
2k views

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 ...
Stefan Jaritz's user avatar
1 vote
1 answer
1k views

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 ...
Maartn's user avatar
  • 15
1 vote
2 answers
2k views

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 ...
Iniesta8's user avatar
  • 399
1 vote
1 answer
1k views

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 ...
mmichal10's user avatar
  • 322
0 votes
1 answer
470 views

Unit test run configuration

I need to get up and running with Cmocka unit testing framework. My setup is: src/math/addition/add.c (+add.h) int add(int a, int b) {return a + b;} src/math/subtraction/sub.c (+sub.h) int sub(int ...
Developer's user avatar
  • 954
0 votes
1 answer
2k views

cmocka, how to check a function pointer

I searched in the documentation and in the waiter example but I can't find an example about how to check if the right function pointer is passed as parameter to a function. This sample code should ...
andyinno's user avatar
  • 1,041
6 votes
2 answers
4k views

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 ...
Alana Storm's user avatar
1 vote
0 answers
4k views

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

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 ...
MicroJoe's user avatar
  • 267
1 vote
0 answers
38 views

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 ...
Vikrant Waje's user avatar
1 vote
0 answers
454 views

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 ...
Martin Cowie's user avatar
  • 2,739
1 vote
1 answer
709 views

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 ...
eDeviser's user avatar
  • 1,715
5 votes
1 answer
5k views

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 ] --- ...
User_MK's user avatar
  • 63
2 votes
1 answer
2k views

How to handle static elements with cmocka?

I am using cmocka to do some unit testing on my C-Project and I am wondering how to handle static emelents. Static elements are for me: Functions declared as static Variables inside functions which ...
eDeviser's user avatar
  • 1,715
5 votes
2 answers
3k views

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 ...
eDeviser's user avatar
  • 1,715