2 * lmdb backend specific tests for ldb
3 * Tests for truncated index keys
5 * Copyright (C) Andrew Bartlett <abartlet@samba.org> 2018
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
23 * These tests confirm that database sizes of > 4GB are supported
24 * Due to the disk space requirement they are not run as part of the normal
27 * Setup and tear down code copied from ldb_mod_op_test.c
32 * These headers or their equivalents should be included prior to
40 * This allows test applications to use custom definitions of C standard
41 * library functions and types.
54 #include <ldb_module.h>
55 #include <ldb_private.h>
67 struct tevent_context
*ev
;
68 struct ldb_context
*ldb
;
71 const char *lockfile
; /* lockfile is separate */
76 static void unlink_old_db(struct ldbtest_ctx
*test_ctx
)
81 ret
= unlink(test_ctx
->lockfile
);
82 if (ret
== -1 && errno
!= ENOENT
) {
87 ret
= unlink(test_ctx
->dbfile
);
88 if (ret
== -1 && errno
!= ENOENT
) {
93 static int ldbtest_noconn_setup(void **state
)
95 struct ldbtest_ctx
*test_ctx
;
97 test_ctx
= talloc_zero(NULL
, struct ldbtest_ctx
);
98 assert_non_null(test_ctx
);
100 test_ctx
->ev
= tevent_context_init(test_ctx
);
101 assert_non_null(test_ctx
->ev
);
103 test_ctx
->ldb
= ldb_init(test_ctx
, test_ctx
->ev
);
104 assert_non_null(test_ctx
->ldb
);
106 test_ctx
->dbfile
= talloc_strdup(test_ctx
, "apitest.ldb");
107 assert_non_null(test_ctx
->dbfile
);
109 test_ctx
->lockfile
= talloc_asprintf(test_ctx
, "%s-lock",
111 assert_non_null(test_ctx
->lockfile
);
113 test_ctx
->dbpath
= talloc_asprintf(test_ctx
,
114 TEST_BE
"://%s", test_ctx
->dbfile
);
115 assert_non_null(test_ctx
->dbpath
);
117 unlink_old_db(test_ctx
);
122 static int ldbtest_noconn_teardown(void **state
)
124 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
127 unlink_old_db(test_ctx
);
128 talloc_free(test_ctx
);
132 static int ldbtest_setup(void **state
)
134 struct ldbtest_ctx
*test_ctx
;
137 ldbtest_noconn_setup((void **) &test_ctx
);
139 ret
= ldb_connect(test_ctx
->ldb
, test_ctx
->dbpath
, 0, NULL
);
140 assert_int_equal(ret
, 0);
146 static int ldbtest_teardown(void **state
)
148 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
150 ldbtest_noconn_teardown((void **) &test_ctx
);
154 static void test_db_size_gt_4GB(void **state
)
157 struct ldb_message
*msg
;
158 struct ldbtest_ctx
*test_ctx
= talloc_get_type_abort(*state
,
160 const int MB
= 1024 * 1024;
165 tmp_ctx
= talloc_new(test_ctx
);
166 assert_non_null(tmp_ctx
);
169 blob
= talloc_zero_size(tmp_ctx
, (MB
+ 1));
170 assert_non_null(blob
);
171 memset(blob
, 'x', MB
);
174 for (x
= 0; x
< 6144; x
++) {
175 msg
= ldb_msg_new(tmp_ctx
);
176 assert_non_null(msg
);
178 msg
->dn
= ldb_dn_new_fmt(msg
, test_ctx
->ldb
, "dc=test%d", x
);
179 assert_non_null(msg
->dn
);
181 ldb_transaction_start(test_ctx
->ldb
);
182 ret
= ldb_msg_add_string(msg
, "blob", blob
);
183 assert_int_equal(ret
, 0);
185 ret
= ldb_add(test_ctx
->ldb
, msg
);
186 assert_int_equal(ret
, 0);
187 ldb_transaction_commit(test_ctx
->ldb
);
191 talloc_free(tmp_ctx
);
194 ret
= stat(test_ctx
->dbfile
, &s
);
195 assert_int_equal(ret
, 0);
196 assert_true(s
.st_size
> (6144LL * MB
));
200 int main(int argc
, const char **argv
)
202 const struct CMUnitTest tests
[] = {
203 cmocka_unit_test_setup_teardown(
209 return cmocka_run_group_tests(tests
, NULL
, NULL
);