2

I have downloaded the cmocka example files and followed all the instructions. All test files were succesfully generated and I can run them, but no output appears in the console. I have tried to alter the CMOCKA_MESSAGE_OUTPUT environmental variable, tried to write my own tests and compile them, tried to recompile and reinstall cmocka several times - nothing made the tests output anything. I work on Windows 7 32-bit, so I figured to try also cygwin, but cygwin just throws that it cannot find public libraries, so I abandoned this fork of my research - after all cmocka should also normally work in windows cmd. Does anyone know how to make the tests output anything to the console?

EDIT

I'm adding my make info in case there was some problem with compilation/linking, although I don't see any (it doesn't produce any error and outputs correctly the tests.exe file):

# Makefile
OBJ_DIR = obj
HDR = $(wildcard *.h)
SRC = $(HDR:.h=.c)
OBJ = $(HDR:%.h=$(OBJ_DIR)\\%.o)
CC = gcc
CFLAGS = -I"C:\Program Files\cmocka\include" -I"C:\Program Files\cmocka\lib" -I"C:\Program Files\cmocka\bin" -llibcmocka -lcmocka

.PHONY: all clean

all: tests.exe

$(OBJ_DIR)\\%.o: %.c %.h
    $(CC) $< -c -o $@ $(CFLAGS)

$(OBJ_DIR)\tests.o: tests.c
    $(CC) $< -c -o $@ $(CFLAGS)

tests.exe: $(OBJ) $(OBJ_DIR)\tests.o
    $(CC) $^ -o tests.exe $(CFLAGS)

clean:
    del $(OBJ) $(OBJ_DIR)\tests.o tests.exe

note1: the numerous paths in cflags are put out of desperation - at first I had been using only the first one.

note2: when I try to run this script in Netbeans or cygwin I change del to rm -f and switch slashes. The output is like described above: the make is done without any errors and outputs the tests.exe, but once executed, it throws error about not being able to find public libraries.

Per Lundberg
  • 3,837
  • 1
  • 36
  • 46
jalooc
  • 1,169
  • 13
  • 23
  • I have just noticed something that may be useful: when I put `cmocka_set_message_output(CM_OUTPUT_STDOUT);` in the `main()` function, the linker says that the reference is undefined. This is strange to me since `cmocka_run_group_tests()` and `cmocka_unit_test()` works fine. To explain: I copied the libraries files to my project folder and run all gcc commands to compile my tests with `-Icmocka -lcmocka` flags, where _cmocka_ is the folder with library files (libcmocka.a, libcmocka.dll). – jalooc Jul 07 '15 at 07:46

5 Answers5

1

The symbol is not exported, see https://git.cryptomilk.org/projects/cmocka.git/commit/?id=7364469189558a8720b60880940a41e1a0d20452

asn
  • 798
  • 9
  • 17
  • 1
    Ok, thanks for quick reaction. But this still doesn't solve the main problem that the **tests don't output anything on the console**. Since you're the creator of cmocka, do you know what may be the cause? – jalooc Jul 07 '15 at 10:05
1

Sorry for digging out this old thread, but i recently stumbled over exactly the same problem. Compiled everything by myself with meson/ninja and did not get any output neither from the test itself, nor from a simple printf.

I solved the problem by using the precompiled library from here. Just install/start MSYS2 and use for 64-bit MINGW:

pacman -S mingw-w64-x86_64-cmocka

for 32-bit MINGW:

pacman -S mingw-w64-i686-cmocka

Then I recompiled my hello world test, and output worked as intended.

Sibi111
  • 11
  • 1
1

I had the same problem, and for me it was that I had not properly passed the state argument to the tests. My tests had this signature:

void test_something() { /* ...snip... */ }

but it should have been

void test_something(void **state) {
    (void) state;  /* unused */
    /* ...snip... */
}

After fixing this, the output properly appeared.

barfuin
  • 16,865
  • 10
  • 85
  • 132
0

your problem is in the tests.c that has the unit tests, not your setup. Show us your tests.c file where you wrote your unit tests.

Miguel Rentes
  • 994
  • 1
  • 10
  • 27
0

I have had the same problem. Especially I also used gcov to see the coverage and it claims that nothing gets ever executed.

My solution was that I just forgot to add cmocka to my environment-path. After adding "cmocka.dll" to the path everything finally works.

Benny
  • 99
  • 9