-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
150 lines (121 loc) · 3.8 KB
/
Makefile
File metadata and controls
150 lines (121 loc) · 3.8 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
CC = gcc
CFLAGS = -Wall -Wextra -Werror -pedantic -std=c11 -D_POSIX_C_SOURCE=200809L -I./src
LIBS =
# Debug build flags (add -g and sanitizers)
DEBUG_FLAGS = -g -fsanitize=address,undefined -fno-omit-frame-pointer
# Release build flags (optimizations)
RELEASE_FLAGS = -O3 -flto
# Source files
SRC_DIR = src
OBJ_DIR = obj
BIN_DIR = bin
TEST_DIR = tests
EXAMPLE_DIR = examples
# Main server sources (excluding main.c for testing)
SERVER_SRCS = $(SRC_DIR)/server.c \
$(SRC_DIR)/socket_ops.c \
$(SRC_DIR)/epoll_handler.c \
$(SRC_DIR)/connection.c
# Object files
SERVER_OBJS = $(SERVER_SRCS:$(SRC_DIR)/%.c=$(OBJ_DIR)/%.o)
MAIN_OBJ = $(OBJ_DIR)/main.o
# Binary name
TARGET = tcp_server
# Default target (release)
.PHONY: all
all: release
# Release build
.PHONY: release
release: CFLAGS += $(RELEASE_FLAGS)
release: $(TARGET)
# Debug build
.PHONY: debug
debug: CFLAGS += $(DEBUG_FLAGS)
debug: $(TARGET)
# Link the server
$(TARGET): $(SERVER_OBJS) $(MAIN_OBJ)
$(CC) $(CFLAGS) $^ -o $@ $(LIBS)
# Compile source files
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(OBJ_DIR)
$(CC) $(CFLAGS) -c $< -o $@
# Client example
.PHONY: client
client: $(EXAMPLE_DIR)/client.c
$(CC) $(CFLAGS) $< -o $(EXAMPLE_DIR)/client
# Tests
# Tests
test_socket: $(TEST_DIR)/test_socket.c $(SRC_DIR)/socket_ops.c
$(CC) $(CFLAGS) $(TEST_DIR)/test_socket.c $(SRC_DIR)/socket_ops.c -o test_socket
test_connection: $(TEST_DIR)/test_connection.c $(SRC_DIR)/connection.c $(SRC_DIR)/socket_ops.c
$(CC) $(CFLAGS) $(TEST_DIR)/test_connection.c $(SRC_DIR)/connection.c $(SRC_DIR)/socket_ops.c -o test_connection
test_concurrent: $(TEST_DIR)/test_concurrent.c $(SERVER_OBJS)
$(CC) $(CFLAGS) $(TEST_DIR)/test_concurrent.c $(SERVER_OBJS) -o test_concurrent
.PHONY: test test-unit
test test-unit: test_socket test_connection
@echo "Running unit tests..."
./test_socket
./test_connection
.PHONY: integration-test test-integration
integration-test test-integration: $(TARGET) test_concurrent
@echo "Running integration tests..."
# In a real CI, we'd start the server in background and run test_concurrent
# For now, we'll verify the test binary builds
@echo "Integration test binary built."
.PHONY: test-functional
test-functional: $(TARGET) client
@echo "Running functional tests..."
# Starting server in background for testing (simple check)
./$(TARGET) 9999 & PID=$$!; \
sleep 1; \
./examples/client localhost 9999; \
kill $$PID
.PHONY: test-stress
test-stress: $(TARGET)
@echo "Running stress tests..."
chmod +x examples/stress_test.sh
./$(TARGET) 9998 & PID=$$!; \
sleep 1; \
./examples/stress_test.sh localhost 9998 || kill $$PID; \
kill $$PID
.PHONY: test-performance
test-performance: $(TARGET)
@echo "Running performance tests..."
# Reuse stress test for now as basic performance check
make test-stress
.PHONY: build
build: all
# Formatting and Linting
.PHONY: format
format:
clang-format -i $(SRC_DIR)/*.c $(SRC_DIR)/*.h $(TEST_DIR)/*.c $(EXAMPLE_DIR)/*.c
.PHONY: format-check
format-check:
clang-format -n --Werror $(SRC_DIR)/*.c $(SRC_DIR)/*.h $(TEST_DIR)/*.c $(EXAMPLE_DIR)/*.c
.PHONY: lint
lint:
./scripts/lint.sh
# Valgrind
.PHONY: valgrind
valgrind: $(TARGET)
valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./$(TARGET) & PID=$$!; sleep 2; kill -INT $$PID
# Coverage
.PHONY: coverage
coverage: CFLAGS += -fprofile-arcs -ftest-coverage
coverage: LIBS += -lgcov
coverage: clean test
mkdir -p coverage
lcov --capture --directory . --output-file coverage/coverage.info
genhtml coverage/coverage.info --output-directory coverage/report
# Clean
.PHONY: clean
clean:
rm -rf $(OBJ_DIR) $(TARGET) test_socket test_connection test_concurrent $(EXAMPLE_DIR)/client
# Stress test (placeholder)
.PHONY: stress_test
stress_test: client
./examples/stress_test.sh
# Run
.PHONY: run
run: $(TARGET)
./$(TARGET)