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('--enable-coverage',
16 help=("enable options necessary for code coverage reporting on selftest (default=no)"),
17 action
="store_true", dest
='enable_coverage', default
=False)
18 opt
.add_option('--with-selftest-prefix',
19 help=("specify location of selftest directory (default=./st)"),
20 action
="store", dest
='SELFTEST_PREFIX', default
='./st')
22 opt
.ADD_COMMAND('test', cmd_test
)
23 opt
.ADD_COMMAND('testonly', cmd_testonly
)
25 gr
= opt
.add_option_group('test options')
27 gr
.add_option('--load-list',
28 help=("Load a test id list from a text file"),
29 action
="store", dest
='LOAD_LIST', default
=None)
30 gr
.add_option('--list',
31 help=("List available tests"),
32 action
="store_true", dest
='LIST', default
=False)
33 gr
.add_option('--tests',
34 help=("wildcard pattern of tests to run"),
35 action
="store", dest
='TESTS', default
='')
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
75 conf
.env
.enable_coverage
= Options
.options
.enable_coverage
76 if conf
.env
.enable_coverage
:
77 conf
.ADD_LDFLAGS('-lgcov', testflags
=True)
78 conf
.ADD_CFLAGS('--coverage')
80 if Options
.options
.enable_selftest
or Options
.options
.developer
:
81 conf
.DEFINE('ENABLE_SELFTEST', 1)
84 def cmd_testonly(opt
):
85 '''run tests without doing a build first'''
86 env
= LOAD_ENVIRONMENT()
89 if (not CONFIG_SET(opt
, 'NSS_WRAPPER') or
90 not CONFIG_SET(opt
, 'UID_WRAPPER') or
91 not CONFIG_SET(opt
, 'SOCKET_WRAPPER')):
92 print("ERROR: You must use --enable-selftest to enable selftest")
95 os
.environ
['SAMBA_SELFTEST'] = '1'
97 env
.TESTS
= Options
.options
.TESTS
99 env
.SUBUNIT_FORMATTER
= os
.getenv('SUBUNIT_FORMATTER')
100 if not env
.SUBUNIT_FORMATTER
:
101 env
.SUBUNIT_FORMATTER
= '${PYTHON} -u ${srcdir}/selftest/format-subunit --prefix=${SELFTEST_PREFIX} --immediate'
102 env
.FILTER_XFAIL
= '${PYTHON} -u ${srcdir}/selftest/filter-subunit --expected-failures=${srcdir}/selftest/knownfail --flapping=${srcdir}/selftest/flapping'
104 if Options
.options
.FAIL_IMMEDIATELY
:
105 env
.FILTER_XFAIL
+= ' --fail-immediately'
107 env
.FORMAT_TEST_OUTPUT
= '${SUBUNIT_FORMATTER}'
109 # clean any previous temporary files
110 os
.system("rm -rf %s/tmp" % env
.SELFTEST_PREFIX
);
112 # put all command line options in the environment as TESTENV_*=*
113 for o
in dir(Options
.options
):
115 os
.environ
['TESTENV_%s' % o
.upper()] = str(getattr(Options
.options
, o
, ''))
117 binary_mapping
= ('nmblookup3:nmblookup,' +
118 'nmblookup4:nmblookup4,' +
119 'smbclient3:smbclient,' +
120 'smbclient4:smbclient4,' +
121 'smbtorture4:smbtorture,' +
122 'ntlm_auth3:ntlm_auth3')
124 env
.OPTIONS
= '--binary-mapping=%s' % binary_mapping
125 if not Options
.options
.SLOWTEST
:
126 env
.OPTIONS
+= ' --exclude=${srcdir}/selftest/slow'
127 if Options
.options
.QUICKTEST
:
128 env
.OPTIONS
+= ' --quick --include=${srcdir}/selftest/quick'
129 if Options
.options
.LOAD_LIST
:
130 env
.OPTIONS
+= ' --load-list=%s' % Options
.options
.LOAD_LIST
131 if Options
.options
.TESTENV
:
132 env
.OPTIONS
+= ' --testenv'
133 if Options
.options
.SOCKET_WRAPPER_PCAP
:
134 env
.OPTIONS
+= ' --socket-wrapper-pcap'
135 if Options
.options
.SOCKET_WRAPPER_KEEP_PCAP
:
136 env
.OPTIONS
+= ' --socket-wrapper-keep-pcap'
137 if os
.environ
.get('RUN_FROM_BUILD_FARM') is not None:
138 env
.FILTER_OPTIONS
= '${FILTER_XFAIL} --strip-passed-output'
140 env
.FILTER_OPTIONS
= '${FILTER_XFAIL}'
142 if Options
.options
.VALGRIND
:
143 os
.environ
['VALGRIND'] = 'valgrind -q --num-callers=30'
144 if Options
.options
.VALGRINDLOG
is not None:
145 os
.environ
['VALGRIND'] += ' --log-file=%s' % Options
.options
.VALGRINDLOG
149 if Options
.options
.VALGRIND_SERVER
:
150 server_wrapper
= '${srcdir}/selftest/valgrind_run _DUMMY=X'
151 elif Options
.options
.GDBTEST
:
152 server_wrapper
= '${srcdir}/selftest/gdb_run _DUMMY=X'
154 if Options
.options
.SCREEN
:
155 server_wrapper
= '${srcdir}/selftest/in_screen %s' % server_wrapper
156 os
.environ
['TERMINAL'] = EXPAND_VARIABLES(opt
, '${srcdir}/selftest/in_screen')
157 elif server_wrapper
!= '':
158 server_wrapper
= 'xterm -n server -l -e %s' % server_wrapper
160 if server_wrapper
!= '':
161 os
.environ
['SAMBA_VALGRIND'] = EXPAND_VARIABLES(opt
, server_wrapper
)
163 # this is needed for systems without rpath, or with rpath disabled
164 ADD_LD_LIBRARY_PATH('bin/shared')
165 ADD_LD_LIBRARY_PATH('bin/shared/private')
167 # if we are using a system version of ldb then we need to tell it to
168 # load modules from our modules path
169 if env
.USING_SYSTEM_LDB
:
170 os
.environ
['LDB_MODULES_PATH'] = 'bin/modules/ldb'
172 # tell build system where to find config.h
173 os
.environ
['VFSLIBDIR'] = os
.path
.abspath('bin/modules/vfs')
174 os
.environ
['CONFIG_H'] = 'bin/default/include/config.h'
176 st_done
= os
.path
.join(env
.SELFTEST_PREFIX
, 'st_done')
177 if os
.path
.exists(st_done
):
180 if not os
.path
.isdir(env
.SELFTEST_PREFIX
):
181 os
.makedirs(env
.SELFTEST_PREFIX
, int('755', 8))
183 env
.TESTLISTS
= ('--testlist="${PYTHON} ${srcdir}/source3/selftest/tests.py|" ' +
184 '--testlist="${PYTHON} ${srcdir}/source4/selftest/tests.py|"')
186 if CONFIG_SET(opt
, 'AD_DC_BUILD_IS_ENABLED'):
187 env
.SELFTEST_TARGET
="samba"
189 env
.SELFTEST_TARGET
="samba3"
191 # We use the full path rather than relative path because it cause problems on some plateforms (ie. solaris 8).
192 env
.CORE_COMMAND
= '${PERL} ${srcdir}/selftest/selftest.pl --target=${SELFTEST_TARGET} --prefix=${SELFTEST_PREFIX} --srcdir=${srcdir} --exclude=${srcdir}/selftest/skip ${TESTLISTS} ${OPTIONS} ${TESTS}'
193 if Options
.options
.LIST
:
194 cmd
= '${CORE_COMMAND} --list'
196 env
.OPTIONS
+= ' --socket-wrapper'
197 cmd
= '(${CORE_COMMAND} && touch ${SELFTEST_PREFIX}/st_done) | ${FILTER_OPTIONS}'
198 if (os
.environ
.get('RUN_FROM_BUILD_FARM') is None and
199 not Options
.options
.FILTERED_SUBUNIT
):
200 cmd
+= ' | tee ${SELFTEST_PREFIX}/subunit | ${FORMAT_TEST_OUTPUT}'
202 cmd
+= ' | ${FILTER_OPTIONS}'
203 runcmd
= EXPAND_VARIABLES(opt
, cmd
)
205 print("test: running %s" % runcmd
)
206 ret
= RUN_COMMAND(cmd
, env
=env
)
208 if os
.path
.exists(".testrepository") and not Options
.options
.LIST
:
209 testrcmd
= 'testr load -q < ${SELFTEST_PREFIX}/subunit > /dev/null'
210 runcmd
= EXPAND_VARIABLES(opt
, testrcmd
)
211 RUN_COMMAND(runcmd
, env
=env
)
214 print("ERROR: test failed with exit code %d" % ret
)
217 if not Options
.options
.LIST
and not os
.path
.exists(st_done
):
218 print("ERROR: test command failed to complete")
222 ########################################################################
223 # main test entry point
225 '''Run the test suite (see test options below)'''
227 # if running all tests, then force a symbol check
228 env
= LOAD_ENVIRONMENT()
230 if not Options
.options
.TESTS
and not Options
.options
.TESTENV
:
231 Options
.options
.DUP_SYMBOLCHECK
= True
233 Scripting
.commands
.append('build')
234 Scripting
.commands
.append('testonly')