-
Notifications
You must be signed in to change notification settings - Fork 18
/
Makefile
178 lines (147 loc) · 7.34 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
170
171
172
173
174
175
176
177
178
CONTRIB_DIR = .
TEST_DIR = ./tests
SRC_DIR = src
BUILD_DIR = src
BIN_DIR = bin
LIB = -I libs
INC = -I include
GCOV_CFLAGS = -fprofile-arcs -ftest-coverage
SHELL = /bin/bash
CFLAGS += -Iinclude -fno-omit-frame-pointer -fno-common -fsigned-char -g -O2 -fPIC
ifdef SANITIZER
ifeq ($(SANITIZER),address)
MALLOC = libc
CFLAGS += -fsanitize=address -fno-sanitize-recover=all -fno-omit-frame-pointer
LDFLAGS += -fsanitize=address
else
ifeq ($(SANITIZER),undefined)
MALLOC = libc
CFLAGS += -fsanitize=undefined -fno-sanitize-recover=all -fno-omit-frame-pointer
LDFLAGS += -fsanitize=undefined
else
ifeq ($(SANITIZER),thread)
CFLAGS += -fsanitize=thread -fno-sanitize-recover=all -fno-omit-frame-pointer
LDFLAGS += -fsanitize=thread
else
$(error "unknown sanitizer=${SANITIZER}")
endif
endif
endif
endif
ifeq ($(COVERAGE), 1)
CFLAGS += $(GCOV_CFLAGS)
TEST_CFLAGS = $(CFLAGS)
else
TEST_CFLAGS = $(CFLAGS) $(GCOV_CFLAGS)
endif
LIB_CFLAGS = $(CFLAGS) -Wextra -Wall -pedantic -Werror
UNAME := $(shell uname)
ifeq ($(UNAME), Darwin)
ASANFLAGS = -fsanitize=address
SHAREDFLAGS = -dynamiclib
SHAREDEXT = dylib
# We need to include the El Capitan specific /usr/includes, aargh
CFLAGS += -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk/usr/include/
CFLAGS += -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/usr/include
CFLAGS += $(ASANFLAGS)
CFLAGS += -Wno-nullability-completeness
else
SHAREDFLAGS = -shared
SHAREDEXT = so
endif
# Export LD_LIBRARY_PATH to allow the CFFI shared object to find libraft.so.
export LD_LIBRARY_PATH=$(PWD)
OBJECTS = \
$(BUILD_DIR)/raft_server.o \
$(BUILD_DIR)/raft_server_properties.o \
$(BUILD_DIR)/raft_node.o \
$(BUILD_DIR)/raft_log.o
TEST_OBJECTS = $(patsubst $(BUILD_DIR)/%.o,$(BUILD_DIR)/test-%.o,$(OBJECTS))
TEST_HELPERS = \
$(TEST_DIR)/CuTest.o \
$(TEST_DIR)/linked_list_queue.o \
$(TEST_DIR)/mock_send_functions.o
TESTS = $(wildcard $(TEST_DIR)/test_*.c)
TEST_TARGETS = $(patsubst $(TEST_DIR)/%.c,$(BIN_DIR)/%,$(TESTS))
LIBRAFT_STATIC = libraft.a
LIBRAFT_SHARED = libraft.$(SHAREDEXT)
all: static shared
shared: $(LIBRAFT_SHARED)
static: $(LIBRAFT_STATIC)
$(LIBRAFT_SHARED): $(OBJECTS)
$(CC) $^ $(LDFLAGS) $(LIB_CFLAGS) -fPIC $(SHAREDFLAGS) -o $@
$(LIBRAFT_STATIC): $(OBJECTS)
ar -r $@ $^
.PHONY: tests
tests: $(TEST_TARGETS)
gcov $(TEST_OBJECTS)
.PHONY: gcov
gcov: $(OBJECTS)
gcov $(OBJECTS) $(TEST_OBJECTS)
$(TEST_TARGETS): $(BIN_DIR)/%: $(TEST_OBJECTS) $(TEST_HELPERS)
$(CC) $(TEST_CFLAGS) $(TEST_DIR)/$*.c $(LIB) $(INC) $^ -o $@
./$@
$(BUILD_DIR)/test-%.o: $(SRC_DIR)/%.c
$(CC) $(TEST_CFLAGS) $(INC) -c -o $@ $<
$(TEST_DIR)/%.o: $(TEST_DIR)/%.c
$(CC) $(TEST_CFLAGS) $(INC) -c -o $@ $<
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
$(CC) $(LIB_CFLAGS) $(INC) -c -o $@ $<
.PHONY: test_helper
test_helper: $(TEST_HELPERS)
$(CC) $(TEST_CFLAGS) -o $@
# A file to signal we've built the CFFI module, because its name is not fixed.
RAFT_CFFI_TARGET = tests/.raft_cffi_built
$(RAFT_CFFI_TARGET): $(LIBRAFT_SHARED)
python3 tests/raft_cffi_builder.py
touch $(RAFT_CFFI_TARGET)
.PHONY: test_fuzzer
test_fuzzer: $(RAFT_CFFI_TARGET)
python tests/log_fuzzer.py
.PHONY: tests_full
tests_full:
make clean
make tests
make test_fuzzer
make test_virtraft
.PHONY: test_virtraft
test_virtraft: $(RAFT_CFFI_TARGET)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 1 -m 3 $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 1 -m 3 --client_rate 0 $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 7 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 1 -m 3 $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 7 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 1 -m 3 --client_rate 0 $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 2 -m 3 $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 2 -m 3 --client_rate 0 $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 3 -m 3 $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 3 -m 3 --client_rate 0 $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 4 -m 3 $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 4 -m 3 --client_rate 0 $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 5 -m 3 $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 5 -m 3 --client_rate 0 $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 6 -m 3 $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 6 -m 3 --client_rate 0 $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 1 -m 3 --auto_flush $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 1 -m 3 --client_rate 0 --auto_flush $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 7 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 1 -m 3 --auto_flush $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 7 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 1 -m 3 --client_rate 0 --auto_flush $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 2 -m 3 --auto_flush $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 2 -m 3 --client_rate 0 --auto_flush $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 3 -m 3 --auto_flush $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 3 -m 3 --client_rate 0 --auto_flush $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 4 -m 3 --auto_flush $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 4 -m 3 --client_rate 0 --auto_flush $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 5 -m 3 --auto_flush $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 5 -m 3 --client_rate 0 --auto_flush $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 6 -m 3 --auto_flush $(VIRTRAFT_OPTS)
python3 tests/virtraft2.py --servers 5 -i 20000 --compaction_rate 10 --drop_rate 5 -P 10 --seed 6 -m 3 --client_rate 0 --auto_flush $(VIRTRAFT_OPTS)
.PHONY: amalgamation
amalgamation:
./scripts/amalgamate.sh > raft.h
.PHONY: infer
infer: do_infer
.PHONY: do_infer
do_infer:
make clean
infer -- make
clean:
-@rm -f src/*.o bin/* src/*.gcda src/*.gcno *.gcno *.gcda *.gcov tests/*.o tests/*.gcda tests/*.gcno tests/raft_cffi.* $(RAFT_CFFI_TARGET) $(LIBRAFT_SHARED) $(LIBRAFT_STATIC)