Closed nikohansen closed 8 years ago
For building the cmocka library on your computer, you can follow this instructions: http://zhuyong.me/blog/2014/03/19/c-code-unit-testing-using-cmocka/
with one small exception. Download the latest version of cmocka library files from: https://cmocka.org/files/1.0/
Then add the compiled library (create a new folder in code-experiments\test\unit-test\lib) and update the build_c_unit_tests() in the do.py so that the correct library is copied on your computer.
I don't quite know what "the compiled library" refers to and what "add" exactly means. When I type sudo make install
, I get this output:
Install the project...
-- Install configuration: "Release"
-- Installing: /usr/lib/pkgconfig/cmocka.pc
-- Installing: /usr/lib/cmake/cmocka/cmocka-config.cmake
-- Installing: /usr/lib/cmake/cmocka/cmocka-config-version.cmake
-- Installing: /usr/include/cmocka.h
-- Installing: /usr/include/cmocka_pbc.h
-- Installing: /usr/lib/libcmocka.0.3.1.dylib
-- Installing: /usr/lib/libcmocka.0.dylib
-- Installing: /usr/lib/libcmocka.dylib
What do I do now?
I copied libcmocka.dylib
into code-experiments\test\unit-test\lib\macosx
and checked build_c_unit_tests()
in do.py
but get this (error) output:
[00:10:35] 0 numbbo$ ./do.py test-c
AML ['code-experiments/src/coco_generics.c', 'code-experiments/src/coco_random.c', 'code-experiments/src/coco_suite.c', 'code-experiments/src/coco_observer.c', 'code-experiments/src/coco_runtime_c.c'] -> code-experiments/build/c/coco.c
COPY code-experiments/src/coco.h -> code-experiments/build/c/coco.h
COPY code-experiments/src/best_values_hyp.txt -> code-experiments/build/c/best_values_hyp.txt
COPY code-experiments/build/c/coco.c -> code-experiments/examples/bbob2009-c-cmaes/coco.c
COPY code-experiments/build/c/coco.h -> code-experiments/examples/bbob2009-c-cmaes/coco.h
WRITE code-experiments/build/c/REVISION
WRITE code-experiments/build/c/VERSION
MAKE clean in code-experiments/build/c
COPY Makefile.in -> Makefile
MAKE all in code-experiments/build/c
COPY Makefile.in -> Makefile
COPY code-experiments/test/unit-test/lib/macosx/libcmocka.dylib -> code-experiments/test/unit-test/libcmocka.dylib
COPY code-experiments/build/c/coco.c -> code-experiments/test/unit-test/coco.c
COPY code-experiments/src/coco.h -> code-experiments/test/unit-test/coco.h
MAKE clean in code-experiments/test/unit-test
COPY Makefile.in -> Makefile
MAKE all in code-experiments/test/unit-test
COPY Makefile.in -> Makefile
RUN ./unit_test in code-experiments/test/unit-test
COPY code-experiments/build/c/coco.c -> code-experiments/test/integration-test/coco.c
COPY code-experiments/src/coco.h -> code-experiments/test/integration-test/coco.h
COPY code-experiments/src/bbob2009_testcases.txt -> code-experiments/test/integration-test/bbob2009_testcases.txt
COPY code-experiments/src/best_values_hyp.txt -> code-experiments/test/integration-test/best_values_hyp.txt
MAKE clean in code-experiments/test/integration-test
COPY Makefile.in -> Makefile
MAKE all in code-experiments/test/integration-test
COPY Makefile.in -> Makefile
ERROR: return value=2
cc -c -g -ggdb -std=c89 -pedantic -Wall -Wextra -Wstrict-prototypes -Wshadow -Wno-sign-compare -Wconversion -o test_coco.o test_coco.c
cc -c -g -ggdb -std=c89 -pedantic -Wall -Wextra -Wstrict-prototypes -Wshadow -Wno-sign-compare -Wconversion -o coco.o coco.c
code-experiments/src/logger_biobj_avl_tree.c:119:35: warning: missing field 'next' initializer [-Wmissing-field-initializers]
const avl_node_t avl_node_0 = { 0 };
^
code-experiments/src/logger_biobj_avl_tree.c:120:35: warning: missing field 'head' initializer [-Wmissing-field-initializers]
const avl_tree_t avl_tree_0 = { 0 };
^
code-experiments/src/logger_biobj_avl_tree.c:121:45: warning: missing field 'deallocate' initializer [-Wmissing-field-initializers]
const avl_allocator_t avl_allocator_0 = { 0 };
^
code-experiments/src/logger_biobj.c:680:14: warning: variable 'file_name' is used uninitialized whenever 'if' condition is false [-Wsometimes-uninitialized]
else if (logger->log_nondom_mode == FINAL)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
code-experiments/src/logger_biobj.c:682:46: note: uninitialized use occurs here
coco_join_path(path_name, COCO_PATH_MAX, file_name, NULL);
^~~~~~~~~
code-experiments/src/logger_biobj.c:680:10: note: remove the 'if' if its condition is always true
else if (logger->log_nondom_mode == FINAL)
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
code-experiments/src/logger_biobj.c:636:30: note: initialize the variable 'file_name' to silence this warning
char *path_name, *file_name, *prefix;
^
= NULL
4 warnings generated.
cc -g -ggdb -std=c89 -pedantic -Wall -Wextra -Wstrict-prototypes -Wshadow -Wno-sign-compare -Wconversion -o test_coco coco.o test_coco.o -lm
cc -c -g -ggdb -std=c89 -pedantic -Wall -Wextra -Wstrict-prototypes -Wshadow -Wno-sign-compare -Wconversion -o test_instance_extraction.o test_instance_extraction.c
cc -g -ggdb -std=c89 -pedantic -Wall -Wextra -Wstrict-prototypes -Wshadow -Wno-sign-compare -Wconversion -o test_instance_extraction coco.o test_instance_extraction.o -lm
cc -c -g -ggdb -std=c89 -pedantic -Wall -Wextra -Wstrict-prototypes -Wshadow -Wno-sign-compare -Wconversion -o test_biobj.o test_biobj.c
test_biobj.c:12:6: error: conflicting types for 'wait'
void wait (unsigned int secs) {
^
/usr/include/sys/wait.h:248:7: note: previous declaration is here
pid_t wait(int *) __DARWIN_ALIAS_C(wait);
^
test_biobj.c:72:8: warning: incompatible integer to pointer conversion passing 'int' to parameter of type 'int *' [-Wint-conversion]
wait(2); /* So that the directory removal is surely finished */
^
/usr/include/sys/wait.h:248:17: note: passing argument to parameter here
pid_t wait(int *) __DARWIN_ALIAS_C(wait);
^
1 warning and 1 error generated.
make: *** [test_biobj.o] Error 1
Traceback (most recent call last):
File "./do.py", line 562, in <module>
main(sys.argv[1:])
File "./do.py", line 548, in main
elif cmd == 'test-c': test_c()
File "./do.py", line 63, in test_c
build_c_integration_tests()
File "./do.py", line 135, in build_c_integration_tests
make("code-experiments/test/integration-test", "all")
File "/Users/hansen/git/numbbo/code-experiments/tools/cocoutils.py", line 154, in make
universal_newlines=True)
File "/Users/hansen/anaconda/lib/python2.7/subprocess.py", line 573, in check_output
raise CalledProcessError(retcode, cmd, output=output)
subprocess.CalledProcessError: Command '['make', 'all']' returned non-zero exit status 2
Similar result for the other .dylib
files.
I am not sure how the proposed solution, if it works, can work with several users in the git repository.
Did you tried the "Use cmocka" example from the installation link? If that works then I would assume that the library is OK and the problem is in our code.
Regarding the library file I don't remember exactly if I used the libcmocka.dylib or the libcmocka.0.3.1.dylib.
Needs either to be solved or obvious to the average end user how to solve it (e.g.
do.py
could provide a hint what to do).