s3:util: fix usage of popt_burn_cmdline_password()
[Samba/vl.git] / selftest / wscript
blob4733dc17cd1d4ddd257b4cdcbe914e8baa4365b7
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)
72 gr.add_option('--random-order', dest='RANDOM_ORDER', default=False,
73 action="store_true", help="Run testsuites in random order")
75 def configure(conf):
76 conf.env.SELFTEST_PREFIX = Options.options.SELFTEST_PREFIX
77 conf.env.enable_coverage = Options.options.enable_coverage
78 if conf.env.enable_coverage:
79 conf.ADD_LDFLAGS('-lgcov', testflags=True)
80 conf.ADD_CFLAGS('--coverage')
82 if Options.options.enable_selftest or Options.options.developer:
83 conf.DEFINE('ENABLE_SELFTEST', 1)
86 def cmd_testonly(opt):
87 '''run tests without doing a build first'''
88 env = LOAD_ENVIRONMENT()
89 opt.env = env
91 if (not CONFIG_SET(opt, 'NSS_WRAPPER') or
92 not CONFIG_SET(opt, 'UID_WRAPPER') or
93 not CONFIG_SET(opt, 'SOCKET_WRAPPER')):
94 print("ERROR: You must use --enable-selftest to enable selftest")
95 sys.exit(1)
97 os.environ['SAMBA_SELFTEST'] = '1'
99 env.TESTS = Options.options.TESTS
101 env.SUBUNIT_FORMATTER = os.getenv('SUBUNIT_FORMATTER')
102 if not env.SUBUNIT_FORMATTER:
103 env.SUBUNIT_FORMATTER = '${PYTHON} -u ${srcdir}/selftest/format-subunit --prefix=${SELFTEST_PREFIX} --immediate'
104 env.FILTER_XFAIL = '${PYTHON} -u ${srcdir}/selftest/filter-subunit --expected-failures=${srcdir}/selftest/knownfail --flapping=${srcdir}/selftest/flapping'
106 if Options.options.FAIL_IMMEDIATELY:
107 env.FILTER_XFAIL += ' --fail-immediately'
109 env.FORMAT_TEST_OUTPUT = '${SUBUNIT_FORMATTER}'
111 # clean any previous temporary files
112 os.system("rm -rf %s/tmp" % env.SELFTEST_PREFIX);
114 # put all command line options in the environment as TESTENV_*=*
115 for o in dir(Options.options):
116 if o[0:1] != '_':
117 os.environ['TESTENV_%s' % o.upper()] = str(getattr(Options.options, o, ''))
119 binary_mapping = ('nmblookup3:nmblookup,' +
120 'nmblookup4:nmblookup4,' +
121 'smbclient3:smbclient,' +
122 'smbclient4:smbclient4,' +
123 'smbtorture4:smbtorture,' +
124 'ntlm_auth3:ntlm_auth')
126 env.OPTIONS = '--binary-mapping=%s' % binary_mapping
127 if not Options.options.SLOWTEST:
128 env.OPTIONS += ' --exclude=${srcdir}/selftest/slow'
129 if Options.options.QUICKTEST:
130 env.OPTIONS += ' --quick --include=${srcdir}/selftest/quick'
131 if Options.options.LOAD_LIST:
132 env.OPTIONS += ' --load-list=%s' % Options.options.LOAD_LIST
133 if Options.options.TESTENV:
134 env.OPTIONS += ' --testenv'
135 if Options.options.SOCKET_WRAPPER_PCAP:
136 env.OPTIONS += ' --socket-wrapper-pcap'
137 if Options.options.SOCKET_WRAPPER_KEEP_PCAP:
138 env.OPTIONS += ' --socket-wrapper-keep-pcap'
139 if Options.options.RANDOM_ORDER:
140 env.OPTIONS += ' --random-order'
141 if os.environ.get('RUN_FROM_BUILD_FARM') is not None:
142 env.FILTER_OPTIONS = '${FILTER_XFAIL} --strip-passed-output'
143 else:
144 env.FILTER_OPTIONS = '${FILTER_XFAIL}'
146 if Options.options.VALGRIND:
147 os.environ['VALGRIND'] = 'valgrind -q --num-callers=30'
148 if Options.options.VALGRINDLOG is not None:
149 os.environ['VALGRIND'] += ' --log-file=%s' % Options.options.VALGRINDLOG
151 server_wrapper=''
153 if Options.options.VALGRIND_SERVER:
154 server_wrapper = '${srcdir}/selftest/valgrind_run _DUMMY=X'
155 elif Options.options.GDBTEST:
156 server_wrapper = '${srcdir}/selftest/gdb_run _DUMMY=X'
158 if Options.options.SCREEN:
159 server_wrapper = '${srcdir}/selftest/in_screen %s' % server_wrapper
160 os.environ['TERMINAL'] = EXPAND_VARIABLES(opt, '${srcdir}/selftest/in_screen')
161 elif server_wrapper != '':
162 server_wrapper = 'xterm -n server -l -e %s' % server_wrapper
164 if server_wrapper != '':
165 os.environ['SAMBA_VALGRIND'] = EXPAND_VARIABLES(opt, server_wrapper)
167 # this is needed for systems without rpath, or with rpath disabled
168 ADD_LD_LIBRARY_PATH('bin/shared')
169 ADD_LD_LIBRARY_PATH('bin/shared/private')
171 # if we are using a system version of ldb then we need to tell it to
172 # load modules from our modules path
173 if env.USING_SYSTEM_LDB:
174 os.environ['LDB_MODULES_PATH'] = 'bin/modules/ldb'
176 # tell build system where to find config.h
177 os.environ['VFSLIBDIR'] = os.path.abspath('bin/modules/vfs')
178 os.environ['CONFIG_H'] = 'bin/default/include/config.h'
180 st_done = os.path.join(env.SELFTEST_PREFIX, 'st_done')
181 if os.path.exists(st_done):
182 os.unlink(st_done)
184 if not os.path.isdir(env.SELFTEST_PREFIX):
185 os.makedirs(env.SELFTEST_PREFIX, int('755', 8))
187 env.TESTLISTS = ('--testlist="${PYTHON} ${srcdir}/selftest/tests.py|" ' +
188 '--testlist="${PYTHON} ${srcdir}/source3/selftest/tests.py|" ' +
189 '--testlist="${PYTHON} ${srcdir}/source4/selftest/tests.py|"')
191 if CONFIG_SET(opt, 'AD_DC_BUILD_IS_ENABLED'):
192 env.SELFTEST_TARGET="samba"
193 else:
194 env.SELFTEST_TARGET="samba3"
196 # We use the full path rather than relative path because it cause problems on some plateforms (ie. solaris 8).
197 env.CORE_COMMAND = '${PERL} ${srcdir}/selftest/selftest.pl --target=${SELFTEST_TARGET} --prefix=${SELFTEST_PREFIX} --srcdir=${srcdir} --exclude=${srcdir}/selftest/skip ${TESTLISTS} ${OPTIONS} ${TESTS}'
198 if Options.options.LIST:
199 cmd = '${CORE_COMMAND} --list'
200 else:
201 env.OPTIONS += ' --socket-wrapper'
202 cmd = '(${CORE_COMMAND} && touch ${SELFTEST_PREFIX}/st_done) | ${FILTER_OPTIONS}'
203 if (os.environ.get('RUN_FROM_BUILD_FARM') is None and
204 not Options.options.FILTERED_SUBUNIT):
205 cmd += ' | tee ${SELFTEST_PREFIX}/subunit | ${FORMAT_TEST_OUTPUT}'
206 else:
207 cmd += ' | ${FILTER_OPTIONS}'
208 runcmd = EXPAND_VARIABLES(opt, cmd)
210 print("test: running %s" % runcmd)
211 ret = RUN_COMMAND(cmd, env=env)
213 if os.path.exists(".testrepository") and not Options.options.LIST:
214 testrcmd = 'testr load -q < ${SELFTEST_PREFIX}/subunit > /dev/null'
215 runcmd = EXPAND_VARIABLES(opt, testrcmd)
216 RUN_COMMAND(runcmd, env=env)
218 if ret != 0:
219 print("ERROR: test failed with exit code %d" % ret)
220 sys.exit(ret)
222 if not Options.options.LIST and not os.path.exists(st_done):
223 print("ERROR: test command failed to complete")
224 sys.exit(1)
227 ########################################################################
228 # main test entry point
229 def cmd_test(opt):
230 '''Run the test suite (see test options below)'''
232 # if running all tests, then force a symbol check
233 env = LOAD_ENVIRONMENT()
234 CHECK_MAKEFLAGS(env)
235 if not Options.options.TESTS and not Options.options.TESTENV:
236 Options.options.DUP_SYMBOLCHECK = True
238 Scripting.commands.append('build')
239 Scripting.commands.append('testonly')