Questions tagged [cmocka]

Cmocka is a C unit testing framework

Cmocka is a C unit testing framework

66 questions
0
votes
0 answers

How do I properly build cmocka unit tests with CMake

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. The code has the following directory…
Jon
  • 1,621
  • 5
  • 23
  • 46
0
votes
0 answers

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, so i wonder if someone has an example of testing…
jst
  • 1
  • 1
0
votes
0 answers

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 library I am testing. It is a C project in visual studio and there isn't a…
jst
  • 1
  • 1
0
votes
0 answers

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 about what's in the report, I saw that there's an…
Risusdan
  • 61
  • 7
0
votes
1 answer

set_target_properties does not work with multiple --wrap functions

#include #include #include #include #include "stdint.h" typedef enum { eSTATE_STARTUP, eSTATE_ADDRESSING, eSTATE_RANDOMISE, eSTATE_SELECTED }e_State_t; void test_main() { static…
arda30
  • 83
  • 1
  • 1
  • 6
0
votes
0 answers

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 the defined flags I get compiling error: gcc -g…
0
votes
0 answers

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 foo_under_test() { foo_private(); } void foo_private()…
gnac
  • 1,573
  • 15
  • 17
0
votes
1 answer

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" example to show what is the issue: my program is composed 5…
Gionata Benelli
  • 357
  • 1
  • 3
  • 20
0
votes
1 answer

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 but I'm always getting: cmocka.h: No such file or directory. my Build is: cc_library( name = "mock", srcs =…
Nesmo07
  • 15
  • 3
0
votes
0 answers

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 shared library is the issue because I can…
0
votes
1 answer

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 work.a) override function and call real function…
J. Allen
  • 11
  • 4
0
votes
1 answer

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 and installed it from installation steps. But I…
Dinesh Kumar
  • 545
  • 4
  • 17
0
votes
1 answer

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 tests for each function in product code, mocking…
upInCloud
  • 979
  • 2
  • 10
  • 29
0
votes
1 answer

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 custom bitbake recipe, but when I try to build the…
Gaurav Pathak
  • 1,065
  • 11
  • 28
0
votes
1 answer

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 run_test.c \ -lcmocka -lapr-1 \ …
tvlooy
  • 1,036
  • 10
  • 16