2

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 C Project in eclipse called "cmocka_test". It compiles, it is debuggable and it prints out to the console.

Then, I expand the project to include the cmocka library by doing the following:

  1. I extract the contents of cmocka-1.1.0-mingw.zip ( https://cmocka.org/files/1.1/ ) into the project folder
  2. I add the "include" path to project Properties -> C/C++ Build -> Settings -> GCC C Compiler -> Includes
  3. I add the "lib" path to project Properties -> C/C++ Build -> Settings -> MinGW C Linker -> Libraries -> Library search path and "cmocka" to -> Libraries -> Libraries (-l)
  4. The code is modified to include a simple cmocka testcase:
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>

static void null_test_success(void **state) {
    (void) state; /* unused */
    int test = 4;
    assert_int_equal(test, 5);

}
int main(void) {
    printf("Hello");
    const struct CMUnitTest tests[] = {
        cmocka_unit_test(null_test_success),
    };
    return cmocka_run_group_tests(tests, NULL, NULL);
}

It compiles fine, this is the console output:

12:30:17 **** Rebuild of configuration Debug for project cmocka_test ****
Info: Internal Builder is used for build
gcc "-IC:\\Users\\UnbescholtenerBuerger\\eclipse-workspace\\cmocka_test\\cmocka\\cmocka-1.1.0\\include" -O0 -g3 -pedantic -Wall -c -fmessage-length=0 -o "src\\cmocka_test.o" "..\\src\\cmocka_test.c" 
gcc "-LC:\\Program Files (x86)\\cmocka\\lib" -o cmocka_test.exe "src\\cmocka_test.o" -lcmocka 

However, debugging/running does not work as expected. CLicking on the debug symbol in eclipse does not bring me to the start of the main() function. It does not stop at breakpoints that I set. It does not write 'Hello' to the console, neither does it inform about a failed test case. No console output, no problems or warnings. I just immediately get the info <terminated, exit value: 0> gdb (7.6.1) in the debug view. And in the Debugger console (which I never used before):

[New Thread 18044.0x3020]
[New Thread 18044.0x598]
[New Thread 18044.0x38f0]
Thread ID 0 not known.
Thread ID 0 not known.
Thread ID 0 not known.

What am I missing here?


per request of user the busybee, here the gcc commands from makefile:

gcc -c -Icmocka/cmocka-1.0.0/include -g -o ut_test.o C:/Users/UnbescholtenerBuerger/eclipse-workspace/ut_test/src/ut_test.c
gcc -Lcmocka/cmocka-1.0.0/bin -lcmocka -g -o ut_test ut_test.o

Results are the same.

  • It seems as if your linking is not for debugging. I'd expect the `-g` option in the linker command, too. – the busybee Jan 28 '22 at 12:33
  • Redid the whole thing as a makefile project and included -g in the ldflags, but the result is unchanged. – UnbescholtenerBuerger Jan 31 '22 at 09:03
  • Would you mind to [edit] your question and add the compile and link commands that are currently executed, please? – the busybee Jan 31 '22 at 09:48
  • Does it work when you try to run gdb from command line (or MSYS terminal)? Assuming you have GDB configured in Eclipse as the debugger. – kiner_shah Feb 02 '22 at 11:10
  • 1
    Eclipse output does not match gcc commands. The former is using `cmocka- 1.1.0/include` and `Program Files (x86)\\cmocka\\lib` while the latter is using `cmocka-1.0.0/include` and `cmocka-1.0.0/bin`... And you don't seem to bother copying cmocka dll. And it is a good idea to download cmocka sources and build it yourself rather than use prebuilt. – user7860670 Feb 03 '22 at 13:14

0 Answers0