summaryrefslogtreecommitdiff
path: root/source4/selftest
diff options
context:
space:
mode:
Diffstat (limited to 'source4/selftest')
-rw-r--r--source4/selftest/README81
-rw-r--r--source4/selftest/Subunit.pm15
-rw-r--r--source4/selftest/output/plain.pm3
-rwxr-xr-xsource4/selftest/selftest.pl16
4 files changed, 95 insertions, 20 deletions
diff --git a/source4/selftest/README b/source4/selftest/README
index e8e87c8b3f..f8be20a569 100644
--- a/source4/selftest/README
+++ b/source4/selftest/README
@@ -3,15 +3,70 @@
This directory contains test scripts that are useful for running a
bunch of tests all at once.
-===============
-Available tests
-===============
-The available tests are obtained from a script, usually
-selftest/samba{3,4}_tests.sh. This script should for each test output
+Available testsuites
+====================
+The available testsuites are obtained from a script, usually
+selftest/samba{3,4}_tests.sh. This script should for each testsuite output
the name of the test, the command to run and the environment that should be
-provided.
+provided. Use the included "plantest" function to generate the required output.
+
+Testsuite behaviour
+================================
+
+Exit code
+------------
+The testsuites should exit with a non-zero exit code if at least one
+test failed. Skipped tests should not influence the exit code.
+
+Output format
+-------------
+Testsuites can simply use the exit code to indicate whether all of their
+tests have succeeded or one or more have failed. It is also possible to
+provide more granular information using the Subunit protocol.
+
+This protocol works by writing simple messages to standard output. Any
+messages that can not be interpreted by this protocol are considered comments
+for the last announced test.
+
+Accepted commands are:
+
+test
+~~~~~~~~~~~~
+test: <NAME>
+
+Announce that a new test with the specified name is starting
+
+success
+~~~~~~~~~~~~~~~
+success: <NAME>
+
+Announce that the test with the specified name is done and ran successfully.
+
+failure
+~~~~~~~~~~~~~~~
+failure: <NAME>
+failure: <NAME> [ REASON ]
+
+Announce that the test with the specified name failed. Optionally, it is
+possible to specify a reason it failed.
+
+skip
+~~~~~~~~~~~~
+skip: <NAME>
+skip: <NAME> [ REASON ]
+
+Announce that the test with the specified name was skipped. Optionally a
+reason can be specified.
+
+knownfail
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+knownfail: <NAME>
+knownfail: <NAME> [ REASON ]
+
+Announce that the test with the specified name was run and failed as expected.
+Alternatively it is also possible to simply return "failure:" here but
+specify in the samba4-knownfailures file that it is failing.
-============
Environments
============
Tests often need to run against a server with particular things set up,
@@ -23,6 +78,7 @@ The following environments are currently available:
- none: No server set up, no variables set.
- dc: Domain controller set up. The following environment variables will
be set:
+
* USERNAME: Administrator user name
* PASSWORD: Administrator password
* DOMAIN: Domain name
@@ -34,6 +90,7 @@ The following environments are currently available:
- member: Domain controller and member server that is joined to it set up. The
following environment variables will be set:
+
* USERNAME: Domain administrator user name
* PASSWORD: Domain administrator password
* DOMAIN: Domain name
@@ -41,22 +98,22 @@ The following environments are currently available:
* SERVER: Name of the member server
-=============
Running tests
=============
-To run all the tests use:
+To run all the tests use::
make test
-To run a quick subset (aiming for about 1 minute of testing) run:
+To run a quick subset (aiming for about 1 minute of testing) run::
make quicktest
-To run a specific test, use this syntax
+To run a specific test, use this syntax::
make test TESTS=testname
-for example
+for example::
make test TESTS=samba4.BASE-DELETE
+
diff --git a/source4/selftest/Subunit.pm b/source4/selftest/Subunit.pm
index e5c61ca9ba..05e51da541 100644
--- a/source4/selftest/Subunit.pm
+++ b/source4/selftest/Subunit.pm
@@ -20,15 +20,22 @@ sub parse_results($$$$$)
$msg_ops->control_msg($_);
$msg_ops->start_test($open_tests, $1);
push (@$open_tests, $1);
- } elsif (/^(success|successful|failure|skip|error): (.*?)( \[)?([ \t]*)\n/) {
+ } elsif (/^(success|successful|failure|skip|knownfail|error): (.*?)( \[)?([ \t]*)\n/) {
$msg_ops->control_msg($_);
my $reason = undef;
if ($3) {
$reason = "";
# reason may be specified in next lines
+ my $terminated = 0;
while(<$fh>) {
$msg_ops->control_msg($_);
- if ($_ eq "]\n") { last; } else { $reason .= $_; }
+ if ($_ eq "]\n") { $terminated = 1; last; } else { $reason .= $_; }
+ }
+
+ unless ($terminated) {
+ $statistics->{TESTS_ERROR}++;
+ $msg_ops->end_test($open_tests, $2, $1, 1, "reason interrupted");
+ return 1;
}
}
my $result = $1;
@@ -53,6 +60,10 @@ sub parse_results($$$$$)
$msg_ops->end_test($open_tests, $2, $1, 1, $reason);
$unexpected_fail++;
}
+ } elsif ($1 eq "knownfail") {
+ pop(@$open_tests); #FIXME: Check that popped value == $2
+ $statistics->{TESTS_EXPECTED_FAIL}++;
+ $msg_ops->end_test($open_tests, $2, $1, 0, $reason);
} elsif ($1 eq "skip") {
$statistics->{TESTS_SKIP}++;
pop(@$open_tests); #FIXME: Check that popped value == $2
diff --git a/source4/selftest/output/plain.pm b/source4/selftest/output/plain.pm
index 25ff74792e..f14e26b38d 100644
--- a/source4/selftest/output/plain.pm
+++ b/source4/selftest/output/plain.pm
@@ -81,6 +81,9 @@ sub end_testsuite($$$$$)
my $out = "";
if ($unexpected) {
+ if ($result eq "success" and not defined($reason)) {
+ $reason = "Expected negative exit code, got positive exit code";
+ }
$self->output_msg("ERROR: $reason\n");
push (@{$self->{suitesfailed}}, $name);
} else {
diff --git a/source4/selftest/selftest.pl b/source4/selftest/selftest.pl
index 39a1b5a450..d6cf8d3a00 100755
--- a/source4/selftest/selftest.pl
+++ b/source4/selftest/selftest.pl
@@ -238,7 +238,13 @@ sub run_testsuite($$$$$$)
$msg_ops->start_test([], $name);
- open(RESULT, "$cmd 2>&1|");
+ unless (open(RESULT, "$cmd 2>&1|")) {
+ $statistics->{TESTS_ERROR}++;
+ $msg_ops->end_test([], $name, "error", 1, "Unable to run $cmd: $!");
+ $statistics->{SUITES_FAIL}++;
+ return 0;
+ }
+
my $expected_ret = parse_results(
$msg_ops, $statistics, *RESULT, \&expecting_failure, [$name]);
@@ -251,16 +257,14 @@ sub run_testsuite($$$$$$)
$ret = 0 unless $ret == 1;
if ($ret == 1) {
- $msg_ops->end_test([], $name, "success", $expected_ret != $ret, undef);
+ $msg_ops->end_test([], $name, "success", $expected_ret != $ret, undef);
} else {
- $msg_ops->end_test([], $name, "failure", $expected_ret != $ret,
- "Returned $ret");
+ $msg_ops->end_test([], $name, "failure", $expected_ret != $ret, "Returned $ret");
}
cleanup_pcap($pcap_file, $expected_ret, $ret);
- if (not $opt_socket_wrapper_keep_pcap and
- defined($pcap_file)) {
+ if (not $opt_socket_wrapper_keep_pcap and defined($pcap_file)) {
$msg_ops->output_msg("PCAP FILE: $pcap_file\n");
}