3535#define RTREE_TEST_CREATE_RANK 8
3636#define RTREE_TEST_CREATE_NUM_COUNTS 4
3737
38- #define RTREE_SRC_FILENAME "vds_src_file.h5"
38+ static const char * FILENAME [] = {"vds_rtree_src" , /* 0: Source file for VDS mappings */
39+ "vds_rtree_dapl" , /* 1: DAPL test file */
40+ "vds_rtree_threshold" , /* 2: Threshold test file */
41+ "vds_rtree_rw" , /* 3: Read/write test file */
42+ NULL };
3943
40- #define RTREE_DAPL_FILENAME "vds_rtree_test.h5"
41- #define RTREE_DAPL_SRC_FILENAME "vds_src_rtree_test.h5"
42- #define RTREE_DAPL_VDS_NAME "vdset"
43- #define RTREE_DAPL_SRC_DATASET_NAME "src_dset"
44+ #define FILENAME_BUF_SIZE 1024
45+
46+ #define RTREE_DAPL_VDS_NAME "vdset"
4447
4548#define RTREE_DAPL_DATASET_DIM1 10
4649#define RTREE_DAPL_DATASET_DIM2 10
4750
48- #define RTREE_THRESHOLD_FILENAME "vds_rtree_threshold_test.h5"
49- #define RTREE_MAX_TEST_MAPPINGS (H5D_VIRTUAL_TREE_THRESHOLD + 100)
50-
51- #define RTREE_RW_FILENAME "vds_rtree_rw.h5"
51+ #define RTREE_MAX_TEST_MAPPINGS (H5D_VIRTUAL_TREE_THRESHOLD + 100)
5252
5353static const size_t test_counts [RTREE_TEST_CREATE_NUM_COUNTS ] = {H5D_VIRTUAL_TREE_THRESHOLD , 100 , 1000 ,
5454 10000 };
@@ -68,7 +68,7 @@ static herr_t verify_rtree_search(H5RT_result_set_t *result_set, H5RT_leaf_t *le
6868 hsize_t min [], hsize_t max [], int rank );
6969
7070/* Helper to create and initialize virtual dset in a file */
71- static hid_t create_virtual_dataset (hid_t file_id , hid_t dapl_id , int num_mappings );
71+ static hid_t create_virtual_dataset (hid_t file_id , hid_t dapl_id , int num_mappings , hid_t src_fapl );
7272
7373static herr_t
7474verify_rtree_search (H5RT_result_set_t * result_set , H5RT_leaf_t * leaves , size_t leaf_count , hsize_t min [],
@@ -444,7 +444,7 @@ test_rtree_copy(void)
444444 *-------------------------------------------------------------------------
445445 */
446446static hid_t
447- create_virtual_dataset (hid_t file_id , hid_t dapl_id , int num_mappings )
447+ create_virtual_dataset (hid_t file_id , hid_t dapl_id , int num_mappings , hid_t src_fapl )
448448{
449449 hid_t vspace_id = H5I_INVALID_HID ;
450450 hid_t srcspace_id = H5I_INVALID_HID ;
@@ -457,9 +457,15 @@ create_virtual_dataset(hid_t file_id, hid_t dapl_id, int num_mappings)
457457 hsize_t srcdims [1 ] = {1 };
458458 hsize_t start [1 ], count [1 ];
459459 char srcdset_name [256 ];
460+ char srcfilename [FILENAME_BUF_SIZE ];
461+ char srcfilename_map [FILENAME_BUF_SIZE ];
460462 int wdata ;
461463 int i ;
462464
465+ /* Generate VFD-specific source filenames */
466+ h5_fixname (FILENAME [0 ], src_fapl , srcfilename , sizeof (srcfilename ));
467+ h5_fixname_printf (FILENAME [0 ], src_fapl , srcfilename_map , sizeof (srcfilename_map ));
468+
463469 /* Create 1D virtual dataset space */
464470 if ((vspace_id = H5Screate_simple (1 , vdims , NULL )) < 0 )
465471 goto error ;
@@ -472,13 +478,13 @@ create_virtual_dataset(hid_t file_id, hid_t dapl_id, int num_mappings)
472478 if ((dcpl_id = H5Pcreate (H5P_DATASET_CREATE )) < 0 )
473479 goto error ;
474480
475- /* Create source file */
476- if ((srcfile_id = H5Fcreate (RTREE_SRC_FILENAME , H5F_ACC_TRUNC , H5P_DEFAULT , H5P_DEFAULT )) < 0 )
481+ /* Create source file - use actual filename, not the mapping version */
482+ if ((srcfile_id = H5Fcreate (srcfilename , H5F_ACC_TRUNC , H5P_DEFAULT , src_fapl )) < 0 )
477483 goto error ;
478484
479485 /* Create multiple source dsets and add virtual mappings */
480486 for (i = 0 ; i < num_mappings ; i ++ ) {
481- sprintf (srcdset_name , "src_dset_%d " , i );
487+ sprintf (srcdset_name , "%d_src_dset " , i );
482488
483489 /* Create source dataset */
484490 if ((srcdset_id = H5Dcreate2 (srcfile_id , srcdset_name , H5T_NATIVE_INT , srcspace_id , H5P_DEFAULT ,
@@ -499,8 +505,8 @@ create_virtual_dataset(hid_t file_id, hid_t dapl_id, int num_mappings)
499505 if (H5Sselect_hyperslab (vsel_id , H5S_SELECT_SET , start , NULL , count , NULL ) < 0 )
500506 goto error ;
501507
502- /* Add virtual mapping */
503- if (H5Pset_virtual (dcpl_id , vsel_id , RTREE_SRC_FILENAME , srcdset_name , srcspace_id ) < 0 )
508+ /* Add virtual mapping - use the printf-escaped version for VDS mapping */
509+ if (H5Pset_virtual (dcpl_id , vsel_id , srcfilename_map , srcdset_name , srcspace_id ) < 0 )
504510 goto error ;
505511
506512 /* Close source dataset and selection */
@@ -624,7 +630,7 @@ test_rtree_existence_helper(hid_t vdset_id, bool expect_tree, bool *correct_out)
624630 *-------------------------------------------------------------------------
625631 */
626632static herr_t
627- test_rtree_dapl (bool use_tree , bool read_init )
633+ test_rtree_dapl (bool use_tree , bool read_init , hid_t vds_fapl , hid_t src_fapl )
628634{
629635 hid_t file_id = H5I_INVALID_HID ;
630636 hid_t dapl_id = H5I_INVALID_HID ;
@@ -634,6 +640,7 @@ test_rtree_dapl(bool use_tree, bool read_init)
634640 int wbuf [RTREE_MAX_TEST_MAPPINGS ];
635641 bool tree_correct = false;
636642 char test_str [256 ];
643+ char vfilename [FILENAME_BUF_SIZE ];
637644
638645 /* Inverse of use_tree for re-open part of test */
639646 bool use_tree_inverse = !use_tree ;
@@ -655,15 +662,18 @@ test_rtree_dapl(bool use_tree, bool read_init)
655662 memset (rbuf , 0 , sizeof (int ) * RTREE_MAX_TEST_MAPPINGS );
656663 memset (wbuf , 0 , sizeof (int ) * RTREE_MAX_TEST_MAPPINGS );
657664
665+ /* Generate VFD-specific filename for VDS file */
666+ h5_fixname (FILENAME [1 ], vds_fapl , vfilename , sizeof (vfilename ));
667+
658668 /* One-time setup */
659- if ((file_id = H5Fcreate (RTREE_DAPL_FILENAME , H5F_ACC_TRUNC , H5P_DEFAULT , H5P_DEFAULT )) < 0 )
669+ if ((file_id = H5Fcreate (vfilename , H5F_ACC_TRUNC , H5P_DEFAULT , vds_fapl )) < 0 )
660670 FAIL_STACK_ERROR ;
661671
662672 if ((dapl_id = H5Pcreate (H5P_DATASET_ACCESS )) < 0 )
663673 FAIL_STACK_ERROR ;
664674
665675 /* Create virtual dataset with enough mappings to use tree */
666- if ((vdset_id = create_virtual_dataset (file_id , dapl_id , RTREE_MAX_TEST_MAPPINGS )) < 0 )
676+ if ((vdset_id = create_virtual_dataset (file_id , dapl_id , RTREE_MAX_TEST_MAPPINGS , src_fapl )) < 0 )
667677 FAIL_STACK_ERROR ;
668678
669679 if (H5Dclose (vdset_id ) < 0 )
@@ -717,7 +727,7 @@ test_rtree_dapl(bool use_tree, bool read_init)
717727 if (H5Pset_virtual_spatial_tree (dapl_id , use_tree_inverse ) < 0 )
718728 FAIL_STACK_ERROR ;
719729
720- if ((file_id = H5Fopen (RTREE_DAPL_FILENAME , H5F_ACC_RDWR , H5P_DEFAULT )) < 0 )
730+ if ((file_id = H5Fopen (vfilename , H5F_ACC_RDWR , vds_fapl )) < 0 )
721731 FAIL_STACK_ERROR ;
722732
723733 if ((vdset_id = H5Dopen2 (file_id , RTREE_DAPL_VDS_NAME , dapl_id )) < 0 )
@@ -774,12 +784,13 @@ test_rtree_dapl(bool use_tree, bool read_init)
774784 *-------------------------------------------------------------------------
775785 */
776786static herr_t
777- test_rtree_threshold (bool use_tree )
787+ test_rtree_threshold (bool use_tree , hid_t vds_fapl , hid_t src_fapl )
778788{
779789 hid_t file_id = H5I_INVALID_HID ;
780790 hid_t dapl_id = H5I_INVALID_HID ;
781791 hid_t vdset_id = H5I_INVALID_HID ;
782792 int rbuf [RTREE_MAX_TEST_MAPPINGS ];
793+ char vfilename [FILENAME_BUF_SIZE ];
783794
784795 /* Internal values for introspection */
785796 H5D_t * dset = NULL ;
@@ -790,6 +801,9 @@ test_rtree_threshold(bool use_tree)
790801
791802 TESTING (test_str );
792803
804+ /* Generate VFD-specific filename for VDS file */
805+ h5_fixname (FILENAME [2 ], vds_fapl , vfilename , sizeof (vfilename ));
806+
793807 /* Test cases: below threshold, at threshold, above threshold */
794808 int test_cases [3 ] = {H5D_VIRTUAL_TREE_THRESHOLD - 1 , H5D_VIRTUAL_TREE_THRESHOLD , RTREE_MAX_TEST_MAPPINGS };
795809
@@ -801,7 +815,7 @@ test_rtree_threshold(bool use_tree)
801815 /* Tree is created only when: tree_enabled AND num_mappings >= threshold */
802816 expect_tree = (use_tree && (num_mappings >= H5D_VIRTUAL_TREE_THRESHOLD ));
803817
804- if ((file_id = H5Fcreate (RTREE_THRESHOLD_FILENAME , H5F_ACC_TRUNC , H5P_DEFAULT , H5P_DEFAULT )) < 0 )
818+ if ((file_id = H5Fcreate (vfilename , H5F_ACC_TRUNC , H5P_DEFAULT , vds_fapl )) < 0 )
805819 FAIL_STACK_ERROR ;
806820
807821 if ((dapl_id = H5Pcreate (H5P_DATASET_ACCESS )) < 0 )
@@ -812,7 +826,7 @@ test_rtree_threshold(bool use_tree)
812826 FAIL_STACK_ERROR ;
813827
814828 /* Create virtual dataset with specified number of mappings */
815- if ((vdset_id = create_virtual_dataset (file_id , dapl_id , num_mappings )) < 0 )
829+ if ((vdset_id = create_virtual_dataset (file_id , dapl_id , num_mappings , src_fapl )) < 0 )
816830 FAIL_STACK_ERROR ;
817831
818832 /* Read the virtual dataset to force initialization */
@@ -904,7 +918,7 @@ test_rtree_threshold(bool use_tree)
904918 *-------------------------------------------------------------------------
905919 */
906920static herr_t
907- test_rtree_rw (bool use_tree )
921+ test_rtree_rw (bool use_tree , hid_t vds_fapl , hid_t src_fapl )
908922{
909923 hid_t file_id = H5I_INVALID_HID ;
910924 hid_t dapl_id = H5I_INVALID_HID ;
@@ -914,6 +928,7 @@ test_rtree_rw(bool use_tree)
914928 int rbuf [RTREE_MAX_TEST_MAPPINGS ];
915929 int wbuf [RTREE_MAX_TEST_MAPPINGS ];
916930 int num_mappings = RTREE_MAX_TEST_MAPPINGS ;
931+ char vfilename [FILENAME_BUF_SIZE ];
917932
918933 const char * test_str = use_tree ? "R/W behavior with tree enabled" : "R/W behavior with tree disabled" ;
919934
@@ -922,7 +937,10 @@ test_rtree_rw(bool use_tree)
922937 memset (rbuf , 0 , sizeof (int ) * RTREE_MAX_TEST_MAPPINGS );
923938 memset (wbuf , 0 , sizeof (int ) * RTREE_MAX_TEST_MAPPINGS );
924939
925- if ((file_id = H5Fcreate (RTREE_RW_FILENAME , H5F_ACC_TRUNC , H5P_DEFAULT , H5P_DEFAULT )) < 0 )
940+ /* Generate VFD-specific filename for VDS file */
941+ h5_fixname (FILENAME [3 ], vds_fapl , vfilename , sizeof (vfilename ));
942+
943+ if ((file_id = H5Fcreate (vfilename , H5F_ACC_TRUNC , H5P_DEFAULT , vds_fapl )) < 0 )
926944 FAIL_STACK_ERROR ;
927945
928946 if ((dapl_id = H5Pcreate (H5P_DATASET_ACCESS )) < 0 )
@@ -933,7 +951,7 @@ test_rtree_rw(bool use_tree)
933951 FAIL_STACK_ERROR ;
934952
935953 /* Create virtual dataset with specified number of mappings */
936- if ((vdset_id = create_virtual_dataset (file_id , dapl_id , num_mappings )) < 0 )
954+ if ((vdset_id = create_virtual_dataset (file_id , dapl_id , num_mappings , src_fapl )) < 0 )
937955 FAIL_STACK_ERROR ;
938956
939957 /* Verify initial read values (each element should equal its index) */
@@ -1013,46 +1031,76 @@ test_rtree_rw(bool use_tree)
10131031int
10141032main (void )
10151033{
1016- int nerrors = 0 ;
1034+ int nerrors = 0 ;
1035+ hid_t vds_fapl = H5I_INVALID_HID ;
1036+ hid_t src_fapl = H5I_INVALID_HID ;
1037+ char srcfilename [FILENAME_BUF_SIZE ];
1038+ char vfilename [FILENAME_BUF_SIZE ];
1039+ char threshfilename [FILENAME_BUF_SIZE ];
1040+ char rwfilename [FILENAME_BUF_SIZE ];
10171041
10181042 printf ("Testing R-tree spatial indexing...\n" );
10191043
10201044 H5open ();
10211045
1046+ /* Create file access property lists for VDS and source files */
1047+ if ((vds_fapl = h5_fileaccess ()) < 0 )
1048+ TEST_ERROR ;
1049+ if ((src_fapl = h5_fileaccess ()) < 0 )
1050+ TEST_ERROR ;
1051+
10221052 /* Run core R-tree tests */
10231053 nerrors += test_rtree_create () < 0 ? 1 : 0 ;
10241054 nerrors += test_rtree_search () < 0 ? 1 : 0 ;
10251055 nerrors += test_rtree_copy () < 0 ? 1 : 0 ;
10261056
10271057 /* Test spatial tree with DAPL property enabled */
1028- nerrors += test_rtree_dapl (true, true) < 0 ? 1 : 0 ;
1029- nerrors += test_rtree_dapl (true, false) < 0 ? 1 : 0 ;
1030- nerrors += test_rtree_dapl (false, true) < 0 ? 1 : 0 ;
1031- nerrors += test_rtree_dapl (false, false) < 0 ? 1 : 0 ;
1058+ nerrors += test_rtree_dapl (true, true, vds_fapl , src_fapl ) < 0 ? 1 : 0 ;
1059+ nerrors += test_rtree_dapl (true, false, vds_fapl , src_fapl ) < 0 ? 1 : 0 ;
1060+ nerrors += test_rtree_dapl (false, true, vds_fapl , src_fapl ) < 0 ? 1 : 0 ;
1061+ nerrors += test_rtree_dapl (false, false, vds_fapl , src_fapl ) < 0 ? 1 : 0 ;
10321062
10331063 /* Test the mapping count threshold */
1034- nerrors += test_rtree_threshold (true) < 0 ? 1 : 0 ;
1064+ nerrors += test_rtree_threshold (true, vds_fapl , src_fapl ) < 0 ? 1 : 0 ;
10351065 // TODO - Fix failure
1036- nerrors += test_rtree_threshold (false) < 0 ? 1 : 0 ;
1037- nerrors += test_rtree_rw (true) < 0 ? 1 : 0 ;
1038- nerrors += test_rtree_rw (false) < 0 ? 1 : 0 ;
1066+ nerrors += test_rtree_threshold (false, vds_fapl , src_fapl ) < 0 ? 1 : 0 ;
1067+ nerrors += test_rtree_rw (true, vds_fapl , src_fapl ) < 0 ? 1 : 0 ;
1068+ nerrors += test_rtree_rw (false, vds_fapl , src_fapl ) < 0 ? 1 : 0 ;
10391069
10401070 if (nerrors )
10411071 goto error ;
10421072
1073+ /* Generate VFD-specific filenames for cleanup */
1074+ h5_fixname (FILENAME [0 ], src_fapl , srcfilename , sizeof (srcfilename ));
1075+ h5_fixname (FILENAME [1 ], vds_fapl , vfilename , sizeof (vfilename ));
1076+ h5_fixname (FILENAME [2 ], vds_fapl , threshfilename , sizeof (threshfilename ));
1077+ h5_fixname (FILENAME [3 ], vds_fapl , rwfilename , sizeof (rwfilename ));
1078+
10431079 H5E_BEGIN_TRY
10441080 {
1045- H5Fdelete (RTREE_SRC_FILENAME , H5P_DEFAULT );
1046- H5Fdelete (RTREE_DAPL_FILENAME , H5P_DEFAULT );
1047- H5Fdelete (RTREE_THRESHOLD_FILENAME , H5P_DEFAULT );
1048- H5Fdelete (RTREE_RW_FILENAME , H5P_DEFAULT );
1081+ H5Fdelete (srcfilename , src_fapl );
1082+ H5Fdelete (vfilename , vds_fapl );
1083+ H5Fdelete (threshfilename , vds_fapl );
1084+ H5Fdelete (rwfilename , vds_fapl );
10491085 }
10501086 H5E_END_TRY ;
10511087
1088+ if (H5Pclose (vds_fapl ) < 0 )
1089+ TEST_ERROR ;
1090+ if (H5Pclose (src_fapl ) < 0 )
1091+ TEST_ERROR ;
1092+
10521093 printf ("All R-tree tests passed.\n" );
10531094 return EXIT_SUCCESS ;
10541095
10551096error :
1097+ H5E_BEGIN_TRY
1098+ {
1099+ H5Pclose (vds_fapl );
1100+ H5Pclose (src_fapl );
1101+ }
1102+ H5E_END_TRY ;
1103+
10561104 printf ("***** R-TREE TESTS FAILED *****\n" );
10571105 return EXIT_FAILURE ;
10581106}
0 commit comments