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('--filtered-subunit',
34 help=("output (xfail) filtered subunit"),
35 action
="store_true", dest
='FILTERED_SUBUNIT', default
=False)
36 gr
.add_option('--quick',
37 help=("enable only quick tests"),
38 action
="store_true", dest
='QUICKTEST', default
=False)
39 gr
.add_option('--slow',
40 help=("enable the really slow tests"),
41 action
="store_true", dest
='SLOWTEST', default
=False)
42 gr
.add_option('--testenv',
43 help=("start a terminal with the test environment setup"),
44 action
="store_true", dest
='TESTENV', default
=False)
45 gr
.add_option('--valgrind',
46 help=("use valgrind on client programs in the tests"),
47 action
="store_true", dest
='VALGRIND', default
=False)
48 gr
.add_option('--valgrind-log',
49 help=("where to put the valgrind log"),
50 action
="store", dest
='VALGRINDLOG', default
=None)
51 gr
.add_option('--valgrind-server',
52 help=("use valgrind on the server in the tests (opens an xterm)"),
53 action
="store_true", dest
='VALGRIND_SERVER', default
=False)
54 gr
.add_option('--screen',
55 help=("run the samba servers in screen sessions"),
56 action
="store_true", dest
='SCREEN', default
=False)
57 gr
.add_option('--gdbtest',
58 help=("run the servers within a gdb window"),
59 action
="store_true", dest
='GDBTEST', default
=False)
60 gr
.add_option('--fail-immediately',
61 help=("stop tests on first failure"),
62 action
="store_true", dest
='FAIL_IMMEDIATELY', default
=False)
63 gr
.add_option('--socket-wrapper-pcap',
64 help=("create a pcap file for each failing test"),
65 action
="store_true", dest
='SOCKET_WRAPPER_PCAP', default
=False)
66 gr
.add_option('--socket-wrapper-keep-pcap',
67 help=("create a pcap file for all individual test"),
68 action
="store_true", dest
='SOCKET_WRAPPER_KEEP_PCAP', default
=False)
71 conf
.env
.SELFTEST_PREFIX
= Options
.options
.SELFTEST_PREFIX
73 def cmd_testonly(opt
):
74 '''run tests without doing a build first'''
75 env
= LOAD_ENVIRONMENT()
78 if (not CONFIG_SET(opt
, 'NSS_WRAPPER') or
79 not CONFIG_SET(opt
, 'UID_WRAPPER') or
80 not CONFIG_SET(opt
, 'SOCKET_WRAPPER')):
81 print("ERROR: You must use --enable-selftest to enable selftest")
84 os
.environ
['SAMBA_SELFTEST'] = '1'
86 env
.TESTS
= Options
.options
.TESTS
88 env
.SUBUNIT_FORMATTER
= os
.getenv('SUBUNIT_FORMATTER')
89 if not env
.SUBUNIT_FORMATTER
:
90 env
.SUBUNIT_FORMATTER
= '${PYTHON} -u ${srcdir}/selftest/format-subunit --prefix=${SELFTEST_PREFIX} --immediate'
91 env
.FILTER_XFAIL
= '${PYTHON} -u ${srcdir}/selftest/filter-subunit --expected-failures=${srcdir}/selftest/knownfail --flapping=${srcdir}/selftest/flapping'
93 if Options
.options
.FAIL_IMMEDIATELY
:
94 env
.FILTER_XFAIL
+= ' --fail-immediately'
96 env
.FORMAT_TEST_OUTPUT
= '${SUBUNIT_FORMATTER}'
98 # clean any previous temporary files
99 os
.system("rm -rf %s/tmp" % env
.SELFTEST_PREFIX
);
101 # put all command line options in the environment as TESTENV_*=*
102 for o
in dir(Options
.options
):
104 os
.environ
['TESTENV_%s' % o
.upper()] = str(getattr(Options
.options
, o
, ''))
106 binary_mapping
= ('nmblookup3:nmblookup3,' +
107 'smbclient3:smbclient3,' +
108 'smbtorture4:smbtorture,' +
109 'ntlm_auth3:ntlm_auth3')
111 env
.OPTIONS
= '--binary-mapping=%s' % binary_mapping
112 if not Options
.options
.SLOWTEST
:
113 env
.OPTIONS
+= ' --exclude=${srcdir}/selftest/slow'
114 if Options
.options
.QUICKTEST
:
115 env
.OPTIONS
+= ' --quick --include=${srcdir}/selftest/quick'
116 if Options
.options
.LOAD_LIST
:
117 env
.OPTIONS
+= ' --load-list=%s' % Options
.options
.LOAD_LIST
118 if Options
.options
.TESTENV
:
119 env
.OPTIONS
+= ' --testenv'
120 if Options
.options
.SOCKET_WRAPPER_PCAP
:
121 env
.OPTIONS
+= ' --socket-wrapper-pcap'
122 if Options
.options
.SOCKET_WRAPPER_KEEP_PCAP
:
123 env
.OPTIONS
+= ' --socket-wrapper-keep-pcap'
124 if os
.environ
.get('RUN_FROM_BUILD_FARM') is not None:
125 env
.FILTER_OPTIONS
= '${FILTER_XFAIL} --strip-passed-output'
127 env
.FILTER_OPTIONS
= '${FILTER_XFAIL}'
129 if Options
.options
.VALGRIND
:
130 os
.environ
['VALGRIND'] = 'valgrind -q --num-callers=30'
131 if Options
.options
.VALGRINDLOG
is not None:
132 os
.environ
['VALGRIND'] += ' --log-file=%s' % Options
.options
.VALGRINDLOG
136 if Options
.options
.VALGRIND_SERVER
:
137 server_wrapper
= '${srcdir}/selftest/valgrind_run _DUMMY=X'
138 elif Options
.options
.GDBTEST
:
139 server_wrapper
= '${srcdir}/selftest/gdb_run _DUMMY=X'
141 if Options
.options
.SCREEN
:
142 server_wrapper
= '${srcdir}/selftest/in_screen %s' % server_wrapper
143 os
.environ
['TERMINAL'] = EXPAND_VARIABLES(opt
, '${srcdir}/selftest/in_screen')
144 elif server_wrapper
!= '':
145 server_wrapper
= 'xterm -n server -l -e %s' % server_wrapper
147 if server_wrapper
!= '':
148 os
.environ
['SAMBA_VALGRIND'] = EXPAND_VARIABLES(opt
, server_wrapper
)
150 # this is needed for systems without rpath, or with rpath disabled
151 ADD_LD_LIBRARY_PATH('bin/shared')
152 ADD_LD_LIBRARY_PATH('bin/shared/private')
154 # if we are using a system version of ldb then we need to tell it to
155 # load modules from our modules path
156 if env
.USING_SYSTEM_LDB
:
157 os
.environ
['LDB_MODULES_PATH'] = 'bin/modules/ldb'
160 os
.environ
['BUILD_TDB2'] = '1'
162 # tell build system where to find config.h
163 os
.environ
['VFSLIBDIR'] = os
.path
.abspath('bin/modules/vfs')
164 os
.environ
['CONFIG_H'] = 'bin/default/include/config.h'
166 st_done
= os
.path
.join(env
.SELFTEST_PREFIX
, 'st_done')
167 if os
.path
.exists(st_done
):
170 if not os
.path
.isdir(env
.SELFTEST_PREFIX
):
171 os
.makedirs(env
.SELFTEST_PREFIX
, int('755', 8))
173 env
.TESTLISTS
= ('--testlist="${PYTHON} ${srcdir}/source3/selftest/tests.py|" ' +
174 '--testlist="${PYTHON} ${srcdir}/source4/selftest/tests.py|"')
176 # We use the full path rather than relative path because it cause problems on some plateforms (ie. solaris 8).
177 env
.CORE_COMMAND
= '${PERL} ${srcdir}/selftest/selftest.pl --target=samba --prefix=${SELFTEST_PREFIX} --srcdir=${srcdir} --exclude=${srcdir}/selftest/skip ${TESTLISTS} ${OPTIONS} ${TESTS}'
178 if Options
.options
.LIST
:
179 cmd
= '${CORE_COMMAND} --list'
181 env
.OPTIONS
+= ' --socket-wrapper'
182 cmd
= '(${CORE_COMMAND} && touch ${SELFTEST_PREFIX}/st_done) | ${FILTER_OPTIONS}'
183 if (os
.environ
.get('RUN_FROM_BUILD_FARM') is None and
184 not Options
.options
.FILTERED_SUBUNIT
):
185 cmd
+= ' | tee ${SELFTEST_PREFIX}/subunit | ${FORMAT_TEST_OUTPUT}'
186 runcmd
= EXPAND_VARIABLES(opt
, cmd
)
188 print("test: running %s" % runcmd
)
189 ret
= RUN_COMMAND(cmd
, env
=env
)
191 if os
.path
.exists(".testrepository") and not Options
.options
.LIST
:
192 testrcmd
= 'testr load -q < ${SELFTEST_PREFIX}/subunit > /dev/null'
193 runcmd
= EXPAND_VARIABLES(opt
, testrcmd
)
194 RUN_COMMAND(runcmd
, env
=env
)
197 print("ERROR: test failed with exit code %d" % ret
)
200 if not Options
.options
.LIST
and not os
.path
.exists(st_done
):
201 print("ERROR: test command failed to complete")
205 ########################################################################
206 # main test entry point
208 '''Run the test suite (see test options below)'''
210 # if running all tests, then force a symbol check
211 env
= LOAD_ENVIRONMENT()
213 if not Options
.options
.TESTS
:
214 Options
.options
.DUP_SYMBOLCHECK
= True
216 Scripting
.commands
.append('build')
217 Scripting
.commands
.append('testonly')