Line data Source code
1 : #include "../common/tdb_private.h"
2 : #include "../common/io.c"
3 : #include "../common/tdb.c"
4 : #include "../common/lock.c"
5 : #include "../common/freelist.c"
6 : #include "../common/traverse.c"
7 : #include "../common/transaction.c"
8 : #include "../common/error.c"
9 : #include "../common/open.c"
10 : #include "../common/check.c"
11 : #include "../common/hash.c"
12 : #include "../common/mutex.c"
13 : #include "tap-interface.h"
14 : #include <stdlib.h>
15 :
16 4 : static void log_fn(struct tdb_context *tdb, enum tdb_debug_level level, const char *fmt, ...)
17 : {
18 4 : unsigned int *count = tdb_get_logging_private(tdb);
19 4 : if (strstr(fmt, "hash"))
20 4 : (*count)++;
21 4 : }
22 :
23 1 : int main(int argc, char *argv[])
24 : {
25 : struct tdb_context *tdb;
26 : unsigned int log_count;
27 : TDB_DATA d;
28 1 : struct tdb_logging_context log_ctx = { log_fn, &log_count };
29 :
30 : plan_tests(28);
31 :
32 : /* Create with default hash. */
33 1 : log_count = 0;
34 1 : tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0,
35 : O_CREAT|O_RDWR|O_TRUNC, 0600, &log_ctx, NULL);
36 1 : ok1(tdb);
37 1 : ok1(log_count == 0);
38 1 : d.dptr = discard_const_p(uint8_t, "Hello");
39 1 : d.dsize = 5;
40 1 : ok1(tdb_store(tdb, d, d, TDB_INSERT) == 0);
41 1 : tdb_close(tdb);
42 :
43 : /* Fail to open with different hash. */
44 1 : tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDWR, 0,
45 : &log_ctx, tdb_jenkins_hash);
46 1 : ok1(!tdb);
47 1 : ok1(log_count == 1);
48 :
49 : /* Create with different hash. */
50 1 : log_count = 0;
51 1 : tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0,
52 : O_CREAT|O_RDWR|O_TRUNC,
53 : 0600, &log_ctx, tdb_jenkins_hash);
54 1 : ok1(tdb);
55 1 : ok1(log_count == 0);
56 1 : tdb_close(tdb);
57 :
58 : /* Endian should be no problem. */
59 1 : log_count = 0;
60 1 : tdb = tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDWR, 0,
61 : &log_ctx, tdb_old_hash);
62 1 : ok1(!tdb);
63 1 : ok1(log_count == 1);
64 :
65 1 : log_count = 0;
66 1 : tdb = tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDWR, 0,
67 : &log_ctx, tdb_old_hash);
68 1 : ok1(!tdb);
69 1 : ok1(log_count == 1);
70 :
71 1 : log_count = 0;
72 : /* Fail to open with old default hash. */
73 1 : tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDWR, 0,
74 : &log_ctx, tdb_old_hash);
75 1 : ok1(!tdb);
76 1 : ok1(log_count == 1);
77 :
78 1 : log_count = 0;
79 1 : tdb = tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDONLY,
80 : 0, &log_ctx, tdb_jenkins_hash);
81 1 : ok1(tdb);
82 1 : ok1(log_count == 0);
83 1 : ok1(tdb_check(tdb, NULL, NULL) == 0);
84 1 : tdb_close(tdb);
85 :
86 1 : log_count = 0;
87 1 : tdb = tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDONLY,
88 : 0, &log_ctx, tdb_jenkins_hash);
89 1 : ok1(tdb);
90 1 : ok1(log_count == 0);
91 1 : ok1(tdb_check(tdb, NULL, NULL) == 0);
92 1 : tdb_close(tdb);
93 :
94 : /* It should open with jenkins hash if we don't specify. */
95 1 : log_count = 0;
96 1 : tdb = tdb_open_ex("test/jenkins-le-hash.tdb", 0, 0, O_RDWR, 0,
97 : &log_ctx, NULL);
98 1 : ok1(tdb);
99 1 : ok1(log_count == 0);
100 1 : ok1(tdb_check(tdb, NULL, NULL) == 0);
101 1 : tdb_close(tdb);
102 :
103 1 : log_count = 0;
104 1 : tdb = tdb_open_ex("test/jenkins-be-hash.tdb", 0, 0, O_RDWR, 0,
105 : &log_ctx, NULL);
106 1 : ok1(tdb);
107 1 : ok1(log_count == 0);
108 1 : ok1(tdb_check(tdb, NULL, NULL) == 0);
109 1 : tdb_close(tdb);
110 :
111 1 : log_count = 0;
112 1 : tdb = tdb_open_ex("run-wronghash-fail.tdb", 0, 0, O_RDONLY,
113 : 0, &log_ctx, NULL);
114 1 : ok1(tdb);
115 1 : ok1(log_count == 0);
116 1 : ok1(tdb_check(tdb, NULL, NULL) == 0);
117 1 : tdb_close(tdb);
118 :
119 :
120 1 : return exit_status();
121 : }
|