summaryrefslogtreecommitdiff
path: root/test/scr029/t.c
blob: 22a61d60a3b1f7bd396153c1660372fe22d66992 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
/*-
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2002-2009 Oracle.  All rights reserved.
 */

#include <sys/types.h>

#include <assert.h>
#include <stdlib.h>
#include <string.h>

#include "db.h"

#define	ENV {								\
	if (dbenv != NULL)						\
		assert(dbenv->close(dbenv, 0) == 0);			\
	assert(db_env_create(&dbenv, 0) == 0);				\
	dbenv->set_errfile(dbenv, stderr);				\
}

int
main()
{
	const u_int8_t *lk_conflicts;
	DB_ENV *dbenv;
	db_timeout_t timeout;
	u_int32_t a, b, c, v;
	int nmodes, lk_modes;
	u_int8_t conflicts[40];

	dbenv = NULL;

	/* tx_max: NOT reset at run-time. */
	system("rm -rf TESTDIR; mkdir TESTDIR");
	ENV
	assert(dbenv->set_tx_max(dbenv, 37) == 0);
	assert(dbenv->open(dbenv,
	    "TESTDIR", DB_CREATE | DB_INIT_TXN, 0666) == 0);
	assert(dbenv->get_tx_max(dbenv, &v) == 0);
	assert(v == 37);
	ENV
	assert(dbenv->set_tx_max(dbenv, 63) == 0);
	assert(dbenv->open(dbenv, "TESTDIR", DB_JOINENV, 0666) == 0);
	assert(dbenv->get_tx_max(dbenv, &v) == 0);
	assert(v == 37);

	/* lg_max: reset at run-time. */
	system("rm -rf TESTDIR; mkdir TESTDIR");
	ENV
	assert(dbenv->set_lg_max(dbenv, 37 * 1024 * 1024) == 0);
	assert(dbenv->open(dbenv,
	    "TESTDIR", DB_CREATE | DB_INIT_LOG, 0666) == 0);
	assert(dbenv->get_lg_max(dbenv, &v) == 0);
	assert(v == 37 * 1024 * 1024);
	ENV
	assert(dbenv->set_lg_max(dbenv, 63 * 1024 * 1024) == 0);
	assert(dbenv->open(dbenv, "TESTDIR", DB_JOINENV, 0666) == 0);
	assert(dbenv->get_lg_max(dbenv, &v) == 0);
	assert(v == 63 * 1024 * 1024);

	/* lg_bsize: NOT reset at run-time. */
	system("rm -rf TESTDIR; mkdir TESTDIR");
	ENV
	assert(dbenv->set_lg_bsize(dbenv, 37 * 1024) == 0);
	assert(dbenv->open(dbenv,
	    "TESTDIR", DB_CREATE | DB_INIT_LOG, 0666) == 0);
	assert(dbenv->get_lg_bsize(dbenv, &v) == 0);
	assert(v == 37 * 1024);
	ENV
	assert(dbenv->set_lg_bsize(dbenv, 63 * 1024) == 0);
	assert(dbenv->open(dbenv, "TESTDIR", DB_JOINENV, 0666) == 0);
	assert(dbenv->get_lg_bsize(dbenv, &v) == 0);
	assert(v == 37 * 1024);

	/* lg_regionmax: NOT reset at run-time. */
	system("rm -rf TESTDIR; mkdir TESTDIR");
	ENV
	assert(dbenv->set_lg_regionmax(dbenv, 137 * 1024) == 0);
	assert(dbenv->open(dbenv,
	    "TESTDIR", DB_CREATE | DB_INIT_LOG, 0666) == 0);
	assert(dbenv->get_lg_regionmax(dbenv, &v) == 0);
	assert(v == 137 * 1024);
	ENV
	assert(dbenv->set_lg_regionmax(dbenv, 163 * 1024) == 0);
	assert(dbenv->open(dbenv, "TESTDIR", DB_JOINENV, 0666) == 0);
	assert(dbenv->get_lg_regionmax(dbenv, &v) == 0);
	assert(v == 137 * 1024);

	/* lk_get_lk_conflicts: NOT reset at run-time. */
	system("rm -rf TESTDIR; mkdir TESTDIR");
	ENV
	memset(conflicts, 'a', sizeof(conflicts));
	nmodes = 6;
	assert(dbenv->set_lk_conflicts(dbenv, conflicts, nmodes) == 0);
	assert(dbenv->open(dbenv,
	    "TESTDIR", DB_CREATE | DB_INIT_LOCK, 0666) == 0);
	assert(dbenv->get_lk_conflicts(dbenv, &lk_conflicts, &lk_modes) == 0);
	assert(lk_conflicts[0] == 'a');
	assert(lk_modes == 6);
	ENV
	memset(conflicts, 'b', sizeof(conflicts));
	nmodes = 8;
	assert(dbenv->set_lk_conflicts(dbenv, conflicts, nmodes) == 0);
	assert(dbenv->open(dbenv, "TESTDIR", DB_JOINENV, 0666) == 0);
	assert(dbenv->get_lk_conflicts(dbenv, &lk_conflicts, &lk_modes) == 0);
	assert(lk_conflicts[0] == 'a');
	assert(lk_modes == 6);

	/* lk_detect: NOT reset at run-time. */
	system("rm -rf TESTDIR; mkdir TESTDIR");
	ENV
	assert(dbenv->set_lk_detect(dbenv, DB_LOCK_MAXLOCKS) == 0);
	assert(dbenv->open(dbenv,
	    "TESTDIR", DB_CREATE | DB_INIT_LOCK, 0666) == 0);
	assert(dbenv->get_lk_detect(dbenv, &v) == 0);
	assert(v == DB_LOCK_MAXLOCKS);
	ENV
	assert(dbenv->set_lk_detect(dbenv, DB_LOCK_DEFAULT) == 0);
	assert(dbenv->open(dbenv, "TESTDIR", DB_JOINENV, 0666) == 0);
	assert(dbenv->get_lk_detect(dbenv, &v) == 0);
	assert(v == DB_LOCK_MAXLOCKS);

	/* lk_max_locks: NOT reset at run-time. */
	system("rm -rf TESTDIR; mkdir TESTDIR");
	ENV
	assert(dbenv->set_lk_max_locks(dbenv, 37) == 0);
	assert(dbenv->open(dbenv,
	    "TESTDIR", DB_CREATE | DB_INIT_LOCK, 0666) == 0);
	assert(dbenv->get_lk_max_locks(dbenv, &v) == 0);
	assert(v == 37);
	ENV
	assert(dbenv->set_lk_max_locks(dbenv, 63) == 0);
	assert(dbenv->open(dbenv, "TESTDIR", DB_JOINENV, 0666) == 0);
	assert(dbenv->get_lk_max_locks(dbenv, &v) == 0);
	assert(v == 37);

	/* lk_max_lockers: NOT reset at run-time. */
	system("rm -rf TESTDIR; mkdir TESTDIR");
	ENV
	assert(dbenv->set_lk_max_lockers(dbenv, 37) == 0);
	assert(dbenv->open(dbenv,
	    "TESTDIR", DB_CREATE | DB_INIT_LOCK, 0666) == 0);
	assert(dbenv->get_lk_max_lockers(dbenv, &v) == 0);
	assert(v == 37);
	ENV
	assert(dbenv->set_lk_max_lockers(dbenv, 63) == 0);
	assert(dbenv->open(dbenv, "TESTDIR", DB_JOINENV, 0666) == 0);
	assert(dbenv->get_lk_max_lockers(dbenv, &v) == 0);
	assert(v == 37);

	/* lk_max_objects: NOT reset at run-time. */
	system("rm -rf TESTDIR; mkdir TESTDIR");
	ENV
	assert(dbenv->set_lk_max_objects(dbenv, 37) == 0);
	assert(dbenv->open(dbenv,
	    "TESTDIR", DB_CREATE | DB_INIT_LOCK, 0666) == 0);
	assert(dbenv->get_lk_max_objects(dbenv, &v) == 0);
	assert(v == 37);
	ENV
	assert(dbenv->set_lk_max_objects(dbenv, 63) == 0);
	assert(dbenv->open(dbenv, "TESTDIR", DB_JOINENV, 0666) == 0);
	assert(dbenv->get_lk_max_objects(dbenv, &v) == 0);
	assert(v == 37);

	/* lock timeout: reset at run-time. */
	system("rm -rf TESTDIR; mkdir TESTDIR");
	ENV
	assert(dbenv->set_timeout(dbenv, 37, DB_SET_LOCK_TIMEOUT) == 0);
	assert(dbenv->open(dbenv,
	    "TESTDIR", DB_CREATE | DB_INIT_LOCK, 0666) == 0);
	assert(dbenv->get_timeout(dbenv, &timeout, DB_SET_LOCK_TIMEOUT) == 0);
	assert(timeout == 37);
	ENV
	assert(dbenv->set_timeout(dbenv, 63, DB_SET_LOCK_TIMEOUT) == 0);
	assert(dbenv->open(dbenv, "TESTDIR", DB_JOINENV, 0666) == 0);
	assert(dbenv->get_timeout(dbenv, &timeout, DB_SET_LOCK_TIMEOUT) == 0);
	assert(timeout == 63);

	/* txn timeout: reset at run-time. */
	system("rm -rf TESTDIR; mkdir TESTDIR");
	ENV
	assert(dbenv->set_timeout(dbenv, 37, DB_SET_TXN_TIMEOUT) == 0);
	assert(dbenv->open(dbenv,
	    "TESTDIR", DB_CREATE | DB_INIT_LOCK, 0666) == 0);
	assert(dbenv->get_timeout(dbenv, &timeout, DB_SET_TXN_TIMEOUT) == 0);
	assert(timeout == 37);
	ENV
	assert(dbenv->set_timeout(dbenv, 63, DB_SET_TXN_TIMEOUT) == 0);
	assert(dbenv->open(dbenv, "TESTDIR", DB_JOINENV, 0666) == 0);
	assert(dbenv->get_timeout(dbenv, &timeout, DB_SET_TXN_TIMEOUT) == 0);
	assert(timeout == 63);

	/* cache size: NOT reset at run-time. */
	system("rm -rf TESTDIR; mkdir TESTDIR");
	ENV
	assert(dbenv->set_cachesize(dbenv, 1, 37, 3) == 0);
	assert(dbenv->open(dbenv,
	    "TESTDIR", DB_CREATE | DB_INIT_MPOOL, 0666) == 0);
	assert(dbenv->get_cachesize(dbenv, &a, &b, &c) == 0);
	assert(a == 1 && b == 37 && c == 3);
	ENV
	assert(dbenv->set_cachesize(dbenv, 2, 63, 1) == 0);
	assert(dbenv->open(dbenv, "TESTDIR", DB_JOINENV, 0666) == 0);
	assert(dbenv->get_cachesize(dbenv, &a, &b, &c) == 0);
	assert(a == 1 && b == 37 && c == 3);

	return (0);
}