diff options
author | Mathieu Parent <math.parent@gmail.com> | 2018-10-03 20:18:55 +0000 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2019-03-06 03:16:14 +0000 |
commit | c059b8cb82c7c2443e74aa780646607606f41e4b (patch) | |
tree | 5cba50f25b2edbd2f530e5cf6fd2b16a687f1c4d /lib | |
parent | 4125ff89e44a3e98882cfc38c06e559a6e1e56a5 (diff) | |
download | samba-c059b8cb82c7c2443e74aa780646607606f41e4b.tar.gz |
Enable make test even without lmdb
Bug: https://bugzilla.samba.org/show_bug.cgi?id=13630
Signed-off-by: Mathieu Parent <math.parent@gmail.com>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Garming Sam <garming@catalyst.net.nz>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ldb/tests/ldb_no_lmdb_test.c | 158 | ||||
-rwxr-xr-x | lib/ldb/tests/python/api.py | 41 | ||||
-rwxr-xr-x | lib/ldb/tests/python/index.py | 4 | ||||
-rw-r--r-- | lib/ldb/wscript | 30 |
4 files changed, 223 insertions, 10 deletions
diff --git a/lib/ldb/tests/ldb_no_lmdb_test.c b/lib/ldb/tests/ldb_no_lmdb_test.c new file mode 100644 index 00000000000..8e5a6eee8d2 --- /dev/null +++ b/lib/ldb/tests/ldb_no_lmdb_test.c @@ -0,0 +1,158 @@ +/* + * Ensure lmdb backend is disabled + * + * Copyright (C) Mathieu Parent <math.parent@gmail.com> 2019 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + * + */ + +/* + * Ensure lmdb backend is disabled + * + * Setup and tear down code copied from ldb_lmdb_test.c + */ + +/* + * from cmocka.c: + * These headers or their equivalents should be included prior to + * including + * this header file. + * + * #include <stdarg.h> + * #include <stddef.h> + * #include <setjmp.h> + * + * This allows test applications to use custom definitions of C standard + * library functions and types. + * + */ +#include <stdarg.h> +#include <stddef.h> +#include <setjmp.h> +#include <cmocka.h> + +#include <errno.h> +#include <unistd.h> +#include <talloc.h> +#include <tevent.h> +#include <ldb.h> + +#define TEST_BE "mdb" + +struct ldbtest_ctx { + struct tevent_context *ev; + struct ldb_context *ldb; + + const char *dbfile; + const char *lockfile; /* lockfile is separate */ + + const char *dbpath; +}; + +static void unlink_old_db(struct ldbtest_ctx *test_ctx) +{ + int ret; + + errno = 0; + ret = unlink(test_ctx->lockfile); + if (ret == -1 && errno != ENOENT) { + fail(); + } + + errno = 0; + ret = unlink(test_ctx->dbfile); + if (ret == -1 && errno != ENOENT) { + fail(); + } +} + +static int ldbtest_noconn_setup(void **state) +{ + struct ldbtest_ctx *test_ctx; + + test_ctx = talloc_zero(NULL, struct ldbtest_ctx); + assert_non_null(test_ctx); + + test_ctx->ev = tevent_context_init(test_ctx); + assert_non_null(test_ctx->ev); + + test_ctx->ldb = ldb_init(test_ctx, test_ctx->ev); + assert_non_null(test_ctx->ldb); + + test_ctx->dbfile = talloc_strdup(test_ctx, "apitest.ldb"); + assert_non_null(test_ctx->dbfile); + + test_ctx->lockfile = talloc_asprintf(test_ctx, "%s-lock", + test_ctx->dbfile); + assert_non_null(test_ctx->lockfile); + + test_ctx->dbpath = talloc_asprintf(test_ctx, + TEST_BE"://%s", test_ctx->dbfile); + assert_non_null(test_ctx->dbpath); + + unlink_old_db(test_ctx); + *state = test_ctx; + return 0; +} + +static int ldbtest_noconn_teardown(void **state) +{ + struct ldbtest_ctx *test_ctx = talloc_get_type_abort(*state, + struct ldbtest_ctx); + + unlink_old_db(test_ctx); + talloc_free(test_ctx); + return 0; +} + +static int ldbtest_setup(void **state) +{ + struct ldbtest_ctx *test_ctx; + int ret; + + ldbtest_noconn_setup((void **) &test_ctx); + + ret = ldb_connect(test_ctx->ldb, test_ctx->dbpath, 0, NULL); + assert_int_equal(ret, LDB_ERR_OTHER); + + *state = test_ctx; + return 0; +} + +static int ldbtest_teardown(void **state) +{ + struct ldbtest_ctx *test_ctx = talloc_get_type_abort(*state, + struct ldbtest_ctx); + ldbtest_noconn_teardown((void **) &test_ctx); + return 0; +} + +static void test_ldb_lmdb_not_found(void **state) +{ + // Actual test in ldbtest_setup + assert_int_equal(0, 0); +} + +int main(int argc, const char **argv) +{ + const struct CMUnitTest tests[] = { + cmocka_unit_test_setup_teardown( + test_ldb_lmdb_not_found, + ldbtest_setup, + ldbtest_teardown), + }; + + return cmocka_run_group_tests(tests, NULL, NULL); +} diff --git a/lib/ldb/tests/python/api.py b/lib/ldb/tests/python/api.py index e8826b5af3b..0c4e269239b 100755 --- a/lib/ldb/tests/python/api.py +++ b/lib/ldb/tests/python/api.py @@ -710,6 +710,8 @@ class SimpleLdb(LdbBaseTest): class SimpleLdbLmdb(SimpleLdb): def setUp(self): + if os.environ.get('HAVE_LMDB', '1') == '0': + self.skipTest("No lmdb backend") self.prefix = MDB_PREFIX self.index = MDB_INDEX_OBJ super(SimpleLdbLmdb, self).setUp() @@ -718,6 +720,29 @@ class SimpleLdbLmdb(SimpleLdb): super(SimpleLdbLmdb, self).tearDown() +class SimpleLdbNoLmdb(LdbBaseTest): + + def setUp(self): + if os.environ.get('HAVE_LMDB', '1') != '0': + self.skipTest("lmdb backend enabled") + self.prefix = MDB_PREFIX + self.index = MDB_INDEX_OBJ + super(SimpleLdbNoLmdb, self).setUp() + + def tearDown(self): + super(SimpleLdbNoLmdb, self).tearDown() + + def test_lmdb_disabled(self): + self.testdir = tempdir() + self.filename = os.path.join(self.testdir, "test.ldb") + try: + self.ldb = ldb.Ldb(self.url(), flags=self.flags()) + self.fail("Should have failed on missing LMDB") + except ldb.LdbError as err: + enum = err.args[0] + self.assertEqual(enum, ldb.LDB_ERR_OTHER) + + class SearchTests(LdbBaseTest): def tearDown(self): shutil.rmtree(self.testdir) @@ -1369,6 +1394,8 @@ class SearchTests(LdbBaseTest): class SearchTestsLmdb(SearchTests): def setUp(self): + if os.environ.get('HAVE_LMDB', '1') == '0': + self.skipTest("No lmdb backend") self.prefix = MDB_PREFIX self.index = MDB_INDEX_OBJ super(SearchTestsLmdb, self).setUp() @@ -1510,6 +1537,8 @@ class GUIDAndOneLevelIndexedSearchTests(SearchTests): class GUIDIndexedSearchTestsLmdb(GUIDIndexedSearchTests): def setUp(self): + if os.environ.get('HAVE_LMDB', '1') == '0': + self.skipTest("No lmdb backend") self.prefix = MDB_PREFIX super(GUIDIndexedSearchTestsLmdb, self).setUp() @@ -1520,6 +1549,8 @@ class GUIDIndexedSearchTestsLmdb(GUIDIndexedSearchTests): class GUIDIndexedDNFilterSearchTestsLmdb(GUIDIndexedDNFilterSearchTests): def setUp(self): + if os.environ.get('HAVE_LMDB', '1') == '0': + self.skipTest("No lmdb backend") self.prefix = MDB_PREFIX super(GUIDIndexedDNFilterSearchTestsLmdb, self).setUp() @@ -1530,6 +1561,8 @@ class GUIDIndexedDNFilterSearchTestsLmdb(GUIDIndexedDNFilterSearchTests): class GUIDAndOneLevelIndexedSearchTestsLmdb(GUIDAndOneLevelIndexedSearchTests): def setUp(self): + if os.environ.get('HAVE_LMDB', '1') == '0': + self.skipTest("No lmdb backend") self.prefix = MDB_PREFIX super(GUIDAndOneLevelIndexedSearchTestsLmdb, self).setUp() @@ -1740,6 +1773,8 @@ class AddModifyTests(LdbBaseTest): class AddModifyTestsLmdb(AddModifyTests): def setUp(self): + if os.environ.get('HAVE_LMDB', '1') == '0': + self.skipTest("No lmdb backend") self.prefix = MDB_PREFIX self.index = MDB_INDEX_OBJ super(AddModifyTestsLmdb, self).setUp() @@ -1868,6 +1903,8 @@ class TransIndexedAddModifyTests(IndexedAddModifyTests): class GuidIndexedAddModifyTestsLmdb(GUIDIndexedAddModifyTests): def setUp(self): + if os.environ.get('HAVE_LMDB', '1') == '0': + self.skipTest("No lmdb backend") self.prefix = MDB_PREFIX super(GuidIndexedAddModifyTestsLmdb, self).setUp() @@ -1878,6 +1915,8 @@ class GuidIndexedAddModifyTestsLmdb(GUIDIndexedAddModifyTests): class GuidTransIndexedAddModifyTestsLmdb(GUIDTransIndexedAddModifyTests): def setUp(self): + if os.environ.get('HAVE_LMDB', '1') == '0': + self.skipTest("No lmdb backend") self.prefix = MDB_PREFIX super(GuidTransIndexedAddModifyTestsLmdb, self).setUp() @@ -2933,6 +2972,8 @@ class LdbResultTests(LdbBaseTest): class LdbResultTestsLmdb(LdbResultTests): def setUp(self): + if os.environ.get('HAVE_LMDB', '1') == '0': + self.skipTest("No lmdb backend") self.prefix = MDB_PREFIX self.index = MDB_INDEX_OBJ super(LdbResultTestsLmdb, self).setUp() diff --git a/lib/ldb/tests/python/index.py b/lib/ldb/tests/python/index.py index 3652901888e..48dbaccfa56 100755 --- a/lib/ldb/tests/python/index.py +++ b/lib/ldb/tests/python/index.py @@ -1286,6 +1286,8 @@ class MaxIndexKeyLengthTests(LdbBaseTest): class MaxIndexKeyLengthTestsLmdb(MaxIndexKeyLengthTests): def setUp(self): + if os.environ.get('HAVE_LMDB', '1') == '0': + self.skipTest("No lmdb backend") self.prefix = MDB_PREFIX super(MaxIndexKeyLengthTestsLmdb, self).setUp() @@ -1297,6 +1299,8 @@ class MaxIndexKeyLengthTestsLmdb(MaxIndexKeyLengthTests): class RejectSubDBIndex(LdbBaseTest): def setUp(self): + if os.environ.get('HAVE_LMDB', '1') == '0': + self.skipTest("No lmdb backend") self.prefix = MDB_PREFIX super(RejectSubDBIndex, self).setUp() self.testdir = tempdir() diff --git a/lib/ldb/wscript b/lib/ldb/wscript index c59d4ead7b9..8f14b09b583 100644 --- a/lib/ldb/wscript +++ b/lib/ldb/wscript @@ -197,6 +197,7 @@ def configure(conf): if conf.CHECK_FUNCS_IN('mdb_env_create', 'lmdb', headers='lmdb.h'): conf.DEFINE('HAVE_LMDB', '1') + conf.env.HAVE_LMDB = True conf.DEFINE('HAVE_CONFIG_H', 1, add_to_cflags=True) @@ -539,21 +540,26 @@ def build(bld): cflags='-DTEST_BE=\"mdb\"', deps='cmocka ldb', install=False) + else: + bld.SAMBA_BINARY('ldb_no_lmdb_test', + source='tests/ldb_no_lmdb_test.c', + deps='cmocka ldb', + install=False) def test(ctx): '''run ldb testsuite''' env = samba_utils.LOAD_ENVIRONMENT() ctx.env = env - if not env.HAVE_LMDB: - raise Errors.WafError('make test called, but ldb was built ' - '--without-ldb-lmdb') - test_prefix = "%s/st" % (Context.g_module.out) shutil.rmtree(test_prefix, ignore_errors=True) os.makedirs(test_prefix) os.environ['TEST_DATA_PREFIX'] = test_prefix os.environ['LDB_MODULES_PATH'] = Context.g_module.out + "/modules/ldb" + if env.HAVE_LMDB: + os.environ['HAVE_LMDB'] = '1' + else: + os.environ['HAVE_LMDB'] = '0' samba_utils.ADD_LD_LIBRARY_PATH('bin/shared') samba_utils.ADD_LD_LIBRARY_PATH('bin/shared/private') @@ -578,14 +584,18 @@ def test(ctx): 'ldb_msg_test', 'ldb_tdb_kv_ops_test', 'ldb_tdb_test', - 'ldb_mdb_mod_op_test', - 'ldb_lmdb_test', - # we don't want to run ldb_lmdb_size_test (which proves we can - # fit > 4G of data into the DB), it would fill up the disk on - # many of our test instances - 'ldb_mdb_kv_ops_test', 'ldb_match_test'] + if env.HAVE_LMDB: + test_exes += ['ldb_mdb_mod_op_test', + 'ldb_lmdb_test', + # we don't want to run ldb_lmdb_size_test (which proves we can + # fit > 4G of data into the DB), it would fill up the disk on + # many of our test instances + 'ldb_mdb_kv_ops_test'] + else: + test_exes += ['ldb_no_lmdb_test'] + for test_exe in test_exes: cmd = os.path.join(Context.g_module.out, test_exe) cmocka_ret = cmocka_ret or samba_utils.RUN_COMMAND(cmd) |