samba-tool: Some more unifications...
[Samba/gbeck.git] / selftest / wscript
blob9ea2f6fdd4a7f1485e83bdfd9f4ce8fd96e798bd
1 #!/usr/bin/env python
2 # vim: expandtab ft=python
4 # selftest main code.
6 import Scripting, os, Options, Utils, Environment, optparse, sys
7 from samba_utils import *
8 from samba_autoconf import *
10 def set_options(opt):
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)
73 def configure(conf):
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()
87 opt.env = env
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")
93 sys.exit(1)
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):
114 if o[0:1] != '_':
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'
139 else:
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
147 server_wrapper=''
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):
178 os.unlink(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}/selftest/tests.py|" ' +
184 '--testlist="${PYTHON} ${srcdir}/source3/selftest/tests.py|" ' +
185 '--testlist="${PYTHON} ${srcdir}/source4/selftest/tests.py|"')
187 if CONFIG_SET(opt, 'AD_DC_BUILD_IS_ENABLED'):
188 env.SELFTEST_TARGET="samba"
189 else:
190 env.SELFTEST_TARGET="samba3"
192 # We use the full path rather than relative path because it cause problems on some plateforms (ie. solaris 8).
193 env.CORE_COMMAND = '${PERL} ${srcdir}/selftest/selftest.pl --target=${SELFTEST_TARGET} --prefix=${SELFTEST_PREFIX} --srcdir=${srcdir} --exclude=${srcdir}/selftest/skip ${TESTLISTS} ${OPTIONS} ${TESTS}'
194 if Options.options.LIST:
195 cmd = '${CORE_COMMAND} --list'
196 else:
197 env.OPTIONS += ' --socket-wrapper'
198 cmd = '(${CORE_COMMAND} && touch ${SELFTEST_PREFIX}/st_done) | ${FILTER_OPTIONS}'
199 if (os.environ.get('RUN_FROM_BUILD_FARM') is None and
200 not Options.options.FILTERED_SUBUNIT):
201 cmd += ' | tee ${SELFTEST_PREFIX}/subunit | ${FORMAT_TEST_OUTPUT}'
202 else:
203 cmd += ' | ${FILTER_OPTIONS}'
204 runcmd = EXPAND_VARIABLES(opt, cmd)
206 print("test: running %s" % runcmd)
207 ret = RUN_COMMAND(cmd, env=env)
209 if os.path.exists(".testrepository") and not Options.options.LIST:
210 testrcmd = 'testr load -q < ${SELFTEST_PREFIX}/subunit > /dev/null'
211 runcmd = EXPAND_VARIABLES(opt, testrcmd)
212 RUN_COMMAND(runcmd, env=env)
214 if ret != 0:
215 print("ERROR: test failed with exit code %d" % ret)
216 sys.exit(ret)
218 if not Options.options.LIST and not os.path.exists(st_done):
219 print("ERROR: test command failed to complete")
220 sys.exit(1)
223 ########################################################################
224 # main test entry point
225 def cmd_test(opt):
226 '''Run the test suite (see test options below)'''
228 # if running all tests, then force a symbol check
229 env = LOAD_ENVIRONMENT()
230 CHECK_MAKEFLAGS(env)
231 if not Options.options.TESTS and not Options.options.TESTENV:
232 Options.options.DUP_SYMBOLCHECK = True
234 Scripting.commands.append('build')
235 Scripting.commands.append('testonly')