tevent: Fix epoll_mod_event() to cope with modifying a multiplexed fde event.
[Samba/gebeck_regimport.git] / selftest / wscript
blobc7637a19ac5837ab6acdc1537316b571f478691d
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 *
9 import types
11 def set_options(opt):
13 opt.add_option('--enable-selftest',
14 help=("enable options necessary for selftest (default=no)"),
15 action="store_true", dest='enable_selftest', default=False)
16 opt.add_option('--enable-coverage',
17 help=("enable options necessary for code coverage reporting on selftest (default=no)"),
18 action="store_true", dest='enable_coverage', default=False)
19 opt.add_option('--with-selftest-prefix',
20 help=("specify location of selftest directory (default=./st)"),
21 action="store", dest='SELFTEST_PREFIX', default='./st')
23 opt.ADD_COMMAND('test', cmd_test)
24 opt.ADD_COMMAND('testonly', cmd_testonly)
26 gr = opt.add_option_group('test options')
28 gr.add_option('--load-list',
29 help=("Load a test id list from a text file"),
30 action="store", dest='LOAD_LIST', default=None)
31 gr.add_option('--list',
32 help=("List available tests"),
33 action="store_true", dest='LIST', default=False)
34 gr.add_option('--tests',
35 help=("wildcard pattern of tests to run"),
36 action="store", dest='TESTS', default='')
37 gr.add_option('--filtered-subunit',
38 help=("output (xfail) filtered subunit"),
39 action="store_true", dest='FILTERED_SUBUNIT', default=False)
40 gr.add_option('--quick',
41 help=("enable only quick tests"),
42 action="store_true", dest='QUICKTEST', default=False)
43 gr.add_option('--slow',
44 help=("enable the really slow tests"),
45 action="store_true", dest='SLOWTEST', default=False)
46 gr.add_option('--testenv',
47 help=("start a terminal with the test environment setup"),
48 action="store_true", dest='TESTENV', default=False)
49 gr.add_option('--valgrind',
50 help=("use valgrind on client programs in the tests"),
51 action="store_true", dest='VALGRIND', default=False)
52 gr.add_option('--valgrind-log',
53 help=("where to put the valgrind log"),
54 action="store", dest='VALGRINDLOG', default=None)
55 gr.add_option('--valgrind-server',
56 help=("use valgrind on the server in the tests (opens an xterm)"),
57 action="store_true", dest='VALGRIND_SERVER', default=False)
58 gr.add_option('--screen',
59 help=("run the samba servers in screen sessions"),
60 action="store_true", dest='SCREEN', default=False)
61 gr.add_option('--gdbtest',
62 help=("run the servers within a gdb window"),
63 action="store_true", dest='GDBTEST', default=False)
64 gr.add_option('--fail-immediately',
65 help=("stop tests on first failure"),
66 action="store_true", dest='FAIL_IMMEDIATELY', default=False)
67 gr.add_option('--socket-wrapper-pcap',
68 help=("create a pcap file for each failing test"),
69 action="store_true", dest='SOCKET_WRAPPER_PCAP', default=False)
70 gr.add_option('--socket-wrapper-keep-pcap',
71 help=("create a pcap file for all individual test"),
72 action="store_true", dest='SOCKET_WRAPPER_KEEP_PCAP', default=False)
73 gr.add_option('--random-order', dest='RANDOM_ORDER', default=False,
74 action="store_true", help="Run testsuites in random order")
76 def configure(conf):
77 conf.env.SELFTEST_PREFIX = Options.options.SELFTEST_PREFIX
78 conf.env.enable_coverage = Options.options.enable_coverage
79 if conf.env.enable_coverage:
80 conf.ADD_LDFLAGS('-lgcov', testflags=True)
81 conf.ADD_CFLAGS('--coverage')
83 if Options.options.enable_selftest or Options.options.developer:
84 conf.DEFINE('ENABLE_SELFTEST', 1)
87 def cmd_testonly(opt):
88 '''run tests without doing a build first'''
89 env = LOAD_ENVIRONMENT()
90 opt.env = env
92 if (not CONFIG_SET(opt, 'NSS_WRAPPER') or
93 not CONFIG_SET(opt, 'UID_WRAPPER') or
94 not CONFIG_SET(opt, 'SOCKET_WRAPPER')):
95 print("ERROR: You must use --enable-selftest to enable selftest")
96 sys.exit(1)
98 os.environ['SAMBA_SELFTEST'] = '1'
100 env.TESTS = Options.options.TESTS
102 env.SUBUNIT_FORMATTER = os.getenv('SUBUNIT_FORMATTER')
103 if not env.SUBUNIT_FORMATTER:
104 env.SUBUNIT_FORMATTER = '${PYTHON} -u ${srcdir}/selftest/format-subunit --prefix=${SELFTEST_PREFIX} --immediate'
105 env.FILTER_XFAIL = '${PYTHON} -u ${srcdir}/selftest/filter-subunit --expected-failures=${srcdir}/selftest/knownfail --flapping=${srcdir}/selftest/flapping'
107 if Options.options.FAIL_IMMEDIATELY:
108 env.FILTER_XFAIL += ' --fail-immediately'
110 env.FORMAT_TEST_OUTPUT = '${SUBUNIT_FORMATTER}'
112 # clean any previous temporary files
113 os.system("rm -rf %s/tmp" % env.SELFTEST_PREFIX);
115 # put all command line options in the environment as TESTENV_*=*
116 for o in dir(Options.options):
117 if o[0:1] != '_':
118 val = getattr(Options.options, o, '')
119 if not issubclass(type(val), types.FunctionType) \
120 and not issubclass(type(val), types.MethodType):
121 os.environ['TESTENV_%s' % o.upper()] = str(getattr(Options.options, o, ''))
124 binary_mapping = ('nmblookup3:nmblookup,' +
125 'nmblookup4:nmblookup4,' +
126 'smbclient3:smbclient,' +
127 'smbclient4:smbclient4,' +
128 'smbtorture4:smbtorture,' +
129 'ntlm_auth3:ntlm_auth')
131 env.OPTIONS = '--binary-mapping=%s' % binary_mapping
132 if not Options.options.SLOWTEST:
133 env.OPTIONS += ' --exclude=${srcdir}/selftest/slow'
134 if Options.options.QUICKTEST:
135 env.OPTIONS += ' --quick --include=${srcdir}/selftest/quick'
136 if Options.options.LOAD_LIST:
137 env.OPTIONS += ' --load-list=%s' % Options.options.LOAD_LIST
138 if Options.options.TESTENV:
139 env.OPTIONS += ' --testenv'
140 if Options.options.SOCKET_WRAPPER_PCAP:
141 env.OPTIONS += ' --socket-wrapper-pcap'
142 if Options.options.SOCKET_WRAPPER_KEEP_PCAP:
143 env.OPTIONS += ' --socket-wrapper-keep-pcap'
144 if Options.options.RANDOM_ORDER:
145 env.OPTIONS += ' --random-order'
146 if os.environ.get('RUN_FROM_BUILD_FARM') is not None:
147 env.FILTER_OPTIONS = '${FILTER_XFAIL} --strip-passed-output'
148 else:
149 env.FILTER_OPTIONS = '${FILTER_XFAIL}'
151 if Options.options.VALGRIND:
152 os.environ['VALGRIND'] = 'valgrind -q --num-callers=30'
153 if Options.options.VALGRINDLOG is not None:
154 os.environ['VALGRIND'] += ' --log-file=%s' % Options.options.VALGRINDLOG
156 server_wrapper=''
158 if Options.options.VALGRIND_SERVER:
159 server_wrapper = '${srcdir}/selftest/valgrind_run _DUMMY=X'
160 elif Options.options.GDBTEST:
161 server_wrapper = '${srcdir}/selftest/gdb_run _DUMMY=X'
163 if Options.options.SCREEN:
164 server_wrapper = '${srcdir}/selftest/in_screen %s' % server_wrapper
165 os.environ['TERMINAL'] = EXPAND_VARIABLES(opt, '${srcdir}/selftest/in_screen')
166 elif server_wrapper != '':
167 server_wrapper = 'xterm -n server -l -e %s' % server_wrapper
169 if server_wrapper != '':
170 os.environ['SAMBA_VALGRIND'] = EXPAND_VARIABLES(opt, server_wrapper)
172 # this is needed for systems without rpath, or with rpath disabled
173 ADD_LD_LIBRARY_PATH('bin/shared')
174 ADD_LD_LIBRARY_PATH('bin/shared/private')
176 # if we are using a system version of ldb then we need to tell it to
177 # load modules from our modules path
178 if env.USING_SYSTEM_LDB:
179 os.environ['LDB_MODULES_PATH'] = 'bin/modules/ldb'
181 # tell build system where to find config.h
182 os.environ['VFSLIBDIR'] = os.path.abspath('bin/modules/vfs')
183 os.environ['CONFIG_H'] = 'bin/default/include/config.h'
185 st_done = os.path.join(env.SELFTEST_PREFIX, 'st_done')
186 if os.path.exists(st_done):
187 os.unlink(st_done)
189 if not os.path.isdir(env.SELFTEST_PREFIX):
190 os.makedirs(env.SELFTEST_PREFIX, int('755', 8))
192 env.TESTLISTS = ('--testlist="${PYTHON} ${srcdir}/selftest/tests.py|" ' +
193 '--testlist="${PYTHON} ${srcdir}/source3/selftest/tests.py|" ' +
194 '--testlist="${PYTHON} ${srcdir}/source4/selftest/tests.py|"')
196 if CONFIG_SET(opt, 'AD_DC_BUILD_IS_ENABLED'):
197 env.SELFTEST_TARGET="samba"
198 else:
199 env.SELFTEST_TARGET="samba3"
201 # We use the full path rather than relative path because it cause problems on some plateforms (ie. solaris 8).
202 env.CORE_COMMAND = '${PERL} ${srcdir}/selftest/selftest.pl --target=${SELFTEST_TARGET} --prefix=${SELFTEST_PREFIX} --srcdir=${srcdir} --exclude=${srcdir}/selftest/skip ${TESTLISTS} ${OPTIONS} ${TESTS}'
203 if Options.options.LIST:
204 cmd = '${CORE_COMMAND} --list'
205 else:
206 env.OPTIONS += ' --socket-wrapper'
207 cmd = '(${CORE_COMMAND} && touch ${SELFTEST_PREFIX}/st_done) | ${FILTER_OPTIONS}'
208 if (os.environ.get('RUN_FROM_BUILD_FARM') is None and
209 not Options.options.FILTERED_SUBUNIT):
210 cmd += ' | tee ${SELFTEST_PREFIX}/subunit | ${FORMAT_TEST_OUTPUT}'
211 else:
212 cmd += ' | ${FILTER_OPTIONS}'
213 runcmd = EXPAND_VARIABLES(opt, cmd)
215 print("test: running %s" % runcmd)
216 ret = RUN_COMMAND(cmd, env=env)
218 if os.path.exists(".testrepository") and not Options.options.LIST:
219 testrcmd = 'testr load -q < ${SELFTEST_PREFIX}/subunit > /dev/null'
220 runcmd = EXPAND_VARIABLES(opt, testrcmd)
221 RUN_COMMAND(runcmd, env=env)
223 if ret != 0:
224 print("ERROR: test failed with exit code %d" % ret)
225 sys.exit(ret)
227 if not Options.options.LIST and not os.path.exists(st_done):
228 print("ERROR: test command failed to complete")
229 sys.exit(1)
232 ########################################################################
233 # main test entry point
234 def cmd_test(opt):
235 '''Run the test suite (see test options below)'''
237 # if running all tests, then force a symbol check
238 env = LOAD_ENVIRONMENT()
239 CHECK_MAKEFLAGS(env)
240 if not Options.options.TESTS and not Options.options.TESTENV:
241 Options.options.DUP_SYMBOLCHECK = True
243 Scripting.commands.append('build')
244 Scripting.commands.append('testonly')