-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
202 lines (156 loc) · 6.29 KB
/
Makefile
File metadata and controls
202 lines (156 loc) · 6.29 KB
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
CC ?= gcc
CFLAGS := -std=c17 -Wall -Wextra -Wpedantic -Werror
CFLAGS += -fno-strict-aliasing
CFLAGS += -D_GNU_SOURCE
CFLAGS += -I./include
CFLAGS += $(EXTRA_CFLAGS)
# Build modes
ifeq ($(MODE),debug)
CFLAGS += -O0 -g3 -fsanitize=address,undefined
LDFLAGS += -fsanitize=address,undefined
else ifeq ($(MODE),release)
CFLAGS += -O2 -DNDEBUG
else ifeq ($(MODE),bench)
CFLAGS += -O3 -march=native -DNDEBUG
else
CFLAGS += -O2 -g
endif
LDFLAGS += -lm -lpthread $(EXTRA_LDFLAGS)
TEST_SRCS := src/tests/test_correctness.c \
src/tests/test_stress.c \
src/tests/test_edge.c \
src/tests/test_fragmentation.c \
src/tests/test_features.c \
src/tests/test_realistic.c \
src/harness/main_tests.c
BENCH_SRCS := src/benchmarks/bench_synthetic.c \
src/harness/main_bench.c
DEFAULT_ALLOC := allocators/glibc/glibc_allocator.c
ALLOCATOR ?= $(DEFAULT_ALLOC)
BUILD_DIR := build
BIN_DIR := bin
TEST_BIN := $(BIN_DIR)/run_tests
BENCH_BIN := $(BIN_DIR)/run_bench
TEST_OBJS := $(patsubst %.c,$(BUILD_DIR)/%.o,$(TEST_SRCS))
BENCH_OBJS := $(patsubst %.c,$(BUILD_DIR)/%.o,$(BENCH_SRCS))
ALLOC_OBJ := $(BUILD_DIR)/allocator.o
.PHONY: all tests bench clean help run-tests run-bench
all: tests bench
tests: $(TEST_BIN)
bench: $(BENCH_BIN)
$(TEST_BIN): $(TEST_OBJS) $(ALLOC_OBJ) | $(BIN_DIR)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
@echo "Built test runner: $@"
@echo "Allocator: $(ALLOCATOR)"
$(BENCH_BIN): $(BENCH_OBJS) $(ALLOC_OBJ) | $(BIN_DIR)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
@echo "Built benchmark runner: $@"
@echo "Allocator: $(ALLOCATOR)"
$(BUILD_DIR)/src/tests/%.o: src/tests/%.c | $(BUILD_DIR)/src/tests
$(CC) $(CFLAGS) -c -o $@ $<
$(BUILD_DIR)/src/benchmarks/%.o: src/benchmarks/%.c | $(BUILD_DIR)/src/benchmarks
$(CC) $(CFLAGS) -c -o $@ $<
$(BUILD_DIR)/src/harness/%.o: src/harness/%.c | $(BUILD_DIR)/src/harness
$(CC) $(CFLAGS) -c -o $@ $<
$(ALLOC_OBJ): $(ALLOCATOR) | $(BUILD_DIR)
$(CC) $(CFLAGS) -c -o $@ $<
$(BUILD_DIR):
mkdir -p $@
$(BUILD_DIR)/src/tests:
mkdir -p $@
$(BUILD_DIR)/src/benchmarks:
mkdir -p $@
$(BUILD_DIR)/src/harness:
mkdir -p $@
$(BIN_DIR):
mkdir -p $@
run-tests: tests
@echo ""
@echo "Running tests..."
@echo ""
./$(TEST_BIN) $(ARGS)
run-bench: bench
@echo ""
@echo "Running benchmarks..."
@echo ""
./$(BENCH_BIN) $(ARGS)
run-quick: bench
@echo ""
@echo "Running quick benchmarks..."
@echo ""
./$(BENCH_BIN) --quick
MIMALLOC_WRAPPER := allocators/mimalloc/mimalloc_wrapper.c
JEMALLOC_WRAPPER := allocators/jemalloc/jemalloc_wrapper.c
GLIBC_ALLOC := allocators/glibc/glibc_allocator.c
SKELETON_ALLOC := allocators/skeleton/my_allocator.c
SHARE_RDALLOC_WRAPPER := allocators/share_rdalloc/share_rdalloc_wrapper.c
SHARE_RDALLOC_DIR ?= ../share-rdAlloc
# Force rebuild of allocator object when switching
clean-alloc:
rm -f $(ALLOC_OBJ)
# Convenience targets for testing variants
test-mimalloc: clean-alloc
$(MAKE) run-tests ALLOCATOR=$(MIMALLOC_WRAPPER) EXTRA_LDFLAGS="-Llibs -lmimalloc" EXTRA_CFLAGS="-Iallocators/mimalloc/mimalloc_src/include"
test-mimalloc-secure: clean-alloc
$(MAKE) run-tests ALLOCATOR=$(MIMALLOC_WRAPPER) EXTRA_LDFLAGS="-Llibs -lmimalloc-secure" EXTRA_CFLAGS="-Iallocators/mimalloc/mimalloc_src/include"
test-jemalloc: clean-alloc
$(MAKE) run-tests ALLOCATOR=$(JEMALLOC_WRAPPER) EXTRA_LDFLAGS="-Llibs -ljemalloc -lrt -ldl -lm" EXTRA_CFLAGS="-Iallocators/jemalloc/jemalloc_src/include"
test-jemalloc-debug: clean-alloc
$(MAKE) run-tests ALLOCATOR=$(JEMALLOC_WRAPPER) EXTRA_LDFLAGS="-Llibs -ljemalloc-debug -lrt -ldl -lm" EXTRA_CFLAGS="-Iallocators/jemalloc/jemalloc_src/include"
test-glibc: clean-alloc
$(MAKE) run-tests ALLOCATOR=$(GLIBC_ALLOC)
test-skeleton: clean-alloc
$(MAKE) run-tests ALLOCATOR=$(SKELETON_ALLOC)
test-share-rdalloc: clean-alloc
$(MAKE) -C $(SHARE_RDALLOC_DIR) all
$(MAKE) run-tests ALLOCATOR=$(SHARE_RDALLOC_WRAPPER) \
EXTRA_CFLAGS="-I$(SHARE_RDALLOC_DIR)" \
EXTRA_LDFLAGS="-L$(SHARE_RDALLOC_DIR) -lshare_rdalloc"
# Benchmark/Performance targets
bench-glibc: clean-alloc
$(MAKE) MODE=bench run-bench ALLOCATOR=$(GLIBC_ALLOC)
bench-skeleton: clean-alloc
$(MAKE) MODE=bench run-bench ALLOCATOR=$(SKELETON_ALLOC)
bench-mimalloc: clean-alloc
$(MAKE) MODE=bench run-bench ALLOCATOR=$(MIMALLOC_WRAPPER) EXTRA_LDFLAGS="-Llibs -lmimalloc" EXTRA_CFLAGS="-Iallocators/mimalloc/mimalloc_src/include"
bench-jemalloc: clean-alloc
$(MAKE) MODE=bench run-bench ALLOCATOR=$(JEMALLOC_WRAPPER) EXTRA_LDFLAGS="-Llibs -ljemalloc -lrt -ldl -lm" EXTRA_CFLAGS="-Iallocators/jemalloc/jemalloc_src/include"
debug:
$(MAKE) MODE=debug all
release:
$(MAKE) MODE=release all
bench-optimized:
$(MAKE) MODE=bench bench
clean:
rm -rf $(BUILD_DIR) $(BIN_DIR)
help:
@echo "Allocator Test Suite - Build System"
@echo ""
@echo "Targets:"
@echo " all Build tests and benchmarks (default)"
@echo " tests Build test runner only"
@echo " bench Build benchmark runner only"
@echo " run-tests Build and run tests"
@echo " run-bench Build and run benchmarks"
@echo " run-quick Build and run quick benchmarks"
@echo " test-mimalloc Run tests with Mimalloc (Release)"
@echo " test-mimalloc-secure Run tests with Mimalloc (Secure)"
@echo " test-jemalloc Run tests with Jemalloc (Release)"
@echo " test-jemalloc-debug Run tests with Jemalloc (Debug)"
@echo " test-skeleton Run tests with Student Skeleton"
@echo " test-share-rdalloc Run tests with share-rdAlloc (set SHARE_RDALLOC_DIR if not ../share-rdAlloc)"
@echo ""
@echo "Variables:"
@echo " ALLOCATOR=path Path to custom allocator source"
@echo " SHARE_RDALLOC_DIR Path to share-rdAlloc (default: ../share-rdAlloc)"
@echo " MODE=debug Build with -O0 -g3 -fsanitize"
@echo " MODE=release Build with -O2 -DNDEBUG"
@echo " MODE=bench Build with -O3 -march=native"
@echo " ARGS=... Arguments to pass to runner"
@echo ""
@echo "Examples:"
@echo " make # Build with glibc"
@echo " make ALLOCATOR=../myalloc/myalloc.c # Build with custom allocator"
@echo " make run-tests ARGS='--correctness' # Run only correctness tests"
@echo " make run-bench ARGS='--csv' # Output benchmarks as CSV"
@echo " make debug run-tests # Run with AddressSanitizer"