1 #include <ccan/tdb2/tdb.c>
2 #include <ccan/tdb2/free.c>
3 #include <ccan/tdb2/lock.c>
4 #include <ccan/tdb2/io.c>
5 #include <ccan/tdb2/hash.c>
6 #include <ccan/tdb2/check.c>
7 #include <ccan/tdb2/transaction.c>
8 #include <ccan/tap/tap.h>
11 static int log_count = 0;
13 /* Normally we get a log when setting random seed. */
14 static void my_log_fn(struct tdb_context *tdb,
15 enum tdb_log_level level, void *priv,
21 static union tdb_attribute log_attr = {
22 .log = { .base = { .attr = TDB_ATTRIBUTE_LOG },
26 int main(int argc, char *argv[])
29 struct tdb_context *tdb;
30 union tdb_attribute attr;
31 int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
32 TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
33 TDB_NOMMAP|TDB_CONVERT };
35 attr.seed.base.attr = TDB_ATTRIBUTE_SEED;
36 attr.seed.base.next = &log_attr;
39 plan_tests(sizeof(flags) / sizeof(flags[0]) * 4 + 4 * 3);
40 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
41 struct tdb_header hdr;
43 tdb = tdb_open("run-seed.tdb", flags[i],
44 O_RDWR|O_CREAT|O_TRUNC, 0600, &attr);
48 ok1(tdb_check(tdb, NULL, NULL) == 0);
49 ok1(tdb->hash_seed == 42);
53 if (flags[i] & TDB_INTERNAL)
56 fd = open("run-seed.tdb", O_RDONLY);
58 ok1(read(fd, &hdr, sizeof(hdr)) == sizeof(hdr));
59 if (flags[i] & TDB_CONVERT)
60 ok1(bswap_64(hdr.hash_seed) == 42);
62 ok1(hdr.hash_seed == 42);