From 9660546a18cc9af508e6e594349d869bdcefafb2 Mon Sep 17 00:00:00 2001 From: Rusty Russell Date: Wed, 14 Sep 2011 07:24:13 +0930 Subject: tdb2: test: import tdb1's tests. The main change is to s/tdb/tdb1_/ everywhere. Signed-off-by: Rusty Russell (Imported from CCAN commit fab544c24c1ad6523f95893abcaec4e6cce6c2b4) --- lib/tdb2/test/run-tdb1-summary.c | 54 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 lib/tdb2/test/run-tdb1-summary.c (limited to 'lib/tdb2/test/run-tdb1-summary.c') diff --git a/lib/tdb2/test/run-tdb1-summary.c b/lib/tdb2/test/run-tdb1-summary.c new file mode 100644 index 0000000000..ccfc0958e1 --- /dev/null +++ b/lib/tdb2/test/run-tdb1-summary.c @@ -0,0 +1,54 @@ +#include "tdb2-source.h" +#include +#include +#include + +int main(int argc, char *argv[]) +{ + unsigned int i, j; + struct tdb1_context *tdb; + int flags[] = { TDB1_INTERNAL, TDB1_DEFAULT, TDB1_NOMMAP, + TDB1_INTERNAL|TDB1_CONVERT, TDB1_CONVERT, + TDB1_NOMMAP|TDB1_CONVERT }; + TDB1_DATA key = { (unsigned char *)&j, sizeof(j) }; + TDB1_DATA data = { (unsigned char *)&j, sizeof(j) }; + char *summary; + + plan_tests(sizeof(flags) / sizeof(flags[0]) * 14); + for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) { + tdb = tdb1_open("run-summary.tdb", 131, flags[i], + O_RDWR|O_CREAT|O_TRUNC, 0600); + ok1(tdb); + if (!tdb) + continue; + + /* Put some stuff in there. */ + for (j = 0; j < 500; j++) { + /* Make sure padding varies to we get some graphs! */ + data.dsize = j % (sizeof(j) + 1); + if (tdb1_store(tdb, key, data, TDB1_REPLACE) != 0) + fail("Storing in tdb"); + } + + summary = tdb1_summary(tdb); + diag("%s", summary); + ok1(strstr(summary, "Size of file/data: ")); + ok1(strstr(summary, "Number of records: 500\n")); + ok1(strstr(summary, "Smallest/average/largest keys: 4/4/4\n")); + ok1(strstr(summary, "Smallest/average/largest data: 0/2/4\n")); + ok1(strstr(summary, "Smallest/average/largest padding: ")); + ok1(strstr(summary, "Number of dead records: 0\n")); + ok1(strstr(summary, "Number of free records: 1\n")); + ok1(strstr(summary, "Smallest/average/largest free records: ")); + ok1(strstr(summary, "Number of hash chains: 131\n")); + ok1(strstr(summary, "Smallest/average/largest hash chains: ")); + ok1(strstr(summary, "Number of uncoalesced records: 0\n")); + ok1(strstr(summary, "Smallest/average/largest uncoalesced runs: 0/0/0\n")); + ok1(strstr(summary, "Percentage keys/data/padding/free/dead/rechdrs&tailers/hashes: ")); + + free(summary); + tdb1_close(tdb); + } + + return exit_status(); +} -- cgit