2021-07-27 09:50:54 +03:00
#!/usr/bin/env python3
#
2011-02-21 03:16:03 +03:00
# This script generates a list of testsuites that should be run as part of
# the Samba 4 test suite.
# The output of this script is parsed by selftest.pl, which then decides
# which of the tests to actually run. It will, for example, skip all tests
# listed in selftest/skip or only run a subset during "make quicktest".
# The idea is that this script outputs all of the tests of Samba 4, not
# just those that are known to pass, and list those that should be skipped
# or are known to fail in selftest/skip or selftest/knownfail. This makes it
# very easy to see what functionality is still missing in Samba 4 and makes
# it possible to run the testsuite against other servers, such as Samba 3 or
# Windows that have a different set of features.
# The syntax for a testsuite is "-- TEST --" on a single line, followed
# by the name of the test, the environment it needs and the command to run, all
# three separated by newlines. All other lines in the output are considered
# comments.
import os
import subprocess
2011-11-27 22:52:57 +04:00
import sys
2011-02-21 03:16:03 +03:00
2018-07-30 09:20:39 +03:00
2011-02-21 03:16:03 +03:00
def srcdir ( ) :
2021-07-27 09:50:54 +03:00
alternate_path = os . path . join ( os . path . dirname ( os . path . abspath ( __file__ ) ) , " .. " )
return os . path . normpath ( os . getenv ( " SRCDIR " , alternate_path ) )
2011-02-21 03:16:03 +03:00
2018-07-30 09:20:39 +03:00
2011-02-21 03:16:03 +03:00
def source4dir ( ) :
2011-04-15 06:27:30 +04:00
return os . path . normpath ( os . path . join ( srcdir ( ) , " source4 " ) )
2011-02-21 03:16:03 +03:00
2018-07-30 09:20:39 +03:00
2012-10-27 17:23:57 +04:00
def source3dir ( ) :
return os . path . normpath ( os . path . join ( srcdir ( ) , " source3 " ) )
2018-07-30 09:20:39 +03:00
2011-02-21 03:16:03 +03:00
def bindir ( ) :
2011-04-15 06:41:22 +04:00
return os . path . normpath ( os . getenv ( " BINDIR " , " ./bin " ) )
2011-02-21 03:16:03 +03:00
2018-07-30 09:20:39 +03:00
2011-02-21 03:16:03 +03:00
def binpath ( name ) :
2012-01-26 02:42:27 +04:00
return os . path . join ( bindir ( ) , name )
2011-02-21 03:16:03 +03:00
2018-07-30 09:21:29 +03:00
2011-11-14 16:47:50 +04:00
# Split perl variable to allow $PERL to be set to e.g. "perl -W"
perl = os . getenv ( " PERL " , " perl " ) . split ( )
2011-02-21 03:16:03 +03:00
2011-11-14 16:47:50 +04:00
if subprocess . call ( perl + [ " -e " , " eval require Test::More; " ] ) == 0 :
2011-02-21 03:16:03 +03:00
has_perl_test_more = True
else :
has_perl_test_more = False
python = os . getenv ( " PYTHON " , " python " )
2014-12-14 22:25:12 +03:00
tap2subunit = python + " " + os . path . join ( srcdir ( ) , " selftest " , " tap2subunit " )
2014-11-02 01:13:18 +03:00
2011-02-21 03:16:03 +03:00
def valgrindify ( cmdline ) :
""" Run a command under valgrind, if $VALGRIND was set. """
valgrind = os . getenv ( " VALGRIND " )
if valgrind is None :
return cmdline
return valgrind + " " + cmdline
2014-12-14 22:25:12 +03:00
def plantestsuite ( name , env , cmdline ) :
2011-02-21 03:16:03 +03:00
""" Plan a test suite.
: param name : Testsuite name
: param env : Environment to run the testsuite in
: param cmdline : Command line to run
"""
2018-03-09 17:03:29 +03:00
print ( " -- TEST -- " )
2016-12-29 17:57:03 +03:00
if env == " none " :
fullname = name
else :
fullname = " %s ( %s ) " % ( name , env )
2018-03-09 17:03:29 +03:00
print ( fullname )
print ( env )
2011-02-21 03:16:03 +03:00
if isinstance ( cmdline , list ) :
cmdline = " " . join ( cmdline )
2014-11-02 01:13:18 +03:00
if " $LISTOPT " in cmdline :
raise AssertionError ( " test %s supports --list, but not --load-list " % name )
2018-03-09 17:03:29 +03:00
print ( cmdline + " 2>&1 " + " | " + add_prefix ( name , env ) )
2011-02-21 03:16:03 +03:00
2012-04-27 06:50:36 +04:00
def add_prefix ( prefix , env , support_list = False ) :
2011-02-21 03:16:03 +03:00
if support_list :
listopt = " $LISTOPT "
else :
listopt = " "
2021-07-27 09:50:54 +03:00
return ( " %s %s /selftest/filter-subunit %s --fail-on-empty --prefix= \" %s . \" --suffix= \" ( %s ) \" " %
( python , srcdir ( ) , listopt , prefix , env ) )
2011-02-21 03:16:03 +03:00
2014-12-14 22:25:12 +03:00
def plantestsuite_loadlist ( name , env , cmdline ) :
2018-03-09 17:03:29 +03:00
print ( " -- TEST-LOADLIST -- " )
2011-02-21 03:16:03 +03:00
if env == " none " :
fullname = name
else :
fullname = " %s ( %s ) " % ( name , env )
2018-03-09 17:03:29 +03:00
print ( fullname )
print ( env )
2011-02-21 03:16:03 +03:00
if isinstance ( cmdline , list ) :
cmdline = " " . join ( cmdline )
support_list = ( " $LISTOPT " in cmdline )
2018-07-30 09:22:34 +03:00
if " $LISTOPT " not in cmdline :
2014-11-02 02:36:54 +03:00
raise AssertionError ( " loadlist test %s does not support not --list " % name )
2018-07-30 09:22:34 +03:00
if " $LOADLIST " not in cmdline :
2014-11-02 02:36:54 +03:00
raise AssertionError ( " loadlist test %s does not support --load-list " % name )
2021-07-27 09:50:54 +03:00
print ( ( " %s | %s " %
( cmdline . replace ( " $LOADLIST " , " " ) ,
add_prefix ( name , env , support_list ) ) ) . replace ( " $LISTOPT " , " --list " ) )
2018-03-09 17:03:29 +03:00
print ( cmdline . replace ( " $LISTOPT " , " " ) + " 2>&1 " + " | " + add_prefix ( name , env , False ) )
2011-02-21 03:16:03 +03:00
def skiptestsuite ( name , reason ) :
""" Indicate that a testsuite was skipped.
: param name : Test suite name
: param reason : Reason the test suite was skipped
"""
# FIXME: Report this using subunit, but re-adjust the testsuite count somehow
2018-03-09 17:03:29 +03:00
print ( " skipping %s ( %s ) " % ( name , reason ) , file = sys . stderr )
2011-02-21 03:16:03 +03:00
def planperltestsuite ( name , path ) :
""" Run a perl test suite.
: param name : Name of the test suite
: param path : Path to the test runner
"""
if has_perl_test_more :
2011-11-14 16:47:50 +04:00
plantestsuite ( name , " none " , " %s %s | %s " % ( " " . join ( perl ) , path , tap2subunit ) )
2011-02-21 03:16:03 +03:00
else :
skiptestsuite ( name , " Test::More not available " )
2020-07-24 13:18:11 +03:00
def planpythontestsuite ( env , module , name = None , extra_path = [ ] , environ = { } , extra_args = [ ] ) :
environ = dict ( environ )
py_path = list ( extra_path )
if py_path is not None :
environ [ " PYTHONPATH " ] = " : " . join ( [ " $PYTHONPATH " ] + py_path )
args = [ " %s = %s " % item for item in environ . items ( ) ]
args + = [ python , " -m " , " samba.subunit.run " , " $LISTOPT " , " $LOADLIST " , module ]
args + = extra_args
2011-11-14 15:21:38 +04:00
if name is None :
name = module
2018-10-28 00:53:49 +03:00
2020-07-24 13:18:11 +03:00
plantestsuite_loadlist ( name , env , args )
2012-10-05 13:51:37 +04:00
2012-10-27 01:38:32 +04:00
def get_env_torture_options ( ) :
ret = [ ]
if not os . getenv ( " SELFTEST_VERBOSE " ) :
ret . append ( " --option=torture:progress=no " )
if os . getenv ( " SELFTEST_QUICK " ) :
ret . append ( " --option=torture:quick=yes " )
return ret
2012-10-05 13:51:37 +04:00
samba4srcdir = source4dir ( )
2012-10-27 17:23:57 +04:00
samba3srcdir = source3dir ( )
2012-10-05 13:51:37 +04:00
bbdir = os . path . join ( srcdir ( ) , " testprogs/blackbox " )
configuration = " --configfile=$SMB_CONF_PATH "
2015-06-05 06:18:19 +03:00
smbtorture4 = binpath ( " smbtorture " )
2021-07-27 09:50:54 +03:00
smbtorture4_testsuite_list = subprocess . Popen (
[ smbtorture4 , " --list-suites " ] ,
stdout = subprocess . PIPE ,
stderr = subprocess . PIPE ) . communicate ( " " ) [ 0 ] . decode ( ' utf8 ' ) . splitlines ( )
2012-10-27 01:03:32 +04:00
2012-10-27 01:38:32 +04:00
smbtorture4_options = [
configuration ,
2013-05-15 02:42:35 +04:00
" --option= \' fss:sequence timeout=1 \' " ,
2012-10-27 01:38:32 +04:00
" --maximum-runtime=$SELFTEST_MAXTIME " ,
" --basedir=$SELFTEST_TMPDIR " ,
" --format=subunit "
2018-07-30 09:14:37 +03:00
] + get_env_torture_options ( )
2012-10-27 01:09:45 +04:00
2012-10-27 01:38:32 +04:00
2021-07-27 14:25:59 +03:00
def plansmbtorture4testsuite ( name , env , options , target , environ = { } , modname = None ) :
2012-10-27 01:03:32 +04:00
if modname is None :
modname = " samba4. %s " % name
2020-03-10 21:51:09 +03:00
if isinstance ( options , list ) :
options = " " . join ( options )
options = " " . join ( smbtorture4_options + [ " --target= %s " % target ] ) + " " + options
2021-07-27 14:25:59 +03:00
cmdline = [ " %s = %s " % item for item in environ . items ( ) ]
cmdline + = " %s $LISTOPT $LOADLIST %s %s " % ( valgrindify ( smbtorture4 ) , options , name )
2012-10-27 01:03:32 +04:00
plantestsuite_loadlist ( modname , env , cmdline )
2012-10-27 01:09:45 +04:00
2012-10-27 01:03:32 +04:00
def smbtorture4_testsuites ( prefix ) :
2018-08-03 20:45:35 +03:00
return list ( filter ( lambda x : x . startswith ( prefix ) , smbtorture4_testsuite_list ) )
2012-10-27 17:23:57 +04:00
2015-06-05 06:18:19 +03:00
smbclient3 = binpath ( ' smbclient ' )
2012-10-27 17:23:57 +04:00
smbtorture3 = binpath ( ' smbtorture3 ' )
2015-06-05 06:18:19 +03:00
ntlm_auth3 = binpath ( ' ntlm_auth ' )
2012-10-27 17:23:57 +04:00
net = binpath ( ' net ' )
2012-10-27 17:31:06 +04:00
scriptdir = os . path . join ( srcdir ( ) , " script/tests " )
wbinfo = binpath ( ' wbinfo ' )
dbwrap_tool = binpath ( ' dbwrap_tool ' )
vfstest = binpath ( ' vfstest ' )
2016-01-06 13:59:06 +03:00
smbcquotas = binpath ( ' smbcquotas ' )
2016-02-04 23:41:08 +03:00
smbget = binpath ( ' smbget ' )
2016-02-29 23:09:57 +03:00
rpcclient = binpath ( ' rpcclient ' )
2016-03-22 00:13:25 +03:00
smbcacls = binpath ( ' smbcacls ' )
2019-01-24 21:15:56 +03:00
smbcontrol = binpath ( ' smbcontrol ' )
2019-03-13 14:00:11 +03:00
smbstatus = binpath ( ' smbstatus ' )