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