Skip to content

Commit

Permalink
add test_valgrind. refactor Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
813gan committed Aug 19, 2024
1 parent 3e72f27 commit 73d1a48
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,27 @@ PYTHON := "python3"
ifeq ("$(EMACS)","")
EMACS := emacs
endif
CLANGFORMAT := clang-format

HARDENING_FLAGS=-fstack-protector -fstack-clash-protection -fcf-protection \
HARDENING_FLAGS := -fstack-protector -fstack-clash-protection -fcf-protection \
-D_FORTIFY_SOURCE=2 -ftrapv
OPTIMALISATION_FLAGS := -O2

ifeq ("$(BUILD)","DEBUG")
HARDENING_FLAGS=
OPTIMALISATION_FLAGS=
endif

UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S), Darwin) # Clang does not support some gcc options
GCC_NO_WARN=-Wno-unused-command-line-argument
HARDENING_FLAGS=''
HARDENING_FLAGS=
ifeq (, $(shell which ${CLANGFORMAT}))
CLANGFORMAT := true # darwin form gh CI have no clang-format
endif
endif

.PHONY: all clean test_module_assertions test test_ert test_formatting
.PHONY: all clean test_module_assertions test test_ert test_formatting test_valgrind

all: emacspy.so

Expand All @@ -27,8 +37,8 @@ emacspy.so: PKGCONFIG_PATH=$(shell ${PYTHON} -c \
emacspy.so: LIBPYTHON_NAME=$(shell ${PYTHON} -c \
'import sysconfig; print(sysconfig.get_config_var("LDLIBRARY"))')
emacspy.so: emacspy.c stub.c subinterpreter.c
gcc -O2 -fPIC -g -DCYTHON_FAST_THREAD_STATE=0 -DCYTHON_PEP489_MULTI_PHASE_INIT=0 \
-Wall -Wextra -Werror ${GCC_NO_WARN} ${HARDENING_FLAGS} \
gcc -fPIC -g -DCYTHON_FAST_THREAD_STATE=0 -DCYTHON_PEP489_MULTI_PHASE_INIT=0 \
-Wall -Wextra -Werror ${OPTIMALISATION_FLAGS} ${HARDENING_FLAGS} ${GCC_NO_WARN} \
emacspy.c stub.c \
${BLDLIBRARY} -DLIBPYTHON_NAME=$(LIBPYTHON_NAME) \
-shared $(shell pkg-config --cflags --libs $(PKGCONFIG_PATH)"/python3-embed.pc") \
Expand All @@ -44,12 +54,14 @@ test_ert: all
-f ert-run-tests-batch-and-exit

test_formatting:
ifeq ($(UNAME_S), Darwin)
true
else
clang-format --dry-run --Werror stub.c subinterpreter.c
endif
${CLANGFORMAT} --dry-run --Werror stub.c subinterpreter.c

test_module_assertions: emacspy.so
${EMACS} --batch --module-assertions --eval \
'(progn (add-to-list '\''load-path ".") (load "emacspy"))'

# Run `make clean && BUILD=DEBUG make all` first.
test_valgrind: all
valgrind --tool=memcheck --leak-check=full \
${EMACS} -batch -l tests/prepare-tests.el -l ert -l tests/test.el \
-f ert-run-tests-batch-and-exit

0 comments on commit 73d1a48

Please sign in to comment.