ldb_mdb/tests: Tests for wrap open
[Samba.git] / lib / ldb / wscript
blobb8b97191fbb474aee6175911a9cf78ea11bbe327
1 #!/usr/bin/env python
3 APPNAME = 'ldb'
4 VERSION = '1.3.2'
6 blddir = 'bin'
8 import sys, os
9 import Logs
11 # find the buildtools directory
12 srcdir = '.'
13 while not os.path.exists(srcdir+'/buildtools') and len(srcdir.split('/')) < 5:
14 srcdir = srcdir + '/..'
15 sys.path.insert(0, srcdir + '/buildtools/wafsamba')
17 import wafsamba, samba_dist, Utils, Options
19 samba_dist.DIST_DIRS('''lib/ldb:. lib/replace:lib/replace lib/talloc:lib/talloc
20 lib/tdb:lib/tdb lib/tdb:lib/tdb lib/tevent:lib/tevent
21 third_party/popt:third_party/popt
22 third_party/cmocka:third_party/cmocka
23 buildtools:buildtools third_party/waf:third_party/waf''')
25 samba_dist.DIST_FILES('''lib/util/binsearch.h:lib/util/binsearch.h''')
27 def set_options(opt):
28 opt.BUILTIN_DEFAULT('replace')
29 opt.PRIVATE_EXTENSION_DEFAULT('ldb', noextension='ldb')
30 opt.RECURSE('lib/tdb')
31 opt.RECURSE('lib/tevent')
32 opt.RECURSE('lib/replace')
33 opt.tool_options('python') # options for disabling pyc or pyo compilation
35 opt.add_option('--without-ldb-lmdb',
36 help='disable new LMDB backend for LDB',
37 action='store_true', dest='without_ldb_lmdb', default=False)
40 def configure(conf):
41 conf.RECURSE('lib/tdb')
42 conf.RECURSE('lib/tevent')
44 if conf.CHECK_FOR_THIRD_PARTY():
45 conf.RECURSE('third_party/popt')
46 conf.RECURSE('third_party/cmocka')
47 else:
48 if not conf.CHECK_POPT():
49 raise Utils.WafError('popt development packages have not been found.\nIf third_party is installed, check that it is in the proper place.')
50 else:
51 conf.define('USING_SYSTEM_POPT', 1)
53 if not conf.CHECK_CMOCKA():
54 raise Utils.WafError('cmocka development package have not been found.\nIf third_party is installed, check that it is in the proper place.')
55 else:
56 conf.define('USING_SYSTEM_CMOCKA', 1)
58 conf.RECURSE('lib/replace')
59 conf.find_program('python', var='PYTHON')
60 conf.find_program('xsltproc', var='XSLTPROC')
61 conf.check_tool('python')
62 conf.check_python_version((2,4,2))
63 conf.SAMBA_CHECK_PYTHON_HEADERS(mandatory=not conf.env.disable_python)
65 # where does the default LIBDIR end up? in conf.env somewhere?
67 conf.CONFIG_PATH('LDB_MODULESDIR', conf.SUBST_ENV_VAR('MODULESDIR') + '/ldb')
69 conf.env.standalone_ldb = conf.IN_LAUNCH_DIR()
71 if not conf.env.standalone_ldb:
72 if conf.env.disable_python:
73 if conf.CHECK_BUNDLED_SYSTEM_PKG('ldb', minversion=VERSION,
74 onlyif='talloc tdb tevent',
75 implied_deps='replace talloc tdb tevent'):
76 conf.define('USING_SYSTEM_LDB', 1)
77 else:
78 using_system_pyldb_util = True
79 if not conf.CHECK_BUNDLED_SYSTEM_PKG('pyldb-util', minversion=VERSION,
80 onlyif='talloc tdb tevent',
81 implied_deps='replace talloc tdb tevent ldb'):
82 using_system_pyldb_util = False
84 # We need to get a pyldb-util for all the python versions
85 # we are building for
86 if conf.env['EXTRA_PYTHON']:
87 name = 'pyldb-util' + conf.all_envs['extrapython']['PYTHON_SO_ABI_FLAG']
88 if not conf.CHECK_BUNDLED_SYSTEM_PKG(name, minversion=VERSION,
89 onlyif='talloc tdb tevent',
90 implied_deps='replace talloc tdb tevent ldb'):
91 using_system_pyldb_util = False
93 if using_system_pyldb_util:
94 conf.define('USING_SYSTEM_PYLDB_UTIL', 1)
96 if conf.CHECK_BUNDLED_SYSTEM_PKG('ldb', minversion=VERSION,
97 onlyif='talloc tdb tevent pyldb-util',
98 implied_deps='replace talloc tdb tevent'):
99 conf.define('USING_SYSTEM_LDB', 1)
101 if not conf.CHECK_CODE('return !(sizeof(size_t) >= 8)',
102 "HAVE_64_BIT_SIZE_T_FOR_LMDB",
103 execute=True,
104 msg='Checking for a 64-bit host to '
105 'support lmdb'):
106 Logs.warn("--without-ldb-lmdb implied as this "
107 "host is not 64-bit")
109 if not conf.env.standalone_ldb and \
110 not Options.options.without_ad_dc and \
111 conf.CONFIG_GET('ENABLE_SELFTEST'):
112 Logs.warn("NOTE: Some AD DC parts of selftest will fail")
114 conf.env.REQUIRE_LMDB = False
115 else:
116 if conf.env.standalone_ldb:
117 if Options.options.without_ldb_lmdb:
118 conf.env.REQUIRE_LMDB = False
119 else:
120 conf.env.REQUIRE_LMDB = True
121 elif Options.options.without_ad_dc:
122 conf.env.REQUIRE_LMDB = False
123 else:
124 if Options.options.without_ldb_lmdb:
125 if not Options.options.without_ad_dc and \
126 conf.CONFIG_GET('ENABLE_SELFTEST'):
127 raise Utils.WafError('--without-ldb-lmdb conflicts '
128 'with --enable-selftest while '
129 'building the AD DC')
131 conf.env.REQUIRE_LMDB = False
132 else:
133 conf.env.REQUIRE_LMDB = True
136 if conf.CONFIG_SET('USING_SYSTEM_LDB'):
137 v = VERSION.split('.')
138 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_MAJOR', int(v[0]))
139 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_MINOR', int(v[1]))
140 conf.DEFINE('EXPECTED_SYSTEM_LDB_VERSION_RELEASE', int(v[2]))
142 if conf.env.standalone_ldb:
143 conf.CHECK_XSLTPROC_MANPAGES()
145 # we need this for the ldap backend
146 if conf.CHECK_FUNCS_IN('ber_flush ldap_open ldap_initialize', 'lber ldap', headers='lber.h ldap.h'):
147 conf.env.ENABLE_LDAP_BACKEND = True
149 # we don't want any libraries or modules to rely on runtime
150 # resolution of symbols
151 if not sys.platform.startswith("openbsd"):
152 conf.ADD_LDFLAGS('-Wl,-no-undefined', testflags=True)
154 # if lmdb support is enabled then we require lmdb
155 # is present, build the mdb back end and enable lmdb support in
156 # the tools.
157 if conf.env.REQUIRE_LMDB and \
158 not conf.CONFIG_SET('USING_SYSTEM_LDB'):
159 if not conf.CHECK_CFG(package='lmdb',
160 args='"lmdb >= 0.9.16" --cflags --libs',
161 msg='Checking for lmdb >= 0.9.16',
162 mandatory=False):
163 if not conf.CHECK_CODE('''
164 #if MDB_VERSION_MAJOR == 0 \
165 && MDB_VERSION_MINOR <= 9 \
166 && MDB_VERSION_PATCH < 16
167 #error LMDB too old
168 #endif
169 ''',
170 'HAVE_GOOD_LMDB_VERSION',
171 headers='lmdb.h',
172 msg='Checking for lmdb >= 0.9.16 via header check'):
174 if conf.env.standalone_ldb:
175 raise Utils.WafError('ldb build (unless --without-ldb-lmdb) '
176 'requires '
177 'lmdb 0.9.16 or later')
178 elif not Options.options.without_ad_dc:
179 raise Utils.WafError('Samba AD DC and --enable-selftest '
180 'requires '
181 'lmdb 0.9.16 or later')
183 if conf.CHECK_FUNCS_IN('mdb_env_create', 'lmdb', headers='lmdb.h'):
184 conf.DEFINE('HAVE_LMDB', '1')
187 conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True)
189 conf.SAMBA_CONFIG_H()
191 conf.SAMBA_CHECK_UNDEFINED_SYMBOL_FLAGS()
193 def build(bld):
194 bld.RECURSE('lib/tevent')
196 if bld.CHECK_FOR_THIRD_PARTY():
197 bld.RECURSE('third_party/popt')
198 bld.RECURSE('third_party/cmocka')
200 bld.RECURSE('lib/replace')
201 bld.RECURSE('lib/tdb')
203 if bld.env.standalone_ldb:
204 private_library = False
205 else:
206 private_library = True
208 LDB_MAP_SRC = bld.SUBDIR('ldb_map',
209 'ldb_map.c ldb_map_inbound.c ldb_map_outbound.c')
211 COMMON_SRC = bld.SUBDIR('common',
212 '''ldb_modules.c ldb_ldif.c ldb_parse.c ldb_msg.c ldb_utf8.c
213 ldb_debug.c ldb_dn.c ldb_match.c ldb_options.c ldb_pack.c
214 ldb_attributes.c attrib_handlers.c ldb_controls.c qsort.c''')
216 bld.SAMBA_MODULE('ldb_ldap', 'ldb_ldap/ldb_ldap.c',
217 init_function='ldb_ldap_init',
218 module_init_name='ldb_init_module',
219 deps='talloc lber ldap ldb',
220 enabled=bld.env.ENABLE_LDAP_BACKEND,
221 internal_module=False,
222 subsystem='ldb')
224 if bld.PYTHON_BUILD_IS_ENABLED():
225 if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
226 for env in bld.gen_python_environments(['PKGCONFIGDIR']):
227 # we're not currently linking against the ldap libs, but ldb.pc.in
228 # has @LDAP_LIBS@
229 bld.env.LDAP_LIBS = ''
231 if not 'PACKAGE_VERSION' in bld.env:
232 bld.env.PACKAGE_VERSION = VERSION
233 bld.env.PKGCONFIGDIR = '${LIBDIR}/pkgconfig'
235 name = bld.pyembed_libname('pyldb-util')
236 bld.SAMBA_LIBRARY(name,
237 deps='ldb',
238 source='pyldb_util.c',
239 public_headers=('' if private_library else 'pyldb.h'),
240 public_headers_install=not private_library,
241 vnum=VERSION,
242 private_library=private_library,
243 pc_files='pyldb-util.pc',
244 pyembed=True,
245 enabled=bld.PYTHON_BUILD_IS_ENABLED(),
246 abi_directory='ABI',
247 abi_match='pyldb_*')
249 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
250 bld.SAMBA_PYTHON('pyldb', 'pyldb.c',
251 deps='ldb ' + name,
252 realname='ldb.so',
253 cflags='-DPACKAGE_VERSION=\"%s\"' % VERSION)
255 # Do only install this file as part of the Samba build if we do not
256 # use the system libldb!
257 if not bld.CONFIG_SET('USING_SYSTEM_PYLDB_UTIL'):
258 for env in bld.gen_python_environments(['PKGCONFIGDIR']):
259 bld.SAMBA_SCRIPT('_ldb_text.py',
260 pattern='_ldb_text.py',
261 installdir='python')
263 bld.INSTALL_FILES('${PYTHONARCHDIR}', '_ldb_text.py')
265 if not bld.CONFIG_SET('USING_SYSTEM_LDB'):
266 if bld.is_install:
267 modules_dir = bld.EXPAND_VARIABLES('${LDB_MODULESDIR}')
268 else:
269 # when we run from the source directory, we want to use
270 # the current modules, not the installed ones
271 modules_dir = os.path.join(os.getcwd(), 'bin/modules/ldb')
273 abi_match = '!ldb_*module_ops !ldb_*backend_ops ldb_*'
275 ldb_headers = ('include/ldb.h include/ldb_errors.h '
276 'include/ldb_module.h include/ldb_handlers.h')
278 bld.SAMBA_LIBRARY('ldb',
279 COMMON_SRC + ' ' + LDB_MAP_SRC,
280 deps='tevent LIBLDB_MAIN replace',
281 includes='include',
282 public_headers=('' if private_library else ldb_headers),
283 public_headers_install=not private_library,
284 pc_files='ldb.pc',
285 vnum=VERSION,
286 private_library=private_library,
287 manpages='man/ldb.3',
288 abi_directory='ABI',
289 abi_match = abi_match)
291 # generate a include/ldb_version.h
292 def generate_ldb_version_h(t):
293 '''generate a vscript file for our public libraries'''
295 tgt = t.outputs[0].bldpath(t.env)
297 v = t.env.LDB_VERSION.split('.')
299 f = open(tgt, mode='w')
300 try:
301 f.write('#define LDB_VERSION "%s"\n' % t.env.LDB_VERSION)
302 f.write('#define LDB_VERSION_MAJOR %d\n' % int(v[0]))
303 f.write('#define LDB_VERSION_MINOR %d\n' % int(v[1]))
304 f.write('#define LDB_VERSION_RELEASE %d\n' % int(v[2]))
305 finally:
306 f.close()
307 return
308 t = bld.SAMBA_GENERATOR('ldb_version.h',
309 rule=generate_ldb_version_h,
310 dep_vars=['LDB_VERSION'],
311 target='include/ldb_version.h',
312 public_headers='include/ldb_version.h',
313 public_headers_install=not private_library)
314 t.env.LDB_VERSION = VERSION
317 bld.SAMBA_MODULE('ldb_paged_results',
318 'modules/paged_results.c',
319 init_function='ldb_paged_results_init',
320 module_init_name='ldb_init_module',
321 internal_module=False,
322 deps='ldb',
323 subsystem='ldb')
325 bld.SAMBA_MODULE('ldb_asq',
326 'modules/asq.c',
327 init_function='ldb_asq_init',
328 module_init_name='ldb_init_module',
329 internal_module=False,
330 deps='ldb',
331 subsystem='ldb')
333 bld.SAMBA_MODULE('ldb_server_sort',
334 'modules/sort.c',
335 init_function='ldb_server_sort_init',
336 internal_module=False,
337 module_init_name='ldb_init_module',
338 deps='ldb',
339 subsystem='ldb')
341 bld.SAMBA_MODULE('ldb_paged_searches',
342 'modules/paged_searches.c',
343 init_function='ldb_paged_searches_init',
344 internal_module=False,
345 module_init_name='ldb_init_module',
346 deps='ldb',
347 subsystem='ldb')
349 bld.SAMBA_MODULE('ldb_rdn_name',
350 'modules/rdn_name.c',
351 init_function='ldb_rdn_name_init',
352 internal_module=False,
353 module_init_name='ldb_init_module',
354 deps='ldb',
355 subsystem='ldb')
357 bld.SAMBA_MODULE('ldb_sample',
358 'tests/sample_module.c',
359 init_function='ldb_sample_init',
360 internal_module=False,
361 module_init_name='ldb_init_module',
362 deps='ldb',
363 subsystem='ldb')
365 bld.SAMBA_MODULE('ldb_skel',
366 'modules/skel.c',
367 init_function='ldb_skel_init',
368 internal_module=False,
369 module_init_name='ldb_init_module',
370 deps='ldb',
371 subsystem='ldb')
373 bld.SAMBA_MODULE('ldb_sqlite3',
374 'sqlite3/ldb_sqlite3.c',
375 init_function='ldb_sqlite3_init',
376 internal_module=False,
377 module_init_name='ldb_init_module',
378 enabled=False,
379 deps='ldb',
380 subsystem='ldb')
382 bld.SAMBA_MODULE('ldb_tdb',
383 bld.SUBDIR('ldb_tdb',
384 '''ldb_tdb_init.c'''),
385 init_function='ldb_tdb_init',
386 module_init_name='ldb_init_module',
387 internal_module=False,
388 deps='tdb ldb ldb_key_value',
389 subsystem='ldb')
391 bld.SAMBA_LIBRARY('ldb_key_value',
392 bld.SUBDIR('ldb_tdb',
393 '''ldb_tdb.c ldb_search.c ldb_index.c
394 ldb_cache.c ldb_tdb_wrap.c'''),
395 private_library=True,
396 deps='tdb ldb')
398 if bld.CONFIG_SET('HAVE_LMDB'):
399 bld.SAMBA_MODULE('ldb_mdb',
400 bld.SUBDIR('ldb_mdb',
401 '''ldb_mdb_init.c'''),
402 init_function='ldb_mdb_init',
403 module_init_name='ldb_init_module',
404 internal_module=False,
405 deps='ldb ldb_key_value ldb_mdb_int',
406 subsystem='ldb')
408 bld.SAMBA_LIBRARY('ldb_mdb_int',
409 bld.SUBDIR('ldb_mdb',
410 '''ldb_mdb.c '''),
411 private_library=True,
412 deps='ldb lmdb ldb_key_value')
413 lmdb_deps = ' ldb_mdb_int'
414 else:
415 lmdb_deps = ''
418 bld.SAMBA_MODULE('ldb_ldb',
419 bld.SUBDIR('ldb_ldb',
420 '''ldb_ldb.c'''),
421 init_function='ldb_ldb_init',
422 module_init_name='ldb_init_module',
423 internal_module=False,
424 deps='ldb ldb_key_value' + lmdb_deps,
425 subsystem='ldb')
427 # have a separate subsystem for common/ldb.c, so it can rebuild
428 # for install with a different -DLDB_MODULESDIR=
429 bld.SAMBA_SUBSYSTEM('LIBLDB_MAIN',
430 'common/ldb.c',
431 deps='tevent tdb',
432 includes='include',
433 cflags=['-DLDB_MODULESDIR=\"%s\"' % modules_dir])
435 LDB_TOOLS='ldbadd ldbsearch ldbdel ldbmodify ldbedit ldbrename'
436 for t in LDB_TOOLS.split():
437 bld.SAMBA_BINARY(t, 'tools/%s.c' % t, deps='ldb-cmdline ldb',
438 manpages='man/%s.1' % t)
440 # ldbtest doesn't get installed
441 bld.SAMBA_BINARY('ldbtest', 'tools/ldbtest.c', deps='ldb-cmdline ldb',
442 install=False)
444 if bld.CONFIG_SET('HAVE_LMDB'):
445 lmdb_deps = ' lmdb'
446 else:
447 lmdb_deps = ''
448 # ldbdump doesn't get installed
449 bld.SAMBA_BINARY('ldbdump',
450 'tools/ldbdump.c',
451 deps='ldb-cmdline ldb' + lmdb_deps,
452 install=False)
454 bld.SAMBA_LIBRARY('ldb-cmdline',
455 source='tools/ldbutil.c tools/cmdline.c',
456 deps='ldb dl popt',
457 private_library=True)
459 bld.SAMBA_BINARY('ldb_tdb_mod_op_test',
460 source='tests/ldb_mod_op_test.c',
461 cflags='-DTEST_BE=\"tdb\"',
462 deps='cmocka ldb',
463 install=False)
465 bld.SAMBA_BINARY('ldb_tdb_guid_mod_op_test',
466 source='tests/ldb_mod_op_test.c',
467 cflags='-DTEST_BE=\"tdb\" -DGUID_IDX=1',
468 deps='cmocka ldb',
469 install=False)
471 bld.SAMBA_BINARY('ldb_tdb_kv_ops_test',
472 source='tests/ldb_kv_ops_test.c',
473 cflags='-DTEST_BE=\"tdb\"',
474 deps='cmocka ldb',
475 install=False)
477 bld.SAMBA_BINARY('ldb_tdb_test',
478 source='tests/ldb_tdb_test.c',
479 deps='cmocka ldb',
480 install=False)
482 bld.SAMBA_BINARY('ldb_msg_test',
483 source='tests/ldb_msg.c',
484 deps='cmocka ldb',
485 install=False)
487 bld.SAMBA_BINARY('test_ldb_qsort',
488 source='tests/test_ldb_qsort.c',
489 deps='cmocka ldb',
490 install=False)
492 if bld.CONFIG_SET('HAVE_LMDB'):
493 bld.SAMBA_BINARY('ldb_mdb_mod_op_test',
494 source='tests/ldb_mod_op_test.c',
495 cflags='-DTEST_BE=\"mdb\" -DGUID_IDX=1 '
496 + '-DTEST_LMDB=1',
497 deps='cmocka ldb lmdb',
498 install=False)
500 bld.SAMBA_BINARY('ldb_lmdb_test',
501 source='tests/ldb_lmdb_test.c',
502 deps='cmocka ldb',
503 install=False)
505 bld.SAMBA_BINARY('ldb_lmdb_size_test',
506 source='tests/ldb_lmdb_size_test.c',
507 deps='cmocka ldb',
508 install=False)
510 bld.SAMBA_BINARY('ldb_mdb_kv_ops_test',
511 source='tests/ldb_kv_ops_test.c',
512 cflags='-DTEST_BE=\"mdb\"',
513 deps='cmocka ldb',
514 install=False)
516 def test(ctx):
517 '''run ldb testsuite'''
518 import Utils, samba_utils, shutil
519 env = samba_utils.LOAD_ENVIRONMENT()
520 ctx.env = env
522 if not env.HAVE_LMDB:
523 raise Utils.WafError('make test called, but ldb was built '
524 '--without-ldb-lmdb')
526 test_prefix = "%s/st" % (Utils.g_module.blddir)
527 shutil.rmtree(test_prefix, ignore_errors=True)
528 os.makedirs(test_prefix)
529 os.environ['TEST_DATA_PREFIX'] = test_prefix
530 os.environ['LDB_MODULES_PATH'] = Utils.g_module.blddir + "/modules/ldb"
531 samba_utils.ADD_LD_LIBRARY_PATH('bin/shared')
532 samba_utils.ADD_LD_LIBRARY_PATH('bin/shared/private')
534 cmd = 'tests/test-tdb.sh %s' % Utils.g_module.blddir
535 ret = samba_utils.RUN_COMMAND(cmd)
536 print("testsuite returned %d" % ret)
538 tmp_dir = os.path.join(test_prefix, 'tmp')
539 if not os.path.exists(tmp_dir):
540 os.mkdir(tmp_dir)
541 pyret = samba_utils.RUN_PYTHON_TESTS(
542 ['tests/python/api.py', 'tests/python/index.py'],
543 extra_env={'SELFTEST_PREFIX': test_prefix})
544 print("Python testsuite returned %d" % pyret)
546 cmocka_ret = 0
547 test_exes = ['test_ldb_qsort',
548 'ldb_msg_test',
549 'ldb_tdb_mod_op_test',
550 'ldb_tdb_guid_mod_op_test',
551 'ldb_msg_test',
552 'ldb_tdb_kv_ops_test',
553 'ldb_tdb_test',
554 'ldb_lmdb_test']
555 # we don't want to run ldb_lmdb_size_test (which proves we can
556 # fit > 4G of data into the DB), it would fill up the disk on
557 # many of our test instances
559 for test_exe in test_exes:
560 cmd = os.path.join(Utils.g_module.blddir, test_exe)
561 cmocka_ret = cmocka_ret or samba_utils.RUN_COMMAND(cmd)
563 sys.exit(ret or pyret or cmocka_ret)
565 def dist():
566 '''makes a tarball for distribution'''
567 samba_dist.dist()
569 def reconfigure(ctx):
570 '''reconfigure if config scripts have changed'''
571 import samba_utils
572 samba_utils.reconfigure(ctx)