-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest.mk
152 lines (126 loc) · 5.12 KB
/
test.mk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# extra template to dummy entrypoint and remove coverage files on cleanup
define test_c_dummy_main_tpl
$$(addprefix $1/,$2.dummy.c):
@echo "int main(int argc, char **argv ){return 0;}" > $$@
endef
test_c_dummy_main = $(eval $(call test_c_dummy_main_tpl,$1,$2))
define test_c_dummy_main_clean_tpl
clean: RMFLAGS+=$$(addprefix $1/,$2.gcda) $$(addprefix $1/,$2.gcno) $$(addprefix $1/,$2.dummy.c)
endef
test_c_dummy_main_clean = $(eval $(call test_c_dummy_main_clean_tpl,$1,$2))
define test_c_meta_rules_tpl
$(3)+= \
$(2:.c=) \
$(2:.c=.reflect.c) \
$(2:.c=.test.c) \
$$(dir $(2:.c=))_meta_$$(notdir $(2:.c=))
TPL-$(2:.c=):=bin_target test_c_dummy_main
IN-$(2:.c=)=$(2:.c=.o) $(2:.c=.test.o)
LDFLAGS-$(2:.c=)+=--coverage $$(METAC_CHECK_LDFLAGS)
$$(addprefix $1/,$(2:.c=.test.o)):CFLAGS+=-g3 $$(METAC_CHECK_CFLAGS)
$$(addprefix $1/,$(2:.c=.o)):CFLAGS+=-g3 -Wno-format-extra-args --coverage $$(METAC_CHECK_CFLAGS)
$$(addprefix $1/,$(2:.c=.meta.o)):CFLAGS+=-Wno-format-extra-args $$(METAC_CHECK_CFLAGS)
ifneq ($$(REFLECT-$(2:.c=)),n)
IN-$(2:.c=)+=$(2:.c=.reflect.o)
TPL-$(2:.c=.reflect.c):=metac_target
METACFLAGS-$(2:.c=.reflect.c)+=run metac-reflect-gen $(METAC_OVERRIDE_IN_TYPE)
IN-$(2:.c=.reflect.c)=$$(dir $(2:.c=))_meta_$$(notdir $(2:.c=))
endif
TPL-$(2:.c=.test.c):=metac_target
METACFLAGS-$(2:.c=.test.c)+=run metac-test-gen $(METAC_OVERRIDE_IN_TYPE)
IN-$(2:.c=.test.c)=$$(dir $(2:.c=))_meta_$$(notdir $(2:.c=))
TPL-$$(dir $(2:.c=))_meta_$$(notdir $(2:.c=)):=bin_target
IN-$$(dir $(2:.c=))_meta_$$(notdir $(2:.c=))=$(2:.c=.meta.o) $(2:.c=.dummy.o)
LDFLAGS-$$(dir $(2:.c=))_meta_$$(notdir $(2:.c=))=$$(LDFLAGS-$(2:.c=))
DEPS-$$(dir $(2:.c=))_meta_$$(notdir $(2:.c=))=$$(DEPS-$(2:.c=))
POST-$$(dir $(2:.c=))_meta_$$(notdir $(2:.c=))=$$(METAC_POST_META)
bin_test: $$(addprefix $1/,$(2:.c=))
endef # test_c_meta_rules_tpl
test_c_rules = $(eval $(call test_c_meta_rules_tpl,$1,$2,$3))
# checkmk support
# extra template to convert checkmk to c using checkmk
define test_checkmk_c_tpl
$$(addprefix $1/,$2.c): $$(addprefix $1/,$(subst _checkmk,.checkmk,$2))
checkmk $$^ > $$@
endef
test_checkmk_c = $(eval $(call test_checkmk_c_tpl,$1,$2))
define test_checkmk_c_clean_tpl
clean: RMFLAGS+=$$(addprefix $1/,$2.gcda) $$(addprefix $1/,$2.gcno) $$(addprefix $1/,$2.c)
endef
test_checkmk_c_clean = $(eval $(call test_checkmk_c_clean_tpl,$1,$2))
define test_checkmk_meta_rules_tpl
$(3)+= \
$(2:.checkmk=_checkmk)
TPL-$(2:.checkmk=_checkmk):=bin_target test_checkmk_c
IN-$(2:.checkmk=_checkmk)=$(2:.checkmk=_checkmk.o)
LDFLAGS-$(2:.checkmk=_checkmk)+=--coverage $$(METAC_CHECK_LDFLAGS)
$$(addprefix $1/,$(2:.checkmk=_checkmk.o)):CFLAGS+=-g3 -Wno-format-extra-args --coverage $$(METAC_CHECK_CFLAGS)
$$(addprefix $1/,$(2:.checkmk=_checkmk.meta.o)):CFLAGS+=-Wno-format-extra-args $$(METAC_CHECK_CFLAGS)
ifneq ($$(REFLECT-$(2:.checkmk=_checkmk)),n)
IN-$(2:.checkmk=_checkmk)+=$(2:.checkmk=_checkmk.reflect.o)
TPL-$(2:.checkmk=_checkmk.reflect.c):=metac_target
METACFLAGS-$(2:.checkmk=_checkmk.reflect.c)+=run metac-reflect-gen $(METAC_OVERRIDE_IN_TYPE)
IN-$(2:.checkmk=_checkmk.reflect.c)=$$(dir $(2:.c=))_meta_$$(notdir $(2:.checkmk=_checkmk))
TPL-$$(dir $(2:.checkmk=_checkmk))_meta_$$(notdir $(2:.checkmk=_checkmk)):=bin_target
IN-$$(dir $(2:.checkmk=_checkmk))_meta_$$(notdir $(2:.checkmk=_checkmk))=$(2:.checkmk=_checkmk.meta.o)
LDFLAGS-$$(dir $(2:.checkmk=_checkmk))_meta_$$(notdir $(2:.checkmk=_checkmk))=$$(LDFLAGS-$(2:.checkmk=_checkmk))
DEPS-$$(dir $(2:.checkmk=_checkmk))_meta_$$(notdir $(2:.checkmk=_checkmk))=$$(DEPS-$(2:.checkmk=))
POST-$$(dir $(2:.checkmk=_checkmk))_meta_$$(notdir $(2:.checkmk=_checkmk))=$$(METAC_POST_META)
$(3)+= \
$(2:.checkmk=_checkmk.reflect.c) \
$$(dir $(2:.checkmk=_checkmk))_meta_$$(notdir $(2:.checkmk=_checkmk))
endif
bin_test: $$(addprefix $1/,$(2:.checkmk=_checkmk))
endef # test_checkmk_meta_rules_tpl
test_checkmk_rules = $(eval $(call test_checkmk_meta_rules_tpl,$1,$2,$3))
ifneq ($(INCLUDE),)
RUNFILTERFN:=filter
RUNFILTER:=$(INCLUDE)
else
RUNFILTERFN:=filter-out
RUNFILTER:=$(EXCLUDE)
endif
ifeq ($(RUNMODE), valgrind)
# valgrind test target
VALGRIND=$(shell which valgrind)
ifeq ($(VALGRIND), )
$(error Couldn't find valgrind in PATH. Please specify the path manually using VALGRIND param)
endif
bin_test:
@exitCode=0; \
for j in $(call $(RUNFILTERFN),$(RUNFILTER), $(sort $^)); do \
CK_FORK=no $(VALGRIND) --leak-check=full --track-origins=yes -s $$j || exitCode=1; \
done; \
exit $$exitCode
else
ifeq ($(RUNMODE), coverage)
GCOV=$(shell which gcov)
ifeq ($(GCOV), )
$(error Couldn't find gcov in PATH. Please specify the path manually using GCOV param)
endif
# don't create gcov be default (anyway they ovewrite)
GCOVFLAGS=-n
# coverage test target
bin_test:
@exitCode=0; \
for j in $(call $(RUNFILTERFN),$(RUNFILTER),$(sort $^)); do \
$$j || exitCode=1; \
$(GCOV) $(GCOVFLAGS) $$j; \
done; \
exit $$exitCode
else
ifneq ($(RUNMODE),)
$(error Unknown RUNMODE $(RUNMODE). Please check the parameter)
endif
# default test target
bin_test:
@exitCode=0; \
for j in $(call $(RUNFILTERFN),$(RUNFILTER),$(sort $^)); do \
$$j || exitCode=1; \
done; \
exit $$exitCode
endif
endif
test: bin_test
@echo All test dependencies were: $^
.PHONY: bin_test test