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 eafbb60
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 11 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
11 changes: 9 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
inputs.utils.lib.eachDefaultSystem (system: let
pkgs = inputs.nixpkgs.legacyPackages.${system};
cc = pkgs.gcc12;
python = pkgs.python311;

deriv = name:
pkgs.stdenv.mkDerivation rec {
Expand Down Expand Up @@ -38,14 +39,20 @@
packages =
packages.server.buildInputs
++ (with pkgs; [
python312
criterion
gcovr
valgrind
bear
gdb
]);
])
++ [python]
++ (with python.pkgs; [venvShellHook black]);
LD_LIBRARY_PATH = ["./libs/myteams"];

venvDir = ".venv";
postVenvCreation = ''
pip install -r ${./tests/requirements.txt}
'';
};

packages = {
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
3 changes: 2 additions & 1 deletion tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
pytest
pytest==8.1.1
pytest-xdist==3.5.0

0 comments on commit eafbb60

Please sign in to comment.