author | Alberto Bertogli
<albertito@blitiri.com.ar> 2015-08-02 22:41:08 UTC |
committer | Alberto Bertogli
<albertito@blitiri.com.ar> 2015-08-03 00:05:35 UTC |
parent | f16b8a8b3a13f18b0c2c8a4454e237125dc53704 |
tests/Makefile | +4 | -1 |
tests/collisions/.gitignore | +2 | -0 |
tests/collisions/Makefile | +67 | -0 |
tests/collisions/binary.c | +32 | -0 |
tests/collisions/libcoltest.c | +6 | -0 |
tests/collisions/libcoltest.h | +4 | -0 |
diff --git a/tests/Makefile b/tests/Makefile index c6efc9a..5d8ec6e 100644 --- a/tests/Makefile +++ b/tests/Makefile @@ -27,7 +27,7 @@ default: tests all: tests -tests: c-tests py-tests gen-tests utils-tests +tests: c-tests py-tests gen-tests utils-tests collisions-tests # Link the libraries to a single place, some of the tests need this. @@ -97,6 +97,9 @@ gen-tests: utils-tests: $(MAKE) -C utils +collisions-tests: + $(MAKE) -C collisions + # # Cleanup # diff --git a/tests/collisions/.gitignore b/tests/collisions/.gitignore new file mode 100644 index 0000000..7e2df7b --- /dev/null +++ b/tests/collisions/.gitignore @@ -0,0 +1,2 @@ +binary +libcoltest.so diff --git a/tests/collisions/Makefile b/tests/collisions/Makefile new file mode 100644 index 0000000..0192572 --- /dev/null +++ b/tests/collisions/Makefile @@ -0,0 +1,67 @@ + +CFLAGS += -std=c99 -pedantic -Wall -rdynamic +ALL_CFLAGS = -I../../libfiu/ -L../../libfiu/ -L./ \ + -D_XOPEN_SOURCE=600 -D_GNU_SOURCE -fPIC -DFIU_ENABLE=1 $(CFLAGS) + +ifdef DEBUG +ALL_CFLAGS += -g +endif + +ifdef PROFILE +ALL_CFLAGS += -g -pg -fprofile-arcs -ftest-coverage +endif + +ifneq ($(V), 1) + NICE_CC = @echo " CC $@"; $(CC) + NICE_RUN = @echo " RUN $<"; \ + LD_LIBRARY_PATH="./:../../libfiu/" + NICE_LN = @echo " LN $@"; ln -f +else + NICE_CC = $(CC) + NICE_RUN = LD_LIBRARY_PATH="./:../../libfiu/" + NICE_LN = ln -f +endif + +default: tests + +all: tests + + +BF = $(ALL_CFLAGS) ~ $(PREFIX) +build-flags: .force-build-flags + @if [ x"$(BF)" != x"`cat build-flags 2>/dev/null`" ]; then \ + if [ -f build-flags ]; then \ + echo "build flags changed, rebuilding"; \ + fi; \ + echo "$(BF)" > build-flags; \ + fi + +# +# Test library and binaries. +# + +libcoltest.so: libcoltest.c libcoltest.h + $(NICE_CC) $(ALL_CFLAGS) -shared -fPIC $< -o $@ + +binary: binary.c libcoltest.so + $(NICE_CC) $(ALL_CFLAGS) -L. -lfiu -lcoltest $< -o $@ + + +tests: binary + $(NICE_RUN) ./binary + +# +# Cleanup +# + +clean: + rm -f *.bb *.bbg *.da *.gcov *.gcda *.gcno gmon.out build-flags + rm -f libcoltest.so binary + +FORCE: + +.PHONY: default all clean \ + tests c-tests py-tests \ + .force-build-flags + + diff --git a/tests/collisions/binary.c b/tests/collisions/binary.c new file mode 100644 index 0000000..7fb825d --- /dev/null +++ b/tests/collisions/binary.c @@ -0,0 +1,32 @@ +// A binary that uses some of the same function names as libfiu. +// We use this to test function name collissions. + +#include <stdio.h> // printf() +#include "libcoltest.h" + +#define ASSERT_CALLED(NAME, N) \ + if (called_##NAME != N) { \ + printf("Error: " #NAME "called %d != " #N "\n", \ + called_##NAME); \ + return 1; \ + } + +#define CHECK(NAME) \ + ASSERT_CALLED(NAME, 0) \ + NAME(); \ + ASSERT_CALLED(NAME, 1) + +int called_wtable_set = 0; + +void wtable_set(void) { called_wtable_set++; } + +int main(void) +{ + // Defined in libcoltest. + CHECK(wtable_get) + + // Defined here. + CHECK(wtable_set) + + return 0; +} diff --git a/tests/collisions/libcoltest.c b/tests/collisions/libcoltest.c new file mode 100644 index 0000000..765d6d0 --- /dev/null +++ b/tests/collisions/libcoltest.c @@ -0,0 +1,6 @@ +// A library that uses some of the same function names as libfiu. +// We use this to test function name collissions. + +int called_wtable_get = 0; + +void wtable_get(void) { called_wtable_get++; } diff --git a/tests/collisions/libcoltest.h b/tests/collisions/libcoltest.h new file mode 100644 index 0000000..3d704ab --- /dev/null +++ b/tests/collisions/libcoltest.h @@ -0,0 +1,4 @@ +// Headers for libcoltest. + +extern int called_wtable_get; +void wtable_get(void);