forked from redBorder/f2k
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
169 lines (130 loc) · 5.13 KB
/
Makefile
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
include Makefile.config
BIN=kafka-netflow
.PHONY+=src/version.c
SRCS_SFLOW_$(WITH_SFLOW) += src/f2k/sflow_collect.c
SRCS= src/collect.c \
src/export.c \
src/globals.c \
src/f2k.c \
src/printbuf.c \
src/rb_sensor.c \
src/template.c \
src/rb_dns_cache.c \
src/util.c \
src/version.c \
src/NumNameAssocTree.c \
src/rb_kafka.c \
src/rb_listener.c \
src/rb_mac.c \
$(SRCS_SFLOW_y)
OBJS= $(SRCS:.c=.o)
LIBS= src/dynamic-sensors/target/release/libdsensorsdb.a
LDFLAGS += -ldl
TESTS_C = $(wildcard tests/0*.c)
TESTS = $(TESTS_C:.c=.test)
TESTS_OBJS = $(TESTS:.test=.o)
TESTS_CHECKS_XML = $(TESTS_C:.c=.xml)
TESTS_MEM_XML = $(TESTS_C:.c=.mem.xml)
TESTS_HELGRIND_XML = $(TESTS_C:.c=.helgrind.xml)
TESTS_DRD_XML = $(TESTS_C:.c=.drd.xml)
TESTS_VALGRIND_XML = $(TESTS_MEM_XML) $(TESTS_HELGRIND_XML) $(TESTS_DRD_XML)
TESTS_XML = $(TESTS_CHECKS_XML) $(TESTS_VALGRIND_XML)
MAXMIND_DB = tests/asn.dat tests/country.dat tests/asnv6.dat tests/countryv6.dat
COV_FILES = $(foreach ext,gcda gcno, $(SRCS:.c=.$(ext)) $(TESTS_C:.c=.$(ext)))
VALGRIND ?= valgrind
SUPPRESSIONS_FILE ?= tests/valgrind.suppressions
ifneq ($(wildcard $(SUPPRESSIONS_FILE)),)
SUPPRESSIONS_VALGRIND_ARG = --suppressions=$(SUPPRESSIONS_FILE)
endif
.PHONY: src/version.c tests checks memchecks drdchecks helchecks coverage \
check_coverage manuf
all: $(BIN)
include mklove/Makefile.base
dynamic-sensors:
cd src/dynamic-sensors/; cargo build --release
manuf:
tools/manuf.py
src/version.c:
@rm -f $@
@echo "const char *f2k_revision=\"`git describe --abbrev=6 --tags HEAD --always`\";" >> $@
@echo "const char *version=\"6.13.`date +"%y%m%d"`\";" >> $@
install: bin-install
clean: bin-clean
@echo -e '\033[1;33m[Workdir cleaned]\033[0m\t $<'
@rm -f $(TESTS) $(TESTS_OBJS) $(TESTS_XML) $(COV_FILES)
run_tests = tests/run_tests.sh $(1) $(TESTS_C:.c=)
run_valgrind = $(VALGRIND) --tool=$(1) $(SUPPRESSIONS_VALGRIND_ARG) --xml=yes \
--xml-file=$(2) $(3) &>/dev/null
setup-tests:
@echo -e '\033[1;33m[Initializing Zookeeper container...]\033[0m\t $<'
@docker network create --subnet=172.26.0.0/24 test
@docker run -d --net test --ip 172.26.0.2 --name zookeeper wurstmeister/zookeeper
teardown-tests:
@echo -e '\033[1;33m[Cleaning Zookeeper container...]\033[0m\t $<'
@-docker rm -f zookeeper
@-docker network rm test
tests: $(TESTS_XML)
@$(call run_tests, -cvdh)
checks: $(TESTS_CHECKS_XML)
@$(call run_tests,-c)
memchecks: $(TESTS_MEM_XML)
@$(call run_tests,-v)
drdchecks: $(TESTS_DRD_XML)
@$(call run_tests,-d)
helchecks: $(TESTS_HELGRIND_XML)
@$(call run_tests,-h)
tests/%.mem.xml: tests/%.test $(MAXMIND_DB)
@echo -e '\033[1;34m[Checking memory ]\033[0m\t $<'
-@$(call run_valgrind,memcheck,"$@","./$<")
tests/%.helgrind.xml: tests/%.test $(MAXMIND_DB)
@echo -e '\033[1;34m[Checking concurrency with HELGRIND]\033[0m\t $<'
-@$(call run_valgrind,helgrind,"$@","./$<")
tests/%.drd.xml: tests/%.test $(MAXMIND_DB)
@echo -e '\033[1;34m[Checking concurrency with DRD]\033[0m\t $<'
-@$(call run_valgrind,drd,"$@","./$<")
tests/%.xml: tests/%.test $(MAXMIND_DB)
@echo -e '\033[1;34m[Testing ]\033[0m\t $<'
@CMOCKA_XML_FILE="$@" CMOCKA_MESSAGE_OUTPUT=XML "./$<" >/dev/null 2>&1
MALLOC_FUNCTIONS := $(strip malloc calloc realloc strdup __strdup)
WRAP_ALLOC_FUNCTIONS := $(foreach fn, $(MALLOC_FUNCTIONS)\
,-Wl,-u,$(fn) -Wl,-wrap,$(fn))
TEST_DEPS := tests/rb_netflow_test.o tests/rb_json_test.o tests/rb_mem_wraps.o
tests/0023-testPrintbuf.test: TEST_DEPS = tests/rb_mem_wraps.o
tests/%.test: CPPFLAGS := -I ./src $(CPPFLAGS)
tests/%.test: tests/%.o tests/%.objdeps $(TEST_DEPS) $(OBJS)
@echo -e '\033[1;32m[Building]\033[0m\t $@'
@$(CC) $(CPPFLAGS) $< $(WRAP_ALLOC_FUNCTIONS) $(shell cat $(@:.test=.objdeps)) $(TEST_DEPS) -o $@ $(LIBS) $(LDFLAGS) -lcmocka > /dev/null
get_maxmind_db = wget $(1) -O $@.gz; gunzip $@
tests/asn.dat:
$(call get_maxmind_db,http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNum.dat.gz)
tests/asnv6.dat:
$(call get_maxmind_db,http://download.maxmind.com/download/geoip/database/asnum/GeoIPASNumv6.dat.gz)
tests/country.dat:
$(call get_maxmind_db,http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz)
tests/countryv6.dat:
$(call get_maxmind_db,http://geolite.maxmind.com/download/geoip/database/GeoIPv6.dat.gz)
check_coverage:
@( if [[ "x$(WITH_COVERAGE)" == "xn" ]]; then \
echo "$(MKL_RED) You need to configure using --enable-coverage"; \
echo -n "$(MKL_CLR_RESET)"; \
false; \
fi)
COVERAGE_INFO ?= coverage.info
COVERAGE_OUTPUT_DIRECTORY ?= coverage.out.html
COV_VALGRIND ?= valgrind
COV_GCOV ?= gcov
COV_LCOV ?= lcov
coverage: check_coverage $(TESTS) checks
@$(COV_LCOV) --gcov-tool=$(COV_GCOV) -q \
--rc lcov_branch_coverage=1 \
--capture \
--directory ./ --output-file ${COVERAGE_INFO} >/dev/null 2>&1
@$(COV_LCOV) --remove coverage.info '/app/tests/*' 'include/*' \
--rc lcov_branch_coverage=1 \
--compat-libtool \
--output-file coverage.info >/dev/null 2>&1
@$(COV_LCOV) --list --rc lcov_branch_coverage=1 coverage.info
coverage-html: coverage
genhtml --branch-coverage ${COVERAGE_INFO} --output-directory \
${COVERAGE_OUTPUT_DIRECTORY} > coverage.out
-include $(DEPS)