tdb/test: add mutex related tests
[samba.git] / lib / tdb / wscript
1 #!/usr/bin/env python
2
3 APPNAME = 'tdb'
4 VERSION = '1.3.0'
5
6 blddir = 'bin'
7
8 import sys, os
9
10 # find the buildtools directory
11 srcdir = '.'
12 while not os.path.exists(srcdir+'/buildtools') and len(srcdir.split('/')) < 5:
13     srcdir = '../' + srcdir
14 sys.path.insert(0, srcdir + '/buildtools/wafsamba')
15
16 import wafsamba, samba_dist, Options, Logs
17
18 samba_dist.DIST_DIRS('lib/tdb:. lib/replace:lib/replace buildtools:buildtools')
19
20 tdb1_unit_tests = [
21     'run-3G-file',
22     'run-bad-tdb-header',
23     'run',
24     'run-check',
25     'run-corrupt',
26     'run-die-during-transaction',
27     'run-endian',
28     'run-incompatible',
29     'run-nested-transactions',
30     'run-nested-traverse',
31     'run-no-lock-during-traverse',
32     'run-oldhash',
33     'run-open-during-transaction',
34     'run-readonly-check',
35     'run-rescue',
36     'run-rescue-find_entry',
37     'run-rwlock-check',
38     'run-summary',
39     'run-transaction-expand',
40     'run-traverse-in-transaction',
41     'run-wronghash-fail',
42     'run-zero-append',
43     'run-mutex-openflags2',
44     'run-mutex-trylock',
45     'run-mutex-allrecord-bench',
46     'run-mutex-allrecord-trylock',
47     'run-mutex-allrecord-block',
48     'run-mutex-die',
49     'run-mutex1',
50 ]
51
52 def set_options(opt):
53     opt.BUILTIN_DEFAULT('replace')
54     opt.PRIVATE_EXTENSION_DEFAULT('tdb', noextension='tdb')
55     opt.RECURSE('lib/replace')
56     opt.add_option('--disable-tdb-mutex-locking',
57                    help=("Disable the use of pthread robust mutexes"),
58                    action="store_true", dest='disable_tdb_mutex_locking',
59                    default=False)
60     if opt.IN_LAUNCH_DIR():
61         opt.add_option('--disable-python',
62                        help=("disable the pytdb module"),
63                        action="store_true", dest='disable_python', default=False)
64
65
66 def configure(conf):
67     conf.env.disable_tdb_mutex_locking = getattr(Options.options,
68                                                  'disable_tdb_mutex_locking',
69                                                  False)
70     if not conf.env.disable_tdb_mutex_locking:
71         conf.env.replace_add_global_pthread = True
72     conf.RECURSE('lib/replace')
73
74     conf.env.standalone_tdb = conf.IN_LAUNCH_DIR()
75     conf.env.building_tdb = True
76
77     if not conf.env.standalone_tdb:
78         if conf.CHECK_BUNDLED_SYSTEM_PKG('tdb', minversion=VERSION,
79                                      implied_deps='replace'):
80             conf.define('USING_SYSTEM_TDB', 1)
81             conf.env.building_tdb = False
82             if conf.CHECK_BUNDLED_SYSTEM_PYTHON('pytdb', 'tdb', minversion=VERSION):
83                 conf.define('USING_SYSTEM_PYTDB', 1)
84
85     conf.env.disable_python = getattr(Options.options, 'disable_python', False)
86
87     if (conf.CONFIG_SET('HAVE_ROBUST_MUTEXES') and
88         conf.env.building_tdb and
89         not conf.env.disable_tdb_mutex_locking):
90         conf.define('USE_TDB_MUTEX_LOCKING', 1)
91
92     conf.CHECK_XSLTPROC_MANPAGES()
93
94     if not conf.env.disable_python:
95         # also disable if we don't have the python libs installed
96         conf.find_program('python', var='PYTHON')
97         conf.check_tool('python')
98         conf.check_python_version((2,4,2))
99         conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=False)
100         if not conf.env.HAVE_PYTHON_H:
101             Logs.warn('Disabling pytdb as python devel libs not found')
102             conf.env.disable_python = True
103
104     conf.SAMBA_CONFIG_H()
105
106     conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
107
108 def build(bld):
109     bld.RECURSE('lib/replace')
110
111     COMMON_FILES='''check.c error.c tdb.c traverse.c
112                     freelistcheck.c lock.c dump.c freelist.c
113                     io.c open.c transaction.c hash.c summary.c rescue.c
114                     mutex.c'''
115
116     COMMON_SRC = bld.SUBDIR('common', COMMON_FILES)
117
118     if bld.env.standalone_tdb:
119         bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
120         private_library = False
121     else:
122         private_library = True
123
124     if not bld.CONFIG_SET('USING_SYSTEM_TDB'):
125
126         tdb_deps = 'replace'
127
128         if bld.CONFIG_SET('USE_TDB_MUTEX_LOCKING'):
129             tdb_deps += ' pthread'
130
131         bld.SAMBA_LIBRARY('tdb',
132                           COMMON_SRC,
133                           deps=tdb_deps,
134                           includes='include',
135                           abi_directory='ABI',
136                           abi_match='tdb_*',
137                           hide_symbols=True,
138                           vnum=VERSION,
139                           public_headers='include/tdb.h',
140                           public_headers_install=not private_library,
141                           pc_files='tdb.pc',
142                           private_library=private_library)
143
144         bld.SAMBA_BINARY('tdbtorture',
145                          'tools/tdbtorture.c',
146                          'tdb',
147                          install=False)
148
149         bld.SAMBA_BINARY('tdbrestore',
150                          'tools/tdbrestore.c',
151                          'tdb', manpages='man/tdbrestore.8')
152
153         bld.SAMBA_BINARY('tdbdump',
154                          'tools/tdbdump.c',
155                          'tdb', manpages='man/tdbdump.8')
156
157         bld.SAMBA_BINARY('tdbbackup',
158                          'tools/tdbbackup.c',
159                          'tdb',
160                          manpages='man/tdbbackup.8')
161
162         bld.SAMBA_BINARY('tdbtool',
163                          'tools/tdbtool.c',
164                          'tdb', manpages='man/tdbtool.8')
165
166         # FIXME: This hardcoded list is stupid, stupid, stupid.
167         bld.SAMBA_SUBSYSTEM('tdb-test-helpers',
168                             'test/external-agent.c test/lock-tracking.c test/logging.c',
169                             tdb_deps,
170                             includes='include')
171
172         for t in tdb1_unit_tests:
173             b = "tdb1-" + t
174             s = "test/" + t + ".c"
175             bld.SAMBA_BINARY(b, s, 'replace tdb-test-helpers',
176                              includes='include', install=False)
177
178     if not bld.CONFIG_SET('USING_SYSTEM_PYTDB'):
179         bld.SAMBA_PYTHON('pytdb',
180                          'pytdb.c',
181                          deps='tdb',
182                          enabled=not bld.env.disable_python,
183                          realname='tdb.so',
184                          cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
185
186 def testonly(ctx):
187     '''run tdb testsuite'''
188     import Utils, samba_utils, shutil
189     ecode = 0
190
191     test_prefix = "%s/st" % (Utils.g_module.blddir)
192     shutil.rmtree(test_prefix, ignore_errors=True)
193     os.makedirs(test_prefix)
194     os.environ['TEST_DATA_PREFIX'] = test_prefix
195
196     env = samba_utils.LOAD_ENVIRONMENT()
197     # FIXME: This is horrible :(
198     if env.building_tdb:
199         # Create scratch directory for tests.
200         testdir = os.path.join(test_prefix, 'tdb-tests')
201         samba_utils.mkdir_p(testdir)
202         # Symlink back to source dir so it can find tests in test/
203         link = os.path.join(testdir, 'test')
204         if not os.path.exists(link):
205             os.symlink(os.path.abspath(os.path.join(env.cwd, 'test')), link)
206
207         for t in tdb1_unit_tests:
208             f = "tdb1-" + t
209             cmd = "cd " + testdir + " && " + os.path.abspath(os.path.join(Utils.g_module.blddir, f)) + " > test-output 2>&1"
210             print("..." + f)
211             ret = samba_utils.RUN_COMMAND(cmd)
212             if ret != 0:
213                 print("%s failed:" % f)
214                 samba_utils.RUN_COMMAND("cat " + os.path.join(testdir, 'test-output'))
215                 ecode = ret
216                 break
217
218     if ecode == 0:
219         cmd = os.path.join(Utils.g_module.blddir, 'tdbtorture')
220         ret = samba_utils.RUN_COMMAND(cmd)
221         print("testsuite returned %d" % ret)
222         if ret != 0:
223             ecode = ret
224     sys.exit(ecode)
225
226 # WAF doesn't build the unit tests for this, maybe because they don't link with tdb?
227 # This forces it
228 def test(ctx):
229     import Scripting
230     Scripting.commands.append('build')
231     Scripting.commands.append('testonly')
232
233 def dist():
234     '''makes a tarball for distribution'''
235     samba_dist.dist()
236
237 def reconfigure(ctx):
238     '''reconfigure if config scripts have changed'''
239     import samba_utils
240     samba_utils.reconfigure(ctx)