Debian Codegraph @

build_vxworks/test/micro/b_open.c

raw
1 /*
2 * See the file LICENSE for redistribution information.
3 *
4 * Copyright (c) 2005, 2013 Oracle and/or its affiliates. All rights reserved.
5 *
6 * $Id$
7 */
8 #include "bench.h"
9
10 static int b_open_usage(void);
11
12 int
13 b_open(int argc, char *argv[])
14 {
15 extern char *optarg;
16 extern int optind, __db_getopt_reset;
17 DB_ENV *dbenv;
18 DB *dbp;
19 DBTYPE type;
20 int ch, i, count;
21 char *fname, *dbname, *ts;
22
23 type = DB_BTREE;
24 count = 1000;
25 fname = dbname = NULL;
26 ts = "Btree";
27 __db_getopt_reset = 1;
28 while ((ch = getopt(argc, argv, "c:dft:")) != EOF)
29 switch (ch) {
30 case 'c':
31 count = atoi(optarg);
32 break;
33 case 'd':
34 dbname = "dbname";
35 break;
36 case 'f':
37 fname = "filename";
38 break;
39 case 't':
40 switch (optarg[0]) {
41 case 'B': case 'b':
42 ts = "Btree";
43 type = DB_BTREE;
44 break;
45 case 'H': case 'h':
46 if (optarg[1] == 'E' || optarg[1] == 'e') {
47 #if DB_VERSION_MAJOR > 5 || (DB_VERSION_MAJOR == 5 && DB_VERSION_MINOR >= 2)
48 if (b_util_have_heap())
49 return (0);
50 ts = "Heap";
51 type = DB_HEAP;
52 #else
53 fprintf(stderr,
54 "b_curwalk: Heap is not supported! \n");
55 return (EXIT_SUCCESS);
56 #endif
57 } else {
58 if (b_util_have_hash())
59 return (0);
60 ts = "Hash";
61 type = DB_HASH;
62 }
63 break;
64 case 'Q': case 'q':
65 if (b_util_have_queue())
66 return (0);
67 ts = "Queue";
68 type = DB_QUEUE;
69 break;
70 case 'R': case 'r':
71 ts = "Recno";
72 type = DB_RECNO;
73 break;
74 default:
75 return (b_open_usage());
76 }
77 break;
78 case '?':
79 default:
80 return (b_open_usage());
81 }
82 argc -= optind;
83 argv += optind;
84 if (argc != 0)
85 return (b_open_usage());
86
87 #if DB_VERSION_MAJOR < 4
88 /*
89 * Don't run in-memory database tests on versions less than 3, it
90 * takes forever and eats memory.
91 */
92 if (fname == NULL && dbname == NULL)
93 return (0);
94 #endif
95 #if DB_VERSION_MAJOR < 4 || DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR < 4
96 /*
97 * Named in-memory databases weren't available until 4.4.
98 */
99 if (fname == NULL && dbname != NULL)
100 return (0);
101 #endif
102
103 /* Create the environment. */
104 DB_BENCH_ASSERT(db_env_create(&dbenv, 0) == 0);
105 dbenv->set_errfile(dbenv, stderr);
106 #if DB_VERSION_MAJOR == 3 && DB_VERSION_MINOR == 0
107 DB_BENCH_ASSERT(dbenv->open(dbenv, TESTDIR,
108 NULL, DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE, 0666) == 0);
109 #else
110 DB_BENCH_ASSERT(dbenv->open(dbenv, TESTDIR,
111 DB_CREATE | DB_INIT_MPOOL | DB_PRIVATE, 0666) == 0);
112 #endif
113
114 /* Create the database. */
115 DB_BENCH_ASSERT(db_create(&dbp, dbenv, 0) == 0);
116
117 #if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1)
118 DB_BENCH_ASSERT(dbp->open(
119 dbp, NULL, fname, dbname, type, DB_CREATE, 0666) == 0);
120 #else
121 DB_BENCH_ASSERT(dbp->open(
122 dbp, fname, dbname, type, DB_CREATE, 0666) == 0);
123 #endif
124 DB_BENCH_ASSERT(dbp->close(dbp, 0) == 0);
125
126 /* Open the database count times. */
127 TIMER_START;
128 for (i = 0; i < count; ++i) {
129 DB_BENCH_ASSERT(db_create(&dbp, dbenv, 0) == 0);
130 #if DB_VERSION_MAJOR > 4 || (DB_VERSION_MAJOR == 4 && DB_VERSION_MINOR >= 1)
131 DB_BENCH_ASSERT(dbp->open(
132 dbp, NULL, fname, dbname, type, DB_CREATE, 0666) == 0);
133 #else
134 DB_BENCH_ASSERT(dbp->open(
135 dbp, fname, dbname, type, DB_CREATE, 0666) == 0);
136 #endif
137 DB_BENCH_ASSERT(dbp->close(dbp, 0) == 0);
138 }
139 TIMER_STOP;
140
141 printf("# %d %s %sdatabase open/close pairs\n",
142 count, ts,
143 fname == NULL ?
144 (dbname == NULL ? "in-memory " : "named in-memory ") :
145 (dbname == NULL ? "" : "sub-"));
146 TIMER_DISPLAY(count);
147
148 DB_BENCH_ASSERT(dbenv->close(dbenv, 0) == 0);
149
150 return (0);
151 }
152
153 static int
154 b_open_usage()
155 {
156 (void)fprintf(stderr, "usage: b_open [-df] [-c count] [-t type]\n");
157 return (EXIT_FAILURE);
158 }