source3/lib/util_tdb.c: operation timeout support for TDB2.
[Samba/gbeck.git] / selftest / wscript
blobab9f269b79270da0d84062169a210c95e16f5eaa
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('--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('--target',
34 help=("target of samba3 or samba4"),
35 action="store", dest='TARGET', default=None)
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
76 def combine_files(file1, file2, outfile):
78 f1 = open(file1)
79 f2 = open(file2)
80 of = open(outfile, mode='w')
81 for line in f1:
82 of.write(line)
83 for line in f2:
84 of.write(line)
85 f1.close()
86 f2.close()
87 of.close()
89 def cmd_testonly(opt):
90 '''run tests without doing a build first'''
91 env = LOAD_ENVIRONMENT()
92 opt.env = env
94 if (not CONFIG_SET(opt, 'NSS_WRAPPER') or
95 not CONFIG_SET(opt, 'UID_WRAPPER') or
96 not CONFIG_SET(opt, 'SOCKET_WRAPPER')):
97 print("ERROR: You must use --enable-selftest to enable selftest")
98 sys.exit(1)
100 os.environ['SAMBA_SELFTEST'] = '1'
102 env.TESTS = Options.options.TESTS
104 env.SUBUNIT_FORMATTER = os.getenv('SUBUNIT_FORMATTER')
105 if not env.SUBUNIT_FORMATTER:
106 env.SUBUNIT_FORMATTER = '${PYTHON} -u ${srcdir}/selftest/format-subunit --prefix=${SELFTEST_PREFIX} --immediate'
107 env.FILTER_XFAIL = '${PYTHON} -u ${srcdir}/selftest/filter-subunit --expected-failures=${SELFTEST_DIR}/knownfail'
109 if Options.options.FAIL_IMMEDIATELY:
110 env.FILTER_XFAIL += ' --fail-immediately'
112 env.FORMAT_TEST_OUTPUT = '${SUBUNIT_FORMATTER}'
114 # clean any previous temporary files
115 os.system("rm -rf %s/tmp" % env.SELFTEST_PREFIX);
117 # put all command line options in the environment as TESTENV_*=*
118 for o in dir(Options.options):
119 if o[0:1] != '_':
120 os.environ['TESTENV_%s' % o.upper()] = str(getattr(Options.options, o, ''))
122 binary_mapping = ('nmblookup3:nmblookup3,' +
123 'smbclient3:smbclient3,' +
124 'smbtorture4:smbtorture,' +
125 'ntlm_auth3:ntlm_auth3')
127 env.OPTIONS = '--binary-mapping=%s' % binary_mapping
128 if not Options.options.SLOWTEST:
129 env.OPTIONS += ' --exclude=${SELFTEST_DIR}/slow'
130 if Options.options.QUICKTEST:
131 env.OPTIONS += ' --quick --include=${SELFTEST_DIR}/quick'
132 if Options.options.LOAD_LIST:
133 env.OPTIONS += ' --load-list=%s' % Options.options.LOAD_LIST
134 if Options.options.TESTENV:
135 env.OPTIONS += ' --testenv'
136 if Options.options.SOCKET_WRAPPER_PCAP:
137 env.OPTIONS += ' --socket-wrapper-pcap'
138 if Options.options.SOCKET_WRAPPER_KEEP_PCAP:
139 env.OPTIONS += ' --socket-wrapper-keep-pcap'
140 if Options.options.LIST:
141 env.OPTIONS += ' --list'
142 if os.environ.get('RUN_FROM_BUILD_FARM') is not None:
143 env.FILTER_OPTIONS = '${FILTER_XFAIL} --strip-passed-output'
144 else:
145 env.FILTER_OPTIONS = '${FILTER_XFAIL}'
147 if Options.options.VALGRIND:
148 os.environ['VALGRIND'] = 'valgrind -q --num-callers=30'
149 if Options.options.VALGRINDLOG is not None:
150 os.environ['VALGRIND'] += ' --log-file=%s' % Options.options.VALGRINDLOG
152 server_wrapper=''
154 if Options.options.VALGRIND_SERVER:
155 server_wrapper = '${srcdir}/selftest/valgrind_run _DUMMY=X'
156 elif Options.options.GDBTEST:
157 server_wrapper = '${srcdir}/selftest/gdb_run _DUMMY=X'
159 if Options.options.SCREEN:
160 server_wrapper = '${srcdir}/selftest/in_screen %s' % server_wrapper
161 os.environ['TERMINAL'] = EXPAND_VARIABLES(opt, '${srcdir}/selftest/in_screen')
162 elif server_wrapper != '':
163 server_wrapper = 'xterm -n server -l -e %s' % server_wrapper
165 if server_wrapper != '':
166 os.environ['SAMBA_VALGRIND'] = EXPAND_VARIABLES(opt, server_wrapper)
168 # this is needed for systems without rpath, or with rpath disabled
169 ADD_LD_LIBRARY_PATH('bin/shared')
170 ADD_LD_LIBRARY_PATH('bin/shared/private')
172 # if we are using a system version of ldb then we need to tell it to
173 # load modules from our modules path
174 if env.USING_SYSTEM_LDB:
175 os.environ['LDB_MODULES_PATH'] = 'bin/modules/ldb'
177 # tell build system where to find config.h
178 os.environ['VFSLIBDIR'] = os.path.abspath('bin/modules/vfs')
179 os.environ['CONFIG_H'] = 'bin/default/include/config.h'
181 st_done = os.path.join(env.SELFTEST_PREFIX, 'st_done')
182 if os.path.exists(st_done):
183 os.unlink(st_done)
185 if not os.path.isdir(env.SELFTEST_PREFIX):
186 os.makedirs(env.SELFTEST_PREFIX, int('755', 8))
188 if Options.options.TARGET:
189 env.SELFTEST_TARGET = Options.options.TARGET
190 else:
191 env.SELFTEST_TARGET = "samba"
193 if env.SELFTEST_TARGET == "samba4":
194 env.SELFTEST_DIR = "${srcdir}/source4/selftest"
195 elif env.SELFTEST_TARGET == "samba3":
196 env.SELFTEST_DIR = "${srcdir}/source3/selftest"
198 if env.SELFTEST_TARGET == "samba":
199 for f in ["knownfail", "slow", "quick", "skip" ]:
200 combine_files(env.srcdir + "/source4/selftest/" + f,
201 env.srcdir + "/source3/selftest/" + f,
202 env.SELFTEST_PREFIX + "/" + f)
204 env.SELFTEST_DIR = env.SELFTEST_PREFIX
205 env.TESTLISTS = ('--testlist="${PYTHON} ${srcdir}/source3/selftest/tests.py|" ' +
206 '--testlist="${PYTHON} ${srcdir}/source4/selftest/tests.py|"')
207 else:
208 env.TESTLISTS = '--testlist="${SELFTEST_DIR}/tests.py|"'
210 # We use the full path rather than relative path because it cause problems on some plateforms (ie. solaris 8).
211 cmd = '(${PERL} ${srcdir}/selftest/selftest.pl --target=${SELFTEST_TARGET} --prefix=${SELFTEST_PREFIX} --srcdir=${srcdir} --exclude=${SELFTEST_DIR}/skip ${TESTLISTS} ${OPTIONS} --socket-wrapper ${TESTS} && touch ${SELFTEST_PREFIX}/st_done) | ${FILTER_OPTIONS} | tee ${SELFTEST_PREFIX}/subunit'
213 if os.environ.get('RUN_FROM_BUILD_FARM') is None and not Options.options.FILTERED_SUBUNIT:
214 cmd += ' | ${FORMAT_TEST_OUTPUT}'
215 else:
216 cmd += ' | ${PYTHON} -u ${srcdir}/selftest/filter-subunit'
217 runcmd = EXPAND_VARIABLES(opt, cmd)
219 print("test: running %s" % runcmd)
220 ret = RUN_COMMAND(cmd, env=env)
221 if os.path.exists(".testrepository"):
222 # "testr load -q" isn't
223 testrcmd = 'testr load -q < ${SELFTEST_PREFIX}/subunit > /dev/null'
224 runcmd = EXPAND_VARIABLES(opt, testrcmd)
225 RUN_COMMAND(runcmd, env=env)
227 if ret != 0:
228 print("ERROR: test failed with exit code %d" % ret)
229 sys.exit(ret)
231 if not os.path.exists(st_done):
232 print("ERROR: test command failed to complete")
233 sys.exit(1)
236 ########################################################################
237 # main test entry point
238 def cmd_test(opt):
239 '''Run the test suite (see test options below)'''
240 Scripting.commands.append('build')
241 Scripting.commands.append('testonly')