diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2005-03-04 22:22:34 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2005-03-04 22:22:34 (GMT) |
commit | c153ca4d5e5bb7c3bff99b44494f632b4cbf2759 (patch) | |
tree | f42404064ea674a1fa6a1d9cb35e2373e48190d4 /test | |
parent | 831be556f4cca3b5f9380757ce4f09b40f13dd4b (diff) | |
download | hdf5-c153ca4d5e5bb7c3bff99b44494f632b4cbf2759.zip hdf5-c153ca4d5e5bb7c3bff99b44494f632b4cbf2759.tar.gz hdf5-c153ca4d5e5bb7c3bff99b44494f632b4cbf2759.tar.bz2 |
[svn-r10149] Purpose:
Bug fix & new feature
Description:
Fix a couple of off-by-one errors in assertions (code was actually correct)
for 3 node redistributions.
Remove "old" node removal code that is unused now.
Add more tests that verify that 2-node and 3-node redistributions are
working correctly for removals.
Platforms tested:
FreeBSD 4.11 (sleipnir)
Solaris 2.9 (shanti)
Diffstat (limited to 'test')
-rw-r--r-- | test/btree2.c | 170 |
1 files changed, 170 insertions, 0 deletions
diff --git a/test/btree2.c b/test/btree2.c index b9f28f9..6c6486a 100644 --- a/test/btree2.c +++ b/test/btree2.c @@ -2385,6 +2385,175 @@ error: /*------------------------------------------------------------------------- + * Function: test_remove_level1_redistrib + * + * Purpose: Basic tests for the B-tree v2 code + * + * Return: Success: 0 + * + * Failure: 1 + * + * Programmer: Quincey Koziol + * Friday, March 4, 2005 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +test_remove_level1_redistrib(hid_t fapl) +{ + hid_t file=-1; + char filename[1024]; + H5F_t *f=NULL; + hsize_t record; /* Record to insert into tree */ + hsize_t nrec; /* Number of records in B-tree */ + haddr_t bt2_addr; /* Address of B-tree created */ + haddr_t root_addr; /* Address of root of B-tree created */ + unsigned u; /* Local index variable */ + herr_t ret; /* Generic error return value */ + + h5_fixname(FILENAME[0], fapl, filename, sizeof filename); + + /* Create the file to work on */ + if ((file=H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl))<0) TEST_ERROR; + + /* Get a pointer to the internal file object */ + if (NULL==(f=H5I_object(file))) { + H5Eprint_stack(H5E_DEFAULT, stdout); + TEST_ERROR; + } + + /* + * Test v2 B-tree creation + */ + if (H5B2_create(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, 512, 8, 100, 40, &bt2_addr/*out*/)<0) { + H5_FAILED(); + H5Eprint_stack(H5E_DEFAULT, stdout); + goto error; + } + + /* Create level-1 B-tree with 3 leaves */ + for(u=0; u<INSERT_SPLIT_ROOT_NREC*2; u++) { + record=u; + if (H5B2_insert(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &record)<0) { + H5_FAILED(); + H5Eprint_stack(H5E_DEFAULT, stdout); + goto error; + } + } + + /* Query the number of records in the B-tree */ + if (H5B2_get_nrec(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &nrec)<0) { + H5_FAILED(); + H5Eprint_stack(H5E_DEFAULT, stdout); + goto error; + } /* end if */ + + /* Make certain that the # of records is correct */ + if(nrec != (INSERT_SPLIT_ROOT_NREC*2)) TEST_ERROR; + + /* Query the address of the root node in the B-tree */ + if (H5B2_get_root_addr(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &root_addr)<0) { + H5_FAILED(); + H5Eprint_stack(H5E_DEFAULT, stdout); + goto error; + } /* end if */ + + /* Make certain that the address of the root node is defined */ + if(!H5F_addr_defined(root_addr)) TEST_ERROR; + + /* Attempt to remove enough records from right leaf of a level-1 B-tree to force redistribution */ + TESTING("B-tree remove: redistribute 2 leaves in level-1 B-tree (r->l)"); + for(u=0; u < (INSERT_SPLIT_ROOT_NREC/2); u++) { + record = (INSERT_SPLIT_ROOT_NREC*2)-(u+1); + if(H5B2_remove(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &record)<0) { + H5_FAILED(); + H5Eprint_stack(H5E_DEFAULT, stdout); + goto error; + } /* end if */ + + /* Make certain that the record value is correct */ + if(record != ((INSERT_SPLIT_ROOT_NREC*2)-(u+1))) TEST_ERROR; + + /* Query the number of records in the B-tree */ + if (H5B2_get_nrec(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &nrec)<0) { + H5_FAILED(); + H5Eprint_stack(H5E_DEFAULT, stdout); + goto error; + } /* end if */ + + /* Make certain that the # of records is correct */ + if(nrec != ((INSERT_SPLIT_ROOT_NREC*2)-(u+1))) TEST_ERROR; + } /* end for */ + + PASSED(); + + /* Attempt to remove enough records from left leaf of a level-1 B-tree to force redistribution */ + TESTING("B-tree remove: redistribute 2 leaves in level-1 B-tree (l->r)"); + for(u=0; u < (INSERT_SPLIT_ROOT_NREC/4); u++) { + record = u; + if(H5B2_remove(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &record)<0) { + H5_FAILED(); + H5Eprint_stack(H5E_DEFAULT, stdout); + goto error; + } /* end if */ + + /* Make certain that the record value is correct */ + if(record != u) TEST_ERROR; + + /* Query the number of records in the B-tree */ + if (H5B2_get_nrec(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &nrec)<0) { + H5_FAILED(); + H5Eprint_stack(H5E_DEFAULT, stdout); + goto error; + } /* end if */ + + /* Make certain that the # of records is correct */ + if(nrec != (((INSERT_SPLIT_ROOT_NREC*2)-(INSERT_SPLIT_ROOT_NREC/2))-(u+1))) TEST_ERROR; + } /* end for */ + + PASSED(); + + /* Attempt to remove enough records from middle leaf of a level-1 B-tree to force redistribution */ + TESTING("B-tree remove: redistribute 3 leaves in level-1 B-tree"); + for(u=0; u < (INSERT_SPLIT_ROOT_NREC/8); u++) { + record = ((INSERT_SPLIT_ROOT_NREC/4)*3) + u; + if(H5B2_remove(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &record)<0) { + H5_FAILED(); + H5Eprint_stack(H5E_DEFAULT, stdout); + goto error; + } /* end if */ + + /* Make certain that the record value is correct */ + if(record != (((INSERT_SPLIT_ROOT_NREC/4)*3) + u)) TEST_ERROR; + + /* Query the number of records in the B-tree */ + if (H5B2_get_nrec(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &nrec)<0) { + H5_FAILED(); + H5Eprint_stack(H5E_DEFAULT, stdout); + goto error; + } /* end if */ + + /* Make certain that the # of records is correct */ + if(nrec != (((INSERT_SPLIT_ROOT_NREC*2)-(3*(INSERT_SPLIT_ROOT_NREC/4)))-(u+1))) TEST_ERROR; + } /* end for */ + + PASSED(); + + if (H5Fclose(file)<0) TEST_ERROR; + + return 0; + +error: + H5E_BEGIN_TRY { + H5Fclose(file); + } H5E_END_TRY; + return 1; +} /* test_remove_level1_noredistrib() */ + + +/*------------------------------------------------------------------------- * Function: main * * Purpose: Test the B-tree v2 code @@ -2436,6 +2605,7 @@ HDfprintf(stderr,"Uncomment tests!\n"); /* Querying the number of records routine also tested in these routines as well */ nerrors += test_remove_basic(fapl); nerrors += test_remove_level1_noredistrib(fapl); + nerrors += test_remove_level1_redistrib(fapl); #else /* QAK */ HDfprintf(stderr,"Uncomment tests!\n"); #endif /* QAK */ |