[apparmor] [PATCH] parser: Detect core dumps during parser tests

Tyler Hicks tyhicks at canonical.com
Wed Sep 11 08:33:59 UTC 2013


If a parser test case causes the parser to produce a core dump, the
simple.pl test runner incorrectly treats the test as a success.

This patch treats tests that cause core dumps as failures, even when the
tests are marked as #=TODO. The only way to ignore tests that fail in
this manner is with #=DISABLED.

Note that this patch changes the meaning of the $result variable.
Previously, it held a true or false status returned when closing the
apparmor_parser pipe. Now, it holds the exit status of apparmor_parser.

Signed-off-by: Tyler Hicks <tyhicks at canonical.com>
---
 parser/tst/README    |  2 +-
 parser/tst/simple.pl | 16 +++++++++++-----
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/parser/tst/README b/parser/tst/README
index 41fce42..782b8fa 100644
--- a/parser/tst/README
+++ b/parser/tst/README
@@ -65,6 +65,6 @@ The simple script looks for a few special comments in the profile,
 
   - #=DISABLED -- skips the test, and marks it as a failed TODO task.
     Useful if the particular testcase causes the parser to infinite
-    loop.
+    loop or dump core.
 
 Otherwise, the profile is passed on as-is to the subdomain parser.
diff --git a/parser/tst/simple.pl b/parser/tst/simple.pl
index f17eeca..515de76 100755
--- a/parser/tst/simple.pl
+++ b/parser/tst/simple.pl
@@ -71,7 +71,9 @@ sub test_profile {
   my $expass = 1;
   my $istodo = 0;
   my $isdisabled = 0;
-  my $result = 0;
+  my $result = 1;
+  my $signal = 0;
+  my $coredump = 0;
   my $child;
 
   $child = open(PARSER, "|-");
@@ -86,7 +88,6 @@ sub test_profile {
   # parent
   eval {
     local $SIG{ALRM} = sub {
-      $result = 1;
       kill PIPE => $child;
       $description = "$description - TESTCASE TIMED OUT";
     };
@@ -114,7 +115,10 @@ sub test_profile {
       }
     }
 
-    $result = close(PARSER);
+    close(PARSER) or ($! and die "Bail out! couldn't close parser pipe");
+    $result = $? >> 8;
+    $signal = $? & 127;
+    $coredump = $signal ? $? & 128 : 0;
     alarm 0;
   };
 
@@ -124,13 +128,15 @@ sub test_profile {
       local $TODO = "Disabled testcase.";
       ok(0, "TODO: $profile: $description");
     }
+  } elsif ($coredump) {
+    ok(0, "$profile: Produced core dump (signal $signal): $description");
   } elsif ($istodo) {
     TODO: {
       local $TODO = "Unfixed testcase.";
-      ok($expass ? $result : !$result, "TODO: $profile: $description");
+      ok($expass ? !$result : $result, "TODO: $profile: $description");
     }
   } else {
-    ok($expass ? $result : !$result, "$profile: $description");
+    ok($expass ? !$result : $result, "$profile: $description");
   }
 }
 
-- 
1.8.3.2




More information about the AppArmor mailing list