s4:password_hash LDB module - adapt the module to the new "ldb_msg_remove_attr" behaviour
[Samba/ekacnet.git] / source4 / selftest / wscript
blob5e42e6fb67c15e2d66cb1e04a05f69602fd0d4c9
1 #!/usr/bin/env python
3 # selftest main code.
5 import Scripting, os, Options, Utils, Environment, optparse, sys
6 from samba_utils import *
7 from samba_autoconf import *
9 def set_options(opt):
11 opt.add_option('--enable-selftest',
12 help=("enable options necessary for selftest (default=no)"),
13 action="store_true", dest='enable_selftest', default=False)
14 opt.add_option('--with-selftest-prefix',
15 help=("specify location of selftest directory (default=./st)"),
16 action="store", dest='SELFTEST_PREFIX', default='./st')
18 opt.ADD_COMMAND('test', cmd_test)
19 opt.ADD_COMMAND('testonly', cmd_testonly)
21 gr = opt.add_option_group('test options')
23 gr.add_option('--load-list',
24 help=("Load a test id list from a text file"),
25 action="store", dest='LOAD_LIST', default=None)
26 gr.add_option('--tests',
27 help=("wildcard pattern of tests to run"),
28 action="store", dest='TESTS', default='')
29 gr.add_option('--filtered-subunit',
30 help=("output (xfail) filtered subunit"),
31 action="store_true", dest='FILTERED_SUBUNIT', default=False)
32 gr.add_option('--quick',
33 help=("enable only quick tests"),
34 action="store_true", dest='QUICKTEST', default=False)
35 gr.add_option('--slow',
36 help=("enable the really slow tests"),
37 action="store_true", dest='SLOWTEST', default=False)
38 gr.add_option('--testenv',
39 help=("start a terminal with the test environment setup"),
40 action="store_true", dest='TESTENV', default=False)
41 gr.add_option('--valgrind',
42 help=("use valgrind on client programs in the tests"),
43 action="store_true", dest='VALGRIND', default=False)
44 gr.add_option('--valgrind-log',
45 help=("where to put the valgrind log"),
46 action="store", dest='VALGRINDLOG', default=None)
47 gr.add_option('--valgrind-server',
48 help=("use valgrind on the server in the tests (opens an xterm)"),
49 action="store_true", dest='VALGRIND_SERVER', default=False)
50 gr.add_option('--gdbtest',
51 help=("run the testsuite within a gdb xterm window"),
52 action="store_true", dest='GDBTEST', default=False)
53 gr.add_option('--socket-wrapper-pcap',
54 help=("create a pcap file for each failing test"),
55 action="store_true", dest='SOCKET_WRAPPER_PCAP', default=False)
56 gr.add_option('--socket-wrapper-keep-pcap',
57 help=("create a pcap file for all individual test"),
58 action="store_true", dest='SOCKET_WRAPPER_KEEP_PCAP', default=False)
60 def configure(conf):
61 conf.env.SELFTEST_PREFIX = Options.options.SELFTEST_PREFIX
63 def cmd_testonly(opt):
64 '''run tests without doing a build first'''
65 env = LOAD_ENVIRONMENT()
66 opt.env = env
68 if (not CONFIG_SET(opt, 'NSS_WRAPPER') or
69 not CONFIG_SET(opt, 'UID_WRAPPER') or
70 not CONFIG_SET(opt, 'SOCKET_WRAPPER')):
71 print("ERROR: You must use --enable-selftest to enable selftest")
72 sys.exit(1)
74 env.TESTS = Options.options.TESTS
76 env.SUBUNIT_FORMATTER = '${PYTHON} -u ../selftest/format-subunit --prefix=${SELFTEST_PREFIX} --immediate'
77 env.FILTER_XFAIL = '${PYTHON} -u ../selftest/filter-subunit --expected-failures=./selftest/knownfail'
78 env.FORMAT_TEST_OUTPUT = '${SUBUNIT_FORMATTER}'
80 env.OPTIONS = ''
81 if not Options.options.SLOWTEST:
82 env.OPTIONS += ' --exclude=./selftest/slow'
83 if Options.options.QUICKTEST:
84 env.OPTIONS += ' --quick --include=./selftest/quick'
85 if Options.options.LOAD_LIST:
86 env.OPTIONS += ' --load-list=%s' % Options.options.LOAD_LIST
87 if Options.options.TESTENV:
88 env.OPTIONS += ' --testenv'
89 if Options.options.SOCKET_WRAPPER_PCAP:
90 env.OPTIONS += ' --socket-wrapper-pcap'
91 if Options.options.SOCKET_WRAPPER_KEEP_PCAP:
92 env.OPTIONS += ' --socket-wrapper-keep-pcap'
94 if os.environ.get('RUN_FROM_BUILD_FARM') is not None:
95 env.FILTER_OPTIONS = '${FILTER_XFAIL} --strip-passed-output'
96 else:
97 env.FILTER_OPTIONS = '${FILTER_XFAIL}'
98 if not Options.options.FILTERED_SUBUNIT:
99 env.FILTER_OPTIONS += ' | ${FORMAT_TEST_OUTPUT}'
101 if Options.options.VALGRIND:
102 os.environ['VALGRIND'] = 'valgrind -q --num-callers=30'
103 if Options.options.VALGRINDLOG is not None:
104 os.environ['VALGRIND'] += ' --log-file=%s' % Options.options.VALGRINDLOG
106 if Options.options.VALGRIND_SERVER:
107 os.environ['SAMBA_VALGRIND'] = 'xterm -n server -e ../selftest/valgrind_run DUMMY=X'
109 if Options.options.GDBTEST:
110 os.environ['SAMBA_VALGRIND'] = 'xterm -n server -e ../selftest/gdb_run DUMMY=X'
112 # this is needed for systems without rpath, or with rpath disabled
113 ADD_LD_LIBRARY_PATH('bin/shared')
115 # tell build system where to find config.h
116 os.environ['CONFIG_H'] = 'bin/default/source4/include/config.h'
118 st_done = os.path.join(env.SELFTEST_PREFIX, 'st_done')
119 if os.path.exists(st_done):
120 os.unlink(st_done)
122 cmd = '(${PERL} ../selftest/selftest.pl --prefix=${SELFTEST_PREFIX} --builddir=. --srcdir=. --exclude=./selftest/skip --testlist="./selftest/tests.sh|" ${OPTIONS} --socket-wrapper ${TESTS} && touch ${SELFTEST_PREFIX}/st_done) | ${FILTER_OPTIONS}'
123 cmd = EXPAND_VARIABLES(opt, cmd)
125 print("test: running %s" % cmd)
126 ret = RUN_COMMAND(cmd, env=env)
127 if ret != 0:
128 print("ERROR: test failed with exit code %d" % ret)
129 sys.exit(ret)
131 if not os.path.exists(st_done):
132 print("ERROR: test command failed to complete")
133 sys.exit(1)
136 ########################################################################
137 # main test entry point
138 def cmd_test(opt):
139 '''Run the test suite (see test options below)'''
140 Scripting.commands.append('build')
141 Scripting.commands.append('testonly')