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/summary.c>
8 #include <ccan/tap/tap.h>
11 int main(int argc, char *argv[])
14 struct tdb_context *tdb;
15 int flags[] = { TDB_INTERNAL, TDB_DEFAULT, TDB_NOMMAP,
16 TDB_INTERNAL|TDB_CONVERT, TDB_CONVERT,
17 TDB_NOMMAP|TDB_CONVERT };
18 struct tdb_data key = { (unsigned char *)&j, sizeof(j) };
19 struct tdb_data data = { (unsigned char *)&j, sizeof(j) };
22 plan_tests(sizeof(flags) / sizeof(flags[0]) * (1 + 2 * 17) + 1);
23 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
24 tdb = tdb_open("run-summary.tdb", flags[i],
25 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
30 /* Put some stuff in there. */
31 for (j = 0; j < 500; j++) {
32 /* Make sure padding varies to we get some graphs! */
33 data.dsize = j % (sizeof(j) + 1);
34 if (tdb_store(tdb, key, data, TDB_REPLACE) != 0)
35 fail("Storing in tdb");
39 j <= TDB_SUMMARY_HISTOGRAMS;
40 j += TDB_SUMMARY_HISTOGRAMS) {
41 summary = tdb_summary(tdb, j);
42 ok1(strstr(summary, "Number of records: 500\n"));
43 ok1(strstr(summary, "Smallest/average/largest keys: 4/4/4\n"));
44 ok1(strstr(summary, "Smallest/average/largest data: 0/2/4\n"));
45 ok1(strstr(summary, "Free bucket 16:"));
46 ok1(strstr(summary, "Free bucket 24:"));
47 ok1(strstr(summary, "Free bucket 32:"));
48 ok1(strstr(summary, "Free bucket 40:"));
49 ok1(strstr(summary, "Free bucket 48:"));
50 ok1(strstr(summary, "Free bucket 56:"));
51 ok1(strstr(summary, "Free bucket 64:"));
52 ok1(strstr(summary, "Free bucket 72:"));
53 ok1(strstr(summary, "Free bucket 80:"));
54 ok1(strstr(summary, "Free bucket 88-136:"));
55 ok1(strstr(summary, "Free bucket 144-264:"));
56 ok1(strstr(summary, "Free bucket 272-520:"));
57 ok1(strstr(summary, "Free bucket 528-1032:"));
58 if (j == TDB_SUMMARY_HISTOGRAMS)
59 ok1(strstr(summary, "|")
60 && strstr(summary, "*"));
62 ok1(!strstr(summary, "|")
63 && !strstr(summary, "*"));
69 ok1(tap_log_messages == 0);