~ubuntu-branches/ubuntu/wily/apparmor/wily

« back to all changes in this revision

Viewing changes to parser/tst/simple.pl

  • Committer: Bazaar Package Importer
  • Author(s): Kees Cook
  • Date: 2011-04-27 10:38:07 UTC
  • mfrom: (5.1.118 natty)
  • Revision ID: james.westby@ubuntu.com-20110427103807-ym3rhwys6o84ith0
Tags: 2.6.1-2
debian/copyright: clarify for some full organization names.

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
#
6
6
use strict;
7
7
use Getopt::Long;
8
 
use Test::More; 
 
8
use Test::More;
9
9
 
10
 
my $__VERSION__='$Id: simple.pl 270 2006-12-15 08:10:25Z steve-beattie $';
11
10
my %config;
12
11
$config{'parser'} = "/sbin/subdomain_parser";
13
12
$config{'profiledir'} = "./simple_tests/";
 
13
$config{'timeout'} = 120; # in seconds
14
14
 
15
15
my $help;
16
16
my $pwd = `pwd`;
21
21
);
22
22
 
23
23
sub usage {
24
 
  print STDERR "$__VERSION__\n";
25
24
  print STDERR "Usage $0 profile_directory\n";
26
25
  print STDERR "\tTests the subdomain parser on the given profile directory\n";
27
26
  print STDOUT "Bail out! Got the usage statement\n";
28
27
  exit 0;
29
28
}
30
 
  
 
29
 
31
30
&usage if ($help);
32
31
read_config();
33
32
 
66
65
  my $expass = 1;
67
66
  my $istodo = 0;
68
67
  my $isdisabled = 0;
69
 
 
70
 
  open(PARSER, "| $config{'parser'} -S -I $config{'includedir'} > /dev/null 2>&1") or die "Bail out! couldn't open parser";
71
 
 
72
 
  open(PROFILE, $profile) or die "Bail out! couldn't open profile $profile";
73
 
  while (<PROFILE>) {
74
 
    if (/^#=DESCRIPTION\s*(.*)/) {
75
 
      $description = $1;
76
 
    } elsif (/^#=EXRESULT\s*(\w+)/) {
77
 
      if ($1 eq "PASS") {
78
 
        $expass = 1;
79
 
      } elsif ($1 eq "FAIL") {
80
 
        $expass = 0;
 
68
  my $result = 0;
 
69
  my $child;
 
70
 
 
71
  eval {
 
72
    local $SIG{ALRM} = sub {
 
73
      $result = 1;
 
74
      kill PIPE => $child;
 
75
      $description = "$description - TESTCASE TIMED OUT";
 
76
    };
 
77
 
 
78
    alarm $config{'timeout'};
 
79
 
 
80
    $child = open(PARSER, "|-");
 
81
    if ($child == 0) {
 
82
      # child
 
83
      open(STDOUT, ">/dev/null") or die "Failed to redirect STDOUT";
 
84
      open(STDERR, ">/dev/null") or die "Failed to redirect STDERR";
 
85
      exec("$config{'parser'}", "-S", "-I", "$config{'includedir'}") or die "Bail out! couldn't open parser";
 
86
      # noreturn
 
87
    }
 
88
 
 
89
    # parent
 
90
    open(PROFILE, $profile) or die "Bail out! couldn't open profile $profile";
 
91
    while (<PROFILE>) {
 
92
      if (/^#=DESCRIPTION\s*(.*)/) {
 
93
        $description = $1;
 
94
      } elsif (/^#=EXRESULT\s*(\w+)/) {
 
95
        if ($1 eq "PASS") {
 
96
          $expass = 1;
 
97
        } elsif ($1 eq "FAIL") {
 
98
          $expass = 0;
 
99
        } else {
 
100
          die "Bail out! unknown expected result '$1' in $profile";
 
101
        }
 
102
      } elsif (/^#=TODO\s*/) {
 
103
          $istodo = 1;
 
104
      } elsif (/^#=DISABLED\s*/) {
 
105
          $isdisabled = 1;
81
106
      } else {
82
 
        die "Bail out! unknown expected result '$1' in $profile";
 
107
        print PARSER if not $isdisabled;
83
108
      }
84
 
    } elsif (/^#=TODO\s*/) {
85
 
        $istodo = 1;
86
 
    } elsif (/^#=DISABLED\s*/) {
87
 
        $isdisabled = 1;
88
 
    } else {
89
 
      print PARSER if not $isdisabled;
90
109
    }
91
 
  }
92
 
 
93
 
  my $result = close(PARSER);
 
110
 
 
111
    $result = close(PARSER);
 
112
    alarm 0;
 
113
  };
 
114
 
 
115
  alarm 0;
94
116
  if ($isdisabled) {
95
117
    TODO: {
96
118
      local $TODO = "Disabled testcase.";
107
129
}
108
130
 
109
131
 
110
 
opendir(DIR, $config{'profiledir'}) or die "Bail out! can't opendir $config{'profiledir'}: $!";
111
 
my @profiles = sort grep { /\.sd$/ && -f "$config{'profiledir'}/$_" } readdir(DIR);
112
 
closedir(DIR);
 
132
sub find_all_tests {
 
133
    my $testdir = shift;
 
134
 
 
135
    opendir(DIR, $testdir) or die "Bail out! can't opendir $testdir: $!";
 
136
    my @files = sort grep { /\.sd$/ && -f "$testdir/$_" } readdir(DIR);
 
137
    closedir(DIR);
 
138
 
 
139
    my @profiles;
 
140
    foreach my $profile (@files) {
 
141
        push (@profiles, "$testdir/$profile");
 
142
    }
 
143
 
 
144
    opendir(DIR, $testdir) or die "Bail out! can't opendir $testdir: $!";
 
145
    my @dirs = sort grep { /^[^\.]/ && -d "$testdir/$_" } readdir(DIR);
 
146
    closedir(DIR);
 
147
 
 
148
    foreach my $dir (@dirs) {
 
149
        push(@profiles, find_all_tests("$testdir/$dir"));
 
150
    }
 
151
    return @profiles;
 
152
}
 
153
 
 
154
my @profiles = find_all_tests($config{'profiledir'});
113
155
 
114
156
plan tests => scalar(@profiles);
115
157
 
116
158
foreach my $profile (@profiles) {
117
 
  test_profile ("$config{'profiledir'}/$profile");
 
159
    test_profile ("$profile");
118
160
}