2011-02-21 03:16:03 +03:00
#!/usr/bin/python
# 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
def srcdir ( ) :
2011-04-15 06:27:30 +04:00
return os . path . normpath ( os . getenv ( " SRCDIR " , os . path . join ( os . path . dirname ( os . path . abspath ( __file__ ) ) , " .. " ) ) )
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
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
2011-04-15 09:17:58 +04:00
binary_mapping = { }
2011-02-21 03:16:03 +03:00
def binpath ( name ) :
2011-04-15 09:17:58 +04:00
if name in binary_mapping :
name = binary_mapping [ name ]
2012-01-26 02:42:27 +04:00
return os . path . join ( bindir ( ) , name )
2011-02-21 03:16:03 +03:00
2011-04-15 09:17:58 +04:00
binary_mapping_string = os . getenv ( " BINARY_MAPPING " , None )
if binary_mapping_string is not None :
for binmapping_entry in binary_mapping_string . split ( ' , ' ) :
2011-11-14 00:51:53 +04:00
try :
( from_path , to_path ) = binmapping_entry . split ( ' : ' , 1 )
except ValueError :
continue
binary_mapping [ from_path ] = to_path
2011-04-15 09:17:58 +04: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
try :
from subunit . run import TestProgram
except ImportError :
has_system_subunit_run = False
else :
has_system_subunit_run = True
python = os . getenv ( " PYTHON " , " python " )
#Set a default value, overridden if we find a working one on the system
tap2subunit = " PYTHONPATH= %s /lib/subunit/python: %s /lib/testtools %s %s /lib/subunit/filters/tap2subunit " % ( srcdir ( ) , srcdir ( ) , python , srcdir ( ) )
sub = subprocess . Popen ( " tap2subunit 2> /dev/null " , stdout = subprocess . PIPE , stdin = subprocess . PIPE , shell = True )
sub . communicate ( " " )
if sub . returncode == 0 :
cmd = " echo -ne \" 1..1 \n ok 1 # skip doesn ' t seem to work yet \n \" | tap2subunit 2> /dev/null | grep skip "
sub = subprocess . Popen ( cmd , stdout = subprocess . PIPE , stdin = subprocess . PIPE , stderr = subprocess . PIPE , shell = True )
if sub . returncode == 0 :
tap2subunit = " tap2subunit "
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
def plantestsuite ( name , env , cmdline , allow_empty_output = False ) :
""" Plan a test suite.
: param name : Testsuite name
: param env : Environment to run the testsuite in
: param cmdline : Command line to run
"""
print " -- TEST -- "
print name
print env
if isinstance ( cmdline , list ) :
cmdline = " " . join ( cmdline )
filter_subunit_args = [ ]
if not allow_empty_output :
filter_subunit_args . append ( " --fail-on-empty " )
if " $LISTOPT " in cmdline :
filter_subunit_args . append ( " $LISTOPT " )
2012-04-27 06:50:36 +04:00
print " %s 2>&1 | %s /selftest/filter-subunit %s --prefix= \" %s . \" --suffix= \" ( %s ) \" " % ( cmdline ,
2011-02-21 03:16:03 +03:00
srcdir ( ) ,
" " . join ( filter_subunit_args ) ,
2012-04-27 06:50:36 +04:00
name , env )
2011-02-21 03:16:03 +03:00
if allow_empty_output :
2011-11-27 22:52:57 +04:00
print >> sys . stderr , " WARNING: allowing empty subunit output from %s " % name
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 = " "
2012-04-27 06:50:36 +04:00
return " %s /selftest/filter-subunit %s --fail-on-empty --prefix= \" %s . \" --suffix= \" ( %s ) \" " % ( srcdir ( ) , listopt , prefix , env )
2011-02-21 03:16:03 +03:00
def plantestsuite_loadlist ( name , env , cmdline ) :
print " -- TEST-LOADLIST -- "
if env == " none " :
fullname = name
else :
fullname = " %s ( %s ) " % ( name , env )
print fullname
print env
if isinstance ( cmdline , list ) :
cmdline = " " . join ( cmdline )
support_list = ( " $LISTOPT " in cmdline )
2012-04-27 06:50:36 +04:00
print " %s $LOADLIST 2>&1 | %s " % ( cmdline , add_prefix ( name , env , support_list ) )
2011-02-21 03:16:03 +03:00
def plantestsuite_idlist ( name , env , cmdline ) :
print " -- TEST-IDLIST -- "
2011-11-14 17:10:17 +04:00
if env == " none " :
fullname = name
else :
fullname = " %s ( %s ) " % ( name , env )
print fullname
2011-02-21 03:16:03 +03:00
print env
if isinstance ( cmdline , list ) :
cmdline = " " . join ( cmdline )
print cmdline
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
2011-11-27 22:52:57 +04:00
print >> sys . stderr , " skipping %s ( %s ) " % ( name , reason )
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 " )
2011-11-10 23:24:17 +04:00
def planpythontestsuite ( env , module , name = None , extra_path = [ ] ) :
2011-11-14 15:21:38 +04:00
if name is None :
name = module
2011-11-10 23:24:17 +04:00
pypath = list ( extra_path )
2011-11-10 16:59:21 +04:00
if not has_system_subunit_run :
pypath . extend ( [ " %s /lib/subunit/python " % srcdir ( ) ,
" %s /lib/testtools " % srcdir ( ) ] )
args = [ python , " -m " , " subunit.run " , " $LISTOPT " , module ]
if pypath :
2011-11-10 23:44:59 +04:00
args . insert ( 0 , " PYTHONPATH= %s " % " : " . join ( [ " $PYTHONPATH " ] + pypath ) )
2011-11-10 16:59:21 +04:00
plantestsuite_idlist ( 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 ( )
bbdir = os . path . join ( srcdir ( ) , " testprogs/blackbox " )
configuration = " --configfile=$SMB_CONF_PATH "
2012-10-27 01:03:32 +04:00
smbtorture4 = binpath ( " smbtorture4 " )
smbtorture4_testsuite_list = subprocess . Popen ( [ smbtorture4 , " --list-suites " ] , stdout = subprocess . PIPE , stderr = subprocess . PIPE ) . communicate ( " " ) [ 0 ] . splitlines ( )
2012-10-27 01:38:32 +04:00
smbtorture4_options = [
configuration ,
" --maximum-runtime=$SELFTEST_MAXTIME " ,
" --basedir=$SELFTEST_TMPDIR " ,
" --format=subunit "
] + get_env_torture_options ( )
2012-10-27 01:09:45 +04:00
2012-10-27 01:38:32 +04:00
def plansmbtorture4testsuite ( name , env , options , target , modname = None ) :
2012-10-27 01:03:32 +04:00
if modname is None :
modname = " samba4. %s " % name
if isinstance ( options , list ) :
options = " " . join ( options )
2012-10-27 01:38:32 +04:00
options + = " " + " " . join ( smbtorture4_options + [ " --target= %s " % target ] )
2012-10-27 01:03:32 +04:00
cmdline = " %s $LISTOPT %s %s " % ( valgrindify ( smbtorture4 ) , options , name )
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 ) :
return filter ( lambda x : x . startswith ( prefix ) , smbtorture4_testsuite_list )