summaryrefslogtreecommitdiff
path: root/Mk/tests.mk
diff options
context:
space:
mode:
Diffstat (limited to 'Mk/tests.mk')
-rw-r--r--Mk/tests.mk72
1 files changed, 72 insertions, 0 deletions
diff --git a/Mk/tests.mk b/Mk/tests.mk
new file mode 100644
index 0000000..d542044
--- /dev/null
+++ b/Mk/tests.mk
@@ -0,0 +1,72 @@
1BUILDDEPS+=Mk/tests.mk
2
3# The modules under test are compiled straight into the test binary, so a test
4# may reach a static function by including the source. tests/stubs.c supplies
5# the few symbols those modules reference but the tests never reach.
6TESTBIN=tests/runner
7TEST_SOURCES=tests/runner.c tests/test.c tests/stubs.c tests/t_urlencoded.c tests/t_iovec.c tests/t_vector.c tests/t_random.c tests/t_hex.c tests/t_accesslist.c tests/t_scan.c tests/t_buf.c tests/t_ip.c tests/t_socket.c tests/t_mutex.c tests/t_trackerlogic.c tests/t_workqueue.c tests/t_batch.c tests/t_fdstate.c tests/t_event.c tests/t_fmt.c
8TEST_UNITS=ot_urlencoded.c ot_fmt.c ot_event.c ot_batch.c ot_fdstate.c ot_buf.c ot_ip.c ot_socket.c ot_iovec.c ot_vector.c ot_random.c ot_hex.c ot_scan.c ot_accesslist.c ot_mutex.c ot_workqueue.c trackerlogic.c
9TEST_HEADERS=tests/test.h $(HEADERS)
10
11# A test binary is not a production binary, so it is built with the features
12# the tests need to reach.
13FEATURES_test=$(FEATURES) -DWANT_ACCESSLIST_BLACK -DWANT_SYNC_LIVE
14CFLAGS_test=$(CFLAGS) -I. -g -O1 $(FEATURES_test)
15
16# clang over $(CC) because the two toolchains do not check the same things.
17CC_sanitize?=clang
18CFLAGS_sanitize=$(CFLAGS_test) -fsanitize=address,undefined -fno-omit-frame-pointer
19LDFLAGS_sanitize=$(LDFLAGS) -fsanitize=address,undefined
20
21# Black box tests drive the real binary over the wire, so they cover the event
22# loop and the parsers working together. The client timeout is cut right down
23# so a test can reach the expiry sweep; tests/integration/test_expiry.py
24# mirrors these two numbers.
25PYTHON?=python3
26FEATURES_integration=$(FEATURES) -DWANT_IP_FROM_QUERY_STRING -DWANT_ACCESSLIST_BLACK -DWANT_DYNAMIC_ACCESSLIST -DWANT_KEEPALIVE -DOT_CLIENT_TIMEOUT=5 -DOT_CLIENT_TIMEOUT_CHECKINTERVAL=1
27CFLAGS_integration=$(CFLAGS) $(OPTS_debug) $(FEATURES_integration) -fsanitize=address,undefined -fno-omit-frame-pointer
28LDFLAGS_integration=$(LDFLAGS) -fsanitize=address,undefined
29CFLAGS_tsan=$(CFLAGS) $(OPTS_debug) $(FEATURES_integration) -fsanitize=thread -fno-omit-frame-pointer
30LDFLAGS_tsan=$(LDFLAGS) -fsanitize=thread
31
32BINARIES+=$(TESTBIN) $(TESTBIN).poll $(TESTBIN).sanitize opentracker.integration opentracker.tsan
33
34$(TESTBIN): $(TEST_SOURCES) $(TEST_UNITS) $(TEST_HEADERS) $(BUILDDEPS)
35 $(CC) -o $@ $(CFLAGS_test) $(TEST_SOURCES) $(TEST_UNITS)
36
37$(TESTBIN).poll: $(TEST_SOURCES) $(TEST_UNITS) $(TEST_HEADERS) $(BUILDDEPS)
38 $(CC) -o $@ $(CFLAGS_test) -DOT_EVENT_FORCE_POLL $(TEST_SOURCES) $(TEST_UNITS)
39
40$(TESTBIN).sanitize: $(TEST_SOURCES) $(TEST_UNITS) $(TEST_HEADERS) $(BUILDDEPS)
41 $(CC_sanitize) -o $@ $(CFLAGS_sanitize) $(TEST_SOURCES) $(TEST_UNITS) $(LDFLAGS_sanitize)
42
43opentracker.integration: $(SOURCES) $(HEADERS) $(BUILDDEPS)
44 $(CC) -o $@ $(CFLAGS_integration) $(SOURCES) $(LDFLAGS_integration)
45
46opentracker.tsan: $(SOURCES) $(HEADERS) $(BUILDDEPS)
47 $(CC) -o $@ $(CFLAGS_tsan) $(SOURCES) $(LDFLAGS_tsan)
48
49check: $(TESTBIN) $(BINARY)
50 ./$(TESTBIN)
51
52check-poll: $(TESTBIN).poll
53 ./$(TESTBIN).poll ot_event
54
55check-sanitize: $(TESTBIN).sanitize
56 ./$(TESTBIN).sanitize
57
58check-integration: opentracker.integration
59 OPENTRACKER=./opentracker.integration $(PYTHON) -m unittest discover -s tests/integration
60
61check-tsan: opentracker.tsan
62 OPENTRACKER=./opentracker.tsan $(PYTHON) -m unittest discover -s tests/integration
63
64# Cheapest first, so a quick failure comes back quickly.
65check-all:
66 $(MAKE) check
67 $(MAKE) check-poll
68 $(MAKE) check-sanitize
69 $(MAKE) check-integration
70 $(MAKE) check-tsan
71
72.PHONY: check check-poll check-sanitize check-integration check-tsan check-all