s3:lib/afs fix the build
[Samba/bjacke.git] / lib / ntdb / test / api-91-get-stats.c
blob1ed36f028daa1e7fc980ee861d78b38dc8db91e3
1 #include "config.h"
2 #include "ntdb.h"
3 #include "tap-interface.h"
4 #include <sys/types.h>
5 #include <sys/stat.h>
6 #include <fcntl.h>
7 #include <stdlib.h>
8 #include <stddef.h>
9 #include "logging.h"
11 int main(int argc, char *argv[])
13 unsigned int i;
14 struct ntdb_context *ntdb;
15 int flags[] = { NTDB_DEFAULT, NTDB_NOMMAP,
16 NTDB_CONVERT, NTDB_NOMMAP|NTDB_CONVERT };
18 plan_tests(sizeof(flags) / sizeof(flags[0]) * 11);
20 for (i = 0; i < sizeof(flags) / sizeof(flags[0]); i++) {
21 union ntdb_attribute *attr;
22 NTDB_DATA key = ntdb_mkdata("key", 3), data;
24 ntdb = ntdb_open("run-91-get-stats.ntdb", flags[i]|MAYBE_NOSYNC,
25 O_RDWR|O_CREAT|O_TRUNC, 0600, &tap_log_attr);
26 ok1(ntdb);
27 /* Force an expansion */
28 data.dsize = 65536;
29 data.dptr = calloc(data.dsize, 1);
30 ok1(ntdb_store(ntdb, key, data, NTDB_REPLACE) == 0);
31 free(data.dptr);
33 /* Use malloc so valgrind will catch overruns. */
34 attr = malloc(sizeof *attr);
35 attr->stats.base.attr = NTDB_ATTRIBUTE_STATS;
36 attr->stats.size = sizeof(*attr);
38 ok1(ntdb_get_attribute(ntdb, attr) == 0);
39 ok1(attr->stats.size == sizeof(*attr));
40 ok1(attr->stats.allocs > 0);
41 ok1(attr->stats.expands > 0);
42 ok1(attr->stats.locks > 0);
43 free(attr);
45 /* Try short one. */
46 attr = malloc(offsetof(struct ntdb_attribute_stats, allocs)
47 + sizeof(attr->stats.allocs));
48 attr->stats.base.attr = NTDB_ATTRIBUTE_STATS;
49 attr->stats.size = offsetof(struct ntdb_attribute_stats, allocs)
50 + sizeof(attr->stats.allocs);
51 ok1(ntdb_get_attribute(ntdb, attr) == 0);
52 ok1(attr->stats.size == sizeof(*attr));
53 ok1(attr->stats.allocs > 0);
54 free(attr);
55 ok1(tap_log_messages == 0);
57 ntdb_close(ntdb);
60 return exit_status();