summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorQuincey Koziol <koziol@hdfgroup.org>2005-03-05 05:27:45 (GMT)
committerQuincey Koziol <koziol@hdfgroup.org>2005-03-05 05:27:45 (GMT)
commit36b45feae5fe886f7f41aefac97680b9fb4c39d7 (patch)
tree4114caa31e68f3e0bd7ad363a2d0563d9aaf0073 /test
parent8d2ddf51709999a74dd32df49e52509d82eee627 (diff)
downloadhdf5-36b45feae5fe886f7f41aefac97680b9fb4c39d7.zip
hdf5-36b45feae5fe886f7f41aefac97680b9fb4c39d7.tar.gz
hdf5-36b45feae5fe886f7f41aefac97680b9fb4c39d7.tar.bz2
[svn-r10155] Purpose:
More tests Description: Add tests for removing records in the root of a level-1 B-tree and promoting and merging leaf nodes. Platforms tested: FreeBSD 4.11 (sleipnir) Solaris 2.9 (shanti)
Diffstat (limited to 'test')
-rw-r--r--test/btree2.c298
1 files changed, 288 insertions, 10 deletions
diff --git a/test/btree2.c b/test/btree2.c
index 2f9cf5e..1bebd20 100644
--- a/test/btree2.c
+++ b/test/btree2.c
@@ -2985,7 +2985,7 @@ error:
/*-------------------------------------------------------------------------
- * Function: test_remove_level1_promote_2leaf_redistrib_right
+ * Function: test_remove_level1_promote_2leaf_redistrib
*
* Purpose: Basic tests for the B-tree v2 code
*
@@ -3001,7 +3001,7 @@ error:
*-------------------------------------------------------------------------
*/
static int
-test_remove_level1_promote_2leaf_redistrib_right(hid_t fapl)
+test_remove_level1_promote_2leaf_redistrib(hid_t fapl)
{
hid_t file=-1;
char filename[1024];
@@ -3063,7 +3063,7 @@ test_remove_level1_promote_2leaf_redistrib_right(hid_t fapl)
if(!H5F_addr_defined(root_addr)) TEST_ERROR;
/* Attempt to remove record from root node of a level-1 B-tree to force promotion from right leaf */
- TESTING("B-tree remove: promote from right leaf of level-1 B-tree w/redistrib");
+ TESTING("B-tree remove: promote from leaf of level-1 B-tree w/2 node redistrib");
/* Remove records from right leaf until its ready to redistribute */
for(u=0; u < 33; u++) {
@@ -3119,11 +3119,11 @@ error:
H5Fclose(file);
} H5E_END_TRY;
return 1;
-} /* test_remove_level1_promote_2leaf_redistrib_right() */
+} /* test_remove_level1_promote_2leaf_redistrib() */
/*-------------------------------------------------------------------------
- * Function: test_remove_level1_promote_2leaf_redistrib_middle
+ * Function: test_remove_level1_promote_3leaf_redistrib
*
* Purpose: Basic tests for the B-tree v2 code
*
@@ -3139,7 +3139,7 @@ error:
*-------------------------------------------------------------------------
*/
static int
-test_remove_level1_promote_2leaf_redistrib_middle(hid_t fapl)
+test_remove_level1_promote_3leaf_redistrib(hid_t fapl)
{
hid_t file=-1;
char filename[1024];
@@ -3201,7 +3201,7 @@ test_remove_level1_promote_2leaf_redistrib_middle(hid_t fapl)
if(!H5F_addr_defined(root_addr)) TEST_ERROR;
/* Attempt to remove record from root node of a level-1 B-tree to force promotion from middle leaf */
- TESTING("B-tree remove: promote from middle leaf of level-1 B-tree w/redistrib");
+ TESTING("B-tree remove: promote from leaf of level-1 B-tree w/3 node redistrib");
/* Remove records from right leaf until its ready to redistribute */
for(u=0; u < 33; u++) {
@@ -3257,7 +3257,283 @@ error:
H5Fclose(file);
} H5E_END_TRY;
return 1;
-} /* test_remove_level1_promote_2leaf_redistrib_middle() */
+} /* test_remove_level1_promote_3leaf_redistrib() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_remove_level1_promote_2leaf_merge
+ *
+ * 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_promote_2leaf_merge(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-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 record from root node of a level-1 B-tree to force promotion from right leaf */
+ TESTING("B-tree remove: promote from leaf of level-1 B-tree w/2->1 merge");
+
+ /* Remove records from right leaf until its ready to redistribute */
+ for(u=0; u < 66; 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 */
+
+ record = 68;
+ 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 != 68) 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)-67) TEST_ERROR;
+
+ PASSED();
+
+ if (H5Fclose(file)<0) TEST_ERROR;
+
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Fclose(file);
+ } H5E_END_TRY;
+ return 1;
+} /* test_remove_level1_promote_2leaf_merge() */
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_remove_level1_promote_3leaf_merge
+ *
+ * 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_promote_3leaf_merge(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-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 record from root node of a level-1 B-tree to force promotion from middle leaf */
+ TESTING("B-tree remove: promote from leaf of level-1 B-tree w/3->2 merge");
+
+ /* Remove records from right leaf until its ready to redistribute */
+ for(u=0; u < 81; u++) {
+ record = 43 + 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 != (43 + 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)-(u+1))) TEST_ERROR;
+ } /* end for */
+
+ record = 26;
+ 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 != 26) 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)-82) TEST_ERROR;
+
+ PASSED();
+
+ if (H5Fclose(file)<0) TEST_ERROR;
+
+ return 0;
+
+error:
+ H5E_BEGIN_TRY {
+ H5Fclose(file);
+ } H5E_END_TRY;
+ return 1;
+} /* test_remove_level1_promote_3leaf_redistrib() */
/*-------------------------------------------------------------------------
@@ -3316,8 +3592,10 @@ HDfprintf(stderr,"Uncomment tests!\n");
nerrors += test_remove_level1_2leaf_merge(fapl);
nerrors += test_remove_level1_3leaf_merge(fapl);
nerrors += test_remove_level1_promote(fapl);
- nerrors += test_remove_level1_promote_2leaf_redistrib_right(fapl);
- nerrors += test_remove_level1_promote_2leaf_redistrib_middle(fapl);
+ nerrors += test_remove_level1_promote_2leaf_redistrib(fapl);
+ nerrors += test_remove_level1_promote_3leaf_redistrib(fapl);
+ nerrors += test_remove_level1_promote_2leaf_merge(fapl);
+ nerrors += test_remove_level1_promote_3leaf_merge(fapl);
#else /* QAK */
HDfprintf(stderr,"Uncomment tests!\n");
#endif /* QAK */