2007-01-12 05:33:09 +03:00
#!/usr/bin/perl
# Bootstrap Samba and run a number of tests against it.
# Copyright (C) 2005-2007 Jelmer Vernooij <jelmer@samba.org>
# Published under the GNU GPL, v3 or later.
2007-03-06 00:28:55 +03:00
= pod
= head1 NAME
selftest - Samba test runner
= head1 SYNOPSIS
selftest - - help
2008-02-19 04:44:31 +03:00
selftest [ - - srcdir = DIR ] [ - - builddir = DIR ] [ - - target = samba4 | samba3 | win | kvm ] [ - - socket - wrapper ] [ - - quick ] [ - - exclude = FILE ] [ - - include = FILE ] [ - - one ] [ - - prefix = prefix ] [ - - immediate ] [ - - testlist = FILE ] [ TESTS ]
2007-03-06 00:28:55 +03:00
= head1 DESCRIPTION
A simple test runner . TESTS is a regular expression with tests to run .
= head1 OPTIONS
= over 4
= item I <--help>
Show list of available options .
= item I <--srcdir=DIR>
Source directory .
= item I <--builddir=DIR>
Build directory .
= item I <--prefix=DIR>
Change directory to run tests in . Default is 'st' .
= item I <--immediate>
Show errors as soon as they happen rather than at the end of the test run .
2008-02-19 04:44:31 +03:00
= item I < - - target samba4 | samba3 | win | kvm >
2007-03-06 00:28:55 +03:00
Specify test target against which to run . Default is 'samba4' .
= item I <--quick>
Run only a limited number of tests . Intended to run in about 30 seconds on
moderately recent systems .
= item I <--socket-wrapper>
Use socket wrapper library for communication with server . Only works
when the server is running locally .
Will prevent TCP and UDP ports being opened on the local host but
( transparently ) redirects these calls to use unix domain sockets .
= item I <--expected-failures>
Specify a file containing a list of tests that are expected to fail . Failures for
these tests will be counted as successes , successes will be counted as failures .
The format for the file is , one entry per line:
2008-01-16 19:40:25 +03:00
TESTSUITE - NAME . TEST - NAME
2007-03-06 00:28:55 +03:00
2007-09-02 17:32:52 +04:00
The reason for a test can also be specified , by adding a hash sign ( #) and the reason
after the test name .
2007-10-26 00:20:52 +04:00
= item I <--exclude>
2007-03-06 01:24:21 +03:00
2007-10-26 00:20:52 +04:00
Specify a file containing a list of tests that should be skipped . Possible
candidates are tests that segfault the server , flip or don ' t end . The format of this file is the same as
2007-09-02 17:32:52 +04:00
for the - - expected - failures flag .
2007-03-06 01:24:21 +03:00
2007-10-26 00:20:52 +04:00
= item I <--include>
Specify a file containing a list of tests that should be run . Same format
as the - - exclude flag .
Not includes specified means all tests will be run .
2007-03-06 00:28:55 +03:00
= item I <--one>
Abort as soon as one test fails .
2007-09-02 17:32:52 +04:00
= item I <--testlist>
Load a list of tests from the specified location .
2007-03-06 00:28:55 +03:00
= back
= head1 ENVIRONMENT
= over 4
= item I <SMBD_VALGRIND>
= item I <TORTURE_MAXTIME>
= item I <VALGRIND>
= item I <TLS_ENABLED>
= item I <srcdir>
= back
= head1 LICENSE
selftest is licensed under the GNU General Public License L <http://www.gnu.org/licenses/gpl.html> .
= head1 AUTHOR
Jelmer Vernooij
= cut
2007-01-12 05:33:09 +03:00
use strict ;
use FindBin qw( $RealBin $Script ) ;
use File::Spec ;
2007-01-13 19:08:58 +03:00
use Getopt::Long ;
2007-01-12 05:33:09 +03:00
use POSIX ;
2007-04-17 17:06:00 +04:00
use Cwd qw( abs_path ) ;
2007-03-06 00:28:55 +03:00
use lib "$RealBin" ;
2007-08-27 19:15:38 +04:00
use Subunit qw( parse_results ) ;
2007-03-06 00:28:55 +03:00
use SocketWrapper ;
2007-01-12 05:33:09 +03:00
2007-03-06 00:28:55 +03:00
my $ opt_help = 0 ;
my $ opt_target = "samba4" ;
my $ opt_quick = 0 ;
my $ opt_socket_wrapper = 0 ;
my $ opt_socket_wrapper_pcap = undef ;
2007-04-18 04:12:39 +04:00
my $ opt_socket_wrapper_keep_pcap = undef ;
2007-03-06 00:28:55 +03:00
my $ opt_one = 0 ;
my $ opt_immediate = 0 ;
my $ opt_expected_failures = undef ;
2007-10-26 00:20:52 +04:00
my @ opt_exclude = ( ) ;
my @ opt_include = ( ) ;
2007-03-06 00:28:55 +03:00
my $ opt_verbose = 0 ;
2008-02-19 06:44:30 +03:00
my $ opt_image = undef ;
2007-03-07 05:11:40 +03:00
my $ opt_testenv = 0 ;
2007-04-17 04:30:01 +04:00
my $ ldap = undef ;
2007-03-21 18:57:07 +03:00
my $ opt_analyse_cmd = undef ;
2007-04-11 00:19:31 +04:00
my $ opt_resetup_env = undef ;
2007-04-18 04:12:39 +04:00
my $ opt_bindir = undef ;
2007-04-30 16:48:42 +04:00
my $ opt_no_lazy_setup = undef ;
2007-08-12 08:00:15 +04:00
my $ opt_format = "plain" ;
2007-10-26 00:20:52 +04:00
my @ testlists = ( ) ;
2007-01-12 05:33:09 +03:00
2007-03-06 00:28:55 +03:00
my $ srcdir = "." ;
my $ builddir = "." ;
2007-04-17 17:06:00 +04:00
my $ prefix = "./st" ;
2007-03-06 00:28:55 +03:00
my @ expected_failures = ( ) ;
2007-10-26 00:20:52 +04:00
my @ includes = ( ) ;
my @ excludes = ( ) ;
2007-03-06 00:28:55 +03:00
my $ statistics = {
SUITES_FAIL = > 0 ,
TESTS_UNEXPECTED_OK = > 0 ,
TESTS_EXPECTED_OK = > 0 ,
TESTS_UNEXPECTED_FAIL = > 0 ,
TESTS_EXPECTED_FAIL = > 0 ,
2007-08-26 23:07:46 +04:00
TESTS_ERROR = > 0 ,
TESTS_SKIP = > 0 ,
2007-03-06 00:28:55 +03:00
} ;
2007-09-02 04:24:38 +04:00
sub find_in_list ($$)
2007-01-12 05:33:09 +03:00
{
2007-09-02 04:24:38 +04:00
my ( $ list , $ fullname ) = @ _ ;
2007-01-12 05:33:09 +03:00
2007-09-02 04:24:38 +04:00
foreach ( @$ list ) {
if ( $ fullname =~ /$$_[0]/ ) {
return ( $$ _ [ 1 ] ) if ( $$ _ [ 1 ] ) ;
return "NO REASON SPECIFIED" ;
}
2007-04-18 18:18:33 +04:00
}
2007-01-12 05:33:09 +03:00
2007-09-02 04:24:38 +04:00
return undef ;
2007-03-06 00:28:55 +03:00
}
2007-09-02 04:24:38 +04:00
sub expecting_failure ($)
2007-03-06 01:24:21 +03:00
{
2007-09-02 04:24:38 +04:00
my ( $ name ) = @ _ ;
return find_in_list ( \ @ expected_failures , $ name ) ;
}
2007-04-18 18:43:05 +04:00
2007-09-02 04:24:38 +04:00
sub skip ($)
{
my ( $ name ) = @ _ ;
2007-10-26 00:20:52 +04:00
2007-10-31 16:48:48 +03:00
return find_in_list ( \ @ excludes , $ name ) ;
2007-03-06 01:24:21 +03:00
}
2007-04-18 18:02:26 +04:00
sub getlog_env ($) ;
2007-12-20 19:07:21 +03:00
sub setup_pcap ($)
2007-04-19 12:04:35 +04:00
{
2007-12-20 17:54:05 +03:00
my ( $ state , $ name ) = @ _ ;
2007-04-19 12:04:35 +04:00
return unless ( $ opt_socket_wrapper_pcap ) ;
return unless defined ( $ ENV { SOCKET_WRAPPER_PCAP_DIR } ) ;
2007-12-20 17:54:05 +03:00
my $ fname = $ name ;
2007-04-19 12:04:35 +04:00
$ fname =~ s%[^abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789\-]%_%g ;
2007-12-20 19:07:21 +03:00
my $ pcap_file = "$ENV{SOCKET_WRAPPER_PCAP_DIR}/$fname.pcap" ;
2007-04-19 12:04:35 +04:00
2007-12-20 19:07:21 +03:00
SocketWrapper:: setup_pcap ( $ pcap_file ) ;
return $ pcap_file ;
2007-04-19 12:04:35 +04:00
}
sub cleanup_pcap ($$$)
{
2007-12-20 19:07:21 +03:00
my ( $ pcap_file , $ expected_ret , $ ret ) = @ _ ;
2007-04-19 12:04:35 +04:00
return unless ( $ opt_socket_wrapper_pcap ) ;
return if ( $ opt_socket_wrapper_keep_pcap ) ;
return unless ( $ expected_ret == $ ret ) ;
2007-12-20 19:07:21 +03:00
return unless defined ( $ pcap_file ) ;
2007-04-19 12:04:35 +04:00
2007-12-20 19:07:21 +03:00
unlink ( $ pcap_file ) ;
2007-04-19 12:04:35 +04:00
}
2007-12-20 17:54:05 +03:00
sub run_testsuite ($$$$$$)
2007-08-12 05:49:38 +04:00
{
2007-12-20 17:54:05 +03:00
my ( $ envname , $ name , $ cmd , $ i , $ totalsuites , $ msg_ops ) = @ _ ;
2007-12-20 19:07:21 +03:00
my $ pcap_file = setup_pcap ( $ name ) ;
2007-08-12 05:49:38 +04:00
2007-12-20 19:07:21 +03:00
$ msg_ops - > start_test ( [] , $ name ) ;
2007-08-12 05:49:38 +04:00
2007-12-20 17:54:02 +03:00
open ( RESULT , "$cmd 2>&1|" ) ;
2007-08-27 19:15:38 +04:00
my $ expected_ret = parse_results (
2007-12-20 19:07:21 +03:00
$ msg_ops , $ statistics , * RESULT , \ & expecting_failure , [ $ name ] ) ;
2007-12-20 17:54:02 +03:00
my $ envlog = getlog_env ( $ envname ) ;
2007-12-20 19:07:21 +03:00
$ msg_ops - > output_msg ( "ENVLOG: $envlog\n" ) if ( $ envlog ne "" ) ;
2007-08-12 05:49:38 +04:00
2007-12-20 19:07:21 +03:00
$ msg_ops - > output_msg ( "CMD: $cmd\n" ) ;
2007-12-20 17:54:05 +03:00
2007-03-06 00:28:55 +03:00
my $ ret = close ( RESULT ) ;
2007-10-02 19:54:26 +04:00
$ ret = 0 unless $ ret == 1 ;
2007-04-19 12:04:35 +04:00
2007-12-20 17:54:02 +03:00
if ( $ ret == 1 ) {
2007-12-20 19:07:21 +03:00
$ msg_ops - > end_test ( [] , $ name , "success" , $ expected_ret != $ ret , undef ) ;
2007-12-20 17:54:02 +03:00
} else {
2007-12-20 19:07:21 +03:00
$ msg_ops - > end_test ( [] , $ name , "failure" , $ expected_ret != $ ret ,
2007-12-20 17:54:02 +03:00
"Returned $ret" ) ;
}
2007-04-19 12:04:35 +04:00
2007-12-20 19:07:21 +03:00
cleanup_pcap ( $ pcap_file , $ expected_ret , $ ret ) ;
2007-08-12 04:50:25 +04:00
if ( not $ opt_socket_wrapper_keep_pcap and
2007-12-20 19:07:21 +03:00
defined ( $ pcap_file ) ) {
$ msg_ops - > output_msg ( "PCAP FILE: $pcap_file\n" ) ;
2007-08-12 04:50:25 +04:00
}
2007-04-19 12:04:35 +04:00
2007-03-06 00:28:55 +03:00
if ( $ ret != $ expected_ret ) {
$ statistics - > { SUITES_FAIL } + + ;
exit ( 1 ) if ( $ opt_one ) ;
2007-01-12 05:33:09 +03:00
}
2007-04-18 04:12:39 +04:00
return ( $ ret == $ expected_ret ) ;
2007-01-12 05:33:09 +03:00
}
2007-01-13 19:08:58 +03:00
sub ShowHelp ()
{
print " Samba test runner
Copyright ( C ) Jelmer Vernooij <jelmer\@samba.org>
2007-03-06 00:28:55 +03:00
Usage: $ Script [ OPTIONS ] PREFIX
2007-01-13 19:08:58 +03:00
Generic options:
2007-01-13 23:02:10 +03:00
- - help this help page
2008-02-19 04:44:31 +03:00
- - target = samba [ 34 ] | win | kvm Samba version to target
2007-09-02 15:16:16 +04:00
- - testlist = FILE file to read available tests from
2007-03-06 00:28:55 +03:00
Paths:
- - prefix = DIR prefix to run tests in [ st ]
- - srcdir = DIR source directory [ . ]
- - builddir = DIR output directory [ . ]
Target Specific:
2007-09-28 03:44:38 +04:00
- - socket - wrapper - pcap save traffic to pcap directories
2007-04-18 04:12:39 +04:00
- - socket - wrapper - keep - pcap keep all pcap files , not just those for tests that
failed
2007-01-13 23:02:10 +03:00
- - socket - wrapper enable socket wrapper
2007-03-06 00:28:55 +03:00
- - expected - failures = FILE specify list of tests that is guaranteed to fail
2007-04-18 04:12:39 +04:00
Samba4 Specific:
2007-05-29 17:06:08 +04:00
- - ldap = openldap | fedora - ds back smbd onto specified ldap server
2007-03-06 00:28:55 +03:00
2007-04-18 04:12:39 +04:00
Samba3 Specific:
- - bindir = PATH path to binaries
2008-02-19 04:44:31 +03:00
Kvm Specific:
- - image = PATH path to KVM image
2007-03-06 00:28:55 +03:00
Behaviour:
2007-01-13 23:02:10 +03:00
- - quick run quick overall test
2007-01-14 07:32:11 +03:00
- - one abort when the first test fails
2007-03-06 00:28:55 +03:00
- - immediate print test output for failed tests during run
- - verbose be verbose
2007-03-21 19:26:25 +03:00
- - analyse - cmd CMD command to run after each test
2007-01-13 19:08:58 +03:00
" ;
exit ( 0 ) ;
}
my $ result = GetOptions (
2007-04-12 16:45:41 +04:00
'help|h|?' = > \ $ opt_help ,
2007-03-06 00:28:55 +03:00
'target=s' = > \ $ opt_target ,
'prefix=s' = > \ $ prefix ,
2007-01-13 23:02:10 +03:00
'socket-wrapper' = > \ $ opt_socket_wrapper ,
2007-04-18 04:12:39 +04:00
'socket-wrapper-pcap' = > \ $ opt_socket_wrapper_pcap ,
'socket-wrapper-keep-pcap' = > \ $ opt_socket_wrapper_keep_pcap ,
2007-01-14 07:32:11 +03:00
'quick' = > \ $ opt_quick ,
2007-03-06 00:28:55 +03:00
'one' = > \ $ opt_one ,
'immediate' = > \ $ opt_immediate ,
'expected-failures=s' = > \ $ opt_expected_failures ,
2007-10-26 00:20:52 +04:00
'exclude=s' = > \ @ opt_exclude ,
'include=s' = > \ @ opt_include ,
2007-03-06 00:28:55 +03:00
'srcdir=s' = > \ $ srcdir ,
'builddir=s' = > \ $ builddir ,
2007-03-07 05:11:40 +03:00
'verbose' = > \ $ opt_verbose ,
2007-03-21 18:57:07 +03:00
'testenv' = > \ $ opt_testenv ,
2007-04-17 04:30:01 +04:00
'ldap:s' = > \ $ ldap ,
2007-03-21 18:57:07 +03:00
'analyse-cmd=s' = > \ $ opt_analyse_cmd ,
2007-04-30 16:48:42 +04:00
'no-lazy-setup' = > \ $ opt_no_lazy_setup ,
2007-04-11 00:19:31 +04:00
'resetup-environment' = > \ $ opt_resetup_env ,
2007-04-18 04:12:39 +04:00
'bindir:s' = > \ $ opt_bindir ,
2007-08-12 08:00:15 +04:00
'format=s' = > \ $ opt_format ,
2008-02-19 04:44:31 +03:00
'image=s' = > \ $ opt_image ,
2007-10-26 00:20:52 +04:00
'testlist=s' = > \ @ testlists
2007-01-13 19:08:58 +03:00
) ;
2007-03-06 00:28:55 +03:00
exit ( 1 ) if ( not $ result ) ;
2007-01-13 19:08:58 +03:00
ShowHelp ( ) if ( $ opt_help ) ;
2007-01-12 05:33:09 +03:00
2007-03-06 00:28:55 +03:00
my $ tests = shift ;
2007-01-12 05:33:09 +03:00
2007-03-06 00:28:55 +03:00
# quick hack to disable rpc validation when using valgrind - its way too slow
unless ( defined ( $ ENV { VALGRIND } ) ) {
$ ENV { VALIDATE } = "validate" ;
2007-04-12 16:45:41 +04:00
$ ENV { MALLOC_CHECK_ } = 2 ;
2007-01-12 05:33:09 +03:00
}
2007-04-30 00:37:59 +04:00
my $ old_pwd = "$RealBin/.." ;
2007-04-17 04:30:01 +04:00
# Backwards compatibility:
if ( defined ( $ ENV { TEST_LDAP } ) and $ ENV { TEST_LDAP } eq "yes" ) {
2007-12-21 11:33:43 +03:00
if ( defined ( $ ENV { FEDORA_DS_ROOT } ) ) {
2007-05-29 17:06:08 +04:00
$ ldap = "fedora-ds" ;
2007-04-17 04:30:01 +04:00
} else {
$ ldap = "openldap" ;
}
2007-03-21 18:57:07 +03:00
}
my $ torture_maxtime = ( $ ENV { TORTURE_MAXTIME } or 1200 ) ;
if ( $ ldap ) {
# LDAP is slow
$ torture_maxtime *= 2 ;
}
2007-01-12 05:33:09 +03:00
$ prefix =~ s + // + / + ;
2007-04-17 17:06:00 +04:00
$ prefix =~ s + /./ + / + ;
$ prefix =~ s + / $+ + ;
2007-04-19 11:39:45 +04:00
die ( "using an empty prefix isn't allowed" ) unless $ prefix ne "" ;
#Ensure we have the test prefix around
2007-04-20 15:40:44 +04:00
mkdir ( $ prefix , 0777 ) unless - d $ prefix ;
2007-04-19 11:39:45 +04:00
2007-04-17 17:06:00 +04:00
my $ prefix_abs = abs_path ( $ prefix ) ;
my $ srcdir_abs = abs_path ( $ srcdir ) ;
die ( "using an empty absolute prefix isn't allowed" ) unless $ prefix_abs ne "" ;
die ( "using '/' as absolute prefix isn't allowed" ) unless $ prefix_abs ne "/" ;
2007-01-12 05:33:09 +03:00
$ ENV { PREFIX } = $ prefix ;
2008-02-08 01:47:18 +03:00
$ ENV { KRB5CCNAME } = "$prefix/krb5ticket" ;
2007-07-12 13:52:32 +04:00
$ ENV { PREFIX_ABS } = $ prefix_abs ;
2007-01-12 05:33:09 +03:00
$ ENV { SRCDIR } = $ srcdir ;
2007-07-12 13:52:32 +04:00
$ ENV { SRCDIR_ABS } = $ srcdir_abs ;
2007-01-12 05:33:09 +03:00
2007-08-12 08:00:15 +04:00
if ( defined ( $ ENV { RUN_FROM_BUILD_FARM } ) and
( $ ENV { RUN_FROM_BUILD_FARM } eq "yes" ) ) {
$ opt_format = "buildfarm" ;
}
2007-01-12 05:33:09 +03:00
2007-10-08 19:22:26 +04:00
my $ tls_enabled = not $ opt_quick ;
2007-01-12 05:33:09 +03:00
$ ENV { TLS_ENABLED } = ( $ tls_enabled ? "yes" : "no" ) ;
2007-12-04 13:56:23 +03:00
$ ENV { LDB_MODULES_PATH } = "$old_pwd/bin/modules/ldb" ;
2007-01-12 05:33:09 +03:00
$ ENV { LD_SAMBA_MODULE_PATH } = "$old_pwd/bin/modules" ;
2007-12-17 13:12:26 +03:00
if ( defined ( $ ENV { PKG_CONFIG_PATH } ) ) {
$ ENV { PKG_CONFIG_PATH } = "$old_pwd/bin/pkgconfig:$ENV{PKG_CONFIG_PATH}" ;
} else {
$ ENV { PKG_CONFIG_PATH } = "$old_pwd/bin/pkgconfig" ;
}
2007-09-01 06:33:00 +04:00
# Required for smbscript:
$ ENV { PATH } = "$old_pwd/bin:$old_pwd:$ENV{PATH}" ;
2007-01-12 05:33:09 +03:00
2007-10-12 10:08:46 +04:00
if ( $ opt_socket_wrapper_keep_pcap ) {
# Socket wrapper keep pcap implies socket wrapper pcap
$ opt_socket_wrapper_pcap = 1 ;
}
2007-04-18 04:12:39 +04:00
2007-03-06 00:28:55 +03:00
if ( $ opt_socket_wrapper_pcap ) {
# Socket wrapper pcap implies socket wrapper
$ opt_socket_wrapper = 1 ;
}
2007-01-12 05:33:09 +03:00
2007-03-06 00:28:55 +03:00
my $ socket_wrapper_dir ;
2007-04-04 18:24:44 +04:00
if ( $ opt_socket_wrapper ) {
2007-04-19 12:04:35 +04:00
$ socket_wrapper_dir = SocketWrapper:: setup_dir ( "$prefix/w" , $ opt_socket_wrapper_pcap ) ;
2007-03-06 00:28:55 +03:00
print "SOCKET_WRAPPER_DIR=$socket_wrapper_dir\n" ;
2007-04-04 16:23:10 +04:00
} else {
warn ( "Not using socket wrapper, but also not running as root. Will not be able to listen on proper ports" ) unless $< == 0 ;
2007-01-12 05:33:09 +03:00
}
2007-03-21 18:57:07 +03:00
my $ target ;
2007-09-30 13:07:07 +04:00
my $ testenv_default = "none" ;
2007-03-06 00:28:55 +03:00
2007-03-21 18:57:07 +03:00
if ( $ opt_target eq "samba4" ) {
2007-09-30 13:07:07 +04:00
$ testenv_default = "member" ;
2008-01-16 23:30:58 +03:00
require target::Samba4 ;
2007-09-01 04:36:01 +04:00
$ target = new Samba4 ( $ opt_bindir or "$srcdir/bin" , $ ldap , "$srcdir/setup" ) ;
2007-03-21 18:57:07 +03:00
} elsif ( $ opt_target eq "samba3" ) {
2007-09-01 04:36:01 +04:00
if ( $ opt_socket_wrapper and `$opt_bindir/smbd -b | grep SOCKET_WRAPPER` eq "" ) {
2007-04-18 04:12:39 +04:00
die ( "You must include --enable-socket-wrapper when compiling Samba in order to execute 'make test'. Exiting...." ) ;
}
2007-09-30 13:07:07 +04:00
$ testenv_default = "dc" ;
2008-01-16 23:30:58 +03:00
require target::Samba3 ;
2007-04-18 04:12:39 +04:00
$ target = new Samba3 ( $ opt_bindir ) ;
2007-03-21 18:57:07 +03:00
} elsif ( $ opt_target eq "win" ) {
die ( "Windows tests will not run with socket wrapper enabled." )
if ( $ opt_socket_wrapper ) ;
2007-09-30 13:07:07 +04:00
$ testenv_default = "dc" ;
2008-01-16 23:30:58 +03:00
require target::Windows ;
2007-03-21 18:57:07 +03:00
$ target = new Windows ( ) ;
2008-02-19 04:44:31 +03:00
} elsif ( $ opt_target eq "kvm" ) {
require target::Kvm ;
die ( "No image specified" ) unless ( $ opt_image ) ;
$ target = new Kvm ( $ opt_image ) ;
2007-01-12 05:33:09 +03:00
}
2007-09-02 04:24:38 +04:00
sub read_test_regexes ($)
{
my ( $ name ) = @ _ ;
my @ ret = ( ) ;
open ( LF , "<$name" ) or die ( "unable to read $name: $!" ) ;
while ( <LF> ) {
2007-03-06 00:28:55 +03:00
chomp ;
2007-10-26 23:15:04 +04:00
if ( /^(.*?)([ \t]+)\#([\t ]*)(.*?)$/ ) {
push ( @ ret , [ $ 1 , $ 4 ] ) ;
2007-09-02 04:24:38 +04:00
} else {
2007-10-26 23:15:04 +04:00
s/^(.*?)([ \t]+)\#([\t ]*)(.*?)$// ;
2007-09-02 04:24:38 +04:00
push ( @ ret , [ $ _ , undef ] ) ;
}
}
close ( LF ) ;
return @ ret ;
}
if ( defined ( $ opt_expected_failures ) ) {
@ expected_failures = read_test_regexes ( $ opt_expected_failures ) ;
2007-03-06 00:28:55 +03:00
}
2007-10-26 00:20:52 +04:00
foreach ( @ opt_exclude ) {
push ( @ excludes , read_test_regexes ( $ _ ) ) ;
}
if ( $ opt_quick ) {
push ( @ includes , read_test_regexes ( "samba4-quick" ) ) ;
}
foreach ( @ opt_include ) {
push ( @ includes , read_test_regexes ( $ _ ) ) ;
2007-03-06 01:24:21 +03:00
}
2007-03-06 00:28:55 +03:00
my $ interfaces = join ( ',' , ( "127.0.0.6/8" ,
2007-04-12 16:45:41 +04:00
"127.0.0.7/8" ,
"127.0.0.8/8" ,
"127.0.0.9/8" ,
"127.0.0.10/8" ,
"127.0.0.11/8" ) ) ;
2007-01-12 05:33:09 +03:00
2007-04-17 17:06:00 +04:00
my $ conffile = "$prefix_abs/client/client.conf" ;
2007-04-11 00:19:31 +04:00
sub write_clientconf ($$)
{
my ( $ conffile , $ vars ) = @ _ ;
2007-04-20 15:40:44 +04:00
mkdir ( "$prefix/client" , 0777 ) unless - d "$prefix/client" ;
2007-04-11 16:10:40 +04:00
if ( - d "$prefix/client/private" ) {
unlink <$prefix/client/private/*> ;
} else {
2007-04-20 15:40:44 +04:00
mkdir ( "$prefix/client/private" , 0777 ) ;
2007-04-11 16:10:40 +04:00
}
2007-04-11 00:19:31 +04:00
open ( CF , ">$conffile" ) ;
print CF "[global]\n" ;
if ( defined ( $ ENV { VALGRIND } ) ) {
print CF "\ticonv:native = true\n" ;
} else {
print CF "\ticonv:native = false\n" ;
}
2007-04-12 16:45:41 +04:00
print CF "\tnetbios name = client\n" ;
2007-04-11 00:19:31 +04:00
if ( defined ( $ vars - > { DOMAIN } ) ) {
print CF "\tworkgroup = $vars->{DOMAIN}\n" ;
}
if ( defined ( $ vars - > { REALM } ) ) {
print CF "\trealm = $vars->{REALM}\n" ;
}
if ( defined ( $ vars - > { NCALRPCDIR } ) ) {
print CF "\tncalrpc dir = $vars->{NCALRPCDIR}\n" ;
}
2007-04-11 17:01:46 +04:00
if ( defined ( $ vars - > { PIDDIR } ) ) {
print CF "\tpid directory = $vars->{PIDDIR}\n" ;
}
2007-04-11 00:19:31 +04:00
if ( defined ( $ vars - > { WINBINDD_SOCKET_DIR } ) ) {
print CF "\twinbindd socket directory = $vars->{WINBINDD_SOCKET_DIR}\n" ;
}
print CF "
2007-04-28 12:43:51 +04:00
private dir = $ prefix_abs /client/ private
2007-04-17 17:06:00 +04:00
js include = $ srcdir_abs /scripting/ libjs
2007-04-09 04:53:05 +04:00
name resolve order = bcast
2007-04-11 00:19:31 +04:00
interfaces = $ interfaces
2007-04-17 17:06:00 +04:00
panic action = $ srcdir_abs /script/g db_backtrace \ % PID \ % \ % PROG \ %
2007-04-09 04:53:05 +04:00
max xmit = 32 K
notify:inotify = false
ldb:nosync = true
system : anonymous = true
2007-04-28 12:43:51 +04:00
torture:basedir = $ prefix_abs / client
2007-04-11 16:10:40 +04:00
#We don't want to pass our self-tests if the PAC code is wrong
2007-04-09 04:53:05 +04:00
gensec:require_pac = true
2007-11-09 20:33:18 +03:00
modules dir = $ ENV { LD_SAMBA_MODULE_PATH }
2007-04-09 04:53:05 +04:00
" ;
2007-04-11 00:19:31 +04:00
close ( CF ) ;
}
2007-04-09 03:55:01 +04:00
my @ torture_options = ( ) ;
2007-04-09 04:53:05 +04:00
push ( @ torture_options , "--configfile=$conffile" ) ;
2007-01-12 05:33:09 +03:00
# ensure any one smbtorture call doesn't run too long
push ( @ torture_options , "--maximum-runtime=$torture_maxtime" ) ;
2007-01-13 19:08:58 +03:00
push ( @ torture_options , "--target=$opt_target" ) ;
2007-09-02 20:17:12 +04:00
push ( @ torture_options , "--basedir=$prefix_abs" ) ;
2007-08-12 08:00:15 +04:00
push ( @ torture_options , "--option=torture:progress=no" ) if ( $ opt_format eq "buildfarm" ) ;
2007-03-06 00:28:55 +03:00
push ( @ torture_options , "--format=subunit" ) ;
push ( @ torture_options , "--option=torture:quick=yes" ) if ( $ opt_quick ) ;
2007-01-12 05:33:09 +03:00
$ ENV { TORTURE_OPTIONS } = join ( ' ' , @ torture_options ) ;
print "OPTIONS $ENV{TORTURE_OPTIONS}\n" ;
2007-01-14 07:32:11 +03:00
my @ todo = ( ) ;
2007-01-12 05:33:09 +03:00
2007-04-30 00:37:59 +04:00
my $ testsdir = "$srcdir/selftest" ;
2007-05-01 07:26:01 +04:00
$ ENV { SMB_CONF_PATH } = "$conffile" ;
2007-04-09 16:15:56 +04:00
$ ENV { CONFIGURATION } = "--configfile=$conffile" ;
2007-04-04 16:23:10 +04:00
2007-04-30 16:48:42 +04:00
my % required_envs = ( ) ;
2007-04-11 00:19:31 +04:00
2007-09-02 15:16:16 +04:00
sub read_testlist ($)
{
my ( $ filename ) = @ _ ;
my @ ret = ( ) ;
open ( IN , $ filename ) or die ( "Unable to open $filename: $!" ) ;
while ( <IN> ) {
if ( $ _ eq "-- TEST --\n" ) {
my $ name = <IN> ;
$ name =~ s/\n//g ;
my $ env = <IN> ;
$ env =~ s/\n//g ;
my $ cmdline = <IN> ;
$ cmdline =~ s/\n//g ;
if ( not defined ( $ tests ) or $ name =~ /$tests/ ) {
$ required_envs { $ env } = 1 ;
push ( @ ret , [ $ name , $ env , $ cmdline ] ) ;
}
} else {
print ;
}
}
close ( IN ) or die ( "Error creating recipe" ) ;
return @ ret ;
}
2007-10-26 00:20:52 +04:00
if ( $# testlists == - 1 ) {
die ( "No testlists specified" ) ;
2007-03-21 18:57:07 +03:00
}
2007-09-02 15:16:16 +04:00
2007-12-20 17:54:05 +03:00
my @ available = ( ) ;
foreach my $ fn ( @ testlists ) {
foreach ( read_testlist ( $ fn ) ) {
my $ name = $$ _ [ 0 ] ;
next if ( @ includes and not find_in_list ( \ @ includes , $ name ) ) ;
push ( @ available , $ _ ) ;
}
}
2007-10-31 16:48:48 +03:00
my $ msg_ops ;
if ( $ opt_format eq "buildfarm" ) {
require output::buildfarm ;
$ msg_ops = new output:: buildfarm ( $ statistics ) ;
} elsif ( $ opt_format eq "plain" ) {
require output::plain ;
2007-12-20 17:54:05 +03:00
$ msg_ops = new output:: plain ( "$prefix/summary" , $ opt_verbose , $ opt_immediate , $ statistics , $# available + 1 ) ;
2007-10-31 16:48:48 +03:00
} elsif ( $ opt_format eq "html" ) {
require output::html ;
mkdir ( "test-results" , 0777 ) ;
$ msg_ops = new output:: html ( "test-results" , $ statistics ) ;
} else {
die ( "Invalid output format '$opt_format'" ) ;
}
2007-12-20 17:54:05 +03:00
foreach ( @ available ) {
my $ name = $$ _ [ 0 ] ;
my $ skipreason = skip ( $ name ) ;
if ( $ skipreason ) {
$ msg_ops - > skip_testsuite ( $ name , $ skipreason ) ;
} else {
push ( @ todo , $ _ ) ;
2007-10-31 16:48:48 +03:00
}
2007-01-14 07:32:11 +03:00
}
2007-10-08 18:57:11 +04:00
if ( $# todo == - 1 ) {
print STDERR "No tests to run\n" ;
exit ( 1 ) ;
}
2007-03-06 00:28:55 +03:00
my $ suitestotal = $# todo + 1 ;
2007-01-14 07:32:11 +03:00
my $ i = 0 ;
$| = 1 ;
2007-04-11 00:19:31 +04:00
my % running_envs = ( ) ;
2007-03-06 00:28:55 +03:00
2007-04-28 12:48:11 +04:00
my @ exported_envvars = (
# domain stuff
"DOMAIN" ,
"REALM" ,
2007-04-28 12:57:06 +04:00
# domain controller stuff
"DC_SERVER" ,
"DC_SERVER_IP" ,
"DC_NETBIOSNAME" ,
"DC_NETBIOSALIAS" ,
2007-04-28 12:48:11 +04:00
# server stuff
"SERVER" ,
2007-04-28 12:57:06 +04:00
"SERVER_IP" ,
2007-04-28 12:48:11 +04:00
"NETBIOSNAME" ,
2007-04-28 12:57:06 +04:00
"NETBIOSALIAS" ,
2007-04-28 12:48:11 +04:00
# user stuff
"USERNAME" ,
"PASSWORD" ,
2007-04-28 12:57:06 +04:00
"DC_USERNAME" ,
"DC_PASSWORD" ,
2007-04-28 12:48:11 +04:00
# misc stuff
2007-07-13 12:38:51 +04:00
"KRB5_CONFIG" ,
2007-10-02 19:56:33 +04:00
"WINBINDD_SOCKET_DIR" ,
"WINBINDD_PRIV_PIPE_DIR"
2007-04-28 12:48:11 +04:00
) ;
2007-09-02 21:13:56 +04:00
$ SIG { INT } = $ SIG { QUIT } = $ SIG { TERM } = sub {
my $ signame = shift ;
teardown_env ( $ _ ) foreach ( keys % running_envs ) ;
die ( "Received signal $signame" ) ;
} ;
2007-04-11 00:19:31 +04:00
sub setup_env ($)
{
my ( $ envname ) = @ _ ;
2007-04-09 03:55:01 +04:00
2007-04-11 00:19:31 +04:00
my $ testenv_vars ;
2007-04-19 19:05:59 +04:00
if ( $ envname eq "none" ) {
$ testenv_vars = { } ;
} elsif ( defined ( $ running_envs { $ envname } ) ) {
2007-04-11 00:19:31 +04:00
$ testenv_vars = $ running_envs { $ envname } ;
2007-04-19 18:54:09 +04:00
if ( not $ target - > check_env ( $ testenv_vars ) ) {
$ testenv_vars = undef ;
}
2007-04-11 00:19:31 +04:00
} else {
2007-04-11 07:45:39 +04:00
$ testenv_vars = $ target - > setup_env ( $ envname , $ prefix ) ;
2007-04-11 00:19:31 +04:00
}
2007-04-19 18:54:09 +04:00
return undef unless defined ( $ testenv_vars ) ;
2007-09-02 21:13:56 +04:00
$ running_envs { $ envname } = $ testenv_vars ;
2007-04-28 12:48:11 +04:00
SocketWrapper:: set_default_iface ( 6 ) ;
2007-04-11 00:19:31 +04:00
write_clientconf ( $ conffile , $ testenv_vars ) ;
2007-04-28 12:48:11 +04:00
foreach ( @ exported_envvars ) {
2007-04-11 00:19:31 +04:00
if ( defined ( $ testenv_vars - > { $ _ } ) ) {
$ ENV { $ _ } = $ testenv_vars - > { $ _ } ;
} else {
delete $ ENV { $ _ } ;
}
}
return $ testenv_vars ;
}
2007-04-28 12:48:11 +04:00
sub exported_envvars_str ($)
{
my ( $ testenv_vars ) = @ _ ;
my $ out = "" ;
foreach ( @ exported_envvars ) {
next unless defined ( $ testenv_vars - > { $ _ } ) ;
$ out . = $ _ . "=" . $ testenv_vars - > { $ _ } . "\n" ;
}
return $ out ;
}
2007-04-18 18:02:26 +04:00
sub getlog_env ($)
{
my ( $ envname ) = @ _ ;
return "" if ( $ envname eq "none" ) ;
return $ target - > getlog_env ( $ running_envs { $ envname } ) ;
}
2007-04-19 18:54:09 +04:00
sub check_env ($)
{
my ( $ envname ) = @ _ ;
return 1 if ( $ envname eq "none" ) ;
return $ target - > check_env ( $ running_envs { $ envname } ) ;
}
2007-04-11 00:19:31 +04:00
sub teardown_env ($)
{
my ( $ envname ) = @ _ ;
2007-04-17 04:30:01 +04:00
return if ( $ envname eq "none" ) ;
2007-04-11 00:19:31 +04:00
$ target - > teardown_env ( $ running_envs { $ envname } ) ;
delete $ running_envs { $ envname } ;
}
2007-04-16 07:16:23 +04:00
2007-04-30 16:48:42 +04:00
if ( $ opt_no_lazy_setup ) {
setup_env ( $ _ ) foreach ( keys % required_envs ) ;
}
2007-03-07 05:11:40 +03:00
if ( $ opt_testenv ) {
2007-04-28 12:48:11 +04:00
my $ testenv_name = $ ENV { SELFTEST_TESTENV } ;
2007-09-30 13:07:07 +04:00
$ testenv_name = $ testenv_default unless defined ( $ testenv_name ) ;
2007-04-28 12:48:11 +04:00
my $ testenv_vars = setup_env ( $ testenv_name ) ;
2007-04-09 03:55:01 +04:00
$ ENV { PIDDIR } = $ testenv_vars - > { PIDDIR } ;
2007-04-28 12:48:11 +04:00
my $ envvarstr = exported_envvars_str ( $ testenv_vars ) ;
2007-03-21 18:57:07 +03:00
my $ term = ( $ ENV { TERM } or "xterm" ) ;
2007-04-28 12:48:11 +04:00
system ( " $ term - e ' echo - e \ "
Welcome to the Samba4 Test environment '$testenv_name'
2007-03-07 05:11:40 +03:00
This matches the client environment used in make test
smbd is pid `cat \$PIDDIR/smbd.pid`
Some useful environment variables:
TORTURE_OPTIONS = \ $ TORTURE_OPTIONS
CONFIGURATION = \ $ CONFIGURATION
2007-04-28 12:48:11 +04:00
$ envvarstr
2007-12-22 09:47:48 +03:00
\ " && LD_LIBRARY_PATH=$ENV{LD_LIBRARY_PATH} bash'" ) ;
2007-04-28 12:48:11 +04:00
teardown_env ( $ testenv_name ) ;
2007-03-07 05:11:40 +03:00
} else {
foreach ( @ todo ) {
$ i + + ;
2007-03-21 18:57:07 +03:00
my $ cmd = $$ _ [ 2 ] ;
2007-03-07 05:11:40 +03:00
$ cmd =~ s/([\(\)])/\\$1/g ;
my $ name = $$ _ [ 0 ] ;
2007-03-21 18:57:07 +03:00
my $ envname = $$ _ [ 1 ] ;
2007-03-07 05:11:40 +03:00
2007-04-19 18:54:09 +04:00
my $ envvars = setup_env ( $ envname ) ;
if ( not defined ( $ envvars ) ) {
2007-10-26 23:15:04 +04:00
$ msg_ops - > skip_testsuite ( $ name , "unable to set up environment $envname" ) ;
2007-04-19 18:54:09 +04:00
next ;
}
2007-03-21 18:57:07 +03:00
2007-12-20 17:54:05 +03:00
run_testsuite ( $ envname , $ name , $ cmd , $ i , $ suitestotal ,
2007-09-12 03:53:25 +04:00
$ msg_ops ) ;
2007-03-21 18:57:07 +03:00
if ( defined ( $ opt_analyse_cmd ) ) {
system ( "$opt_analyse_cmd \"$name\"" ) ;
}
2007-04-11 00:19:31 +04:00
teardown_env ( $ envname ) if ( $ opt_resetup_env ) ;
2007-01-14 07:32:11 +03:00
}
2007-01-13 23:02:10 +03:00
}
2007-01-12 05:33:09 +03:00
2007-01-14 07:32:11 +03:00
print "\n" ;
2007-04-11 00:19:31 +04:00
teardown_env ( $ _ ) foreach ( keys % running_envs ) ;
$ target - > stop ( ) ;
2007-01-12 05:33:09 +03:00
2007-08-26 20:56:41 +04:00
$ msg_ops - > summary ( ) ;
2007-01-12 05:33:09 +03:00
2007-04-11 00:19:31 +04:00
my $ failed = 0 ;
2007-01-12 05:33:09 +03:00
# if there were any valgrind failures, show them
foreach ( <$prefix/valgrind.log*> ) {
next unless ( - s $ _ ) ;
system ( "grep DWARF2.CFI.reader $_ > /dev/null" ) ;
if ( $? >> 8 == 0 ) {
print "VALGRIND FAILURE\n" ;
$ failed + + ;
system ( "cat $_" ) ;
}
}
2007-08-12 08:00:15 +04:00
if ( $ opt_format eq "buildfarm" ) {
2007-08-26 20:56:41 +04:00
print "TEST STATUS: $statistics->{SUITES_FAIL}\n" ;
2007-03-06 03:45:30 +03:00
}
2007-08-26 20:56:41 +04:00
exit $ statistics - > { SUITES_FAIL } ;