Skip to content

Commit 205f986

Browse files
authored
Initial commit
0 parents  commit 205f986

28 files changed

+4781
-0
lines changed

.github/workflows/ci.yml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: Allocator Test Suite CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
build-and-test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Install Build Dependencies
17+
run: |
18+
sudo apt-get update
19+
sudo apt-get install -y build-essential cmake autoconf automake libtool
20+
21+
- name: Setup Allocators (Local Build)
22+
run: ./setup_allocators.sh
23+
24+
- name: Run Glibc Baseline Tests
25+
run: make run-tests
26+
continue-on-error: true
27+
28+
- name: Run Mimalloc Tests (Release)
29+
run: make test-mimalloc
30+
continue-on-error: true
31+
32+
- name: Run Mimalloc Tests (Secure)
33+
run: make test-mimalloc-secure
34+
continue-on-error: true
35+
36+
- name: Run Jemalloc Tests (Release)
37+
run: make test-jemalloc
38+
continue-on-error: true
39+
40+
- name: Run Jemalloc Tests (Debug)
41+
run: make test-jemalloc-debug
42+
continue-on-error: true
43+
44+
- name: Run Skeleton/MyAlloc Tests
45+
run: make test-skeleton
46+
continue-on-error: true
47+
48+
- name: Run Glibc Benchmarks (Full)
49+
run: make bench-glibc
50+
continue-on-error: true
51+
52+
- name: Run Skeleton Benchmarks (Full)
53+
run: make bench-skeleton
54+
continue-on-error: true

.gitignore

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# Build directories
2+
build/
3+
build_*/
4+
libs/
5+
6+
# Compiled Object files
7+
*.o
8+
*.a
9+
*.so
10+
*.dylib
11+
*.dll
12+
*.exe
13+
14+
# CMake
15+
CMakeCache.txt
16+
CMakeFiles/
17+
cmake_install.cmake
18+
*.cmake
19+
!CMakeLists.txt
20+
21+
# Editor / IDE
22+
.vscode/
23+
.idea/
24+
*.swp
25+
*.swo
26+
*~
27+
.DS_Store
28+
29+
# Allocator Sources (managed by setup_allocators.sh)
30+
allocators/mimalloc/mimalloc_src/
31+
allocators/jemalloc/jemalloc_src/

