selftest: Support multiple instances of $LISTOPT.
[abartlet/samba.git/.git] / selftest / selftest.pl
index 7431bed8ed8ad3eda71ef7f6df53c55ee8d7abf2..9759220c685b732d12a89ef180da6e169b93ca60 100755 (executable)
@@ -153,6 +153,7 @@ my @opt_include = ();
 my $opt_verbose = 0;
 my $opt_image = undef;
 my $opt_testenv = 0;
+my $opt_list = 0;
 my $ldap = undef;
 my $opt_resetup_env = undef;
 my $opt_bindir = undef;
@@ -253,7 +254,7 @@ sub run_testsuite($$$$$)
        if ($? == -1) {
                Subunit::progress_pop();
                Subunit::end_testsuite($name, "error", "Unable to run $cmd: $!");
-               return 0;
+               exit(1);
        } elsif ($? & 127) {
                Subunit::end_testsuite($name, "error",
                        sprintf("%s died with signal %d, %s coredump\n", $cmd, ($? & 127),  ($? & 128) ? 'with' : 'without'));
@@ -325,7 +326,8 @@ Behaviour:
  --quick                    run quick overall test
  --one                      abort when the first test fails
  --verbose                  be verbose
- --analyse-cmd CMD          command to run after each test
+ --testenv                  run a shell in the requested test environment
+ --list                     list available tests
 ";
        exit(0);
 }
@@ -346,6 +348,7 @@ my $result = GetOptions (
                'exeext=s' => \$exeext,
                'verbose' => \$opt_verbose,
                'testenv' => \$opt_testenv,
+               'list' => \$opt_list,
                'ldap:s' => \$ldap,
                'resetup-environment' => \$opt_resetup_env,
                'bindir:s' => \$opt_bindir,
@@ -358,6 +361,8 @@ exit(1) if (not $result);
 
 ShowHelp() if ($opt_help);
 
+die("--list and --testenv are mutually exclusive") if ($opt_list and $opt_testenv);
+
 # we want unbuffered output
 $| = 1;
 
@@ -420,8 +425,7 @@ $ENV{EXEEXT} = $exeext;
 
 my $tls_enabled = not $opt_quick;
 $ENV{TLS_ENABLED} = ($tls_enabled?"yes":"no");
-$ENV{LDB_MODULES_PATH} = "$bindir_abs/modules/ldb";
-$ENV{LD_SAMBA_MODULE_PATH} = "$bindir_abs/modules";
+
 sub prefix_pathvar($$)
 {
        my ($name, $newpath) = @_;
@@ -602,7 +606,6 @@ sub write_clientconf($$$)
        torture:basedir = $clientdir
 #We don't want to pass our self-tests if the PAC code is wrong
        gensec:require_pac = true
-       modules dir = $ENV{LD_SAMBA_MODULE_PATH}
        setup directory = ./setup
        resolv:host file = $prefix_abs/dns_host_file
 #We don't want to run 'speed' tests for very long
@@ -942,6 +945,32 @@ SMB_CONF_PATH=\$SMB_CONF_PATH
 $envvarstr
 \" && LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} bash'");
        teardown_env($testenv_name);
+} elsif ($opt_list) {
+       foreach (@todo) {
+               my $cmd = $$_[2];
+               my $name = $$_[0];
+               my $envname = $$_[1];
+
+               unless($cmd =~ /\$LISTOPT/) {
+                       warn("Unable to list tests in $name");
+                       next;
+               }
+
+               $cmd =~ s/\$LISTOPT/--list/g;
+
+               system($cmd);
+
+               if ($? == -1) {
+                       die("Unable to run $cmd: $!");
+               } elsif ($? & 127) {
+                       die(snprintf("%s died with signal %d, %s coredump\n", $cmd, ($? & 127),  ($? & 128) ? 'with' : 'without'));
+               }
+
+               my $exitcode = $? >> 8;
+               if ($exitcode != 0) {
+                       die("$cmd exited with exit code $exitcode");
+               }
+       }
 } else {
        foreach (@todo) {
                $i++;
@@ -953,7 +982,7 @@ $envvarstr
                if (not defined($envvars)) {
                        Subunit::start_testsuite($name);
                        Subunit::end_testsuite($name, "error",
-                               "unable to set up environment $envname");
+                               "unable to set up environment $envname - exiting");
                        next;
                }