diff options
author | Quincey Koziol <koziol@hdfgroup.org> | 2005-03-08 19:56:29 (GMT) |
---|---|---|
committer | Quincey Koziol <koziol@hdfgroup.org> | 2005-03-08 19:56:29 (GMT) |
commit | 7f884850250ee587b17eda0bbbde105202098e30 (patch) | |
tree | 2950045a214b0d90578480b619d03a611da70f2a /test/btree2.c | |
parent | 3f70d6c95ee28ded2b179c9218e116262c96403f (diff) | |
download | hdf5-7f884850250ee587b17eda0bbbde105202098e30.zip hdf5-7f884850250ee587b17eda0bbbde105202098e30.tar.gz hdf5-7f884850250ee587b17eda0bbbde105202098e30.tar.bz2 |
[svn-r10168] Purpose:
Bug fix & new tests
Description:
Fix another couple of issues with record removal and add some more tests to
make certain removals work correctly.
Platforms tested:
FreeBSD 4.11 (sleipnir)
Solaris 2.9 (shanti)
Diffstat (limited to 'test/btree2.c')
-rw-r--r-- | test/btree2.c | 262 |
1 files changed, 262 insertions, 0 deletions
diff --git a/test/btree2.c b/test/btree2.c index e3ba210..fc852c4 100644 --- a/test/btree2.c +++ b/test/btree2.c @@ -4751,6 +4751,266 @@ error: /*------------------------------------------------------------------------- + * Function: test_remove_level2_collapse_right + * + * Purpose: Basic tests for the B-tree v2 code + * + * Return: Success: 0 + * + * Failure: 1 + * + * Programmer: Quincey Koziol + * Tuesday, March 8, 2005 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +test_remove_level2_collapse_right(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 */ + + 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-2 B-tree with 3 internal nodes */ + for(u=0; u<INSERT_SPLIT_ROOT_NREC*21; 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*21)) 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 records from a level-2 B-tree to force back to level-1 */ + TESTING("B-tree remove: collapse level-1 B-tree back to level-0 (r->l)"); + for(u=0; u < (INSERT_SPLIT_ROOT_NREC*12); u++) { + record = (INSERT_SPLIT_ROOT_NREC*21)-(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*21)-(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*21)-(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_level2_collapse_right() */ + + +/*------------------------------------------------------------------------- + * Function: test_remove_lots + * + * Purpose: Basic tests for the B-tree v2 code. This test inserts many + * records in random order, enough to make at a level 4 B-tree + * and then removes them all. + * + * Return: Success: 0 + * + * Failure: 1 + * + * Programmer: Quincey Koziol + * Tuesday, March 8, 2005 + * + * Modifications: + * + *------------------------------------------------------------------------- + */ +static int +test_remove_lots(hid_t fapl) +{ + hid_t file=-1; + char filename[1024]; + H5F_t *f=NULL; + hsize_t record; /* Record to insert into tree */ + haddr_t bt2_addr; /* Address of B-tree created */ + hsize_t idx; /* Index within B-tree, for iterator */ + time_t curr_time; /* Current time, for seeding random number generator */ + hsize_t *records; /* Record #'s for random insertion */ + unsigned u; /* Local index variable */ + unsigned swap_idx; /* Location to swap with when shuffling */ + hsize_t temp_rec; /* Temporary record */ + hsize_t nrec; /* Number of records in B-tree */ + herr_t ret; /* Generic error return value */ + + /* Initialize random number seed */ + curr_time=HDtime(NULL); +#ifdef QAK +curr_time=1109170019; +HDfprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time); +#endif /* QAK */ + HDsrandom((unsigned long)curr_time); + + /* Allocate space for the records */ + if((records = HDmalloc(sizeof(hsize_t)*INSERT_MANY))==NULL) TEST_ERROR; + + /* Initialize record #'s */ + for(u=0; u<INSERT_MANY; u++) + records[u] = u; + + /* Shuffle record #'s */ + for(u=0; u<INSERT_MANY; u++) { + swap_idx = (unsigned)(HDrandom()%(INSERT_MANY-u))+u; + temp_rec = records[u]; + records[u] = records[swap_idx]; + records[swap_idx] = temp_rec; + } /* end for */ + + 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); + goto error; + } + + /* + * Create v2 B-tree + */ + 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; + } + + /* + * Test inserting many records into v2 B-tree + */ + TESTING("B-tree remove: create random level 4 B-tree and delete all records"); + + /* Insert random records */ + for(u=0; u<INSERT_MANY; u++) { + record=records[u]; + if (H5B2_insert(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &record)<0) { + H5_FAILED(); + H5Eprint_stack(H5E_DEFAULT, stdout); + goto error; + } + } /* end for */ + + /* Re-shuffle record #'s */ + for(u=0; u<INSERT_MANY; u++) { + swap_idx = (unsigned)(HDrandom()%(INSERT_MANY-u))+u; + temp_rec = records[u]; + records[u] = records[swap_idx]; + records[swap_idx] = temp_rec; + } /* end for */ + + /* Remove all records */ + for(u=0; u<INSERT_MANY; u++) { + record=records[u]; + if(H5B2_remove(f, H5P_DATASET_XFER_DEFAULT, H5B2_TEST, bt2_addr, &record)<0) { +#ifdef QAK +HDfprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time); +#endif /* QAK */ + H5_FAILED(); + H5Eprint_stack(H5E_DEFAULT, stdout); + goto error; + } /* end if */ + + /* Make certain that the record value is correct */ + if(record != records[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_MANY-(u+1))) TEST_ERROR; + } /* end for */ + + PASSED(); + + if (H5Fclose(file)<0) TEST_ERROR; + + HDfree(records); + + return 0; + +error: + H5E_BEGIN_TRY { + H5Fclose(file); + } H5E_END_TRY; + HDfree(records); + return 1; +} /* test_remove_lots() */ + + +/*------------------------------------------------------------------------- * Function: main * * Purpose: Test the B-tree v2 code @@ -4819,6 +5079,8 @@ HDfprintf(stderr,"Uncomment tests!\n"); nerrors += test_remove_level2_2internal_merge_left(fapl); nerrors += test_remove_level2_2internal_merge_right(fapl); nerrors += test_remove_level2_3internal_merge(fapl); + nerrors += test_remove_level2_collapse_right(fapl); + nerrors += test_remove_lots(fapl); #else /* QAK */ HDfprintf(stderr,"Uncomment tests!\n"); #endif /* QAK */ |