2014-02-27 16:23:35 -08:00
# ----------------------------------------------------------------------
# Copyright (c) 1999, 2004-2009 NOVELL (All rights reserved)
# Copyright (c) 2010-2014 Canonical Ltd.
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of version 2 of the GNU General Public
# License published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, contact Novell, Inc.
# ----------------------------------------------------------------------
NAME = apparmor-utils
all :
COMMONDIR = ../../common/
2015-01-23 15:52:09 -08:00
i n c l u d e $( COMMONDIR ) / M a k e . r u l e s
2014-02-27 16:23:35 -08:00
2021-01-10 18:14:02 +01:00
# files that don't have 100% test coverage
2024-05-10 22:11:28 +02:00
INCOMPLETE_COVERAGE = libraries/libapparmor/swig/python/.*/LibAppArmor/LibAppArmor.py| utils/aa-logprof| utils/apparmor/aa.py| utils/apparmor/common.py| utils/apparmor/config.py| utils/apparmor/easyprof.py| utils/apparmor/fail.py| utils/apparmor/logparser.py| utils/apparmor/ui.py| minitools_test.py
2021-01-10 18:14:02 +01:00
2015-10-20 23:04:23 +02:00
i f d e f U S E _ S Y S T E M
2025-01-17 12:55:53 -08:00
LD_LIBRARY_PATH?=
PYTHONPATH?=
2017-03-02 21:21:53 +00:00
CONFDIR =
2017-03-02 21:23:32 +00:00
BASEDIR =
2017-03-02 21:24:33 +00:00
PARSER =
2015-10-20 23:04:23 +02:00
e l s e
2025-01-17 12:55:53 -08:00
LIBAPPARMOR_BASEDIR?= ../../libraries/libapparmor
PYTHON_DIST_BUILD_PATH ?= $( LIBAPPARMOR_BASEDIR) /swig/python/build/$$ ( $( PYTHON) $( LIBAPPARMOR_BASEDIR) /swig/python/test/buildpath.py)
LIBAPPARMOR_PATH?= $( LIBAPPARMOR_BASEDIR) /src/.libs/
LD_LIBRARY_PATH:= $( LD_LIBRARY_PATH) :$( LIBAPPARMOR_PATH) :$( PYTHON_DIST_BUILD_PATH)
PYTHONPATH:= $( PYTHONPATH) :..:$( PYTHON_DIST_BUILD_PATH)
2017-03-02 21:21:53 +00:00
CONFDIR = $( CURDIR)
2017-03-02 21:23:32 +00:00
BASEDIR = ../../profiles/apparmor.d
2017-03-02 21:24:33 +00:00
PARSER = ../../parser/apparmor_parser
2015-10-20 23:04:23 +02:00
e n d i f
2017-12-04 18:03:44 +00:00
.PHONY : __libapparmor __parser
2015-10-20 23:04:23 +02:00
__libapparmor :
i f n d e f U S E _ S Y S T E M
2020-07-24 00:22:25 -07:00
@if [ ! -f $( LIBAPPARMOR_PATH) libapparmor.so ] ; then \
echo " error: $( LIBAPPARMOR_PATH) libapparmor.so is missing. Pick one of these possible solutions: " 1>& 2; \
2015-10-20 23:04:23 +02:00
echo " 1) Build against the in-tree libapparmor by building it first and then trying again. See the top-level README for help." 1>& 2; \
echo " 2) Build against the system libapparmor by adding USE_SYSTEM=1 to your make command." 1>& 2; \
2017-12-04 23:28:10 +00:00
exit 1; \
2015-10-20 23:04:23 +02:00
fi
e n d i f
2017-12-04 18:03:44 +00:00
__parser :
i f n d e f U S E _ S Y S T E M
@if [ ! -f $( PARSER) ] ; then \
echo " error: $( PARSER) is missing. Pick one of these possible solutions: " 1>& 2; \
echo " 1) Test using the in-tree parser by building it first and then trying again. See the top-level README for help." 1>& 2; \
echo " 2) Test using the system parser by adding USE_SYSTEM=1 to your make command." 1>& 2; \
exit 1; \
fi
e n d i f
2024-04-30 16:46:32 -03:00
COVERAGE_OMIT = test-*.py,common_test.py,*/dist-packages/*
2014-11-04 13:01:14 -08:00
i f n e q ( $( COVERAGE_OUT ) , )
HTML_COVR_ARGS = -d $( COVERAGE_OUT)
e n d i f
2015-01-16 14:45:16 +01:00
# use make COVERAGE_IGNORE_FAILURES=true coverage to build coverage data even if some tests fail
i f e q ( $( COVERAGE_IGNORE_FAILURES ) , t r u e )
COVERAGE_IGNORE_FAILURES_CMD = true
e l s e
COVERAGE_IGNORE_FAILURES_CMD = set -e
e n d i f
2014-11-04 13:01:14 -08:00
.PHONY : clean check coverage coverage -report coverage -html
2014-02-27 16:23:35 -08:00
i f n d e f V E R B O S E
2014-11-04 13:01:14 -08:00
.SILENT : clean check .coverage coverage coverage -report coverage -html
2014-02-27 16:23:35 -08:00
e n d i f
2014-10-27 11:23:49 -07:00
2015-01-23 15:52:09 -08:00
clean :
2021-01-10 18:14:02 +01:00
rm -rf __pycache__/ .coverage htmlcov coverage-report.txt
2014-02-27 16:23:35 -08:00
2017-12-04 18:03:44 +00:00
check : __libapparmor __parser
2019-01-09 23:59:40 +01:00
export PYTHONPATH = $( PYTHONPATH) LD_LIBRARY_PATH = $( LD_LIBRARY_PATH) LC_ALL = C __AA_CONFDIR = $( CONFDIR) __AA_BASEDIR = $( BASEDIR) __AA_PARSER = $( PARSER) ; $( foreach test, $( wildcard test-*.py) , echo ; echo = = = $( test ) = = = ; $( call pyalldo, $( test ) ) )
2014-11-04 13:01:14 -08:00
2024-12-02 14:38:28 +01:00
# FIXME: passing -v to test-$*.py below makes some tests fail.
#
# This is a static pattern rule that allows running individual tests via the
# check-one-test-NAME target, where NAME matches an exciting file test-NAME.py.
# The way it is coded allows make <tab><tab> to complete it, making it easier
# to use interactively.
check-one-test-% : PYTHON ?= python 3
$(foreach t,$(wildcard test-*.py),check-one-test-$(patsubst test-%.py,%,$t)) : check -one -test -%: __libapparmor __parser
PYTHONPATH = $( PYTHONPATH) LD_LIBRARY_PATH = $( LD_LIBRARY_PATH) LC_ALL = C __AA_CONFDIR = $( CONFDIR) __AA_BASEDIR = $( BASEDIR) __AA_PARSER = $( PARSER) $( PYTHON) test-$* .py
2017-12-04 18:03:44 +00:00
.coverage : $( wildcard ../aa -* ../apparmor /*.py test -*.py ) __libapparmor __parser
2017-03-02 21:24:33 +00:00
export PYTHONPATH = $( PYTHONPATH) LD_LIBRARY_PATH = $( LD_LIBRARY_PATH) LC_ALL = C __AA_CONFDIR = $( CONFDIR) __AA_BASEDIR = $( BASEDIR) __AA_PARSER = $( PARSER) ; $( COVERAGE_IGNORE_FAILURES_CMD) ; $( foreach test, $( wildcard test-*.py) , echo ; echo = = = $( test ) = = = ; $( PYTHON) -m coverage run --branch -p $( test ) ; )
2014-11-04 13:01:14 -08:00
$( PYTHON) -m coverage combine
coverage : .coverage
coverage-report : .coverage
$( PYTHON) -m coverage report --omit= " $( COVERAGE_OMIT) "
2021-01-10 18:14:02 +01:00
coverage-regression : .coverage
$( PYTHON) -m coverage report --omit= " $( COVERAGE_OMIT) " > coverage-report.txt
2021-07-13 12:21:52 +02:00
$( PYTHON) -m coverage html --omit= " $( COVERAGE_OMIT) " $( HTML_COVR_ARGS)
2021-01-10 18:14:02 +01:00
cat coverage-report.txt
@echo 'Checking for coverage changes...'
@if grep -vE ' 100%$$|TOTAL|$(INCOMPLETE_COVERAGE)' coverage-report.txt | grep '%$$' ; then echo "ERROR: Coverage regression - the files listed above are expected to have 100% test coverage" ; exit 1; fi
@if grep -E '($(INCOMPLETE_COVERAGE)).*100%$$' coverage-report.txt ; then echo 'ERROR: Coverage improvement - the files listed above now have 100% coverage. Please adjust INCOMPLETE_COVERAGE in the Makefile!' ; exit 2; fi
@echo ' ... unchanged'
2014-11-04 13:01:14 -08:00
coverage-html : .coverage
$( PYTHON) -m coverage html --omit= " $( COVERAGE_OMIT) " $( HTML_COVR_ARGS)