selftest: Allow selftest.pl to run just some environments
authorAndrew Bartlett <abartlet@samba.org>
Mon, 27 Feb 2017 21:45:24 +0000 (10:45 +1300)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 30 Jun 2017 00:12:22 +0000 (02:12 +0200)
This makes it easier to declare that some autobuild environments
only run some selftest environments.

Signed-off-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
selftest/selftest.pl

index 6869132..38de96d 100755 (executable)
@@ -47,6 +47,8 @@ my $opt_random_order = 0;
 my $opt_one = 0;
 my @opt_exclude = ();
 my @opt_include = ();
+my @opt_exclude_env = ();
+my @opt_include_env = ();
 my $opt_testenv = 0;
 my $opt_list = 0;
 my $opt_mitkrb5 = 0;
@@ -198,6 +200,8 @@ Generic options:
  --testlist=FILE            file to read available tests from
  --exclude=FILE             Exclude tests listed in the file
  --include=FILE             Include tests listed in the file
+ --exclude-env=ENV          Exclude tests for the specified environment
+ --include-env=ENV          Include tests for the specified environment
 
 Paths:
  --prefix=DIR               prefix to run tests in [st]
@@ -243,6 +247,8 @@ my $result = GetOptions (
                'one' => \$opt_one,
                'exclude=s' => \@opt_exclude,
                'include=s' => \@opt_include,
+               'exclude-env=s' => \@opt_exclude_env,
+               'include-env=s' => \@opt_include_env,
                'srcdir=s' => \$srcdir,
                'bindir=s' => \$bindir,
                'testenv' => \$opt_testenv,
@@ -1080,12 +1086,38 @@ $envvarstr
                my $name = $$_[0];
                my $envname = $$_[1];
 
-               my $envvars = setup_env($envname, $prefix);
+               my $envvars = "SKIP";
+
+               if (@opt_include_env) {
+                   foreach my $env (@opt_include_env) {
+                       if ($envname eq $env) {
+                           $envvars = setup_env($envname, $prefix);
+                       }
+                   }
+               } elsif (@opt_exclude_env) {
+                   my $excluded = 0;
+                   foreach my $env (@opt_exclude_env) {
+                       if ($envname eq $env) {
+                           $excluded = 1;
+                       }
+                   }
+                   if ($excluded == 0) {
+                       $envvars = setup_env($envname, $prefix);
+                   }
+               } else {
+                   $envvars = setup_env($envname, $prefix);
+               }
+               
                if (not defined($envvars)) {
                        Subunit::start_testsuite($name);
                        Subunit::end_testsuite($name, "error",
                                "unable to set up environment $envname - exiting");
                        next;
+               } elsif ($envvars eq "SKIP") {
+                       Subunit::start_testsuite($name);
+                       Subunit::end_testsuite($name, "skip",
+                               "environment $envname is disabled (via --exclude-env / --include-env command line options) in this test run - skipping");
+                       next;
                } elsif ($envvars eq "UNKNOWN") {
                        Subunit::start_testsuite($name);
                        Subunit::end_testsuite($name, "skip",