If USE_SYSTEM is not set, the utils make check target will instruct
test-aa-easyprof.py to provide the path of the in-tree
profiles/apparmor.d directory to aa-easyprof as the parser base
directory.

If USE_SYSTEM is set, the default base directory (/etc/apparmor.d) is
used.

The test-aa-easyprof.py script receives the base path by checking the
__AA_BASEDIR environment variable. This environment variable is strictly
used by the test script and not any user-facing code so two leading
underscores were used.

Signed-off-by: Tyler Hicks <tyhi...@canonical.com>
Acked-by: Christian Boltz <appar...@cboltz.de>
Acked-by: Seth Arnold <seth.arn...@canonical.com>
---
 utils/test/Makefile            |  6 ++++--
 utils/test/test-aa-easyprof.py | 10 ++++++++++
 2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/utils/test/Makefile b/utils/test/Makefile
index 025bba4..ce08cbb 100644
--- a/utils/test/Makefile
+++ b/utils/test/Makefile
@@ -24,12 +24,14 @@ ifdef USE_SYSTEM
     LD_LIBRARY_PATH=
     PYTHONPATH=
     CONFDIR=
+    BASEDIR=
 else
     # PYTHON_DIST_BUILD_PATH based on libapparmor/swig/python/test/Makefile.am
     PYTHON_DIST_BUILD_PATH = 
../../libraries/libapparmor/swig/python/build/$$($(PYTHON) -c "import 
distutils.util; import platform; print(\"lib.%s-%s\" 
%(distutils.util.get_platform(), platform.python_version()[:3]))")
     LD_LIBRARY_PATH=../../libraries/libapparmor/src/.libs/
     PYTHONPATH=..:$(PYTHON_DIST_BUILD_PATH)
     CONFDIR=$(CURDIR)
+    BASEDIR=../../profiles/apparmor.d
 endif
 
 .PHONY: __libapparmor
@@ -64,10 +66,10 @@ clean:
        rm -rf __pycache__/ .coverage htmlcov
 
 check: __libapparmor
-       export PYTHONPATH=$(PYTHONPATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) 
LC_ALL=C __AA_CONFDIR=$(CONFDIR) ; $(foreach test, $(wildcard test-*.py), echo 
; echo === $(test) === ; $(call pyalldo, $(test)))
+       export PYTHONPATH=$(PYTHONPATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) 
LC_ALL=C __AA_CONFDIR=$(CONFDIR) __AA_BASEDIR=$(BASEDIR) ; $(foreach test, 
$(wildcard test-*.py), echo ; echo === $(test) === ; $(call pyalldo, $(test)))
 
 .coverage: $(wildcard ../aa-* ../apparmor/*.py test-*.py) __libapparmor
-       export PYTHONPATH=$(PYTHONPATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) 
LC_ALL=C __AA_CONFDIR=$(CONFDIR) ; $(COVERAGE_IGNORE_FAILURES_CMD) ; $(foreach 
test, $(wildcard test-*.py), echo ; echo === $(test) === ; $(PYTHON) -m 
coverage run --branch -p $(test); )
+       export PYTHONPATH=$(PYTHONPATH) LD_LIBRARY_PATH=$(LD_LIBRARY_PATH) 
LC_ALL=C __AA_CONFDIR=$(CONFDIR) __AA_BASEDIR=$(BASEDIR) ; 
$(COVERAGE_IGNORE_FAILURES_CMD) ; $(foreach test, $(wildcard test-*.py), echo ; 
echo === $(test) === ; $(PYTHON) -m coverage run --branch -p $(test); )
        $(PYTHON) -m coverage combine
 
 coverage: .coverage
diff --git a/utils/test/test-aa-easyprof.py b/utils/test/test-aa-easyprof.py
index 3ebfec6..8f7e916 100755
--- a/utils/test/test-aa-easyprof.py
+++ b/utils/test/test-aa-easyprof.py
@@ -163,6 +163,16 @@ TEMPLATES_DIR="%s/templates"
         self.binary = "/opt/bin/foo"
         self.full_args = ['-c', self.conffile, self.binary]
 
+        # Check __AA_BASEDIR, which may be set by the Makefile, to see if
+        # we should use a non-default base directory path to find
+        # abstraction files
+        #
+        # NOTE: Individual tests can append another --base path to the
+        #       args list and override a base path set here
+        base = os.getenv('__AA_BASEDIR')
+        if base:
+            self.full_args.append('--base=%s' % base)
+
         if debugging:
             self.full_args.append('-d')
 
-- 
2.7.4


-- 
AppArmor mailing list
AppArmor@lists.ubuntu.com
Modify settings or unsubscribe at: 
https://lists.ubuntu.com/mailman/listinfo/apparmor

Reply via email to