add cursor flag test, recno reverse insert test
[unix-history] / usr / src / lib / libc / db / test / run.test
CommitLineData
6bba19c8
KB
1#!/bin/sh -
2#
3# Copyright (c) 1992 The Regents of the University of California.
4# All rights reserved.
5#
6# %sccs.include.redist.sh%
7#
d3132760 8# @(#)run.test 5.11 (Berkeley) %G%
6bba19c8
KB
9#
10
11# db regression tests
12
13main()
14{
15 DICT=/usr/share/dict/words
66d7a193 16 PROG=obj/dbtest
6bba19c8
KB
17 TMP1=t1
18 TMP2=t2
19 TMP3=t3
20
21 test1
22 test2
23 test3
24 test4
00643224
KB
25 test5
26 test6
66d7a193 27 test7
2e789ad4 28 test8
f6552e4d 29 test10
d3132760
KB
30 test11
31 test20
6bba19c8 32 rm -f $TMP1 $TMP2 $TMP3
d3132760 33 exit 0
6bba19c8
KB
34}
35
36# Take the first hundred entries in the dictionary, and make them
37# be key/data pairs.
38test1()
39{
00643224 40 printf "Test 1: btree, hash: small key, small data pairs\n"
2e789ad4 41 sed 200q $DICT > $TMP1
6bba19c8
KB
42 for type in btree hash; do
43 rm -f $TMP2 $TMP3
44 for i in `sed 200q $DICT`; do
45 printf "p\nk%s\nd%s\ng\nk%s\n" $i $i $i
46 done > $TMP2
66d7a193 47 $PROG -o $TMP3 $type $TMP2
6bba19c8
KB
48 if (cmp -s $TMP1 $TMP3) ; then
49 else
50 printf "test1: type %s: failed\n" $type
51 exit 1
52 fi
53 done
00643224 54 printf "Test 1: recno: small key, small data pairs\n"
6bba19c8
KB
55 rm -f $TMP2 $TMP3
56 sed 200q $DICT |
66d7a193
KB
57 awk '{
58 ++i;
59 printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
60 }' > $TMP2
61 $PROG -o $TMP3 recno $TMP2
6bba19c8
KB
62 if (cmp -s $TMP1 $TMP3) ; then
63 else
64 printf "test1: type recno: failed\n"
65 exit 1
66 fi
67}
68
69# Take the first hundred entries in the dictionary, and give them
70# each a medium size data entry.
71test2()
72{
00643224 73 printf "Test 2: btree, hash: small key, medium data pairs\n"
6bba19c8
KB
74 mdata=abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz
75 echo $mdata |
66d7a193 76 awk '{ for (i = 1; i < 201; ++i) print $0 }' > $TMP1
6bba19c8
KB
77 for type in hash btree; do
78 rm -f $TMP2 $TMP3
79 for i in `sed 200q $DICT`; do
80 printf "p\nk%s\nd%s\ng\nk%s\n" $i $mdata $i
81 done > $TMP2
66d7a193 82 $PROG -o $TMP3 $type $TMP2
6bba19c8
KB
83 if (cmp -s $TMP1 $TMP3) ; then
84 else
85 printf "test2: type %s: failed\n" $type
86 exit 1
87 fi
88 done
00643224 89 printf "Test 2: recno: small key, medium data pairs\n"
6bba19c8
KB
90 rm -f $TMP2 $TMP3
91 echo $mdata |
66d7a193
KB
92 awk '{ for (i = 1; i < 201; ++i)
93 printf("p\nk%d\nd%s\ng\nk%d\n", i, $0, i);
94 }' > $TMP2
95 $PROG -o $TMP3 recno $TMP2
6bba19c8
KB
96 if (cmp -s $TMP1 $TMP3) ; then
97 else
98 printf "test2: type recno: failed\n"
99 exit 1
100 fi
101}
102
103# Insert the programs in /bin with their paths as their keys.
104test3()
105{
00643224 106 printf "Test 3: btree, hash: small key, big data pairs\n"
6bba19c8
KB
107 rm -f $TMP1
108 (find /bin -type f -print | xargs cat) > $TMP1
109 for type in hash btree; do
110 rm -f $TMP2 $TMP3
111 for i in `find /bin -type f -print`; do
112 printf "p\nk%s\nD%s\ng\nk%s\n" $i $i $i
113 done > $TMP2
66d7a193 114 $PROG -o $TMP3 $type $TMP2
6bba19c8
KB
115 if (cmp -s $TMP1 $TMP3) ; then
116 else
cd6864e9 117 printf "test3: type %s: failed\n" $type
6bba19c8
KB
118 exit 1
119 fi
120 done
00643224 121 printf "Test 3: recno: big data pairs\n"
6bba19c8
KB
122 rm -f $TMP2 $TMP3
123 find /bin -type f -print |
66d7a193
KB
124 awk '{
125 ++i;
126 printf("p\nk%d\nD%s\ng\nk%d\n", i, $0, i);
127 }' > $TMP2
128 $PROG -o $TMP3 recno $TMP2
6bba19c8
KB
129 if (cmp -s $TMP1 $TMP3) ; then
130 else
131 printf "test3: type recno: failed\n"
132 exit 1
133 fi
134}
135
136# Do random recno entries.
137test4()
138{
00643224
KB
139 printf "Test 4: recno: random entries\n"
140 echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
66d7a193
KB
141 awk '{
142 for (i = 37; i <= 37 + 88 * 17; i += 17)
143 printf("input key %d: %.*s\n", i, i % 41, $0);
144 for (i = 1; i <= 15; ++i)
145 printf("input key %d: %.*s\n", i, i % 41, $0);
146 for (i = 19234; i <= 19234 + 61 * 27; i += 27)
147 printf("input key %d: %.*s\n", i, i % 41, $0);
148 exit
149 }' > $TMP1
150 rm -f TMP2 $TMP3
151 cat $TMP1 |
152 awk 'BEGIN {
153 i = 37;
154 incr = 17;
155 }
156 {
157 printf("p\nk%d\nd%s\n", i, $0);
158 if (i == 19234 + 61 * 27)
159 exit;
160 if (i == 37 + 88 * 17) {
161 i = 1;
162 incr = 1;
163 } else if (i == 15) {
164 i = 19234;
165 incr = 27;
166 } else
167 i += incr;
168 }
169 END {
6bba19c8 170 for (i = 37; i <= 37 + 88 * 17; i += 17)
66d7a193 171 printf("g\nk%d\n", i);
6bba19c8 172 for (i = 1; i <= 15; ++i)
66d7a193 173 printf("g\nk%d\n", i);
6bba19c8 174 for (i = 19234; i <= 19234 + 61 * 27; i += 27)
66d7a193
KB
175 printf("g\nk%d\n", i);
176 }' > $TMP2
177 $PROG -o $TMP3 recno $TMP2
6bba19c8
KB
178 if (cmp -s $TMP1 $TMP3) ; then
179 else
180 printf "test4: type recno: failed\n"
181 exit 1
182 fi
183}
00643224
KB
184
185# Do reverse order recno entries.
186test5()
187{
188 printf "Test 5: recno: reverse order entries\n"
189 echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
66d7a193
KB
190 awk ' {
191 for (i = 1500; i; --i)
192 printf("input key %d: %.*s\n", i, i % 34, $0);
193 exit;
194 }' > $TMP1
00643224 195 rm -f TMP2 $TMP3
66d7a193
KB
196 cat $TMP1 |
197 awk 'BEGIN {
198 i = 1500;
199 }
200 {
201 printf("p\nk%d\nd%s\n", i, $0);
202 --i;
203 }
204 END {
205 for (i = 1500; i; --i)
206 printf("g\nk%d\n", i);
207 }' > $TMP2
208 $PROG -o $TMP3 recno $TMP2
00643224
KB
209 if (cmp -s $TMP1 $TMP3) ; then
210 else
211 printf "test5: type recno: failed\n"
212 exit 1
213 fi
214}
6bba19c8 215
00643224
KB
216# Do alternating order recno entries.
217test6()
218{
219 printf "Test 6: recno: alternating order entries\n"
220 echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
66d7a193
KB
221 awk ' {
222 for (i = 1; i < 1200; i += 2)
223 printf("input key %d: %.*s\n", i, i % 34, $0);
224 for (i = 2; i < 1200; i += 2)
225 printf("input key %d: %.*s\n", i, i % 34, $0);
226 exit;
227 }' > $TMP1
00643224 228 rm -f TMP2 $TMP3
66d7a193
KB
229 cat $TMP1 |
230 awk 'BEGIN {
231 i = 1;
232 even = 0;
233 }
234 {
235 printf("p\nk%d\nd%s\n", i, $0);
236 i += 2;
237 if (i >= 1200) {
238 if (even == 1)
239 exit;
240 even = 1;
241 i = 2;
00643224 242 }
66d7a193
KB
243 }
244 END {
245 for (i = 1; i < 1200; ++i)
246 printf("g\nk%d\n", i);
247 }' > $TMP2
248 $PROG -o $TMP3 recno $TMP2
00643224
KB
249 sort -o $TMP1 $TMP1
250 sort -o $TMP3 $TMP3
251 if (cmp -s $TMP1 $TMP3) ; then
252 else
253 printf "test6: type recno: failed\n"
254 exit 1
255 fi
256}
257
66d7a193
KB
258# Delete cursor record
259test7()
260{
261 printf "Test 7: btree, recno: delete cursor record\n"
262 echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
263 awk '{
264 for (i = 1; i <= 120; ++i)
265 printf("%05d: input key %d: %s\n", i, i, $0);
266 printf("%05d: input key %d: %s\n", 120, 120, $0);
267 printf("get failed, no such key\n");
268 printf("%05d: input key %d: %s\n", 1, 1, $0);
269 printf("%05d: input key %d: %s\n", 2, 2, $0);
270 exit;
271 }' > $TMP1
272 rm -f TMP2 $TMP3
8244ba92 273
66d7a193
KB
274 for type in btree recno; do
275 cat $TMP1 |
276 awk '{
277 if (i == 120)
278 exit;
279 printf("p\nk%d\nd%s\n", ++i, $0);
280 }
281 END {
282 printf("fR_NEXT\n");
283 for (i = 1; i <= 120; ++i)
284 printf("s\n");
285 printf("fR_CURSOR\ns\nk120\n");
286 printf("r\nk120\n");
287 printf("fR_NEXT\ns\n");
288 printf("fR_CURSOR\ns\nk1\n");
289 printf("r\nk1\n");
290 printf("fR_FIRST\ns\n");
291 }' > $TMP2
292 $PROG -o $TMP3 recno $TMP2
293 if (cmp -s $TMP1 $TMP3) ; then
294 else
295 printf "test7: type $type: failed\n"
296 exit 1
297 fi
298 done
299}
300
ea6b8ce7 301# Make sure that overflow pages are reused.
2e789ad4 302test8()
ea6b8ce7
KB
303{
304 printf "Test 8: btree, hash: repeated small key, big data pairs\n"
305 rm -f $TMP1
306 awk 'BEGIN {
c918295b 307 for (i = 1; i <= 10; ++i) {
ea6b8ce7
KB
308 printf("p\nkkey1\nD/bin/sh\n");
309 printf("p\nkkey2\nD/bin/csh\n");
5f9f1519
KB
310 if (i % 8 == 0) {
311 printf("c\nkkey2\nD/bin/csh\n");
312 printf("c\nkkey1\nD/bin/sh\n");
8244ba92 313 printf("e\t%d of 10 (comparison)\r\n", i);
5f9f1519 314 } else
8244ba92 315 printf("e\t%d of 10 \r\n", i);
ea6b8ce7
KB
316 printf("r\nkkey1\nr\nkkey2\n");
317 }
c918295b
KB
318 printf("e\n");
319 printf("eend of test8 run\n");
ea6b8ce7 320 }' > $TMP1
5f9f1519
KB
321 $PROG btree $TMP1
322 $PROG hash $TMP1
ea6b8ce7
KB
323 # No explicit test for success.
324}
325
d3132760
KB
326# Test use of cursor flags without initialization
327test10()
328{
329 printf "Test 10: btree, recno: test cursor flag use\n"
330 echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
331 awk '{
332 for (i = 1; i <= 20; ++i)
333 printf("%05d: input key %d: %s\n", i, i, $0);
334 exit;
335 }' > $TMP1
336 rm -f TMP2 $TMP3
337
338 # Test that R_CURSOR doesn't succeed before cursor initialized
339 for type in btree recno; do
340 cat $TMP1 |
341 awk '{
342 if (i == 10)
343 exit;
344 printf("p\nk%d\nd%s\n", ++i, $0);
345 }
346 END {
347 printf("fR_CURSOR\nr\nk1\n");
348 printf("eR_CURSOR SHOULD HAVE FAILED\n");
349 }' > $TMP2
350 $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1
351 if [ -s $TMP3 ] ; then
352 printf "Test 10: delete: R_CURSOR SHOULD HAVE FAILED\n"
353 exit 1
354 fi
355 done
356 for type in btree recno; do
357 cat $TMP1 |
358 awk '{
359 if (i == 10)
360 exit;
361 printf("p\nk%d\nd%s\n", ++i, $0);
362 }
363 END {
364 printf("fR_CURSOR\np\nk1\ndsome data\n");
365 printf("eR_CURSOR SHOULD HAVE FAILED\n");
366 }' > $TMP2
367 $PROG -o $TMP3 $type $TMP2 > /dev/null 2>&1
368 if [ -s $TMP3 ] ; then
369 printf "Test 10: put: R_CURSOR SHOULD HAVE FAILED\n"
370 exit 1
371 fi
372 done
373}
374
375# Test insert in reverse order.
376test11()
377{
378 printf "Test 11: recno: reverse order insert\n"
379 echo "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg" |
380 awk '{
381 for (i = 1; i <= 779; ++i)
382 printf("%05d: input key %d: %s\n", i, i, $0);
383 exit;
384 }' > $TMP1
385 rm -f TMP2 $TMP3
386
387 for type in recno; do
388 cat $TMP1 |
389 awk '{
390 if (i == 0) {
391 i = 1;
392 printf("p\nk1\nd%s\n", $0);
393 printf("%s\n", "fR_IBEFORE");
394 } else
395 printf("p\nk1\nd%s\n", $0);
396 }
397 END {
398 printf("or\n");
399 }' > $TMP2
400 $PROG -o $TMP3 $type $TMP2
401 if (cmp -s $TMP1 $TMP3) ; then
402 else
403 printf "test11: type $type: failed\n"
404 exit 1
405 fi
406 done
407}
408
ea6b8ce7 409# Try a variety of bucketsizes and fill factors for hashing
d3132760 410test20()
2e789ad4
KB
411{
412 printf\
d3132760 413 "Test 20: hash: bucketsize, fill factor; nelem 25000 cachesize 65536\n"
2e789ad4
KB
414 awk 'BEGIN {
415 for (i = 1; i <= 10000; ++i)
416 printf("%.*s\n", i % 34,
417 "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg");
418 }' > $TMP1
419 sed 10000q $DICT |
420 awk '{
421 ++i;
422 printf("p\nk%s\nd%.*s\n", $0, i % 34,
423 "abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg abcdefg");
424 }' > $TMP2
425 sed 10000q $DICT |
426 awk '{
427 ++i;
428 printf("g\nk%s\n", $0);
429 }' >> $TMP2
430 bsize=256
431 for ffactor in 11 14 21; do
432 printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
ea6b8ce7 433 $PROG -o$TMP3 \
2e789ad4
KB
434 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
435 hash $TMP2
436 if (cmp -s $TMP1 $TMP3) ; then
437 else
d3132760 438 printf "test20: type hash:\
2e789ad4
KB
439bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
440 exit 1
441 fi
442 done
443 bsize=512
444 for ffactor in 21 28 43; do
445 printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
ea6b8ce7 446 $PROG -o$TMP3 \
2e789ad4
KB
447 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
448 hash $TMP2
449 if (cmp -s $TMP1 $TMP3) ; then
450 else
d3132760 451 printf "test20: type hash:\
2e789ad4
KB
452bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
453 exit 1
454 fi
455 done
456 bsize=1024
457 for ffactor in 43 57 85; do
458 printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
ea6b8ce7 459 $PROG -o$TMP3 \
2e789ad4
KB
460 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
461 hash $TMP2
462 if (cmp -s $TMP1 $TMP3) ; then
463 else
d3132760 464 printf "test20: type hash:\
2e789ad4
KB
465bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
466 exit 1
467 fi
468 done
469 bsize=2048
470 for ffactor in 85 114 171; do
471 printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
ea6b8ce7 472 $PROG -o$TMP3 \
2e789ad4
KB
473 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
474 hash $TMP2
475 if (cmp -s $TMP1 $TMP3) ; then
476 else
d3132760 477 printf "test20: type hash:\
2e789ad4
KB
478bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
479 exit 1
480 fi
481 done
482 bsize=4096
483 for ffactor in 171 228 341; do
484 printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
ea6b8ce7 485 $PROG -o$TMP3 \
2e789ad4
KB
486 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
487 hash $TMP2
488 if (cmp -s $TMP1 $TMP3) ; then
489 else
d3132760 490 printf "test20: type hash:\
2e789ad4
KB
491bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
492 exit 1
493 fi
494 done
495 bsize=8192
496 for ffactor in 341 455 683; do
497 printf "\tbucketsize %d, fill factor %d\n" $bsize, $ffactor
ea6b8ce7 498 $PROG -o$TMP3 \
2e789ad4
KB
499 -ibsize=$bsize,ffactor=$ffactor,nelem=25000,cachesize=65536\
500 hash $TMP2
501 if (cmp -s $TMP1 $TMP3) ; then
502 else
d3132760 503 printf "test20: type hash:\
2e789ad4
KB
504bsize=$bsize ffactor=$ffactor nelem=25000 cachesize=65536 failed\n"
505 exit 1
506 fi
507 done
508}
509
6bba19c8 510main