Browse Source

dpkg-source: Generate Testsuite-Restrictions fields from test restrictions

This information is currently only available in the Restrictions field in
the debian/tests/control file.

When dispatching tests, it might be inconvenient to have to download and
unpack the source package beforehand. Let's expose this via the .dsc in
a similar way we do for the Testsuite-Triggers field.

Closes: #847926
Based-on-patch-by: Iain Lane <laney@debian.org>
Guillem Jover 7 years ago
parent
commit
9899bdcf9b

+ 3 - 0
debian/changelog

@@ -12,6 +12,9 @@ dpkg (1.18.19) UNRELEASED; urgency=medium
   * Refactor update-alternatives pathname existence check into a new function.
   * Avoid useless repeated lstat()s in update-alternatives.
   * Only check for debian/tests/control file once in dpkg-source.
+  * Generate Testsuite-Restrictions fields from the test restrictions in
+    dpkg-source into .dsc files. Closes: #847926
+    Based on a patch by Iain Lane <laney@debian.org>.
   * Portability:
     - On GNU/Hurd try to use the new process executable name attribute from
       libps, to properly match on start-stop-daemon --exec.

+ 7 - 0
man/dsc.man

@@ -153,6 +153,13 @@ generated by this source package and meta-dependencies such as \fB@\fP or
 Rationale: this field is needed because otherwise to be able to get the
 test dependencies, each source package would need to be unpacked.
 .TP
+.BI Testsuite\-Restrictions: " name-list"
+This field declares the comma-separated union of all test restrictions
+(\fBRestrictions\fP fields in \fIdebian/tests/control\fP file).
+
+Rationale: this field is needed because otherwise to be able to get the
+test restrictions, each source package would need to be unpacked.
+.TP
 .BI Build\-Depends: " package-list"
 .TQ
 .BI Build\-Depends\-Arch: " package-list"

+ 6 - 1
scripts/Dpkg/Control/FieldsCore.pm

@@ -383,6 +383,10 @@ our %FIELDS = (
         allowed => ALL_SRC,
         separator => FIELD_SEP_COMMA,
     },
+    'Testsuite-Restrictions' => {
+        allowed => ALL_SRC,
+        separator => FIELD_SEP_COMMA,
+    },
     'Testsuite-Triggers' => {
         allowed => ALL_SRC,
         separator => FIELD_SEP_COMMA,
@@ -472,7 +476,8 @@ our %FIELD_ORDER = (
         qw(Format Source Binary Architecture Version Origin Maintainer
         Uploaders Homepage Standards-Version Vcs-Browser
         Vcs-Arch Vcs-Bzr Vcs-Cvs Vcs-Darcs Vcs-Git Vcs-Hg Vcs-Mtn
-        Vcs-Svn Testsuite Testsuite-Triggers), &field_list_src_dep(),
+        Vcs-Svn Testsuite Testsuite-Triggers Testsuite-Restrictions),
+        &field_list_src_dep(),
         qw(Package-List), @checksum_fields, qw(Files)
     ],
     CTRL_FILE_BUILDINFO() => [

+ 1 - 0
scripts/Makefile.am

@@ -326,6 +326,7 @@ test_data = \
 	t/dpkg_source/testsuite_1.dsc \
 	t/dpkg_source/testsuite_2.dsc \
 	t/dpkg_source/testsuite_3.dsc \
+	t/dpkg_source/testsuite_4.dsc \
 	t/merge_changelogs/ch-old \
 	t/merge_changelogs/ch-a \
 	t/merge_changelogs/ch-b \

+ 17 - 0
scripts/dpkg-source.pl

@@ -520,6 +520,7 @@ sub set_testsuite_fields
         $tests->load("$dir/debian/tests/control");
 
         set_testsuite_triggers_field($tests, $fields, @binarypackages);
+        set_testsuite_restrictions_field($tests, $fields);
     } elsif ($testsuite{autopkgtest}) {
         warning(g_('%s field contains value %s, but no tests control file %s'),
                 'Testsuite', 'autopkgtest', 'debian/tests/control');
@@ -550,6 +551,22 @@ sub set_testsuite_triggers_field
     $fields->{'Testsuite-Triggers'} = join ', ', sort keys %testdeps;
 }
 
+sub set_testsuite_restrictions_field
+{
+    my ($tests, $fields) = @_;
+    my %restrict;
+
+    # Never overwrite a manually defined field.
+    return if $fields->{'Testsuite-Restrictions'};
+
+    foreach my $test ($tests->get()) {
+        next unless $test->{Restrictions};
+
+        $restrict{$_} = 1 foreach (split /[,\s]+/, $test->{Restrictions});
+    }
+    $fields->{'Testsuite-Restrictions'} = join ', ', sort keys %restrict;
+}
+
 sub setopmode {
     my $opmode = shift;
 

+ 15 - 1
scripts/t/dpkg_source.t

@@ -16,7 +16,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 8;
+use Test::More tests => 10;
 use Test::Dpkg qw(test_neutralize_checksums);
 
 use File::Spec::Functions qw(rel2abs);
@@ -64,12 +64,20 @@ Architecture: all
 Description: test package
 TMPL_CONTROL
 
+my $tmpl_tests_control = <<'TMPL_TESTS_CONTROL';
+Test-Command: ${test-command}
+Depends: ${test-depends}
+Restrictions: ${test-restrictions}
+TMPL_TESTS_CONTROL
+
 my %default_substvars = (
     'source-name' => 'test-source',
     'source-version' => 0,
     'source-section' => 'test',
     'source-priority' => 'optional',
     'source-testsuite' => 'autopkgtest',
+    'test-command' => 'true',
+    'test-depends' => '@',
     'suite' => 'unstable',
     'urgency' => 'low',
     'maintainer' => 'Dpkg Developers <debian-dpkg@lists.debian.org>',
@@ -168,4 +176,10 @@ $dirname = gen_source('source-name' => 'testsuite',
                       'source-version' => 3);
 test_build_source($dirname);
 
+$dirname = gen_source('source-name' => 'testsuite',
+                      'source-version' => 4,
+                      'test-restrictions' => 'needs-root,build-needed  allow-stderr',
+                      'control-test' => $tmpl_tests_control);
+test_build_source($dirname);
+
 1;

+ 17 - 0
scripts/t/dpkg_source/testsuite_4.dsc

@@ -0,0 +1,17 @@
+Format: 3.0 (native)
+Source: testsuite
+Binary: test-binary
+Architecture: all
+Version: 4
+Maintainer: Dpkg Developers <debian-dpkg@lists.debian.org>
+Standards-Version: 1.0
+Testsuite: autopkgtest
+Testsuite-Restrictions: allow-stderr, build-needed, needs-root
+Package-List:
+ test-binary deb test optional arch=all
+Checksums-Sha1:
+ 0000000000000000000000000000000000000000 0 testsuite_4.tar.xz
+Checksums-Sha256:
+ 0000000000000000000000000000000000000000000000000000000000000000 0 testsuite_4.tar.xz
+Files:
+ 00000000000000000000000000000000 0 testsuite_4.tar.xz