summaryrefslogtreecommitdiff
path: root/Mk/tests.mk
blob: 2efdd72717fc554b573aed8f93654145e9e80e16 (plain)
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
BUILDDEPS+=Mk/tests.mk

# The modules under test are compiled straight into the test binary, so a test
# may reach a static function by including the source. tests/stubs.c supplies
# the few symbols those modules reference but the tests never reach.
TESTBIN=tests/runner
TEST_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
TEST_UNITS=src/ot_urlencoded.c src/ot_fmt.c src/ot_event.c src/ot_batch.c src/ot_fdstate.c src/ot_buf.c src/ot_ip.c src/ot_socket.c src/ot_iovec.c src/ot_vector.c src/ot_random.c src/ot_hex.c src/ot_scan.c src/ot_accesslist.c src/ot_mutex.c src/ot_workqueue.c src/trackerlogic.c
TEST_HEADERS=tests/test.h $(HEADERS)

# A test binary is not a production binary, so it is built with the features
# the tests need to reach.
FEATURES_test=$(FEATURES) -DWANT_ACCESSLIST_BLACK -DWANT_SYNC_LIVE
CFLAGS_test=-Isrc -g -O1 $(CPPFLAGS) $(OT_CFLAGS) $(FEATURES_test)

# clang over $(CC) because the two toolchains do not check the same things.
CC_sanitize?=clang
CFLAGS_sanitize=$(CFLAGS_test) -fsanitize=address,undefined -fno-omit-frame-pointer
LDFLAGS_sanitize=$(LINK) -fsanitize=address,undefined

# Black box tests drive the real binary over the wire, so they cover the event
# loop and the parsers working together. The client timeout is cut right down
# so a test can reach the expiry sweep; tests/integration/test_expiry.py
# mirrors these two numbers.
PYTHON?=python3
FEATURES_integration=$(FEATURES) -DWANT_IP_FROM_QUERY_STRING -DWANT_ACCESSLIST_BLACK -DWANT_DYNAMIC_ACCESSLIST -DWANT_KEEPALIVE -DOT_CLIENT_TIMEOUT=5 -DOT_CLIENT_TIMEOUT_CHECKINTERVAL=1
CFLAGS_integration=$(OPTS_debug) $(CPPFLAGS) $(OT_CFLAGS) $(FEATURES_integration) -fsanitize=address,undefined -fno-omit-frame-pointer
LDFLAGS_integration=$(LINK) -fsanitize=address,undefined
CFLAGS_tsan=$(OPTS_debug) $(CPPFLAGS) $(OT_CFLAGS) $(FEATURES_integration) -fsanitize=thread -fno-omit-frame-pointer
LDFLAGS_tsan=$(LINK) -fsanitize=thread

# Live sync is a compile time feature, so reaching it from a black box test
# needs a binary of its own. tests/integration/test_livesync.py skips itself
# against a build without it, which is what -v is for.
FEATURES_livesync=$(FEATURES_integration) -DWANT_SYNC_LIVE
CFLAGS_livesync=$(OPTS_debug) $(CPPFLAGS) $(OT_CFLAGS) $(FEATURES_livesync) -fsanitize=address,undefined -fno-omit-frame-pointer

BINARIES+=$(TESTBIN) $(TESTBIN).poll $(TESTBIN).sanitize opentracker.integration opentracker.tsan opentracker.livesync

$(TESTBIN): $(TEST_SOURCES) $(TEST_UNITS) $(TEST_HEADERS) $(BUILDDEPS)
	$(CC) -o $@ $(CFLAGS_test) $(TEST_SOURCES) $(TEST_UNITS)

$(TESTBIN).poll: $(TEST_SOURCES) $(TEST_UNITS) $(TEST_HEADERS) $(BUILDDEPS)
	$(CC) -o $@ $(CFLAGS_test) -DOT_EVENT_FORCE_POLL $(TEST_SOURCES) $(TEST_UNITS)

$(TESTBIN).sanitize: $(TEST_SOURCES) $(TEST_UNITS) $(TEST_HEADERS) $(BUILDDEPS)
	$(CC_sanitize) -o $@ $(CFLAGS_sanitize) $(TEST_SOURCES) $(TEST_UNITS) $(LDFLAGS_sanitize)

opentracker.integration: $(SOURCES) $(HEADERS) $(BUILDDEPS)
	$(CC) -o $@ $(CFLAGS_integration) $(SOURCES) $(LDFLAGS_integration)

opentracker.tsan: $(SOURCES) $(HEADERS) $(BUILDDEPS)
	$(CC) -o $@ $(CFLAGS_tsan) $(SOURCES) $(LDFLAGS_tsan)

opentracker.livesync: $(SOURCES) $(HEADERS) $(BUILDDEPS)
	$(CC) -o $@ $(CFLAGS_livesync) $(SOURCES) $(LDFLAGS_integration)

check: $(TESTBIN) $(BINARY)
	./$(TESTBIN)

check-poll: $(TESTBIN).poll
	./$(TESTBIN).poll ot_event

check-sanitize: $(TESTBIN).sanitize
	./$(TESTBIN).sanitize

check-integration: opentracker.integration
	OPENTRACKER=./opentracker.integration $(PYTHON) -m unittest discover -s tests/integration

check-tsan: opentracker.tsan
	OPENTRACKER=./opentracker.tsan $(PYTHON) -m unittest discover -s tests/integration

# The whole suite against a build that has live sync, which is also the only
# way the live sync tests stop skipping.
check-livesync: opentracker.livesync
	OPENTRACKER=./opentracker.livesync $(PYTHON) -m unittest discover -s tests/integration

# Cheapest first, so a quick failure comes back quickly.
check-all:
	$(MAKE) check
	$(MAKE) check-poll
	$(MAKE) check-sanitize
	$(MAKE) check-integration
	$(MAKE) check-livesync
	$(MAKE) check-tsan

.PHONY: check check-poll check-sanitize check-integration check-livesync check-tsan check-all