Debian Codegraph @

tools/Makefile

raw symbols SCIP
1 # Makefile to run unit tests for cgreen-runner units
2 #
3 # We are using cgreen itself to test this but since the modules here
4 # might at some point get into the actual cgreen-runner there will be
5 # a clash when it loads the test library. So we will have to make the
6 # external symbols in the modules have other names when unittesting
7 # them using macro magic. The UNITTESTING preprocessor symbol will
8 # add the suffix '_unittesting' to externally, clashing symbols so
9 # that we can separate the ones in the cgreen-runner that is running
10 # the tests, and the ones in the units being tested.
11
12 UNAMEOEXISTS=$(shell uname -o 1>&2 2>/dev/null; echo $$?)
13 ifeq ($(UNAMEOEXISTS),0)
14 OS=$(shell uname -o)
15 else
16 OS=$(shell uname -s)
17 endif
18
19 CFLAGS = -Wall -g -I../include -MMD -DUNITTESTING -I.
20 ifneq ($(OS),Cygwin)
21 CFLAGS+=-fPIC
22 endif
23
24 LDFLAGS = $(COMMONFLAGS)
25
26 LIBRARIES = -L../build/src -lcgreen
27
28 VPATH = ../src
29
30 ifeq ($(OS),Darwin)
31 LD_PATH_NAME=DYLD_LIBRARY_PATH
32 else
33 LD_PATH_NAME=LD_LIBRARY_PATH
34 endif
35
36 CGREEN_RUNNER = $(LD_PATH_NAME)=../build/src cgreen-runner
37
38
39 # Redirect to CMake build from top level
40 all:
41 make --no-print-directory -C ..
42
43 # Use this if you want quick feed-back in this directory
44 tests: unit_tests acceptance_tests
45
46 #----------------------------------------------------------------------
47 unit unit_tests: discoverer_unit_tests runner_unit_tests
48 LD_LIBRARY_PATH=. ./discoverer_unit_tests
49 LD_LIBRARY_PATH=. ./runner_unit_tests
50
51 discoverer.o: CFLAGS += -DNM_EXECUTABLE='"nm"'
52
53 discoverer_unit_tests : discoverer_unit_tests.so
54 $(CC) $(LDFLAGS) -o $@ $^
55
56 discoverer_unit_tests.so : discoverer_unit_test_runner.o discoverer.o test_item.o
57 $(CC) $(LDFLAGS) -shared -o $@ $^ $(LIBRARIES)
58
59 # Auto-generate a runner for discoverer unittests
60 discoverer_unit_test_runner.c : discoverer_unit_tests.c
61 echo "#include \"discoverer_unit_tests.c\"" > discoverer_unit_test_runner.c
62 echo "TestSuite *discoverer_unit_tests() {" >> discoverer_unit_test_runner.c
63 echo " TestSuite *suite = create_test_suite();" >> discoverer_unit_test_runner.c
64 grep Ensure discoverer_unit_tests.c | sed -e 's/Ensure(/ add_test_with_context(suite, /g' -e 's/) {/);/g' >> discoverer_unit_test_runner.c
65 echo " return suite;" >> discoverer_unit_test_runner.c
66 echo "}" >> discoverer_unit_test_runner.c
67 echo "int main(int argc, char **argv) {" >> discoverer_unit_test_runner.c
68 echo " return run_test_suite(discoverer_unit_tests(), create_text_reporter());" >> discoverer_unit_test_runner.c
69 echo "}" >> discoverer_unit_test_runner.c
70
71 runner_unit_tests: runner_unit_tests.so
72 $(CC) $(LDFLAGS) -o $@ $^ $(LIBRARIES)
73
74 runner_unit_tests.so: runner_unit_test_runner.o test_item.o
75 $(CC) $(LDFLAGS) -shared -o $@ $^ -ldl $(LIBRARIES)
76
77 # Auto-generate a runner for runner unittests
78 runner_unit_test_runner.c : runner_unit_tests.c
79 echo "#include \"runner_unit_tests.c\"" > runner_unit_test_runner.c
80 echo "TestSuite *runner_unit_tests() {" >> runner_unit_test_runner.c
81 echo " TestSuite *suite = create_test_suite();" >> runner_unit_test_runner.c
82 grep Ensure runner_unit_tests.c | sed -e 's/Ensure(/ add_test_with_context(suite, /g' -e 's/) {/);/g' >> runner_unit_test_runner.c
83 echo " return suite;" >> runner_unit_test_runner.c
84 echo "}" >> runner_unit_test_runner.c
85 echo "int main(int argc, char **argv) {" >> runner_unit_test_runner.c
86 echo " return run_test_suite(runner_unit_tests(), create_text_reporter());" >> runner_unit_test_runner.c
87 echo "}" >> runner_unit_test_runner.c
88
89 #----------------------------------------------------------------------
90 acceptance_tests: libdiscoverer_acceptance_tests.so
91 $(CGREEN_RUNNER) $^
92
93 libdiscoverer_acceptance_tests.so: discoverer_acceptance_tests.o discoverer.o test_item.o io.o
94 $(CC) -shared -o $@ $^ $(LIBRARIES)
95
96 #----------------------------------------------------------------------
97 clean:
98 -rm *.o *.so *.dll
99
100 -include *.d