[apparmor] [patch] parser tests: abort valgrind test if valgrind is missing

Steve Beattie steve at nxnw.org
Tue Mar 25 21:14:36 UTC 2014


The valgrind test script would happily chug along even if if valgrind
was not installed, not doing anything of use. This patch fixes that, and
offers up the ability to specify an alternate location for valgrind if
it does not exist in the usual /usr/bin location.

Signed-off-by: Steve Beattie <steve at nxnw.org>
---
 parser/tst/valgrind_simple.py |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

Index: b/parser/tst/valgrind_simple.py
===================================================================
--- a/parser/tst/valgrind_simple.py
+++ b/parser/tst/valgrind_simple.py
@@ -15,6 +15,7 @@
 
 from argparse import ArgumentParser  # requires python 2.7 or newer
 import os
+import sys
 import tempfile
 import unittest
 import testlib
@@ -43,7 +44,7 @@ class AAParserValgrindTests(testlib.AATe
     def _runtest(self, testname, config):
         parser_args = ['-Q', '-I', config.testdir]
         failure_rc = [VALGRIND_ERROR_CODE, testlib.TIMEOUT_ERROR_CODE]
-        command = ['valgrind']
+        command = [config.valgrind]
         command.extend(VALGRIND_ARGS)
         command.append(config.parser)
         command.extend(parser_args)
@@ -75,8 +76,11 @@ def create_suppressions():
 def main():
     rc = 0
     p = ArgumentParser()
-    p.add_argument('-p', '--parser', default=testlib.DEFAULT_PARSER, action="store", dest='parser')
+    p.add_argument('-p', '--parser', default=testlib.DEFAULT_PARSER, action="store", dest='parser',
+                   help="Specify path of apparmor parser to use [default = %(default)s]")
     p.add_argument('-v', '--verbose', action="store_true", dest="verbose")
+    p.add_argument('-V', '--valgrind', default='/usr/bin/valgrind', action="store", dest="valgrind",
+                   help="Specify path of valgrind to use [default = %(default)s]")
     p.add_argument('-s', '--skip-suppressions', action="store_true", dest="skip_suppressions",
                    help="Don't use valgrind suppressions to skip false positives")
     p.add_argument('--dump-suppressions', action="store_true", dest="dump_suppressions",
@@ -89,6 +93,11 @@ def main():
         print(VALGRIND_SUPPRESSIONS)
         return rc
 
+    if not os.path.exists(config.valgrind):
+        print("Unable to find valgrind at '%s', ensure that it is installed" % (config.valgrind),
+              file=sys.stderr)
+        exit(1)
+
     verbosity = 1
     if config.verbose:
         verbosity = 2

-- 
Steve Beattie
<sbeattie at ubuntu.com>
http://NxNW.org/~steve/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <https://lists.ubuntu.com/archives/apparmor/attachments/20140325/addca646/attachment.pgp>


More information about the AppArmor mailing list