2012-03-04 18:11:36 +04:00
#!/usr/bin/python -u
2012-03-04 04:24:10 +04:00
# Bootstrap Samba and run a number of tests against it.
# Copyright (C) 2005-2012 Jelmer Vernooij <jelmer@samba.org>
# Copyright (C) 2007-2009 Stefan Metzmacher <metze@samba.org>
# 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/>.
2012-03-04 19:39:43 +04:00
import atexit
2012-03-04 18:11:36 +04:00
from cStringIO import StringIO
2012-03-04 08:00:55 +04:00
import os
2012-03-04 04:24:10 +04:00
import sys
import signal
2012-03-04 18:11:36 +04:00
import subprocess
2014-12-11 05:10:53 +03:00
from samba import subunit
2012-03-04 19:22:34 +04:00
import traceback
2012-03-04 08:00:55 +04:00
import warnings
import optparse
2012-03-04 18:11:36 +04:00
sys . path . insert ( 0 , os . path . dirname ( os . path . dirname ( __file__ ) ) )
from selftest import (
socket_wrapper ,
subunithelper ,
testlist ,
)
2012-03-05 06:45:57 +04:00
from selftest . client import write_clientconf
2012-03-05 06:27:40 +04:00
from selftest . run import (
expand_command_list ,
2012-03-05 06:39:57 +04:00
expand_command_run ,
2012-03-05 06:49:50 +04:00
exported_envvars_str ,
2012-03-11 23:58:00 +04:00
now ,
run_testsuite_command ,
2012-03-05 06:27:40 +04:00
)
2012-03-04 19:22:34 +04:00
from selftest . target import (
EnvironmentManager ,
NoneTarget ,
UnsupportedEnvironment ,
)
2012-03-04 18:11:36 +04:00
2012-03-04 08:00:55 +04:00
includes = ( )
excludes = ( )
def read_excludes ( fn ) :
2012-03-04 18:11:36 +04:00
excludes . extend ( testlist . read_test_regexes ( fn ) )
2012-03-04 08:00:55 +04:00
def read_includes ( fn ) :
2012-03-04 18:11:36 +04:00
includes . extend ( testlist . read_test_regexes ( fn ) )
2012-03-04 08:00:55 +04:00
parser = optparse . OptionParser ( " TEST-REGEXES " )
2012-03-04 19:22:34 +04:00
parser . add_option ( " --target " , type = " choice " , choices = [ " samba " , " samba3 " , " none " ] , default = " samba " , help = " Samba version to target " )
2012-03-04 19:39:43 +04:00
parser . add_option ( " --quick " , help = " run quick overall test " , action = " store_true " , default = False )
parser . add_option ( " --list " , help = " list available tests " , action = " store_true " , default = False )
parser . add_option ( " --socket-wrapper " , help = " enable socket wrapper " , action = " store_true " , default = False )
2012-03-04 08:00:55 +04:00
parser . add_option ( " --socket-wrapper-pcap " , help = " save traffic to pcap directories " , type = " str " )
2012-03-04 19:39:43 +04:00
parser . add_option ( " --socket-wrapper-keep-pcap " , help = " keep all pcap files, not just those for tests that failed " , action = " store_true " , default = False )
parser . add_option ( " --one " , help = " abort when the first test fails " , action = " store_true " , default = False )
2012-03-04 08:00:55 +04:00
parser . add_option ( " --exclude " , action = " callback " , help = " Add file to exclude files " , callback = read_excludes )
parser . add_option ( " --include " , action = " callback " , help = " Add file to include files " , callback = read_includes )
2012-03-04 19:39:43 +04:00
parser . add_option ( " --testenv " , help = " run a shell in the requested test environment " , action = " store_true " , default = False )
parser . add_option ( " --resetup-environment " , help = " Re-setup environment " , action = " store_true " , default = False )
2012-03-04 08:00:55 +04:00
parser . add_option ( " --binary-mapping " , help = " Map binaries to use " , type = str )
parser . add_option ( " --load-list " , help = " Load list of tests to load from a file " , type = str )
parser . add_option ( " --prefix " , help = " prefix to run tests in " , type = str , default = " ./st " )
parser . add_option ( " --srcdir " , type = str , default = " . " , help = " source directory " )
parser . add_option ( " --bindir " , type = str , default = " ./bin " , help = " binaries directory " )
parser . add_option ( " --testlist " , type = str , action = " append " , help = " file to read available tests from " )
2012-03-04 18:11:36 +04:00
parser . add_option ( " --ldap " , help = " back samba onto specified ldap server " , choices = [ " openldap " , " fedora-ds " ] , type = " choice " )
2012-03-04 08:00:55 +04:00
opts , args = parser . parse_args ( )
2012-03-04 04:24:10 +04:00
2012-03-04 18:11:36 +04:00
subunit_ops = subunithelper . SubunitOps ( sys . stdout )
2012-03-04 19:49:30 +04:00
def handle_signal ( sig , frame ) :
sys . stderr . write ( " Exiting early because of signal %s . \n " % sig )
2012-03-04 04:24:10 +04:00
sys . exit ( 1 )
2014-07-29 12:59:43 +04:00
for sig in ( signal . SIGINT , signal . SIGQUIT , signal . SIGTERM , signal . SIGPIPE ) :
2012-03-04 19:49:30 +04:00
signal . signal ( sig , handle_signal )
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
def skip ( name ) :
2012-03-04 18:11:36 +04:00
return testlist . find_in_list ( excludes , name )
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
def setup_pcap ( name ) :
if ( not opts . socket_wrapper_pcap or
2012-03-04 18:11:36 +04:00
not os . environ . get ( " SOCKET_WRAPPER_PCAP_DIR " ) ) :
2012-03-04 08:00:55 +04:00
return
2012-03-04 04:24:10 +04:00
2012-03-04 18:11:36 +04:00
fname = " " . join ( [ x for x in name if x . isalnum ( ) or x == ' - ' ] )
2012-03-04 04:24:10 +04:00
2012-03-04 18:11:36 +04:00
pcap_file = os . path . join (
os . environ [ " SOCKET_WRAPPER_PCAP_DIR " ] , " %s .pcap " % fname )
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
socket_wrapper . setup_pcap ( pcap_file )
return pcap_file
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
def cleanup_pcap ( pcap_file , exit_code ) :
if not opts . socket_wrapper_pcap :
return
if opts . socket_wrapper_keep_pcap :
return
if exitcode == 0 :
return
if pcap_file is None :
return
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
os . unlink ( pcap_file )
2012-03-04 04:24:10 +04:00
2012-03-11 23:58:00 +04:00
def run_testsuite ( name , cmd , subunit_ops , env = None ) :
2012-03-04 19:49:30 +04:00
""" Run a single testsuite.
2012-03-11 23:58:00 +04:00
: param env : Environment to run in
2012-03-04 19:49:30 +04:00
: param name : Name of the testsuite
: param cmd : Name of the ( fully expanded ) command to run
: return : exitcode of the command
"""
2012-03-04 08:00:55 +04:00
pcap_file = setup_pcap ( name )
2012-03-11 23:58:00 +04:00
exitcode = run_testsuite_command ( name , cmd , subunit_ops , env )
if exitcode is None :
2012-03-04 17:55:39 +04:00
sys . exit ( 1 )
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
cleanup_pcap ( pcap_file , exitcode )
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
if not opts . socket_wrapper_keep_pcap and pcap_file is not None :
sys . stdout . write ( " PCAP FILE: %s \n " % pcap_file )
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
if exitcode != 0 and opts . one :
sys . exit ( 1 )
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
return exitcode
2012-03-11 23:58:00 +04:00
2012-03-04 08:00:55 +04:00
if opts . list and opts . testenv :
sys . stderr . write ( " --list and --testenv are mutually exclusive \n " )
sys . exit ( 1 )
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
tests = args
2012-03-04 04:24:10 +04:00
2012-03-04 19:49:30 +04:00
# quick hack to disable rpc validation when using valgrind - it is way too slow
2012-03-04 08:00:55 +04:00
if not os . environ . get ( " VALGRIND " ) :
2012-03-04 18:11:36 +04:00
os . environ [ " VALIDATE " ] = " validate "
2013-03-20 13:58:22 +04:00
os . environ [ " MALLOC_CHECK_ " ] = " 3 "
2012-03-04 04:24:10 +04:00
# make all our python scripts unbuffered
2012-03-04 08:00:55 +04:00
os . environ [ " PYTHONUNBUFFERED " ] = " 1 "
2012-03-04 04:24:10 +04:00
2012-03-04 18:11:36 +04:00
bindir_abs = os . path . abspath ( opts . bindir )
2012-03-04 04:24:10 +04:00
# Backwards compatibility:
2012-03-04 08:00:55 +04:00
if os . environ . get ( " TEST_LDAP " ) == " yes " :
if os . environ . get ( " FEDORA_DS_ROOT " ) :
ldap = " fedora-ds "
else :
ldap = " openldap "
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
torture_maxtime = int ( os . getenv ( " TORTURE_MAXTIME " , " 1200 " ) )
2012-03-04 18:11:36 +04:00
if opts . ldap :
2012-03-04 08:00:55 +04:00
# LDAP is slow
torture_maxtime * = 2
2012-03-04 04:24:10 +04:00
2012-03-04 18:11:36 +04:00
prefix = os . path . normpath ( opts . prefix )
2012-03-04 04:24:10 +04:00
# Ensure we have the test prefix around.
#
2012-03-04 19:49:30 +04:00
# We need restrictive permissions on this as some subdirectories in this tree
# will have wider permissions (ie 0777) and this would allow other users on the
2012-03-04 04:24:10 +04:00
# host to subvert the test process.
2012-03-04 08:00:55 +04:00
if not os . path . isdir ( prefix ) :
os . mkdir ( prefix , 0700 )
else :
os . chmod ( prefix , 0700 )
prefix_abs = os . path . abspath ( prefix )
2012-03-04 19:22:34 +04:00
tmpdir_abs = os . path . abspath ( os . path . join ( prefix_abs , " tmp " ) )
2012-03-04 08:00:55 +04:00
if not os . path . isdir ( tmpdir_abs ) :
os . mkdir ( tmpdir_abs , 0777 )
2012-03-04 18:11:36 +04:00
srcdir_abs = os . path . abspath ( opts . srcdir )
2012-03-04 08:00:55 +04:00
if prefix_abs == " / " :
2012-03-12 00:46:00 +04:00
raise Exception ( " using ' / ' as absolute prefix is a bad idea " )
2012-03-04 08:00:55 +04:00
os . environ [ " PREFIX " ] = prefix
os . environ [ " KRB5CCNAME " ] = os . path . join ( prefix , " krb5ticket " )
os . environ [ " PREFIX_ABS " ] = prefix_abs
2012-03-04 18:11:36 +04:00
os . environ [ " SRCDIR " ] = opts . srcdir
2012-03-04 08:00:55 +04:00
os . environ [ " SRCDIR_ABS " ] = srcdir_abs
os . environ [ " BINDIR " ] = bindir_abs
tls_enabled = not opts . quick
if tls_enabled :
os . environ [ " TLS_ENABLED " ] = " yes "
else :
os . environ [ " TLS_ENABLED " ] = " no "
def prefix_pathvar ( name , newpath ) :
if name in os . environ :
os . environ [ name ] = " %s : %s " % ( newpath , os . environ [ name ] )
else :
2012-03-04 18:11:36 +04:00
os . environ [ name ] = newpath
2012-03-04 08:00:55 +04:00
prefix_pathvar ( " PKG_CONFIG_PATH " , os . path . join ( bindir_abs , " pkgconfig " ) )
prefix_pathvar ( " PYTHONPATH " , os . path . join ( bindir_abs , " python " ) )
if opts . socket_wrapper_keep_pcap :
# Socket wrapper keep pcap implies socket wrapper pcap
opts . socket_wrapper_pcap = True
if opts . socket_wrapper_pcap :
# Socket wrapper pcap implies socket wrapper
opts . socket_wrapper = True
if opts . socket_wrapper :
socket_wrapper_dir = socket_wrapper . setup_dir ( os . path . join ( prefix_abs , " w " ) , opts . socket_wrapper_pcap )
sys . stdout . write ( " SOCKET_WRAPPER_DIR= %s \n " % socket_wrapper_dir )
elif not opts . list :
2012-03-04 18:11:36 +04:00
if os . getuid ( ) != 0 :
2012-03-04 08:00:55 +04:00
warnings . warn ( " not using socket wrapper, but also not running as root. Will not be able to listen on proper ports " )
testenv_default = " none "
if opts . binary_mapping :
binary_mapping = dict ( [ l . split ( " : " ) for l in opts . binary_mapping . split ( " , " ) ] )
2012-03-04 18:11:36 +04:00
os . environ [ " BINARY_MAPPING " ] = opts . binary_mapping
2012-03-04 08:00:55 +04:00
else :
binary_mapping = { }
2012-03-04 18:11:36 +04:00
os . environ [ " BINARY_MAPPING " ] = " "
2012-03-04 04:24:10 +04:00
# After this many seconds, the server will self-terminate. All tests
# must terminate in this time, and testenv will only stay alive this
# long
2012-03-04 08:00:55 +04:00
if os . environ . get ( " SMBD_MAXTIME " , " " ) :
server_maxtime = int ( os . environ [ " SMBD_MAXTIME " ] )
2012-03-11 23:58:00 +04:00
else :
server_maxtime = 7500
2012-03-04 08:00:55 +04:00
2012-03-04 18:11:36 +04:00
def has_socket_wrapper ( bindir ) :
2012-03-04 19:32:56 +04:00
""" Check if Samba has been built with socket wrapper support.
"""
2012-03-04 18:11:36 +04:00
f = StringIO ( )
subprocess . check_call ( [ os . path . join ( bindir , " smbd " ) , " -b " ] , stdout = f )
for l in f . readlines ( ) :
if " SOCKET_WRAPPER " in l :
return True
return False
2012-03-04 08:00:55 +04:00
if not opts . list :
if opts . target == " samba " :
2012-03-04 18:11:36 +04:00
if opts . socket_wrapper and not has_socket_wrapper ( opts . bindir ) :
sys . stderr . write ( " You must include --enable-socket-wrapper when compiling Samba in order to execute ' make test ' . Exiting.... \n " )
sys . exit ( 1 )
2015-03-06 01:38:26 +03:00
testenv_default = " ad_dc_ntvfs "
2012-03-04 17:55:39 +04:00
from selftest . target . samba import Samba
2012-03-04 18:11:36 +04:00
target = Samba ( opts . bindir , binary_mapping , ldap , opts . srcdir , server_maxtime )
2012-03-04 08:00:55 +04:00
elif opts . target == " samba3 " :
2012-03-04 18:11:36 +04:00
if opts . socket_wrapper and not has_socket_wrapper ( opts . bindir ) :
sys . stderr . write ( " You must include --enable-socket-wrapper when compiling Samba in order to execute ' make test ' . Exiting.... \n " )
sys . exit ( 1 )
2012-03-04 08:00:55 +04:00
testenv_default = " member "
2012-03-04 17:55:39 +04:00
from selftest . target . samba3 import Samba3
2012-03-04 18:11:36 +04:00
target = Samba3 ( opts . bindir , binary_mapping , srcdir_abs , server_maxtime )
2012-03-04 19:22:34 +04:00
elif opts . target == " none " :
testenv_default = " none "
target = NoneTarget ( )
2012-03-04 18:11:36 +04:00
env_manager = EnvironmentManager ( target )
2012-03-04 19:39:43 +04:00
atexit . register ( env_manager . teardown_all )
2012-03-04 08:00:55 +04:00
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 " ] )
clientdir = os . path . join ( prefix_abs , " client " )
conffile = os . path . join ( clientdir , " client.conf " )
os . environ [ " SMB_CONF_PATH " ] = conffile
todo = [ ]
2012-03-04 19:22:34 +04:00
if not opts . testlist :
2012-03-04 08:00:55 +04:00
sys . stderr . write ( " No testlists specified \n " )
sys . exit ( 1 )
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
os . environ [ " SELFTEST_PREFIX " ] = prefix_abs
os . environ [ " SELFTEST_TMPDIR " ] = tmpdir_abs
os . environ [ " TEST_DATA_PREFIX " ] = tmpdir_abs
if opts . socket_wrapper :
os . environ [ " SELFTEST_INTERFACES " ] = interfaces
else :
os . environ [ " SELFTEST_INTERFACES " ] = " "
if opts . quick :
os . environ [ " SELFTEST_QUICK " ] = " 1 "
else :
os . environ [ " SELFTEST_QUICK " ] = " "
os . environ [ " SELFTEST_MAXTIME " ] = str ( torture_maxtime )
2012-03-04 19:22:34 +04:00
2012-03-04 08:00:55 +04:00
available = [ ]
2012-03-04 19:22:34 +04:00
for fn in opts . testlist :
2012-03-05 07:05:35 +04:00
for testsuite in testlist . read_testlist_file ( fn ) :
if not testlist . should_run_test ( tests , testsuite ) :
continue
name = testsuite [ 0 ]
if ( includes is not None and
testlist . find_in_list ( includes , name ) is not None ) :
continue
available . append ( testsuite )
2012-03-04 08:00:55 +04:00
if opts . load_list :
2012-03-04 18:11:36 +04:00
restricted_mgr = testlist . RestrictedTestManager . from_path ( opts . load_list )
2012-03-04 08:00:55 +04:00
else :
restricted_mgr = None
for testsuite in available :
name = testsuite [ 0 ]
skipreason = skip ( name )
if restricted_mgr is not None :
match = restricted_mgr . should_run_testsuite ( name )
if match == [ ] :
continue
else :
match = None
if skipreason is not None :
if not opts . list :
2012-03-04 18:11:36 +04:00
subunit_ops . skip_testsuite ( name , skipreason )
2012-03-04 08:00:55 +04:00
else :
todo . append ( testsuite + ( match , ) )
if restricted_mgr is not None :
for name in restricted_mgr . iter_unused ( ) :
sys . stdout . write ( " No test or testsuite found matching %s \n " % name )
if todo == [ ] :
sys . stderr . write ( " No tests to run \n " )
sys . exit ( 1 )
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
suitestotal = len ( todo )
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
if not opts . list :
2012-03-04 19:22:34 +04:00
subunit_ops . progress ( suitestotal , subunit . PROGRESS_SET )
subunit_ops . time ( now ( ) )
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
exported_envvars = [
# domain stuff
" DOMAIN " ,
" REALM " ,
# domain controller stuff
" DC_SERVER " ,
" DC_SERVER_IP " ,
" DC_NETBIOSNAME " ,
" DC_NETBIOSALIAS " ,
# domain member
" MEMBER_SERVER " ,
" MEMBER_SERVER_IP " ,
" MEMBER_NETBIOSNAME " ,
" MEMBER_NETBIOSALIAS " ,
# rpc proxy controller stuff
" RPC_PROXY_SERVER " ,
" RPC_PROXY_SERVER_IP " ,
" RPC_PROXY_NETBIOSNAME " ,
" RPC_PROXY_NETBIOSALIAS " ,
# domain controller stuff for Vampired DC
" VAMPIRE_DC_SERVER " ,
" VAMPIRE_DC_SERVER_IP " ,
" VAMPIRE_DC_NETBIOSNAME " ,
" VAMPIRE_DC_NETBIOSALIAS " ,
2013-05-13 20:16:24 +04:00
# domain controller stuff for Vampired DC
" PROMOTED_DC_SERVER " ,
" PROMOTED_DC_SERVER_IP " ,
" PROMOTED_DC_NETBIOSNAME " ,
" PROMOTED_DC_NETBIOSALIAS " ,
2012-03-04 08:00:55 +04:00
# server stuff
" SERVER " ,
" SERVER_IP " ,
" NETBIOSNAME " ,
" NETBIOSALIAS " ,
# user stuff
" USERNAME " ,
" USERID " ,
" PASSWORD " ,
" DC_USERNAME " ,
" DC_PASSWORD " ,
# misc stuff
" KRB5_CONFIG " ,
" WINBINDD_SOCKET_DIR " ,
" WINBINDD_PRIV_PIPE_DIR " ,
" NMBD_SOCKET_DIR " ,
" LOCAL_PATH "
]
def switch_env ( name , prefix ) :
if " : " in name :
( envname , option ) = name . split ( " : " , 1 )
else :
envname = name
option = " client "
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
env = env_manager . setup_env ( envname , prefix )
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
testenv_vars = env . get_vars ( )
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
if option == " local " :
socket_wrapper . set_default_iface ( testenv_vars [ " SOCKET_WRAPPER_DEFAULT_IFACE " ] )
os . environ [ " SMB_CONF_PATH " ] = testenv_vars [ " SERVERCONFFILE " ]
elif option == " client " :
socket_wrapper . set_default_iface ( 11 )
write_clientconf ( conffile , clientdir , testenv_vars )
os . environ [ " SMB_CONF_PATH " ] = conffile
else :
raise Exception ( " Unknown option[ %s ] for envname[ %s ] " % ( option ,
envname ) )
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
for name in exported_envvars :
if name in testenv_vars :
os . environ [ name ] = testenv_vars [ name ]
2012-03-04 19:22:34 +04:00
elif name in os . environ :
2012-03-04 08:00:55 +04:00
del os . environ [ name ]
2012-03-04 04:24:10 +04:00
2012-03-11 23:58:00 +04:00
return env
2012-03-04 04:24:10 +04:00
# This 'global' file needs to be empty when we start
2012-03-04 19:22:34 +04:00
dns_host_file_path = os . path . join ( prefix_abs , " dns_host_file " )
if os . path . exists ( dns_host_file_path ) :
os . unlink ( dns_host_file_path )
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
if opts . testenv :
testenv_name = os . environ . get ( " SELFTEST_TESTENV " , testenv_default )
2012-03-04 04:24:10 +04:00
2012-03-11 23:58:00 +04:00
env = switch_env ( testenv_name , prefix )
testenv_vars = env . get_vars ( )
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
os . environ [ " PIDDIR " ] = testenv_vars [ " PIDDIR " ]
os . environ [ " ENVNAME " ] = testenv_name
2012-03-04 04:24:10 +04:00
2012-03-05 06:49:50 +04:00
envvarstr = exported_envvars_str ( testenv_vars , exported_envvars )
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
term = os . environ . get ( " TERMINAL " , " xterm -e " )
2012-03-04 18:11:36 +04:00
cmd = """ ' echo -e "
Welcome to the Samba4 Test environment ' % (testenv_name) '
2012-03-04 04:24:10 +04:00
This matches the client environment used in make test
server is pid ` cat \$ PIDDIR / samba . pid `
Some useful environment variables :
TORTURE_OPTIONS = \$ TORTURE_OPTIONS
SMB_CONF_PATH = \$ SMB_CONF_PATH
$ envvarstr
2012-03-04 18:11:36 +04:00
\" && LD_LIBRARY_PATH= %(LD_LIBRARY_PATH)s $(SHELL) ' " " " % {
" testenv_name " : testenv_name ,
" LD_LIBRARY_PATH " : os . environ [ " LD_LIBRARY_PATH " ] }
2012-03-04 19:22:34 +04:00
subprocess . call ( term + ' ' + cmd , shell = True )
2012-03-04 08:00:55 +04:00
env_manager . teardown_env ( testenv_name )
elif opts . list :
for ( name , envname , cmd , supports_loadfile , supports_idlist , subtests ) in todo :
2012-03-05 06:27:40 +04:00
cmd = expand_command_list ( cmd )
if cmd is None :
2012-03-04 08:00:55 +04:00
warnings . warn ( " Unable to list tests in %s " % name )
continue
2012-03-04 04:24:10 +04:00
2012-03-04 19:22:34 +04:00
exitcode = subprocess . call ( cmd , shell = True )
2012-03-04 04:24:10 +04:00
2012-03-04 08:00:55 +04:00
if exitcode != 0 :
sys . stderr . write ( " %s exited with exit code %s \n " % ( cmd , exitcode ) )
sys . exit ( 1 )
else :
for ( name , envname , cmd , supports_loadfile , supports_idlist , subtests ) in todo :
try :
2012-03-11 23:58:00 +04:00
env = switch_env ( envname , prefix )
2012-03-04 19:22:34 +04:00
except UnsupportedEnvironment :
subunit_ops . start_testsuite ( name )
2012-03-04 18:11:36 +04:00
subunit_ops . end_testsuite ( name , " skip " ,
2012-03-04 19:22:34 +04:00
" environment %s is unknown in this test backend - skipping " % envname )
continue
except Exception , e :
subunit_ops . start_testsuite ( name )
traceback . print_exc ( )
subunit_ops . end_testsuite ( name , " error " ,
" unable to set up environment %s : %s " % ( envname , e ) )
2012-03-04 08:00:55 +04:00
continue
2012-03-05 06:39:57 +04:00
cmd , tmpf = expand_command_run ( cmd , supports_loadfile , supports_idlist ,
subtests )
2012-03-04 08:00:55 +04:00
2012-03-11 23:58:00 +04:00
run_testsuite ( name , cmd , subunit_ops , env = env )
2012-03-04 08:00:55 +04:00
2012-03-05 06:39:57 +04:00
if tmpf is not None :
os . remove ( tmpf )
2012-03-04 19:22:34 +04:00
if opts . resetup_environment :
2012-03-04 08:00:55 +04:00
env_manager . teardown_env ( envname )
2012-03-06 03:38:54 +04:00
env_manager . teardown_all ( )
2012-03-04 08:00:55 +04:00
sys . stdout . write ( " \n " )
2012-03-04 04:24:10 +04:00
# if there were any valgrind failures, show them
2012-03-04 08:00:55 +04:00
for fn in os . listdir ( prefix ) :
if fn . startswith ( " valgrind.log " ) :
sys . stdout . write ( " VALGRIND FAILURE \n " )
f = open ( os . path . join ( prefix , fn ) , ' r ' )
try :
sys . stdout . write ( f . read ( ) )
finally :
f . close ( )
sys . exit ( 0 )