2007-01-12 05:33:09 +03:00
#!/usr/bin/perl
# Bootstrap Samba and run a number of tests against it.
2009-05-13 21:57:58 +04:00
# Copyright (C) 2005-2009 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 ;
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" ;
2009-06-05 16:13:07 +04:00
use Subunit ;
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 ;
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-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
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
}
2009-06-04 15:49:11 +04:00
sub run_testsuite ($$$$$)
2007-08-12 05:49:38 +04:00
{
2009-06-04 15:49:11 +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-04 15:49:11 +04:00
Subunit:: report_time ( time ( ) ) ;
2009-06-05 18:10:12 +04:00
Subunit:: start_testsuite ( $ name ) ;
2007-08-12 05:49:38 +04:00
2009-06-05 18:10:12 +04:00
system ( "$cmd 2>&1 | $RealBin/filter-subunit.pl --prefix \"$name.\"" ) ;
my $ ret = $? ;
2009-06-04 15:49:11 +04:00
if ( $ ret == - 1 ) {
2009-06-05 18:10:12 +04:00
Subunit:: end_testsuite ( $ name , "error" , "Unable to run $cmd: $!" ) ;
return 0 ;
} elsif ( $ ret & 127 ) {
Subunit:: end_testsuite ( $ name , "error" , sprintf ( "Testsuite died with signal %d, %s coredump" , ( $ ret & 127 ) , ( $ ret & 128 ) ? "with" : "without" ) ) ;
2008-04-16 01:52:06 +04:00
return 0 ;
}
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" ;
2007-04-19 12:04:35 +04:00
2009-06-04 15:49:11 +04:00
my $ exitcode = $ ret >> 8 ;
2008-04-16 02:17:03 +04:00
2009-06-04 15:49:11 +04:00
Subunit:: report_time ( time ( ) ) ;
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
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 ,
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 ,
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 ,
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
}
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 ) ;
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" ) ;
2009-02-02 14:43:20 +03:00
$ ENV { LDB_MODULES_PATH } = "$bindir_abs/modules/ldb" ;
$ ENV { LD_SAMBA_MODULE_PATH } = "$bindir_abs/modules" ;
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 ) {
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 {
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" ) {
2007-09-30 13:07:07 +04:00
$ testenv_default = "member" ;
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
}
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" ;
2008-10-20 12:53:26 +04:00
$ ENV { SMB_CONF_PATH } = $ conffile ;
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
}
2009-01-28 13:59:26 +03:00
if ( - d "$prefix/client/lock" ) {
unlink <$prefix/client/lockdir/*> ;
} else {
mkdir ( "$prefix/client/lockdir" , 0777 ) ;
}
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 "
2007-04-28 12:43:51 +04:00
private dir = $ prefix_abs /client/ private
2009-01-28 13:59:26 +03:00
lock dir = $ prefix_abs /client/ lockdir
2007-04-09 04:53:05 +04:00
name resolve order = bcast
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
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-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
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
2008-10-19 18:07:00 +04:00
$ ENV { SELFTEST_PREFIX } = "$prefix_abs" ;
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 , $ _ ) ;
}
}
2009-06-05 18:10:12 +04:00
Subunit:: testsuite_count ( $# available + 1 ) ;
2009-06-04 15:49:11 +04:00
Subunit:: report_time ( time ( ) ) ;
2007-12-20 17:54:05 +03:00
foreach ( @ available ) {
my $ name = $$ _ [ 0 ] ;
my $ skipreason = skip ( $ name ) ;
2009-06-05 18:10:12 +04:00
if ( defined ( $ skipreason ) ) {
Subunit:: skip_testsuite ( $ name , $ skipreason ) ;
2007-12-20 17:54:05 +03:00
} 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
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" ,
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 ($)
{
2009-01-30 10:25:27 +03:00
my ( $ name ) = @ _ ;
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 ) ) {
$ 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" ) {
SocketWrapper:: set_default_iface ( 6 ) ;
write_clientconf ( $ conffile , $ testenv_vars ) ;
$ 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
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
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 ) ;
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 ) ) {
2009-06-05 18:10:12 +04:00
Subunit:: skip_testsuite ( $ name ,
2009-05-13 21:57:58 +04:00
"unable to set up environment $envname" ) ;
2007-04-19 18:54:09 +04:00
next ;
}
2007-03-21 18:57:07 +03:00
2009-06-04 15:49:11 +04:00
run_testsuite ( $ envname , $ name , $ cmd , $ i , $ suitestotal ) ;
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-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 $_" ) ;
}
}
2009-06-04 15:49:11 +04:00
exit 0 ;