selinux/libsepol/tests/Makefile
Evgeny Vereshchagin ad2ff8a840 ci: run the tests under ASan/UBsan on GHActions
It was tested in https://github.com/SELinuxProject/selinux/pull/321 and
https://github.com/SELinuxProject/selinux/pull/320. In the process
it discovered a few issues all of which were fixed in
b98d3c4c53
ea539017fb
fe01a91a79
f95dbf2c74

Now that all the issues are gone it should be safe to turn it on
to make it easier to automatically catch bugs like that almost as soon as
they end up in the repository.

Signed-off-by: Evgeny Vereshchagin <evvers@ya.ru>
2022-01-06 10:34:33 -05:00

61 lines
2.1 KiB
Makefile

ENV ?= env
M4 ?= m4
MKDIR ?= mkdir
EXE ?= libsepol-tests
CFLAGS += -g3 -gdwarf-2 -O0 -Wall -W -Wundef -Wmissing-noreturn -Wmissing-format-attribute -Wno-unused-parameter -Werror
# Statically link libsepol on the assumption that we are going to
# be testing internal functions.
LIBSEPOL := ../src/libsepol.a
# In order to load source policies we need to link in the checkpolicy/checkmodule parser and util code.
# This is less than ideal, but it makes the tests easier to maintain by allowing source policies
# to be loaded directly.
CHECKPOLICY := ../../checkpolicy/
override CPPFLAGS += -I../include/ -I$(CHECKPOLICY)
# test program object files
objs := $(patsubst %.c,%.o,$(sort $(wildcard *.c)))
parserobjs := $(CHECKPOLICY)queue.o $(CHECKPOLICY)y.tab.o \
$(CHECKPOLICY)parse_util.o $(CHECKPOLICY)lex.yy.o \
$(CHECKPOLICY)policy_define.o $(CHECKPOLICY)module_compiler.o
# test policy pieces
m4support := $(wildcard policies/support/*.spt)
testsuites := $(wildcard policies/test-*)
policysrc := $(foreach path,$(testsuites),$(wildcard $(path)/*.conf))
stdpol := $(addsuffix .std,$(policysrc))
mlspol := $(addsuffix .mls,$(policysrc))
policies := $(stdpol) $(mlspol)
all: $(EXE) $(policies)
policies: $(policies)
$(EXE): $(objs) $(parserobjs) $(LIBSEPOL)
$(CC) $(LDFLAGS) $(objs) $(parserobjs) -lcunit $(LIBSEPOL) -o $@
%.conf.std: $(m4support) %.conf
$(M4) $(M4PARAMS) $^ > $@
%.conf.mls: $(m4support) %.conf
$(M4) $(M4PARAMS) -D enable_mls $^ > $@
clean:
rm -f $(objs) $(EXE)
rm -f $(policies)
rm -f policies/test-downgrade/policy.hi policies/test-downgrade/policy.lo
# mkdir is run in a clean environment created by env -i to avoid failing under ASan with:
#
# ASan runtime does not come first in initial library list;
# you should either link runtime to your application or manually preload it with LD_PRELOAD
#
# when the source code is built with ASan
test: $(EXE) $(policies)
$(ENV) -i $(MKDIR) -p policies/test-downgrade
../../checkpolicy/checkpolicy -M policies/test-cond/refpolicy-base.conf -o policies/test-downgrade/policy.hi
./$(EXE)
.PHONY: all policies clean test