Merge master into v3-6-test again.
[Samba.git] / source3 / selftest / wscript
blobb3139d531c6daba1d06f5c35a5fff3ec571527a3
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('--tests',
28 help=("wildcard pattern of tests to run"),
29 action="store", dest='TESTS', default='')
30 gr.add_option('--filtered-subunit',
31 help=("output (xfail) filtered subunit"),
32 action="store_true", dest='FILTERED_SUBUNIT', default=False)
33 gr.add_option('--quick',
34 help=("enable only quick tests"),
35 action="store_true", dest='QUICKTEST', default=False)
36 gr.add_option('--slow',
37 help=("enable the really slow tests"),
38 action="store_true", dest='SLOWTEST', default=False)
39 gr.add_option('--testenv',
40 help=("start a terminal with the test environment setup"),
41 action="store_true", dest='TESTENV', default=False)
42 gr.add_option('--valgrind',
43 help=("use valgrind on client programs in the tests"),
44 action="store_true", dest='VALGRIND', default=False)
45 gr.add_option('--valgrind-log',
46 help=("where to put the valgrind log"),
47 action="store", dest='VALGRINDLOG', default=None)
48 gr.add_option('--valgrind-server',
49 help=("use valgrind on the server in the tests (opens an xterm)"),
50 action="store_true", dest='VALGRIND_SERVER', default=False)
51 gr.add_option('--gdbtest',
52 help=("run the testsuite within a gdb xterm window"),
53 action="store_true", dest='GDBTEST', default=False)
54 gr.add_option('--fail-immediately',
55 help=("stop tests on first failure"),
56 action="store_true", dest='FAIL_IMMEDIATELY', default=False)
57 gr.add_option('--socket-wrapper-pcap',
58 help=("create a pcap file for each failing test"),
59 action="store_true", dest='SOCKET_WRAPPER_PCAP', default=False)
60 gr.add_option('--socket-wrapper-keep-pcap',
61 help=("create a pcap file for all individual test"),
62 action="store_true", dest='SOCKET_WRAPPER_KEEP_PCAP', default=False)
64 def configure(conf):
65 conf.env.SELFTEST_PREFIX = Options.options.SELFTEST_PREFIX
67 def cmd_testonly(opt):
68 '''run tests without doing a build first'''
69 env = LOAD_ENVIRONMENT()
70 opt.env = env
72 if (not CONFIG_SET(opt, 'NSS_WRAPPER') or
73 # not CONFIG_SET(opt, 'UID_WRAPPER') or
74 not CONFIG_SET(opt, 'SOCKET_WRAPPER')):
75 print("ERROR: You must use --enable-selftest to enable selftest")
76 sys.exit(1)
78 env.TESTS = Options.options.TESTS
80 env.SUBUNIT_FORMATTER = '${PYTHON} -u ../selftest/format-subunit --prefix=${SELFTEST_PREFIX} --immediate'
81 env.FILTER_XFAIL = '${PYTHON} -u ../selftest/filter-subunit --expected-failures=./selftest/knownfail'
83 if Options.options.FAIL_IMMEDIATELY:
84 env.FILTER_XFAIL += ' --fail-immediately'
86 env.FORMAT_TEST_OUTPUT = '${SUBUNIT_FORMATTER}'
88 env.OPTIONS = ''
89 if not Options.options.SLOWTEST:
90 env.OPTIONS += ' --exclude=./selftest/slow'
91 if Options.options.QUICKTEST:
92 env.OPTIONS += ' --quick --include=./selftest/quick'
93 if Options.options.LOAD_LIST:
94 env.OPTIONS += ' --load-list=%s' % Options.options.LOAD_LIST
95 if Options.options.TESTENV:
96 env.OPTIONS += ' --testenv'
97 if Options.options.SOCKET_WRAPPER_PCAP:
98 env.OPTIONS += ' --socket-wrapper-pcap'
99 if Options.options.SOCKET_WRAPPER_KEEP_PCAP:
100 env.OPTIONS += ' --socket-wrapper-keep-pcap'
102 if os.environ.get('RUN_FROM_BUILD_FARM') is not None:
103 env.FILTER_OPTIONS = '${FILTER_XFAIL} --strip-passed-output'
104 else:
105 env.FILTER_OPTIONS = '${FILTER_XFAIL}'
107 if Options.options.VALGRIND:
108 os.environ['VALGRIND'] = 'valgrind -q --num-callers=30'
109 if Options.options.VALGRINDLOG is not None:
110 os.environ['VALGRIND'] += ' --log-file=%s' % Options.options.VALGRINDLOG
112 if Options.options.VALGRIND_SERVER:
113 os.environ['SAMBA_VALGRIND'] = 'xterm -n server -l -e ../selftest/valgrind_run DUMMY=X'
115 if Options.options.GDBTEST:
116 os.environ['SAMBA_VALGRIND'] = 'xterm -n server -e ../selftest/gdb_run DUMMY=X'
118 # this is needed for systems without rpath, or with rpath disabled
119 ADD_LD_LIBRARY_PATH('bin/shared')
121 # tell build system where to find config.h
122 os.environ['CONFIG_H'] = 'bin/default/source3/include/config.h'
124 st_done = os.path.join(env.SELFTEST_PREFIX, 'st_done')
125 if os.path.exists(st_done):
126 os.unlink(st_done)
128 cmd = '(${PERL} ../selftest/selftest.pl --target=samba3 --prefix=${SELFTEST_PREFIX} --builddir=. --srcdir=. --exclude=./selftest/skip --testlist="./selftest/tests.sh|" ${OPTIONS} --socket-wrapper ${TESTS} && touch ${SELFTEST_PREFIX}/st_done) | ${FILTER_OPTIONS} | tee ${SELFTEST_PREFIX}/subunit'
129 if os.environ.get('RUN_FROM_BUILD_FARM') is None and not Options.options.FILTERED_SUBUNIT:
130 cmd += ' | ${FORMAT_TEST_OUTPUT}'
131 cmd = EXPAND_VARIABLES(opt, cmd)
133 print("test: running %s" % cmd)
134 ret = RUN_COMMAND(cmd, env=env)
135 if os.path.exists(".testrepository"):
136 # "testr load -q" isn't
137 cmd = 'testr load -q < ${SELFTEST_PREFIX}/subunit > /dev/null'
138 cmd = EXPAND_VARIABLES(opt, cmd)
139 RUN_COMMAND(cmd, env=env)
141 if ret != 0:
142 print("ERROR: test failed with exit code %d" % ret)
143 sys.exit(ret)
145 if not os.path.exists(st_done):
146 print("ERROR: test command failed to complete")
147 sys.exit(1)
150 ########################################################################
151 # main test entry point
152 def cmd_test(opt):
153 '''Run the test suite (see test options below)'''
154 Scripting.commands.append('build')
155 Scripting.commands.append('testonly')