[apparmor] [PATCH 11/11] Fix the "Kernel features are written to cache:" test

John Johansen john.johansen at canonical.com
Wed Mar 7 14:17:30 UTC 2012


the cache test is failing because it assumes that kernel features are
stored in a file instead of a directory

Signed-off-by: John Johansen <john.johansen at canonical.com>
---
 parser/parser_main.c  |    2 +-
 parser/tst/caching.sh |   29 ++++++++++++++++++++++++++---
 2 files changed, 27 insertions(+), 4 deletions(-)

diff --git a/parser/parser_main.c b/parser/parser_main.c
index ea2e1ed..67ab231 100644
--- a/parser/parser_main.c
+++ b/parser/parser_main.c
@@ -768,7 +768,7 @@ static char *handle_features_dir(const char *filename, char **buffer, int size,
 
 		}
 
-		pos = snprintf_buffer(*buffer, pos, size, " }\n");
+		pos = snprintf_buffer(*buffer, pos, size, "}\n");
 	}
 	if (dirent_path)
 		free(dirent_path);
diff --git a/parser/tst/caching.sh b/parser/tst/caching.sh
index 2d3f552..ac265a9 100755
--- a/parser/tst/caching.sh
+++ b/parser/tst/caching.sh
@@ -49,11 +49,34 @@ echo -n "Profiles are cached when requested: "
 [ ! -f $basedir/cache/$profile ] && echo "FAIL ($basedir/cache/$profile does not exist)" && exit 1
 echo "ok"
 
+read_features_dir()
+{
+    directory="$1"
+    if [ ! -d "$directory" ] ; then
+	return
+    fi
+    for f in `ls -AU "$directory"` ; do
+	if [ -f "$directory/$f" ] ; then
+	    read -r -d "" KF < "$directory/$f" || true
+	    echo -e "$f {$KF\n}"
+	elif [ -d "$directory/$f" ] ; then
+	    echo -n "$f {"
+	    KF=`read_features_dir "$directory/$f" "$KF"` || true
+	    echo "$KF"
+	    echo -e "}"
+	fi
+    done
+}
+
 echo -n "Kernel features are written to cache: "
 [ ! -f $basedir/cache/.features ] && echo "FAIL ($basedir/cache/.features missing)" && exit 1
-read CF < $basedir/cache/.features || true
-read KF < /sys/kernel/security/apparmor/features || true
-[ "$CF" != "$KF" ] && echo "FAIL (feature text mismatch: cache '$CF' vs kernel '$KF')" && exit 1
+read -r -d "" CF < $basedir/cache/.features || true
+if [ -d /sys/kernel/security/apparmor/features ] ; then
+    KF=`read_features_dir /sys/kernel/security/apparmor/features`
+else
+    read -r -d "" KF < /sys/kernel/security/apparmor/features || true
+fi
+[ "$CF" != "$KF" ] && echo -e "FAIL (feature text mismatch:\n  cache '$CF'\nvs\n  kernel '$KF')" && exit 1
 echo "ok"
 
 echo -n "Cache is loaded when it exists and features match: "
-- 
1.7.9




More information about the AppArmor mailing list