[apparmor] [PATCH 3/3] tests: The USE_SYSTEM make variable can control the parser to test with
Tyler Hicks
tyhicks at canonical.com
Sat Jan 11 00:50:47 UTC 2014
Use the in-tree parser, by default, or use the system parser when
USE_SYSTEM is set.
If the parser cannot be found, print an error message before running
the tests.
Signed-off-by: Tyler Hicks <tyhicks at canonical.com>
---
tests/regression/apparmor/Makefile | 55 +++++++++++++++++++++++++++-----------
1 file changed, 40 insertions(+), 15 deletions(-)
diff --git a/tests/regression/apparmor/Makefile b/tests/regression/apparmor/Makefile
index 1c4d01a..543baf7 100644
--- a/tests/regression/apparmor/Makefile
+++ b/tests/regression/apparmor/Makefile
@@ -7,6 +7,14 @@
# License.
ifdef USE_SYSTEM
+ # use the system parser
+ APPARMOR_PARSER = $(shell which apparmor_parser)
+ ifeq ($(strip $(APPARMOR_PARSER)),)
+ PARSER_ERROR_MESSAGE = Unable to find apparmor_parser installed on this \
+ system; either install the apparmor package, set the \
+ APPARMOR_PARSER variable manually, or use the in-tree parser)
+ endif
+
# use the system libapparmor headers and library
LIBAPPARMOR = $(shell if pkg-config --exists libapparmor ; then \
pkg-config --silence-errors --libs libapparmor ; \
@@ -14,22 +22,33 @@ ifdef USE_SYSTEM
echo -lapparmor ; \
fi )
ifeq ($(strip $(LIBAPPARMOR)),)
- ERROR_MESSAGE = Unable to find libapparmor installed on this system; either \
- install libapparmor devel packages, set the LIBAPPARMOR variable \
- manually, or build against in-tree libapparmor)
+ LIBAPPARMOR_ERROR_MESSAGE = Unable to find libapparmor installed on this \
+ system; either install libapparmor devel packages, set the \
+ LIBAPPARMOR variable manually, or build against in-tree \
+ libapparmor)
endif # LIBAPPARMOR not set
LDLIBS += $(LIBAPPARMOR)
else # !USE_SYSTEM
+ # use the in-tree parser
+ APPARMOR_PARSER = ../../../parser/apparmor_parser
+ ifeq ($(realpath $(APPARMOR_PARSER)),)
+ PARSER_ERROR_MESSAGE = $(APPARMOR_PARSER) is missing; either build the \
+ in-tree parser first and then try again (see the top-level README \
+ for help) or use the system parser by adding USE_SYSTEM=1 to your \
+ make command.)
+ endif
+
# use in-tree versions
LIBAPPARMOR_SRC := ../../../libraries/libapparmor/
LIBAPPARMOR_INCLUDE = $(LIBAPPARMOR_SRC)/include
LIBAPPARMOR_PATH := $(LIBAPPARMOR_SRC)/src/.libs/
ifeq ($(realpath $(LIBAPPARMOR_PATH)/libapparmor.a),)
- ERROR_MESSAGE = $(LIBAPPARMOR_PATH)/libapparmor.a is missing; either build against \
- the in-tree libapparmor by building it first and then trying again \
- (see the top-level README for help) or build against the system \
- libapparmor by adding USE_SYSTEM=1 to your make command.)
+ LIBAPPARMOR_ERROR_MESSAGE = $(LIBAPPARMOR_PATH)/libapparmor.a is missing; \
+ either build against the in-tree libapparmor by building it first \
+ and then trying again (see the top-level README for help) or build \
+ against the system libapparmor by adding USE_SYSTEM=1 to your make \
+ command.)
endif
CFLAGS += -L$(LIBAPPARMOR_PATH) -I$(LIBAPPARMOR_INCLUDE)
@@ -172,11 +191,17 @@ TESTS=access \
# Tests that can crash the kernel should be placed here
RISKY_TESTS=
-.PHONY: libapparmor_check
-.SILENT: libapparmor_check
+.PHONY: parser_check libapparmor_check
+.SILENT: parser_check libapparmor_check
+parser_check:
+ @if [ -n "$(PARSER_ERROR_MESSAGE)" ] ; then \
+ echo "$(PARSER_ERROR_MESSAGE)" 1>&2 ; \
+ return 1 ; \
+ fi
+
libapparmor_check:
- @if [ -n "$(ERROR_MESSAGE)" ] ; then \
- echo "$(ERROR_MESSAGE)" 1>&2 ; \
+ @if [ -n "$(LIBAPPARMOR_ERROR_MESSAGE)" ] ; then \
+ echo "$(LIBAPPARMOR_ERROR_MESSAGE)" 1>&2 ; \
return 1 ; \
fi
@@ -197,7 +222,7 @@ dbus_message: dbus_message.c dbus_common.o
dbus_service: dbus_message dbus_service.c dbus_common.o
${CC} ${CFLAGS} ${LDFLAGS} $(filter-out dbus_message, $^) -o dbus_service ${LDLIBS} $(shell pkg-config --cflags --libs dbus-1)
-tests: all
+tests: parser_check all
@if [ `whoami` = "root" ] ;\
then \
rc=0; \
@@ -205,7 +230,7 @@ tests: all
do \
echo ;\
echo "running $$i" ;\
- bash $$i.sh ;\
+ APPARMOR_PARSER=$(APPARMOR_PARSER) bash $$i.sh ;\
if [ $$? -ne 0 ] ; then \
rc=1;\
fi;\
@@ -216,7 +241,7 @@ tests: all
exit 1;\
fi
-alltests: all
+alltests: parser_check all
@if [ `whoami` = "root" ] ;\
then \
rc=0; \
@@ -224,7 +249,7 @@ alltests: all
do \
echo ;\
echo "running $$i" ;\
- bash $$i.sh ;\
+ APPARMOR_PARSER=$(APPARMOR_PARSER) bash $$i.sh ;\
if [ $$? -ne 0 ] ; then \
rc=1;\
fi;\
--
1.8.3.2
More information about the AppArmor
mailing list