2007-01-12 05:33:09 +03:00
#!/usr/bin/perl
# Bootstrap Samba and run a number of tests against it.
2010-09-24 02:14:57 +04:00
# Copyright (C) 2005-2010 Jelmer Vernooij <jelmer@samba.org>
2009-02-04 13:20:14 +03:00
# Copyright (C) 2007-2009 Stefan Metzmacher <metze@samba.org>
2009-03-25 17:40:39 +03:00
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
2007-03-06 00:28:55 +03:00
= pod
= head1 NAME
selftest - Samba test runner
= head1 SYNOPSIS
selftest - - help
2009-06-04 15:49:11 +04:00
selftest [ - - srcdir = DIR ] [ - - builddir = DIR ] [ - - exeext = EXT ] [ - - target = samba4 | samba3 | win | kvm ] [ - - socket - wrapper ] [ - - quick ] [ - - exclude = FILE ] [ - - include = FILE ] [ - - one ] [ - - prefix = prefix ] [ - - 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 .
2009-01-21 12:14:29 +03:00
= item I <--exeext=EXT>
Executable extention
2007-03-06 00:28:55 +03:00
= item I <--prefix=DIR>
Change directory to run tests in . Default is 'st' .
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 .
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
2009-06-03 20:19:01 +04:00
candidates are tests that segfault the server , flip or don ' t end .
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 ;
2010-04-11 00:20:12 +04:00
use File::Temp qw( tempfile ) ;
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" ;
2010-09-14 02:22:55 +04:00
use Subunit ;
2007-03-06 00:28:55 +03:00
use SocketWrapper ;
2007-01-12 05:33:09 +03:00
2010-09-14 01:22:35 +04:00
eval {
require Time::HiRes ;
2010-10-18 20:21:12 +04:00
Time::HiRes - > import ( "time" ) ;
2010-09-14 01:22:35 +04:00
} ;
2010-10-18 20:21:12 +04:00
if ( $@ ) {
print "You don't have Time::Hires installed !\n" ;
2010-09-14 01:22:35 +04: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 ;
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 ;
2010-12-09 16:46:09 +03:00
my $ opt_list = 0 ;
2007-04-17 04:30:01 +04:00
my $ ldap = 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 ;
2010-04-08 18:16:15 +04:00
my $ opt_load_list = undef ;
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 = "." ;
2009-01-21 12:14:29 +03:00
my $ exeext = "" ;
2007-04-17 17:06:00 +04:00
my $ prefix = "./st" ;
2007-03-06 00:28:55 +03:00
2007-10-26 00:20:52 +04:00
my @ includes = ( ) ;
my @ excludes = ( ) ;
2007-03-06 00:28:55 +03:00
2010-09-28 09:40:27 +04:00
sub pipe_handler {
my $ sig = shift @ _ ;
print STDERR "Exiting early because of SIGPIPE.\n" ;
exit ( 1 ) ;
}
$ SIG { PIPE } = \ & pipe_handler ;
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 ] ) ;
2009-06-05 18:10:12 +04:00
return "" ;
2007-09-02 04:24:38 +04:00
}
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 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
{
2008-02-21 17:54:31 +03:00
my ( $ 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
}
2009-06-04 15:49:11 +04:00
sub cleanup_pcap ($$)
2007-04-19 12:04:35 +04:00
{
2009-06-04 15:49:11 +04:00
my ( $ pcap_file , $ exitcode ) = @ _ ;
2007-04-19 12:04:35 +04:00
return unless ( $ opt_socket_wrapper_pcap ) ;
return if ( $ opt_socket_wrapper_keep_pcap ) ;
2009-06-04 15:49:11 +04:00
return unless ( $ exitcode == 0 ) ;
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
}
2010-01-11 01:36:48 +03:00
# expand strings from %ENV
sub expand_environment_strings ($)
{
my $ s = shift ;
# we use a reverse sort so we do the longer ones first
foreach my $ k ( sort { $ b cmp $ a } keys % ENV ) {
$ s =~ s/\$$k/$ENV{$k}/g ;
}
return $ s ;
}
2010-04-11 00:20:12 +04:00
sub run_testsuite ($$$$$)
2007-08-12 05:49:38 +04:00
{
2010-04-11 00:20:12 +04:00
my ( $ envname , $ name , $ cmd , $ i , $ totalsuites ) = @ _ ;
2007-12-20 19:07:21 +03:00
my $ pcap_file = setup_pcap ( $ name ) ;
2007-08-12 05:49:38 +04:00
2009-06-05 18:10:12 +04:00
Subunit:: start_testsuite ( $ name ) ;
2010-03-30 16:42:23 +04:00
Subunit:: progress_push ( ) ;
2009-06-17 23:37:49 +04:00
Subunit:: report_time ( time ( ) ) ;
2010-09-22 22:30:34 +04:00
system ( $ cmd ) ;
Subunit:: report_time ( time ( ) ) ;
Subunit:: progress_pop ( ) ;
2007-08-12 05:49:38 +04:00
2010-09-22 22:30:34 +04:00
if ( $? == - 1 ) {
2010-03-30 16:30:08 +04:00
Subunit:: progress_pop ( ) ;
2010-09-22 22:30:34 +04:00
Subunit:: end_testsuite ( $ name , "error" , "Unable to run $cmd: $!" ) ;
2010-10-19 07:49:17 +04:00
exit ( 1 ) ;
2010-09-22 22:30:34 +04:00
} elsif ( $? & 127 ) {
Subunit:: end_testsuite ( $ name , "error" ,
sprintf ( "%s died with signal %d, %s coredump\n" , $ cmd , ( $? & 127 ) , ( $? & 128 ) ? 'with' : 'without' ) ) ;
2010-09-24 02:14:57 +04:00
exit ( 1 ) ;
2008-04-16 01:52:06 +04:00
}
2010-09-22 22:30:34 +04:00
my $ exitcode = $? >> 8 ;
2007-12-20 17:54:02 +03:00
my $ envlog = getlog_env ( $ envname ) ;
2009-06-04 15:49:11 +04:00
if ( $ envlog ne "" ) {
2009-06-04 19:30:23 +04:00
print "envlog: $envlog\n" ;
2009-06-04 15:49:11 +04:00
}
2007-12-20 17:54:05 +03:00
2009-06-04 19:30:23 +04:00
print "command: $cmd\n" ;
2010-01-11 01:36:48 +03:00
printf "expanded command: %s\n" , expand_environment_strings ( $ cmd ) ;
2007-04-19 12:04:35 +04:00
2009-06-04 15:49:11 +04:00
if ( $ exitcode == 0 ) {
2009-06-05 18:32:52 +04:00
Subunit:: end_testsuite ( $ name , "success" ) ;
2007-12-20 17:54:02 +03:00
} else {
2009-06-05 18:32:52 +04:00
Subunit:: end_testsuite ( $ name , "failure" , "Exit code was $exitcode" ) ;
2007-12-20 17:54:02 +03:00
}
2007-04-19 12:04:35 +04:00
2009-06-04 15:49:11 +04:00
cleanup_pcap ( $ pcap_file , $ exitcode ) ;
2007-08-12 04:50:25 +04:00
2008-04-16 01:52:06 +04:00
if ( not $ opt_socket_wrapper_keep_pcap and defined ( $ pcap_file ) ) {
2009-06-04 15:49:11 +04:00
print "PCAP FILE: $pcap_file\n" ;
2007-08-12 04:50:25 +04:00
}
2007-04-19 12:04:35 +04:00
2009-06-04 15:49:11 +04:00
if ( $ exitcode != 0 ) {
2007-03-06 00:28:55 +03:00
exit ( 1 ) if ( $ opt_one ) ;
2007-01-12 05:33:09 +03:00
}
2007-04-18 04:12:39 +04:00
2009-06-04 15:49:11 +04:00
return $ exitcode ;
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>
2009-02-04 13:20:14 +03:00
Copyright ( C ) Stefan Metzmacher <metze\@samba.org>
2007-01-13 19:08:58 +03:00
2008-10-19 16:50:25 +04:00
Usage: $ Script [ OPTIONS ] TESTNAME - REGEX
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
2008-10-19 16:50:25 +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 [ . ]
2009-01-21 12:14:29 +03:00
- - exeext = EXT executable extention []
2007-03-06 00:28:55 +03:00
Target Specific:
2008-10-19 16:50:25 +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
2008-10-21 19:48:05 +04:00
- - bindir = PATH path to target binaries
2007-04-18 04:12:39 +04:00
Samba4 Specific:
2008-10-19 16:50:25 +04:00
- - ldap = openldap | fedora - ds back samba onto specified ldap server
2007-03-06 00:28:55 +03:00
2008-02-19 04:44:31 +03:00
Kvm Specific:
2008-02-19 17:12:57 +03:00
- - image = PATH path to KVM image
2008-02-19 04:44:31 +03:00
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
- - verbose be verbose
2010-12-09 15:37:13 +03:00
- - testenv run a shell in the requested test environment
2010-12-09 16:46:09 +03:00
- - list list available tests
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 ,
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 ,
2009-01-21 12:14:29 +03:00
'exeext=s' = > \ $ exeext ,
2007-03-07 05:11:40 +03:00
'verbose' = > \ $ opt_verbose ,
2007-03-21 18:57:07 +03:00
'testenv' = > \ $ opt_testenv ,
2010-12-09 16:46:09 +03:00
'list' = > \ $ opt_list ,
2007-04-17 04:30:01 +04:00
'ldap:s' = > \ $ ldap ,
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 ,
2008-02-19 04:44:31 +03:00
'image=s' = > \ $ opt_image ,
2010-04-08 18:16:15 +04:00
'testlist=s' = > \ @ testlists ,
'load-list=s' = > \ $ opt_load_list ,
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
2010-12-09 16:46:09 +03:00
die ( "--list and --testenv are mutually exclusive" ) if ( $ opt_list and $ opt_testenv ) ;
2009-11-16 18:34:13 +03:00
# we want unbuffered output
$| = 1 ;
2009-08-14 07:04:21 +04:00
my @ tests = @ ARGV ;
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
}
2009-10-22 04:04:40 +04:00
# make all our python scripts unbuffered
$ ENV { PYTHONUNBUFFERED } = 1 ;
2009-02-02 14:43:20 +03:00
my $ bindir = ( $ opt_bindir or "$builddir/bin" ) ;
my $ bindir_abs = abs_path ( $ bindir ) ;
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 ) ;
2010-10-01 05:31:06 +04:00
my $ tmpdir_abs = abs_path ( "$prefix/tmp" ) ;
mkdir ( $ tmpdir_abs , 0777 ) unless - d $ tmpdir_abs ;
2007-04-17 17:06:00 +04:00
my $ srcdir_abs = abs_path ( $ srcdir ) ;
2009-02-03 18:19:46 +03:00
my $ builddir_abs = abs_path ( $ builddir ) ;
2007-04-17 17:06:00 +04:00
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 ;
2009-02-03 18:19:46 +03:00
$ ENV { BUILDDIR } = $ builddir ;
$ ENV { BUILDDIR_ABS } = $ builddir_abs ;
$ ENV { EXEEXT } = $ exeext ;
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" ) ;
2010-10-30 04:29:49 +04:00
2008-05-23 17:20:32 +04:00
sub prefix_pathvar ($$)
{
my ( $ name , $ newpath ) = @ _ ;
if ( defined ( $ ENV { $ name } ) ) {
$ ENV { $ name } = "$newpath:$ENV{$name}" ;
} else {
$ ENV { $ name } = $ newpath ;
}
2007-12-17 13:12:26 +03:00
}
2009-02-02 14:43:20 +03:00
prefix_pathvar ( "PKG_CONFIG_PATH" , "$bindir_abs/pkgconfig" ) ;
prefix_pathvar ( "PYTHONPATH" , "$bindir_abs/python" ) ;
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 ) {
2010-01-19 02:55:48 +03:00
$ socket_wrapper_dir = SocketWrapper:: setup_dir ( "$prefix_abs/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 {
2008-10-20 14:09:36 +04:00
unless ( $< == 0 ) {
print "WARNING: Not using socket wrapper, but also not running as root. Will not be able to listen on proper ports\n" ;
}
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" ) {
2010-02-19 07:56:30 +03:00
$ testenv_default = "all" ;
2008-01-16 23:30:58 +03:00
require target::Samba4 ;
2009-02-02 14:43:20 +03:00
$ target = new Samba4 ( $ bindir , $ ldap , "$srcdir/setup" , $ exeext ) ;
2007-03-21 18:57:07 +03:00
} elsif ( $ opt_target eq "samba3" ) {
2008-10-21 19:48:05 +04:00
if ( $ opt_socket_wrapper and `$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...." ) ;
}
2009-01-28 23:01:04 +03:00
$ testenv_default = "member" ;
2008-01-16 23:30:58 +03:00
require target::Samba3 ;
2008-10-21 19:48:05 +04:00
$ target = new Samba3 ( $ 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" ) {
2008-02-19 18:28:32 +03:00
die ( "Kvm tests will not run with socket wrapper enabled." )
if ( $ opt_socket_wrapper ) ;
2008-02-19 04:44:31 +03:00
require target::Kvm ;
die ( "No image specified" ) unless ( $ opt_image ) ;
2008-02-19 23:51:09 +03:00
$ target = new Kvm ( $ opt_image , undef ) ;
2007-01-12 05:33:09 +03:00
}
2008-02-20 00:04:26 +03:00
#
# Start a Virtual Distributed Ethernet Switch
# Returns the pid of the switch.
#
sub start_vde_switch ($)
{
my ( $ path ) = @ _ ;
system ( "vde_switch --pidfile $path/vde.pid --sock $path/vde.sock --daemon" ) ;
open ( PID , "$path/vde.pid" ) ;
<PID> =~ /([0-9]+)/ ;
my $ pid = $ 1 ;
close ( PID ) ;
return $ pid ;
}
# Stop a Virtual Distributed Ethernet Switch
sub stop_vde_switch ($)
{
my ( $ pid ) = @ _ ;
kill 9 , $ pid ;
}
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 ;
2008-05-29 20:17:42 +04:00
next if ( /^#/ ) ;
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 ;
}
2007-10-26 00:20:52 +04:00
foreach ( @ opt_exclude ) {
push ( @ excludes , read_test_regexes ( $ _ ) ) ;
}
foreach ( @ opt_include ) {
push ( @ includes , read_test_regexes ( $ _ ) ) ;
2007-03-06 01:24:21 +03:00
}
2010-06-16 13:02:48 +04:00
my $ interfaces = join ( ',' , ( "127.0.0.11/8" ,
"127.0.0.12/8" ,
"127.0.0.13/8" ,
"127.0.0.14/8" ,
"127.0.0.15/8" ,
"127.0.0.16/8" ) ) ;
2007-01-12 05:33:09 +03:00
2010-09-23 12:42:57 +04:00
my $ clientdir = "$prefix_abs/client" ;
my $ conffile = "$clientdir/client.conf" ;
2008-10-20 12:53:26 +04:00
$ ENV { SMB_CONF_PATH } = $ conffile ;
2007-04-11 00:19:31 +04:00
2010-09-23 12:42:57 +04:00
sub write_clientconf ($$$)
2007-04-11 00:19:31 +04:00
{
2010-09-23 12:42:57 +04:00
my ( $ conffile , $ clientdir , $ vars ) = @ _ ;
2007-04-11 00:19:31 +04:00
2010-09-23 12:42:57 +04:00
mkdir ( "$clientdir" , 0777 ) unless - d "$clientdir" ;
2010-09-04 20:24:02 +04:00
2010-09-23 12:42:57 +04:00
if ( - d "$clientdir/private" ) {
unlink <$clientdir/private/*> ;
2007-04-11 16:10:40 +04:00
} else {
2010-09-23 12:42:57 +04:00
mkdir ( "$clientdir/private" , 0777 ) ;
2007-04-11 16:10:40 +04:00
}
2010-09-23 12:42:57 +04:00
if ( - d "$clientdir/lockdir" ) {
unlink <$clientdir/lockdir/*> ;
2009-01-28 13:59:26 +03:00
} else {
2010-09-23 12:42:57 +04:00
mkdir ( "$clientdir/lockdir" , 0777 ) ;
2009-01-28 13:59:26 +03:00
}
2010-09-23 12:42:57 +04:00
if ( - d "$clientdir/ncalrpcdir" ) {
unlink <$clientdir/ncalrpcdir/*> ;
2009-05-01 20:18:31 +04:00
} else {
2010-09-23 12:42:57 +04:00
mkdir ( "$clientdir/ncalrpcdir" , 0777 ) ;
2009-05-01 20:18:31 +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" ;
}
2008-02-19 20:03:02 +03:00
if ( $ opt_socket_wrapper ) {
print CF "\tinterfaces = $interfaces\n" ;
}
2007-04-11 00:19:31 +04:00
print CF "
2010-09-23 12:42:57 +04:00
private dir = $ clientdir / private
lock dir = $ clientdir / lockdir
ncalrpc dir = $ clientdir / ncalrpcdir
2010-03-11 15:04:56 +03:00
name resolve order = bcast file
2008-10-28 14:20:59 +03:00
panic action = $ RealBin / gdb_backtrace \ % PID \ % \ % PROG \ %
2007-04-09 04:53:05 +04:00
max xmit = 32 K
notify:inotify = false
ldb:nosync = true
system : anonymous = true
2008-10-31 17:07:34 +03:00
client lanman auth = Yes
2010-09-02 10:46:20 +04:00
log level = 1
2010-09-23 12:42:57 +04:00
torture:basedir = $ clientdir
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
2010-01-11 01:29:29 +03:00
setup directory = . / setup
2010-03-11 15:04:56 +03:00
resolv:host file = $ prefix_abs / dns_host_file
2010-09-23 11:32:46 +04:00
#We don't want to run 'speed' tests for very long
torture:timelimit = 1
2007-04-09 04:53:05 +04:00
" ;
2007-04-11 00:19:31 +04:00
close ( CF ) ;
}
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-04-04 16:23:10 +04:00
2009-08-14 07:04:21 +04:00
sub should_run_test ($)
{
my $ name = shift ;
if ( $# tests == - 1 ) {
return 1 ;
}
for ( my $ i = 0 ; $ i <= $# tests ; $ i + + ) {
if ( $ name =~ /$tests[$i]/i ) {
return 1 ;
}
}
return 0 ;
}
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> ) {
2010-09-22 07:58:23 +04:00
if ( /-- TEST(-LOADLIST|-IDLIST|) --\n/ ) {
2010-04-12 18:11:31 +04:00
my $ supports_loadlist = ( defined ( $ 1 ) and $ 1 eq "-LOADLIST" ) ;
2010-09-22 07:36:50 +04:00
my $ supports_idlist = ( defined ( $ 1 ) and $ 1 eq "-IDLIST" ) ;
2007-09-02 15:16:16 +04:00
my $ name = <IN> ;
$ name =~ s/\n//g ;
my $ env = <IN> ;
$ env =~ s/\n//g ;
my $ cmdline = <IN> ;
$ cmdline =~ s/\n//g ;
2009-08-14 07:04:21 +04:00
if ( should_run_test ( $ name ) == 1 ) {
2010-09-22 07:36:50 +04:00
push ( @ ret , [ $ name , $ env , $ cmdline , $ supports_loadlist , $ supports_idlist ] ) ;
2007-09-02 15:16:16 +04:00
}
} 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
2008-10-19 18:07:00 +04:00
$ ENV { SELFTEST_PREFIX } = "$prefix_abs" ;
2010-10-01 05:31:06 +04:00
$ ENV { SELFTEST_TMPDIR } = "$tmpdir_abs" ;
2010-12-27 14:57:18 +03:00
$ ENV { TEST_DATA_PREFIX } = "$tmpdir_abs" ;
2008-10-19 18:07:00 +04:00
if ( $ opt_socket_wrapper ) {
$ ENV { SELFTEST_INTERFACES } = $ interfaces ;
} else {
$ ENV { SELFTEST_INTERFACES } = "" ;
}
if ( $ opt_verbose ) {
$ ENV { SELFTEST_VERBOSE } = "1" ;
} else {
$ ENV { SELFTEST_VERBOSE } = "" ;
}
if ( $ opt_quick ) {
$ ENV { SELFTEST_QUICK } = "1" ;
} else {
$ ENV { SELFTEST_QUICK } = "" ;
}
$ ENV { SELFTEST_TARGET } = $ opt_target ;
$ ENV { SELFTEST_MAXTIME } = $ torture_maxtime ;
2007-12-20 17:54:05 +03:00
my @ available = ( ) ;
foreach my $ fn ( @ testlists ) {
foreach ( read_testlist ( $ fn ) ) {
my $ name = $$ _ [ 0 ] ;
2009-06-05 18:10:12 +04:00
next if ( @ includes and not defined ( find_in_list ( \ @ includes , $ name ) ) ) ;
2007-12-20 17:54:05 +03:00
push ( @ available , $ _ ) ;
}
}
2010-04-08 18:16:15 +04:00
my $ restricted = undef ;
2010-09-05 05:16:48 +04:00
my $ restricted_used = { } ;
2010-04-08 18:16:15 +04:00
if ( $ opt_load_list ) {
$ restricted = [] ;
open ( LOAD_LIST , "<$opt_load_list" ) or die ( "Unable to open $opt_load_list" ) ;
2010-09-05 04:20:56 +04:00
while ( <LOAD_LIST> ) {
chomp ;
2010-04-08 18:16:15 +04:00
push ( @$ restricted , $ _ ) ;
}
close ( LOAD_LIST ) ;
}
my $ individual_tests = undef ;
$ individual_tests = { } ;
foreach my $ testsuite ( @ available ) {
my $ name = $$ testsuite [ 0 ] ;
2007-12-20 17:54:05 +03:00
my $ skipreason = skip ( $ name ) ;
2010-09-23 06:28:02 +04:00
if ( defined ( $ restricted ) ) {
2010-04-08 18:16:15 +04:00
# Find the testsuite for this test
2010-09-05 05:16:48 +04:00
my $ match = undef ;
2010-04-08 18:16:15 +04:00
foreach my $ r ( @$ restricted ) {
if ( $ r eq $ name ) {
$ individual_tests - > { $ name } = [] ;
2010-09-05 05:16:48 +04:00
$ match = $ r ;
$ restricted_used - > { $ r } = 1 ;
2010-09-22 04:35:53 +04:00
} elsif ( substr ( $ r , 0 , length ( $ name ) + 1 ) eq "$name." ) {
2010-09-23 06:21:58 +04:00
push ( @ { $ individual_tests - > { $ name } } , $ r ) ;
2010-09-05 05:16:48 +04:00
$ match = $ r ;
$ restricted_used - > { $ r } = 1 ;
2010-04-08 18:16:15 +04:00
}
}
2010-09-23 06:28:02 +04:00
if ( $ match ) {
if ( defined ( $ skipreason ) ) {
Subunit:: skip_testsuite ( $ name , $ skipreason ) ;
} else {
push ( @ todo , $ testsuite ) ;
}
}
} elsif ( defined ( $ skipreason ) ) {
Subunit:: skip_testsuite ( $ name , $ skipreason ) ;
2007-12-20 17:54:05 +03:00
} else {
2010-09-23 06:28:02 +04:00
push ( @ todo , $ testsuite ) ;
2007-10-31 16:48:48 +03:00
}
2007-01-14 07:32:11 +03:00
}
2010-09-05 04:20:56 +04:00
if ( defined ( $ restricted ) ) {
foreach ( @$ restricted ) {
2010-09-05 05:16:48 +04:00
unless ( defined ( $ restricted_used - > { $ _ } ) ) {
2010-09-05 04:20:56 +04:00
print "No test or testsuite found matching $_\n" ;
}
}
} elsif ( $# todo == - 1 ) {
2007-10-08 18:57:11 +04:00
print STDERR "No tests to run\n" ;
exit ( 1 ) ;
2010-09-05 04:20:56 +04:00
}
2007-10-08 18:57:11 +04:00
2007-03-06 00:28:55 +03:00
my $ suitestotal = $# todo + 1 ;
2010-09-23 06:28:02 +04:00
Subunit:: progress ( $ suitestotal ) ;
Subunit:: report_time ( time ( ) ) ;
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
2009-01-30 10:25:27 +03:00
sub get_running_env ($)
{
my ( $ name ) = @ _ ;
my $ envname = $ name ;
$ envname =~ s/:.*// ;
return $ running_envs { $ envname } ;
}
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" ,
2010-03-12 02:36:12 +03:00
# domain member
2010-02-19 07:56:30 +03:00
"MEMBER_SERVER" ,
"MEMBER_SERVER_IP" ,
"MEMBER_NETBIOSNAME" ,
"MEMBER_NETBIOSALIAS" ,
2010-03-12 02:36:12 +03:00
# rpc proxy controller stuff
2010-02-19 07:56:30 +03:00
"RPC_PROXY_SERVER" ,
"RPC_PROXY_SERVER_IP" ,
"RPC_PROXY_NETBIOSNAME" ,
"RPC_PROXY_NETBIOSALIAS" ,
2010-03-12 02:36:12 +03:00
# domain controller stuff for Vampired DC
"VAMPIRE_DC_SERVER" ,
"VAMPIRE_DC_SERVER_IP" ,
"VAMPIRE_DC_NETBIOSNAME" ,
"VAMPIRE_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" ,
2010-06-02 17:35:33 +04:00
"USERID" ,
2007-04-28 12:48:11 +04:00
"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" ,
2010-06-02 17:35:33 +04:00
"WINBINDD_PRIV_PIPE_DIR" ,
2011-01-08 08:28:45 +03:00
"NMBD_SOCKET_DIR" ,
2010-06-02 17:35:33 +04:00
"LOCAL_PATH"
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" ) ;
} ;
2010-09-23 21:28:22 +04:00
sub setup_env ($$)
2007-04-11 00:19:31 +04:00
{
2010-09-23 21:28:22 +04:00
my ( $ name , $ prefix ) = @ _ ;
2009-01-30 10:25:27 +03:00
my $ testenv_vars = undef ;
my $ envname = $ name ;
my $ option = $ name ;
$ envname =~ s/:.*// ;
2009-01-30 12:01:48 +03:00
$ option =~ s/^[^:]*// ;
$ option =~ s/^:// ;
2009-01-30 10:25:27 +03:00
$ option = "client" if $ option eq "" ;
2007-04-09 03:55:01 +04:00
2007-04-19 19:05:59 +04:00
if ( $ envname eq "none" ) {
2009-01-30 12:29:39 +03:00
$ testenv_vars = { } ;
2009-01-30 10:25:27 +03:00
} elsif ( defined ( get_running_env ( $ envname ) ) ) {
$ testenv_vars = get_running_env ( $ envname ) ;
2007-04-19 18:54:09 +04:00
if ( not $ target - > check_env ( $ testenv_vars ) ) {
2010-09-04 23:13:37 +04:00
print $ target - > getlog_env ( $ testenv_vars ) ;
2007-04-19 18:54:09 +04:00
$ 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 ;
2009-01-30 10:25:27 +03:00
if ( $ option eq "local" ) {
SocketWrapper:: set_default_iface ( $ testenv_vars - > { SOCKET_WRAPPER_DEFAULT_IFACE } ) ;
$ ENV { SMB_CONF_PATH } = $ testenv_vars - > { SERVERCONFFILE } ;
} elsif ( $ option eq "client" ) {
2010-06-16 13:02:48 +04:00
SocketWrapper:: set_default_iface ( 11 ) ;
2010-09-23 12:42:57 +04:00
write_clientconf ( $ conffile , $ clientdir , $ testenv_vars ) ;
2009-01-30 10:25:27 +03:00
$ ENV { SMB_CONF_PATH } = $ conffile ;
} else {
die ( "Unknown option[$option] for envname[$envname]" ) ;
}
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" ) ;
2009-01-30 10:25:27 +03:00
return $ target - > getlog_env ( get_running_env ( $ envname ) ) ;
2007-04-18 18:02:26 +04:00
}
2007-04-19 18:54:09 +04:00
sub check_env ($)
{
my ( $ envname ) = @ _ ;
return 1 if ( $ envname eq "none" ) ;
2009-01-30 10:25:27 +03:00
return $ target - > check_env ( get_running_env ( $ envname ) ) ;
2007-04-19 18:54:09 +04:00
}
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" ) ;
2009-01-30 10:25:27 +03:00
$ target - > teardown_env ( get_running_env ( $ envname ) ) ;
2007-04-11 00:19:31 +04:00
delete $ running_envs { $ envname } ;
}
2007-04-16 07:16:23 +04:00
2010-03-12 02:45:16 +03:00
# This 'global' file needs to be empty when we start
unlink ( "$prefix_abs/dns_host_file" ) ;
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
2010-09-23 21:28:22 +04:00
my $ testenv_vars = setup_env ( $ testenv_name , $ prefix ) ;
2007-04-28 12:48:11 +04:00
2010-09-14 16:36:56 +04:00
die ( "Unable to setup environment $testenv_name" ) unless ( $ testenv_vars ) ;
2007-04-09 03:55:01 +04:00
$ ENV { PIDDIR } = $ testenv_vars - > { PIDDIR } ;
2010-10-03 01:23:43 +04:00
$ ENV { ENVNAME } = $ testenv_name ;
2007-04-28 12:48:11 +04:00
my $ envvarstr = exported_envvars_str ( $ testenv_vars ) ;
2010-10-03 01:23:43 +04:00
my $ term = ( $ ENV { TERMINAL } or "xterm -e" ) ;
system ( " $ term ' echo - e \ "
2007-04-28 12:48:11 +04:00
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
2008-09-24 05:16:15 +04:00
server is pid `cat \$PIDDIR/samba.pid`
2007-03-07 05:11:40 +03:00
Some useful environment variables:
TORTURE_OPTIONS = \ $ TORTURE_OPTIONS
2009-01-30 13:03:45 +03:00
SMB_CONF_PATH = \ $ SMB_CONF_PATH
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 ) ;
2010-12-09 16:46:09 +03:00
} elsif ( $ opt_list ) {
foreach ( @ todo ) {
my $ cmd = $$ _ [ 2 ] ;
my $ name = $$ _ [ 0 ] ;
my $ envname = $$ _ [ 1 ] ;
2010-12-09 17:35:23 +03:00
unless ( $ cmd =~ /\$LISTOPT/ ) {
2010-12-09 16:46:09 +03:00
warn ( "Unable to list tests in $name" ) ;
next ;
}
2010-12-11 20:21:58 +03:00
$ cmd =~ s/\$LISTOPT/--list/g ;
2010-12-09 16:46:09 +03:00
system ( $ cmd ) ;
2010-12-09 18:48:24 +03:00
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" ) ;
}
2010-12-09 16:46:09 +03:00
}
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
my $ name = $$ _ [ 0 ] ;
2007-03-21 18:57:07 +03:00
my $ envname = $$ _ [ 1 ] ;
2010-09-05 04:20:56 +04:00
2010-09-23 21:28:22 +04:00
my $ envvars = setup_env ( $ envname , $ prefix ) ;
2007-04-19 18:54:09 +04:00
if ( not defined ( $ envvars ) ) {
2010-09-14 16:36:56 +04:00
Subunit:: start_testsuite ( $ name ) ;
Subunit:: end_testsuite ( $ name , "error" ,
2010-10-19 07:49:17 +04:00
"unable to set up environment $envname - exiting" ) ;
2007-04-19 18:54:09 +04:00
next ;
}
2007-03-21 18:57:07 +03:00
2010-06-25 04:35:29 +04:00
# Generate a file with the individual tests to run, if the
# test runner for this test suite supports it.
2010-09-22 07:36:50 +04:00
if ( $ individual_tests and $ individual_tests - > { $ name } ) {
if ( $$ _ [ 3 ] ) {
my ( $ fh , $ listid_file ) = tempfile ( UNLINK = > 0 ) ;
foreach my $ test ( @ { $ individual_tests - > { $ name } } ) {
2010-09-23 06:21:58 +04:00
print $ fh substr ( $ test , length ( $ name ) + 1 ) . "\n" ;
2010-09-22 07:36:50 +04:00
}
2010-09-23 06:08:37 +04:00
$ cmd =~ s/\$LOADLIST/--load-list=$listid_file/g ;
2010-09-22 07:36:50 +04:00
} elsif ( $$ _ [ 4 ] ) {
2010-09-22 07:58:23 +04:00
$ cmd =~ s/\s+[^\s]+\s*$// ;
$ cmd . = " " . join ( ' ' , @ { $ individual_tests - > { $ name } } ) ;
2010-04-11 00:20:12 +04:00
}
}
2010-09-14 16:36:56 +04:00
run_testsuite ( $ envname , $ name , $ cmd , $ i , $ suitestotal ) ;
2007-03-21 18:57:07 +03:00
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 ) ;
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 $ _ ) ;
2009-10-19 15:58:23 +04:00
print "VALGRIND FAILURE\n" ;
$ failed + + ;
system ( "cat $_" ) ;
2007-01-12 05:33:09 +03:00
}
2009-06-04 15:49:11 +04:00
exit 0 ;