2 # vim: expandtab ft=python
6 import Scripting
, os
, Options
, Utils
, Environment
, optparse
, sys
7 from samba_utils
import *
8 from samba_autoconf
import *
12 opt
.add_option('--enable-selftest',
13 help=("enable options necessary for selftest (default=no)"),
14 action
="store_true", dest
='enable_selftest', default
=False)
15 opt
.add_option('--with-selftest-prefix',
16 help=("specify location of selftest directory (default=./st)"),
17 action
="store", dest
='SELFTEST_PREFIX', default
='./st')
19 opt
.ADD_COMMAND('test', cmd_test
)
20 opt
.ADD_COMMAND('testonly', cmd_testonly
)
22 gr
= opt
.add_option_group('test options')
24 gr
.add_option('--load-list',
25 help=("Load a test id list from a text file"),
26 action
="store", dest
='LOAD_LIST', default
=None)
27 gr
.add_option('--list',
28 help=("List available tests"),
29 action
="store_true", dest
='LIST', default
=False)
30 gr
.add_option('--tests',
31 help=("wildcard pattern of tests to run"),
32 action
="store", dest
='TESTS', default
='')
33 gr
.add_option('--target',
34 help=("target of samba3 or samba4"),
35 action
="store", dest
='TARGET', default
=None)
36 gr
.add_option('--filtered-subunit',
37 help=("output (xfail) filtered subunit"),
38 action
="store_true", dest
='FILTERED_SUBUNIT', default
=False)
39 gr
.add_option('--quick',
40 help=("enable only quick tests"),
41 action
="store_true", dest
='QUICKTEST', default
=False)
42 gr
.add_option('--slow',
43 help=("enable the really slow tests"),
44 action
="store_true", dest
='SLOWTEST', default
=False)
45 gr
.add_option('--testenv',
46 help=("start a terminal with the test environment setup"),
47 action
="store_true", dest
='TESTENV', default
=False)
48 gr
.add_option('--valgrind',
49 help=("use valgrind on client programs in the tests"),
50 action
="store_true", dest
='VALGRIND', default
=False)
51 gr
.add_option('--valgrind-log',
52 help=("where to put the valgrind log"),
53 action
="store", dest
='VALGRINDLOG', default
=None)
54 gr
.add_option('--valgrind-server',
55 help=("use valgrind on the server in the tests (opens an xterm)"),
56 action
="store_true", dest
='VALGRIND_SERVER', default
=False)
57 gr
.add_option('--screen',
58 help=("run the samba servers in screen sessions"),
59 action
="store_true", dest
='SCREEN', default
=False)
60 gr
.add_option('--gdbtest',
61 help=("run the servers within a gdb window"),
62 action
="store_true", dest
='GDBTEST', default
=False)
63 gr
.add_option('--fail-immediately',
64 help=("stop tests on first failure"),
65 action
="store_true", dest
='FAIL_IMMEDIATELY', default
=False)
66 gr
.add_option('--socket-wrapper-pcap',
67 help=("create a pcap file for each failing test"),
68 action
="store_true", dest
='SOCKET_WRAPPER_PCAP', default
=False)
69 gr
.add_option('--socket-wrapper-keep-pcap',
70 help=("create a pcap file for all individual test"),
71 action
="store_true", dest
='SOCKET_WRAPPER_KEEP_PCAP', default
=False)
74 conf
.env
.SELFTEST_PREFIX
= Options
.options
.SELFTEST_PREFIX
76 def combine_files(file1
, file2
, outfile
):
80 of
= open(outfile
, mode
='w')
89 def cmd_testonly(opt
):
90 '''run tests without doing a build first'''
91 env
= LOAD_ENVIRONMENT()
94 if (not CONFIG_SET(opt
, 'NSS_WRAPPER') or
95 not CONFIG_SET(opt
, 'UID_WRAPPER') or
96 not CONFIG_SET(opt
, 'SOCKET_WRAPPER')):
97 print("ERROR: You must use --enable-selftest to enable selftest")
100 os
.environ
['SAMBA_SELFTEST'] = '1'
102 env
.TESTS
= Options
.options
.TESTS
104 env
.SUBUNIT_FORMATTER
= os
.getenv('SUBUNIT_FORMATTER')
105 if not env
.SUBUNIT_FORMATTER
:
106 env
.SUBUNIT_FORMATTER
= '${PYTHON} -u ${srcdir}/selftest/format-subunit --prefix=${SELFTEST_PREFIX} --immediate'
107 env
.FILTER_XFAIL
= '${PYTHON} -u ${srcdir}/selftest/filter-subunit --expected-failures=${SELFTEST_DIR}/knownfail'
109 if Options
.options
.FAIL_IMMEDIATELY
:
110 env
.FILTER_XFAIL
+= ' --fail-immediately'
112 env
.FORMAT_TEST_OUTPUT
= '${SUBUNIT_FORMATTER}'
114 # clean any previous temporary files
115 os
.system("rm -rf %s/tmp" % env
.SELFTEST_PREFIX
);
117 # put all command line options in the environment as TESTENV_*=*
118 for o
in dir(Options
.options
):
120 os
.environ
['TESTENV_%s' % o
.upper()] = str(getattr(Options
.options
, o
, ''))
122 binary_mapping
= ('nmblookup3:nmblookup3,' +
123 'smbclient3:smbclient3,' +
124 'smbtorture4:smbtorture,' +
125 'ntlm_auth3:ntlm_auth3')
127 env
.OPTIONS
= '--binary-mapping=%s' % binary_mapping
128 if not Options
.options
.SLOWTEST
:
129 env
.OPTIONS
+= ' --exclude=${SELFTEST_DIR}/slow'
130 if Options
.options
.QUICKTEST
:
131 env
.OPTIONS
+= ' --quick --include=${SELFTEST_DIR}/quick'
132 if Options
.options
.LOAD_LIST
:
133 env
.OPTIONS
+= ' --load-list=%s' % Options
.options
.LOAD_LIST
134 if Options
.options
.TESTENV
:
135 env
.OPTIONS
+= ' --testenv'
136 if Options
.options
.SOCKET_WRAPPER_PCAP
:
137 env
.OPTIONS
+= ' --socket-wrapper-pcap'
138 if Options
.options
.SOCKET_WRAPPER_KEEP_PCAP
:
139 env
.OPTIONS
+= ' --socket-wrapper-keep-pcap'
140 if Options
.options
.LIST
:
141 env
.OPTIONS
+= ' --list'
142 if os
.environ
.get('RUN_FROM_BUILD_FARM') is not None:
143 env
.FILTER_OPTIONS
= '${FILTER_XFAIL} --strip-passed-output'
145 env
.FILTER_OPTIONS
= '${FILTER_XFAIL}'
147 if Options
.options
.VALGRIND
:
148 os
.environ
['VALGRIND'] = 'valgrind -q --num-callers=30'
149 if Options
.options
.VALGRINDLOG
is not None:
150 os
.environ
['VALGRIND'] += ' --log-file=%s' % Options
.options
.VALGRINDLOG
154 if Options
.options
.VALGRIND_SERVER
:
155 server_wrapper
= '${srcdir}/selftest/valgrind_run _DUMMY=X'
156 elif Options
.options
.GDBTEST
:
157 server_wrapper
= '${srcdir}/selftest/gdb_run _DUMMY=X'
159 if Options
.options
.SCREEN
:
160 server_wrapper
= '${srcdir}/selftest/in_screen %s' % server_wrapper
161 os
.environ
['TERMINAL'] = EXPAND_VARIABLES(opt
, '${srcdir}/selftest/in_screen')
162 elif server_wrapper
!= '':
163 server_wrapper
= 'xterm -n server -l -e %s' % server_wrapper
165 if server_wrapper
!= '':
166 os
.environ
['SAMBA_VALGRIND'] = EXPAND_VARIABLES(opt
, server_wrapper
)
168 # this is needed for systems without rpath, or with rpath disabled
169 ADD_LD_LIBRARY_PATH('bin/shared')
170 ADD_LD_LIBRARY_PATH('bin/shared/private')
172 # if we are using a system version of ldb then we need to tell it to
173 # load modules from our modules path
174 if env
.USING_SYSTEM_LDB
:
175 os
.environ
['LDB_MODULES_PATH'] = 'bin/modules/ldb'
177 # tell build system where to find config.h
178 os
.environ
['VFSLIBDIR'] = os
.path
.abspath('bin/modules/vfs')
179 os
.environ
['CONFIG_H'] = 'bin/default/include/config.h'
181 st_done
= os
.path
.join(env
.SELFTEST_PREFIX
, 'st_done')
182 if os
.path
.exists(st_done
):
185 if not os
.path
.isdir(env
.SELFTEST_PREFIX
):
186 os
.makedirs(env
.SELFTEST_PREFIX
, int('755', 8))
188 if Options
.options
.TARGET
:
189 env
.SELFTEST_TARGET
= Options
.options
.TARGET
191 env
.SELFTEST_TARGET
= "samba"
193 if env
.SELFTEST_TARGET
== "samba4":
194 env
.SELFTEST_DIR
= "${srcdir}/source4/selftest"
195 elif env
.SELFTEST_TARGET
== "samba3":
196 env
.SELFTEST_DIR
= "${srcdir}/source3/selftest"
198 if env
.SELFTEST_TARGET
== "samba":
199 for f
in ["knownfail", "slow", "quick", "skip" ]:
200 combine_files(env
.srcdir
+ "/source4/selftest/" + f
,
201 env
.srcdir
+ "/source3/selftest/" + f
,
202 env
.SELFTEST_PREFIX
+ "/" + f
)
204 env
.SELFTEST_DIR
= env
.SELFTEST_PREFIX
205 env
.TESTLISTS
= ('--testlist="${PYTHON} ${srcdir}/source3/selftest/tests.py|" ' +
206 '--testlist="${PYTHON} ${srcdir}/source4/selftest/tests.py|"')
208 env
.TESTLISTS
= '--testlist="${SELFTEST_DIR}/tests.py|"'
210 # We use the full path rather than relative path because it cause problems on some plateforms (ie. solaris 8).
211 cmd
= '(${PERL} ${srcdir}/selftest/selftest.pl --target=${SELFTEST_TARGET} --prefix=${SELFTEST_PREFIX} --srcdir=${srcdir} --exclude=${SELFTEST_DIR}/skip ${TESTLISTS} ${OPTIONS} --socket-wrapper ${TESTS} && touch ${SELFTEST_PREFIX}/st_done) | ${FILTER_OPTIONS} | tee ${SELFTEST_PREFIX}/subunit'
213 if os
.environ
.get('RUN_FROM_BUILD_FARM') is None and not Options
.options
.FILTERED_SUBUNIT
:
214 cmd
+= ' | ${FORMAT_TEST_OUTPUT}'
216 cmd
+= ' | ${PYTHON} -u ${srcdir}/selftest/filter-subunit'
217 runcmd
= EXPAND_VARIABLES(opt
, cmd
)
219 print("test: running %s" % runcmd
)
220 ret
= RUN_COMMAND(cmd
, env
=env
)
221 if os
.path
.exists(".testrepository"):
222 # "testr load -q" isn't
223 testrcmd
= 'testr load -q < ${SELFTEST_PREFIX}/subunit > /dev/null'
224 runcmd
= EXPAND_VARIABLES(opt
, testrcmd
)
225 RUN_COMMAND(runcmd
, env
=env
)
228 print("ERROR: test failed with exit code %d" % ret
)
231 if not os
.path
.exists(st_done
):
232 print("ERROR: test command failed to complete")
236 ########################################################################
237 # main test entry point
239 '''Run the test suite (see test options below)'''
240 Scripting
.commands
.append('build')
241 Scripting
.commands
.append('testonly')