1 #include "tdb2-source.h"
2 #include <ccan/tap/tap.h>
5 static int log_count
= 0;
7 /* Normally we get a log when setting random seed. */
8 static void my_log_fn(struct tdb_context
*tdb
,
9 enum tdb_log_level level
,
11 const char *message
, void *priv
)
16 static union tdb_attribute log_attr
= {
17 .log
= { .base
= { .attr
= TDB_ATTRIBUTE_LOG
},
21 int main(int argc
, char *argv
[])
24 struct tdb_context
*tdb
;
25 union tdb_attribute attr
;
26 int flags
[] = { TDB_INTERNAL
, TDB_DEFAULT
, TDB_NOMMAP
,
27 TDB_INTERNAL
|TDB_CONVERT
, TDB_CONVERT
,
28 TDB_NOMMAP
|TDB_CONVERT
};
30 attr
.seed
.base
.attr
= TDB_ATTRIBUTE_SEED
;
31 attr
.seed
.base
.next
= &log_attr
;
34 plan_tests(sizeof(flags
) / sizeof(flags
[0]) * 4 + 4 * 3);
35 for (i
= 0; i
< sizeof(flags
) / sizeof(flags
[0]); i
++) {
36 struct tdb_header hdr
;
38 tdb
= tdb_open("run-seed.tdb", flags
[i
],
39 O_RDWR
|O_CREAT
|O_TRUNC
, 0600, &attr
);
43 ok1(tdb_check(tdb
, NULL
, NULL
) == 0);
44 ok1(tdb
->hash_seed
== 42);
48 if (flags
[i
] & TDB_INTERNAL
)
51 fd
= open("run-seed.tdb", O_RDONLY
);
53 ok1(read(fd
, &hdr
, sizeof(hdr
)) == sizeof(hdr
));
54 if (flags
[i
] & TDB_CONVERT
)
55 ok1(bswap_64(hdr
.hash_seed
) == 42);
57 ok1(hdr
.hash_seed
== 42);