Makefile

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
2+
CC ?= gcc
3+
CFLAGS := -std=c17 -Wall -Wextra -Wpedantic -Werror
4+
CFLAGS += -fno-strict-aliasing
5+
CFLAGS += -D_GNU_SOURCE
6+
CFLAGS += -I./include
7+
CFLAGS += $(EXTRA_CFLAGS)
8+
9+
# Build modes
10+
ifeq ($(MODE),debug)
11+
CFLAGS += -O0 -g3 -fsanitize=address,undefined
12+
LDFLAGS += -fsanitize=address,undefined
13+
else ifeq ($(MODE),release)
14+
CFLAGS += -O2 -DNDEBUG
15+
else ifeq ($(MODE),bench)
16+
CFLAGS += -O3 -march=native -DNDEBUG
17+
else
18+
CFLAGS += -O2 -g
19+
endif
20+
21+
LDFLAGS += -lm -lpthread $(EXTRA_LDFLAGS)
22+
23+
TEST_SRCS := src/tests/test_correctness.c \
24+
src/tests/test_stress.c \
25+
src/tests/test_edge.c \
26+
src/tests/test_fragmentation.c \
27+
src/tests/test_features.c \
28+
src/tests/test_realistic.c \
29+
src/harness/main_tests.c
30+
31+
BENCH_SRCS := src/benchmarks/bench_synthetic.c \
32+
src/harness/main_bench.c
33+
34+
DEFAULT_ALLOC := allocators/glibc/glibc_allocator.c
35+
36+
ALLOCATOR ?= $(DEFAULT_ALLOC)
37+
38+
BUILD_DIR := build
39+
BIN_DIR := bin
40+
41+
TEST_BIN := $(BIN_DIR)/run_tests
42+
BENCH_BIN := $(BIN_DIR)/run_bench
43+
44+
TEST_OBJS := $(patsubst %.c,$(BUILD_DIR)/%.o,$(TEST_SRCS))
45+
BENCH_OBJS := $(patsubst %.c,$(BUILD_DIR)/%.o,$(BENCH_SRCS))
46+
ALLOC_OBJ := $(BUILD_DIR)/allocator.o
47+
48+
.PHONY: all tests bench clean help run-tests run-bench
49+
50+
all: tests bench
51+
52+
tests: $(TEST_BIN)
53+
54+
bench: $(BENCH_BIN)
55+
56+
$(TEST_BIN): $(TEST_OBJS) $(ALLOC_OBJ) | $(BIN_DIR)
57+
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
58+
@echo "Built test runner: $@"
59+
@echo "Allocator: $(ALLOCATOR)"
60+
61+
$(BENCH_BIN): $(BENCH_OBJS) $(ALLOC_OBJ) | $(BIN_DIR)
62+
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
63+
@echo "Built benchmark runner: $@"
64+
@echo "Allocator: $(ALLOCATOR)"
65+
66+
$(BUILD_DIR)/src/tests/%.o: src/tests/%.c | $(BUILD_DIR)/src/tests
67+
$(CC) $(CFLAGS) -c -o $@ $<
68+
69+
$(BUILD_DIR)/src/benchmarks/%.o: src/benchmarks/%.c | $(BUILD_DIR)/src/benchmarks
70+
$(CC) $(CFLAGS) -c -o $@ $<
71+
72+
$(BUILD_DIR)/src/harness/%.o: src/harness/%.c | $(BUILD_DIR)/src/harness
73+
$(CC) $(CFLAGS) -c -o $@ $<
74+
75+
$(ALLOC_OBJ): $(ALLOCATOR) | $(BUILD_DIR)
76+
$(CC) $(CFLAGS) -c -o $@ $<
77+
78+
$(BUILD_DIR):
79+
mkdir -p $@
80+
81+
$(BUILD_DIR)/src/tests:
82+
mkdir -p $@
83+
84+
$(BUILD_DIR)/src/benchmarks:
85+
mkdir -p $@
86+
87+
$(BUILD_DIR)/src/harness:
88+
mkdir -p $@
89+
90+
$(BIN_DIR):
91+
mkdir -p $@
92+
93+
run-tests: tests
94+
@echo ""
95+
@echo "Running tests..."
96+
@echo ""
97+
./$(TEST_BIN) $(ARGS)
98+
99+
run-bench: bench
100+
@echo ""
101+
@echo "Running benchmarks..."
102+
@echo ""
103+
./$(BENCH_BIN) $(ARGS)
104+
105+
run-quick: bench
106+
@echo ""
107+
@echo "Running quick benchmarks..."
108+
@echo ""
109+
./$(BENCH_BIN) --quick
110+
111+
MIMALLOC_WRAPPER := allocators/mimalloc/mimalloc_wrapper.c
112+
JEMALLOC_WRAPPER := allocators/jemalloc/jemalloc_wrapper.c
113+
GLIBC_ALLOC := allocators/glibc/glibc_allocator.c
114+
SKELETON_ALLOC := allocators/skeleton/my_allocator.c
115+
116+
# Force rebuild of allocator object when switching
117+
clean-alloc:
118+
rm -f $(ALLOC_OBJ)
119+
120+
# Convenience targets for testing variants
121+
test-mimalloc: clean-alloc
122+
$(MAKE) run-tests ALLOCATOR=$(MIMALLOC_WRAPPER) EXTRA_LDFLAGS="-Llibs -lmimalloc" EXTRA_CFLAGS="-Iallocators/mimalloc/mimalloc_src/include"
123+
124+
test-mimalloc-secure: clean-alloc
125+
$(MAKE) run-tests ALLOCATOR=$(MIMALLOC_WRAPPER) EXTRA_LDFLAGS="-Llibs -lmimalloc-secure" EXTRA_CFLAGS="-Iallocators/mimalloc/mimalloc_src/include"
126+
127+
test-jemalloc: clean-alloc
128+
$(MAKE) run-tests ALLOCATOR=$(JEMALLOC_WRAPPER) EXTRA_LDFLAGS="-Llibs -ljemalloc -lrt -ldl -lm" EXTRA_CFLAGS="-Iallocators/jemalloc/jemalloc_src/include"
129+
130+
test-jemalloc-debug: clean-alloc
131+
$(MAKE) run-tests ALLOCATOR=$(JEMALLOC_WRAPPER) EXTRA_LDFLAGS="-Llibs -ljemalloc-debug -lrt -ldl -lm" EXTRA_CFLAGS="-Iallocators/jemalloc/jemalloc_src/include"
132+
133+
test-glibc: clean-alloc
134+
$(MAKE) run-tests ALLOCATOR=$(GLIBC_ALLOC)
135+
136+
test-skeleton: clean-alloc
137+
$(MAKE) run-tests ALLOCATOR=$(SKELETON_ALLOC)
138+
139+
# Benchmark/Performance targets
140+
bench-glibc: clean-alloc
141+
$(MAKE) MODE=bench run-bench ALLOCATOR=$(GLIBC_ALLOC)
142+
143+
bench-skeleton: clean-alloc
144+
$(MAKE) MODE=bench run-bench ALLOCATOR=$(SKELETON_ALLOC)
145+
146+
bench-mimalloc: clean-alloc
147+
$(MAKE) MODE=bench run-bench ALLOCATOR=$(MIMALLOC_WRAPPER) EXTRA_LDFLAGS="-Llibs -lmimalloc" EXTRA_CFLAGS="-Iallocators/mimalloc/mimalloc_src/include"
148+
149+
bench-jemalloc: clean-alloc
150+
$(MAKE) MODE=bench run-bench ALLOCATOR=$(JEMALLOC_WRAPPER) EXTRA_LDFLAGS="-Llibs -ljemalloc -lrt -ldl -lm" EXTRA_CFLAGS="-Iallocators/jemalloc/jemalloc_src/include"
151+
152+
debug:
153+
$(MAKE) MODE=debug all
154+
155+
release:
156+
$(MAKE) MODE=release all
157+
158+
bench-optimized:
159+
$(MAKE) MODE=bench bench
160+
161+
clean:
162+
rm -rf $(BUILD_DIR) $(BIN_DIR)
163+
164+
help:
165+
@echo "Allocator Test Suite - Build System"
166+
@echo ""
167+
@echo "Targets:"
168+
@echo " all Build tests and benchmarks (default)"
169+
@echo " tests Build test runner only"
170+
@echo " bench Build benchmark runner only"
171+
@echo " run-tests Build and run tests"
172+
@echo " run-bench Build and run benchmarks"
173+
@echo " run-quick Build and run quick benchmarks"
174+
@echo " test-mimalloc Run tests with Mimalloc (Release)"
175+
@echo " test-mimalloc-secure Run tests with Mimalloc (Secure)"
176+
@echo " test-jemalloc Run tests with Jemalloc (Release)"
177+
@echo " test-jemalloc-debug Run tests with Jemalloc (Debug)"
178+
@echo " test-skeleton Run tests with Student Skeleton"
179+
@echo ""
180+
@echo "Variables:"
181+
@echo " ALLOCATOR=path Path to custom allocator source"
182+
@echo " MODE=debug Build with -O0 -g3 -fsanitize"
183+
@echo " MODE=release Build with -O2 -DNDEBUG"
184+
@echo " MODE=bench Build with -O3 -march=native"
185+
@echo " ARGS=... Arguments to pass to runner"
186+
@echo ""
187+
@echo "Examples:"
188+
@echo " make # Build with glibc"
189+
@echo " make ALLOCATOR=../myalloc/myalloc.c # Build with custom allocator"
190+
@echo " make run-tests ARGS='--correctness' # Run only correctness tests"
191+
@echo " make run-bench ARGS='--csv' # Output benchmarks as CSV"
192+
@echo " make debug run-tests # Run with AddressSanitizer"

0 commit comments

Comments
 (0)