[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[SCM] Debian package checker branch, master, updated. 2.5.6-60-g33acfe7



The following commit has been merged in the master branch:
commit cd472afeecedfd6e183d6f7cef3ef46f5c9de76a
Author: Niels Thykier <niels@thykier.net>
Date:   Sun Apr 1 15:37:58 2012 +0200

    t/: Add calibration hook to handle hardening flags test
    
    Signed-off-by: Niels Thykier <niels@thykier.net>

diff --git a/t/runtests b/t/runtests
index d424351..164ecf2 100755
--- a/t/runtests
+++ b/t/runtests
@@ -371,6 +371,8 @@ sub test_package {
 
     my $is_native = ($testdata->{type} eq 'native');
     my $orig_version = $testdata->{version};
+    my $expected = "$origdir/tags";
+    my $origexp = $expected;
 
     if (-f "$origdir/skip") {
         msg_print "skipped.\n";
@@ -428,7 +430,15 @@ sub test_package {
     runsystem_ok("sed -ri -f $origdir/post_test $rundir/tags.$pkg")
         if -e "$origdir/post_test";
 
-    return _check_result($testdata, "$origdir/tags", "$rundir/tags.$pkg");
+    if ( -x "$origdir/test_calibration" ) {
+        my $calibrated = "$rundir/expected.$pkg.calibrated";
+        msg_print 'running test_calibration hook... ' if $VERBOSE;
+        runsystem_ok ("$origdir/test_calibration", $expected,
+                      "$rundir/tags.$pkg", $calibrated);
+        $expected = $calibrated if -e $calibrated;
+    }
+
+    return _check_result($testdata, $expected, "$rundir/tags.$pkg", $origexp);
 }
 
 sub _builder_tests {
@@ -618,7 +628,7 @@ sub generic_test_runner {
 }
 
 sub _check_result {
-    my ($testdata, $expected, $actual) = @_;
+    my ($testdata, $expected, $actual, $origexp) = @_;
     # Compare the output to the expected tags.
     my $testok = runsystem_ok('cmp', '-s', $expected, $actual);
 
@@ -676,6 +686,31 @@ sub _check_result {
         }
         close $etags;
         if (%test_for) {
+            if ($origexp && $origexp ne $expected) {
+                # Test has been calibrated, check if some of the
+                # "Test-For" has been calibrated out.  (Happens with
+                # binaries-hardening on some architectures).
+                open my $oe, '<', $expected or fail "open $expected: $!";
+                my %cp_tf = %test_for;
+                while ( <$oe> ) {
+                    next if m/^N: /;
+                    # Some of the traversal tests are skipped; accept that in the output
+                    next if m/tainted/o && m/skipping/o;
+                    if (not /^.: \S+(?: (?:changes|source|udeb))?: (\S+)/o) {
+                        msg_print (($testdata->{'todo'} eq 'yes')? 'TODO' : 'E');
+                        msg_print ": Invalid line:\n$_";
+                        $okay = 0;
+                        next;
+                    }
+                    print STDERR "N: Kept tag: $1\n";
+                    delete $cp_tf{$1};
+                }
+                close $oe;
+                # Remove tags that has been calibrated out.
+                foreach my $tag (keys %cp_tf) {
+                    delete $test_for{$tag};
+                }
+            }
             for my $tag (sort keys %test_for) {
                 msg_print (($testdata->{'todo'} eq 'yes')? 'TODO' : 'E');
                 msg_print ": Tag $tag listed in Test-For but not found\n";
diff --git a/t/tests/README b/t/tests/README
index 3668aaa..4ed8065 100644
--- a/t/tests/README
+++ b/t/tests/README
@@ -190,6 +190,22 @@ post_test
     but it may be useful for other cases where the output of Lintian
     may change on different systems.
 
+test_calibration
+    If present and executable, this script is run after the Lintian
+    output has been generated and after post_test (if present).  The
+    script can be used to calibrate the expected output or actual
+    output.
+
+    It is useful for cases the expected output is architecture
+    dependent beyond what the post_test script can handle.
+
+    The script will be passed 3 arguments, the "expected output" file,
+    the "actual output" file and file name to write the "calibrated
+    expected output".  The script may modify the "actual output" file
+    and create the calibration file, which (if it is created) will
+    be used instead of the original "expected output" file.
+
+
 Be aware that Git doesn't track directories, only files, so any
 directory must contain at least one file to exist in a fresh Git
 checkout.  Test cases that just use the template must therefore still
diff --git a/t/tests/binaries-hardening/test_calibration b/t/tests/binaries-hardening/test_calibration
new file mode 100755
index 0000000..7d538aa
--- /dev/null
+++ b/t/tests/binaries-hardening/test_calibration
@@ -0,0 +1,47 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use lib "$ENV{LINTIAN_ROOT}/lib";
+
+use Lintian::Data;
+use Lintian::Profile;
+
+sub _split_hash {
+    my (undef, $val) = @_;
+    my $hash = {};
+    map { $hash->{$_} = 1 } split m/\s*,\s*/o, $val;
+    return $hash;
+}
+my $PROFILE = Lintian::Profile->new ('debian/main', $ENV{'LINTIAN_ROOT'},
+                                     ["$ENV{'LINTIAN_ROOT'}/profiles"]);
+
+Lintian::Data->set_vendor ($PROFILE);
+
+my $HARDENING = Lintian::Data->new ('binaries/hardening-tags', qr/\s*\|\|\s*/o, \&_split_hash);
+
+my ($expected, undef, $calibrated) = @ARGV;
+
+my $arch = `dpkg-architecture -qDEB_HOST_ARCH`;
+chomp $arch;
+
+die "Unknown architecture: $arch" unless $HARDENING->known ($arch);
+
+open my $cfd, '>', $calibrated or die "open $calibrated: $!";
+open my $efd, '<', $expected or die "open $expected: $!";
+
+while (my $line = <$efd>) {
+    my $dp = 0;
+    if ($line =~ m/^.: [^:]++: (hardening-\S+)/) {
+        # It is a hardening flag, maybe it is not for this architecture
+        $dp = 1 if $HARDENING->value ($arch)->{$1};
+    } else {
+        # only calibrate hardening flags.
+        $dp = 1;
+    }
+
+    print $cfd $line if $dp;
+}
+
+close $efd;
+close $cfd or die "close $expected: $!";
diff --git a/t/tests/runtests-calibration/desc b/t/tests/runtests-calibration/desc
new file mode 100644
index 0000000..2c262e9
--- /dev/null
+++ b/t/tests/runtests-calibration/desc
@@ -0,0 +1,4 @@
+Testname: runtests-calibration
+Sequence: 0700
+Version: 1.0
+Description: Test calibration support
diff --git a/t/tests/runtests-calibration/tags b/t/tests/runtests-calibration/tags
new file mode 100644
index 0000000..30616c5
--- /dev/null
+++ b/t/tests/runtests-calibration/tags
@@ -0,0 +1 @@
+E: runtests-calibration source: lintian-says-hi ;)
diff --git a/t/tests/runtests-calibration/test_calibration b/t/tests/runtests-calibration/test_calibration
new file mode 100755
index 0000000..817f837
--- /dev/null
+++ b/t/tests/runtests-calibration/test_calibration
@@ -0,0 +1,6 @@
+#!/bin/sh
+
+set -e
+
+echo "E: runtests-calibration source: lintian-says-goodbye" >> "$2"
+echo "E: runtests-calibration source: lintian-says-goodbye" > "$3"

-- 
Debian package checker


Reply to: