1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2 * Copyright by The HDF Group. *
3 * Copyright by the Board of Trustees of the University of Illinois. *
4 * All rights reserved. *
5 * *
6 * This file is part of HDF5. The full HDF5 copyright notice, including *
7 * terms governing use, modification, and redistribution, is contained in *
8 * the COPYING file, which can be found at the root of the source code *
9 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
10 * If you do not have access to either file, you may request a copy from *
11 * help@hdfgroup.org. *
12 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13
14 /* Programmer: Quincey Koziol <koziol@ncsa.uiuc.edu>
15 * Tuesday, February 1, 2005
16 */
17 #include "h5test.h"
18
19 /*
20 * This file needs to access private datatypes from the H5B2 package.
21 * This file also needs to access the v2 B-tree testing code.
22 */
23 #define H5B2_PACKAGE
24 #define H5B2_TESTING
25 #include "H5B2pkg.h"
26
27 /* Other private headers that this test requires */
28 #include "H5Iprivate.h"
29
30 const char *FILENAME[] = {
31 "btree2",
32 NULL
33 };
34
35 #define INSERT_SPLIT_ROOT_NREC 63
36 #define INSERT_MANY (1000*1000)
37 #define FIND_MANY (INSERT_MANY/100)
38 #define FIND_NEIGHBOR 2000
39 #define DELETE_SMALL 20
40 #define DELETE_MEDIUM 200
41 #define DELETE_LARGE 2000
42
43 /* Testing parameters */
44 typedef struct bt2_test_param_t {
45 hbool_t reopen_btree; /* Whether to re-open the B-tree during the test */
46 } bt2_test_param_t;
47
48
49 /*-------------------------------------------------------------------------
50 * Function: init_cparam
51 *
52 * Purpose: Initialize v2 B-tree creation parameter structure
53 *
54 * Return: Success: 0
55 * Failure: -1
56 *
57 * Programmer: Quincey Koziol
58 * Thursday, October 29, 2009
59 *
60 *-------------------------------------------------------------------------
61 */
62 static int
init_cparam(H5B2_create_t * cparam)63 init_cparam(H5B2_create_t *cparam)
64 {
65 /* Wipe out background */
66 HDmemset(cparam, 0, sizeof(*cparam));
67
68 /* General parameters */
69 cparam->cls = H5B2_TEST;
70 cparam->node_size = (size_t)512;
71 cparam->rrec_size = (size_t)8;
72 cparam->split_percent = 100;
73 cparam->merge_percent = 40;
74
75 return(0);
76 } /* init_cparam() */
77
78
79 /*-------------------------------------------------------------------------
80 * Function: create_file
81 *
82 * Purpose: Perform common "creation" operations on file
83 *
84 * Return: Success: 0
85 * Failure: 1
86 *
87 * Programmer: Quincey Koziol
88 * Thursday, November 5, 2009
89 *
90 *-------------------------------------------------------------------------
91 */
92 static int
create_file(hid_t * file,H5F_t ** f,hid_t fapl)93 create_file(hid_t *file, H5F_t **f, hid_t fapl)
94 {
95 char filename[1024]; /* Filename to use */
96
97 /* Set the filename to use for this test (dependent on fapl) */
98 h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));
99
100 /* Create the file to work on */
101 if((*file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
102 TEST_ERROR
103
104 /* Get a pointer to the internal file object */
105 if(NULL == (*f = (H5F_t *)H5I_object(*file)))
106 STACK_ERROR
107
108 /* Success */
109 return(0);
110
111 error:
112 return(-1);
113 } /* end create_file() */
114
115
116 /*-------------------------------------------------------------------------
117 * Function: create_btree
118 *
119 * Purpose: Perform common "create" operations on B-tree for testing
120 *
121 * Return: Success: 0
122 * Failure: 1
123 *
124 * Programmer: Quincey Koziol
125 * Thursday, November 5, 2009
126 *
127 *-------------------------------------------------------------------------
128 */
129 static int
create_btree(H5F_t * f,hid_t dxpl,const H5B2_create_t * cparam,H5B2_t ** bt2,haddr_t * bt2_addr)130 create_btree(H5F_t *f, hid_t dxpl, const H5B2_create_t *cparam,
131 H5B2_t **bt2, haddr_t *bt2_addr)
132 {
133 /* Create the v2 B-tree & get its address */
134 if(NULL == (*bt2 = H5B2_create(f, dxpl, cparam, f)))
135 FAIL_STACK_ERROR
136 if(H5B2_get_addr(*bt2, bt2_addr/*out*/) < 0)
137 FAIL_STACK_ERROR
138 if(!H5F_addr_defined(*bt2_addr))
139 FAIL_STACK_ERROR
140
141 /* Success */
142 return(0);
143
144 error:
145 return(-1);
146 } /* end create_btree() */
147
148
149 /*-------------------------------------------------------------------------
150 * Function: reopen_btree
151 *
152 * Purpose: Perform common "re-open" operations on B-tree for testing
153 *
154 * Return: Success: 0
155 * Failure: 1
156 *
157 * Programmer: Quincey Koziol
158 * Thursday, November 5, 2009
159 *
160 *-------------------------------------------------------------------------
161 */
162 static int
reopen_btree(H5F_t * f,hid_t dxpl,H5B2_t ** bt2,haddr_t bt2_addr,const bt2_test_param_t * tparam)163 reopen_btree(H5F_t *f, hid_t dxpl, H5B2_t **bt2, haddr_t bt2_addr,
164 const bt2_test_param_t *tparam)
165 {
166 /* Check for closing & re-opening the B-tree */
167 if(tparam->reopen_btree) {
168 /* Close (empty) v2 B-tree */
169 if(H5B2_close(*bt2, dxpl) < 0)
170 FAIL_STACK_ERROR
171
172 /* Re-open v2 B-tree */
173 if(NULL == (*bt2 = H5B2_open(f, dxpl, bt2_addr, f)))
174 FAIL_STACK_ERROR
175 } /* end if */
176
177 /* Success */
178 return(0);
179
180 error:
181 return(-1);
182 } /* end reopen_btree() */
183
184
185 /*-------------------------------------------------------------------------
186 * Function: check_stats
187 *
188 * Purpose: Check statistics about v1 B-tree
189 *
190 * Return: Success: 0
191 * Failure: -1
192 *
193 * Programmer: Quincey Koziol
194 * Thursday, November 5, 2009
195 *
196 *-------------------------------------------------------------------------
197 */
198 static int
check_stats(H5B2_t * bt2,const H5B2_stat_t * expected)199 check_stats(H5B2_t *bt2, const H5B2_stat_t *expected)
200 {
201 H5B2_stat_t actual; /* Actual stats retrieved about v2 B-tree */
202
203 /* Get current stats */
204 if(H5B2_stat_info(bt2, &actual) < 0)
205 FAIL_STACK_ERROR
206 if(actual.depth != expected->depth)
207 TEST_ERROR
208 if(actual.nrecords != expected->nrecords)
209 TEST_ERROR
210
211 /* Success */
212 return(0);
213
214 error:
215 return(-1);
216 } /* end check_stats() */
217
218
219 /*-------------------------------------------------------------------------
220 * Function: check_node_depth
221 *
222 * Purpose: Check the depth of the node containing a record
223 *
224 * Return: Success: 0
225 * Failure: -1
226 *
227 * Programmer: Quincey Koziol
228 * Thursday, November 5, 2009
229 *
230 *-------------------------------------------------------------------------
231 */
232 static int
check_node_depth(H5B2_t * bt2,hid_t dxpl,hsize_t record,unsigned depth)233 check_node_depth(H5B2_t *bt2, hid_t dxpl, hsize_t record, unsigned depth)
234 {
235 int rec_depth; /* Depth of record in B-tree */
236
237 if((rec_depth = H5B2_get_node_depth_test(bt2, dxpl, &record)) < 0)
238 FAIL_STACK_ERROR
239 if((unsigned)rec_depth != depth)
240 TEST_ERROR
241
242 /* Success */
243 return(0);
244
245 error:
246 return(-1);
247 } /* end check_node_depth() */
248
249
250 /*-------------------------------------------------------------------------
251 * Function: check_node_info
252 *
253 * Purpose: Check the info of the node containing a record
254 *
255 * Return: Success: 0
256 * Failure: -1
257 *
258 * Programmer: Quincey Koziol
259 * Friday, November 6, 2009
260 *
261 *-------------------------------------------------------------------------
262 */
263 static int
check_node_info(H5B2_t * bt2,hid_t dxpl,hsize_t record,H5B2_node_info_test_t * ninfo)264 check_node_info(H5B2_t *bt2, hid_t dxpl, hsize_t record,
265 H5B2_node_info_test_t *ninfo)
266 {
267 H5B2_node_info_test_t rec_ninfo; /* Node info for record in B-tree */
268
269 if(H5B2_get_node_info_test(bt2, dxpl, &record, &rec_ninfo) < 0)
270 FAIL_STACK_ERROR
271 if(rec_ninfo.depth != ninfo->depth)
272 TEST_ERROR
273 if(rec_ninfo.nrec != ninfo->nrec)
274 TEST_ERROR
275
276 /* Success */
277 return(0);
278
279 error:
280 return(-1);
281 } /* end check_node_depth() */
282
283
284 /*-------------------------------------------------------------------------
285 * Function: iter_cb
286 *
287 * Purpose: v2 B-tree iterator callback
288 *
289 * Return: Success: 0
290 *
291 * Failure: 1
292 *
293 * Programmer: Quincey Koziol
294 * Wednesday, February 16, 2005
295 *
296 *-------------------------------------------------------------------------
297 */
298 static int
iter_cb(const void * _record,void * _op_data)299 iter_cb(const void *_record, void *_op_data)
300 {
301 const hsize_t *record = (const hsize_t *)_record;
302 hsize_t *idx = (hsize_t *)_op_data;
303
304 if(*record != *idx)
305 return(H5_ITER_ERROR);
306
307 (*idx)++;
308 return(H5_ITER_CONT);
309 } /* end iter_cb() */
310
311
312 /*-------------------------------------------------------------------------
313 * Function: find_cb
314 *
315 * Purpose: v2 B-tree find callback
316 *
317 * Return: Success: TRUE/FALSE
318 *
319 * Failure: FAIL
320 *
321 * Programmer: Quincey Koziol
322 * Thursday, February 24, 2005
323 *
324 *-------------------------------------------------------------------------
325 */
326 static int
find_cb(const void * _record,void * _op_data)327 find_cb(const void *_record, void *_op_data)
328 {
329 const hsize_t *record = (const hsize_t *)_record;
330 hsize_t *search = (hsize_t *)_op_data;
331
332 if(*record != *search)
333 return(FALSE);
334
335 return(TRUE);
336 } /* end find_cb() */
337
338
339 /*-------------------------------------------------------------------------
340 * Function: find_dec_cb
341 *
342 * Purpose: v2 B-tree find callback for indexing in decreasing order
343 *
344 * Note: Currently hard-wired to "insert_lots" test
345 *
346 * Return: Success: 0
347 * Failure: 1
348 *
349 * Programmer: Quincey Koziol
350 * Tuesday, November 7, 2006
351 *
352 *-------------------------------------------------------------------------
353 */
354 static int
find_dec_cb(const void * _record,void * _op_data)355 find_dec_cb(const void *_record, void *_op_data)
356 {
357 const hsize_t *record = (const hsize_t *)_record;
358 hsize_t *search = (hsize_t *)_op_data;
359
360 if(*record != (INSERT_MANY - (*search + 1)))
361 return(-1);
362
363 return(0);
364 } /* end find_dec_cb() */
365
366
367 /*-------------------------------------------------------------------------
368 * Function: neighbor_cb
369 *
370 * Purpose: v2 B-tree neighbor callback
371 *
372 * Return: Success: 0
373 *
374 * Failure: 1
375 *
376 * Programmer: Quincey Koziol
377 * Tuesday, March 8, 2005
378 *
379 *-------------------------------------------------------------------------
380 */
381 static int
neighbor_cb(const void * _record,void * _op_data)382 neighbor_cb(const void *_record, void *_op_data)
383 {
384 const hsize_t *record = (const hsize_t *)_record;
385 hsize_t *search = (hsize_t *)_op_data;
386
387 *search = *record;
388
389 return(0);
390 } /* end neighbor_cb() */
391
392
393 /*-------------------------------------------------------------------------
394 * Function: modify_cb
395 *
396 * Purpose: v2 B-tree modify callback
397 *
398 * Return: Success: 0
399 *
400 * Failure: 1
401 *
402 * Programmer: Quincey Koziol
403 * Friday, March 10, 2005
404 *
405 *-------------------------------------------------------------------------
406 */
407 static int
modify_cb(void * _record,void * _op_data,hbool_t * changed)408 modify_cb(void *_record, void *_op_data, hbool_t *changed)
409 {
410 hsize_t *record = (hsize_t *)_record;
411 hsize_t *modify = (hsize_t *)_op_data;
412
413 *record = *modify;
414 *changed = TRUE;
415
416 return(0);
417 } /* end modify_cb() */
418
419
420 /*-------------------------------------------------------------------------
421 * Function: remove_cb
422 *
423 * Purpose: v2 B-tree remove callback
424 *
425 * Return: Success: 0
426 *
427 * Failure: 1
428 *
429 * Programmer: Quincey Koziol
430 * Tuesday, August 8, 2006
431 *
432 *-------------------------------------------------------------------------
433 */
434 static int
remove_cb(const void * _record,void * _op_data)435 remove_cb(const void *_record, void *_op_data)
436 {
437 const hsize_t *record = (const hsize_t *)_record;
438 hsize_t *rrecord = (hsize_t *)_op_data;
439
440 *rrecord = *record;
441
442 return(0);
443 } /* end remove_cb() */
444
445
446 /*-------------------------------------------------------------------------
447 * Function: test_insert_basic
448 *
449 * Purpose: Basic tests for the B-tree v2 code
450 *
451 * Return: Success: 0
452 * Failure: 1
453 *
454 * Programmer: Quincey Koziol
455 * Thursday, February 3, 2005
456 *
457 *-------------------------------------------------------------------------
458 */
459 static unsigned
test_insert_basic(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)460 test_insert_basic(hid_t fapl, const H5B2_create_t *cparam,
461 const bt2_test_param_t *tparam)
462 {
463 hid_t file = -1; /* File ID */
464 H5F_t *f = NULL; /* Internal file object pointer */
465 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
466 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
467 haddr_t bt2_addr; /* Address of B-tree created */
468 hsize_t record; /* Record to insert into tree */
469 hsize_t idx; /* Index within B-tree, for iterator */
470 herr_t ret; /* Generic error return value */
471
472 /*
473 * Test v2 B-tree creation
474 */
475 TESTING("B-tree creation");
476
477 /* Create the file for the test */
478 if(create_file(&file, &f, fapl) < 0)
479 TEST_ERROR
480
481 /* Create the v2 B-tree & get its address */
482 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
483 TEST_ERROR
484
485 PASSED();
486
487 /*
488 * Test queries/iterations on empty v2 B-tree
489 */
490 TESTING("B-tree iteration: empty B-tree");
491
492 /* Check for closing & re-opening the B-tree */
493 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
494 TEST_ERROR
495
496 /* Attempt to iterate over a B-tree with no records */
497 idx = 0;
498 if(H5B2_iterate(bt2, dxpl, iter_cb, &idx) < 0)
499 FAIL_STACK_ERROR
500 /* Make certain that the index hasn't changed */
501 if(idx != 0)
502 TEST_ERROR
503
504 /* Attempt to find record in B-tree with no records */
505 idx = 0;
506 if(H5B2_find(bt2, dxpl, &idx, find_cb, NULL) != FALSE)
507 TEST_ERROR
508
509 /* Attempt to index record in B-tree with no records */
510 idx = 0;
511 H5E_BEGIN_TRY {
512 ret = H5B2_index(bt2, dxpl, H5_ITER_INC, (hsize_t)0, find_cb, NULL);
513 } H5E_END_TRY;
514 /* Should fail */
515 if(ret != FAIL)
516 TEST_ERROR
517
518 PASSED();
519
520 /*
521 * Test inserting first record into v2 B-tree
522 */
523 TESTING("B-tree insert: first record");
524
525 /* Check for closing & re-opening the B-tree */
526 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
527 TEST_ERROR
528
529 record = 42;
530 if(H5B2_insert(bt2, dxpl, &record) < 0)
531 FAIL_STACK_ERROR
532
533 /* Attempt to find non-existant record in B-tree with 1 record */
534 /* (Should not be found, but not fail) */
535 idx = 41;
536 if(H5B2_find(bt2, dxpl, &idx, find_cb, &idx) != FALSE)
537 TEST_ERROR
538
539 /* Try again with NULL 'op' */
540 /* (Should not be found, but not fail) */
541 if(H5B2_find(bt2, dxpl, &idx, NULL, NULL) != FALSE)
542 TEST_ERROR
543
544 /* Attempt to find existant record in B-tree with 1 record */
545 idx = 42;
546 if(H5B2_find(bt2, dxpl, &idx, find_cb, &idx) != TRUE)
547 TEST_ERROR
548
549 /* Try again with NULL 'op' */
550 if(H5B2_find(bt2, dxpl, &idx, NULL, NULL) != TRUE)
551 TEST_ERROR
552
553 /* Attempt to index non-existant record in B-tree with 1 record */
554 idx = 0;
555 H5E_BEGIN_TRY {
556 ret = H5B2_index(bt2, dxpl, H5_ITER_INC, (hsize_t)1, find_cb, NULL);
557 } H5E_END_TRY;
558 /* Should fail */
559 if(ret != FAIL)
560 TEST_ERROR
561
562 /* Attempt to index existing record in B-tree with 1 record */
563 idx = 42;
564 if(H5B2_index(bt2, dxpl, H5_ITER_INC, (hsize_t)0, find_cb, &idx) < 0)
565 TEST_ERROR
566
567 PASSED();
568
569 /*
570 * Test inserting more records into v2 B-tree
571 */
572 TESTING("B-tree insert: several records");
573
574 /* Check for closing & re-opening the B-tree */
575 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
576 TEST_ERROR
577
578 /*
579 * Test inserting second record into v2 B-tree, before all other records
580 */
581 record = 34;
582 if(H5B2_insert(bt2, dxpl, &record) < 0)
583 FAIL_STACK_ERROR
584
585 /*
586 * Test inserting third record into v2 B-tree, after all other records
587 */
588 record = 56;
589 if(H5B2_insert(bt2, dxpl, &record) < 0)
590 FAIL_STACK_ERROR
591
592 /*
593 * Test inserting fourth record into v2 B-tree, in the middle of other records
594 */
595 record = 38;
596 if(H5B2_insert(bt2, dxpl, &record) < 0)
597 FAIL_STACK_ERROR
598
599 /* Attempt to find non-existant record in level-0 B-tree with several records */
600 /* (Should not be found, but not fail) */
601 idx = 41;
602 if(H5B2_find(bt2, dxpl, &idx, find_cb, &idx) != FALSE)
603 TEST_ERROR
604
605 /* Attempt to find existant record in level-0 B-tree with several record */
606 idx = 56;
607 if(H5B2_find(bt2, dxpl, &idx, find_cb, &idx) != TRUE)
608 TEST_ERROR
609
610 /* Attempt to index non-existant record in B-tree with several records */
611 idx = 0;
612 H5E_BEGIN_TRY {
613 ret = H5B2_index(bt2, dxpl, H5_ITER_INC, (hsize_t)4, find_cb, NULL);
614 } H5E_END_TRY;
615 /* Should fail */
616 if(ret != FAIL)
617 TEST_ERROR
618
619 /* Attempt to index existing record in B-tree with several records */
620 idx = 34;
621 if(H5B2_index(bt2, dxpl, H5_ITER_INC, (hsize_t)0, find_cb, &idx) < 0)
622 TEST_ERROR
623 idx = 38;
624 if(H5B2_index(bt2, dxpl, H5_ITER_INC, (hsize_t)1, find_cb, &idx) < 0)
625 TEST_ERROR
626 idx = 42;
627 if(H5B2_index(bt2, dxpl, H5_ITER_INC, (hsize_t)2, find_cb, &idx) < 0)
628 TEST_ERROR
629 idx = 56;
630 if(H5B2_index(bt2, dxpl, H5_ITER_INC, (hsize_t)3, find_cb, &idx) < 0)
631 TEST_ERROR
632
633 /* Close the v2 B-tree */
634 if(H5B2_close(bt2, dxpl) < 0)
635 FAIL_STACK_ERROR
636 bt2 = NULL;
637
638 /* Close the file */
639 if(H5Fclose(file) < 0)
640 TEST_ERROR
641
642 PASSED();
643
644 /* All tests passed */
645 return(0);
646
647 error:
648 H5E_BEGIN_TRY {
649 if(bt2)
650 H5B2_close(bt2, dxpl);
651 H5Fclose(file);
652 } H5E_END_TRY;
653 return(1);
654 } /* test_insert_basic() */
655
656
657 /*-------------------------------------------------------------------------
658 * Function: test_insert_split_root
659 *
660 * Purpose: Basic tests for the B-tree v2 code. This test inserts enough
661 * records to split the root node and force the tree to depth 1.
662 * It also continues to add a few more records to each of the
663 * left and right leaf nodes after the split
664 *
665 * Return: Success: 0
666 * Failure: 1
667 *
668 * Programmer: Quincey Koziol
669 * Thursday, February 3, 2005
670 *
671 *-------------------------------------------------------------------------
672 */
673 static unsigned
test_insert_split_root(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)674 test_insert_split_root(hid_t fapl, const H5B2_create_t *cparam,
675 const bt2_test_param_t *tparam)
676 {
677 hid_t file = -1; /* File ID */
678 H5F_t *f = NULL; /* Internal file object pointer */
679 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
680 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
681 haddr_t bt2_addr; /* Address of B-tree created */
682 hsize_t record; /* Record to insert into tree */
683 hsize_t idx; /* Index within B-tree, for iterator */
684 H5B2_stat_t bt2_stat; /* Statistics about B-tree created */
685 unsigned u; /* Local index variable */
686 herr_t ret; /* Generic error return value */
687
688 /*
689 * Test inserting enough records into v2 B-tree to split the root node
690 */
691 TESTING("B-tree insert: split root");
692
693 /* Create the file for the test */
694 if(create_file(&file, &f, fapl) < 0)
695 TEST_ERROR
696
697 /* Create the v2 B-tree & get its address */
698 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
699 TEST_ERROR
700
701 /* Insert records to fill root leaf node */
702 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC - 1); u++) {
703 record = u + 2;
704 if(H5B2_insert(bt2, dxpl, &record) < 0)
705 FAIL_STACK_ERROR
706 } /* end for */
707
708 /* Check up on B-tree */
709 bt2_stat.depth = 0;
710 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC - 1);
711 if(check_stats(bt2, &bt2_stat) < 0)
712 TEST_ERROR
713 if(check_node_depth(bt2, dxpl, (hsize_t)33, (unsigned)0) < 0)
714 TEST_ERROR
715
716 /* Check for closing & re-opening the B-tree */
717 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
718 TEST_ERROR
719
720 /* Insert record to split root leaf node */
721 record = INSERT_SPLIT_ROOT_NREC + 1;
722 if(H5B2_insert(bt2, dxpl, &record) < 0)
723 FAIL_STACK_ERROR
724
725 /* Check up on B-tree */
726 bt2_stat.depth = 1;
727 bt2_stat.nrecords = INSERT_SPLIT_ROOT_NREC;
728 if(check_stats(bt2, &bt2_stat) < 0)
729 TEST_ERROR
730 if(check_node_depth(bt2, dxpl, (hsize_t)33, (unsigned)1) < 0)
731 TEST_ERROR
732
733 /* Check for closing & re-opening the B-tree */
734 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
735 TEST_ERROR
736
737
738 /* Insert a couple more records, on the left side of the B-tree */
739 record = 0;
740 if(H5B2_insert(bt2, dxpl, &record) < 0)
741 FAIL_STACK_ERROR
742 record = 1;
743 if(H5B2_insert(bt2, dxpl, &record) < 0)
744 FAIL_STACK_ERROR
745
746 /* Check up on B-tree */
747 bt2_stat.depth = 1;
748 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC + 2);
749 if(check_stats(bt2, &bt2_stat) < 0)
750 TEST_ERROR
751 if(check_node_depth(bt2, dxpl, (hsize_t)33, (unsigned)1) < 0)
752 TEST_ERROR
753
754 /* Check for closing & re-opening the B-tree */
755 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
756 TEST_ERROR
757
758
759 /* Iterate over B-tree to check records have been inserted correctly */
760 idx = 0;
761 if(H5B2_iterate(bt2, dxpl, iter_cb, &idx) < 0)
762 FAIL_STACK_ERROR
763
764 /* Make certain that the index is correct */
765 if(idx != (INSERT_SPLIT_ROOT_NREC + 2))
766 TEST_ERROR
767
768 /* Attempt to find non-existant record in level-1 B-tree */
769 /* (Should not be found, but not fail) */
770 idx = INSERT_SPLIT_ROOT_NREC + 10;
771 if(H5B2_find(bt2, dxpl, &idx, find_cb, &idx) != FALSE)
772 TEST_ERROR
773
774 /* Attempt to find existant record in root of level-1 B-tree */
775 idx = 33;
776 if(H5B2_find(bt2, dxpl, &idx, find_cb, &idx) != TRUE)
777 FAIL_STACK_ERROR
778
779 /* Attempt to find existant record in leaf of level-1 B-tree */
780 idx = 56;
781 if(H5B2_find(bt2, dxpl, &idx, find_cb, &idx) != TRUE)
782 FAIL_STACK_ERROR
783
784 /* Attempt to index non-existant record in level-1 B-tree */
785 idx = 0;
786 H5E_BEGIN_TRY {
787 ret = H5B2_index(bt2, dxpl, H5_ITER_INC, (hsize_t)(INSERT_SPLIT_ROOT_NREC+2), find_cb, NULL);
788 } H5E_END_TRY;
789 /* Should fail */
790 if(ret != FAIL)
791 TEST_ERROR
792
793 /* Attempt to index existing record in root of level-1 B-tree */
794 idx = 33;
795 if(H5B2_index(bt2, dxpl, H5_ITER_INC, (hsize_t)33, find_cb, &idx) < 0)
796 FAIL_STACK_ERROR
797
798 /* Attempt to index existing record in left leaf of level-1 B-tree */
799 idx = 0;
800 if(H5B2_index(bt2, dxpl, H5_ITER_INC, (hsize_t)0, find_cb, &idx) < 0)
801 FAIL_STACK_ERROR
802
803 /* Attempt to index existing record in right leaf of level-1 B-tree */
804 idx = 50;
805 if(H5B2_index(bt2, dxpl, H5_ITER_INC, (hsize_t)50, find_cb, &idx) < 0)
806 FAIL_STACK_ERROR
807
808 /* Close the v2 B-tree */
809 if(H5B2_close(bt2, dxpl) < 0)
810 FAIL_STACK_ERROR
811 bt2 = NULL;
812
813 if(H5Fclose(file) < 0)
814 TEST_ERROR
815
816 PASSED();
817
818 return 0;
819
820 error:
821 H5E_BEGIN_TRY {
822 if(bt2)
823 H5B2_close(bt2, dxpl);
824 H5Fclose(file);
825 } H5E_END_TRY;
826 return 1;
827 } /* test_insert_split_root() */
828
829
830 /*-------------------------------------------------------------------------
831 * Function: test_insert_level1_2leaf_redistrib
832 *
833 * Purpose: Basic tests for the B-tree v2 code. This test inserts enough
834 * records to split the root node and force the tree to depth 1.
835 * It continues to add a more records to the each of the
836 * left and right leaf nodes after the split to force a 2 node
837 * redistribution
838 *
839 * Return: Success: 0
840 * Failure: 1
841 *
842 * Programmer: Quincey Koziol
843 * Tuesday, February 8, 2005
844 *
845 *-------------------------------------------------------------------------
846 */
847 static unsigned
test_insert_level1_2leaf_redistrib(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)848 test_insert_level1_2leaf_redistrib(hid_t fapl, const H5B2_create_t *cparam,
849 const bt2_test_param_t *tparam)
850 {
851 hid_t file = -1; /* File ID */
852 H5F_t *f = NULL; /* Internal file object pointer */
853 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
854 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
855 haddr_t bt2_addr; /* Address of B-tree created */
856 hsize_t record; /* Record to insert into tree */
857 H5B2_stat_t bt2_stat; /* Statistics about B-tree created */
858 unsigned u; /* Local index variable */
859
860 /*
861 * Test inserting many records into v2 B-tree
862 */
863 TESTING("B-tree insert: redistribute 2 leaves in level 1 B-tree (l->r)");
864
865 /* Create the file for the test */
866 if(create_file(&file, &f, fapl) < 0)
867 TEST_ERROR
868
869 /* Create the v2 B-tree & get its address */
870 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
871 TEST_ERROR
872
873 /* Insert enough records to force root to split into 2 leaves */
874 for(u = 0; u < INSERT_SPLIT_ROOT_NREC; u++) {
875 record = u + (INSERT_SPLIT_ROOT_NREC/2) + 1;
876 if(H5B2_insert(bt2, dxpl, &record) < 0)
877 FAIL_STACK_ERROR
878 } /* end for */
879
880 /* Check up on B-tree */
881 bt2_stat.depth = 1;
882 bt2_stat.nrecords = INSERT_SPLIT_ROOT_NREC;
883 if(check_stats(bt2, &bt2_stat) < 0)
884 TEST_ERROR
885 if(check_node_depth(bt2, dxpl, (hsize_t)INSERT_SPLIT_ROOT_NREC, (unsigned)1) < 0)
886 TEST_ERROR
887
888 /* Check for closing & re-opening the B-tree */
889 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
890 TEST_ERROR
891
892
893 /* Force redistribution from left node into right node */
894 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC / 2) + 1; u++) {
895 record = u;
896 if(H5B2_insert(bt2, dxpl, &record) < 0)
897 FAIL_STACK_ERROR
898 } /* end for */
899
900 /* Check up on B-tree */
901 bt2_stat.depth = 1;
902 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC + (INSERT_SPLIT_ROOT_NREC / 2) + 1);
903 if(check_stats(bt2, &bt2_stat) < 0)
904 TEST_ERROR
905 if(check_node_depth(bt2, dxpl, (hsize_t)((INSERT_SPLIT_ROOT_NREC / 2) + (INSERT_SPLIT_ROOT_NREC / 4) + 1), (unsigned)1) < 0)
906 TEST_ERROR
907
908 /* Close the v2 B-tree */
909 if(H5B2_close(bt2, dxpl) < 0)
910 FAIL_STACK_ERROR
911 bt2 = NULL;
912
913 PASSED();
914
915 /*
916 * Test inserting many records into v2 B-tree
917 */
918 TESTING("B-tree insert: redistribute 2 leaves in level 1 B-tree (r->l)");
919
920 /* Create the v2 B-tree & get its address */
921 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
922 TEST_ERROR
923
924 /* Insert enough records to force root to split into 2 leaves */
925 for(u = 0; u < INSERT_SPLIT_ROOT_NREC; u++) {
926 record = u;
927 if(H5B2_insert(bt2, dxpl, &record) < 0)
928 FAIL_STACK_ERROR
929 } /* end for */
930
931 /* Check up on B-tree */
932 bt2_stat.depth = 1;
933 bt2_stat.nrecords = INSERT_SPLIT_ROOT_NREC;
934 if(check_stats(bt2, &bt2_stat) < 0)
935 TEST_ERROR
936 if(check_node_depth(bt2, dxpl, (hsize_t)(INSERT_SPLIT_ROOT_NREC / 2), (unsigned)1) < 0)
937 TEST_ERROR
938
939 /* Check for closing & re-opening the B-tree */
940 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
941 TEST_ERROR
942
943 /* Force redistribution from left node into right node */
944 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC / 2) + 1; u++) {
945 record = u + INSERT_SPLIT_ROOT_NREC;
946 if(H5B2_insert(bt2, dxpl, &record) < 0)
947 FAIL_STACK_ERROR
948 } /* end for */
949
950 /* Check up on B-tree */
951 bt2_stat.depth = 1;
952 bt2_stat.nrecords = INSERT_SPLIT_ROOT_NREC + (INSERT_SPLIT_ROOT_NREC / 2) + 1;
953 if(check_stats(bt2, &bt2_stat) < 0)
954 TEST_ERROR
955 if(check_node_depth(bt2, dxpl, (hsize_t)((INSERT_SPLIT_ROOT_NREC / 2) + (INSERT_SPLIT_ROOT_NREC / 4) + 1), (unsigned)1) < 0)
956 TEST_ERROR
957
958 /* Close the v2 B-tree */
959 if(H5B2_close(bt2, dxpl) < 0)
960 FAIL_STACK_ERROR
961 bt2 = NULL;
962
963 /* Close file */
964 if(H5Fclose(file) < 0)
965 FAIL_STACK_ERROR
966
967 PASSED();
968
969 return 0;
970
971 error:
972 H5E_BEGIN_TRY {
973 if(bt2)
974 H5B2_close(bt2, dxpl);
975 H5Fclose(file);
976 } H5E_END_TRY;
977 return 1;
978 } /* test_insert_level1_2leaf_redistrib() */
979
980
981 /*-------------------------------------------------------------------------
982 * Function: test_insert_level1_side_split
983 *
984 * Purpose: Basic tests for the B-tree v2 code. This test inserts enough
985 * records to split the root node and force the tree to depth 1.
986 * It continues to add a more records to the each of the
987 * left and right leaf nodes after the split to force a 2 node
988 * split, adding another node to the B-tree
989 *
990 * Return: Success: 0
991 * Failure: 1
992 *
993 * Programmer: Quincey Koziol
994 * Tuesday, February 9, 2005
995 *
996 *-------------------------------------------------------------------------
997 */
998 static unsigned
test_insert_level1_side_split(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)999 test_insert_level1_side_split(hid_t fapl, const H5B2_create_t *cparam,
1000 const bt2_test_param_t *tparam)
1001 {
1002 hid_t file = -1; /* File ID */
1003 H5F_t *f = NULL; /* Internal file object pointer */
1004 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
1005 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
1006 haddr_t bt2_addr; /* Address of B-tree created */
1007 hsize_t record; /* Record to insert into tree */
1008 H5B2_stat_t bt2_stat; /* Statistics about B-tree created */
1009 unsigned u; /* Local index variable */
1010
1011 /*
1012 * Test inserting many records into v2 B-tree
1013 */
1014 TESTING("B-tree insert: split side leaf into 2 leaves in level 1 B-tree (l->r)");
1015
1016 /* Create the file for the test */
1017 if(create_file(&file, &f, fapl) < 0)
1018 TEST_ERROR
1019
1020 /* Create the v2 B-tree & get its address */
1021 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
1022 TEST_ERROR
1023
1024 /* Insert enough records to force root to split into 2 leaves */
1025 for(u = 0; u < INSERT_SPLIT_ROOT_NREC; u++) {
1026 record = u + INSERT_SPLIT_ROOT_NREC;
1027 if(H5B2_insert(bt2, dxpl, &record) < 0)
1028 FAIL_STACK_ERROR
1029 } /* end for */
1030
1031 /* Check up on B-tree */
1032 bt2_stat.depth = 1;
1033 bt2_stat.nrecords = INSERT_SPLIT_ROOT_NREC;
1034 if(check_stats(bt2, &bt2_stat) < 0)
1035 TEST_ERROR
1036 record = INSERT_SPLIT_ROOT_NREC + (INSERT_SPLIT_ROOT_NREC / 2);
1037 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
1038 TEST_ERROR
1039
1040 /* Check for closing & re-opening the B-tree */
1041 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
1042 TEST_ERROR
1043
1044 /* Force left node to split */
1045 for(u = 0; u < INSERT_SPLIT_ROOT_NREC; u++) {
1046 record = u;
1047 if(H5B2_insert(bt2, dxpl, &record) < 0)
1048 FAIL_STACK_ERROR
1049 } /* end for */
1050
1051 /* Check up on B-tree */
1052 bt2_stat.depth = 1;
1053 bt2_stat.nrecords = 2 * INSERT_SPLIT_ROOT_NREC;
1054 if(check_stats(bt2, &bt2_stat) < 0)
1055 TEST_ERROR
1056 record = 31;
1057 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
1058 TEST_ERROR
1059 record = 63;
1060 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
1061 TEST_ERROR
1062
1063 /* Close the v2 B-tree */
1064 if(H5B2_close(bt2, dxpl) < 0)
1065 FAIL_STACK_ERROR
1066 bt2 = NULL;
1067
1068 PASSED();
1069
1070 /*
1071 * Test inserting many records into v2 B-tree
1072 */
1073 TESTING("B-tree insert: split side leaf into 2 leaves in level 1 B-tree (r->l)");
1074
1075 /* Create the v2 B-tree & get its address */
1076 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
1077 TEST_ERROR
1078
1079 /* Insert enough records to force root to split into 2 leaves */
1080 for(u = 0; u < INSERT_SPLIT_ROOT_NREC; u++) {
1081 record = u;
1082 if(H5B2_insert(bt2, dxpl, &record) < 0)
1083 FAIL_STACK_ERROR
1084 } /* end for */
1085
1086 /* Check up on B-tree */
1087 bt2_stat.depth = 1;
1088 bt2_stat.nrecords = INSERT_SPLIT_ROOT_NREC;
1089 if(check_stats(bt2, &bt2_stat) < 0)
1090 TEST_ERROR
1091 record = (INSERT_SPLIT_ROOT_NREC / 2);
1092 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
1093 TEST_ERROR
1094
1095 /* Check for closing & re-opening the B-tree */
1096 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
1097 TEST_ERROR
1098
1099 /* Force right node to split */
1100 for(u = 0; u < INSERT_SPLIT_ROOT_NREC; u++) {
1101 record = u + INSERT_SPLIT_ROOT_NREC;
1102 if(H5B2_insert(bt2, dxpl, &record) < 0)
1103 FAIL_STACK_ERROR
1104 } /* end for */
1105
1106 /* Check up on B-tree */
1107 bt2_stat.depth = 1;
1108 bt2_stat.nrecords = 2 * INSERT_SPLIT_ROOT_NREC;
1109 if(check_stats(bt2, &bt2_stat) < 0)
1110 TEST_ERROR
1111 if(check_node_depth(bt2, dxpl, (hsize_t)62, (unsigned)1) < 0)
1112 TEST_ERROR
1113 if(check_node_depth(bt2, dxpl, (hsize_t)94, (unsigned)1) < 0)
1114 TEST_ERROR
1115
1116 /* Close the v2 B-tree */
1117 if(H5B2_close(bt2, dxpl) < 0)
1118 FAIL_STACK_ERROR
1119 bt2 = NULL;
1120
1121 /* Close file */
1122 if(H5Fclose(file) < 0)
1123 FAIL_STACK_ERROR
1124
1125 PASSED();
1126
1127 return 0;
1128
1129 error:
1130 H5E_BEGIN_TRY {
1131 if(bt2)
1132 H5B2_close(bt2, dxpl);
1133 H5Fclose(file);
1134 } H5E_END_TRY;
1135 return 1;
1136 } /* test_insert_level1_side_split() */
1137
1138
1139 /*-------------------------------------------------------------------------
1140 * Function: test_insert_level1_3leaf_redistrib
1141 *
1142 * Purpose: Basic tests for the B-tree v2 code. This test inserts enough
1143 * records to split the root node and force the tree to depth 1.
1144 * It continues to add a more records to the each of the
1145 * left and right leaf nodes after the split to force a 2 node
1146 * split, adding another node to the B-tree, then continues to
1147 * add records until a 3 node redistribution occurs
1148 *
1149 * Return: Success: 0
1150 *
1151 * Failure: 1
1152 *
1153 * Programmer: Quincey Koziol
1154 * Thursday, February 10, 2005
1155 *
1156 *-------------------------------------------------------------------------
1157 */
1158 static unsigned
test_insert_level1_3leaf_redistrib(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)1159 test_insert_level1_3leaf_redistrib(hid_t fapl, const H5B2_create_t *cparam,
1160 const bt2_test_param_t *tparam)
1161 {
1162 hid_t file = -1; /* File ID */
1163 H5F_t *f = NULL; /* Internal file object pointer */
1164 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
1165 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
1166 haddr_t bt2_addr; /* Address of B-tree created */
1167 hsize_t record; /* Record to insert into tree */
1168 H5B2_stat_t bt2_stat; /* Statistics about B-tree created */
1169 hsize_t idx; /* Index within B-tree, for iterator */
1170 unsigned u; /* Local index variable */
1171
1172 /*
1173 * Test inserting many records into v2 B-tree
1174 */
1175 TESTING("B-tree insert: redistribute 3 leaves in level 1 B-tree");
1176
1177 /* Create the file for the test */
1178 if(create_file(&file, &f, fapl) < 0)
1179 TEST_ERROR
1180
1181 /* Create the v2 B-tree & get its address */
1182 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
1183 TEST_ERROR
1184
1185 /* Insert enough records to force root to split into 2 leaves */
1186 for(u = 0; u < INSERT_SPLIT_ROOT_NREC; u++) {
1187 record = u + (INSERT_SPLIT_ROOT_NREC + (INSERT_SPLIT_ROOT_NREC / 2) + 1);
1188 if(H5B2_insert(bt2, dxpl, &record) < 0)
1189 FAIL_STACK_ERROR
1190 } /* end for */
1191
1192 /* Check up on B-tree */
1193 bt2_stat.depth = 1;
1194 bt2_stat.nrecords = INSERT_SPLIT_ROOT_NREC;
1195 if(check_stats(bt2, &bt2_stat) < 0)
1196 TEST_ERROR
1197 record = (2 * INSERT_SPLIT_ROOT_NREC);
1198 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
1199 TEST_ERROR
1200
1201 /* Check for closing & re-opening the B-tree */
1202 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
1203 TEST_ERROR
1204
1205 /* Force left node to split */
1206 for(u = 0; u < INSERT_SPLIT_ROOT_NREC; u++) {
1207 record = u;
1208 if(H5B2_insert(bt2, dxpl, &record) < 0)
1209 FAIL_STACK_ERROR
1210 } /* end for */
1211
1212 /* Check up on B-tree */
1213 bt2_stat.depth = 1;
1214 bt2_stat.nrecords = 2 * INSERT_SPLIT_ROOT_NREC;
1215 if(check_stats(bt2, &bt2_stat) < 0)
1216 TEST_ERROR
1217 record = (INSERT_SPLIT_ROOT_NREC / 2);
1218 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
1219 TEST_ERROR
1220 record = (INSERT_SPLIT_ROOT_NREC + (INSERT_SPLIT_ROOT_NREC / 2) + 1);
1221 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
1222 TEST_ERROR
1223
1224 /* Check for closing & re-opening the B-tree */
1225 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
1226 TEST_ERROR
1227
1228 /* Insert records to force middle node to redistribute */
1229 for(u = 0; u < ((INSERT_SPLIT_ROOT_NREC / 2) + 1); u++) {
1230 record = u + INSERT_SPLIT_ROOT_NREC;
1231 if(H5B2_insert(bt2, dxpl, &record) < 0)
1232 FAIL_STACK_ERROR
1233 } /* end for */
1234
1235 /* Check up on B-tree */
1236 bt2_stat.depth = 1;
1237 bt2_stat.nrecords = (2 * INSERT_SPLIT_ROOT_NREC) + (INSERT_SPLIT_ROOT_NREC / 2) + 1;
1238 if(check_stats(bt2, &bt2_stat) < 0)
1239 TEST_ERROR
1240 if(check_node_depth(bt2, dxpl, (hsize_t)52, (unsigned)1) < 0)
1241 TEST_ERROR
1242 if(check_node_depth(bt2, dxpl, (hsize_t)105, (unsigned)1) < 0)
1243 TEST_ERROR
1244
1245 /* Check for closing & re-opening the B-tree */
1246 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
1247 TEST_ERROR
1248
1249 /* Iterate over B-tree to check records have been inserted correctly */
1250 idx = 0;
1251 if(H5B2_iterate(bt2, dxpl, iter_cb, &idx) < 0)
1252 FAIL_STACK_ERROR
1253
1254 /* Make certain that the index is correct */
1255 if(idx != ((INSERT_SPLIT_ROOT_NREC * 2) + (INSERT_SPLIT_ROOT_NREC / 2) + 1))
1256 TEST_ERROR
1257
1258 /* Close the v2 B-tree */
1259 if(H5B2_close(bt2, dxpl) < 0)
1260 FAIL_STACK_ERROR
1261 bt2 = NULL;
1262
1263 /* Close file */
1264 if(H5Fclose(file) < 0)
1265 FAIL_STACK_ERROR
1266
1267 PASSED();
1268
1269 return 0;
1270
1271 error:
1272 H5E_BEGIN_TRY {
1273 if(bt2)
1274 H5B2_close(bt2, dxpl);
1275 H5Fclose(file);
1276 } H5E_END_TRY;
1277 return 1;
1278 } /* test_insert_level1_3leaf_redistrib() */
1279
1280
1281 /*-------------------------------------------------------------------------
1282 * Function: test_insert_level1_middle_split
1283 *
1284 * Purpose: Basic tests for the B-tree v2 code. This test inserts enough
1285 * records to split the root node and force the tree to depth 1.
1286 * It continues to add a more records to the each of the
1287 * left and right leaf nodes after the split to force a 2 node
1288 * split, adding another node to the B-tree, then continues to
1289 * add records until a 3 node split occurs
1290 *
1291 * Return: Success: 0
1292 * Failure: 1
1293 *
1294 * Programmer: Quincey Koziol
1295 * Thursday, February 10, 2005
1296 *
1297 *-------------------------------------------------------------------------
1298 */
1299 static unsigned
test_insert_level1_middle_split(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)1300 test_insert_level1_middle_split(hid_t fapl, const H5B2_create_t *cparam,
1301 const bt2_test_param_t *tparam)
1302 {
1303 hid_t file = -1; /* File ID */
1304 H5F_t *f = NULL; /* Internal file object pointer */
1305 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
1306 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
1307 haddr_t bt2_addr; /* Address of B-tree created */
1308 hsize_t record; /* Record to insert into tree */
1309 H5B2_stat_t bt2_stat; /* Statistics about B-tree created */
1310 hsize_t idx; /* Index within B-tree, for iterator */
1311 unsigned u; /* Local index variable */
1312
1313 /*
1314 * Test inserting many records into v2 B-tree
1315 */
1316 TESTING("B-tree insert: split middle leaf into 2 leaves in level 1 B-tree");
1317
1318 /* Create the file for the test */
1319 if(create_file(&file, &f, fapl) < 0)
1320 TEST_ERROR
1321
1322 /* Create the v2 B-tree & get its address */
1323 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
1324 TEST_ERROR
1325
1326 /* Insert enough records to force root to split into 2 leaves */
1327 for(u = 0; u < INSERT_SPLIT_ROOT_NREC; u++) {
1328 record = u + (INSERT_SPLIT_ROOT_NREC * 2);
1329 if(H5B2_insert(bt2, dxpl, &record) < 0)
1330 FAIL_STACK_ERROR
1331 } /* end for */
1332
1333 /* Check up on B-tree */
1334 bt2_stat.depth = 1;
1335 bt2_stat.nrecords = INSERT_SPLIT_ROOT_NREC;
1336 if(check_stats(bt2, &bt2_stat) < 0)
1337 TEST_ERROR
1338 record = (2 * INSERT_SPLIT_ROOT_NREC) + (INSERT_SPLIT_ROOT_NREC / 2);
1339 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
1340 TEST_ERROR
1341
1342 /* Check for closing & re-opening the B-tree */
1343 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
1344 TEST_ERROR
1345
1346 /* Force split from left node into right node */
1347 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC * 2); u++) {
1348 record = u;
1349 if(H5B2_insert(bt2, dxpl, &record) < 0)
1350 FAIL_STACK_ERROR
1351 } /* end for */
1352
1353 /* Check up on B-tree */
1354 bt2_stat.depth = 1;
1355 bt2_stat.nrecords = 3 * INSERT_SPLIT_ROOT_NREC;
1356 if(check_stats(bt2, &bt2_stat) < 0)
1357 TEST_ERROR
1358 if(check_node_depth(bt2, dxpl, (hsize_t)62, (unsigned)1) < 0)
1359 TEST_ERROR
1360 if(check_node_depth(bt2, dxpl, (hsize_t)94, (unsigned)1) < 0)
1361 TEST_ERROR
1362 if(check_node_depth(bt2, dxpl, (hsize_t)126, (unsigned)1) < 0)
1363 TEST_ERROR
1364
1365 /* Check for closing & re-opening the B-tree */
1366 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
1367 TEST_ERROR
1368
1369 /* Iterate over B-tree to check records have been inserted correctly */
1370 idx = 0;
1371 if(H5B2_iterate(bt2, dxpl, iter_cb, &idx) < 0)
1372 FAIL_STACK_ERROR
1373
1374 /* Make certain that the index is correct */
1375 if(idx != (INSERT_SPLIT_ROOT_NREC * 3))
1376 TEST_ERROR
1377
1378 /* Close the v2 B-tree */
1379 if(H5B2_close(bt2, dxpl) < 0)
1380 FAIL_STACK_ERROR
1381 bt2 = NULL;
1382
1383 /* Close file */
1384 if(H5Fclose(file) < 0)
1385 STACK_ERROR
1386
1387 PASSED();
1388
1389 return 0;
1390
1391 error:
1392 H5E_BEGIN_TRY {
1393 if(bt2)
1394 H5B2_close(bt2, dxpl);
1395 H5Fclose(file);
1396 } H5E_END_TRY;
1397 return 1;
1398 } /* test_insert_level1_middle_split() */
1399
1400
1401 /*-------------------------------------------------------------------------
1402 * Function: test_insert_make_level2
1403 *
1404 * Purpose: Basic tests for the B-tree v2 code. This test inserts enough
1405 * records to make a level 2 B-tree
1406 *
1407 * Return: Success: 0
1408 * Failure: 1
1409 *
1410 * Programmer: Quincey Koziol
1411 * Friday, February 11, 2005
1412 *
1413 *-------------------------------------------------------------------------
1414 */
1415 static unsigned
test_insert_make_level2(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)1416 test_insert_make_level2(hid_t fapl, const H5B2_create_t *cparam,
1417 const bt2_test_param_t *tparam)
1418 {
1419 hid_t file = -1; /* File ID */
1420 H5F_t *f = NULL; /* Internal file object pointer */
1421 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
1422 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
1423 haddr_t bt2_addr; /* Address of B-tree created */
1424 hsize_t record; /* Record to insert into tree */
1425 H5B2_stat_t bt2_stat; /* Statistics about B-tree created */
1426 hsize_t idx; /* Index within B-tree, for iterator */
1427 unsigned u; /* Local index variable */
1428 herr_t ret; /* Generic error return value */
1429
1430 /*
1431 * Test inserting many records into v2 B-tree
1432 */
1433 TESTING("B-tree insert: make level 2 B-tree");
1434
1435 /* Create the file for the test */
1436 if(create_file(&file, &f, fapl) < 0)
1437 TEST_ERROR
1438
1439 /* Create the v2 B-tree & get its address */
1440 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
1441 TEST_ERROR
1442
1443 /* Insert enough records to force root to split into 2 internal nodes */
1444 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC * 9); u++) {
1445 record = u + 2;
1446 if(H5B2_insert(bt2, dxpl, &record) < 0)
1447 FAIL_STACK_ERROR
1448 } /* end for */
1449 for(; u < ((INSERT_SPLIT_ROOT_NREC * 29) + 1); u++) {
1450 record = u + 4;
1451 if(H5B2_insert(bt2, dxpl, &record) < 0)
1452 FAIL_STACK_ERROR
1453 } /* end for */
1454
1455 /* Check up on B-tree */
1456 bt2_stat.depth = 2;
1457 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC * 29) + 1;
1458 if(check_stats(bt2, &bt2_stat) < 0)
1459 TEST_ERROR
1460 if(check_node_depth(bt2, dxpl, (hsize_t)948, (unsigned)2) < 0)
1461 TEST_ERROR
1462
1463 /* Check for closing & re-opening the B-tree */
1464 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
1465 TEST_ERROR
1466
1467 /* Add some extra records to left-most leaf */
1468 record = 0;
1469 if(H5B2_insert(bt2, dxpl, &record) < 0)
1470 FAIL_STACK_ERROR
1471 record = 1;
1472 if(H5B2_insert(bt2, dxpl, &record) < 0)
1473 FAIL_STACK_ERROR
1474
1475 /* Add some extra records to middle leaf */
1476 record = (INSERT_SPLIT_ROOT_NREC * 9) + 2;
1477 if(H5B2_insert(bt2, dxpl, &record) < 0)
1478 FAIL_STACK_ERROR
1479 record = (INSERT_SPLIT_ROOT_NREC * 9) + 3;
1480 if(H5B2_insert(bt2, dxpl, &record) < 0)
1481 FAIL_STACK_ERROR
1482
1483 /* Check for closing & re-opening the B-tree */
1484 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
1485 TEST_ERROR
1486
1487
1488 /* Iterate over B-tree to check records have been inserted correctly */
1489 idx = 0;
1490 if(H5B2_iterate(bt2, dxpl, iter_cb, &idx) < 0)
1491 FAIL_STACK_ERROR
1492
1493 /* Make certain that the index is correct */
1494 if(idx != ((INSERT_SPLIT_ROOT_NREC * 29) + 5))
1495 TEST_ERROR
1496
1497 /* Attempt to find non-existant record in level-2 B-tree */
1498 /* (Should not be found, but not fail) */
1499 idx = INSERT_SPLIT_ROOT_NREC * 30;
1500 if(H5B2_find(bt2, dxpl, &idx, find_cb, &idx) != FALSE)
1501 TEST_ERROR
1502
1503 /* Attempt to find existant record in root of level-2 B-tree */
1504 idx = 948;
1505 if(H5B2_find(bt2, dxpl, &idx, find_cb, &idx) != TRUE)
1506 FAIL_STACK_ERROR
1507
1508 /* Check with B-tree */
1509 if(check_node_depth(bt2, dxpl, (hsize_t)948, (unsigned)2) < 0)
1510 TEST_ERROR
1511
1512 /* Attempt to find existant record in internal node of level-2 B-tree */
1513 idx = 505;
1514 if(H5B2_find(bt2, dxpl, &idx, find_cb, &idx) != TRUE)
1515 FAIL_STACK_ERROR
1516
1517 /* Check with B-tree */
1518 if(check_node_depth(bt2, dxpl, (hsize_t)505, (unsigned)1) < 0)
1519 TEST_ERROR
1520
1521 /* Attempt to find existant record in leaf of level-2 B-tree */
1522 idx = 555;
1523 if(H5B2_find(bt2, dxpl, &idx, find_cb, &idx) != TRUE)
1524 FAIL_STACK_ERROR
1525
1526 /* Check with B-tree */
1527 if(check_node_depth(bt2, dxpl, (hsize_t)555, (unsigned)0) < 0)
1528 TEST_ERROR
1529
1530 /* Attempt to index non-existant record in level-2 B-tree */
1531 idx = 0;
1532 H5E_BEGIN_TRY {
1533 ret = H5B2_index(bt2, dxpl, H5_ITER_INC, (hsize_t)(INSERT_SPLIT_ROOT_NREC * 30), find_cb, NULL);
1534 } H5E_END_TRY;
1535 /* Should fail */
1536 if(ret != FAIL)
1537 TEST_ERROR
1538
1539 /* Attempt to index existing record in root of level-2 B-tree */
1540 idx = 948;
1541 if(H5B2_index(bt2, dxpl, H5_ITER_INC, (hsize_t)948, find_cb, &idx) < 0)
1542 FAIL_STACK_ERROR
1543
1544 /* Attempt to index existing record in internal node of level-2 B-tree */
1545 idx = 505;
1546 if(H5B2_index(bt2, dxpl, H5_ITER_INC, (hsize_t)505, find_cb, &idx) < 0)
1547 FAIL_STACK_ERROR
1548
1549 /* Attempt to index existing record in leaf of level-2 B-tree */
1550 idx = 555;
1551 if(H5B2_index(bt2, dxpl, H5_ITER_INC, (hsize_t)555, find_cb, &idx) < 0)
1552 FAIL_STACK_ERROR
1553
1554 /* Close the v2 B-tree */
1555 if(H5B2_close(bt2, dxpl) < 0)
1556 FAIL_STACK_ERROR
1557 bt2 = NULL;
1558
1559 /* Close file */
1560 if(H5Fclose(file) < 0)
1561 FAIL_STACK_ERROR
1562
1563 PASSED();
1564
1565 return 0;
1566
1567 error:
1568 H5E_BEGIN_TRY {
1569 if(bt2)
1570 H5B2_close(bt2, dxpl);
1571 H5Fclose(file);
1572 } H5E_END_TRY;
1573 return 1;
1574 } /* test_insert_make_level2() */
1575
1576
1577 /*-------------------------------------------------------------------------
1578 * Function: test_insert_level2_leaf_redistrib
1579 *
1580 * Purpose: Basic tests for the B-tree v2 code. This test inserts enough
1581 * records to make a level 2 B-tree and then adds enough more
1582 * records to force the leaves to redistribute
1583 *
1584 * Return: Success: 0
1585 *
1586 * Failure: 1
1587 *
1588 * Programmer: Quincey Koziol
1589 * Thursday, February 17, 2005
1590 *
1591 *-------------------------------------------------------------------------
1592 */
1593 static unsigned
test_insert_level2_leaf_redistrib(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)1594 test_insert_level2_leaf_redistrib(hid_t fapl, const H5B2_create_t *cparam,
1595 const bt2_test_param_t *tparam)
1596 {
1597 hid_t file = -1; /* File ID */
1598 H5F_t *f = NULL; /* Internal file object pointer */
1599 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
1600 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
1601 haddr_t bt2_addr; /* Address of B-tree created */
1602 hsize_t record; /* Record to insert into tree */
1603 H5B2_stat_t bt2_stat; /* Statistics about B-tree created */
1604 hsize_t idx; /* Index within B-tree, for iterator */
1605 unsigned u; /* Local index variable */
1606
1607 /*
1608 * Test inserting many records into v2 B-tree
1609 */
1610 TESTING("B-tree insert: redistrib right-most leaf in level 2 B-tree");
1611
1612 /* Create the file for the test */
1613 if(create_file(&file, &f, fapl) < 0)
1614 TEST_ERROR
1615
1616 /* Create the v2 B-tree & get its address */
1617 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
1618 TEST_ERROR
1619
1620 /* Insert enough records to force root to split into 2 internal nodes */
1621 /* And fill rightmost leaf */
1622 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC * 8); u++) {
1623 record = u + (INSERT_SPLIT_ROOT_NREC / 2) + 1;
1624 if(H5B2_insert(bt2, dxpl, &record) < 0)
1625 FAIL_STACK_ERROR
1626 } /* end for */
1627 for(; u < ((INSERT_SPLIT_ROOT_NREC * 29) + (INSERT_SPLIT_ROOT_NREC / 2)); u++) {
1628 record = u + INSERT_SPLIT_ROOT_NREC + 1;
1629 if(H5B2_insert(bt2, dxpl, &record) < 0)
1630 FAIL_STACK_ERROR
1631 } /* end for */
1632
1633 /* Check up on B-tree */
1634 bt2_stat.depth = 2;
1635 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC * 29) + (INSERT_SPLIT_ROOT_NREC / 2);
1636 if(check_stats(bt2, &bt2_stat) < 0)
1637 TEST_ERROR
1638 if(check_node_depth(bt2, dxpl, (hsize_t)1008, (unsigned)2) < 0)
1639 TEST_ERROR
1640 if(check_node_depth(bt2, dxpl, (hsize_t)1859, (unsigned)1) < 0)
1641 TEST_ERROR
1642 if(check_node_depth(bt2, dxpl, (hsize_t)1921, (unsigned)0) < 0)
1643 TEST_ERROR
1644
1645 /* Check for closing & re-opening the B-tree */
1646 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
1647 TEST_ERROR
1648
1649 /* Insert record to force redistribution of rightmost leaf */
1650 record = u + INSERT_SPLIT_ROOT_NREC + 1;
1651 if(H5B2_insert(bt2, dxpl, &record) < 0)
1652 FAIL_STACK_ERROR
1653
1654 /* Check up on B-tree */
1655 bt2_stat.depth = 2;
1656 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC * 29) + (INSERT_SPLIT_ROOT_NREC / 2) + 1;
1657 if(check_stats(bt2, &bt2_stat) < 0)
1658 TEST_ERROR
1659 if(check_node_depth(bt2, dxpl, (hsize_t)1008, (unsigned)2) < 0)
1660 TEST_ERROR
1661 if(check_node_depth(bt2, dxpl, (hsize_t)1875, (unsigned)1) < 0)
1662 TEST_ERROR
1663 if(check_node_depth(bt2, dxpl, (hsize_t)1922, (unsigned)0) < 0)
1664 TEST_ERROR
1665
1666 PASSED();
1667
1668 TESTING("B-tree insert: redistrib left-most leaf in level 2 B-tree");
1669
1670 /* Check for closing & re-opening the B-tree */
1671 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
1672 TEST_ERROR
1673
1674 /* Check up on B-tree */
1675 bt2_stat.depth = 2;
1676 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC * 29) + (INSERT_SPLIT_ROOT_NREC / 2) + 1;
1677 if(check_stats(bt2, &bt2_stat) < 0)
1678 TEST_ERROR
1679 if(check_node_depth(bt2, dxpl, (hsize_t)1008, (unsigned)2) < 0)
1680 TEST_ERROR
1681 if(check_node_depth(bt2, dxpl, (hsize_t)94, (unsigned)1) < 0)
1682 TEST_ERROR
1683 if(check_node_depth(bt2, dxpl, (hsize_t)32, (unsigned)0) < 0)
1684 TEST_ERROR
1685
1686 /* Add more records to left-most leaf, to force a 2->1 split and then a
1687 * 2 node redistribution on left leaf
1688 */
1689 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC / 2) + 1; u++) {
1690 record = u;
1691 if(H5B2_insert(bt2, dxpl, &record) < 0)
1692 FAIL_STACK_ERROR
1693 } /* end for */
1694
1695 /* Check up on B-tree */
1696 bt2_stat.depth = 2;
1697 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC * 30) + 1;
1698 if(check_stats(bt2, &bt2_stat) < 0)
1699 TEST_ERROR
1700 if(check_node_depth(bt2, dxpl, (hsize_t)1008, (unsigned)2) < 0)
1701 TEST_ERROR
1702 if(check_node_depth(bt2, dxpl, (hsize_t)47, (unsigned)1) < 0)
1703 TEST_ERROR
1704 if(check_node_depth(bt2, dxpl, (hsize_t)0, (unsigned)0) < 0)
1705 TEST_ERROR
1706
1707 PASSED();
1708
1709 TESTING("B-tree insert: redistrib middle leaf in level 2 B-tree");
1710
1711 /* Check for closing & re-opening the B-tree */
1712 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
1713 TEST_ERROR
1714
1715 /* Check up on B-tree */
1716 bt2_stat.depth = 2;
1717 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC * 30) + 1;
1718 if(check_stats(bt2, &bt2_stat) < 0)
1719 TEST_ERROR
1720 if(check_node_depth(bt2, dxpl, (hsize_t)1008, (unsigned)2) < 0) /* Record in root node */
1721 TEST_ERROR
1722 if(check_node_depth(bt2, dxpl, (hsize_t)535, (unsigned)1) < 0) /* Record in middle node before insertion point */
1723 TEST_ERROR
1724 if(check_node_depth(bt2, dxpl, (hsize_t)630, (unsigned)1) < 0) /* Record in middle node after insertion point */
1725 TEST_ERROR
1726 if(check_node_depth(bt2, dxpl, (hsize_t)568, (unsigned)0) < 0) /* Record in leaf node just after insertion point */
1727 TEST_ERROR
1728
1729 /* Add more records to middle leaf, to force a split and a 3 node redistribution on middle leaf */
1730 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC / 2) + 1; u++) {
1731 record = u + (INSERT_SPLIT_ROOT_NREC * 8) + (INSERT_SPLIT_ROOT_NREC / 2) + 1;
1732 if(H5B2_insert(bt2, dxpl, &record) < 0)
1733 FAIL_STACK_ERROR
1734 } /* end for */
1735
1736 /* Check up on B-tree */
1737 bt2_stat.depth = 2;
1738 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC * 30) + (INSERT_SPLIT_ROOT_NREC / 2) + 2;
1739 if(check_stats(bt2, &bt2_stat) < 0)
1740 TEST_ERROR
1741 if(check_node_depth(bt2, dxpl, (hsize_t)1008, (unsigned)2) < 0) /* Record in root node */
1742 TEST_ERROR
1743 if(check_node_depth(bt2, dxpl, (hsize_t)524, (unsigned)1) < 0) /* Record in middle node before insertion point */
1744 TEST_ERROR
1745 if(check_node_depth(bt2, dxpl, (hsize_t)577, (unsigned)1) < 0) /* Record in middle node after insertion point */
1746 TEST_ERROR
1747 if(check_node_depth(bt2, dxpl, (hsize_t)568, (unsigned)0) < 0) /* Record in leaf node just after insertion point */
1748 TEST_ERROR
1749
1750 /* Check for closing & re-opening the B-tree */
1751 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
1752 TEST_ERROR
1753
1754 /* Iterate over B-tree to check records have been inserted correctly */
1755 idx = 0;
1756 if(H5B2_iterate(bt2, dxpl, iter_cb, &idx) < 0)
1757 FAIL_STACK_ERROR
1758
1759 /* Make certain that the index is correct */
1760 if(idx != ((INSERT_SPLIT_ROOT_NREC * 30) + (INSERT_SPLIT_ROOT_NREC / 2) + 2))
1761 TEST_ERROR
1762
1763 /* Close the v2 B-tree */
1764 if(H5B2_close(bt2, dxpl) < 0)
1765 FAIL_STACK_ERROR
1766 bt2 = NULL;
1767
1768 /* Close file */
1769 if(H5Fclose(file) < 0)
1770 STACK_ERROR
1771
1772 PASSED();
1773
1774 return 0;
1775
1776 error:
1777 H5E_BEGIN_TRY {
1778 if(bt2)
1779 H5B2_close(bt2, dxpl);
1780 H5Fclose(file);
1781 } H5E_END_TRY;
1782 return 1;
1783 } /* test_insert_level2_leaf_redistrib() */
1784
1785
1786 /*-------------------------------------------------------------------------
1787 * Function: test_insert_level2_leaf_split
1788 *
1789 * Purpose: Basic tests for the B-tree v2 code. This test inserts enough
1790 * records to make a level 2 B-tree and then adds enough more
1791 * records to force leaves to split.
1792 *
1793 * Return: Success: 0
1794 *
1795 * Failure: 1
1796 *
1797 * Programmer: Quincey Koziol
1798 * Thursday, February 17, 2005
1799 *
1800 *-------------------------------------------------------------------------
1801 */
1802 static unsigned
test_insert_level2_leaf_split(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)1803 test_insert_level2_leaf_split(hid_t fapl, const H5B2_create_t *cparam,
1804 const bt2_test_param_t *tparam)
1805 {
1806 hid_t file = -1; /* File ID */
1807 H5F_t *f = NULL; /* Internal file object pointer */
1808 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
1809 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
1810 haddr_t bt2_addr; /* Address of B-tree created */
1811 hsize_t record; /* Record to insert into tree */
1812 H5B2_stat_t bt2_stat; /* Statistics about B-tree created */
1813 hsize_t idx; /* Index within B-tree, for iterator */
1814 unsigned u; /* Local index variable */
1815
1816 /*
1817 * Test inserting many records into v2 B-tree
1818 */
1819 TESTING("B-tree insert: split right-most leaf in level 2 B-tree");
1820
1821 /* Create the file for the test */
1822 if(create_file(&file, &f, fapl) < 0)
1823 TEST_ERROR
1824
1825 /* Create the v2 B-tree & get its address */
1826 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
1827 TEST_ERROR
1828
1829 /* Insert enough records to force root to split into 2 internal nodes */
1830 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC * 8); u++) {
1831 record = u + 1;
1832 if(H5B2_insert(bt2, dxpl, &record) < 0)
1833 FAIL_STACK_ERROR
1834 } /* end for */
1835 for(; u < ((INSERT_SPLIT_ROOT_NREC * 29) + (INSERT_SPLIT_ROOT_NREC / 2)); u++) {
1836 record = u + 2;
1837 if(H5B2_insert(bt2, dxpl, &record) < 0)
1838 FAIL_STACK_ERROR
1839 } /* end for */
1840
1841 /* Check up on B-tree */
1842 bt2_stat.depth = 2;
1843 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC * 29) + (INSERT_SPLIT_ROOT_NREC / 2);
1844 if(check_stats(bt2, &bt2_stat) < 0)
1845 TEST_ERROR
1846 record = 946; /* Record in root node */
1847 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
1848 TEST_ERROR
1849 record = 1797; /* Right-most record in right internal node */
1850 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
1851 TEST_ERROR
1852 record = 1859; /* Right-most record in right-most leaf */
1853 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
1854 TEST_ERROR
1855
1856 /* Check for closing & re-opening the B-tree */
1857 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
1858 TEST_ERROR
1859
1860 /* Insert enough records to force right-most leaf to split */
1861 for(u = 0; u < ((INSERT_SPLIT_ROOT_NREC / 2) + 1); u++) {
1862 record = u + (INSERT_SPLIT_ROOT_NREC * 29) + (INSERT_SPLIT_ROOT_NREC / 2) + 2;
1863 if(H5B2_insert(bt2, dxpl, &record) < 0)
1864 FAIL_STACK_ERROR
1865 } /* end for */
1866
1867 /* Check up on B-tree */
1868 bt2_stat.depth = 2;
1869 bt2_stat.nrecords = INSERT_SPLIT_ROOT_NREC * 30;
1870 if(check_stats(bt2, &bt2_stat) < 0)
1871 TEST_ERROR
1872 record = 946; /* Record in root node */
1873 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
1874 TEST_ERROR
1875 record = 1828; /* Next-to-right-most record in right-most internal node */
1876 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
1877 TEST_ERROR
1878 record = 1860; /* Right-most record in right-most internal node */
1879 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
1880 TEST_ERROR
1881 record = 1891; /* Right-most record in right-most leaf */
1882 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
1883 TEST_ERROR
1884
1885 PASSED();
1886
1887 TESTING("B-tree insert: split left-most leaf in level 2 B-tree");
1888
1889 /* Check for closing & re-opening the B-tree */
1890 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
1891 TEST_ERROR
1892
1893 /* Check up on B-tree */
1894 bt2_stat.depth = 2;
1895 bt2_stat.nrecords = INSERT_SPLIT_ROOT_NREC * 30;
1896 if(check_stats(bt2, &bt2_stat) < 0)
1897 TEST_ERROR
1898 record = 946; /* Record in root node */
1899 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
1900 TEST_ERROR
1901 record = 63; /* Left-most record in left-most internal node */
1902 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
1903 TEST_ERROR
1904 record = 1; /* Left-most record in left-most leaf */
1905 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
1906 TEST_ERROR
1907
1908 /* Add another record to left-most leaf, to force a 1->2 node split on left leaf */
1909 record = 0;
1910 if(H5B2_insert(bt2, dxpl, &record) < 0)
1911 FAIL_STACK_ERROR
1912
1913 /* Check up on B-tree */
1914 bt2_stat.depth = 2;
1915 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC * 30) + 1;
1916 if(check_stats(bt2, &bt2_stat) < 0)
1917 TEST_ERROR
1918 record = 946; /* Record in root node */
1919 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
1920 TEST_ERROR
1921 record = 63; /* Left-most record in left-most internal node */
1922 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
1923 TEST_ERROR
1924 record = 32; /* Left-most record in left internal node */
1925 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
1926 TEST_ERROR
1927 record = 0; /* Left-most record in left-most leaf */
1928 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
1929 TEST_ERROR
1930
1931 PASSED();
1932
1933 TESTING("B-tree insert: split middle leaf in level 2 B-tree");
1934
1935 /* Check for closing & re-opening the B-tree */
1936 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
1937 TEST_ERROR
1938
1939 /* Check up on B-tree */
1940 bt2_stat.depth = 2;
1941 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC * 30) + 1;
1942 if(check_stats(bt2, &bt2_stat) < 0)
1943 TEST_ERROR
1944 record = 946; /* Record in root node */
1945 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
1946 TEST_ERROR
1947 record = 504; /* Record in internal node just before insertion point */
1948 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
1949 TEST_ERROR
1950 record = 568; /* Record in internal node just after insertion point */
1951 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
1952 TEST_ERROR
1953 record = 506; /* Record in leaf node just after insertion point */
1954 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
1955 TEST_ERROR
1956
1957 /* Add another record to middle leaf, to force a node split on middle leaf */
1958 record = (INSERT_SPLIT_ROOT_NREC * 8) + 1;
1959 if(H5B2_insert(bt2, dxpl, &record) < 0)
1960 FAIL_STACK_ERROR
1961
1962 /* Check up on B-tree */
1963 bt2_stat.depth = 2;
1964 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC * 30) + 2;
1965 if(check_stats(bt2, &bt2_stat) < 0)
1966 TEST_ERROR
1967 record = 946; /* Record in root node */
1968 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
1969 TEST_ERROR
1970 record = 504; /* Left-most record of split in left internal node */
1971 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
1972 TEST_ERROR
1973 record = 537; /* Middle record of split in left internal node */
1974 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
1975 TEST_ERROR
1976 record = 568; /* Right-most record of split in left internal node */
1977 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
1978 TEST_ERROR
1979 record = 506; /* Record in leaf node just after insertion point */
1980 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
1981 TEST_ERROR
1982
1983 /* Check for closing & re-opening the B-tree */
1984 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
1985 TEST_ERROR
1986
1987 /* Iterate over B-tree to check records have been inserted correctly */
1988 idx = 0;
1989 if(H5B2_iterate(bt2, dxpl, iter_cb, &idx) < 0)
1990 FAIL_STACK_ERROR
1991
1992 /* Make certain that the index is correct */
1993 if(idx != ((INSERT_SPLIT_ROOT_NREC * 30) + 2))
1994 TEST_ERROR
1995
1996 /* Close the v2 B-tree */
1997 if(H5B2_close(bt2, dxpl) < 0)
1998 FAIL_STACK_ERROR
1999 bt2 = NULL;
2000
2001 /* Close file */
2002 if(H5Fclose(file) < 0)
2003 FAIL_STACK_ERROR
2004
2005 PASSED();
2006
2007 return 0;
2008
2009 error:
2010 H5E_BEGIN_TRY {
2011 if(bt2)
2012 H5B2_close(bt2, dxpl);
2013 H5Fclose(file);
2014 } H5E_END_TRY;
2015 return 1;
2016 } /* test_insert_level2_leaf_split() */
2017
2018
2019 /*-------------------------------------------------------------------------
2020 * Function: test_insert_level2_2internal_redistrib
2021 *
2022 * Purpose: Basic tests for the B-tree v2 code. This test inserts enough
2023 * records to make a level 2 B-tree and then adds enough more
2024 * records to force the left-most and right-most internal nodes to
2025 * redistribute.
2026 *
2027 * Return: Success: 0
2028 *
2029 * Failure: 1
2030 *
2031 * Programmer: Quincey Koziol
2032 * Friday, February 18, 2005
2033 *
2034 *-------------------------------------------------------------------------
2035 */
2036 static unsigned
test_insert_level2_2internal_redistrib(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)2037 test_insert_level2_2internal_redistrib(hid_t fapl, const H5B2_create_t *cparam,
2038 const bt2_test_param_t *tparam)
2039 {
2040 hid_t file = -1; /* File ID */
2041 H5F_t *f = NULL; /* Internal file object pointer */
2042 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
2043 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
2044 haddr_t bt2_addr; /* Address of B-tree created */
2045 hsize_t record; /* Record to insert into tree */
2046 H5B2_stat_t bt2_stat; /* Statistics about B-tree created */
2047 hsize_t idx; /* Index within B-tree, for iterator */
2048 unsigned u; /* Local index variable */
2049
2050 /*
2051 * Test inserting many records into v2 B-tree
2052 */
2053 TESTING("B-tree insert: redist. 2 internal (r->l) in level 2 B-tree");
2054
2055 /* Create the file for the test */
2056 if(create_file(&file, &f, fapl) < 0)
2057 TEST_ERROR
2058
2059 /* Create the v2 B-tree & get its address */
2060 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
2061 TEST_ERROR
2062
2063 /* Insert enough records to force root to split into 2 internal nodes */
2064 /* And fill up right internal node, to just before to redistribute it */
2065 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC * 44); u++) {
2066 record = u + (INSERT_SPLIT_ROOT_NREC * 6) - 4;
2067 if(H5B2_insert(bt2, dxpl, &record) < 0)
2068 FAIL_STACK_ERROR
2069 } /* end for */
2070
2071 /* Check up on B-tree */
2072 bt2_stat.depth = 2;
2073 bt2_stat.nrecords = INSERT_SPLIT_ROOT_NREC * 44;
2074 if(check_stats(bt2, &bt2_stat) < 0)
2075 TEST_ERROR
2076 record = 1318; /* Record in root node */
2077 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2078 TEST_ERROR
2079 record = 3114; /* Right-most record in right internal node */
2080 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
2081 TEST_ERROR
2082 record = 3145; /* Right-most record in right leaf node */
2083 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
2084 TEST_ERROR
2085
2086 /* Check for closing & re-opening the B-tree */
2087 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
2088 TEST_ERROR
2089
2090 /* Insert record to redistribute right-most internal node */
2091 record = u + (INSERT_SPLIT_ROOT_NREC * 6) - 4;
2092 if(H5B2_insert(bt2, dxpl, &record) < 0)
2093 FAIL_STACK_ERROR
2094
2095 /* Check up on B-tree */
2096 bt2_stat.depth = 2;
2097 bt2_stat.nrecords = INSERT_SPLIT_ROOT_NREC * 44 + 1;
2098 if(check_stats(bt2, &bt2_stat) < 0)
2099 TEST_ERROR
2100 record = 1822; /* Record in root node */
2101 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2102 TEST_ERROR
2103 record = 3114; /* Right-most record in right internal node */
2104 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
2105 TEST_ERROR
2106 record = 3146; /* Right-most record in right leaf node */
2107 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
2108 TEST_ERROR
2109
2110 PASSED();
2111
2112 TESTING("B-tree insert: redist. 2 internal (l->r) in level 2 B-tree");
2113
2114 /* Check for closing & re-opening the B-tree */
2115 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
2116 TEST_ERROR
2117
2118 /* Check up on B-tree */
2119 bt2_stat.depth = 2;
2120 bt2_stat.nrecords = INSERT_SPLIT_ROOT_NREC * 44 + 1;
2121 if(check_stats(bt2, &bt2_stat) < 0)
2122 TEST_ERROR
2123 record = 1822; /* Record in root node */
2124 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2125 TEST_ERROR
2126 record = 436; /* Left-most record in left internal node */
2127 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
2128 TEST_ERROR
2129 record = 374; /* Left-most record in left leaf node */
2130 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
2131 TEST_ERROR
2132
2133 /* Force left-most internal node to redistribute */
2134 for(u = 0; u < ((INSERT_SPLIT_ROOT_NREC * 6) - 4); u++) {
2135 record = u;
2136 if(H5B2_insert(bt2, dxpl, &record) < 0)
2137 FAIL_STACK_ERROR
2138 } /* end for */
2139
2140 /* Check up on B-tree */
2141 bt2_stat.depth = 2;
2142 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC * 50) - 3;
2143 if(check_stats(bt2, &bt2_stat) < 0)
2144 TEST_ERROR
2145 record = 1570; /* Record in root node */
2146 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2147 TEST_ERROR
2148 record = 61; /* Left-most record in left internal node */
2149 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
2150 TEST_ERROR
2151 record = 0; /* Left-most record in left leaf node */
2152 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
2153 TEST_ERROR
2154
2155 /* Check for closing & re-opening the B-tree */
2156 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
2157 TEST_ERROR
2158
2159 /* Iterate over B-tree to check records have been inserted correctly */
2160 idx = 0;
2161 if(H5B2_iterate(bt2, dxpl, iter_cb, &idx) < 0)
2162 FAIL_STACK_ERROR
2163
2164 /* Make certain that the index is correct */
2165 if(idx != ((INSERT_SPLIT_ROOT_NREC * 50) - 3))
2166 TEST_ERROR
2167
2168 /* Close the v2 B-tree */
2169 if(H5B2_close(bt2, dxpl) < 0)
2170 FAIL_STACK_ERROR
2171 bt2 = NULL;
2172
2173 /* Close file */
2174 if(H5Fclose(file) < 0)
2175 TEST_ERROR
2176
2177 PASSED();
2178
2179 return 0;
2180
2181 error:
2182 H5E_BEGIN_TRY {
2183 if(bt2)
2184 H5B2_close(bt2, dxpl);
2185 H5Fclose(file);
2186 } H5E_END_TRY;
2187 return 1;
2188 } /* test_insert_level2_2internal_redistrib() */
2189
2190
2191 /*-------------------------------------------------------------------------
2192 * Function: test_insert_level2_2internal_split
2193 *
2194 * Purpose: Basic tests for the B-tree v2 code. This test inserts enough
2195 * records to make a level 2 B-tree and then adds enough more
2196 * records to force the left-most and right-most internal nodes to
2197 * split.
2198 *
2199 * Return: Success: 0
2200 *
2201 * Failure: 1
2202 *
2203 * Programmer: Quincey Koziol
2204 * Friday, February 18, 2005
2205 *
2206 *-------------------------------------------------------------------------
2207 */
2208 static unsigned
test_insert_level2_2internal_split(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)2209 test_insert_level2_2internal_split(hid_t fapl, const H5B2_create_t *cparam,
2210 const bt2_test_param_t *tparam)
2211 {
2212 hid_t file = -1; /* File ID */
2213 H5F_t *f = NULL; /* Internal file object pointer */
2214 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
2215 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
2216 haddr_t bt2_addr; /* Address of B-tree created */
2217 hsize_t record; /* Record to insert into tree */
2218 H5B2_stat_t bt2_stat; /* Statistics about B-tree created */
2219 hsize_t idx; /* Index within B-tree, for iterator */
2220 unsigned u; /* Local index variable */
2221
2222 /*
2223 * Test inserting many records into v2 B-tree
2224 */
2225 TESTING("B-tree insert: split side internal node to 2 in level 2 B-tree (r->l)");
2226
2227 /* Create the file for the test */
2228 if(create_file(&file, &f, fapl) < 0)
2229 TEST_ERROR
2230
2231 /* Create the v2 B-tree & get its address */
2232 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
2233 TEST_ERROR
2234
2235 /* Insert enough records to force root to split into 2 internal nodes */
2236 /* (And fill up two child internal nodes) */
2237 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC * 59); u++) {
2238 record = u + (INSERT_SPLIT_ROOT_NREC * 14) - (INSERT_SPLIT_ROOT_NREC / 4) + 3;
2239 if(H5B2_insert(bt2, dxpl, &record) < 0)
2240 FAIL_STACK_ERROR
2241 } /* end for */
2242
2243 /* Check up on B-tree */
2244 bt2_stat.depth = 2;
2245 bt2_stat.nrecords = INSERT_SPLIT_ROOT_NREC * 59;
2246 if(check_stats(bt2, &bt2_stat) < 0)
2247 TEST_ERROR
2248 record = 2759; /* Record in root node */
2249 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2250 TEST_ERROR
2251 record = 4555; /* Right-most record in right internal node */
2252 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
2253 TEST_ERROR
2254 record = 4586; /* Right-most record in right leaf node */
2255 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
2256 TEST_ERROR
2257
2258 /* Check for closing & re-opening the B-tree */
2259 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
2260 TEST_ERROR
2261
2262 /* Insert record to split right-most internal node */
2263 record = u + (INSERT_SPLIT_ROOT_NREC * 14) - (INSERT_SPLIT_ROOT_NREC / 4) + 3;
2264 if(H5B2_insert(bt2, dxpl, &record) < 0)
2265 FAIL_STACK_ERROR
2266
2267 /* Check up on B-tree */
2268 bt2_stat.depth = 2;
2269 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC * 59) + 1;
2270 if(check_stats(bt2, &bt2_stat) < 0)
2271 TEST_ERROR
2272 record = 2759; /* Left record in root node */
2273 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2274 TEST_ERROR
2275 record = 3704; /* Right record in root node */
2276 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2277 TEST_ERROR
2278 record = 4555; /* Right-most record in right internal node */
2279 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
2280 TEST_ERROR
2281 record = 4387; /* Right-most record in right leaf node */
2282 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
2283 TEST_ERROR
2284
2285 PASSED();
2286
2287 TESTING("B-tree insert: split side internal node to 2 in level 2 B-tree (l->2)");
2288
2289 /* Check for closing & re-opening the B-tree */
2290 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
2291 TEST_ERROR
2292
2293 /* Check up on B-tree */
2294 bt2_stat.depth = 2;
2295 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC * 59) + 1;
2296 if(check_stats(bt2, &bt2_stat) < 0)
2297 TEST_ERROR
2298 record = 2759; /* Left record in root node */
2299 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2300 TEST_ERROR
2301 record = 932; /* Left-most record in left internal node */
2302 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
2303 TEST_ERROR
2304 record = 870; /* Left-most record in left leaf node */
2305 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
2306 TEST_ERROR
2307
2308 /* Force left-most internal node to split */
2309 for(u = 0; u < ((INSERT_SPLIT_ROOT_NREC * 14) - (INSERT_SPLIT_ROOT_NREC / 4) + 3); u++) {
2310 record = u;
2311 if(H5B2_insert(bt2, dxpl, &record) < 0)
2312 FAIL_STACK_ERROR
2313 } /* end for */
2314
2315 /* Check up on B-tree */
2316 bt2_stat.depth = 2;
2317 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC * 73) - (INSERT_SPLIT_ROOT_NREC / 4) + 4;
2318 if(check_stats(bt2, &bt2_stat) < 0)
2319 TEST_ERROR
2320 record = 870; /* Left record in root node */
2321 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2322 TEST_ERROR
2323 record = 1814; /* Next-to-left-most record in root node */
2324 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2325 TEST_ERROR
2326 record = 61; /* Left-most record in left internal node */
2327 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
2328 TEST_ERROR
2329 record = 0; /* Left-most record in left leaf node */
2330 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
2331 TEST_ERROR
2332
2333 /* Check for closing & re-opening the B-tree */
2334 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
2335 TEST_ERROR
2336
2337 /* Iterate over B-tree to check records have been inserted correctly */
2338 idx = 0;
2339 if(H5B2_iterate(bt2, dxpl, iter_cb, &idx) < 0)
2340 FAIL_STACK_ERROR
2341
2342 /* Make certain that the index is correct */
2343 if(idx != ((INSERT_SPLIT_ROOT_NREC * 73) - (INSERT_SPLIT_ROOT_NREC / 4) + 4))
2344 TEST_ERROR
2345
2346 /* Close the v2 B-tree */
2347 if(H5B2_close(bt2, dxpl) < 0)
2348 FAIL_STACK_ERROR
2349 bt2 = NULL;
2350
2351 /* Close file */
2352 if(H5Fclose(file) < 0)
2353 STACK_ERROR
2354
2355 PASSED();
2356
2357 return 0;
2358
2359 error:
2360 H5E_BEGIN_TRY {
2361 if(bt2)
2362 H5B2_close(bt2, dxpl);
2363 H5Fclose(file);
2364 } H5E_END_TRY;
2365 return 1;
2366 } /* test_insert_level2_2internal_split() */
2367
2368
2369 /*-------------------------------------------------------------------------
2370 * Function: test_insert_level2_3internal_redistrib
2371 *
2372 * Purpose: Basic tests for the B-tree v2 code. This test inserts enough
2373 * records to make a level 2 B-tree and then adds enough more
2374 * records to force the left-most and right-most internal nodes to
2375 * split and more records to force a 3 node redistribution of the
2376 * internal nodes.
2377 *
2378 * Return: Success: 0
2379 *
2380 * Failure: 1
2381 *
2382 * Programmer: Quincey Koziol
2383 * Saturday, February 19, 2005
2384 *
2385 *-------------------------------------------------------------------------
2386 */
2387 static unsigned
test_insert_level2_3internal_redistrib(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)2388 test_insert_level2_3internal_redistrib(hid_t fapl, const H5B2_create_t *cparam,
2389 const bt2_test_param_t *tparam)
2390 {
2391 hid_t file = -1; /* File ID */
2392 H5F_t *f = NULL; /* Internal file object pointer */
2393 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
2394 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
2395 haddr_t bt2_addr; /* Address of B-tree created */
2396 hsize_t record; /* Record to insert into tree */
2397 H5B2_stat_t bt2_stat; /* Statistics about B-tree created */
2398 hsize_t idx; /* Index within B-tree, for iterator */
2399 unsigned u; /* Local index variable */
2400
2401 /*
2402 * Test inserting many records into v2 B-tree
2403 */
2404 TESTING("B-tree insert: redistrib 3 internals in level 2 B-tree");
2405
2406 /* Create the file for the test */
2407 if(create_file(&file, &f, fapl) < 0)
2408 TEST_ERROR
2409
2410 /* Create the v2 B-tree & get its address */
2411 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
2412 TEST_ERROR
2413
2414 /* Insert enough records to force root to split into 3 internal nodes */
2415 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC * 36); u++) {
2416 record = u;
2417 if(H5B2_insert(bt2, dxpl, &record) < 0)
2418 FAIL_STACK_ERROR
2419 } /* end for */
2420 for(; u < ((INSERT_SPLIT_ROOT_NREC * 59) + 1); u++) {
2421 record = u + (INSERT_SPLIT_ROOT_NREC * 13) + ((3 * INSERT_SPLIT_ROOT_NREC) / 4) + 3;
2422 if(H5B2_insert(bt2, dxpl, &record) < 0)
2423 FAIL_STACK_ERROR
2424 } /* end for */
2425
2426 /* Check up on B-tree */
2427 bt2_stat.depth = 2;
2428 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC * 59) + 1;
2429 if(check_stats(bt2, &bt2_stat) < 0)
2430 TEST_ERROR
2431 record = 1889; /* Left record in root node */
2432 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2433 TEST_ERROR
2434 record = 3703; /* Right record in root node */
2435 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2436 TEST_ERROR
2437 record = 2267; /* Record to left of insertion point in middle internal node */
2438 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
2439 TEST_ERROR
2440 record = 3199; /* Record to right of insertion point in middle internal node */
2441 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
2442 TEST_ERROR
2443 record = 3137; /* Record just above insertion point in leaf node */
2444 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
2445 TEST_ERROR
2446
2447 /* Check for closing & re-opening the B-tree */
2448 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
2449 TEST_ERROR
2450
2451 /* Insert records to fill up middle internal node */
2452 for(u = 0; u < ((INSERT_SPLIT_ROOT_NREC * 13) + ((3 * INSERT_SPLIT_ROOT_NREC) / 4) + 2); u++) {
2453 record = u + (INSERT_SPLIT_ROOT_NREC * 36);
2454 if(H5B2_insert(bt2, dxpl, &record) < 0)
2455 FAIL_STACK_ERROR
2456 } /* end for */
2457
2458 /* Check up on B-tree */
2459 bt2_stat.depth = 2;
2460 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC * 72) + ((3 * INSERT_SPLIT_ROOT_NREC) / 4) + 3;
2461 if(check_stats(bt2, &bt2_stat) < 0)
2462 TEST_ERROR
2463 record = 1889; /* Left record in root node */
2464 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2465 TEST_ERROR
2466 record = 3703; /* Right record in root node */
2467 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2468 TEST_ERROR
2469 record = 3104; /* Record to left of insertion point in middle internal node */
2470 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
2471 TEST_ERROR
2472 record = 3137; /* Record to right of insertion point in middle internal node */
2473 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
2474 TEST_ERROR
2475 record = 3135; /* Record just above insertion point in leaf node */
2476 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
2477 TEST_ERROR
2478
2479 /* Check for closing & re-opening the B-tree */
2480 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
2481 TEST_ERROR
2482
2483 /* Insert another record, forcing the middle internal node to redistribute */
2484 record = u + (INSERT_SPLIT_ROOT_NREC * 36);
2485 if(H5B2_insert(bt2, dxpl, &record) < 0)
2486 FAIL_STACK_ERROR
2487
2488 /* Check up on B-tree */
2489 bt2_stat.depth = 2;
2490 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC * 72) + ((3 * INSERT_SPLIT_ROOT_NREC) / 4) + 4;
2491 if(check_stats(bt2, &bt2_stat) < 0)
2492 TEST_ERROR
2493 record = 1574; /* Left record in root node */
2494 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2495 TEST_ERROR
2496 record = 3104; /* Right record in root node */
2497 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2498 TEST_ERROR
2499 #ifdef NONE
2500 record = 2862; /* Record to left of insertion point in right internal node (now) */
2501 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
2502 TEST_ERROR
2503 #endif /* NONE */
2504 record = 3137; /* Record to right of insertion point in right internal node (now) */
2505 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
2506 TEST_ERROR
2507 record = 3135; /* Record just above insertion point in leaf node */
2508 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
2509 TEST_ERROR
2510
2511 /* Check for closing & re-opening the B-tree */
2512 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
2513 TEST_ERROR
2514
2515 /* Iterate over B-tree to check records have been inserted correctly */
2516 idx = 0;
2517 if(H5B2_iterate(bt2, dxpl, iter_cb, &idx) < 0)
2518 FAIL_STACK_ERROR
2519
2520 /* Make certain that the index is correct */
2521 if(idx != ((INSERT_SPLIT_ROOT_NREC * 72) + ((3 * INSERT_SPLIT_ROOT_NREC) / 4) + 4))
2522 TEST_ERROR
2523
2524 /* Close the v2 B-tree */
2525 if(H5B2_close(bt2, dxpl) < 0)
2526 FAIL_STACK_ERROR
2527 bt2 = NULL;
2528
2529 /* Close file */
2530 if(H5Fclose(file) < 0)
2531 STACK_ERROR
2532
2533 PASSED();
2534
2535 return 0;
2536
2537 error:
2538 H5E_BEGIN_TRY {
2539 if(bt2)
2540 H5B2_close(bt2, dxpl);
2541 H5Fclose(file);
2542 } H5E_END_TRY;
2543 return 1;
2544 } /* test_insert_level2_3internal_redistrib() */
2545
2546
2547 /*-------------------------------------------------------------------------
2548 * Function: test_insert_level2_3internal_split
2549 *
2550 * Purpose: Basic tests for the B-tree v2 code. This test inserts enough
2551 * records to make a level 2 B-tree and then adds enough more
2552 * records to force the left-most and right-most internal nodes to
2553 * split and more records to force a 3->4 node split of the
2554 * internal nodes.
2555 *
2556 * Return: Success: 0
2557 *
2558 * Failure: 1
2559 *
2560 * Programmer: Quincey Koziol
2561 * Saturday, February 19, 2005
2562 *
2563 *-------------------------------------------------------------------------
2564 */
2565 static unsigned
test_insert_level2_3internal_split(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)2566 test_insert_level2_3internal_split(hid_t fapl, const H5B2_create_t *cparam,
2567 const bt2_test_param_t *tparam)
2568 {
2569 hid_t file = -1; /* File ID */
2570 H5F_t *f = NULL; /* Internal file object pointer */
2571 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
2572 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
2573 haddr_t bt2_addr; /* Address of B-tree created */
2574 hsize_t record; /* Record to insert into tree */
2575 H5B2_stat_t bt2_stat; /* Statistics about B-tree created */
2576 hsize_t idx; /* Index within B-tree, for iterator */
2577 unsigned u; /* Local index variable */
2578
2579 /*
2580 * Test inserting many records into v2 B-tree
2581 */
2582 TESTING("B-tree insert: split 3 internals to 4 in level 2 B-tree");
2583
2584 /* Create the file for the test */
2585 if(create_file(&file, &f, fapl) < 0)
2586 TEST_ERROR
2587
2588 /* Create the v2 B-tree & get its address */
2589 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
2590 TEST_ERROR
2591
2592 /* Insert enough records to force root to split into 3 internal nodes */
2593 /* (and fill right internal node) */
2594 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC * 31); u++) {
2595 record = u;
2596 if(H5B2_insert(bt2, dxpl, &record) < 0)
2597 FAIL_STACK_ERROR
2598 } /* end for */
2599 for(; u < (INSERT_SPLIT_ROOT_NREC * 74); u++) {
2600 record = u + ((INSERT_SPLIT_ROOT_NREC * 13) + ((3 * INSERT_SPLIT_ROOT_NREC) / 4) + 3);
2601 if(H5B2_insert(bt2, dxpl, &record) < 0)
2602 FAIL_STACK_ERROR
2603 } /* end for */
2604
2605 /* Check for closing & re-opening the B-tree */
2606 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
2607 TEST_ERROR
2608
2609 /* Check up on B-tree */
2610 bt2_stat.depth = 2;
2611 bt2_stat.nrecords = INSERT_SPLIT_ROOT_NREC * 74;
2612 if(check_stats(bt2, &bt2_stat) < 0)
2613 TEST_ERROR
2614 record = 1889; /* Left record in root node */
2615 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2616 TEST_ERROR
2617 record = 3703; /* Right record in root node */
2618 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2619 TEST_ERROR
2620 record = 1952; /* Record to left of insertion point in middle internal node */
2621 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
2622 TEST_ERROR
2623 record = 2884; /* Record to right of insertion point in middle internal node */
2624 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
2625 TEST_ERROR
2626 record = 2822; /* Record just after insertion point in leaf node */
2627 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
2628 TEST_ERROR
2629
2630 /* Insert records to fill up middle internal node */
2631 for(u = 0; u < ((INSERT_SPLIT_ROOT_NREC * 13) + ((3 * INSERT_SPLIT_ROOT_NREC) / 4) + 2); u++) {
2632 record = u + (INSERT_SPLIT_ROOT_NREC * 31);
2633 if(H5B2_insert(bt2, dxpl, &record) < 0)
2634 FAIL_STACK_ERROR
2635 } /* end for */
2636
2637 /* Check up on B-tree */
2638 bt2_stat.depth = 2;
2639 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC * 87) + ((3 * INSERT_SPLIT_ROOT_NREC) / 4) + 2;
2640 if(check_stats(bt2, &bt2_stat) < 0)
2641 TEST_ERROR
2642 record = 1889; /* Left record in root node */
2643 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2644 TEST_ERROR
2645 record = 3703; /* Right record in root node */
2646 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2647 TEST_ERROR
2648 record = 2789; /* Record to left of insertion point in middle internal node */
2649 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
2650 TEST_ERROR
2651 record = 2822; /* Record to right of insertion point in middle internal node */
2652 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
2653 TEST_ERROR
2654 record = 2823; /* Record just above insertion point in leaf node */
2655 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
2656 TEST_ERROR
2657
2658 /* Check for closing & re-opening the B-tree */
2659 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
2660 TEST_ERROR
2661
2662 /* Insert record to split middle internal node */
2663 record = u + (INSERT_SPLIT_ROOT_NREC * 31);
2664 if(H5B2_insert(bt2, dxpl, &record) < 0)
2665 FAIL_STACK_ERROR
2666
2667 /* Check up on B-tree */
2668 bt2_stat.depth = 2;
2669 bt2_stat.nrecords = (INSERT_SPLIT_ROOT_NREC * 87) + ((3 * INSERT_SPLIT_ROOT_NREC) / 4) + 3;
2670 if(check_stats(bt2, &bt2_stat) < 0)
2671 TEST_ERROR
2672 record = 1889; /* Left record in root node */
2673 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2674 TEST_ERROR
2675 record = 2789; /* Middle record in root node */
2676 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2677 TEST_ERROR
2678 record = 3703; /* Right record in root node */
2679 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
2680 TEST_ERROR
2681 #ifdef NONE
2682 record = 3049; /* Record to left of insertion point in middle internal node */
2683 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
2684 TEST_ERROR
2685 #endif /* NONE */
2686 record = 2822; /* Record to right of insertion point in middle internal node */
2687 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
2688 TEST_ERROR
2689 record = 2823; /* Record just above insertion point in leaf node */
2690 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
2691 TEST_ERROR
2692
2693 /* Check for closing & re-opening the B-tree */
2694 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
2695 TEST_ERROR
2696
2697 /* Iterate over B-tree to check records have been inserted correctly */
2698 idx = 0;
2699 if(H5B2_iterate(bt2, dxpl, iter_cb, &idx) < 0)
2700 FAIL_STACK_ERROR
2701
2702 /* Make certain that the index is correct */
2703 if(idx != ((INSERT_SPLIT_ROOT_NREC * 87) + ((3 * INSERT_SPLIT_ROOT_NREC) / 4) + 3))
2704 TEST_ERROR
2705
2706 /* Close the v2 B-tree */
2707 if(H5B2_close(bt2, dxpl) < 0)
2708 FAIL_STACK_ERROR
2709 bt2 = NULL;
2710
2711 /* Close file */
2712 if(H5Fclose(file) < 0)
2713 FAIL_STACK_ERROR
2714
2715 PASSED();
2716
2717 return 0;
2718
2719 error:
2720 H5E_BEGIN_TRY {
2721 if(bt2)
2722 H5B2_close(bt2, dxpl);
2723 H5Fclose(file);
2724 } H5E_END_TRY;
2725 return 1;
2726 } /* test_insert_level2_3internal_split() */
2727
2728
2729 /*-------------------------------------------------------------------------
2730 * Function: test_insert_lots
2731 *
2732 * Purpose: Basic tests for the B-tree v2 code. This test inserts many
2733 * records in random order, enough to make at a level 4 B-tree.
2734 *
2735 * Return: Success: 0
2736 *
2737 * Failure: 1
2738 *
2739 * Programmer: Quincey Koziol
2740 * Saturday, February 19, 2005
2741 *
2742 *-------------------------------------------------------------------------
2743 */
2744 static unsigned
test_insert_lots(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)2745 test_insert_lots(hid_t fapl, const H5B2_create_t *cparam,
2746 const bt2_test_param_t *tparam)
2747 {
2748 hid_t file = -1; /* File ID */
2749 char filename[1024]; /* Filename to use */
2750 H5F_t *f = NULL; /* Internal file object pointer */
2751 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
2752 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
2753 haddr_t bt2_addr; /* Address of B-tree created */
2754 hsize_t record; /* Record to insert into tree */
2755 hsize_t idx; /* Index within B-tree, for iterator */
2756 time_t curr_time; /* Current time, for seeding random number generator */
2757 hsize_t *records; /* Record #'s for random insertion */
2758 unsigned u; /* Local index variable */
2759 unsigned swap_idx; /* Location to swap with when shuffling */
2760 hsize_t temp_rec; /* Temporary record */
2761 H5B2_stat_t bt2_stat; /* Statistics about B-tree created */
2762 hsize_t nrec; /* Number of records in B-tree */
2763 herr_t ret; /* Generic error return value */
2764
2765 /* Initialize random number seed */
2766 curr_time=HDtime(NULL);
2767 #ifdef QAK
2768 curr_time=1109170019;
2769 HDfprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time);
2770 #endif /* QAK */
2771 HDsrandom((unsigned)curr_time);
2772
2773 /*
2774 * Test inserting many records into v2 B-tree
2775 */
2776 TESTING("B-tree insert: create random level 4 B-tree");
2777
2778 /* Allocate space for the records */
2779 if(NULL == (records = (hsize_t *)HDmalloc(sizeof(hsize_t) * INSERT_MANY)))
2780 TEST_ERROR
2781
2782 /* Initialize record #'s */
2783 for(u = 0; u < INSERT_MANY; u++)
2784 records[u] = u;
2785
2786 /* Shuffle record #'s */
2787 for(u = 0; u < INSERT_MANY; u++) {
2788 swap_idx = ((unsigned)HDrandom() % (INSERT_MANY - u)) + u;
2789 temp_rec = records[u];
2790 records[u] = records[swap_idx];
2791 records[swap_idx] = temp_rec;
2792 } /* end for */
2793
2794 /* Set the filename to use for this test (dependent on fapl) */
2795 h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));
2796
2797 /* Create the file to work on */
2798 if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
2799 TEST_ERROR
2800
2801 /* Get a pointer to the internal file object */
2802 if(NULL == (f = (H5F_t *)H5I_object(file)))
2803 STACK_ERROR
2804
2805 /* Create the v2 B-tree & get its address */
2806 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
2807 TEST_ERROR
2808
2809 /* Insert random records */
2810 for(u = 0; u < INSERT_MANY; u++) {
2811 record = records[u];
2812 if(H5B2_insert(bt2, dxpl, &record) < 0)
2813 FAIL_STACK_ERROR
2814 } /* end for */
2815
2816 /* Check up on B-tree */
2817 bt2_stat.depth = 4;
2818 bt2_stat.nrecords = INSERT_MANY;
2819 if(check_stats(bt2, &bt2_stat) < 0)
2820 TEST_ERROR
2821
2822 /* Close the v2 B-tree */
2823 if(H5B2_close(bt2, dxpl) < 0)
2824 FAIL_STACK_ERROR
2825 bt2 = NULL;
2826
2827 /* Close file */
2828 if(H5Fclose(file) < 0)
2829 STACK_ERROR
2830
2831 /* Re-open the file */
2832 if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
2833 FAIL_STACK_ERROR
2834
2835 /* Get a pointer to the internal file object */
2836 if(NULL == (f = (H5F_t *)H5I_object(file)))
2837 FAIL_STACK_ERROR
2838
2839 /* Re-open v2 B-tree */
2840 if(NULL == (bt2 = H5B2_open(f, dxpl, bt2_addr, f)))
2841 FAIL_STACK_ERROR
2842
2843 /* Check up on B-tree after re-open */
2844 bt2_stat.depth = 4;
2845 bt2_stat.nrecords = INSERT_MANY;
2846 if(check_stats(bt2, &bt2_stat) < 0)
2847 TEST_ERROR
2848
2849 /* Iterate over B-tree to check records have been inserted correctly */
2850 idx = 0;
2851 if(H5B2_iterate(bt2, dxpl, iter_cb, &idx) < 0)
2852 FAIL_STACK_ERROR
2853
2854 /* Make certain that the index is correct */
2855 if(idx != INSERT_MANY)
2856 TEST_ERROR
2857
2858 /* Attempt to find non-existant record in level-4 B-tree */
2859 /* (Should not be found, but not fail) */
2860 idx = INSERT_MANY * 2;
2861 if(H5B2_find(bt2, dxpl, &idx, find_cb, &idx) != FALSE)
2862 TEST_ERROR
2863
2864 /* Find random records */
2865 for(u = 0; u < FIND_MANY; u++) {
2866 /* Pick random record */
2867 idx = (hsize_t)(HDrandom()%INSERT_MANY);
2868
2869 /* Attempt to find existant record in root of level-4 B-tree */
2870 if(H5B2_find(bt2, dxpl, &idx, find_cb, &idx) != TRUE)
2871 FAIL_STACK_ERROR
2872 } /* end for */
2873
2874 /* Attempt to index non-existant record in level-4 B-tree, in increasing & decreasing order */
2875 H5E_BEGIN_TRY {
2876 ret = H5B2_index(bt2, dxpl, H5_ITER_INC, (hsize_t)(INSERT_MANY*3), find_cb, NULL);
2877 } H5E_END_TRY;
2878 /* Should fail */
2879 if(ret != FAIL)
2880 TEST_ERROR
2881 H5E_BEGIN_TRY {
2882 ret = H5B2_index(bt2, dxpl, H5_ITER_DEC, (hsize_t)(INSERT_MANY*3), find_cb, NULL);
2883 } H5E_END_TRY;
2884 /* Should fail */
2885 if(ret != FAIL)
2886 TEST_ERROR
2887
2888 /* Find random records */
2889 for(u = 0; u < FIND_MANY; u++) {
2890 /* Pick random record */
2891 idx = (hsize_t)(HDrandom() % INSERT_MANY);
2892
2893 /* Attempt to find existant record in root of level-4 B-tree */
2894 /* (in increasing order) */
2895 if(H5B2_index(bt2, dxpl, H5_ITER_INC, idx, find_cb, &idx) < 0)
2896 FAIL_STACK_ERROR
2897
2898 /* Attempt to find existant record in root of level-4 B-tree */
2899 /* (in decreasing order) */
2900 if(H5B2_index(bt2, dxpl, H5_ITER_DEC, idx, find_dec_cb, &idx) < 0)
2901 FAIL_STACK_ERROR
2902 } /* end for */
2903
2904 PASSED();
2905
2906 TESTING("B-tree insert: attempt duplicate record in level 4 B-tree");
2907
2908 /* Check for closing & re-opening the B-tree */
2909 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
2910 TEST_ERROR
2911
2912 record = INSERT_MANY / 2;
2913 H5E_BEGIN_TRY {
2914 ret = H5B2_insert(bt2, dxpl, &record);
2915 } H5E_END_TRY;
2916 /* Should fail */
2917 if(ret != FAIL)
2918 TEST_ERROR
2919
2920 /* Query the number of records in the B-tree */
2921 if(H5B2_get_nrec(bt2, &nrec) < 0)
2922 FAIL_STACK_ERROR
2923
2924 /* Make certain that the # of records is correct */
2925 if(nrec != INSERT_MANY)
2926 TEST_ERROR
2927
2928 /* Close the v2 B-tree */
2929 if(H5B2_close(bt2, dxpl) < 0)
2930 FAIL_STACK_ERROR
2931 bt2 = NULL;
2932
2933 /* Close file */
2934 if(H5Fclose(file) < 0)
2935 TEST_ERROR
2936
2937 PASSED();
2938
2939 HDfree(records);
2940
2941 return 0;
2942
2943 error:
2944 H5E_BEGIN_TRY {
2945 if(bt2)
2946 H5B2_close(bt2, dxpl);
2947 H5Fclose(file);
2948 } H5E_END_TRY;
2949 HDfree(records);
2950 return 1;
2951 } /* test_insert_lots() */
2952
2953
2954 /*-------------------------------------------------------------------------
2955 * Function: test_remove_basic
2956 *
2957 * Purpose: Basic tests for the B-tree v2 code
2958 *
2959 * Return: Success: 0
2960 * Failure: 1
2961 *
2962 * Programmer: Quincey Koziol
2963 * Friday, February 25, 2005
2964 *
2965 *-------------------------------------------------------------------------
2966 */
2967 static unsigned
test_remove_basic(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)2968 test_remove_basic(hid_t fapl, const H5B2_create_t *cparam,
2969 const bt2_test_param_t *tparam)
2970 {
2971 hid_t file = -1; /* File ID */
2972 H5F_t *f = NULL; /* Internal file object pointer */
2973 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
2974 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
2975 haddr_t bt2_addr; /* Address of B-tree created */
2976 hsize_t record; /* Record to insert into tree */
2977 hsize_t rrecord; /* Record to remove from tree */
2978 hsize_t nrec; /* Number of records in B-tree */
2979 haddr_t root_addr; /* Address of root of B-tree created */
2980 herr_t ret; /* Generic error return value */
2981
2982 /* Record removal tests */
2983 TESTING("B-tree remove: record from empty B-tree");
2984
2985 /* Create the file for the test */
2986 if(create_file(&file, &f, fapl) < 0)
2987 TEST_ERROR
2988
2989 /* Create the v2 B-tree & get its address */
2990 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
2991 TEST_ERROR
2992
2993 /* Query the number of records in the B-tree */
2994 if(H5B2_get_nrec(bt2, &nrec) < 0)
2995 FAIL_STACK_ERROR
2996
2997 /* Make certain that the # of records is correct */
2998 if(nrec != 0)
2999 TEST_ERROR
3000
3001 /* Attempt to remove a record from a B-tree with no records */
3002 record = 0;
3003 H5E_BEGIN_TRY {
3004 ret = H5B2_remove(bt2, dxpl, &record, NULL, NULL);
3005 } H5E_END_TRY;
3006 /* Should fail */
3007 if(ret != FAIL)
3008 TEST_ERROR
3009
3010 PASSED();
3011
3012 TESTING("B-tree remove: non-existant record from 1 record B-tree");
3013
3014 /* Check for closing & re-opening the B-tree */
3015 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
3016 TEST_ERROR
3017
3018 /* Insert one record into B-tree */
3019 record = 42;
3020 if(H5B2_insert(bt2, dxpl, &record) < 0)
3021 FAIL_STACK_ERROR
3022
3023 /* Query the number of records in the B-tree */
3024 if(H5B2_get_nrec(bt2, &nrec) < 0)
3025 FAIL_STACK_ERROR
3026
3027 /* Make certain that the # of records is correct */
3028 if(nrec != 1)
3029 TEST_ERROR
3030
3031 /* Query the address of the root node in the B-tree */
3032 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
3033 FAIL_STACK_ERROR
3034
3035 /* Make certain that the address of the root node is defined */
3036 if(!H5F_addr_defined(root_addr))
3037 TEST_ERROR
3038
3039 /* Attempt to remove a non-existant record from a B-tree with 1 record */
3040 record = 0;
3041 H5E_BEGIN_TRY {
3042 ret = H5B2_remove(bt2, dxpl, &record, NULL, NULL);
3043 } H5E_END_TRY;
3044 /* Should fail */
3045 if(ret != FAIL)
3046 TEST_ERROR
3047
3048 PASSED();
3049
3050 /* Attempt to remove a record from a B-tree with 1 record */
3051 TESTING("B-tree remove: existant record from 1 record B-tree");
3052
3053 /* Check for closing & re-opening the B-tree */
3054 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
3055 TEST_ERROR
3056
3057 record = 42;
3058 rrecord = 0;
3059 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
3060 FAIL_STACK_ERROR
3061
3062 /* Make certain that the record value is correct */
3063 if(rrecord != 42)
3064 TEST_ERROR
3065
3066 /* Query the number of records in the B-tree */
3067 if(H5B2_get_nrec(bt2, &nrec) < 0)
3068 FAIL_STACK_ERROR
3069
3070 /* Make certain that the # of records is correct */
3071 if(nrec != 0)
3072 TEST_ERROR
3073
3074 /* Query the address of the root node in the B-tree */
3075 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
3076 FAIL_STACK_ERROR
3077
3078 /* Make certain that the root node has been freed */
3079 if(H5F_addr_defined(root_addr))
3080 TEST_ERROR
3081
3082 PASSED();
3083
3084 /* Attempt to insert records into B-tree which had records removed */
3085 TESTING("B-tree remove: adding records to B-tree after removal");
3086
3087 /* Check for closing & re-opening the B-tree */
3088 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
3089 TEST_ERROR
3090
3091 /* Insert several records into B-tree again */
3092 record = 42;
3093 if(H5B2_insert(bt2, dxpl, &record) < 0)
3094 FAIL_STACK_ERROR
3095 record = 34;
3096 if(H5B2_insert(bt2, dxpl, &record) < 0)
3097 FAIL_STACK_ERROR
3098 record = 56;
3099 if(H5B2_insert(bt2, dxpl, &record) < 0)
3100 FAIL_STACK_ERROR
3101 record = 38;
3102 if(H5B2_insert(bt2, dxpl, &record) < 0)
3103 FAIL_STACK_ERROR
3104
3105 /* Query the number of records in the B-tree */
3106 if(H5B2_get_nrec(bt2, &nrec) < 0)
3107 FAIL_STACK_ERROR
3108
3109 /* Make certain that the # of records is correct */
3110 if(nrec != 4)
3111 TEST_ERROR
3112
3113 PASSED();
3114
3115 /* Attempt to remove a non-existant record from a level-0 B-tree with mult. record */
3116 TESTING("B-tree remove: non-existant record from level-0 B-tree");
3117
3118 /* Check for closing & re-opening the B-tree */
3119 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
3120 TEST_ERROR
3121
3122 record = 0;
3123 H5E_BEGIN_TRY {
3124 ret = H5B2_remove(bt2, dxpl, &record, NULL, NULL);
3125 } H5E_END_TRY;
3126 /* Should fail */
3127 if(ret != FAIL)
3128 TEST_ERROR
3129
3130 PASSED();
3131
3132 /* Attempt to remove a record from a level-0 B-tree with mult. record */
3133 TESTING("B-tree remove: mult. existant records from level-0 B-tree");
3134
3135 /* Check for closing & re-opening the B-tree */
3136 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
3137 TEST_ERROR
3138
3139 record = 42;
3140 rrecord = 0;
3141 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
3142 FAIL_STACK_ERROR
3143
3144 /* Make certain that the record value is correct */
3145 if(rrecord != 42)
3146 TEST_ERROR
3147
3148 /* Query the number of records in the B-tree */
3149 if(H5B2_get_nrec(bt2, &nrec) < 0)
3150 FAIL_STACK_ERROR
3151
3152 /* Make certain that the # of records is correct */
3153 if(nrec != 3)
3154 TEST_ERROR
3155
3156 /* Query the address of the root node in the B-tree */
3157 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
3158 FAIL_STACK_ERROR
3159
3160 /* Make certain that the root node has not been freed */
3161 if(!H5F_addr_defined(root_addr))
3162 TEST_ERROR
3163
3164 record = 34;
3165 rrecord = 0;
3166 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
3167 FAIL_STACK_ERROR
3168
3169 /* Make certain that the record value is correct */
3170 if(rrecord != 34)
3171 TEST_ERROR
3172
3173 /* Query the number of records in the B-tree */
3174 if(H5B2_get_nrec(bt2, &nrec) < 0)
3175 FAIL_STACK_ERROR
3176
3177 /* Make certain that the # of records is correct */
3178 if(nrec != 2)
3179 TEST_ERROR
3180
3181 /* Query the address of the root node in the B-tree */
3182 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
3183 FAIL_STACK_ERROR
3184
3185 /* Make certain that the root node has not been freed */
3186 if(!H5F_addr_defined(root_addr))
3187 TEST_ERROR
3188
3189 record = 56;
3190 rrecord = 0;
3191 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
3192 FAIL_STACK_ERROR
3193
3194 /* Make certain that the record value is correct */
3195 if(rrecord != 56)
3196 TEST_ERROR
3197
3198 /* Query the number of records in the B-tree */
3199 if(H5B2_get_nrec(bt2, &nrec) < 0)
3200 FAIL_STACK_ERROR
3201
3202 /* Make certain that the # of records is correct */
3203 if(nrec != 1)
3204 TEST_ERROR
3205
3206 /* Query the address of the root node in the B-tree */
3207 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
3208 FAIL_STACK_ERROR
3209
3210 /* Make certain that the root node has not been freed */
3211 if(!H5F_addr_defined(root_addr))
3212 TEST_ERROR
3213
3214 record = 38;
3215 rrecord = 0;
3216 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
3217 FAIL_STACK_ERROR
3218
3219 /* Make certain that the record value is correct */
3220 if(rrecord != 38)
3221 TEST_ERROR
3222
3223 /* Query the number of records in the B-tree */
3224 if(H5B2_get_nrec(bt2, &nrec) < 0)
3225 FAIL_STACK_ERROR
3226
3227 /* Make certain that the # of records is correct */
3228 if(nrec != 0)
3229 TEST_ERROR
3230
3231 /* Query the address of the root node in the B-tree */
3232 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
3233 FAIL_STACK_ERROR
3234
3235 /* Make certain that the root node has been freed */
3236 if(H5F_addr_defined(root_addr))
3237 TEST_ERROR
3238
3239 /* Close the v2 B-tree */
3240 if(H5B2_close(bt2, dxpl) < 0)
3241 FAIL_STACK_ERROR
3242 bt2 = NULL;
3243
3244 /* Close file */
3245 if(H5Fclose(file) < 0)
3246 FAIL_STACK_ERROR
3247
3248 PASSED();
3249
3250 return 0;
3251
3252 error:
3253 H5E_BEGIN_TRY {
3254 if(bt2)
3255 H5B2_close(bt2, dxpl);
3256 H5Fclose(file);
3257 } H5E_END_TRY;
3258 return 1;
3259 } /* test_remove_basic() */
3260
3261
3262 /*-------------------------------------------------------------------------
3263 * Function: test_remove_level1_noredistrib
3264 *
3265 * Purpose: Basic tests for the B-tree v2 code
3266 *
3267 * Return: Success: 0
3268 * Failure: 1
3269 *
3270 * Programmer: Quincey Koziol
3271 * Friday, February 25, 2005
3272 *
3273 *-------------------------------------------------------------------------
3274 */
3275 static unsigned
test_remove_level1_noredistrib(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)3276 test_remove_level1_noredistrib(hid_t fapl, const H5B2_create_t *cparam,
3277 const bt2_test_param_t *tparam)
3278 {
3279 hid_t file = -1; /* File ID */
3280 H5F_t *f = NULL; /* Internal file object pointer */
3281 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
3282 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
3283 haddr_t bt2_addr; /* Address of B-tree created */
3284 hsize_t record; /* Record to insert into tree */
3285 hsize_t rrecord; /* Record to remove from tree */
3286 hsize_t nrec; /* Number of records in B-tree */
3287 haddr_t root_addr; /* Address of root of B-tree created */
3288 unsigned u; /* Local index variable */
3289 herr_t ret; /* Generic error return value */
3290
3291 /* B-tree record removal tests */
3292 TESTING("B-tree remove: non-existant record from level-1 B-tree");
3293
3294 /* Create the file for the test */
3295 if(create_file(&file, &f, fapl) < 0)
3296 TEST_ERROR
3297
3298 /* Create the v2 B-tree & get its address */
3299 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
3300 TEST_ERROR
3301
3302 /* Create level-1 B-tree with 3 leaves */
3303 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC * 2); u++) {
3304 record = u;
3305 if(H5B2_insert(bt2, dxpl, &record) < 0)
3306 FAIL_STACK_ERROR
3307 } /* end for */
3308
3309 /* Query the number of records in the B-tree */
3310 if(H5B2_get_nrec(bt2, &nrec) < 0)
3311 FAIL_STACK_ERROR
3312
3313 /* Make certain that the # of records is correct */
3314 if(nrec != (INSERT_SPLIT_ROOT_NREC * 2))
3315 TEST_ERROR
3316
3317 /* Query the address of the root node in the B-tree */
3318 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
3319 FAIL_STACK_ERROR
3320
3321 /* Make certain that the address of the root node is defined */
3322 if(!H5F_addr_defined(root_addr))
3323 TEST_ERROR
3324
3325 /* Attempt to remove a non-existant record from a B-tree with 1 record */
3326 record = (INSERT_SPLIT_ROOT_NREC * 2) + 1;
3327 H5E_BEGIN_TRY {
3328 ret = H5B2_remove(bt2, dxpl, &record, NULL, NULL);
3329 } H5E_END_TRY;
3330 /* Should fail */
3331 if(ret != FAIL)
3332 TEST_ERROR
3333
3334 /* Query the number of records in the B-tree */
3335 if(H5B2_get_nrec(bt2, &nrec) < 0)
3336 FAIL_STACK_ERROR
3337
3338 /* Make certain that the # of records is correct */
3339 if(nrec != (INSERT_SPLIT_ROOT_NREC*2))
3340 TEST_ERROR
3341
3342 PASSED();
3343
3344 /* Attempt to remove a record from right leaf of a level-1 B-tree with noredistribution */
3345 TESTING("B-tree remove: record from right leaf of level-1 B-tree");
3346
3347 /* Check for closing & re-opening the B-tree */
3348 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
3349 TEST_ERROR
3350
3351 /* Check up on B-tree */
3352 record = 62; /* Left record in root node */
3353 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
3354 TEST_ERROR
3355 record = 94; /* Right record in root node */
3356 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
3357 TEST_ERROR
3358 record = (INSERT_SPLIT_ROOT_NREC * 2) - 2;
3359 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
3360 TEST_ERROR
3361
3362 rrecord = 0;
3363 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
3364 FAIL_STACK_ERROR
3365
3366 /* Make certain that the record value is correct */
3367 if(rrecord != ((INSERT_SPLIT_ROOT_NREC * 2) - 2))
3368 TEST_ERROR
3369
3370 /* Make certain that the leaf nodes didn't redistribute */
3371 record = 62; /* Left record in root node */
3372 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
3373 TEST_ERROR
3374 record = 94; /* Right record in root node */
3375 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
3376 TEST_ERROR
3377
3378 /* Query the number of records in the B-tree */
3379 if(H5B2_get_nrec(bt2, &nrec) < 0)
3380 FAIL_STACK_ERROR
3381
3382 /* Make certain that the # of records is correct */
3383 if(nrec != ((INSERT_SPLIT_ROOT_NREC * 2) - 1))
3384 TEST_ERROR
3385
3386 PASSED();
3387
3388 /* Attempt to remove a record from left leaf of a level-1 B-tree with noredistribution */
3389 TESTING("B-tree remove: record from left leaf of level-1 B-tree");
3390
3391 /* Check for closing & re-opening the B-tree */
3392 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
3393 TEST_ERROR
3394
3395 /* Check up on B-tree */
3396 record = 0;
3397 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
3398 TEST_ERROR
3399
3400 rrecord = 1;
3401 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
3402 FAIL_STACK_ERROR
3403
3404 /* Make certain that the record value is correct */
3405 if(rrecord != 0)
3406 TEST_ERROR
3407
3408 /* Make certain that the leaf nodes didn't redistribute */
3409 record = 62; /* Left record in root node */
3410 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
3411 TEST_ERROR
3412 record = 94; /* Right record in root node */
3413 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
3414 TEST_ERROR
3415
3416 /* Query the number of records in the B-tree */
3417 if(H5B2_get_nrec(bt2, &nrec) < 0)
3418 FAIL_STACK_ERROR
3419
3420 /* Make certain that the # of records is correct */
3421 if(nrec != ((INSERT_SPLIT_ROOT_NREC * 2) - 2))
3422 TEST_ERROR
3423
3424 PASSED();
3425
3426 /* Attempt to remove a record from middle leaf of a level-1 B-tree with noredistribution */
3427 TESTING("B-tree remove: record from middle leaf of level-1 B-tree");
3428
3429 /* Check for closing & re-opening the B-tree */
3430 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
3431 TEST_ERROR
3432
3433 /* Check up on B-tree */
3434 record = INSERT_SPLIT_ROOT_NREC;
3435 if(check_node_depth(bt2, dxpl, record, (unsigned)0) < 0)
3436 TEST_ERROR
3437
3438 rrecord = 0;
3439 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
3440 FAIL_STACK_ERROR
3441
3442 /* Make certain that the record value is correct */
3443 if(rrecord != INSERT_SPLIT_ROOT_NREC)
3444 TEST_ERROR
3445
3446 /* Make certain that the leaf nodes didn't redistribute */
3447 record = 62; /* Left record in root node */
3448 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
3449 TEST_ERROR
3450 record = 94; /* Right record in root node */
3451 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
3452 TEST_ERROR
3453
3454 /* Query the number of records in the B-tree */
3455 if(H5B2_get_nrec(bt2, &nrec) < 0)
3456 FAIL_STACK_ERROR
3457
3458 /* Make certain that the # of records is correct */
3459 if(nrec != ((INSERT_SPLIT_ROOT_NREC * 2) - 3))
3460 TEST_ERROR
3461
3462 /* Close the v2 B-tree */
3463 if(H5B2_close(bt2, dxpl) < 0)
3464 FAIL_STACK_ERROR
3465 bt2 = NULL;
3466
3467 /* Close file */
3468 if(H5Fclose(file) < 0)
3469 FAIL_STACK_ERROR
3470
3471 PASSED();
3472
3473 return 0;
3474
3475 error:
3476 H5E_BEGIN_TRY {
3477 if(bt2)
3478 H5B2_close(bt2, dxpl);
3479 H5Fclose(file);
3480 } H5E_END_TRY;
3481 return 1;
3482 } /* test_remove_level1_noredistrib() */
3483
3484
3485 /*-------------------------------------------------------------------------
3486 * Function: test_remove_level1_redistrib
3487 *
3488 * Purpose: Basic tests for the B-tree v2 code
3489 *
3490 * Return: Success: 0
3491 * Failure: 1
3492 *
3493 * Programmer: Quincey Koziol
3494 * Friday, March 4, 2005
3495 *
3496 *-------------------------------------------------------------------------
3497 */
3498 static unsigned
test_remove_level1_redistrib(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)3499 test_remove_level1_redistrib(hid_t fapl, const H5B2_create_t *cparam,
3500 const bt2_test_param_t *tparam)
3501 {
3502 hid_t file = -1; /* File ID */
3503 H5F_t *f = NULL; /* Internal file object pointer */
3504 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
3505 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
3506 haddr_t bt2_addr; /* Address of B-tree created */
3507 hsize_t record; /* Record to insert into tree */
3508 hsize_t rrecord; /* Record to remove from tree */
3509 hsize_t nrec; /* Number of records in B-tree */
3510 haddr_t root_addr; /* Address of root of B-tree created */
3511 unsigned u; /* Local index variable */
3512
3513 /* More complex record removals */
3514 TESTING("B-tree remove: redistribute 2 leaves in level-1 B-tree (r->l)");
3515
3516 /* Create the file for the test */
3517 if(create_file(&file, &f, fapl) < 0)
3518 TEST_ERROR
3519
3520 /* Create the v2 B-tree & get its address */
3521 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
3522 TEST_ERROR
3523
3524 /* Create level-1 B-tree with 3 leaves */
3525 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC * 2); u++) {
3526 record = u;
3527 if(H5B2_insert(bt2, dxpl, &record) < 0)
3528 FAIL_STACK_ERROR
3529 } /* end for */
3530
3531 /* Check record values in root of B-tree */
3532 record = 62; /* Left record in root node */
3533 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
3534 TEST_ERROR
3535 record = 94; /* Right record in root node */
3536 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
3537 TEST_ERROR
3538
3539 /* Query the number of records in the B-tree */
3540 if(H5B2_get_nrec(bt2, &nrec) < 0)
3541 FAIL_STACK_ERROR
3542
3543 /* Make certain that the # of records is correct */
3544 if(nrec != (INSERT_SPLIT_ROOT_NREC * 2))
3545 TEST_ERROR
3546
3547 /* Query the address of the root node in the B-tree */
3548 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
3549 FAIL_STACK_ERROR
3550
3551 /* Make certain that the address of the root node is defined */
3552 if(!H5F_addr_defined(root_addr))
3553 TEST_ERROR
3554
3555 /* Check for closing & re-opening the B-tree */
3556 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
3557 TEST_ERROR
3558
3559 /* Attempt to remove enough records from right leaf of a level-1 B-tree to force redistribution */
3560 for(u = 0; u < 8; u++) {
3561 record = (INSERT_SPLIT_ROOT_NREC * 2) - (u + 1);
3562 rrecord = HSIZET_MAX;
3563 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
3564 FAIL_STACK_ERROR
3565
3566 /* Make certain that the record value is correct */
3567 if(rrecord != ((INSERT_SPLIT_ROOT_NREC * 2) - (u + 1)))
3568 TEST_ERROR
3569
3570 /* Query the number of records in the B-tree */
3571 if(H5B2_get_nrec(bt2, &nrec) < 0)
3572 FAIL_STACK_ERROR
3573
3574 /* Make certain that the # of records is correct */
3575 if(nrec != ((INSERT_SPLIT_ROOT_NREC * 2) - (u + 1)))
3576 TEST_ERROR
3577 } /* end for */
3578
3579 /* Check record values in root of B-tree */
3580 record = 62; /* Left record in root node */
3581 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
3582 TEST_ERROR
3583 record = 90; /* Right record in root node */
3584 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
3585 TEST_ERROR
3586
3587 PASSED();
3588
3589 /* Attempt to remove enough records from left leaf of a level-1 B-tree to force redistribution */
3590 TESTING("B-tree remove: redistribute 2 leaves in level-1 B-tree (l->r)");
3591
3592 /* Check for closing & re-opening the B-tree */
3593 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
3594 TEST_ERROR
3595
3596 for(u = 0; u < 39; u++) {
3597 record = u;
3598 rrecord = HSIZET_MAX;
3599 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
3600 FAIL_STACK_ERROR
3601
3602 /* Make certain that the record value is correct */
3603 if(rrecord != u)
3604 TEST_ERROR
3605
3606 /* Query the number of records in the B-tree */
3607 if(H5B2_get_nrec(bt2, &nrec) < 0)
3608 FAIL_STACK_ERROR
3609
3610 /* Make certain that the # of records is correct */
3611 if(nrec != (((INSERT_SPLIT_ROOT_NREC * 2) - 8) - (u + 1)))
3612 TEST_ERROR
3613 } /* end for */
3614
3615 /* Check record values in root of B-tree */
3616 record = 64; /* Left record in root node */
3617 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
3618 TEST_ERROR
3619 record = 90; /* Right record in root node */
3620 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
3621 TEST_ERROR
3622
3623 PASSED();
3624
3625 /* Attempt to remove enough records from middle leaf of a level-1 B-tree to force redistribution */
3626 TESTING("B-tree remove: redistribute 3 leaves in level-1 B-tree");
3627
3628 /* Check for closing & re-opening the B-tree */
3629 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
3630 TEST_ERROR
3631
3632 for(u = 0; u < 2; u++) {
3633 record = INSERT_SPLIT_ROOT_NREC + 2 + u;
3634 rrecord = HSIZET_MAX;
3635 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
3636 FAIL_STACK_ERROR
3637
3638 /* Make certain that the record value is correct */
3639 if(rrecord != (INSERT_SPLIT_ROOT_NREC + 2 + u))
3640 TEST_ERROR
3641
3642 /* Query the number of records in the B-tree */
3643 if(H5B2_get_nrec(bt2, &nrec) < 0)
3644 FAIL_STACK_ERROR
3645
3646 /* Make certain that the # of records is correct */
3647 if(nrec != ((((INSERT_SPLIT_ROOT_NREC * 2) - 47)) - (u + 1)))
3648 TEST_ERROR
3649 } /* end for */
3650
3651 /* Check record values in root of B-tree */
3652 record = 64; /* Left record in root node */
3653 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
3654 TEST_ERROR
3655 record = 91; /* Right record in root node */
3656 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
3657 TEST_ERROR
3658
3659 /* Close the v2 B-tree */
3660 if(H5B2_close(bt2, dxpl) < 0)
3661 FAIL_STACK_ERROR
3662 bt2 = NULL;
3663
3664 /* Close file */
3665 if(H5Fclose(file) < 0)
3666 TEST_ERROR
3667
3668 PASSED();
3669
3670 return 0;
3671
3672 error:
3673 H5E_BEGIN_TRY {
3674 if(bt2)
3675 H5B2_close(bt2, dxpl);
3676 H5Fclose(file);
3677 } H5E_END_TRY;
3678 return 1;
3679 } /* test_remove_level1_redistrib() */
3680
3681
3682 /*-------------------------------------------------------------------------
3683 * Function: test_remove_level1_2leaf_merge
3684 *
3685 * Purpose: Basic tests for the B-tree v2 code
3686 *
3687 * Return: Success: 0
3688 * Failure: 1
3689 *
3690 * Programmer: Quincey Koziol
3691 * Friday, March 4, 2005
3692 *
3693 *-------------------------------------------------------------------------
3694 */
3695 static unsigned
test_remove_level1_2leaf_merge(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)3696 test_remove_level1_2leaf_merge(hid_t fapl, const H5B2_create_t *cparam,
3697 const bt2_test_param_t *tparam)
3698 {
3699 hid_t file = -1; /* File ID */
3700 H5F_t *f = NULL; /* Internal file object pointer */
3701 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
3702 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
3703 haddr_t bt2_addr; /* Address of B-tree created */
3704 hsize_t record; /* Record to insert into tree */
3705 hsize_t rrecord; /* Record to remove from tree */
3706 hsize_t nrec; /* Number of records in B-tree */
3707 haddr_t root_addr; /* Address of root of B-tree created */
3708 H5B2_node_info_test_t ninfo; /* B-tree node info */
3709 unsigned u; /* Local index variable */
3710
3711 TESTING("B-tree remove: merge 2 leaves to 1 in level-1 B-tree (r->l)");
3712
3713 /* Create the file for the test */
3714 if(create_file(&file, &f, fapl) < 0)
3715 TEST_ERROR
3716
3717 /* Create the v2 B-tree & get its address */
3718 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
3719 TEST_ERROR
3720
3721 /* Create level-1 B-tree with 3 leaves */
3722 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC * 2); u++) {
3723 record = u;
3724 if(H5B2_insert(bt2, dxpl, &record) < 0)
3725 FAIL_STACK_ERROR
3726 } /* end for */
3727
3728 /* Check record values in root of B-tree */
3729 record = 62; /* Left record in root node */
3730 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
3731 TEST_ERROR
3732 ninfo.depth = 1;
3733 ninfo.nrec = 2;
3734 record = 94; /* Right record in root node */
3735 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
3736 TEST_ERROR
3737
3738 /* Query the number of records in the B-tree */
3739 if(H5B2_get_nrec(bt2, &nrec) < 0)
3740 FAIL_STACK_ERROR
3741
3742 /* Make certain that the # of records is correct */
3743 if(nrec != (INSERT_SPLIT_ROOT_NREC * 2))
3744 TEST_ERROR
3745
3746 /* Query the address of the root node in the B-tree */
3747 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
3748 FAIL_STACK_ERROR
3749
3750 /* Make certain that the address of the root node is defined */
3751 if(!H5F_addr_defined(root_addr))
3752 TEST_ERROR
3753
3754 /* Check for closing & re-opening the B-tree */
3755 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
3756 TEST_ERROR
3757
3758 /* Attempt to remove enough records from right leaf of a level-1 B-tree to force redistribution */
3759 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC / 4); u++) {
3760 record = (INSERT_SPLIT_ROOT_NREC * 2) - (u + 1);
3761 rrecord = HSIZET_MAX;
3762 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
3763 FAIL_STACK_ERROR
3764
3765 /* Make certain that the record value is correct */
3766 if(rrecord != ((INSERT_SPLIT_ROOT_NREC * 2) - (u + 1)))
3767 TEST_ERROR
3768
3769 /* Query the number of records in the B-tree */
3770 if(H5B2_get_nrec(bt2, &nrec) < 0)
3771 FAIL_STACK_ERROR
3772
3773 /* Make certain that the # of records is correct */
3774 if(nrec != ((INSERT_SPLIT_ROOT_NREC * 2) - (u + 1)))
3775 TEST_ERROR
3776 } /* end for */
3777
3778 /* Check record values in root of B-tree */
3779 ninfo.depth = 1;
3780 ninfo.nrec = 1;
3781 record = 62; /* Left record in root node */
3782 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
3783 TEST_ERROR
3784
3785 PASSED();
3786
3787 /* Attempt to remove enough records from left leaf of a level-1 B-tree to force redistribution */
3788 TESTING("B-tree remove: merge 2 leaves to 1 in level-1 B-tree (l->r)");
3789
3790 /* Check for closing & re-opening the B-tree */
3791 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
3792 TEST_ERROR
3793
3794 /* Fill B-tree back up */
3795 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC / 4); u++) {
3796 record = (INSERT_SPLIT_ROOT_NREC * 2) - (u + 1);
3797 if(H5B2_insert(bt2, dxpl, &record) < 0)
3798 FAIL_STACK_ERROR
3799 } /* end for */
3800
3801 /* Check record values in root of B-tree */
3802 record = 62; /* Left record in root node */
3803 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
3804 TEST_ERROR
3805 ninfo.depth = 1;
3806 ninfo.nrec = 2;
3807 record = 94; /* Right record in root node */
3808 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
3809 TEST_ERROR
3810
3811 /* Remove records */
3812 for(u = 0; u < ((3 * INSERT_SPLIT_ROOT_NREC) / 4) - 1; u++) {
3813 record = u;
3814 rrecord = HSIZET_MAX;
3815 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
3816 FAIL_STACK_ERROR
3817
3818 /* Make certain that the record value is correct */
3819 if(rrecord != u)
3820 TEST_ERROR
3821
3822 /* Query the number of records in the B-tree */
3823 if(H5B2_get_nrec(bt2, &nrec) < 0)
3824 FAIL_STACK_ERROR
3825
3826 /* Make certain that the # of records is correct */
3827 if(nrec != ((INSERT_SPLIT_ROOT_NREC * 2) - (u + 1)))
3828 TEST_ERROR
3829 } /* end for */
3830
3831 /* Check record values in root of B-tree */
3832 ninfo.depth = 1;
3833 ninfo.nrec = 1;
3834 record = 94; /* Left record in root node */
3835 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
3836 TEST_ERROR
3837
3838 /* Close the v2 B-tree */
3839 if(H5B2_close(bt2, dxpl) < 0)
3840 FAIL_STACK_ERROR
3841 bt2 = NULL;
3842
3843 /* Close file */
3844 if(H5Fclose(file) < 0)
3845 TEST_ERROR
3846
3847 PASSED();
3848
3849 return 0;
3850
3851 error:
3852 H5E_BEGIN_TRY {
3853 if(bt2)
3854 H5B2_close(bt2, dxpl);
3855 H5Fclose(file);
3856 } H5E_END_TRY;
3857 return 1;
3858 } /* test_remove_level1_2leaf_merge() */
3859
3860
3861 /*-------------------------------------------------------------------------
3862 * Function: test_remove_level1_3leaf_merge
3863 *
3864 * Purpose: Basic tests for the B-tree v2 code
3865 *
3866 * Return: Success: 0
3867 * Failure: 1
3868 *
3869 * Programmer: Quincey Koziol
3870 * Friday, March 4, 2005
3871 *
3872 *-------------------------------------------------------------------------
3873 */
3874 static unsigned
test_remove_level1_3leaf_merge(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)3875 test_remove_level1_3leaf_merge(hid_t fapl, const H5B2_create_t *cparam,
3876 const bt2_test_param_t *tparam)
3877 {
3878 hid_t file = -1; /* File ID */
3879 H5F_t *f = NULL; /* Internal file object pointer */
3880 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
3881 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
3882 haddr_t bt2_addr; /* Address of B-tree created */
3883 hsize_t record; /* Record to insert into tree */
3884 hsize_t rrecord; /* Record to remove from tree */
3885 hsize_t nrec; /* Number of records in B-tree */
3886 haddr_t root_addr; /* Address of root of B-tree created */
3887 H5B2_node_info_test_t ninfo; /* B-tree node info */
3888 unsigned u; /* Local index variable */
3889
3890 TESTING("B-tree remove: merge 3 leaves to 2 in level-1 B-tree");
3891
3892 /* Create the file for the test */
3893 if(create_file(&file, &f, fapl) < 0)
3894 TEST_ERROR
3895
3896 /* Create the v2 B-tree & get its address */
3897 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
3898 TEST_ERROR
3899
3900 /* Create level-1 B-tree with 3 leaves */
3901 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC * 2); u++) {
3902 record = u;
3903 if(H5B2_insert(bt2, dxpl, &record) < 0)
3904 FAIL_STACK_ERROR
3905 } /* end for */
3906
3907 /* Check record values in root of B-tree */
3908 record = 62; /* Left record in root node */
3909 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
3910 TEST_ERROR
3911 ninfo.depth = 1;
3912 ninfo.nrec = 2;
3913 record = 94; /* Right record in root node */
3914 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
3915 TEST_ERROR
3916
3917 /* Query the number of records in the B-tree */
3918 if(H5B2_get_nrec(bt2, &nrec) < 0)
3919 FAIL_STACK_ERROR
3920
3921 /* Make certain that the # of records is correct */
3922 if(nrec != (INSERT_SPLIT_ROOT_NREC * 2))
3923 TEST_ERROR
3924
3925 /* Query the address of the root node in the B-tree */
3926 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
3927 FAIL_STACK_ERROR
3928
3929 /* Make certain that the address of the root node is defined */
3930 if(!H5F_addr_defined(root_addr))
3931 TEST_ERROR
3932
3933 /* Check for closing & re-opening the B-tree */
3934 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
3935 TEST_ERROR
3936
3937 /* Attempt to remove enough records from middle leaf of a level-1 B-tree to force merge */
3938 for(u = 0; u < ((5 * INSERT_SPLIT_ROOT_NREC) / 6) - 1; u++) {
3939 record = ((3 * INSERT_SPLIT_ROOT_NREC) / 2) - (u + 1);
3940 rrecord = HSIZET_MAX;
3941 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
3942 FAIL_STACK_ERROR
3943
3944 /* Make certain that the record value is correct */
3945 if(rrecord != (((3 * INSERT_SPLIT_ROOT_NREC) / 2) - (u + 1)))
3946 TEST_ERROR
3947
3948 /* Query the number of records in the B-tree */
3949 if(H5B2_get_nrec(bt2, &nrec) < 0)
3950 FAIL_STACK_ERROR
3951
3952 /* Make certain that the # of records is correct */
3953 if(nrec != ((INSERT_SPLIT_ROOT_NREC * 2) - (u + 1)))
3954 TEST_ERROR
3955 } /* end for */
3956
3957 /* Check record values in root of B-tree */
3958 ninfo.depth = 1;
3959 ninfo.nrec = 1;
3960 record = 37; /* Only record in root node */
3961 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
3962 TEST_ERROR
3963
3964 /* Close the v2 B-tree */
3965 if(H5B2_close(bt2, dxpl) < 0)
3966 FAIL_STACK_ERROR
3967 bt2 = NULL;
3968
3969 /* Close file */
3970 if(H5Fclose(file) < 0)
3971 TEST_ERROR
3972
3973 PASSED();
3974
3975 return 0;
3976
3977 error:
3978 H5E_BEGIN_TRY {
3979 if(bt2)
3980 H5B2_close(bt2, dxpl);
3981 H5Fclose(file);
3982 } H5E_END_TRY;
3983 return 1;
3984 } /* test_remove_level1_3leaf_merge() */
3985
3986
3987 /*-------------------------------------------------------------------------
3988 * Function: test_remove_level1_promote
3989 *
3990 * Purpose: Basic tests for the B-tree v2 code
3991 *
3992 * Return: Success: 0
3993 * Failure: 1
3994 *
3995 * Programmer: Quincey Koziol
3996 * Friday, March 4, 2005
3997 *
3998 *-------------------------------------------------------------------------
3999 */
4000 static unsigned
test_remove_level1_promote(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)4001 test_remove_level1_promote(hid_t fapl, const H5B2_create_t *cparam,
4002 const bt2_test_param_t *tparam)
4003 {
4004 hid_t file = -1; /* File ID */
4005 H5F_t *f = NULL; /* Internal file object pointer */
4006 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
4007 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
4008 haddr_t bt2_addr; /* Address of B-tree created */
4009 hsize_t record; /* Record to insert into tree */
4010 hsize_t rrecord; /* Record to remove from tree */
4011 hsize_t nrec; /* Number of records in B-tree */
4012 haddr_t root_addr; /* Address of root of B-tree created */
4013 H5B2_node_info_test_t ninfo; /* B-tree node info */
4014 unsigned u; /* Local index variable */
4015
4016 TESTING("B-tree remove: promote from right leaf of level-1 B-tree");
4017
4018 /* Create the file for the test */
4019 if(create_file(&file, &f, fapl) < 0)
4020 TEST_ERROR
4021
4022 /* Create the v2 B-tree & get its address */
4023 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
4024 TEST_ERROR
4025
4026 /* Create level-1 B-tree with 5 leaves */
4027 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC * 4); u++) {
4028 record = u;
4029 if(H5B2_insert(bt2, dxpl, &record) < 0)
4030 FAIL_STACK_ERROR
4031 } /* end for */
4032
4033 /* Check record values in root of B-tree */
4034 record = 62; /* Left-most record in root node */
4035 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
4036 TEST_ERROR
4037 record = 125; /* Center-Left record in root node */
4038 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
4039 TEST_ERROR
4040 record = 188; /* Center-Right record in root node */
4041 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
4042 TEST_ERROR
4043 ninfo.depth = 1;
4044 ninfo.nrec = 4;
4045 record = 220; /* Right-most record in root node */
4046 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
4047 TEST_ERROR
4048
4049 /* Query the number of records in the B-tree */
4050 if(H5B2_get_nrec(bt2, &nrec) < 0)
4051 FAIL_STACK_ERROR
4052
4053 /* Make certain that the # of records is correct */
4054 if(nrec != (INSERT_SPLIT_ROOT_NREC * 4))
4055 TEST_ERROR
4056
4057 /* Query the address of the root node in the B-tree */
4058 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
4059 FAIL_STACK_ERROR
4060
4061 /* Make certain that the address of the root node is defined */
4062 if(!H5F_addr_defined(root_addr))
4063 TEST_ERROR
4064
4065 /* Check for closing & re-opening the B-tree */
4066 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
4067 TEST_ERROR
4068
4069 /* Attempt to remove record from root node of a level-1 B-tree to force promotion from right leaf */
4070 record = 220;
4071 rrecord = HSIZET_MAX;
4072 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
4073 FAIL_STACK_ERROR
4074
4075 /* Make certain that the record value is correct */
4076 if(rrecord != 220)
4077 TEST_ERROR
4078
4079 /* Check record values in root of B-tree */
4080 record = 62; /* Left-most record in root node */
4081 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
4082 TEST_ERROR
4083 record = 125; /* Center-Left record in root node */
4084 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
4085 TEST_ERROR
4086 record = 188; /* Center-Right record in root node */
4087 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
4088 TEST_ERROR
4089 ninfo.depth = 1;
4090 ninfo.nrec = 4;
4091 record = 221; /* Right-most record in root node */
4092 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
4093 TEST_ERROR
4094
4095 /* Query the number of records in the B-tree */
4096 if(H5B2_get_nrec(bt2, &nrec) < 0)
4097 FAIL_STACK_ERROR
4098
4099 /* Make certain that the # of records is correct */
4100 if(nrec != (INSERT_SPLIT_ROOT_NREC * 4) - 1)
4101 TEST_ERROR
4102
4103 PASSED();
4104
4105 /* Attempt to remove record from root node of a level-1 B-tree to force promotion from left leaf */
4106 /* (Note: current algorithm doesn't actually ever promote from left leaf.
4107 * It would be useful to update the B-tree routines to always choose
4108 * to promote a record from the node with more children. - QAK)
4109 */
4110 TESTING("B-tree remove: promote from left leaf of level-1 B-tree");
4111
4112 /* Check for closing & re-opening the B-tree */
4113 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
4114 TEST_ERROR
4115
4116 record = 62;
4117 rrecord = HSIZET_MAX;
4118 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
4119 FAIL_STACK_ERROR
4120
4121 /* Make certain that the record value is correct */
4122 if(rrecord != 62)
4123 TEST_ERROR
4124
4125 /* Check record values in root of B-tree */
4126 record = 63; /* Left-most record in root node */
4127 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
4128 TEST_ERROR
4129 record = 125; /* Center-Left record in root node */
4130 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
4131 TEST_ERROR
4132 record = 188; /* Center-Right record in root node */
4133 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
4134 TEST_ERROR
4135 ninfo.depth = 1;
4136 ninfo.nrec = 4;
4137 record = 221; /* Right-most record in root node */
4138 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
4139 TEST_ERROR
4140
4141 /* Query the number of records in the B-tree */
4142 if(H5B2_get_nrec(bt2, &nrec) < 0)
4143 FAIL_STACK_ERROR
4144
4145 /* Make certain that the # of records is correct */
4146 if(nrec != (INSERT_SPLIT_ROOT_NREC * 4) - 2)
4147 TEST_ERROR
4148
4149 PASSED();
4150
4151 /* Attempt to remove record from root node of a level-1 B-tree to force promotion from middle leaf */
4152 TESTING("B-tree remove: promote from middle leaf of level-1 B-tree");
4153
4154 /* Check for closing & re-opening the B-tree */
4155 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
4156 TEST_ERROR
4157
4158 record = 125;
4159 rrecord = HSIZET_MAX;
4160 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
4161 FAIL_STACK_ERROR
4162
4163 /* Make certain that the record value is correct */
4164 if(rrecord != 125)
4165 TEST_ERROR
4166
4167 /* Check record values in root of B-tree */
4168 record = 63; /* Left-most record in root node */
4169 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
4170 TEST_ERROR
4171 record = 126; /* Center-Left record in root node */
4172 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
4173 TEST_ERROR
4174 record = 188; /* Center-Right record in root node */
4175 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
4176 TEST_ERROR
4177 ninfo.depth = 1;
4178 ninfo.nrec = 4;
4179 record = 221; /* Right-most record in root node */
4180 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
4181 TEST_ERROR
4182
4183 /* Query the number of records in the B-tree */
4184 if(H5B2_get_nrec(bt2, &nrec) < 0)
4185 FAIL_STACK_ERROR
4186
4187 /* Make certain that the # of records is correct */
4188 if(nrec != (INSERT_SPLIT_ROOT_NREC * 4) - 3)
4189 TEST_ERROR
4190
4191 /* Close the v2 B-tree */
4192 if(H5B2_close(bt2, dxpl) < 0)
4193 FAIL_STACK_ERROR
4194 bt2 = NULL;
4195
4196 /* Close file */
4197 if(H5Fclose(file) < 0)
4198 TEST_ERROR
4199
4200 PASSED();
4201
4202 return 0;
4203
4204 error:
4205 H5E_BEGIN_TRY {
4206 if(bt2)
4207 H5B2_close(bt2, dxpl);
4208 H5Fclose(file);
4209 } H5E_END_TRY;
4210 return 1;
4211 } /* test_remove_level1_promote() */
4212
4213
4214 /*-------------------------------------------------------------------------
4215 * Function: test_remove_level1_promote_2leaf_redistrib
4216 *
4217 * Purpose: Basic tests for the B-tree v2 code
4218 *
4219 * Return: Success: 0
4220 * Failure: 1
4221 *
4222 * Programmer: Quincey Koziol
4223 * Friday, March 4, 2005
4224 *
4225 *-------------------------------------------------------------------------
4226 */
4227 static unsigned
test_remove_level1_promote_2leaf_redistrib(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)4228 test_remove_level1_promote_2leaf_redistrib(hid_t fapl, const H5B2_create_t *cparam,
4229 const bt2_test_param_t *tparam)
4230 {
4231 hid_t file = -1; /* File ID */
4232 H5F_t *f = NULL; /* Internal file object pointer */
4233 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
4234 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
4235 haddr_t bt2_addr; /* Address of B-tree created */
4236 hsize_t record; /* Record to insert into tree */
4237 hsize_t rrecord; /* Record to remove from tree */
4238 hsize_t nrec; /* Number of records in B-tree */
4239 haddr_t root_addr; /* Address of root of B-tree created */
4240 H5B2_node_info_test_t ninfo; /* B-tree node info */
4241 unsigned u; /* Local index variable */
4242
4243 TESTING("B-tree remove: promote from leaf of level-1 B-tree w/2 node redistrib");
4244
4245 /* Create the file for the test */
4246 if(create_file(&file, &f, fapl) < 0)
4247 TEST_ERROR
4248
4249 /* Create the v2 B-tree & get its address */
4250 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
4251 TEST_ERROR
4252
4253 /* Create level-1 B-tree with 3 leaves */
4254 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC * 2); u++) {
4255 record = u;
4256 if(H5B2_insert(bt2, dxpl, &record) < 0)
4257 FAIL_STACK_ERROR
4258 } /* end for */
4259
4260 /* Check record values in root of B-tree */
4261 record = 62; /* Left-most record in root node */
4262 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
4263 TEST_ERROR
4264 ninfo.depth = 1;
4265 ninfo.nrec = 2;
4266 record = 94; /* Right record in root node */
4267 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
4268 TEST_ERROR
4269
4270 /* Query the number of records in the B-tree */
4271 if(H5B2_get_nrec(bt2, &nrec) < 0)
4272 FAIL_STACK_ERROR
4273
4274 /* Make certain that the # of records is correct */
4275 if(nrec != (INSERT_SPLIT_ROOT_NREC * 2))
4276 TEST_ERROR
4277
4278 /* Query the address of the root node in the B-tree */
4279 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
4280 FAIL_STACK_ERROR
4281
4282 /* Make certain that the address of the root node is defined */
4283 if(!H5F_addr_defined(root_addr))
4284 TEST_ERROR
4285
4286 /* Check for closing & re-opening the B-tree */
4287 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
4288 TEST_ERROR
4289
4290 /* Attempt to remove record from root node of a level-1 B-tree to force promotion from right leaf */
4291
4292 /* Remove records from right leaf until its ready to redistribute */
4293 for(u = 0; u < 7; u++) {
4294 record = (INSERT_SPLIT_ROOT_NREC * 2) - (u + 1);
4295 rrecord = HSIZET_MAX;
4296 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
4297 FAIL_STACK_ERROR
4298
4299 /* Make certain that the record value is correct */
4300 if(rrecord != ((INSERT_SPLIT_ROOT_NREC * 2) - (u + 1)))
4301 TEST_ERROR
4302
4303 /* Query the number of records in the B-tree */
4304 if(H5B2_get_nrec(bt2, &nrec) < 0)
4305 FAIL_STACK_ERROR
4306
4307 /* Make certain that the # of records is correct */
4308 if(nrec != ((INSERT_SPLIT_ROOT_NREC * 2) - (u + 1)))
4309 TEST_ERROR
4310 } /* end for */
4311
4312 record = 94;
4313 rrecord = HSIZET_MAX;
4314 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
4315 FAIL_STACK_ERROR
4316
4317 /* Make certain that the record value is correct */
4318 if(rrecord != 94)
4319 TEST_ERROR
4320
4321 /* Check record values in root of B-tree */
4322 record = 62; /* Left-most record in root node */
4323 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
4324 TEST_ERROR
4325 ninfo.depth = 1;
4326 ninfo.nrec = 2;
4327 record = 90; /* Right record in root node */
4328 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
4329 TEST_ERROR
4330
4331 /* Query the number of records in the B-tree */
4332 if(H5B2_get_nrec(bt2, &nrec) < 0)
4333 FAIL_STACK_ERROR
4334
4335 /* Make certain that the # of records is correct */
4336 if(nrec != (INSERT_SPLIT_ROOT_NREC * 2) - 8)
4337 TEST_ERROR
4338
4339 /* Close the v2 B-tree */
4340 if(H5B2_close(bt2, dxpl) < 0)
4341 FAIL_STACK_ERROR
4342 bt2 = NULL;
4343
4344 /* Close file */
4345 if(H5Fclose(file) < 0)
4346 TEST_ERROR
4347
4348 PASSED();
4349
4350 return 0;
4351
4352 error:
4353 H5E_BEGIN_TRY {
4354 if(bt2)
4355 H5B2_close(bt2, dxpl);
4356 H5Fclose(file);
4357 } H5E_END_TRY;
4358 return 1;
4359 } /* test_remove_level1_promote_2leaf_redistrib() */
4360
4361
4362 /*-------------------------------------------------------------------------
4363 * Function: test_remove_level1_promote_3leaf_redistrib
4364 *
4365 * Purpose: Basic tests for the B-tree v2 code
4366 *
4367 * Return: Success: 0
4368 * Failure: 1
4369 *
4370 * Programmer: Quincey Koziol
4371 * Friday, March 4, 2005
4372 *
4373 *-------------------------------------------------------------------------
4374 */
4375 static unsigned
test_remove_level1_promote_3leaf_redistrib(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)4376 test_remove_level1_promote_3leaf_redistrib(hid_t fapl, const H5B2_create_t *cparam,
4377 const bt2_test_param_t *tparam)
4378 {
4379 hid_t file = -1; /* File ID */
4380 H5F_t *f = NULL; /* Internal file object pointer */
4381 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
4382 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
4383 haddr_t bt2_addr; /* Address of B-tree created */
4384 hsize_t record; /* Record to insert into tree */
4385 hsize_t rrecord; /* Record to remove from tree */
4386 hsize_t nrec; /* Number of records in B-tree */
4387 haddr_t root_addr; /* Address of root of B-tree created */
4388 H5B2_node_info_test_t ninfo; /* B-tree node info */
4389 unsigned u; /* Local index variable */
4390
4391 TESTING("B-tree remove: promote from leaf of level-1 B-tree w/3 node redistrib");
4392
4393 /* Create the file for the test */
4394 if(create_file(&file, &f, fapl) < 0)
4395 TEST_ERROR
4396
4397 /* Create the v2 B-tree & get its address */
4398 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
4399 TEST_ERROR
4400
4401 /* Create level-1 B-tree with 3 leaves */
4402 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC * 2); u++) {
4403 record = u;
4404 if(H5B2_insert(bt2, dxpl, &record) < 0)
4405 FAIL_STACK_ERROR
4406 } /* end for */
4407
4408 /* Check record values in root of B-tree */
4409 record = 62; /* Left-most record in root node */
4410 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
4411 TEST_ERROR
4412 ninfo.depth = 1;
4413 ninfo.nrec = 2;
4414 record = 94; /* Right record in root node */
4415 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
4416 TEST_ERROR
4417
4418 /* Query the number of records in the B-tree */
4419 if(H5B2_get_nrec(bt2, &nrec) < 0)
4420 FAIL_STACK_ERROR
4421
4422 /* Make certain that the # of records is correct */
4423 if(nrec != (INSERT_SPLIT_ROOT_NREC * 2))
4424 TEST_ERROR
4425
4426 /* Query the address of the root node in the B-tree */
4427 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
4428 FAIL_STACK_ERROR
4429
4430 /* Make certain that the address of the root node is defined */
4431 if(!H5F_addr_defined(root_addr))
4432 TEST_ERROR
4433
4434 /* Check for closing & re-opening the B-tree */
4435 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
4436 TEST_ERROR
4437
4438 /* Attempt to remove record from root node of a level-1 B-tree to force promotion from middle leaf */
4439
4440 /* Remove records from right leaf until its ready to redistribute */
4441 for(u = 0; u < 7; u++) {
4442 record = 63 + u;
4443 rrecord = HSIZET_MAX;
4444 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
4445 FAIL_STACK_ERROR
4446
4447 /* Make certain that the record value is correct */
4448 if(rrecord != (63 + u))
4449 TEST_ERROR
4450
4451 /* Query the number of records in the B-tree */
4452 if(H5B2_get_nrec(bt2, &nrec) < 0)
4453 FAIL_STACK_ERROR
4454
4455 /* Make certain that the # of records is correct */
4456 if(nrec != ((INSERT_SPLIT_ROOT_NREC * 2) - (u + 1)))
4457 TEST_ERROR
4458 } /* end for */
4459
4460 record = 62;
4461 rrecord = HSIZET_MAX;
4462 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
4463 FAIL_STACK_ERROR
4464
4465 /* Make certain that the record value is correct */
4466 if(rrecord != 62)
4467 TEST_ERROR
4468
4469 /* Check record values in root of B-tree */
4470 record = 39; /* Left record in root node */
4471 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
4472 TEST_ERROR
4473 ninfo.depth = 1;
4474 ninfo.nrec = 2;
4475 record = 86; /* Right record in root node */
4476 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
4477 TEST_ERROR
4478
4479 /* Query the number of records in the B-tree */
4480 if(H5B2_get_nrec(bt2, &nrec) < 0)
4481 FAIL_STACK_ERROR
4482
4483 /* Make certain that the # of records is correct */
4484 if(nrec != (INSERT_SPLIT_ROOT_NREC * 2) - 8)
4485 TEST_ERROR
4486
4487 /* Close the v2 B-tree */
4488 if(H5B2_close(bt2, dxpl) < 0)
4489 FAIL_STACK_ERROR
4490 bt2 = NULL;
4491
4492 /* Close file */
4493 if(H5Fclose(file) < 0)
4494 TEST_ERROR
4495
4496 PASSED();
4497
4498 return 0;
4499
4500 error:
4501 H5E_BEGIN_TRY {
4502 if(bt2)
4503 H5B2_close(bt2, dxpl);
4504 H5Fclose(file);
4505 } H5E_END_TRY;
4506 return 1;
4507 } /* test_remove_level1_promote_3leaf_redistrib() */
4508
4509
4510 /*-------------------------------------------------------------------------
4511 * Function: test_remove_level1_promote_2leaf_merge
4512 *
4513 * Purpose: Basic tests for the B-tree v2 code
4514 *
4515 * Return: Success: 0
4516 * Failure: 1
4517 *
4518 * Programmer: Quincey Koziol
4519 * Friday, March 4, 2005
4520 *
4521 *-------------------------------------------------------------------------
4522 */
4523 static unsigned
test_remove_level1_promote_2leaf_merge(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)4524 test_remove_level1_promote_2leaf_merge(hid_t fapl, const H5B2_create_t *cparam,
4525 const bt2_test_param_t *tparam)
4526 {
4527 hid_t file = -1; /* File ID */
4528 H5F_t *f = NULL; /* Internal file object pointer */
4529 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
4530 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
4531 haddr_t bt2_addr; /* Address of B-tree created */
4532 hsize_t record; /* Record to insert into tree */
4533 hsize_t rrecord; /* Record to remove from tree */
4534 hsize_t nrec; /* Number of records in B-tree */
4535 haddr_t root_addr; /* Address of root of B-tree created */
4536 H5B2_node_info_test_t ninfo; /* B-tree node info */
4537 unsigned u; /* Local index variable */
4538
4539 TESTING("B-tree remove: promote from leaf of level-1 B-tree w/2->1 merge");
4540
4541 /* Create the file for the test */
4542 if(create_file(&file, &f, fapl) < 0)
4543 TEST_ERROR
4544
4545 /* Create the v2 B-tree & get its address */
4546 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
4547 TEST_ERROR
4548
4549 /* Create level-1 B-tree with 3 leaves */
4550 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC * 2); u++) {
4551 record = u;
4552 if(H5B2_insert(bt2, dxpl, &record) < 0)
4553 FAIL_STACK_ERROR
4554 } /* end for */
4555
4556 /* Check record values in root of B-tree */
4557 record = 62; /* Left-most record in root node */
4558 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
4559 TEST_ERROR
4560 ninfo.depth = 1;
4561 ninfo.nrec = 2;
4562 record = 94; /* Right record in root node */
4563 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
4564 TEST_ERROR
4565
4566 /* Query the number of records in the B-tree */
4567 if(H5B2_get_nrec(bt2, &nrec) < 0)
4568 FAIL_STACK_ERROR
4569
4570 /* Make certain that the # of records is correct */
4571 if(nrec != (INSERT_SPLIT_ROOT_NREC * 2))
4572 TEST_ERROR
4573
4574 /* Query the address of the root node in the B-tree */
4575 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
4576 FAIL_STACK_ERROR
4577
4578 /* Make certain that the address of the root node is defined */
4579 if(!H5F_addr_defined(root_addr))
4580 TEST_ERROR
4581
4582 /* Check for closing & re-opening the B-tree */
4583 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
4584 TEST_ERROR
4585
4586 /* Attempt to remove record from root node of a level-1 B-tree to force promotion from right leaf */
4587
4588 /* Remove records from right leaf until its ready to merge */
4589 for(u = 0; u < 14; u++) {
4590 record = (INSERT_SPLIT_ROOT_NREC * 2) - (u + 1);
4591 rrecord = HSIZET_MAX;
4592 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
4593 FAIL_STACK_ERROR
4594
4595 /* Make certain that the record value is correct */
4596 if(rrecord != ((INSERT_SPLIT_ROOT_NREC * 2) - (u + 1)))
4597 TEST_ERROR
4598
4599 /* Query the number of records in the B-tree */
4600 if(H5B2_get_nrec(bt2, &nrec) < 0)
4601 FAIL_STACK_ERROR
4602
4603 /* Make certain that the # of records is correct */
4604 if(nrec != ((INSERT_SPLIT_ROOT_NREC * 2) - (u + 1)))
4605 TEST_ERROR
4606 } /* end for */
4607
4608 record = 87;
4609 rrecord = HSIZET_MAX;
4610 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
4611 FAIL_STACK_ERROR
4612
4613 /* Make certain that the record value is correct */
4614 if(rrecord != 87)
4615 TEST_ERROR
4616
4617 /* Check record values in root of B-tree */
4618 ninfo.depth = 1;
4619 ninfo.nrec = 1;
4620 record = 62; /* Middle record in root node */
4621 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
4622 TEST_ERROR
4623
4624 /* Query the number of records in the B-tree */
4625 if(H5B2_get_nrec(bt2, &nrec) < 0)
4626 FAIL_STACK_ERROR
4627
4628 /* Make certain that the # of records is correct */
4629 if(nrec != (INSERT_SPLIT_ROOT_NREC * 2) - 15)
4630 TEST_ERROR
4631
4632 /* Close the v2 B-tree */
4633 if(H5B2_close(bt2, dxpl) < 0)
4634 FAIL_STACK_ERROR
4635 bt2 = NULL;
4636
4637 /* Close file */
4638 if(H5Fclose(file) < 0)
4639 TEST_ERROR
4640
4641 PASSED();
4642
4643 return 0;
4644
4645 error:
4646 H5E_BEGIN_TRY {
4647 if(bt2)
4648 H5B2_close(bt2, dxpl);
4649 H5Fclose(file);
4650 } H5E_END_TRY;
4651 return 1;
4652 } /* test_remove_level1_promote_2leaf_merge() */
4653
4654
4655 /*-------------------------------------------------------------------------
4656 * Function: test_remove_level1_promote_3leaf_merge
4657 *
4658 * Purpose: Basic tests for the B-tree v2 code
4659 *
4660 * Return: Success: 0
4661 * Failure: 1
4662 *
4663 * Programmer: Quincey Koziol
4664 * Friday, March 4, 2005
4665 *
4666 *-------------------------------------------------------------------------
4667 */
4668 static unsigned
test_remove_level1_promote_3leaf_merge(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)4669 test_remove_level1_promote_3leaf_merge(hid_t fapl, const H5B2_create_t *cparam,
4670 const bt2_test_param_t *tparam)
4671 {
4672 hid_t file = -1; /* File ID */
4673 H5F_t *f = NULL; /* Internal file object pointer */
4674 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
4675 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
4676 haddr_t bt2_addr; /* Address of B-tree created */
4677 hsize_t record; /* Record to insert into tree */
4678 hsize_t rrecord; /* Record to remove from tree */
4679 hsize_t nrec; /* Number of records in B-tree */
4680 haddr_t root_addr; /* Address of root of B-tree created */
4681 H5B2_node_info_test_t ninfo; /* B-tree node info */
4682 unsigned u; /* Local index variable */
4683
4684 TESTING("B-tree remove: promote from leaf of level-1 B-tree w/3->2 merge");
4685
4686 /* Create the file for the test */
4687 if(create_file(&file, &f, fapl) < 0)
4688 TEST_ERROR
4689
4690 /* Create the v2 B-tree & get its address */
4691 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
4692 TEST_ERROR
4693
4694 /* Create level-2 B-tree with 3 leaves */
4695 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC * 2); u++) {
4696 record = u;
4697 if(H5B2_insert(bt2, dxpl, &record) < 0)
4698 FAIL_STACK_ERROR
4699 } /* end for */
4700
4701 /* Check record values in root of B-tree */
4702 record = 62; /* Left-most record in root node */
4703 if(check_node_depth(bt2, dxpl, record, (unsigned)1) < 0)
4704 TEST_ERROR
4705 ninfo.depth = 1;
4706 ninfo.nrec = 2;
4707 record = 94; /* Right record in root node */
4708 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
4709 TEST_ERROR
4710
4711 /* Query the number of records in the B-tree */
4712 if(H5B2_get_nrec(bt2, &nrec) < 0)
4713 FAIL_STACK_ERROR
4714
4715 /* Make certain that the # of records is correct */
4716 if(nrec != (INSERT_SPLIT_ROOT_NREC * 2))
4717 TEST_ERROR
4718
4719 /* Query the address of the root node in the B-tree */
4720 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
4721 FAIL_STACK_ERROR
4722
4723 /* Make certain that the address of the root node is defined */
4724 if(!H5F_addr_defined(root_addr))
4725 TEST_ERROR
4726
4727 /* Check for closing & re-opening the B-tree */
4728 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
4729 TEST_ERROR
4730
4731 /* Attempt to remove record from root node of a level-1 B-tree to force promotion from middle leaf */
4732
4733 /* Remove records from middle leaf until it's ready to merge */
4734 for(u = 0; u < 50; u++) {
4735 record = ((3 * INSERT_SPLIT_ROOT_NREC) / 2) - (u + 1);
4736 rrecord = HSIZET_MAX;
4737 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
4738 FAIL_STACK_ERROR
4739
4740 /* Make certain that the record value is correct */
4741 if(rrecord != (((3 * INSERT_SPLIT_ROOT_NREC) / 2) - (u + 1)))
4742 TEST_ERROR
4743
4744 /* Query the number of records in the B-tree */
4745 if(H5B2_get_nrec(bt2, &nrec) < 0)
4746 FAIL_STACK_ERROR
4747
4748 /* Make certain that the # of records is correct */
4749 if(nrec != ((INSERT_SPLIT_ROOT_NREC * 2) - (u + 1)))
4750 TEST_ERROR
4751 } /* end for */
4752
4753 record = 25;
4754 rrecord = HSIZET_MAX;
4755 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
4756 FAIL_STACK_ERROR
4757
4758 /* Make certain that the record value is correct */
4759 if(rrecord != 25)
4760 TEST_ERROR
4761
4762 /* Check record values in root of B-tree */
4763 ninfo.depth = 1;
4764 ninfo.nrec = 1;
4765 record = 37; /* Right record in root node */
4766 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
4767 TEST_ERROR
4768
4769 /* Query the number of records in the B-tree */
4770 if(H5B2_get_nrec(bt2, &nrec) < 0)
4771 FAIL_STACK_ERROR
4772
4773 /* Make certain that the # of records is correct */
4774 if(nrec != (INSERT_SPLIT_ROOT_NREC * 2) - 51)
4775 TEST_ERROR
4776
4777 /* Close the v2 B-tree */
4778 if(H5B2_close(bt2, dxpl) < 0)
4779 FAIL_STACK_ERROR
4780 bt2 = NULL;
4781
4782 /* Close file */
4783 if(H5Fclose(file) < 0)
4784 TEST_ERROR
4785
4786 PASSED();
4787
4788 return 0;
4789
4790 error:
4791 H5E_BEGIN_TRY {
4792 if(bt2)
4793 H5B2_close(bt2, dxpl);
4794 H5Fclose(file);
4795 } H5E_END_TRY;
4796 return 1;
4797 } /* test_remove_level1_promote_3leaf_merge() */
4798
4799
4800 /*-------------------------------------------------------------------------
4801 * Function: test_remove_level1_collapse
4802 *
4803 * Purpose: Basic tests for the B-tree v2 code
4804 *
4805 * Return: Success: 0
4806 * Failure: 1
4807 *
4808 * Programmer: Quincey Koziol
4809 * Friday, March 4, 2005
4810 *
4811 *-------------------------------------------------------------------------
4812 */
4813 static unsigned
test_remove_level1_collapse(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)4814 test_remove_level1_collapse(hid_t fapl, const H5B2_create_t *cparam,
4815 const bt2_test_param_t *tparam)
4816 {
4817 hid_t file = -1; /* File ID */
4818 H5F_t *f = NULL; /* Internal file object pointer */
4819 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
4820 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
4821 haddr_t bt2_addr; /* Address of B-tree created */
4822 hsize_t record; /* Record to insert into tree */
4823 hsize_t rrecord; /* Record to remove from tree */
4824 hsize_t nrec; /* Number of records in B-tree */
4825 haddr_t root_addr; /* Address of root of B-tree created */
4826 H5B2_node_info_test_t ninfo; /* B-tree node info */
4827 unsigned u; /* Local index variable */
4828
4829 TESTING("B-tree remove: collapse level-1 B-tree back to level-0");
4830
4831 /* Create the file for the test */
4832 if(create_file(&file, &f, fapl) < 0)
4833 TEST_ERROR
4834
4835 /* Create the v2 B-tree & get its address */
4836 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
4837 TEST_ERROR
4838
4839 /* Create level-1 B-tree with 2 leaves */
4840 for(u = 0; u < INSERT_SPLIT_ROOT_NREC; u++) {
4841 record = u;
4842 if(H5B2_insert(bt2, dxpl, &record) < 0)
4843 FAIL_STACK_ERROR
4844 } /* end for */
4845
4846 /* Check record values in root of B-tree */
4847 ninfo.depth = 1;
4848 ninfo.nrec = 1;
4849 record = 31; /* Middle record in root node */
4850 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
4851 TEST_ERROR
4852
4853 /* Query the number of records in the B-tree */
4854 if(H5B2_get_nrec(bt2, &nrec) < 0)
4855 FAIL_STACK_ERROR
4856
4857 /* Make certain that the # of records is correct */
4858 if(nrec != INSERT_SPLIT_ROOT_NREC)
4859 TEST_ERROR
4860
4861 /* Query the address of the root node in the B-tree */
4862 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
4863 FAIL_STACK_ERROR
4864
4865 /* Make certain that the address of the root node is defined */
4866 if(!H5F_addr_defined(root_addr))
4867 TEST_ERROR
4868
4869 /* Check for closing & re-opening the B-tree */
4870 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
4871 TEST_ERROR
4872
4873 /* Attempt to remove records from B-tree to force a single leaf for the B-tree */
4874 for(u = 0; u < 14; u++) {
4875 record = INSERT_SPLIT_ROOT_NREC - (u + 1);
4876 rrecord = HSIZET_MAX;
4877 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
4878 FAIL_STACK_ERROR
4879
4880 /* Make certain that the record value is correct */
4881 if(rrecord != (INSERT_SPLIT_ROOT_NREC - (u + 1)))
4882 TEST_ERROR
4883
4884 /* Query the number of records in the B-tree */
4885 if(H5B2_get_nrec(bt2, &nrec) < 0)
4886 FAIL_STACK_ERROR
4887
4888 /* Make certain that the # of records is correct */
4889 if(nrec != (INSERT_SPLIT_ROOT_NREC - (u + 1)))
4890 TEST_ERROR
4891 } /* end for */
4892
4893 /* Check record values in root of B-tree */
4894 ninfo.depth = 0;
4895 ninfo.nrec = INSERT_SPLIT_ROOT_NREC - u;
4896 record = 31; /* Middle record in root node */
4897 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
4898 TEST_ERROR
4899
4900 /* Query the number of records in the B-tree */
4901 if(H5B2_get_nrec(bt2, &nrec) < 0)
4902 FAIL_STACK_ERROR
4903
4904 /* Make certain that the # of records is correct */
4905 if(nrec != (INSERT_SPLIT_ROOT_NREC - u))
4906 TEST_ERROR
4907
4908 /* Query the address of the root node in the B-tree */
4909 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
4910 FAIL_STACK_ERROR
4911
4912 /* Make certain that the address of the root node is defined */
4913 if(!H5F_addr_defined(root_addr))
4914 TEST_ERROR
4915
4916 /* Close the v2 B-tree */
4917 if(H5B2_close(bt2, dxpl) < 0)
4918 FAIL_STACK_ERROR
4919 bt2 = NULL;
4920
4921 /* Close file */
4922 if(H5Fclose(file) < 0)
4923 TEST_ERROR
4924
4925 PASSED();
4926
4927 return 0;
4928
4929 error:
4930 H5E_BEGIN_TRY {
4931 if(bt2)
4932 H5B2_close(bt2, dxpl);
4933 H5Fclose(file);
4934 } H5E_END_TRY;
4935 return 1;
4936 } /* test_remove_level1_collapse() */
4937
4938
4939 /*-------------------------------------------------------------------------
4940 * Function: test_remove_level2_promote
4941 *
4942 * Purpose: Basic tests for the B-tree v2 code
4943 *
4944 * Return: Success: 0
4945 * Failure: 1
4946 *
4947 * Programmer: Quincey Koziol
4948 * Friday, March 4, 2005
4949 *
4950 *-------------------------------------------------------------------------
4951 */
4952 static unsigned
test_remove_level2_promote(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)4953 test_remove_level2_promote(hid_t fapl, const H5B2_create_t *cparam,
4954 const bt2_test_param_t *tparam)
4955 {
4956 hid_t file = -1; /* File ID */
4957 H5F_t *f = NULL; /* Internal file object pointer */
4958 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
4959 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
4960 haddr_t bt2_addr; /* Address of B-tree created */
4961 hsize_t record; /* Record to insert into tree */
4962 hsize_t rrecord; /* Record to remove from tree */
4963 hsize_t nrec; /* Number of records in B-tree */
4964 haddr_t root_addr; /* Address of root of B-tree created */
4965 H5B2_node_info_test_t ninfo; /* B-tree node info */
4966 unsigned u; /* Local index variable */
4967
4968 TESTING("B-tree remove: promote from right internal of level-2 B-tree");
4969
4970 /* Create the file for the test */
4971 if(create_file(&file, &f, fapl) < 0)
4972 TEST_ERROR
4973
4974 /* Create the v2 B-tree & get its address */
4975 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
4976 TEST_ERROR
4977
4978 /* Create level-2 B-tree with 3 internal nodes */
4979 for(u = 0; u < ((INSERT_SPLIT_ROOT_NREC * 59) + 1); u++) {
4980 record = u;
4981 if(H5B2_insert(bt2, dxpl, &record) < 0)
4982 FAIL_STACK_ERROR
4983 } /* end for */
4984
4985 /* Check record values in root of B-tree */
4986 record = 1889; /* Left record in root node */
4987 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
4988 TEST_ERROR
4989 ninfo.depth = 2;
4990 ninfo.nrec = 2;
4991 record = 2834; /* Right record in root node */
4992 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
4993 TEST_ERROR
4994
4995 /* Query the number of records in the B-tree */
4996 if(H5B2_get_nrec(bt2, &nrec) < 0)
4997 FAIL_STACK_ERROR
4998
4999 /* Make certain that the # of records is correct */
5000 if(nrec != ((INSERT_SPLIT_ROOT_NREC * 59) + 1))
5001 TEST_ERROR
5002
5003 /* Query the address of the root node in the B-tree */
5004 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
5005 FAIL_STACK_ERROR
5006
5007 /* Make certain that the address of the root node is defined */
5008 if(!H5F_addr_defined(root_addr))
5009 TEST_ERROR
5010
5011 /* Check for closing & re-opening the B-tree */
5012 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
5013 TEST_ERROR
5014
5015 /* Check information about record in right internal node */
5016 ninfo.depth = 1;
5017 ninfo.nrec = 14;
5018 record = 2960; /* Record in right internal node */
5019 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5020 TEST_ERROR
5021
5022 /* Attempt to remove record from right internal node of a level-2 B-tree to force promotion */
5023 record = 2960;
5024 rrecord = HSIZET_MAX;
5025 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
5026 FAIL_STACK_ERROR
5027
5028 /* Make certain that the record value is correct */
5029 if(rrecord != 2960)
5030 TEST_ERROR
5031
5032 /* Check information about record promoted into right internal node */
5033 ninfo.depth = 1;
5034 ninfo.nrec = 14;
5035 record = 2961; /* Record in right internal node */
5036 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5037 TEST_ERROR
5038
5039 /* Query the number of records in the B-tree */
5040 if(H5B2_get_nrec(bt2, &nrec) < 0)
5041 FAIL_STACK_ERROR
5042
5043 /* Make certain that the # of records is correct */
5044 if(nrec != (INSERT_SPLIT_ROOT_NREC * 59))
5045 TEST_ERROR
5046
5047 PASSED();
5048
5049 /* Attempt to remove record from left internal node of a level-2 B-tree to force promotion */
5050 TESTING("B-tree remove: promote from left internal of level-2 B-tree");
5051
5052 /* Check for closing & re-opening the B-tree */
5053 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
5054 TEST_ERROR
5055
5056 /* Check information about record in left internal node */
5057 ninfo.depth = 1;
5058 ninfo.nrec = 29;
5059 record = 1133; /* Record in left internal node */
5060 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5061 TEST_ERROR
5062
5063 record = 1133;
5064 rrecord = HSIZET_MAX;
5065 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
5066 FAIL_STACK_ERROR
5067
5068 /* Make certain that the record value is correct */
5069 if(rrecord != 1133)
5070 TEST_ERROR
5071
5072 /* Check information about record in left internal node */
5073 ninfo.depth = 1;
5074 ninfo.nrec = 29;
5075 record = 1134; /* Record in left internal node */
5076 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5077 TEST_ERROR
5078
5079 /* Query the number of records in the B-tree */
5080 if(H5B2_get_nrec(bt2, &nrec) < 0)
5081 FAIL_STACK_ERROR
5082
5083 /* Make certain that the # of records is correct */
5084 if(nrec != (INSERT_SPLIT_ROOT_NREC * 59) - 1)
5085 TEST_ERROR
5086
5087 PASSED();
5088
5089 /* Attempt to remove record from middle internal node of a level-2 B-tree to force promotion */
5090 TESTING("B-tree remove: promote from middle internal of level-2 B-tree");
5091
5092 /* Check for closing & re-opening the B-tree */
5093 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
5094 TEST_ERROR
5095
5096 /* Check information about record in middle internal node */
5097 ninfo.depth = 1;
5098 ninfo.nrec = 14;
5099 record = 2267; /* Record in middle internal node */
5100 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5101 TEST_ERROR
5102
5103 record = 2267;
5104 rrecord = HSIZET_MAX;
5105 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
5106 FAIL_STACK_ERROR
5107
5108 /* Make certain that the record value is correct */
5109 if(rrecord != 2267)
5110 TEST_ERROR
5111
5112 /* Check information about record in middle internal node */
5113 ninfo.depth = 1;
5114 ninfo.nrec = 14;
5115 record = 2268; /* Record in middle internal node */
5116 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5117 TEST_ERROR
5118
5119 /* Query the number of records in the B-tree */
5120 if(H5B2_get_nrec(bt2, &nrec) < 0)
5121 FAIL_STACK_ERROR
5122
5123 /* Make certain that the # of records is correct */
5124 if(nrec != (INSERT_SPLIT_ROOT_NREC * 59) - 2)
5125 TEST_ERROR
5126
5127 PASSED();
5128
5129 /* Attempt to remove record from root node of a level-2 B-tree to force promotion */
5130 TESTING("B-tree remove: promote record from root of level-2 B-tree");
5131
5132 /* Check for closing & re-opening the B-tree */
5133 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
5134 TEST_ERROR
5135
5136 /* Check information about record in root node */
5137 ninfo.depth = 2;
5138 ninfo.nrec = 2;
5139 record = 1889; /* Left record in root node */
5140 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5141 TEST_ERROR
5142
5143 record = 1889;
5144 rrecord = HSIZET_MAX;
5145 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
5146 FAIL_STACK_ERROR
5147
5148 /* Make certain that the record value is correct */
5149 if(rrecord != 1889)
5150 TEST_ERROR
5151
5152 /* Check information about record in root node */
5153 ninfo.depth = 2;
5154 ninfo.nrec = 2;
5155 record = 1890; /* Left record in root node */
5156 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5157 TEST_ERROR
5158
5159 /* Query the number of records in the B-tree */
5160 if(H5B2_get_nrec(bt2, &nrec) < 0)
5161 FAIL_STACK_ERROR
5162
5163 /* Make certain that the # of records is correct */
5164 if(nrec != (INSERT_SPLIT_ROOT_NREC * 59) - 3)
5165 TEST_ERROR
5166
5167 /* Check for closing & re-opening the B-tree */
5168 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
5169 TEST_ERROR
5170
5171 /* Check information about record in root node */
5172 ninfo.depth = 2;
5173 ninfo.nrec = 2;
5174 record = 2834; /* Right record in root node */
5175 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5176 TEST_ERROR
5177
5178 record = 2834;
5179 rrecord = HSIZET_MAX;
5180 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
5181 FAIL_STACK_ERROR
5182
5183 /* Make certain that the record value is correct */
5184 if(rrecord != 2834)
5185 TEST_ERROR
5186
5187 /* Check information about record in root node */
5188 ninfo.depth = 2;
5189 ninfo.nrec = 2;
5190 record = 2835; /* Right record in root node */
5191 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5192 TEST_ERROR
5193
5194 /* Query the number of records in the B-tree */
5195 if(H5B2_get_nrec(bt2, &nrec) < 0)
5196 FAIL_STACK_ERROR
5197
5198 /* Make certain that the # of records is correct */
5199 if(nrec != (INSERT_SPLIT_ROOT_NREC * 59) - 4)
5200 TEST_ERROR
5201
5202 /* Close the v2 B-tree */
5203 if(H5B2_close(bt2, dxpl) < 0)
5204 FAIL_STACK_ERROR
5205 bt2 = NULL;
5206
5207 /* Close file */
5208 if(H5Fclose(file) < 0)
5209 TEST_ERROR
5210
5211 PASSED();
5212
5213 return 0;
5214
5215 error:
5216 H5E_BEGIN_TRY {
5217 if(bt2)
5218 H5B2_close(bt2, dxpl);
5219 H5Fclose(file);
5220 } H5E_END_TRY;
5221 return 1;
5222 } /* test_remove_level2_promote() */
5223
5224
5225 /*-------------------------------------------------------------------------
5226 * Function: test_remove_level2_promote_2internal_redistrib
5227 *
5228 * Purpose: Basic tests for the B-tree v2 code
5229 *
5230 * Return: Success: 0
5231 * Failure: 1
5232 *
5233 * Programmer: Quincey Koziol
5234 * Monday, March 7, 2005
5235 *
5236 *-------------------------------------------------------------------------
5237 */
5238 static unsigned
test_remove_level2_promote_2internal_redistrib(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)5239 test_remove_level2_promote_2internal_redistrib(hid_t fapl, const H5B2_create_t *cparam,
5240 const bt2_test_param_t *tparam)
5241 {
5242 hid_t file = -1; /* File ID */
5243 H5F_t *f = NULL; /* Internal file object pointer */
5244 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
5245 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
5246 haddr_t bt2_addr; /* Address of B-tree created */
5247 hsize_t record; /* Record to insert into tree */
5248 hsize_t rrecord; /* Record to remove from tree */
5249 hsize_t nrec; /* Number of records in B-tree */
5250 haddr_t root_addr; /* Address of root of B-tree created */
5251 H5B2_node_info_test_t ninfo; /* B-tree node info */
5252 unsigned u; /* Local index variable */
5253
5254 TESTING("B-tree remove: promote from right internal of level-2 B-tree w/redistrib");
5255
5256 /* Create the file for the test */
5257 if(create_file(&file, &f, fapl) < 0)
5258 TEST_ERROR
5259
5260 /* Create the v2 B-tree & get its address */
5261 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
5262 TEST_ERROR
5263
5264 /* Create level-2 B-tree with 3 internal nodes */
5265 for(u = 0; u < ((INSERT_SPLIT_ROOT_NREC * 59) + 1); u++) {
5266 record = u;
5267 if(H5B2_insert(bt2, dxpl, &record) < 0)
5268 FAIL_STACK_ERROR
5269 } /* end for */
5270
5271 /* Check record values in root of B-tree */
5272 record = 1889; /* Left record in root node */
5273 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
5274 TEST_ERROR
5275 ninfo.depth = 2;
5276 ninfo.nrec = 2;
5277 record = 2834; /* Right record in root node */
5278 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5279 TEST_ERROR
5280
5281 /* Query the number of records in the B-tree */
5282 if(H5B2_get_nrec(bt2, &nrec) < 0)
5283 FAIL_STACK_ERROR
5284
5285 /* Make certain that the # of records is correct */
5286 if(nrec != ((INSERT_SPLIT_ROOT_NREC * 59) + 1))
5287 TEST_ERROR
5288
5289 /* Query the address of the root node in the B-tree */
5290 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
5291 FAIL_STACK_ERROR
5292
5293 /* Make certain that the address of the root node is defined */
5294 if(!H5F_addr_defined(root_addr))
5295 TEST_ERROR
5296
5297 /* Check for closing & re-opening the B-tree */
5298 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
5299 TEST_ERROR
5300
5301 /* Check status of B-tree */
5302 ninfo.depth = 1;
5303 ninfo.nrec = 14;
5304 record = 3685; /* Right-most record in root node */
5305 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5306 TEST_ERROR
5307
5308 /* Attempt to remove record from right internal node of a level-2 B-tree to force promotion w/redistribution */
5309 for(u = 0; u < 8; u++) {
5310 record = ((INSERT_SPLIT_ROOT_NREC * 59) + 1) - (u + 1);
5311 rrecord = HSIZET_MAX;
5312 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
5313 FAIL_STACK_ERROR
5314
5315 /* Make certain that the record value is correct */
5316 if(rrecord != (((INSERT_SPLIT_ROOT_NREC * 59) + 1)- (u + 1)))
5317 TEST_ERROR
5318
5319 /* Query the number of records in the B-tree */
5320 if(H5B2_get_nrec(bt2, &nrec) < 0)
5321 FAIL_STACK_ERROR
5322
5323 /* Make certain that the # of records is correct */
5324 if(nrec != (((INSERT_SPLIT_ROOT_NREC * 59) + 1) - (u + 1)))
5325 TEST_ERROR
5326 } /* end for */
5327
5328 record = 3685;
5329 rrecord = HSIZET_MAX;
5330 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
5331 FAIL_STACK_ERROR
5332
5333 /* Make certain that the record value is correct */
5334 if(rrecord != 3685)
5335 TEST_ERROR
5336
5337 /* Check status of B-tree */
5338 ninfo.depth = 1;
5339 ninfo.nrec = 14;
5340 record = 3681; /* Right-most record in root node */
5341 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5342 TEST_ERROR
5343
5344 /* Query the number of records in the B-tree */
5345 if(H5B2_get_nrec(bt2, &nrec) < 0)
5346 FAIL_STACK_ERROR
5347
5348 /* Make certain that the # of records is correct */
5349 if(nrec != (INSERT_SPLIT_ROOT_NREC * 59) - 8)
5350 TEST_ERROR
5351
5352 /* Close the v2 B-tree */
5353 if(H5B2_close(bt2, dxpl) < 0)
5354 FAIL_STACK_ERROR
5355 bt2 = NULL;
5356
5357 /* Close file */
5358 if(H5Fclose(file) < 0)
5359 TEST_ERROR
5360
5361 PASSED();
5362
5363 return 0;
5364
5365 error:
5366 H5E_BEGIN_TRY {
5367 if(bt2)
5368 H5B2_close(bt2, dxpl);
5369 H5Fclose(file);
5370 } H5E_END_TRY;
5371 return 1;
5372 } /* test_remove_level2_promote_2internal_redistrib() */
5373
5374
5375 /*-------------------------------------------------------------------------
5376 * Function: test_remove_level2_3promote_internal_redistrib
5377 *
5378 * Purpose: Basic tests for the B-tree v2 code
5379 *
5380 * Return: Success: 0
5381 * Failure: 1
5382 *
5383 * Programmer: Quincey Koziol
5384 * Monday, March 7, 2005
5385 *
5386 *-------------------------------------------------------------------------
5387 */
5388 static unsigned
test_remove_level2_promote_3internal_redistrib(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)5389 test_remove_level2_promote_3internal_redistrib(hid_t fapl, const H5B2_create_t *cparam,
5390 const bt2_test_param_t *tparam)
5391 {
5392 hid_t file = -1; /* File ID */
5393 H5F_t *f = NULL; /* Internal file object pointer */
5394 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
5395 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
5396 haddr_t bt2_addr; /* Address of B-tree created */
5397 hsize_t record; /* Record to insert into tree */
5398 hsize_t rrecord; /* Record to remove from tree */
5399 hsize_t nrec; /* Number of records in B-tree */
5400 haddr_t root_addr; /* Address of root of B-tree created */
5401 H5B2_node_info_test_t ninfo; /* B-tree node info */
5402 unsigned u; /* Local index variable */
5403
5404 TESTING("B-tree remove: promote from left internal of level-2 B-tree w/redistrib");
5405
5406 /* Create the file for the test */
5407 if(create_file(&file, &f, fapl) < 0)
5408 TEST_ERROR
5409
5410 /* Create the v2 B-tree & get its address */
5411 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
5412 TEST_ERROR
5413
5414 /* Create level-2 B-tree with 3 internal nodes */
5415 for(u = 0; u < ((INSERT_SPLIT_ROOT_NREC * 59) + 1); u++) {
5416 record = u;
5417 if(H5B2_insert(bt2, dxpl, &record) < 0)
5418 FAIL_STACK_ERROR
5419 } /* end for */
5420
5421 /* Check record values in root of B-tree */
5422 record = 1889; /* Left record in root node */
5423 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
5424 TEST_ERROR
5425 ninfo.depth = 2;
5426 ninfo.nrec = 2;
5427 record = 2834; /* Right record in root node */
5428 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5429 TEST_ERROR
5430
5431 /* Query the number of records in the B-tree */
5432 if(H5B2_get_nrec(bt2, &nrec) < 0)
5433 FAIL_STACK_ERROR
5434
5435 /* Make certain that the # of records is correct */
5436 if(nrec != ((INSERT_SPLIT_ROOT_NREC * 59) + 1))
5437 TEST_ERROR
5438
5439 /* Query the address of the root node in the B-tree */
5440 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
5441 FAIL_STACK_ERROR
5442
5443 /* Make certain that the address of the root node is defined */
5444 if(!H5F_addr_defined(root_addr))
5445 TEST_ERROR
5446
5447 /* Check for closing & re-opening the B-tree */
5448 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
5449 TEST_ERROR
5450
5451 /* Check status of B-tree */
5452 ninfo.depth = 1;
5453 ninfo.nrec = 29;
5454 record = 62; /* Left-most record in left node */
5455 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5456 TEST_ERROR
5457
5458 /* Attempt to remove record from left internal node of a level-2 B-tree to force promotion w/redistribution */
5459 for(u = 0; u < 38; u++) {
5460 record = 63 + u;
5461 rrecord = HSIZET_MAX;
5462 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
5463 FAIL_STACK_ERROR
5464
5465 /* Make certain that the record value is correct */
5466 if(rrecord != (63 + u))
5467 TEST_ERROR
5468
5469 /* Query the number of records in the B-tree */
5470 if(H5B2_get_nrec(bt2, &nrec) < 0)
5471 FAIL_STACK_ERROR
5472
5473 /* Make certain that the # of records is correct */
5474 if(nrec != (((INSERT_SPLIT_ROOT_NREC * 59) + 1) - (u + 1)))
5475 TEST_ERROR
5476 } /* end for */
5477
5478 record = 62;
5479 rrecord = HSIZET_MAX;
5480 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
5481 FAIL_STACK_ERROR
5482
5483 /* Make certain that the record value is correct */
5484 if(rrecord != 62)
5485 TEST_ERROR
5486
5487 /* Check status of B-tree */
5488 ninfo.depth = 1;
5489 ninfo.nrec = 29;
5490 record = 49; /* Left-most record in left node */
5491 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5492 TEST_ERROR
5493
5494 /* Query the number of records in the B-tree */
5495 if(H5B2_get_nrec(bt2, &nrec) < 0)
5496 FAIL_STACK_ERROR
5497
5498 /* Make certain that the # of records is correct */
5499 if(nrec != (INSERT_SPLIT_ROOT_NREC * 59) - 38)
5500 TEST_ERROR
5501
5502 /* Close the v2 B-tree */
5503 if(H5B2_close(bt2, dxpl) < 0)
5504 FAIL_STACK_ERROR
5505 bt2 = NULL;
5506
5507 /* Close file */
5508 if(H5Fclose(file) < 0)
5509 TEST_ERROR
5510
5511 PASSED();
5512
5513 return 0;
5514
5515 error:
5516 H5E_BEGIN_TRY {
5517 if(bt2)
5518 H5B2_close(bt2, dxpl);
5519 H5Fclose(file);
5520 } H5E_END_TRY;
5521 return 1;
5522 } /* test_remove_level2_promote_3internal_redistrib() */
5523
5524
5525 /*-------------------------------------------------------------------------
5526 * Function: test_remove_level2_promote_2internal_merge
5527 *
5528 * Purpose: Basic tests for the B-tree v2 code
5529 *
5530 * Return: Success: 0
5531 * Failure: 1
5532 *
5533 * Programmer: Quincey Koziol
5534 * Monday, March 7, 2005
5535 *
5536 *-------------------------------------------------------------------------
5537 */
5538 static unsigned
test_remove_level2_promote_2internal_merge(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)5539 test_remove_level2_promote_2internal_merge(hid_t fapl, const H5B2_create_t *cparam,
5540 const bt2_test_param_t *tparam)
5541 {
5542 hid_t file = -1; /* File ID */
5543 H5F_t *f = NULL; /* Internal file object pointer */
5544 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
5545 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
5546 haddr_t bt2_addr; /* Address of B-tree created */
5547 hsize_t record; /* Record to insert into tree */
5548 hsize_t rrecord; /* Record to remove from tree */
5549 hsize_t nrec; /* Number of records in B-tree */
5550 haddr_t root_addr; /* Address of root of B-tree created */
5551 H5B2_node_info_test_t ninfo; /* B-tree node info */
5552 unsigned u; /* Local index variable */
5553
5554 TESTING("B-tree remove: promote from right internal of level-2 B-tree w/merge");
5555
5556 /* Create the file for the test */
5557 if(create_file(&file, &f, fapl) < 0)
5558 TEST_ERROR
5559
5560 /* Create the v2 B-tree & get its address */
5561 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
5562 TEST_ERROR
5563
5564 /* Create level-2 B-tree with 3 internal nodes */
5565 for(u = 0; u < ((INSERT_SPLIT_ROOT_NREC * 59) + 1); u++) {
5566 record = u;
5567 if(H5B2_insert(bt2, dxpl, &record) < 0)
5568 FAIL_STACK_ERROR
5569 } /* end for */
5570
5571 /* Check record values in root of B-tree */
5572 record = 1889; /* Left record in root node */
5573 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
5574 TEST_ERROR
5575 ninfo.depth = 2;
5576 ninfo.nrec = 2;
5577 record = 2834; /* Right record in root node */
5578 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5579 TEST_ERROR
5580
5581 /* Query the number of records in the B-tree */
5582 if(H5B2_get_nrec(bt2, &nrec) < 0)
5583 FAIL_STACK_ERROR
5584
5585 /* Make certain that the # of records is correct */
5586 if(nrec != ((INSERT_SPLIT_ROOT_NREC * 59) + 1))
5587 TEST_ERROR
5588
5589 /* Query the address of the root node in the B-tree */
5590 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
5591 FAIL_STACK_ERROR
5592
5593 /* Make certain that the address of the root node is defined */
5594 if(!H5F_addr_defined(root_addr))
5595 TEST_ERROR
5596
5597 /* Check for closing & re-opening the B-tree */
5598 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
5599 TEST_ERROR
5600
5601 /* Check information about record in right internal node */
5602 ninfo.depth = 1;
5603 ninfo.nrec = 14;
5604 record = 3685; /* Right-most record in right internal node */
5605 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5606 TEST_ERROR
5607
5608 /* Attempt to remove record from right internal node of a level-2 B-tree to force promotion w/redistribution */
5609 for(u = 0; u < 15; u++) {
5610 record = ((INSERT_SPLIT_ROOT_NREC * 59) + 1) - (u + 1);
5611 rrecord = HSIZET_MAX;
5612 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
5613 FAIL_STACK_ERROR
5614
5615 /* Make certain that the record value is correct */
5616 if(rrecord != (((INSERT_SPLIT_ROOT_NREC * 59) + 1)- (u + 1)))
5617 TEST_ERROR
5618
5619 /* Query the number of records in the B-tree */
5620 if(H5B2_get_nrec(bt2, &nrec) < 0)
5621 FAIL_STACK_ERROR
5622
5623 /* Make certain that the # of records is correct */
5624 if(nrec != (((INSERT_SPLIT_ROOT_NREC * 59) + 1) - (u + 1)))
5625 TEST_ERROR
5626 } /* end for */
5627
5628 /* Force merge by promoting current right-most record */
5629 record = 3678;
5630 rrecord = HSIZET_MAX;
5631 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
5632 FAIL_STACK_ERROR
5633
5634 /* Make certain that the record value is correct */
5635 if(rrecord != 3678)
5636 TEST_ERROR
5637
5638 /* Check information about record in right internal node */
5639 ninfo.depth = 1;
5640 ninfo.nrec = 13;
5641 record = 3653; /* Right-most record in right internal node (now) */
5642 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5643 TEST_ERROR
5644
5645 /* Query the number of records in the B-tree */
5646 if(H5B2_get_nrec(bt2, &nrec) < 0)
5647 FAIL_STACK_ERROR
5648
5649 /* Make certain that the # of records is correct */
5650 if(nrec != (INSERT_SPLIT_ROOT_NREC * 59) - 15)
5651 TEST_ERROR
5652
5653 /* Close the v2 B-tree */
5654 if(H5B2_close(bt2, dxpl) < 0)
5655 FAIL_STACK_ERROR
5656 bt2 = NULL;
5657
5658 /* Close file */
5659 if(H5Fclose(file) < 0)
5660 TEST_ERROR
5661
5662 PASSED();
5663
5664 return 0;
5665
5666 error:
5667 H5E_BEGIN_TRY {
5668 if(bt2)
5669 H5B2_close(bt2, dxpl);
5670 H5Fclose(file);
5671 } H5E_END_TRY;
5672 return 1;
5673 } /* test_remove_level2_promote_2internal_merge() */
5674
5675
5676 /*-------------------------------------------------------------------------
5677 * Function: test_remove_level2_3promote_internal_merge
5678 *
5679 * Purpose: Basic tests for the B-tree v2 code
5680 *
5681 * Return: Success: 0
5682 * Failure: 1
5683 *
5684 * Programmer: Quincey Koziol
5685 * Monday, March 7, 2005
5686 *
5687 *-------------------------------------------------------------------------
5688 */
5689 static unsigned
test_remove_level2_promote_3internal_merge(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)5690 test_remove_level2_promote_3internal_merge(hid_t fapl, const H5B2_create_t *cparam,
5691 const bt2_test_param_t *tparam)
5692 {
5693 hid_t file = -1; /* File ID */
5694 H5F_t *f = NULL; /* Internal file object pointer */
5695 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
5696 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
5697 haddr_t bt2_addr; /* Address of B-tree created */
5698 hsize_t record; /* Record to insert into tree */
5699 hsize_t rrecord; /* Record to remove from tree */
5700 hsize_t nrec; /* Number of records in B-tree */
5701 haddr_t root_addr; /* Address of root of B-tree created */
5702 H5B2_node_info_test_t ninfo; /* B-tree node info */
5703 unsigned u; /* Local index variable */
5704
5705 TESTING("B-tree remove: promote from middle internal of level-2 B-tree w/merge");
5706
5707 /* Create the file for the test */
5708 if(create_file(&file, &f, fapl) < 0)
5709 TEST_ERROR
5710
5711 /* Create the v2 B-tree & get its address */
5712 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
5713 TEST_ERROR
5714
5715 /* Create level-2 B-tree with 3 internal nodes */
5716 for(u = 0; u < ((INSERT_SPLIT_ROOT_NREC * 59) + 1); u++) {
5717 record = u;
5718 if(H5B2_insert(bt2, dxpl, &record) < 0)
5719 FAIL_STACK_ERROR
5720 } /* end for */
5721
5722 /* Check record values in root of B-tree */
5723 record = 1889; /* Left record in root node */
5724 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
5725 TEST_ERROR
5726 ninfo.depth = 2;
5727 ninfo.nrec = 2;
5728 record = 2834; /* Right record in root node */
5729 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5730 TEST_ERROR
5731
5732 /* Query the number of records in the B-tree */
5733 if(H5B2_get_nrec(bt2, &nrec) < 0)
5734 FAIL_STACK_ERROR
5735
5736 /* Make certain that the # of records is correct */
5737 if(nrec != ((INSERT_SPLIT_ROOT_NREC * 59) + 1))
5738 TEST_ERROR
5739
5740 /* Query the address of the root node in the B-tree */
5741 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
5742 FAIL_STACK_ERROR
5743
5744 /* Make certain that the address of the root node is defined */
5745 if(!H5F_addr_defined(root_addr))
5746 TEST_ERROR
5747
5748 /* Check for closing & re-opening the B-tree */
5749 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
5750 TEST_ERROR
5751
5752 /* Check information about record in left internal node */
5753 ninfo.depth = 1;
5754 ninfo.nrec = 29;
5755 record = 62; /* Left-most record in left internal node */
5756 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5757 TEST_ERROR
5758
5759 /* Attempt to remove record from left internal node of a level-2 B-tree to force promotion w/redistribution */
5760 for(u = 0; u < 112; u++) {
5761 record = 48 + u;
5762 rrecord = HSIZET_MAX;
5763 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
5764 FAIL_STACK_ERROR
5765
5766 /* Make certain that the record value is correct */
5767 if(rrecord != (48 + u))
5768 TEST_ERROR
5769
5770 /* Query the number of records in the B-tree */
5771 if(H5B2_get_nrec(bt2, &nrec) < 0)
5772 FAIL_STACK_ERROR
5773
5774 /* Make certain that the # of records is correct */
5775 if(nrec != (((INSERT_SPLIT_ROOT_NREC * 59) + 1) - (u + 1)))
5776 TEST_ERROR
5777 } /* end for */
5778
5779 /* Force merge of left-most internal nodes by promotion */
5780 record = 25;
5781 rrecord = HSIZET_MAX;
5782 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
5783 FAIL_STACK_ERROR
5784
5785 /* Make certain that the record value is correct */
5786 if(rrecord != 25)
5787 TEST_ERROR
5788
5789 /* Check information about record in left internal node */
5790 ninfo.depth = 1;
5791 ninfo.nrec = 28;
5792 record = 37; /* Left-most record in left internal node (now) */
5793 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5794 TEST_ERROR
5795
5796 /* Query the number of records in the B-tree */
5797 if(H5B2_get_nrec(bt2, &nrec) < 0)
5798 FAIL_STACK_ERROR
5799
5800 /* Make certain that the # of records is correct */
5801 if(nrec != (INSERT_SPLIT_ROOT_NREC * 59) - 112)
5802 TEST_ERROR
5803
5804 /* Close the v2 B-tree */
5805 if(H5B2_close(bt2, dxpl) < 0)
5806 FAIL_STACK_ERROR
5807 bt2 = NULL;
5808
5809 /* Close file */
5810 if(H5Fclose(file) < 0)
5811 TEST_ERROR
5812
5813 PASSED();
5814
5815 return 0;
5816
5817 error:
5818 H5E_BEGIN_TRY {
5819 if(bt2)
5820 H5B2_close(bt2, dxpl);
5821 H5Fclose(file);
5822 } H5E_END_TRY;
5823 return 1;
5824 } /* test_remove_level2_promote_3internal_merge() */
5825
5826
5827 /*-------------------------------------------------------------------------
5828 * Function: test_remove_level2_2internal_merge_left
5829 *
5830 * Purpose: Basic tests for the B-tree v2 code
5831 *
5832 * Return: Success: 0
5833 * Failure: 1
5834 *
5835 * Programmer: Quincey Koziol
5836 * Tuesday, March 8, 2005
5837 *
5838 *-------------------------------------------------------------------------
5839 */
5840 static unsigned
test_remove_level2_2internal_merge_left(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)5841 test_remove_level2_2internal_merge_left(hid_t fapl, const H5B2_create_t *cparam,
5842 const bt2_test_param_t *tparam)
5843 {
5844 hid_t file = -1; /* File ID */
5845 H5F_t *f = NULL; /* Internal file object pointer */
5846 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
5847 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
5848 haddr_t bt2_addr; /* Address of B-tree created */
5849 hsize_t record; /* Record to insert into tree */
5850 hsize_t rrecord; /* Record to remove from tree */
5851 hsize_t nrec; /* Number of records in B-tree */
5852 haddr_t root_addr; /* Address of root of B-tree created */
5853 H5B2_node_info_test_t ninfo; /* B-tree node info */
5854 unsigned u; /* Local index variable */
5855
5856 TESTING("B-tree remove: merge 2 internal nodes to 1 in level-2 B-tree (l->r)");
5857
5858 /* Create the file for the test */
5859 if(create_file(&file, &f, fapl) < 0)
5860 TEST_ERROR
5861
5862 /* Create the v2 B-tree & get its address */
5863 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
5864 TEST_ERROR
5865
5866 /* Create level-2 B-tree with 3 internal nodes */
5867 for(u = 0; u < ((INSERT_SPLIT_ROOT_NREC * 59) + 1); u++) {
5868 record = u;
5869 if(H5B2_insert(bt2, dxpl, &record) < 0)
5870 FAIL_STACK_ERROR
5871 } /* end for */
5872
5873 /* Check record values in root of B-tree */
5874 record = 1889; /* Left record in root node */
5875 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
5876 TEST_ERROR
5877 ninfo.depth = 2;
5878 ninfo.nrec = 2;
5879 record = 2834; /* Right record in root node */
5880 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5881 TEST_ERROR
5882
5883 /* Query the number of records in the B-tree */
5884 if(H5B2_get_nrec(bt2, &nrec) < 0)
5885 FAIL_STACK_ERROR
5886
5887 /* Make certain that the # of records is correct */
5888 if(nrec != ((INSERT_SPLIT_ROOT_NREC * 59) + 1))
5889 TEST_ERROR
5890
5891 /* Query the address of the root node in the B-tree */
5892 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
5893 FAIL_STACK_ERROR
5894
5895 /* Make certain that the address of the root node is defined */
5896 if(!H5F_addr_defined(root_addr))
5897 TEST_ERROR
5898
5899 /* Check for closing & re-opening the B-tree */
5900 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
5901 TEST_ERROR
5902
5903 /* Attempt to remove records from a level-2 B-tree to force 2 internal nodes to merge */
5904 for(u = 0; u < ((INSERT_SPLIT_ROOT_NREC * 21) + 15); u++) {
5905 record = u;
5906 rrecord = HSIZET_MAX;
5907 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
5908 FAIL_STACK_ERROR
5909
5910 /* Make certain that the record value is correct */
5911 if(rrecord != u)
5912 TEST_ERROR
5913
5914 /* Query the number of records in the B-tree */
5915 if(H5B2_get_nrec(bt2, &nrec) < 0)
5916 FAIL_STACK_ERROR
5917
5918 /* Make certain that the # of records is correct */
5919 if(nrec != (((INSERT_SPLIT_ROOT_NREC * 59) + 1) - (u + 1)))
5920 TEST_ERROR
5921 } /* end for */
5922
5923 /* Check status of B-tree */
5924 ninfo.depth = 2;
5925 ninfo.nrec = 1;
5926 record = 2834; /* Middle record in root node */
5927 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
5928 TEST_ERROR
5929
5930 /* Close the v2 B-tree */
5931 if(H5B2_close(bt2, dxpl) < 0)
5932 FAIL_STACK_ERROR
5933 bt2 = NULL;
5934
5935 /* Close file */
5936 if(H5Fclose(file) < 0)
5937 TEST_ERROR
5938
5939 PASSED();
5940
5941 return 0;
5942
5943 error:
5944 H5E_BEGIN_TRY {
5945 if(bt2)
5946 H5B2_close(bt2, dxpl);
5947 H5Fclose(file);
5948 } H5E_END_TRY;
5949 return 1;
5950 } /* test_remove_level2_2internal_merge_left() */
5951
5952
5953 /*-------------------------------------------------------------------------
5954 * Function: test_remove_level2_2internal_merge_right
5955 *
5956 * Purpose: Basic tests for the B-tree v2 code
5957 *
5958 * Return: Success: 0
5959 * Failure: 1
5960 *
5961 * Programmer: Quincey Koziol
5962 * Tuesday, March 8, 2005
5963 *
5964 *-------------------------------------------------------------------------
5965 */
5966 static unsigned
test_remove_level2_2internal_merge_right(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)5967 test_remove_level2_2internal_merge_right(hid_t fapl, const H5B2_create_t *cparam,
5968 const bt2_test_param_t *tparam)
5969 {
5970 hid_t file = -1; /* File ID */
5971 H5F_t *f = NULL; /* Internal file object pointer */
5972 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
5973 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
5974 haddr_t bt2_addr; /* Address of B-tree created */
5975 hsize_t record; /* Record to insert into tree */
5976 hsize_t rrecord; /* Record to remove from tree */
5977 hsize_t nrec; /* Number of records in B-tree */
5978 haddr_t root_addr; /* Address of root of B-tree created */
5979 H5B2_node_info_test_t ninfo; /* B-tree node info */
5980 unsigned u; /* Local index variable */
5981
5982 TESTING("B-tree remove: merge 2 internal nodes to 1 in level-2 B-tree (r->l)");
5983
5984 /* Create the file for the test */
5985 if(create_file(&file, &f, fapl) < 0)
5986 TEST_ERROR
5987
5988 /* Create the v2 B-tree & get its address */
5989 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
5990 TEST_ERROR
5991
5992 /* Create level-2 B-tree with 3 internal nodes */
5993 for(u = 0; u < ((INSERT_SPLIT_ROOT_NREC * 59) + 1); u++) {
5994 record = u;
5995 if(H5B2_insert(bt2, dxpl, &record) < 0)
5996 FAIL_STACK_ERROR
5997 } /* end for */
5998
5999 /* Check record values in root of B-tree */
6000 record = 1889; /* Left record in root node */
6001 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
6002 TEST_ERROR
6003 ninfo.depth = 2;
6004 ninfo.nrec = 2;
6005 record = 2834; /* Right record in root node */
6006 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
6007 TEST_ERROR
6008
6009 /* Query the number of records in the B-tree */
6010 if(H5B2_get_nrec(bt2, &nrec) < 0)
6011 FAIL_STACK_ERROR
6012
6013 /* Make certain that the # of records is correct */
6014 if(nrec != ((INSERT_SPLIT_ROOT_NREC * 59) + 1))
6015 TEST_ERROR
6016
6017 /* Query the address of the root node in the B-tree */
6018 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
6019 FAIL_STACK_ERROR
6020
6021 /* Make certain that the address of the root node is defined */
6022 if(!H5F_addr_defined(root_addr))
6023 TEST_ERROR
6024
6025 /* Check for closing & re-opening the B-tree */
6026 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
6027 TEST_ERROR
6028
6029 /* Attempt to remove records from a level-2 B-tree to force 2 internal nodes to merge */
6030 for(u = 0; u < ((INSERT_SPLIT_ROOT_NREC * 5) + 17); u++) {
6031 record = ((INSERT_SPLIT_ROOT_NREC * 59) + 1) - (u + 1);
6032 rrecord = HSIZET_MAX;
6033 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
6034 FAIL_STACK_ERROR
6035
6036 /* Make certain that the record value is correct */
6037 if(rrecord != (((INSERT_SPLIT_ROOT_NREC * 59) + 1) - (u + 1)))
6038 TEST_ERROR
6039
6040 /* Query the number of records in the B-tree */
6041 if(H5B2_get_nrec(bt2, &nrec) < 0)
6042 FAIL_STACK_ERROR
6043
6044 /* Make certain that the # of records is correct */
6045 if(nrec != (((INSERT_SPLIT_ROOT_NREC * 59) + 1) - (u+ 1)))
6046 TEST_ERROR
6047 } /* end for */
6048
6049 /* Check status of B-tree */
6050 ninfo.depth = 2;
6051 ninfo.nrec = 1;
6052 record = 1889; /* Middle record in root node */
6053 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
6054 TEST_ERROR
6055
6056 /* Close the v2 B-tree */
6057 if(H5B2_close(bt2, dxpl) < 0)
6058 FAIL_STACK_ERROR
6059 bt2 = NULL;
6060
6061 /* Close file */
6062 if(H5Fclose(file) < 0)
6063 TEST_ERROR
6064
6065 PASSED();
6066
6067 return 0;
6068
6069 error:
6070 H5E_BEGIN_TRY {
6071 if(bt2)
6072 H5B2_close(bt2, dxpl);
6073 H5Fclose(file);
6074 } H5E_END_TRY;
6075 return 1;
6076 } /* test_remove_level2_2internal_merge_right() */
6077
6078
6079 /*-------------------------------------------------------------------------
6080 * Function: test_remove_level2_3internal_merge
6081 *
6082 * Purpose: Basic tests for the B-tree v2 code
6083 *
6084 * Return: Success: 0
6085 * Failure: 1
6086 *
6087 * Programmer: Quincey Koziol
6088 * Tuesday, March 8, 2005
6089 *
6090 *-------------------------------------------------------------------------
6091 */
6092 static unsigned
test_remove_level2_3internal_merge(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)6093 test_remove_level2_3internal_merge(hid_t fapl, const H5B2_create_t *cparam,
6094 const bt2_test_param_t *tparam)
6095 {
6096 hid_t file = -1; /* File ID */
6097 H5F_t *f = NULL; /* Internal file object pointer */
6098 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
6099 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
6100 haddr_t bt2_addr; /* Address of B-tree created */
6101 hsize_t record; /* Record to insert into tree */
6102 hsize_t rrecord; /* Record to remove from tree */
6103 hsize_t nrec; /* Number of records in B-tree */
6104 haddr_t root_addr; /* Address of root of B-tree created */
6105 H5B2_node_info_test_t ninfo; /* B-tree node info */
6106 unsigned u; /* Local index variable */
6107
6108 TESTING("B-tree remove: merge 3 internal nodes to 2 in level-2 B-tree");
6109
6110 /* Create the file for the test */
6111 if(create_file(&file, &f, fapl) < 0)
6112 TEST_ERROR
6113
6114 /* Create the v2 B-tree & get its address */
6115 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
6116 TEST_ERROR
6117
6118 /* Create level-2 B-tree with 3 internal nodes */
6119 for(u = 0; u < ((INSERT_SPLIT_ROOT_NREC * 59) + 1); u++) {
6120 record = u;
6121 if(H5B2_insert(bt2, dxpl, &record) < 0)
6122 FAIL_STACK_ERROR
6123 } /* end for */
6124
6125 /* Check record values in root of B-tree */
6126 record = 1889; /* Left record in root node */
6127 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
6128 TEST_ERROR
6129 ninfo.depth = 2;
6130 ninfo.nrec = 2;
6131 record = 2834; /* Right record in root node */
6132 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
6133 TEST_ERROR
6134
6135 /* Query the number of records in the B-tree */
6136 if(H5B2_get_nrec(bt2, &nrec) < 0)
6137 FAIL_STACK_ERROR
6138
6139 /* Make certain that the # of records is correct */
6140 if(nrec != ((INSERT_SPLIT_ROOT_NREC * 59) + 1))
6141 TEST_ERROR
6142
6143 /* Query the address of the root node in the B-tree */
6144 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
6145 FAIL_STACK_ERROR
6146
6147 /* Make certain that the address of the root node is defined */
6148 if(!H5F_addr_defined(root_addr))
6149 TEST_ERROR
6150
6151 /* Check for closing & re-opening the B-tree */
6152 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
6153 TEST_ERROR
6154
6155 /* Attempt to remove record from middle internal node of a level-2 B-tree to force promotion w/redistribution */
6156 for(u = 0; u < ((INSERT_SPLIT_ROOT_NREC * 23) + 15); u++) {
6157 record = (INSERT_SPLIT_ROOT_NREC * 20) + u;
6158 rrecord = HSIZET_MAX;
6159 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
6160 FAIL_STACK_ERROR
6161
6162 /* Make certain that the record value is correct */
6163 if(rrecord != ((INSERT_SPLIT_ROOT_NREC * 20) + u))
6164 TEST_ERROR
6165
6166 /* Query the number of records in the B-tree */
6167 if(H5B2_get_nrec(bt2, &nrec) < 0)
6168 FAIL_STACK_ERROR
6169
6170 /* Make certain that the # of records is correct */
6171 if(nrec != (((INSERT_SPLIT_ROOT_NREC * 59) + 1) - (u + 1)))
6172 TEST_ERROR
6173 } /* end for */
6174
6175 /* Check status of B-tree */
6176 ninfo.depth = 2;
6177 ninfo.nrec = 1;
6178 record = 1196; /* Right record in root node */
6179 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
6180 TEST_ERROR
6181
6182 /* Close the v2 B-tree */
6183 if(H5B2_close(bt2, dxpl) < 0)
6184 FAIL_STACK_ERROR
6185 bt2 = NULL;
6186
6187 /* Close file */
6188 if(H5Fclose(file) < 0)
6189 TEST_ERROR
6190
6191 PASSED();
6192
6193 return 0;
6194
6195 error:
6196 H5E_BEGIN_TRY {
6197 if(bt2)
6198 H5B2_close(bt2, dxpl);
6199 H5Fclose(file);
6200 } H5E_END_TRY;
6201 return 1;
6202 } /* test_remove_level2_3internal_merge() */
6203
6204
6205 /*-------------------------------------------------------------------------
6206 * Function: test_remove_level2_collapse_right
6207 *
6208 * Purpose: Basic tests for the B-tree v2 code
6209 *
6210 * Return: Success: 0
6211 * Failure: 1
6212 *
6213 * Programmer: Quincey Koziol
6214 * Tuesday, March 8, 2005
6215 *
6216 *-------------------------------------------------------------------------
6217 */
6218 static unsigned
test_remove_level2_collapse_right(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)6219 test_remove_level2_collapse_right(hid_t fapl, const H5B2_create_t *cparam,
6220 const bt2_test_param_t *tparam)
6221 {
6222 hid_t file = -1; /* File ID */
6223 H5F_t *f = NULL; /* Internal file object pointer */
6224 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
6225 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
6226 haddr_t bt2_addr; /* Address of B-tree created */
6227 hsize_t record; /* Record to insert into tree */
6228 hsize_t rrecord; /* Record to remove from tree */
6229 hsize_t nrec; /* Number of records in B-tree */
6230 haddr_t root_addr; /* Address of root of B-tree created */
6231 H5B2_stat_t bt2_stat; /* Statistics about B-tree created */
6232 H5B2_node_info_test_t ninfo; /* B-tree node info */
6233 unsigned u; /* Local index variable */
6234
6235 TESTING("B-tree remove: collapse level-2 B-tree back to level-1 (r->l)");
6236
6237 /* Create the file for the test */
6238 if(create_file(&file, &f, fapl) < 0)
6239 TEST_ERROR
6240
6241 /* Create the v2 B-tree & get its address */
6242 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
6243 TEST_ERROR
6244
6245 /* Create level-2 B-tree with 3 internal nodes */
6246 for(u = 0; u < ((INSERT_SPLIT_ROOT_NREC * 59) + 1); u++) {
6247 record = u;
6248 if(H5B2_insert(bt2, dxpl, &record) < 0)
6249 FAIL_STACK_ERROR
6250 } /* end for */
6251
6252 /* Check record values in root of B-tree */
6253 record = 1889; /* Left record in root node */
6254 if(check_node_depth(bt2, dxpl, record, (unsigned)2) < 0)
6255 TEST_ERROR
6256 ninfo.depth = 2;
6257 ninfo.nrec = 2;
6258 record = 2834; /* Right record in root node */
6259 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
6260 TEST_ERROR
6261
6262 /* Query the number of records in the B-tree */
6263 if(H5B2_get_nrec(bt2, &nrec) < 0)
6264 FAIL_STACK_ERROR
6265
6266 /* Make certain that the # of records is correct */
6267 if(nrec != ((INSERT_SPLIT_ROOT_NREC * 59) + 1))
6268 TEST_ERROR
6269
6270 /* Query the address of the root node in the B-tree */
6271 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
6272 FAIL_STACK_ERROR
6273
6274 /* Make certain that the address of the root node is defined */
6275 if(!H5F_addr_defined(root_addr))
6276 TEST_ERROR
6277
6278 /* Check for closing & re-opening the B-tree */
6279 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
6280 TEST_ERROR
6281
6282 /* Attempt to remove records from a level-2 B-tree to force back to level-1 */
6283 for(u = 0; u < (INSERT_SPLIT_ROOT_NREC * 34) + 17; u++) {
6284 record = ((INSERT_SPLIT_ROOT_NREC * 59) + 1) - (u + 1);
6285 rrecord = HSIZET_MAX;
6286 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
6287 FAIL_STACK_ERROR
6288
6289 /* Make certain that the record value is correct */
6290 if(record != (((INSERT_SPLIT_ROOT_NREC * 59) + 1) - (u + 1)))
6291 TEST_ERROR
6292
6293 /* Query the number of records in the B-tree */
6294 if(H5B2_get_nrec(bt2, &nrec) < 0)
6295 FAIL_STACK_ERROR
6296
6297 /* Make certain that the # of records is correct */
6298 if(nrec != (((INSERT_SPLIT_ROOT_NREC * 59) + 1) - (u + 1)))
6299 TEST_ERROR
6300 } /* end for */
6301
6302 /* Check up on B-tree */
6303 if(H5B2_stat_info(bt2, &bt2_stat) < 0)
6304 FAIL_STACK_ERROR
6305 if(bt2_stat.depth != 1)
6306 TEST_ERROR
6307
6308 /* Close the v2 B-tree */
6309 if(H5B2_close(bt2, dxpl) < 0)
6310 FAIL_STACK_ERROR
6311 bt2 = NULL;
6312
6313 /* Close file */
6314 if(H5Fclose(file) < 0)
6315 TEST_ERROR
6316
6317 PASSED();
6318
6319 return 0;
6320
6321 error:
6322 H5E_BEGIN_TRY {
6323 if(bt2)
6324 H5B2_close(bt2, dxpl);
6325 H5Fclose(file);
6326 } H5E_END_TRY;
6327 return 1;
6328 } /* test_remove_level2_collapse_right() */
6329
6330
6331 /*-------------------------------------------------------------------------
6332 * Function: gen_l4_btree2
6333 *
6334 * Purpose: Generate a level-4 v2 B-tree for testing.
6335 *
6336 * Return: Success: 0
6337 * Failure: 1
6338 *
6339 * Programmer: Quincey Koziol
6340 * Tuesday, October 14, 2008
6341 *
6342 *-------------------------------------------------------------------------
6343 */
6344 static unsigned
gen_l4_btree2(const char * filename,hid_t fapl,const H5B2_create_t * cparam,haddr_t * bt2_addr,const hsize_t * records)6345 gen_l4_btree2(const char *filename, hid_t fapl, const H5B2_create_t *cparam,
6346 haddr_t *bt2_addr, const hsize_t *records)
6347 {
6348 hid_t file = -1; /* File ID */
6349 H5F_t *f = NULL; /* Internal file object pointer */
6350 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
6351 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
6352 hsize_t record; /* Record to insert into tree */
6353 unsigned u; /* Local index variable */
6354 H5B2_stat_t bt2_stat; /* Statistics about B-tree created */
6355
6356 /* Create the file to work on */
6357 if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
6358 STACK_ERROR
6359
6360 /* Get a pointer to the internal file object */
6361 if(NULL == (f = (H5F_t *)H5I_object(file)))
6362 STACK_ERROR
6363
6364 /* Create the v2 B-tree & get its address */
6365 if(create_btree(f, dxpl, cparam, &bt2, bt2_addr) < 0)
6366 TEST_ERROR
6367
6368 /* Insert random records */
6369 for(u = 0; u < INSERT_MANY; u++) {
6370 record = records[u];
6371 if(H5B2_insert(bt2, dxpl, &record) < 0)
6372 FAIL_STACK_ERROR
6373 } /* end for */
6374
6375 /* Check up on B-tree */
6376 if(H5B2_stat_info(bt2, &bt2_stat) < 0)
6377 FAIL_STACK_ERROR
6378 if(bt2_stat.depth != 4)
6379 TEST_ERROR
6380
6381 /* Close the v2 B-tree */
6382 if(H5B2_close(bt2, dxpl) < 0)
6383 FAIL_STACK_ERROR
6384 bt2 = NULL;
6385
6386 /* Close file */
6387 if(H5Fclose(file) < 0)
6388 STACK_ERROR
6389
6390 return 0;
6391
6392 error:
6393 H5E_BEGIN_TRY {
6394 if(bt2)
6395 H5B2_close(bt2, dxpl);
6396 H5Fclose(file);
6397 } H5E_END_TRY;
6398
6399 return 1;
6400 } /* gen_l4_btree2() */
6401
6402
6403 /*-------------------------------------------------------------------------
6404 * Function: test_remove_lots
6405 *
6406 * Purpose: Basic tests for the B-tree v2 code. This test inserts many
6407 * records in random order, enough to make at a level 4 B-tree
6408 * and then removes them all, by record and by index.
6409 *
6410 * Return: Success: 0
6411 * Failure: 1
6412 *
6413 * Programmer: Quincey Koziol
6414 * Tuesday, March 8, 2005
6415 *
6416 *-------------------------------------------------------------------------
6417 */
6418 static unsigned
test_remove_lots(const char * env_h5_drvr,hid_t fapl,const H5B2_create_t * cparam)6419 test_remove_lots(const char *env_h5_drvr, hid_t fapl, const H5B2_create_t *cparam)
6420 {
6421 hid_t file = -1; /* File ID */
6422 char filename[1024]; /* Filename to use */
6423 H5F_t *f = NULL; /* Internal file object pointer */
6424 int fd = -1; /* File descriptor */
6425 h5_stat_t sb; /* Stat buffer for file */
6426 void *file_data = NULL; /* Copy of file data */
6427 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
6428 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
6429 haddr_t bt2_addr; /* Address of B-tree created */
6430 hsize_t record; /* Record to insert into tree */
6431 hsize_t rrecord; /* Record to remove from tree */
6432 haddr_t root_addr; /* Address of root of B-tree created */
6433 time_t curr_time; /* Current time, for seeding random number generator */
6434 hsize_t *records; /* Record #'s for random insertion */
6435 unsigned u; /* Local index variable */
6436 unsigned rem_idx; /* Location to remove */
6437 hsize_t nrec; /* Number of records in B-tree */
6438 hbool_t single_file_vfd; /* Whether VFD used stores data in a single file */
6439
6440 /* Initialize random number seed */
6441 curr_time = HDtime(NULL);
6442 #ifdef QAK
6443 curr_time = 1163537969;
6444 HDfprintf(stderr, "curr_time = %lu\n", (unsigned long)curr_time);
6445 #endif /* QAK */
6446 HDsrandom((unsigned)curr_time);
6447
6448 /*
6449 * Test removing many records into v2 B-tree
6450 */
6451
6452 /* Allocate space for the records */
6453 if(NULL == (records = (hsize_t *)HDmalloc(sizeof(hsize_t) * INSERT_MANY)))
6454 TEST_ERROR
6455
6456 /* Initialize record #'s */
6457 for(u = 0; u < INSERT_MANY; u++)
6458 records[u] = u;
6459
6460 /* Shuffle record #'s */
6461 for(u = 0; u < INSERT_MANY; u++) {
6462 hsize_t temp_rec; /* Temporary record */
6463 unsigned swap_idx; /* Location to swap with when shuffling */
6464
6465 swap_idx = ((unsigned)HDrandom() % (INSERT_MANY - u)) + u;
6466 temp_rec = records[u];
6467 records[u] = records[swap_idx];
6468 records[swap_idx] = temp_rec;
6469 } /* end for */
6470
6471 h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
6472
6473 /* Generate the v2 B-tree to test */
6474 if(gen_l4_btree2(filename, fapl, cparam, &bt2_addr, records))
6475 TEST_ERROR
6476
6477 /* Check for VFD which stores data in multiple files */
6478 single_file_vfd = (hbool_t)(HDstrcmp(env_h5_drvr, "split") && HDstrcmp(env_h5_drvr, "multi") && HDstrcmp(env_h5_drvr, "family"));
6479 if(single_file_vfd) {
6480 /* Make a copy of the file in memory, in order to speed up deletion testing */
6481
6482 /* Open the file just created */
6483 if((fd = HDopen(filename, O_RDONLY, 0)) < 0)
6484 TEST_ERROR
6485
6486 /* Retrieve the file's size */
6487 if(HDfstat(fd, &sb) < 0)
6488 TEST_ERROR
6489
6490 /* Allocate space for the file data */
6491 if(NULL == (file_data = HDmalloc((size_t)sb.st_size)))
6492 TEST_ERROR
6493
6494 /* Read file's data into memory */
6495 if(HDread(fd, file_data, (size_t)sb.st_size) < (ssize_t)sb.st_size)
6496 TEST_ERROR
6497
6498 /* Close the file */
6499 if(HDclose(fd) < 0)
6500 TEST_ERROR
6501 fd = -1;
6502 } /* end if */
6503
6504 /* Print banner for this test */
6505 TESTING("B-tree remove: create random level 4 B-tree and delete all records in random order");
6506
6507 /* Re-open the file */
6508 if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
6509 FAIL_STACK_ERROR
6510
6511 /* Get a pointer to the internal file object */
6512 if(NULL == (f = (H5F_t *)H5I_object(file)))
6513 FAIL_STACK_ERROR
6514
6515 /* Re-shuffle record #'s */
6516 for(u = 0; u < INSERT_MANY; u++) {
6517 hsize_t temp_rec; /* Temporary record */
6518 unsigned swap_idx; /* Location to swap with when shuffling */
6519
6520 swap_idx = ((unsigned)HDrandom() % (INSERT_MANY - u)) + u;
6521 temp_rec = records[u];
6522 records[u] = records[swap_idx];
6523 records[swap_idx] = temp_rec;
6524 } /* end for */
6525
6526 /* Re-open v2 B-tree */
6527 if(NULL == (bt2 = H5B2_open(f, dxpl, bt2_addr, f)))
6528 FAIL_STACK_ERROR
6529
6530 /* Remove all records */
6531 for(u = 0; u < INSERT_MANY; u++) {
6532 record = records[u];
6533 rrecord = HSIZET_MAX;
6534 if(H5B2_remove(bt2, dxpl, &record, remove_cb, &rrecord) < 0)
6535 FAIL_STACK_ERROR
6536
6537 /* Make certain that the record value is correct */
6538 if(rrecord != records[u])
6539 TEST_ERROR
6540
6541 /* Query the number of records in the B-tree */
6542 if(H5B2_get_nrec(bt2, &nrec) < 0)
6543 FAIL_STACK_ERROR
6544
6545 /* Make certain that the # of records is correct */
6546 if(nrec != (INSERT_MANY - (u + 1)))
6547 TEST_ERROR
6548 } /* end for */
6549
6550 /* Query the address of the root node in the B-tree */
6551 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
6552 FAIL_STACK_ERROR
6553
6554 /* Make certain that the address of the root node is defined */
6555 if(H5F_addr_defined(root_addr))
6556 TEST_ERROR
6557
6558 /* Close the v2 B-tree */
6559 if(H5B2_close(bt2, dxpl) < 0)
6560 FAIL_STACK_ERROR
6561 bt2 = NULL;
6562
6563 /* Close file */
6564 if(H5Fclose(file) < 0)
6565 STACK_ERROR
6566
6567 PASSED();
6568
6569
6570
6571 /* Check for VFD which stores data in multiple files */
6572 if(single_file_vfd) {
6573 /* Re-write the file's data with the copy in memory */
6574
6575 /* Open the file just created */
6576 if((fd = HDopen(filename, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0)
6577 TEST_ERROR
6578
6579 /* Write file's data from memory */
6580 if(HDwrite(fd, file_data, (size_t)sb.st_size) < (ssize_t)sb.st_size)
6581 TEST_ERROR
6582
6583 /* Close the file */
6584 if(HDclose(fd) < 0)
6585 TEST_ERROR
6586 fd = -1;
6587 } /* end if */
6588 else {
6589 /* Re-generate the v2 B-tree to test */
6590 if(gen_l4_btree2(filename, fapl, cparam, &bt2_addr, records))
6591 TEST_ERROR
6592 } /* end else */
6593
6594
6595 /* Print banner for this test */
6596 TESTING("B-tree remove: create random level 4 B-tree and delete all records by index, in random order");
6597
6598 /* Re-open the file */
6599 if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
6600 FAIL_STACK_ERROR
6601
6602 /* Get a pointer to the internal file object */
6603 if(NULL == (f = (H5F_t *)H5I_object(file)))
6604 FAIL_STACK_ERROR
6605
6606 /* Re-open v2 B-tree */
6607 if(NULL == (bt2 = H5B2_open(f, dxpl, bt2_addr, f)))
6608 FAIL_STACK_ERROR
6609
6610 /* Remove all records */
6611 for(u = 0; u < INSERT_MANY; u++) {
6612 /* Pick a record index to remove from randomly */
6613 rem_idx = ((unsigned)HDrandom() % (INSERT_MANY - u));
6614 rrecord = HSIZET_MAX;
6615
6616 /* Remove random record */
6617 if(H5B2_remove_by_idx(bt2, dxpl, H5_ITER_INC, (hsize_t)rem_idx, remove_cb, &rrecord) < 0)
6618 FAIL_STACK_ERROR
6619
6620 /* Make certain that the record value is correct */
6621 if(rrecord >= INSERT_MANY)
6622 TEST_ERROR
6623
6624 /* Query the number of records in the B-tree */
6625 if(H5B2_get_nrec(bt2, &nrec) < 0)
6626 FAIL_STACK_ERROR
6627
6628 /* Make certain that the # of records is correct */
6629 if(nrec != (INSERT_MANY - (u + 1)))
6630 TEST_ERROR
6631 } /* end for */
6632
6633 /* Query the address of the root node in the B-tree */
6634 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
6635 FAIL_STACK_ERROR
6636
6637 /* Make certain that the address of the root node is defined */
6638 if(H5F_addr_defined(root_addr))
6639 TEST_ERROR
6640
6641 /* Close the v2 B-tree */
6642 if(H5B2_close(bt2, dxpl) < 0)
6643 FAIL_STACK_ERROR
6644 bt2 = NULL;
6645
6646 /* Close file */
6647 if(H5Fclose(file) < 0)
6648 STACK_ERROR
6649
6650 PASSED();
6651
6652
6653
6654 /* Check for VFD which stores data in multiple files */
6655 if(single_file_vfd) {
6656 /* Re-write the file's data with the copy in memory */
6657
6658 /* Open the file just created */
6659 if((fd = HDopen(filename, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0)
6660 TEST_ERROR
6661
6662 /* Write file's data from memory */
6663 if(HDwrite(fd, file_data, (size_t)sb.st_size) < (ssize_t)sb.st_size)
6664 TEST_ERROR
6665
6666 /* Close the file */
6667 if(HDclose(fd) < 0)
6668 TEST_ERROR
6669 fd = -1;
6670 } /* end if */
6671 else {
6672 /* Re-generate the v2 B-tree to test */
6673 if(gen_l4_btree2(filename, fapl, cparam, &bt2_addr, records))
6674 TEST_ERROR
6675 } /* end else */
6676
6677
6678
6679 /* Print banner for this test */
6680 TESTING("B-tree remove: create random level 4 B-tree and delete all records by index, in increasing order");
6681
6682 /* Re-open the file */
6683 if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
6684 FAIL_STACK_ERROR
6685
6686 /* Get a pointer to the internal file object */
6687 if(NULL == (f = (H5F_t *)H5I_object(file)))
6688 FAIL_STACK_ERROR
6689
6690 /* Re-open v2 B-tree */
6691 if(NULL == (bt2 = H5B2_open(f, dxpl, bt2_addr, f)))
6692 FAIL_STACK_ERROR
6693
6694 /* Remove all records */
6695 for(u = 0; u < INSERT_MANY; u++) {
6696 /* Remove first record */
6697 rrecord = HSIZET_MAX;
6698 if(H5B2_remove_by_idx(bt2, dxpl, H5_ITER_INC, (hsize_t)0, remove_cb, &rrecord) < 0)
6699 FAIL_STACK_ERROR
6700
6701 /* Make certain that the record value is correct */
6702 if(rrecord != u)
6703 TEST_ERROR
6704
6705 /* Query the number of records in the B-tree */
6706 if(H5B2_get_nrec(bt2, &nrec) < 0)
6707 FAIL_STACK_ERROR
6708
6709 /* Make certain that the # of records is correct */
6710 if(nrec != (INSERT_MANY - (u + 1)))
6711 TEST_ERROR
6712 } /* end for */
6713
6714 /* Query the address of the root node in the B-tree */
6715 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
6716 FAIL_STACK_ERROR
6717
6718 /* Make certain that the address of the root node is defined */
6719 if(H5F_addr_defined(root_addr))
6720 TEST_ERROR
6721
6722 /* Close the v2 B-tree */
6723 if(H5B2_close(bt2, dxpl) < 0)
6724 FAIL_STACK_ERROR
6725 bt2 = NULL;
6726
6727 /* Close file */
6728 if(H5Fclose(file) < 0)
6729 STACK_ERROR
6730
6731 PASSED();
6732
6733
6734
6735 /* Check for VFD which stores data in multiple files */
6736 if(single_file_vfd) {
6737 /* Re-write the file's data with the copy in memory */
6738
6739 /* Open the file just created */
6740 if((fd = HDopen(filename, O_RDWR|O_CREAT|O_TRUNC, 0666)) < 0)
6741 TEST_ERROR
6742
6743 /* Write file's data from memory */
6744 if(HDwrite(fd, file_data, (size_t)sb.st_size) < (ssize_t)sb.st_size)
6745 TEST_ERROR
6746
6747 /* Close the file */
6748 if(HDclose(fd) < 0)
6749 TEST_ERROR
6750 fd = -1;
6751 } /* end if */
6752 else {
6753 /* Re-generate the v2 B-tree to test */
6754 if(gen_l4_btree2(filename, fapl, cparam, &bt2_addr, records))
6755 TEST_ERROR
6756 } /* end else */
6757
6758
6759
6760 /* Print banner for this test */
6761 TESTING("B-tree remove: create random level 4 B-tree and delete all records by index, in decreasing order");
6762
6763 /* Re-open the file */
6764 if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
6765 FAIL_STACK_ERROR
6766
6767 /* Get a pointer to the internal file object */
6768 if(NULL == (f = (H5F_t *)H5I_object(file)))
6769 FAIL_STACK_ERROR
6770
6771 /* Re-open v2 B-tree */
6772 if(NULL == (bt2 = H5B2_open(f, dxpl, bt2_addr, f)))
6773 FAIL_STACK_ERROR
6774
6775 /* Remove all records */
6776 for(u = 0; u < INSERT_MANY; u++) {
6777 /* Remove last record */
6778 rrecord = HSIZET_MAX;
6779 if(H5B2_remove_by_idx(bt2, dxpl, H5_ITER_DEC, (hsize_t)0, remove_cb, &rrecord) < 0)
6780 FAIL_STACK_ERROR
6781
6782 /* Make certain that the record value is correct */
6783 if(rrecord != (INSERT_MANY - (u + 1)))
6784 TEST_ERROR
6785
6786 /* Query the number of records in the B-tree */
6787 if(H5B2_get_nrec(bt2, &nrec) < 0)
6788 FAIL_STACK_ERROR
6789
6790 /* Make certain that the # of records is correct */
6791 if(nrec != (INSERT_MANY - (u + 1)))
6792 TEST_ERROR
6793 } /* end for */
6794
6795 /* Query the address of the root node in the B-tree */
6796 if(H5B2_get_root_addr_test(bt2, &root_addr) < 0)
6797 FAIL_STACK_ERROR
6798
6799 /* Make certain that the address of the root node is defined */
6800 if(H5F_addr_defined(root_addr))
6801 TEST_ERROR
6802
6803 /* Close the v2 B-tree */
6804 if(H5B2_close(bt2, dxpl) < 0)
6805 FAIL_STACK_ERROR
6806 bt2 = NULL;
6807
6808 /* Close file */
6809 if(H5Fclose(file) < 0)
6810 STACK_ERROR
6811
6812 PASSED();
6813
6814 if(records)
6815 HDfree(records);
6816 if(file_data)
6817 HDfree(file_data);
6818
6819 return 0;
6820
6821 error:
6822 H5E_BEGIN_TRY {
6823 if(bt2)
6824 H5B2_close(bt2, dxpl);
6825 H5Fclose(file);
6826 } H5E_END_TRY;
6827
6828 if(fd > 0)
6829 HDclose(fd);
6830 if(records)
6831 HDfree(records);
6832 if(file_data)
6833 HDfree(file_data);
6834
6835 return 1;
6836 } /* test_remove_lots() */
6837
6838
6839 /*-------------------------------------------------------------------------
6840 * Function: test_find_neighbor
6841 *
6842 * Purpose: Basic tests for the B-tree v2 code. This test exercises
6843 * code to find nearest neighbors to a given value in a B-tree.
6844 *
6845 * Return: Success: 0
6846 * Failure: 1
6847 *
6848 * Programmer: Quincey Koziol
6849 * Tuesday, March 8, 2005
6850 *
6851 *-------------------------------------------------------------------------
6852 */
6853 static unsigned
test_find_neighbor(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)6854 test_find_neighbor(hid_t fapl, const H5B2_create_t *cparam,
6855 const bt2_test_param_t *tparam)
6856 {
6857 hid_t file = -1; /* File ID */
6858 H5F_t *f = NULL; /* Internal file object pointer */
6859 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
6860 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
6861 haddr_t bt2_addr; /* Address of B-tree created */
6862 hsize_t record; /* Record to insert into tree */
6863 hsize_t search; /* Search value */
6864 hsize_t *records; /* Record #'s for random insertion */
6865 unsigned u; /* Local index variable */
6866 H5B2_node_info_test_t ninfo; /* B-tree node info */
6867 herr_t ret; /* Generic error return value */
6868
6869 /* Allocate space for the records */
6870 if(NULL == (records = (hsize_t *)HDmalloc(sizeof(hsize_t) * FIND_NEIGHBOR)))
6871 TEST_ERROR
6872
6873 /* Initialize record #'s */
6874 for(u = 0; u < FIND_NEIGHBOR; u++)
6875 records[u] = u * 2;
6876
6877 /*
6878 * Test nearest neighbor for '<' cases
6879 */
6880 TESTING("B-tree find: nearest neighbor less than a value");
6881
6882 /* Create the file for the test */
6883 if(create_file(&file, &f, fapl) < 0)
6884 TEST_ERROR
6885
6886 /* Create the v2 B-tree & get its address */
6887 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
6888 TEST_ERROR
6889
6890 /* Insert records */
6891 for(u = 0; u < FIND_NEIGHBOR; u++) {
6892 record = records[u];
6893 if(H5B2_insert(bt2, dxpl, &record) < 0)
6894 FAIL_STACK_ERROR
6895 } /* end for */
6896
6897 /* Attempt to find record B-tree less than a value */
6898 search = 0;
6899 H5E_BEGIN_TRY {
6900 ret = H5B2_neighbor(bt2, dxpl, H5B2_COMPARE_LESS, &search, neighbor_cb, &record);
6901 } H5E_END_TRY;
6902 /* Should fail */
6903 if(ret != FAIL)
6904 TEST_ERROR
6905
6906 search = 1;
6907 if(H5B2_neighbor(bt2, dxpl, H5B2_COMPARE_LESS, &search, neighbor_cb, &record) < 0)
6908 FAIL_STACK_ERROR
6909 if(record != 0)
6910 TEST_ERROR
6911
6912 search = 2;
6913 if(H5B2_neighbor(bt2, dxpl, H5B2_COMPARE_LESS, &search, neighbor_cb, &record) < 0)
6914 FAIL_STACK_ERROR
6915 if(record != 0)
6916 TEST_ERROR
6917
6918 search = 3;
6919 if(H5B2_neighbor(bt2, dxpl, H5B2_COMPARE_LESS, &search, neighbor_cb, &record) < 0)
6920 FAIL_STACK_ERROR
6921 if(record != 2)
6922 TEST_ERROR
6923
6924 search = 4;
6925 if(H5B2_neighbor(bt2, dxpl, H5B2_COMPARE_LESS, &search, neighbor_cb, &record) < 0)
6926 FAIL_STACK_ERROR
6927 if(record != 2)
6928 TEST_ERROR
6929
6930 /* Check status of B-tree */
6931 ninfo.depth = 1;
6932 ninfo.nrec = 14;
6933 record = 250; /* Record in left internal node */
6934 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
6935 TEST_ERROR
6936
6937 /* Neighbor is in internal node */
6938 search = 251;
6939 if(H5B2_neighbor(bt2, dxpl, H5B2_COMPARE_LESS, &search, neighbor_cb, &record) < 0)
6940 FAIL_STACK_ERROR
6941 if(record != 250)
6942 TEST_ERROR
6943
6944 /* Check status of B-tree */
6945 ninfo.depth = 2;
6946 ninfo.nrec = 1;
6947 record = 1888; /* Record in root node */
6948 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
6949 TEST_ERROR
6950
6951 /* Neighbor is in root node */
6952 search = 1889;
6953 if(H5B2_neighbor(bt2, dxpl, H5B2_COMPARE_LESS, &search, neighbor_cb, &record) < 0)
6954 FAIL_STACK_ERROR
6955 if(record != 1888)
6956 TEST_ERROR
6957
6958 search = (FIND_NEIGHBOR * 2) + 1;
6959 if(H5B2_neighbor(bt2, dxpl, H5B2_COMPARE_LESS, &search, neighbor_cb, &record) < 0)
6960 FAIL_STACK_ERROR
6961 if(record != ((FIND_NEIGHBOR - 1) * 2))
6962 TEST_ERROR
6963
6964 PASSED();
6965
6966 /*
6967 * Test nearest neighbor for '>' cases
6968 */
6969 TESTING("B-tree find: nearest neighbor greater than a value");
6970
6971 /* Check for closing & re-opening the B-tree */
6972 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
6973 TEST_ERROR
6974
6975 /* Attempt to find record B-tree less than a value */
6976 search = (FIND_NEIGHBOR * 2) + 1;
6977 H5E_BEGIN_TRY {
6978 ret = H5B2_neighbor(bt2, dxpl, H5B2_COMPARE_GREATER, &search, neighbor_cb, &record);
6979 } H5E_END_TRY;
6980 /* Should fail */
6981 if(ret != FAIL)
6982 TEST_ERROR
6983
6984 search = 0;
6985 if(H5B2_neighbor(bt2, dxpl, H5B2_COMPARE_GREATER, &search, neighbor_cb, &record) < 0)
6986 FAIL_STACK_ERROR
6987 if(record != 2)
6988 TEST_ERROR
6989
6990 search = 1;
6991 if(H5B2_neighbor(bt2, dxpl, H5B2_COMPARE_GREATER, &search, neighbor_cb, &record) < 0)
6992 FAIL_STACK_ERROR
6993 if(record != 2)
6994 TEST_ERROR
6995
6996 search = 2;
6997 if(H5B2_neighbor(bt2, dxpl, H5B2_COMPARE_GREATER, &search, neighbor_cb, &record) < 0)
6998 FAIL_STACK_ERROR
6999 if(record != 4)
7000 TEST_ERROR
7001
7002 search = 3;
7003 if(H5B2_neighbor(bt2, dxpl, H5B2_COMPARE_GREATER, &search, neighbor_cb, &record) < 0)
7004 FAIL_STACK_ERROR
7005 if(record != 4)
7006 TEST_ERROR
7007
7008 /* Check status of B-tree */
7009 ninfo.depth = 1;
7010 ninfo.nrec = 16;
7011 record = 2896; /* Record in right internal node */
7012 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
7013 TEST_ERROR
7014
7015 /* Neighbor is in internal node */
7016 search = 2895;
7017 if(H5B2_neighbor(bt2, dxpl, H5B2_COMPARE_GREATER, &search, neighbor_cb, &record) < 0)
7018 FAIL_STACK_ERROR
7019 if(record != 2896)
7020 TEST_ERROR
7021
7022 /* Neighbor is in root node */
7023 search = 1887;
7024 if(H5B2_neighbor(bt2, dxpl, H5B2_COMPARE_GREATER, &search, neighbor_cb, &record) < 0)
7025 FAIL_STACK_ERROR
7026 if(record != 1888)
7027 TEST_ERROR
7028
7029 search = ((FIND_NEIGHBOR - 1) * 2) - 1;
7030 if(H5B2_neighbor(bt2, dxpl, H5B2_COMPARE_GREATER, &search, neighbor_cb, &record) < 0)
7031 FAIL_STACK_ERROR
7032 if(record != ((FIND_NEIGHBOR - 1) * 2))
7033 TEST_ERROR
7034
7035 /* Close the v2 B-tree */
7036 if(H5B2_close(bt2, dxpl) < 0)
7037 FAIL_STACK_ERROR
7038 bt2 = NULL;
7039
7040 /* Close file */
7041 if(H5Fclose(file) < 0)
7042 STACK_ERROR
7043
7044 PASSED();
7045
7046 HDfree(records);
7047
7048 return 0;
7049
7050 error:
7051 H5E_BEGIN_TRY {
7052 if(bt2)
7053 H5B2_close(bt2, dxpl);
7054 H5Fclose(file);
7055 } H5E_END_TRY;
7056 HDfree(records);
7057 return 1;
7058 } /* test_find_neighbor() */
7059
7060
7061 /*-------------------------------------------------------------------------
7062 * Function: test_delete
7063 *
7064 * Purpose: Basic tests for the B-tree v2 code. This test exercises
7065 * code to delete a B-tree from a file
7066 *
7067 * Return: Success: 0
7068 * Failure: 1
7069 *
7070 * Programmer: Quincey Koziol
7071 * Wednesday, March 9, 2005
7072 *
7073 *-------------------------------------------------------------------------
7074 */
7075 static unsigned
test_delete(hid_t fapl,const H5B2_create_t * cparam)7076 test_delete(hid_t fapl, const H5B2_create_t *cparam)
7077 {
7078 hid_t file = -1; /* File ID */
7079 char filename[1024]; /* Filename to use */
7080 H5F_t *f = NULL; /* Internal file object pointer */
7081 h5_stat_size_t empty_size; /* Size of an empty file */
7082 h5_stat_size_t file_size; /* Size of each file created */
7083 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
7084 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
7085 haddr_t bt2_addr; /* Address of B-tree created */
7086 hsize_t record; /* Record to insert into tree */
7087 H5B2_stat_t bt2_stat; /* Statistics about B-tree created */
7088 unsigned u; /* Local index variable */
7089
7090 h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
7091
7092 /* Attempt to delete empty B-tree */
7093 TESTING("B-tree delete: delete empty B-tree");
7094
7095 /* Create empty file for size comparisons later */
7096
7097 /* Create the file to work on */
7098 if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
7099 STACK_ERROR
7100
7101 /* Close file */
7102 if(H5Fclose(file) < 0)
7103 STACK_ERROR
7104
7105 /* Get the size of an empty file */
7106 if((empty_size = h5_get_file_size(filename, fapl)) < 0)
7107 TEST_ERROR
7108
7109 /* Create the file to work on */
7110 if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
7111 STACK_ERROR
7112
7113 /* Get a pointer to the internal file object */
7114 if(NULL == (f = (H5F_t *)H5I_object(file)))
7115 STACK_ERROR
7116
7117 /* Create the v2 B-tree & get its address */
7118 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
7119 TEST_ERROR
7120
7121 /* Close the v2 B-tree */
7122 if(H5B2_close(bt2, dxpl) < 0)
7123 FAIL_STACK_ERROR
7124 bt2 = NULL;
7125
7126 /*
7127 * Delete v2 B-tree
7128 */
7129 if(H5B2_delete(f, dxpl, bt2_addr, f, NULL, NULL) < 0)
7130 FAIL_STACK_ERROR
7131
7132 /* Close the file */
7133 if(H5Fclose(file) < 0)
7134 STACK_ERROR
7135
7136 /* Get the size of the file */
7137 if((file_size = h5_get_file_size(filename, fapl)) < 0)
7138 TEST_ERROR
7139
7140 /* Verify the file is correct size */
7141 if(file_size != empty_size)
7142 TEST_ERROR
7143
7144 PASSED();
7145
7146 /* Attempt to delete level-0 B-tree */
7147 TESTING("B-tree delete: delete level-0 B-tree");
7148
7149 /* Create the file to work on */
7150 if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
7151 STACK_ERROR
7152
7153 /* Get a pointer to the internal file object */
7154 if(NULL == (f = (H5F_t *)H5I_object(file)))
7155 STACK_ERROR
7156
7157 /* Create the v2 B-tree & get its address */
7158 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
7159 TEST_ERROR
7160
7161 /* Insert records */
7162 for(u = 0; u < DELETE_SMALL; u++) {
7163 record = u;
7164 if(H5B2_insert(bt2, dxpl, &record) < 0)
7165 FAIL_STACK_ERROR
7166 } /* end for */
7167
7168 /* Check up on B-tree */
7169 if(H5B2_stat_info(bt2, &bt2_stat) < 0)
7170 FAIL_STACK_ERROR
7171 if(bt2_stat.depth != 0)
7172 TEST_ERROR
7173
7174 /* Close the v2 B-tree */
7175 if(H5B2_close(bt2, dxpl) < 0)
7176 FAIL_STACK_ERROR
7177 bt2 = NULL;
7178
7179 /*
7180 * Delete v2 B-tree
7181 */
7182 if(H5B2_delete(f, H5P_DATASET_XFER_DEFAULT, bt2_addr, f, NULL, NULL) < 0)
7183 FAIL_STACK_ERROR
7184
7185 /* Close file */
7186 if(H5Fclose(file) < 0)
7187 STACK_ERROR
7188
7189 /* Get the size of the file */
7190 if((file_size = h5_get_file_size(filename, fapl)) < 0)
7191 TEST_ERROR
7192
7193 /* Verify the file is correct size */
7194 if(file_size != empty_size)
7195 TEST_ERROR
7196
7197 PASSED();
7198
7199 /* Attempt to delete level-1 B-tree */
7200 TESTING("B-tree delete: delete level-1 B-tree");
7201
7202 /* Create the file to work on */
7203 if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
7204 STACK_ERROR
7205
7206 /* Get a pointer to the internal file object */
7207 if(NULL == (f = (H5F_t *)H5I_object(file)))
7208 STACK_ERROR
7209
7210 /* Create the v2 B-tree & get its address */
7211 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
7212 TEST_ERROR
7213
7214 /* Insert records */
7215 for(u = 0; u < DELETE_MEDIUM; u++) {
7216 record = u;
7217 if(H5B2_insert(bt2, dxpl, &record) < 0)
7218 FAIL_STACK_ERROR
7219 } /* end for */
7220
7221 /* Check up on B-tree */
7222 if(H5B2_stat_info(bt2, &bt2_stat) < 0)
7223 FAIL_STACK_ERROR
7224 if(bt2_stat.depth != 1)
7225 TEST_ERROR
7226
7227 /* Close the v2 B-tree */
7228 if(H5B2_close(bt2, dxpl) < 0)
7229 FAIL_STACK_ERROR
7230 bt2 = NULL;
7231
7232 /*
7233 * Delete v2 B-tree
7234 */
7235 if(H5B2_delete(f, dxpl, bt2_addr, f, NULL, NULL) < 0)
7236 FAIL_STACK_ERROR
7237
7238 /* Close file */
7239 if(H5Fclose(file) < 0)
7240 STACK_ERROR
7241
7242 /* Get the size of the file */
7243 if((file_size = h5_get_file_size(filename, fapl)) < 0)
7244 TEST_ERROR
7245
7246 /* Verify the file is correct size */
7247 if(file_size != empty_size)
7248 TEST_ERROR
7249
7250 PASSED();
7251
7252 /* Attempt to delete level-2 B-tree */
7253 TESTING("B-tree delete: delete level-2 B-tree");
7254
7255 /* Create the file to work on */
7256 if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
7257 STACK_ERROR
7258
7259 /* Get a pointer to the internal file object */
7260 if(NULL == (f = (H5F_t *)H5I_object(file)))
7261 STACK_ERROR
7262
7263 /* Create the v2 B-tree & get its address */
7264 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
7265 TEST_ERROR
7266
7267 /* Insert records */
7268 for(u = 0; u < DELETE_LARGE; u++) {
7269 record = u;
7270 if(H5B2_insert(bt2, dxpl, &record) < 0)
7271 FAIL_STACK_ERROR
7272 } /* end for */
7273
7274 /* Check up on B-tree */
7275 if(H5B2_stat_info(bt2, &bt2_stat) < 0)
7276 FAIL_STACK_ERROR
7277 if(bt2_stat.depth != 2)
7278 TEST_ERROR
7279
7280 /* Close the v2 B-tree */
7281 if(H5B2_close(bt2, dxpl) < 0)
7282 FAIL_STACK_ERROR
7283 bt2 = NULL;
7284
7285 /*
7286 * Delete v2 B-tree
7287 */
7288 if(H5B2_delete(f, dxpl, bt2_addr, f, NULL, NULL) < 0)
7289 FAIL_STACK_ERROR
7290
7291 /* Close file */
7292 if(H5Fclose(file) < 0)
7293 STACK_ERROR
7294
7295 /* Get the size of the file */
7296 if((file_size = h5_get_file_size(filename, fapl)) < 0)
7297 TEST_ERROR
7298
7299 /* Verify the file is correct size */
7300 if(file_size != empty_size)
7301 TEST_ERROR
7302
7303 PASSED();
7304
7305 return 0;
7306
7307 error:
7308 H5E_BEGIN_TRY {
7309 if(bt2)
7310 H5B2_close(bt2, dxpl);
7311 H5Fclose(file);
7312 } H5E_END_TRY;
7313 return 1;
7314 } /* test_delete() */
7315
7316
7317 /*-------------------------------------------------------------------------
7318 * Function: test_modify
7319 *
7320 * Purpose: Basic tests for the B-tree v2 code. This test exercises
7321 * code to modify an existing record in the B-tree
7322 *
7323 * Return: Success: 0
7324 * Failure: 1
7325 *
7326 * Programmer: Quincey Koziol
7327 * Friday, March 10, 2005
7328 *
7329 *-------------------------------------------------------------------------
7330 */
7331 static unsigned
test_modify(hid_t fapl,const H5B2_create_t * cparam,const bt2_test_param_t * tparam)7332 test_modify(hid_t fapl, const H5B2_create_t *cparam,
7333 const bt2_test_param_t *tparam)
7334 {
7335 hid_t file = -1; /* File ID */
7336 H5F_t *f = NULL; /* Internal file object pointer */
7337 hid_t dxpl = H5P_DATASET_XFER_DEFAULT; /* DXPL to use */
7338 H5B2_t *bt2 = NULL; /* v2 B-tree wrapper */
7339 haddr_t bt2_addr; /* Address of B-tree created */
7340 hsize_t record; /* Record to insert into tree */
7341 hsize_t modify; /* Modified value */
7342 hsize_t found; /* Found value */
7343 H5B2_stat_t bt2_stat; /* Statistics about B-tree created */
7344 H5B2_node_info_test_t ninfo; /* B-tree node info */
7345 unsigned u; /* Local index variable */
7346 herr_t ret; /* Generic error return value */
7347
7348 /*
7349 * Test modifying records
7350 */
7351 TESTING("B-tree modify: attempt to modify non-existant record");
7352
7353 /* Create the file for the test */
7354 if(create_file(&file, &f, fapl) < 0)
7355 TEST_ERROR
7356
7357 /* Create the v2 B-tree & get its address */
7358 if(create_btree(f, dxpl, cparam, &bt2, &bt2_addr) < 0)
7359 TEST_ERROR
7360
7361 /* Create level-2 B-tree with 3 internal nodes */
7362 for(u = 0; u < ((INSERT_SPLIT_ROOT_NREC * 59) + 1); u++) {
7363 record = u * 5;
7364 if(H5B2_insert(bt2, dxpl, &record) < 0)
7365 FAIL_STACK_ERROR
7366 } /* end for */
7367
7368 /* Check up on B-tree */
7369 if(H5B2_stat_info(bt2, &bt2_stat) < 0)
7370 FAIL_STACK_ERROR
7371 if(bt2_stat.depth != 2)
7372 TEST_ERROR
7373
7374 /* Attempt to modify a non-existant record */
7375 record = 3;
7376 modify = 4;
7377 H5E_BEGIN_TRY {
7378 ret = H5B2_modify(bt2, dxpl, &record, modify_cb, &modify);
7379 } H5E_END_TRY;
7380 /* Should fail */
7381 if(ret != FAIL)
7382 TEST_ERROR
7383
7384 PASSED();
7385
7386 TESTING("B-tree modify: modify record in leaf node");
7387
7388 /* Check for closing & re-opening the B-tree */
7389 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
7390 TEST_ERROR
7391
7392 /* Check status of B-tree */
7393 ninfo.depth = 0;
7394 ninfo.nrec = 62;
7395 record = 4330; /* Record in leaf node */
7396 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
7397 TEST_ERROR
7398
7399 /* Attempt to modify a record in a leaf node */
7400 record = 4330;
7401 modify = 4331;
7402 if(H5B2_modify(bt2, dxpl, &record, modify_cb, &modify) < 0)
7403 FAIL_STACK_ERROR
7404
7405 /* Check status of B-tree */
7406 ninfo.depth = 0;
7407 ninfo.nrec = 62;
7408 record = 4331; /* Record in leaf node */
7409 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
7410 TEST_ERROR
7411
7412 /* Attempt to find modified record */
7413 record = 4331;
7414 found = 4331;
7415 if(H5B2_find(bt2, dxpl, &record, find_cb, &found) != TRUE)
7416 FAIL_STACK_ERROR
7417 if(found != 4331)
7418 TEST_ERROR
7419
7420 /* Attempt to find original record */
7421 record = 4330;
7422 found = HSIZET_MAX;
7423 H5E_BEGIN_TRY {
7424 ret = H5B2_modify(bt2, dxpl, &record, modify_cb, &modify);
7425 } H5E_END_TRY;
7426 /* Should fail */
7427 if(ret != FAIL)
7428 TEST_ERROR
7429
7430 PASSED();
7431
7432 TESTING("B-tree modify: modify record in internal node");
7433
7434 /* Check for closing & re-opening the B-tree */
7435 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
7436 TEST_ERROR
7437
7438 /* Check status of B-tree */
7439 ninfo.depth = 1;
7440 ninfo.nrec = 29;
7441 record = 5350; /* Record in internal node */
7442 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
7443 TEST_ERROR
7444
7445 /* Attempt to modify a record in an internal node */
7446 record = 5350;
7447 modify = 5352;
7448 if(H5B2_modify(bt2, dxpl, &record, modify_cb, &modify) < 0)
7449 FAIL_STACK_ERROR
7450
7451 /* Check status of B-tree */
7452 ninfo.depth = 1;
7453 ninfo.nrec = 29;
7454 record = 5352; /* Record in internal node */
7455 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
7456 TEST_ERROR
7457
7458 /* Attempt to find modified record */
7459 record = 5352;
7460 found = 5352;
7461 if(H5B2_find(bt2, dxpl, &record, find_cb, &found) != TRUE)
7462 STACK_ERROR
7463 if(found != 5352)
7464 TEST_ERROR
7465
7466 /* Attempt to find original record */
7467 record = 5350;
7468 found = 5350;
7469 H5E_BEGIN_TRY {
7470 ret = H5B2_modify(bt2, dxpl, &record, modify_cb, &modify);
7471 } H5E_END_TRY;
7472 /* Should fail */
7473 if(ret != FAIL)
7474 TEST_ERROR
7475
7476 PASSED();
7477
7478 TESTING("B-tree modify: modify record in root node");
7479
7480 /* Check for closing & re-opening the B-tree */
7481 if(reopen_btree(f, dxpl, &bt2, bt2_addr, tparam) < 0)
7482 TEST_ERROR
7483
7484 /* Check status of B-tree */
7485 ninfo.depth = 2;
7486 ninfo.nrec = 2;
7487 record = 9445; /* Record in root node */
7488 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
7489 TEST_ERROR
7490
7491 /* Attempt to modify a record in a root node */
7492 record = 9445;
7493 modify = 9448;
7494 if(H5B2_modify(bt2, dxpl, &record, modify_cb, &modify) < 0)
7495 FAIL_STACK_ERROR
7496
7497 /* Check status of B-tree */
7498 ninfo.depth = 2;
7499 ninfo.nrec = 2;
7500 record = 9448; /* Record in root node */
7501 if(check_node_info(bt2, dxpl, record, &ninfo) < 0)
7502 TEST_ERROR
7503
7504 /* Attempt to find modified record */
7505 record = 9448;
7506 found = 9448;
7507 if(H5B2_find(bt2, dxpl, &record, find_cb, &found) != TRUE)
7508 STACK_ERROR
7509 if(found != 9448)
7510 TEST_ERROR
7511
7512 /* Attempt to find original record */
7513 record = 9445;
7514 found = 9445;
7515 H5E_BEGIN_TRY {
7516 ret = H5B2_modify(bt2, dxpl, &record, modify_cb, &modify);
7517 } H5E_END_TRY;
7518 /* Should fail */
7519 if(ret != FAIL)
7520 TEST_ERROR
7521
7522 /* Close the v2 B-tree */
7523 if(H5B2_close(bt2, dxpl) < 0)
7524 FAIL_STACK_ERROR
7525 bt2 = NULL;
7526
7527 /* Close file */
7528 if(H5Fclose(file) < 0)
7529 TEST_ERROR
7530
7531 PASSED();
7532
7533 return 0;
7534
7535 error:
7536 H5E_BEGIN_TRY {
7537 if(bt2)
7538 H5B2_close(bt2, dxpl);
7539 H5Fclose(file);
7540 } H5E_END_TRY;
7541 return 1;
7542 } /* test_modify() */
7543
7544
7545 /*-------------------------------------------------------------------------
7546 * Function: main
7547 *
7548 * Purpose: Test the B-tree v2 code
7549 *
7550 * Return: Success:
7551 *
7552 * Failure:
7553 *
7554 * Programmer: Quincey Koziol
7555 * Tuesday, February 1, 2005
7556 *
7557 *-------------------------------------------------------------------------
7558 */
7559 int
main(void)7560 main(void)
7561 {
7562 H5B2_create_t cparam; /* Creation parameters for v2 B-tree */
7563 bt2_test_param_t tparam; /* Test parameters for v2 B-tree */
7564 hid_t fapl = -1; /* File access property list for data files */
7565 unsigned nerrors = 0; /* Cumulative error count */
7566 hbool_t reopen; /* Whether to reopen B-tree during tests */
7567 int ExpressMode;
7568 const char *envval = NULL;
7569
7570 envval = HDgetenv("HDF5_DRIVER");
7571 if(envval == NULL)
7572 envval = "nomatch";
7573
7574 /* Reset library */
7575 h5_reset();
7576 fapl = h5_fileaccess();
7577 ExpressMode = GetTestExpress();
7578 if(ExpressMode > 1)
7579 printf("***Express test mode on. Some tests may be skipped\n");
7580
7581 /* Initialize v2 B-tree creation parameters */
7582 init_cparam(&cparam);
7583
7584
7585 /* Loop over re-opening B-tree during tests */
7586 for(reopen = FALSE; reopen <= TRUE; reopen++) {
7587 if(reopen) {
7588 fprintf(stdout, "Testing with reopening B-tree:\n");
7589 tparam.reopen_btree = TRUE;
7590 } /* end if */
7591 else {
7592 fprintf(stdout, "Testing without reopening B-tree:\n");
7593 tparam.reopen_btree = FALSE;
7594 } /* end else */
7595
7596 /* Test B-tree record insertion */
7597 /* Iteration, find & index routines tested in these routines as well */
7598 nerrors += test_insert_basic(fapl, &cparam, &tparam);
7599 nerrors += test_insert_split_root(fapl, &cparam, &tparam);
7600 nerrors += test_insert_level1_2leaf_redistrib(fapl, &cparam, &tparam);
7601 nerrors += test_insert_level1_side_split(fapl, &cparam, &tparam);
7602 nerrors += test_insert_level1_3leaf_redistrib(fapl, &cparam, &tparam);
7603 nerrors += test_insert_level1_middle_split(fapl, &cparam, &tparam);
7604 nerrors += test_insert_make_level2(fapl, &cparam, &tparam);
7605 nerrors += test_insert_level2_leaf_redistrib(fapl, &cparam, &tparam);
7606 nerrors += test_insert_level2_leaf_split(fapl, &cparam, &tparam);
7607 nerrors += test_insert_level2_2internal_redistrib(fapl, &cparam, &tparam);
7608 nerrors += test_insert_level2_2internal_split(fapl, &cparam, &tparam);
7609 nerrors += test_insert_level2_3internal_redistrib(fapl, &cparam, &tparam);
7610 nerrors += test_insert_level2_3internal_split(fapl, &cparam, &tparam);
7611 if(ExpressMode > 1)
7612 printf("***Express test mode on. test_insert_lots skipped\n");
7613 else
7614 nerrors += test_insert_lots(fapl, &cparam, &tparam);
7615
7616 /* Test B-tree record removal */
7617 /* Querying the number of records routine also tested in these routines as well */
7618 nerrors += test_remove_basic(fapl, &cparam, &tparam);
7619 nerrors += test_remove_level1_noredistrib(fapl, &cparam, &tparam);
7620 nerrors += test_remove_level1_redistrib(fapl, &cparam, &tparam);
7621 nerrors += test_remove_level1_2leaf_merge(fapl, &cparam, &tparam);
7622 nerrors += test_remove_level1_3leaf_merge(fapl, &cparam, &tparam);
7623 nerrors += test_remove_level1_promote(fapl, &cparam, &tparam);
7624 nerrors += test_remove_level1_promote_2leaf_redistrib(fapl, &cparam, &tparam);
7625 nerrors += test_remove_level1_promote_3leaf_redistrib(fapl, &cparam, &tparam);
7626 nerrors += test_remove_level1_promote_2leaf_merge(fapl, &cparam, &tparam);
7627 nerrors += test_remove_level1_promote_3leaf_merge(fapl, &cparam, &tparam);
7628 nerrors += test_remove_level1_collapse(fapl, &cparam, &tparam);
7629 nerrors += test_remove_level2_promote(fapl, &cparam, &tparam);
7630 nerrors += test_remove_level2_promote_2internal_redistrib(fapl, &cparam, &tparam);
7631 nerrors += test_remove_level2_promote_3internal_redistrib(fapl, &cparam, &tparam);
7632 nerrors += test_remove_level2_promote_2internal_merge(fapl, &cparam, &tparam);
7633 nerrors += test_remove_level2_promote_3internal_merge(fapl, &cparam, &tparam);
7634 nerrors += test_remove_level2_2internal_merge_left(fapl, &cparam, &tparam);
7635 nerrors += test_remove_level2_2internal_merge_right(fapl, &cparam, &tparam);
7636 nerrors += test_remove_level2_3internal_merge(fapl, &cparam, &tparam);
7637 nerrors += test_remove_level2_collapse_right(fapl, &cparam, &tparam);
7638 if(ExpressMode > 1)
7639 printf("***Express test mode on. test_remove_lots skipped\n");
7640 else
7641 nerrors += test_remove_lots(envval, fapl, &cparam);
7642
7643 /* Test more complex B-tree queries */
7644 nerrors += test_find_neighbor(fapl, &cparam, &tparam);
7645
7646 /* Test deleting B-trees */
7647 nerrors += test_delete(fapl, &cparam);
7648
7649 /* Test modifying B-tree records */
7650 nerrors += test_modify(fapl, &cparam, &tparam);
7651 } /* end for */
7652
7653 /* Verify symbol table messages are cached */
7654 nerrors += (h5_verify_cached_stabs(FILENAME, fapl) < 0 ? 1 : 0);
7655
7656 if(nerrors)
7657 goto error;
7658
7659 puts("All v2 B-tree tests passed.");
7660
7661 h5_cleanup(FILENAME, fapl);
7662
7663 return 0;
7664
7665 error:
7666 puts("*** TESTS FAILED ***");
7667
7668 H5E_BEGIN_TRY {
7669 H5Pclose(fapl);
7670 } H5E_END_TRY;
7671
7672 return 1;
7673 } /* end main() */
7674
7675