Skip to content

Commit

Permalink
build: add tests rule
Browse files Browse the repository at this point in the history
  • Loading branch information
drawbu committed Apr 15, 2024
1 parent f1834f5 commit 4852b28
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
10 changes: 5 additions & 5 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# Binaries
*.out
myteams_cli
myteams_server
unit_tests
asan
prof
/myteams_cli
/myteams_server
/src/*/tests
/src/*/asan
/src/*/prof

# Compilation
.build/
Expand Down
8 changes: 7 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,13 @@ asan: all
.PHONY: prof
prof: SERVER_TARGET := prof
prof: CLIENT_TARGET := prof
prof: prof
prof: all

.PHONY: tests
tests: SERVER_TARGET := tests
tests: CLIENT_TARGET := tests
tests: all
@ pytest -n 4

# ↓ Cleaning
.PHONY: clean
Expand Down
10 changes: 8 additions & 2 deletions src/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ LDLIBS += -lmyteams
NAME ?= a.out
ASAN_NAME := asan
PROF_NAME := prof
TEST_NAME := tests

CFLAGS += -D PROG=$(NAME)

Expand Down Expand Up @@ -78,14 +79,19 @@ $(BUILD_DIR)/tests/%.o: %.c
@ $(ECHO) "[${C_BOLD}${C_RED}CC${C_RESET}] $^"
@ $(CC) -o $@ -c $< $(LDLIBS) $(CFLAGS) $(DEPS_FLAGS) || $(DIE)

$(TEST_NAME): LDLIBS += --coverage
$(TEST_NAME): $(OBJ)
@ $(ECHO) "[${C_BOLD}${C_YELLOW}CC${C_RESET}] ${C_GREEN}$@${C_RESET}"
@ $(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS) || $(DIE)

# ↓ Asan
$(BUILD_DIR)/asan/%.o: %.c
@ mkdir -p $(dir $@)
@ $(ECHO) "[${C_BOLD}${C_RED}CC${C_RESET}] $^"
@ $(CC) -o $@ -c $< $(LDLIBS) $(CFLAGS) $(DEPS_FLAGS) || $(DIE)

$(ASAN_NAME): LDFLAGS += -fsanitize=address,leak,undefined -g3
$(ASAN_NAME): LDFLAGS += -fanalyzer
$(ASAN_NAME): LDLIBS += -fsanitize=address,leak,undefined -g3
$(ASAN_NAME): LDLIBS += -fanalyzer
$(ASAN_NAME): CFLAGS += -D DEBUG_MODE
$(ASAN_NAME): $(ASAN_OBJ)
@ $(ECHO) "[${C_BOLD}${C_YELLOW}CC${C_RESET}] ${C_GREEN}$@${C_RESET}"
Expand Down

0 comments on commit 4852b28

Please sign in to comment.