]> git.ozlabs.org Git - ccan/blob - ccan/tdb2/test/run-tdb1-summary.c
tdb2: Remove unused tdb1 functions.
[ccan] / ccan / tdb2 / test / run-tdb1-summary.c
1 #include "tdb2-source.h"
2 #include <ccan/tap/tap.h>
3 #include <stdlib.h>
4 #include <err.h>
5
6 int main(int argc, char *argv[])
7 {
8         unsigned int i, j;
9         struct tdb1_context *tdb;
10         int flags[] = { TDB1_INTERNAL, TDB1_DEFAULT, TDB1_NOMMAP,
11                         TDB1_INTERNAL|TDB1_CONVERT, TDB1_CONVERT,
12                         TDB1_NOMMAP|TDB1_CONVERT };
13         TDB1_DATA key = { (unsigned char *)&j, sizeof(j) };
14         TDB1_DATA data = { (unsigned char *)&j, sizeof(j) };
15         char *summary;
16
17         plan_tests(sizeof(flags) / sizeof(flags[0]) * 14);
18         for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
19                 tdb = tdb1_open("run-summary.tdb", 131, flags[i],
20                                O_RDWR|O_CREAT|O_TRUNC, 0600);
21                 ok1(tdb);
22                 if (!tdb)
23                         continue;
24
25                 /* Put some stuff in there. */
26                 for (j = 0; j < 500; j++) {
27                         /* Make sure padding varies to we get some graphs! */
28                         data.dsize = j % (sizeof(j) + 1);
29                         if (tdb1_store(tdb, key, data, TDB1_REPLACE) != 0)
30                                 fail("Storing in tdb");
31                 }
32
33                 summary = tdb1_summary(tdb);
34                 diag("%s", summary);
35                 ok1(strstr(summary, "Size of file/data: "));
36                 ok1(strstr(summary, "Number of records: 500\n"));
37                 ok1(strstr(summary, "Smallest/average/largest keys: 4/4/4\n"));
38                 ok1(strstr(summary, "Smallest/average/largest data: 0/2/4\n"));
39                 ok1(strstr(summary, "Smallest/average/largest padding: "));
40                 ok1(strstr(summary, "Number of dead records: 0\n"));
41                 ok1(strstr(summary, "Number of free records: 1\n"));
42                 ok1(strstr(summary, "Smallest/average/largest free records: "));
43                 ok1(strstr(summary, "Number of hash chains: 131\n"));
44                 ok1(strstr(summary, "Smallest/average/largest hash chains: "));
45                 ok1(strstr(summary, "Number of uncoalesced records: 0\n"));
46                 ok1(strstr(summary, "Smallest/average/largest uncoalesced runs: 0/0/0\n"));
47                 ok1(strstr(summary, "Percentage keys/data/padding/free/dead/rechdrs&tailers/hashes: "));
48
49                 free(summary);
50                 tdb1_close(tdb);
51         }
52
53         return exit_status();
54 }