1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group.                                               *
3  * All rights reserved.                                                      *
4  *                                                                           *
5  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
6  * terms governing use, modification, and redistribution, is contained in    *
7  * the COPYING file, which can be found at the root of the source code       *
8  * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
9  * If you do not have access to either file, you may request a copy from     *
10  * help@hdfgroup.org.                                                        *
11  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12 
13 /*
14  * Programmer:  Neil Fortner <nfortne2@hdfgroup.org>
15  *              Monday, February 16, 2015
16  *
17  * Purpose:     Tests datasets with virtual layout.
18  */
19 #include "h5test.h"
20 #include "H5Dprivate.h" /* For H5D_VIRTUAL_DEF_LIST_SIZE */
21 
22 typedef enum {
23     TEST_API_BASIC,
24     TEST_API_COPY_PLIST,
25     TEST_API_ENCDEC_PLIST,
26     TEST_API_CREATE_DSET,
27     TEST_API_REOPEN_DSET,
28     TEST_API_REOPEN_FILE,
29     TEST_API_NTESTS
30 } test_api_config_t;
31 
32 const char *FILENAME[] = {
33     "vds_virt_0",
34     "vds_virt_1",
35     "vds_src_0",
36     "vds_src_1",
37     "vds%%_src",
38     "vds_dapl",
39     "vds_virt_2",
40     "vds_virt_3",
41     "vds_src_2",
42     "vds_src_3",
43     "vds%%_src2",
44     "vds_dapl2",
45     NULL
46 };
47 
48 /* I/O test config flags */
49 #define TEST_IO_CLOSE_SRC       0x01u
50 #define TEST_IO_DIFFERENT_FILE  0x02u
51 #define TEST_IO_REOPEN_VIRT     0x04u
52 #define TEST_IO_NTESTS          0x08u
53 
54 #define LIST_DOUBLE_SIZE (H5D_VIRTUAL_DEF_LIST_SIZE + 1)
55 
56 #define FILENAME_BUF_SIZE       1024
57 
58 #define TMPDIR          "tmp_vds/"
59 
60 
61 /*-------------------------------------------------------------------------
62  * Function:    vds_select_equal
63  *
64  * Purpose:     Helper function to check if the selections in the two
65  *              provided dataspaces are the same.
66  *
67  * Return:      Success:        0
68  *              Failure:        -1
69  *-------------------------------------------------------------------------
70  */
71 static htri_t
vds_select_equal(hid_t space1,hid_t space2)72 vds_select_equal(hid_t space1, hid_t space2)
73 {
74     H5S_sel_type    type1;
75     H5S_sel_type    type2;
76     hsize_t         *buf1 = NULL;
77     hsize_t         *buf2 = NULL;
78     size_t          i;
79     htri_t          ret_value = TRUE;
80 
81     /* Get and compare selection types */
82     if((type1 = H5Sget_select_type(space1)) < 0)
83         TEST_ERROR
84     if((type2 = H5Sget_select_type(space2)) < 0)
85         TEST_ERROR
86     if(type1 != type2)
87         return FALSE;
88 
89     /* Check selection type */
90     switch(type1) {
91         case H5S_SEL_NONE:
92         case H5S_SEL_ALL:
93             break;
94 
95         case H5S_SEL_POINTS:
96             {
97                 int         rank1;
98                 int         rank2;
99                 hssize_t    npoints1;
100                 hssize_t    npoints2;
101 
102                 /* Get and compare rank */
103                 if((rank1 = H5Sget_simple_extent_ndims(space1)) < 0)
104                     TEST_ERROR
105                 if((rank2 = H5Sget_simple_extent_ndims(space2)) < 0)
106                     TEST_ERROR
107                 if(rank1 != rank2)
108                     return FALSE;
109 
110                 /* Get and compare number of points */
111                 if((npoints1 = H5Sget_select_elem_npoints(space1)) < 0)
112                     TEST_ERROR
113                 if((npoints2 = H5Sget_select_elem_npoints(space2)) < 0)
114                     TEST_ERROR
115                 if(npoints1 != npoints2)
116                     return FALSE;
117 
118                 /* Allocate point lists.  Do not return directly after
119                  * allocating, to make sure buffers are freed. */
120                 if(NULL == (buf1 = (hsize_t *)HDmalloc((size_t)rank1 * (size_t)npoints1 * sizeof(hsize_t))))
121                     TEST_ERROR
122                 if(NULL == (buf2 = (hsize_t *)HDmalloc((size_t)rank1 * (size_t)npoints1 * sizeof(hsize_t))))
123                     TEST_ERROR
124 
125                 /* Get and compare point lists */
126                 if(H5Sget_select_elem_pointlist(space1, (hsize_t)0, (hsize_t)npoints1, buf1) < 0)
127                     TEST_ERROR
128                 if(H5Sget_select_elem_pointlist(space2, (hsize_t)0, (hsize_t)npoints1, buf2) < 0)
129                     TEST_ERROR
130                 for(i = 0; i < ((size_t)rank1 * (size_t)npoints1); i++)
131                     if(buf1[i] != buf2[i]) {
132                         ret_value = FALSE;
133                         break;
134                     }
135 
136                 /* Free buffers */
137                 HDfree(buf1);
138                 buf1 = NULL;
139                 HDfree(buf2);
140                 buf2 = NULL;
141             } /* end block */
142 
143             break;
144 
145         case H5S_SEL_HYPERSLABS:
146             {
147                 int         rank1;
148                 int         rank2;
149                 hssize_t    nblocks1;
150                 hssize_t    nblocks2;
151 
152                 /* Get and compare rank */
153                 if((rank1 = H5Sget_simple_extent_ndims(space1)) < 0)
154                     TEST_ERROR
155                 if((rank2 = H5Sget_simple_extent_ndims(space2)) < 0)
156                     TEST_ERROR
157                 if(rank1 != rank2)
158                     return FALSE;
159 
160                 /* Get and compare number of blocks */
161                 if((nblocks1 = H5Sget_select_hyper_nblocks(space1)) < 0)
162                     TEST_ERROR
163                 if((nblocks2 = H5Sget_select_hyper_nblocks(space2)) < 0)
164                     TEST_ERROR
165                 if(nblocks1 != nblocks2)
166                     return FALSE;
167 
168                 /* Allocate block lists.  Do not return directly afer
169                  * allocating, to make sure buffers are freed. */
170                 if(NULL == (buf1 = (hsize_t *)HDmalloc((size_t)2 * (size_t)rank1 * (size_t)nblocks1 * sizeof(*buf1))))
171                     TEST_ERROR
172                 if(NULL == (buf2 = (hsize_t *)HDmalloc((size_t)2 * (size_t)rank1 * (size_t)nblocks1 * sizeof(*buf2))))
173                     TEST_ERROR
174 
175                 /* Get and compare block lists */
176                 if(H5Sget_select_hyper_blocklist(space1, (hsize_t)0, (hsize_t)nblocks1, buf1) < 0)
177                     TEST_ERROR
178                 if(H5Sget_select_hyper_blocklist(space2, (hsize_t)0, (hsize_t)nblocks1, buf2) < 0)
179                     TEST_ERROR
180                 for(i = 0; i < ((size_t)2 * (size_t)rank1 * (size_t)nblocks1); i++)
181                     if(buf1[i] != buf2[i]) {
182                         ret_value = FALSE;
183                         break;
184                     }
185 
186                 /* Free buffers */
187                 HDfree(buf1);
188                 buf1 = NULL;
189                 HDfree(buf2);
190                 buf2 = NULL;
191             } /* end block */
192 
193             break;
194 
195         case H5S_SEL_ERROR:
196         case H5S_SEL_N:
197         default:
198             TEST_ERROR
199     } /* end switch */
200 
201     return ret_value;
202 
203 error:
204     if(buf1)
205         HDfree(buf1);
206     if(buf2)
207         HDfree(buf2);
208 
209     return -1;
210 } /* end vds_select_equal() */
211 
212 
213 /*-------------------------------------------------------------------------
214  * Function:    vds_check_mapping
215  *
216  * Purpose:     Helper function to check if the ith virtual mapping in the
217  *              provided dcpl is the same as that described by the other
218  *              parameters.
219  *
220  * Return:      Success:        0
221  *              Failure:        -1
222  *-------------------------------------------------------------------------
223  */
224 static int
vds_check_mapping(hid_t dcpl,size_t i,hid_t vspace,hid_t srcspace,const char * filename,const char * dsetname)225 vds_check_mapping(hid_t dcpl, size_t i, hid_t vspace, hid_t srcspace,
226     const char *filename, const char *dsetname)
227 {
228     hid_t       space_out = -1;
229     char        name_out[32];
230     htri_t      tri_ret;
231     ssize_t     str_len;
232 
233     HDassert(dcpl >= 0);
234     HDassert(vspace >= 0);
235     HDassert(srcspace >= 0);
236     HDassert(filename);
237     HDassert(dsetname);
238 
239     /* Check vspace */
240     if((space_out = H5Pget_virtual_vspace(dcpl, i)) < 0)
241         TEST_ERROR
242     if((tri_ret = H5Sextent_equal(space_out, vspace)) < 0)
243         TEST_ERROR
244     if(!tri_ret)
245         TEST_ERROR
246     if((tri_ret = vds_select_equal(space_out, vspace)) < 0)
247         TEST_ERROR
248     if(!tri_ret)
249         TEST_ERROR
250     if(H5Sclose(space_out) < 0)
251         TEST_ERROR
252     space_out = -1;
253 
254     /* Check srcspace */
255     if((space_out = H5Pget_virtual_srcspace(dcpl, i)) < 0)
256         TEST_ERROR
257     if((tri_ret = vds_select_equal(space_out, srcspace)) < 0)
258         TEST_ERROR
259     if(!tri_ret)
260         TEST_ERROR
261     if(H5Sclose(space_out) < 0)
262         TEST_ERROR
263     space_out = -1;
264 
265     /* Check filename */
266     if((str_len = H5Pget_virtual_filename(dcpl, i, NULL, (size_t)0)) < 0)
267         TEST_ERROR
268     if((size_t)str_len != HDstrlen(filename))
269         TEST_ERROR
270     HDassert((size_t)str_len < sizeof(name_out));
271     if((str_len = H5Pget_virtual_filename(dcpl, i, name_out, sizeof(name_out))) < 0)
272         TEST_ERROR
273     if((size_t)str_len != HDstrlen(filename))
274         TEST_ERROR
275     if(HDstrncmp(name_out, filename, (size_t)str_len + 1) != 0)
276         TEST_ERROR
277 
278     /* Check dsetname */
279     if((str_len = H5Pget_virtual_dsetname(dcpl, i, NULL, (size_t)0)) < 0)
280         TEST_ERROR
281     if((size_t)str_len != HDstrlen(dsetname))
282         TEST_ERROR
283     HDassert((size_t)str_len < sizeof(name_out));
284     if((str_len = H5Pget_virtual_dsetname(dcpl, i, name_out, sizeof(name_out))) < 0)
285         TEST_ERROR
286     if((size_t)str_len != HDstrlen(dsetname))
287         TEST_ERROR
288     if(HDstrncmp(name_out, dsetname, (size_t)str_len + 1) != 0)
289         TEST_ERROR
290 
291     return 0;
292 
293 error:
294     H5E_BEGIN_TRY {
295         H5Sclose(space_out);
296     } H5E_END_TRY
297 
298     return -1;
299 } /* end vds_check_mapping() */
300 
301 
302 /*-------------------------------------------------------------------------
303  * Function:    test_api_get_ex_dcpl
304  *
305  * Purpose:     Tests API functions related to virtual datasets.
306  *
307  * Return:      Success:        0
308  *              Failure:        number of errors
309  *-------------------------------------------------------------------------
310  */
311 /* Helper function to get DCPL for examination depending on config */
312 static int
test_api_get_ex_dcpl(test_api_config_t config,hid_t fapl,hid_t dcpl,hid_t * ex_dcpl,hid_t vspace,char * filename,hsize_t exp_meta_size)313 test_api_get_ex_dcpl(test_api_config_t config, hid_t fapl, hid_t dcpl,
314     hid_t *ex_dcpl, hid_t vspace, char *filename, hsize_t exp_meta_size)
315 {
316     hid_t       file = -1;      /* File */
317     hid_t       dset = -1;      /* Virtual dataset */
318     H5D_space_status_t space_status; /* Dataset space status */
319     void        *plist_buf = NULL; /* Serialized property list buffer */
320     H5O_info_t  oinfo;          /* Object info struct */
321     htri_t      tri_ret;
322 
323     HDassert((config >= TEST_API_BASIC) && (config < TEST_API_NTESTS));
324     HDassert(fapl >= 0);
325     HDassert(dcpl >= 0);
326     HDassert(ex_dcpl);
327     HDassert(*ex_dcpl < 0);
328     HDassert(vspace >= 0);
329     HDassert(filename);
330 
331     /* Take different action depending on test configuration */
332     if(config >= TEST_API_CREATE_DSET) {
333         /* Create file and dataset */
334         if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
335             TEST_ERROR
336         if((dset = H5Dcreate2(file, "vdset", H5T_NATIVE_INT, vspace, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
337             TEST_ERROR
338 
339         /* Test H5Dget_space_status */
340         if(H5Dget_space_status(dset, &space_status) < 0)
341             TEST_ERROR
342         if(space_status != H5D_SPACE_STATUS_ALLOCATED)
343             TEST_ERROR
344 
345         /* Reopen dataset if requested */
346         if(config >= TEST_API_REOPEN_DSET) {
347             /* Close dataset */
348             if(H5Dclose(dset) < 0)
349                 TEST_ERROR
350             dset = -1;
351 
352             /* Reopen file if requested */
353             if(config == TEST_API_REOPEN_FILE) {
354                 if(H5Fclose(file) < 0)
355                     TEST_ERROR
356                 file = -1;
357                 if((file = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
358                     TEST_ERROR
359             }
360 
361             /* Open dataset */
362             if((dset = H5Dopen2(file, "vdset", H5P_DEFAULT)) < 0)
363                 TEST_ERROR
364         }
365 
366         /* Get DCPL from dataset */
367         if((*ex_dcpl = H5Dget_create_plist(dset)) < 0)
368             TEST_ERROR
369 
370         /* Test H5Dget_offset() (just returns HADDR_UNDEF) */
371         if(HADDR_UNDEF != H5Dget_offset(dset))
372             TEST_ERROR
373 
374         /* Test H5Oget_info returns correct metadata size */
375         if(H5Oget_info2(dset, &oinfo, H5O_INFO_META_SIZE) < 0)
376             TEST_ERROR
377         if(oinfo.meta_size.obj.index_size != (hsize_t)0)
378             TEST_ERROR
379         if(config == TEST_API_REOPEN_FILE) {
380             if(oinfo.meta_size.obj.heap_size != exp_meta_size) {
381                 HDprintf("VDS metadata size: %llu Expected: %llu\n", (long long unsigned)oinfo.meta_size.obj.heap_size, (long long unsigned)exp_meta_size);
382                 TEST_ERROR
383             }
384         }
385         else
386             if((oinfo.meta_size.obj.heap_size != exp_meta_size)
387                     && (oinfo.meta_size.obj.heap_size != (hsize_t)0))
388                 TEST_ERROR
389         if(oinfo.meta_size.attr.index_size != (hsize_t)0)
390             TEST_ERROR
391         if(oinfo.meta_size.attr.index_size != (hsize_t)0)
392             TEST_ERROR
393 
394         /* Test H5Dget_space_status */
395         if(H5Dget_space_status(dset, &space_status) < 0)
396             TEST_ERROR
397         if(space_status != H5D_SPACE_STATUS_ALLOCATED)
398             TEST_ERROR
399 
400         /* Close dataset */
401         if(H5Dclose(dset) < 0)
402             TEST_ERROR
403         dset = -1;
404 
405         /* Delete dataset */
406         if(H5Ldelete(file, "vdset", H5P_DEFAULT) < 0)
407             TEST_ERROR
408 
409         /* Close file */
410         if(H5Fclose(file) < 0)
411             TEST_ERROR
412         file = -1;
413     }
414     else if(config == TEST_API_COPY_PLIST) {
415         /* Copy property list */
416         if((*ex_dcpl = H5Pcopy(dcpl)) < 0)
417             TEST_ERROR
418     }
419     else if(config == TEST_API_ENCDEC_PLIST) {
420         size_t plist_buf_size;
421 
422         /* Encode property list to plist_buf */
423         if(H5Pencode(dcpl, NULL, &plist_buf_size) < 0)
424             TEST_ERROR
425         if(NULL == (plist_buf = HDmalloc(plist_buf_size)))
426             TEST_ERROR
427         if(H5Pencode(dcpl, plist_buf, &plist_buf_size) < 0)
428             TEST_ERROR
429 
430         /* Decode serialized property list to *ex_dcpl */
431         if((*ex_dcpl = H5Pdecode(plist_buf)) < 0)
432             TEST_ERROR
433 
434         /* Free plist_buf */
435         HDfree(plist_buf);
436         plist_buf = NULL;
437     }
438     else {
439         /* Simply copy the id to ex_dcpl and increment the ref count so ex_dcpl
440          * can be closed */
441         if(H5Iinc_ref(dcpl) < 0)
442             TEST_ERROR
443         *ex_dcpl = dcpl;
444     }
445 
446     /* Verify examination DCPL is equal to original DCPL.  Do not compare the
447      * plist to itself, and do not do the comparison if we reopened the file,
448      * because in that case the extent of the source dset will not be corrent.
449      */
450     if((*ex_dcpl != dcpl) && (config != TEST_API_REOPEN_FILE)) {
451         if((tri_ret = H5Pequal(dcpl, *ex_dcpl)) < 0)
452             TEST_ERROR
453         if(!tri_ret)
454             TEST_ERROR
455     }
456 
457     return 0;
458 
459 error:
460     H5E_BEGIN_TRY {
461         H5Fclose(file);
462         H5Dclose(dset);
463     } H5E_END_TRY;
464     if(plist_buf)
465         HDfree(plist_buf);
466 
467     return -1;
468 } /* end test_api_get_ex_dcpl() */
469 
470 /* Main test function */
471 static int
test_api(test_api_config_t config,hid_t fapl)472 test_api(test_api_config_t config, hid_t fapl)
473 {
474     char        filename[FILENAME_BUF_SIZE];
475     hid_t       dcpl = -1;      /* Dataset creation property list */
476     hid_t       ex_dcpl = -1;   /* Temporary dcpl for examination */
477     hid_t       srcspace[4] = {-1, -1, -1, -1}; /* Source dataspaces */
478     hid_t       vspace[LIST_DOUBLE_SIZE]; /* Virtual dset dataspaces */
479     const char  *src_file[4] = {"src_file1", "src_file2.", "src_file3..", "src_file4..."}; /* Source file names (different lengths) */
480     const char  *src_dset[4] = {"src_dset1....", "src_dset2.....", "src_dset3......", "src_dset4......."}; /* Source dataset names (different lengths) */
481     char        tmp_filename[32];
482     char        tmp_dsetname[32];
483     hsize_t     dims[2] = {10, 20}; /* Data space current size */
484     hsize_t     start[2];       /* Hyperslab start */
485     hsize_t     stride[2];      /* Hyperslab stride */
486     hsize_t     count[2];       /* Hyperslab count */
487     hsize_t     block[2];       /* Hyperslab block */
488     hsize_t     coord[10];      /* Point selection array */
489     size_t      size_out;
490     herr_t      ret;
491     unsigned    i;
492 
493     /* Initialize vspace */
494     for(i = 0; i < (unsigned)(sizeof(vspace) / sizeof(vspace[0])); i++)
495         vspace[i] = -1;
496 
497     switch(config) {
498         case TEST_API_BASIC:
499             TESTING("virtual dataset API functions")
500             break;
501         case TEST_API_COPY_PLIST:
502             TESTING("virtual dataset API functions with copied plists")
503             break;
504         case TEST_API_ENCDEC_PLIST:
505             TESTING("virtual dataset API functions with encoded and decoded plists")
506             break;
507         case TEST_API_CREATE_DSET:
508             TESTING("virtual dataset create")
509             break;
510         case TEST_API_REOPEN_DSET:
511             TESTING("virtual dataset create with reopened dataset")
512             break;
513         case TEST_API_REOPEN_FILE:
514             TESTING("virtual dataset create with reopened file")
515             break;
516         case TEST_API_NTESTS:
517         default:
518             TEST_ERROR
519     }
520 
521     h5_fixname(FILENAME[0], fapl, filename, sizeof filename);
522 
523     /* Create DCPL */
524     if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
525         TEST_ERROR
526 
527 
528     /*
529      * Test 1: All - all selection
530      */
531     /* Create source dataspace */
532     if((srcspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
533         TEST_ERROR
534 
535     /* Create virtual dataspace */
536     if((vspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
537         TEST_ERROR
538 
539     /* Select all (should not be necessary, but just to be sure) */
540     if(H5Sselect_all(srcspace[0]) < 0)
541         TEST_ERROR
542     if(H5Sselect_all(vspace[0]) < 0)
543         TEST_ERROR
544 
545     /* Add virtual layout mapping */
546     if(H5Pset_virtual(dcpl, vspace[0], src_file[0], src_dset[0], srcspace[0]) < 0)
547         TEST_ERROR
548 
549     /* Get examination DCPL */
550     if(test_api_get_ex_dcpl(config, fapl, dcpl, &ex_dcpl, vspace[0], filename, (hsize_t)69) < 0)
551         TEST_ERROR
552 
553     /* Test H5Pget_virtual_count */
554     if(H5Pget_virtual_count(ex_dcpl, &size_out) < 0)
555         TEST_ERROR
556     if(size_out != (size_t)1)
557         TEST_ERROR
558 
559     /* Check that the mapping in the DCPL is correct */
560     if(vds_check_mapping(ex_dcpl, (size_t)0, vspace[0], srcspace[0], src_file[0], src_dset[0]) < 0)
561         TEST_ERROR
562 
563     /* Close */
564     if(H5Sclose(srcspace[0]) < 0)
565         TEST_ERROR
566     srcspace[0] = -1;
567     if(H5Sclose(vspace[0]) < 0)
568         TEST_ERROR
569     vspace[0] = -1;
570     if(H5Pclose(ex_dcpl) < 0)
571         TEST_ERROR
572     ex_dcpl = -1;
573 
574 
575     /*
576      * Test 2: Hyper - hyper selection
577      */
578     /* Clear virtual layout in DCPL */
579     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
580         TEST_ERROR
581 
582     /* Create source dataspace */
583     if((srcspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
584         TEST_ERROR
585 
586     /* Create virtual dataspace */
587     if((vspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
588         TEST_ERROR
589 
590     /* Select regular hyperslab in source space */
591     start[0] = 2;
592     start[1] = 1;
593     stride[0] = 3;
594     stride[1] = 5;
595     count[0] = 2;
596     count[1] = 3;
597     block[0] = 2;
598     block[1] = 4;
599     if(H5Sselect_hyperslab(srcspace[0], H5S_SELECT_SET, start, stride, count, block) < 0)
600         TEST_ERROR
601 
602     /* Select composite hyperslab in virtual space */
603     count[0] = 1;
604     count[1] = 1;
605     block[0] = 5;
606     block[1] = 6;
607     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, NULL, count, block) < 0)
608         TEST_ERROR
609     start[0] = 7;
610     start[1] = 0;
611     block[0] = 1;
612     block[1] = 18;
613     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_OR, start, NULL, count, block) < 0)
614         TEST_ERROR
615 
616     /* Add virtual layout mapping */
617     if(H5Pset_virtual(dcpl, vspace[0], src_file[0], src_dset[0], srcspace[0]) < 0)
618         TEST_ERROR
619 
620     /* Get examination DCPL */
621 
622     /* Correct previous fix for HDFFV-10469 */
623     if(test_api_get_ex_dcpl(config, fapl, dcpl, &ex_dcpl, vspace[0], filename, (hsize_t)213) < 0)
624         TEST_ERROR
625 
626     /* Test H5Pget_virtual_count */
627     if(H5Pget_virtual_count(ex_dcpl, &size_out) < 0)
628         TEST_ERROR
629     if(size_out != (size_t)1)
630         TEST_ERROR
631 
632     /* Check that the mapping in the DCPL is correct */
633     if(vds_check_mapping(ex_dcpl, (size_t)0, vspace[0], srcspace[0], src_file[0], src_dset[0]) < 0)
634         TEST_ERROR
635 
636     /* Close */
637     if(H5Sclose(srcspace[0]) < 0)
638         TEST_ERROR
639     srcspace[0] = -1;
640     if(H5Sclose(vspace[0]) < 0)
641         TEST_ERROR
642     vspace[0] = -1;
643     if(H5Pclose(ex_dcpl) < 0)
644         TEST_ERROR
645     ex_dcpl = -1;
646 
647 
648 #ifdef VDS_POINT_SELECTIONS /* VDS does not currently support point selections */
649     /*
650      * Test 3: Point - point selection
651      */
652     /* Clear virtual layout in DCPL */
653     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
654         TEST_ERROR
655 
656     /* Create source dataspace */
657     if((srcspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
658         TEST_ERROR
659 
660     /* Create virtual dataspace */
661     if((vspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
662         TEST_ERROR
663 
664     /* Select points in source space */
665     coord[0] = 5;
666     coord[1] = 15;
667     coord[2] = 7;
668     coord[3] = 19;
669     coord[4] = 8;
670     coord[5] = 0;
671     coord[6] = 2;
672     coord[7] = 14;
673     coord[8] = 8;
674     coord[9] = 18;
675     if(H5Sselect_elements(srcspace[0], H5S_SELECT_SET, (size_t)5, coord) < 0)
676         TEST_ERROR
677 
678     /* Select points in virtual space */
679     coord[0] = 3;
680     coord[1] = 12;
681     coord[2] = 7;
682     coord[3] = 11;
683     coord[4] = 4;
684     coord[5] = 9;
685     coord[6] = 7;
686     coord[7] = 11;
687     coord[8] = 5;
688     coord[9] = 5;
689     if(H5Sselect_elements(vspace[0], H5S_SELECT_SET, (size_t)5, coord) < 0)
690         TEST_ERROR
691 
692     /* Add virtual layout mapping */
693     if(H5Pset_virtual(dcpl, vspace[0], src_file[0], src_dset[0], srcspace[0]) < 0)
694         TEST_ERROR
695 
696     /* Get examination DCPL */
697     if(test_api_get_ex_dcpl(config, fapl, dcpl, &ex_dcpl, vspace[0], filename, (hsize_t)0) < 0)
698         TEST_ERROR
699 
700     /* Test H5Pget_virtual_count */
701     if(H5Pget_virtual_count(ex_dcpl, &size_out) < 0)
702         TEST_ERROR
703     if(size_out != (size_t)1)
704         TEST_ERROR
705 
706     /* Check that the mapping in the DCPL is correct */
707     if(vds_check_mapping(ex_dcpl, (size_t)0, vspace[0], srcspace[0], src_file[0], src_dset[0]) < 0)
708         TEST_ERROR
709 
710     /* Close */
711     if(H5Sclose(srcspace[0]) < 0)
712         TEST_ERROR
713     srcspace[0] = -1;
714     if(H5Sclose(vspace[0]) < 0)
715         TEST_ERROR
716     vspace[0] = -1;
717     if(H5Pclose(ex_dcpl) < 0)
718         TEST_ERROR
719     ex_dcpl = -1;
720 
721 
722     /*
723      * Test 4: Point - hyper selection
724      */
725     /* Clear virtual layout in DCPL */
726     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
727         TEST_ERROR
728 
729     /* Create source dataspace */
730     if((srcspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
731         TEST_ERROR
732 
733     /* Create virtual dataspace */
734     if((vspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
735         TEST_ERROR
736 
737     /* Select hyperslab in source space */
738     start[0] = 2;
739     start[1] = 7;
740     count[0] = 1;
741     count[1] = 1;
742     block[0] = 1;
743     block[1] = 5;
744     if(H5Sselect_hyperslab(srcspace[0], H5S_SELECT_SET, start, NULL, count, block) < 0)
745         TEST_ERROR
746 
747     /* Select points in virtual space */
748     coord[0] = 1;
749     coord[1] = 1;
750     coord[2] = 4;
751     coord[3] = 17;
752     coord[4] = 3;
753     coord[5] = 9;
754     coord[6] = 5;
755     coord[7] = 13;
756     coord[8] = 7;
757     coord[9] = 16;
758     if(H5Sselect_elements(vspace[0], H5S_SELECT_SET, (size_t)5, coord) < 0)
759         TEST_ERROR
760 
761     /* Add virtual layout mapping */
762     if(H5Pset_virtual(dcpl, vspace[0], src_file[0], src_dset[0], srcspace[0]) < 0)
763         TEST_ERROR
764 
765     /* Get examination DCPL */
766     if(test_api_get_ex_dcpl(config, fapl, dcpl, &ex_dcpl, vspace[0], filename, (hsize_t)0) < 0)
767         TEST_ERROR
768 
769     /* Test H5Pget_virtual_count */
770     if(H5Pget_virtual_count(ex_dcpl, &size_out) < 0)
771         TEST_ERROR
772     if(size_out != (size_t)1)
773         TEST_ERROR
774 
775     /* Check that the mapping in the DCPL is correct */
776     if(vds_check_mapping(ex_dcpl, (size_t)0, vspace[0], srcspace[0], src_file[0], src_dset[0]) < 0)
777         TEST_ERROR
778 
779     /* Close */
780     if(H5Sclose(srcspace[0]) < 0)
781         TEST_ERROR
782     srcspace[0] = -1;
783     if(H5Sclose(vspace[0]) < 0)
784         TEST_ERROR
785     vspace[0] = -1;
786     if(H5Pclose(ex_dcpl) < 0)
787         TEST_ERROR
788     ex_dcpl = -1;
789 
790 
791     /*
792      * Test 5: All previous mappings together
793      */
794     /* Clear virtual layout in DCPL */
795     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
796         TEST_ERROR
797 
798     /* Create dataspaces */
799     for(i = 0; i < 4; i++) {
800         /* Create source dataspace */
801         if((srcspace[i] = H5Screate_simple(2, dims, NULL)) < 0)
802             TEST_ERROR
803 
804         /* Create virtual dataspace */
805         if((vspace[i] = H5Screate_simple(2, dims, NULL)) < 0)
806             TEST_ERROR
807     }
808 
809     /* Select all (should not be necessary, but just to be sure) */
810     if(H5Sselect_all(srcspace[0]) < 0)
811         TEST_ERROR
812     if(H5Sselect_all(vspace[0]) < 0)
813         TEST_ERROR
814 
815     /* Select regular hyperslab in source space */
816     start[0] = 2;
817     start[1] = 1;
818     stride[0] = 3;
819     stride[1] = 5;
820     count[0] = 2;
821     count[1] = 3;
822     block[0] = 2;
823     block[1] = 4;
824     if(H5Sselect_hyperslab(srcspace[1], H5S_SELECT_SET, start, stride, count, block) < 0)
825         TEST_ERROR
826 
827     /* Select composite hyperslab in virtual space */
828     count[0] = 1;
829     count[1] = 1;
830     block[0] = 5;
831     block[1] = 6;
832     if(H5Sselect_hyperslab(vspace[1], H5S_SELECT_SET, start, NULL, count, block) < 0)
833         TEST_ERROR
834     start[0] = 7;
835     start[1] = 0;
836     block[0] = 1;
837     block[1] = 18;
838     if(H5Sselect_hyperslab(vspace[1], H5S_SELECT_OR, start, NULL, count, block) < 0)
839         TEST_ERROR
840 
841     /* Select points in source space */
842     coord[0] = 5;
843     coord[1] = 15;
844     coord[2] = 7;
845     coord[3] = 19;
846     coord[4] = 8;
847     coord[5] = 0;
848     coord[6] = 2;
849     coord[7] = 14;
850     coord[8] = 8;
851     coord[9] = 18;
852     if(H5Sselect_elements(srcspace[2], H5S_SELECT_SET, (size_t)5, coord) < 0)
853         TEST_ERROR
854 
855     /* Select points in virtual space */
856     coord[0] = 3;
857     coord[1] = 12;
858     coord[2] = 7;
859     coord[3] = 11;
860     coord[4] = 4;
861     coord[5] = 9;
862     coord[6] = 7;
863     coord[7] = 11;
864     coord[8] = 5;
865     coord[9] = 5;
866     if(H5Sselect_elements(vspace[2], H5S_SELECT_SET, (size_t)5, coord) < 0)
867         TEST_ERROR
868 
869     /* Select hyperslab in source space */
870     start[0] = 2;
871     start[1] = 7;
872     count[0] = 1;
873     count[1] = 1;
874     block[0] = 1;
875     block[1] = 5;
876     if(H5Sselect_hyperslab(srcspace[3], H5S_SELECT_SET, start, NULL, count, block) < 0)
877         TEST_ERROR
878 
879     /* Select points in virtual space */
880     coord[0] = 1;
881     coord[1] = 1;
882     coord[2] = 4;
883     coord[3] = 17;
884     coord[4] = 3;
885     coord[5] = 9;
886     coord[6] = 5;
887     coord[7] = 13;
888     coord[8] = 7;
889     coord[9] = 16;
890     if(H5Sselect_elements(vspace[3], H5S_SELECT_SET, (size_t)5, coord) < 0)
891         TEST_ERROR
892 
893     /* Add virtual layout mappings */
894     for(i = 0; i < 4; i++)
895         if(H5Pset_virtual(dcpl, vspace[i], src_file[i], src_dset[i], srcspace[i]) < 0)
896             TEST_ERROR
897 
898     /* Get examination DCPL */
899     if(test_api_get_ex_dcpl(config, fapl, dcpl, &ex_dcpl, vspace[0], filename, (hsize_t)0) < 0)
900         TEST_ERROR
901 
902     /* Test H5Pget_virtual_count */
903     if(H5Pget_virtual_count(ex_dcpl, &size_out) < 0)
904         TEST_ERROR
905     if(size_out != (size_t)4)
906         TEST_ERROR
907 
908     /* Check that the mappings in the DCPL are correct */
909     for(i = 0; i < 4; i++)
910         if(vds_check_mapping(ex_dcpl, (size_t)i, vspace[i], srcspace[i], src_file[i], src_dset[i]) < 0)
911             TEST_ERROR
912 
913     /* Close */
914     for(i = 0; i < 4; i++) {
915         if(H5Sclose(srcspace[i]) < 0)
916             TEST_ERROR
917         srcspace[i] = -1;
918         if(H5Sclose(vspace[i]) < 0)
919             TEST_ERROR
920         vspace[i] = -1;
921     }
922     if(H5Pclose(ex_dcpl) < 0)
923         TEST_ERROR
924     ex_dcpl = -1;
925 
926 #else /* VDS_POINT_SELECTIONS */
927 
928     /*
929      * Test 3: Verify point selections fail
930      */
931     /* Clear virtual layout in DCPL */
932     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
933         TEST_ERROR
934 
935     /* Create source dataspace */
936     if((srcspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
937         TEST_ERROR
938 
939     /* Create virtual dataspace */
940     if((vspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
941         TEST_ERROR
942 
943     /* Select points in source space */
944     coord[0] = 5;
945     coord[1] = 15;
946     coord[2] = 7;
947     coord[3] = 19;
948     coord[4] = 8;
949     coord[5] = 0;
950     coord[6] = 2;
951     coord[7] = 14;
952     coord[8] = 8;
953     coord[9] = 18;
954     if(H5Sselect_elements(srcspace[0], H5S_SELECT_SET, (size_t)5, coord) < 0)
955         TEST_ERROR
956 
957     /* Select points in virtual space */
958     coord[0] = 3;
959     coord[1] = 12;
960     coord[2] = 7;
961     coord[3] = 11;
962     coord[4] = 4;
963     coord[5] = 9;
964     coord[6] = 7;
965     coord[7] = 11;
966     coord[8] = 5;
967     coord[9] = 5;
968     if(H5Sselect_elements(vspace[0], H5S_SELECT_SET, (size_t)5, coord) < 0)
969         TEST_ERROR
970 
971     /* Attempt to add virtual layout mapping */
972     H5E_BEGIN_TRY {
973         ret = H5Pset_virtual(dcpl, vspace[0], src_file[0], src_dset[0], srcspace[0]);
974     } H5E_END_TRY
975     if(ret >= 0)
976         TEST_ERROR
977 #endif /* VDS_POINT_SELECTIONS */
978 
979 
980     /*
981      * Test 6: Enough Selections to trigger doubling of mapping list
982      */
983     /* Clear virtual layout in DCPL */
984     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
985         TEST_ERROR
986 
987     /* Create source dataspace */
988     dims[0] = 1;
989     if((srcspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
990         TEST_ERROR
991 
992     /* Select all in source space (should not be necessary, but just to be sure) */
993     if(H5Sselect_all(srcspace[0]) < 0)
994         TEST_ERROR
995 
996     /* Init virtual space extent */
997     dims[0] = LIST_DOUBLE_SIZE;
998 
999     /* Init hyperslab values */
1000     start[0] = 0;
1001     start[1] = 0;
1002     count[0] = 1;
1003     count[1] = 1;
1004     block[0] = 1;
1005     block[1] = 20;
1006 
1007     /* Build virtual layout */
1008     for(i = 0; i < LIST_DOUBLE_SIZE; i++) {
1009         /* Create virtual dataspace */
1010         if((vspace[i] = H5Screate_simple(2, dims, NULL)) < 0)
1011             TEST_ERROR
1012 
1013         /* Select row in virual dataspace */
1014         start[0] = (hsize_t)i;
1015         if(H5Sselect_hyperslab(vspace[i], H5S_SELECT_SET, start, NULL, count, block) < 0)
1016             TEST_ERROR
1017 
1018         /* Create file and dataset names */
1019         (void)HDsnprintf(tmp_filename, sizeof(tmp_filename), "src_file%u", i);
1020         tmp_filename[sizeof(tmp_filename) - 1] = '\0';
1021         (void)HDsnprintf(tmp_dsetname, sizeof(tmp_dsetname), "src_dset%u", i);
1022         tmp_dsetname[sizeof(tmp_dsetname) - 1] = '\0';
1023 
1024         /* Add virtual layout mapping */
1025         if(H5Pset_virtual(dcpl, vspace[i], tmp_filename, tmp_dsetname, srcspace[0]) < 0)
1026             TEST_ERROR
1027     }
1028 
1029     /* Get examination DCPL */
1030     if(test_api_get_ex_dcpl(config, fapl, dcpl, &ex_dcpl, vspace[0], filename, (hsize_t)697) < 0)
1031         TEST_ERROR
1032 
1033     /* Test H5Pget_virtual_count */
1034     if(H5Pget_virtual_count(ex_dcpl, &size_out) < 0)
1035         TEST_ERROR
1036     if(size_out != (size_t)LIST_DOUBLE_SIZE)
1037         TEST_ERROR
1038 
1039     /* Verify virtual layout */
1040     for(i = 0; i < LIST_DOUBLE_SIZE; i++) {
1041         /* Generate source file name */
1042         (void)HDsnprintf(tmp_filename, sizeof(tmp_filename), "src_file%u", i);
1043         tmp_filename[sizeof(tmp_filename) - 1] = '\0';
1044 
1045         /* Generate source dset name */
1046         (void)HDsnprintf(tmp_dsetname, sizeof(tmp_dsetname), "src_dset%u", i);
1047         tmp_dsetname[sizeof(tmp_dsetname) - 1] = '\0';
1048 
1049         /* Check that the mapping in the DCPL is correct */
1050         if(vds_check_mapping(ex_dcpl, (size_t)i, vspace[i], srcspace[0], tmp_filename, tmp_dsetname) < 0)
1051             TEST_ERROR
1052     }
1053 
1054     /* Close */
1055     if(H5Sclose(srcspace[0]) < 0)
1056         TEST_ERROR
1057     srcspace[0] = -1;
1058     for(i = 0; i < LIST_DOUBLE_SIZE; i++) {
1059         if(H5Sclose(vspace[i]) < 0)
1060             TEST_ERROR
1061         vspace[i] = -1;
1062     }
1063     if(H5Pclose(ex_dcpl) < 0)
1064         TEST_ERROR
1065     ex_dcpl = -1;
1066 
1067 
1068     /*
1069      * Test 7: Empty VDS
1070      */
1071     /* Clear virtual layout in DCPL */
1072     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
1073         TEST_ERROR
1074 
1075     /* Create virtual dataspace */
1076     if((vspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
1077         TEST_ERROR
1078 
1079     /* Select all (should not be necessary, but just to be sure) */
1080     if(H5Sselect_all(vspace[0]) < 0)
1081         TEST_ERROR
1082 
1083     /* Get examination DCPL */
1084     if(test_api_get_ex_dcpl(config, fapl, dcpl, &ex_dcpl, vspace[0], filename, (hsize_t)0) < 0)
1085         TEST_ERROR
1086 
1087     /* Test H5Pget_virtual_count */
1088     if(H5Pget_virtual_count(ex_dcpl, &size_out) < 0)
1089         TEST_ERROR
1090     if(size_out != (size_t)0)
1091         TEST_ERROR
1092 
1093     /* Close */
1094     if(H5Sclose(vspace[0]) < 0)
1095         TEST_ERROR
1096     vspace[0] = -1;
1097     if(H5Pclose(ex_dcpl) < 0)
1098         TEST_ERROR
1099     ex_dcpl = -1;
1100 
1101 
1102     /* Close */
1103     if(H5Pclose(dcpl) < 0)
1104         TEST_ERROR
1105     dcpl = -1;
1106 
1107     PASSED();
1108     return 0;
1109 
1110 error:
1111     H5E_BEGIN_TRY {
1112         for(i = 0; i < (sizeof(srcspace) / sizeof(srcspace[0])); i++)
1113             H5Sclose(srcspace[i]);
1114         for(i = 0; i < (sizeof(vspace) / sizeof(vspace[0])); i++)
1115             H5Sclose(vspace[i]);
1116         H5Pclose(dcpl);
1117         H5Pclose(ex_dcpl);
1118     } H5E_END_TRY;
1119 
1120      return 1;
1121 } /* end test_api() */
1122 
1123 /*-------------------------------------------------------------------------
1124  * Function:    vds_link_prefix_first
1125  *
1126  * Purpose:     Set up vds link prefix via H5Pset_virtual_prefix() to be "tmp"
1127  *        Should be able to access the target source files in tmp directory via the prefix set
1128  *        by H5Pset_virtual_prefix()
1129  *
1130  * Return:      Success:        0
1131  *              Failure:        -1
1132  *-------------------------------------------------------------------------
1133  */
1134 static int
test_vds_prefix_first(unsigned config,hid_t fapl)1135 test_vds_prefix_first(unsigned config, hid_t fapl)
1136 {
1137     char        srcfilename[FILENAME_BUF_SIZE];
1138     char        srcfilename_map[FILENAME_BUF_SIZE];
1139     char        vfilename[FILENAME_BUF_SIZE];
1140     char        vfilename2[FILENAME_BUF_SIZE];
1141     char        srcfilenamepct[FILENAME_BUF_SIZE];
1142     char        srcfilenamepct_map[FILENAME_BUF_SIZE];
1143     const char *srcfilenamepct_map_orig = "vds%%%%_src";
1144     hid_t       srcfile[4] = {-1, -1, -1, -1}; /* Files with source dsets */
1145     hid_t       vfile = -1;     /* File with virtual dset */
1146     hid_t       vfile2 = -1;    /* File with copied virtual dset */
1147     hid_t       dcpl = -1;      /* Dataset creation property list */
1148     hid_t       dapl = -1;      /* Dataset access property list */
1149     hid_t       srcspace[4] = {-1, -1, -1, -1}; /* Source dataspaces */
1150     hid_t       vspace[4] = {-1, -1, -1, -1}; /* Virtual dset dataspaces */
1151     hid_t       memspace = -1;  /* Memory dataspace */
1152     hid_t       srcdset[4] = {-1, -1, -1, -1}; /* Source datsets */
1153     hid_t       vdset = -1;     /* Virtual dataset */
1154     hsize_t     dims[4] = {10, 26, 0, 0}; /* Data space current size */
1155     int         buf[10][26];    /* Write and expected read buffer */
1156     int         rbuf[10][26];   /* Read buffer */
1157     int         fill = -1;      /* Fill value */
1158     int         i, j;
1159     char        buffer[1024];   /* buffer to read vds_prefix       */
1160 
1161     TESTING("basic virtual dataset I/O via H5Pset_vds_prefix(): all selection")
1162 
1163     h5_fixname(FILENAME[0], fapl, vfilename, sizeof vfilename);
1164     h5_fixname(FILENAME[7], fapl, vfilename2, sizeof vfilename2);
1165     h5_fixname(FILENAME[8], fapl, srcfilename, sizeof srcfilename);
1166     h5_fixname_printf(FILENAME[8], fapl, srcfilename_map, sizeof srcfilename_map);
1167     h5_fixname(FILENAME[10], fapl, srcfilenamepct, sizeof srcfilenamepct);
1168     h5_fixname_printf(srcfilenamepct_map_orig, fapl, srcfilenamepct_map, sizeof srcfilenamepct_map);
1169 
1170     /* create tmp directory and get current working directory path */
1171     if (HDmkdir(TMPDIR, (mode_t)0755) < 0 && errno != EEXIST)
1172         TEST_ERROR
1173 
1174     /* Create DCPL */
1175     if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
1176         TEST_ERROR
1177 
1178     /* Set fill value */
1179     if(H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fill) < 0)
1180         TEST_ERROR
1181 
1182     /* Initialize VDS prefix items */
1183     if((dapl = H5Pcreate(H5P_DATASET_ACCESS)) < 0)
1184         TEST_ERROR
1185 
1186     if(H5Pset_virtual_prefix(dapl, TMPDIR) < 0)
1187         TEST_ERROR
1188     if(H5Pget_virtual_prefix(dapl, buffer, sizeof(buffer)) < 0)
1189         TEST_ERROR
1190 
1191     if(HDstrcmp(buffer, TMPDIR) != 0)
1192         FAIL_PUTS_ERROR("vds prefix not set correctly");
1193 
1194     /* Create source dataspace */
1195     if((srcspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
1196         TEST_ERROR
1197 
1198     /* Create virtual dataspace */
1199     if((vspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
1200         TEST_ERROR
1201 
1202     /* Select all (should not be necessary, but just to be sure) */
1203     if(H5Sselect_all(srcspace[0]) < 0)
1204         TEST_ERROR
1205     if(H5Sselect_all(vspace[0]) < 0)
1206         TEST_ERROR
1207 
1208     /* Add virtual layout mapping */
1209     if(H5Pset_virtual(dcpl, vspace[0], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset", srcspace[0]) < 0)
1210         TEST_ERROR
1211 
1212     /* Create virtual file */
1213     if((vfile = H5Fcreate(vfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
1214         TEST_ERROR
1215 
1216     /* Create source file if requested */
1217     if(config & TEST_IO_DIFFERENT_FILE) {
1218         if(NULL == HDgetcwd(buffer, 1024))
1219             TEST_ERROR
1220         if(HDchdir(TMPDIR) < 0)
1221             TEST_ERROR
1222         if((srcfile[0] = H5Fcreate(srcfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
1223             TEST_ERROR
1224         if(HDchdir(buffer) < 0)
1225             TEST_ERROR
1226     }
1227     else {
1228         srcfile[0] = vfile;
1229         if(H5Iinc_ref(srcfile[0]) < 0)
1230             TEST_ERROR
1231     }
1232 
1233     /* Create source dataset */
1234     if((srcdset[0] = H5Dcreate2(srcfile[0], "src_dset", H5T_NATIVE_INT, srcspace[0], H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
1235         TEST_ERROR
1236 
1237     /* Create virtual dataset */
1238     if((vdset = H5Dcreate2(vfile, "v_dset", H5T_NATIVE_INT, vspace[0], H5P_DEFAULT, dcpl, dapl)) < 0)
1239         TEST_ERROR
1240 
1241     /* Populate write buffer */
1242     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
1243         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
1244             buf[i][j] = (i * (int)(sizeof(buf[0]) / sizeof(buf[0][0]))) + j;
1245 
1246     /* Write data directly to source dataset */
1247     if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
1248         TEST_ERROR
1249 
1250     /* Close srcdset and srcfile if config option specified */
1251     if(config & TEST_IO_CLOSE_SRC) {
1252         if(H5Dclose(srcdset[0]) < 0)
1253             TEST_ERROR
1254         srcdset[0] = -1;
1255 
1256         if(config & TEST_IO_DIFFERENT_FILE) {
1257             if(H5Fclose(srcfile[0]) < 0)
1258                 TEST_ERROR
1259             srcfile[0] = -1;
1260         }
1261     }
1262 
1263     /* Reopen virtual dataset and file if config option specified */
1264     if(config & TEST_IO_REOPEN_VIRT) {
1265         if(H5Dclose(vdset) < 0)
1266             TEST_ERROR
1267         vdset = -1;
1268         if(H5Fclose(vfile) < 0)
1269             TEST_ERROR
1270         vfile = -1;
1271         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
1272             TEST_ERROR
1273         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
1274             TEST_ERROR
1275     }
1276 
1277     /* Read data through virtual dataset */
1278     HDmemset(rbuf[0], 0, sizeof(rbuf));
1279     if(H5Dread(vdset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
1280         TEST_ERROR
1281 
1282     /* Verify read data */
1283     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++) {
1284         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
1285             if(rbuf[i][j] != buf[i][j]) {
1286                 TEST_ERROR
1287             }
1288     }
1289 
1290     /* Adjust write buffer */
1291     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
1292         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
1293             buf[i][j] += (int)(sizeof(buf) / sizeof(buf[0][0]));
1294 
1295     /* Write data through virtual dataset */
1296     if(H5Dwrite(vdset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
1297         TEST_ERROR
1298 
1299     /* Reopen srcdset and srcfile if config option specified */
1300     if(config & TEST_IO_CLOSE_SRC) {
1301         if(config & TEST_IO_DIFFERENT_FILE) {
1302             if(NULL == HDgetcwd(buffer, 1024))
1303                 TEST_ERROR
1304             if(HDchdir(TMPDIR) < 0)
1305                 TEST_ERROR
1306             if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDONLY, fapl)) < 0)
1307                 TEST_ERROR
1308             if(HDchdir(buffer) < 0)
1309                 TEST_ERROR
1310         }
1311         if((srcdset[0] = H5Dopen2(srcfile[0], "src_dset", H5P_DEFAULT)) < 0)
1312             TEST_ERROR
1313     }
1314 
1315     /* Read data directly from source dataset */
1316     HDmemset(rbuf[0], 0, sizeof(rbuf));
1317     if(H5Dread(srcdset[0], H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
1318         TEST_ERROR
1319 
1320     /* Verify read data */
1321     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
1322         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
1323             if(rbuf[i][j] != buf[i][j])
1324                 TEST_ERROR
1325 
1326     /* Close */
1327     if(H5Dclose(srcdset[0]) < 0)
1328         TEST_ERROR
1329     srcdset[0] = -1;
1330     if(H5Dclose(vdset) < 0)
1331         TEST_ERROR
1332     vdset = -1;
1333     if(H5Fclose(srcfile[0]) < 0)
1334         TEST_ERROR
1335     srcfile[0] = -1;
1336     if(H5Fclose(vfile) < 0)
1337         TEST_ERROR
1338     vfile = -1;
1339     if(H5Sclose(srcspace[0]) < 0)
1340         TEST_ERROR
1341     srcspace[0] = -1;
1342     if(H5Sclose(vspace[0]) < 0)
1343         TEST_ERROR
1344     vspace[0] = -1;
1345     if(H5Pclose(dapl) < 0)
1346         TEST_ERROR
1347     dapl = -1;
1348     if(H5Pclose(dcpl) < 0)
1349         TEST_ERROR
1350     dcpl = -1;
1351 
1352     PASSED();
1353     return 0;
1354 
1355  error:
1356     H5E_BEGIN_TRY {
1357         for(i = 0; i < (int)(sizeof(srcdset) / sizeof(srcdset[0])); i++)
1358             H5Dclose(srcdset[i]);
1359         H5Dclose(vdset);
1360         for(i = 0; i < (int)(sizeof(srcfile) / sizeof(srcfile[0])); i++)
1361             H5Fclose(srcfile[i]);
1362         H5Fclose(vfile);
1363         for(i = 0; i < (int)(sizeof(srcspace) / sizeof(srcspace[0])); i++)
1364             H5Sclose(srcspace[i]);
1365         for(i = 0; i < (int)(sizeof(vspace) / sizeof(vspace[0])); i++)
1366             H5Sclose(vspace[i]);
1367         H5Sclose(memspace);
1368         H5Pclose(dapl);
1369         H5Pclose(dcpl);
1370     } H5E_END_TRY;
1371 
1372     if(HDsetenv("HDF5_VDS_PREFIX", "", 1) < 0)
1373         TEST_ERROR
1374 
1375     return 1;
1376 } /* end test_vds_prefix */
1377 
1378 
1379 /*-------------------------------------------------------------------------
1380  * Function:    test_basic_io
1381  *
1382  * Purpose:     Tests VDS I/O without unlimited selections or
1383  *              pattern-matching file/dataset strings
1384  *
1385  * Return:      Success:        0
1386  *              Failure:        number of errors
1387  *-------------------------------------------------------------------------
1388  */
1389 static int
test_basic_io(unsigned config,hid_t fapl)1390 test_basic_io(unsigned config, hid_t fapl)
1391 {
1392     char        srcfilename[FILENAME_BUF_SIZE];
1393     char        srcfilename_map[FILENAME_BUF_SIZE];
1394     char        vfilename[FILENAME_BUF_SIZE];
1395     char        vfilename2[FILENAME_BUF_SIZE];
1396     char        srcfilenamepct[FILENAME_BUF_SIZE];
1397     char        srcfilenamepct_map[FILENAME_BUF_SIZE];
1398     const char *srcfilenamepct_map_orig = "vds%%%%_src";
1399     hid_t       srcfile[4] = {-1, -1, -1, -1}; /* Files with source dsets */
1400     hid_t       vfile = -1;     /* File with virtual dset */
1401     hid_t       vfile2 = -1;    /* File with copied virtual dset */
1402     hid_t       dcpl = -1;      /* Dataset creation property list */
1403     hid_t       srcspace[4] = {-1, -1, -1, -1}; /* Source dataspaces */
1404     hid_t       vspace[4] = {-1, -1, -1, -1}; /* Virtual dset dataspaces */
1405     hid_t       memspace = -1;  /* Memory dataspace */
1406     hid_t       srcdset[4] = {-1, -1, -1, -1}; /* Source datsets */
1407     hid_t       vdset = -1;     /* Virtual dataset */
1408     hsize_t     dims[4] = {10, 26, 0, 0}; /* Data space current size */
1409     hsize_t     start[4];       /* Hyperslab start */
1410     hsize_t     stride[4];      /* Hyperslab stride */
1411     hsize_t     count[4];       /* Hyperslab count */
1412     hsize_t     block[4];       /* Hyperslab block */
1413     hssize_t    offset[2] = {0, 0}; /* Selection offset */
1414     int         buf[10][26];    /* Write and expected read buffer */
1415     int         rbuf[10][26];   /* Read buffer */
1416     int         rbuf99[9][9];   /* 9x9 Read buffer */
1417     int         evbuf[10][26];  /* Expected VDS "buffer" */
1418     int         erbuf[10][26];  /* Expected read buffer */
1419     int         fill = -1;      /* Fill value */
1420     herr_t      ret;            /* Generic return value */
1421     int         i, j;
1422 
1423     TESTING("basic virtual dataset I/O")
1424 
1425     h5_fixname(FILENAME[0], fapl, vfilename, sizeof vfilename);
1426     h5_fixname(FILENAME[1], fapl, vfilename2, sizeof vfilename2);
1427     h5_fixname(FILENAME[2], fapl, srcfilename, sizeof srcfilename);
1428     h5_fixname_printf(FILENAME[2], fapl, srcfilename_map, sizeof srcfilename_map);
1429     h5_fixname(FILENAME[4], fapl, srcfilenamepct, sizeof srcfilenamepct);
1430     h5_fixname_printf(srcfilenamepct_map_orig, fapl, srcfilenamepct_map, sizeof srcfilenamepct_map);
1431 
1432     /* Create DCPL */
1433     if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
1434         TEST_ERROR
1435 
1436     /* Set fill value */
1437     if(H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fill) < 0)
1438         TEST_ERROR
1439 
1440     /*
1441      * Test 1: All - all selection
1442      */
1443     /* Create source dataspace */
1444     if((srcspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
1445         TEST_ERROR
1446 
1447     /* Create virtual dataspace */
1448     if((vspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
1449         TEST_ERROR
1450 
1451     /* Select all (should not be necessary, but just to be sure) */
1452     if(H5Sselect_all(srcspace[0]) < 0)
1453         TEST_ERROR
1454     if(H5Sselect_all(vspace[0]) < 0)
1455         TEST_ERROR
1456 
1457     /* Add virtual layout mapping */
1458     if(H5Pset_virtual(dcpl, vspace[0], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset", srcspace[0]) < 0)
1459         TEST_ERROR
1460 
1461     /* Create virtual file */
1462     if((vfile = H5Fcreate(vfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
1463         TEST_ERROR
1464 
1465     /* Create source file if requested */
1466     if(config & TEST_IO_DIFFERENT_FILE) {
1467         if((srcfile[0] = H5Fcreate(srcfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
1468             TEST_ERROR
1469     }
1470     else {
1471         srcfile[0] = vfile;
1472         if(H5Iinc_ref(srcfile[0]) < 0)
1473             TEST_ERROR
1474     }
1475 
1476     /* Create source dataset */
1477     if((srcdset[0] = H5Dcreate2(srcfile[0], "src_dset", H5T_NATIVE_INT, srcspace[0], H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
1478         TEST_ERROR
1479 
1480     /* Create virtual dataset */
1481     if((vdset = H5Dcreate2(vfile, "v_dset", H5T_NATIVE_INT, vspace[0], H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
1482         TEST_ERROR
1483 
1484     /* Populate write buffer */
1485     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
1486         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
1487             buf[i][j] = (i * (int)(sizeof(buf[0]) / sizeof(buf[0][0]))) + j;
1488 
1489     /* Write data directly to source dataset */
1490     if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
1491         TEST_ERROR
1492 
1493     /* Close srcdset and srcfile if config option specified */
1494     if(config & TEST_IO_CLOSE_SRC) {
1495         if(H5Dclose(srcdset[0]) < 0)
1496             TEST_ERROR
1497         srcdset[0] = -1;
1498 
1499         if(config & TEST_IO_DIFFERENT_FILE) {
1500             if(H5Fclose(srcfile[0]) < 0)
1501                 TEST_ERROR
1502             srcfile[0] = -1;
1503         }
1504     }
1505 
1506     /* Reopen virtual dataset and file if config option specified */
1507     if(config & TEST_IO_REOPEN_VIRT) {
1508         if(H5Dclose(vdset) < 0)
1509             TEST_ERROR
1510         vdset = -1;
1511         if(H5Fclose(vfile) < 0)
1512             TEST_ERROR
1513         vfile = -1;
1514         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
1515             TEST_ERROR
1516         if((vdset = H5Dopen2(vfile, "v_dset", H5P_DEFAULT)) < 0)
1517             TEST_ERROR
1518     }
1519 
1520     /* Read data through virtual dataset */
1521     HDmemset(rbuf[0], 0, sizeof(rbuf));
1522     if(H5Dread(vdset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
1523         TEST_ERROR
1524 
1525     /* Verify read data */
1526     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
1527         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
1528             if(rbuf[i][j] != buf[i][j])
1529                 TEST_ERROR
1530 
1531     /* Adjust write buffer */
1532     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
1533         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
1534             buf[i][j] += (int)(sizeof(buf) / sizeof(buf[0][0]));
1535 
1536     /* Write data through virtual dataset */
1537     if(H5Dwrite(vdset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
1538         TEST_ERROR
1539 
1540     /* Reopen srcdset and srcfile if config option specified */
1541     if(config & TEST_IO_CLOSE_SRC) {
1542         if(config & TEST_IO_DIFFERENT_FILE)
1543             if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDONLY, fapl)) < 0)
1544                 TEST_ERROR
1545         if((srcdset[0] = H5Dopen2(srcfile[0], "src_dset", H5P_DEFAULT)) < 0)
1546             TEST_ERROR
1547     }
1548 
1549     /* Read data directly from source dataset */
1550     HDmemset(rbuf[0], 0, sizeof(rbuf));
1551     if(H5Dread(srcdset[0], H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
1552         TEST_ERROR
1553 
1554     /* Verify read data */
1555     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
1556         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
1557             if(rbuf[i][j] != buf[i][j])
1558                 TEST_ERROR
1559 
1560     /* Close */
1561     if(H5Dclose(srcdset[0]) < 0)
1562         TEST_ERROR
1563     srcdset[0] = -1;
1564     if(H5Dclose(vdset) < 0)
1565         TEST_ERROR
1566     vdset = -1;
1567     if(H5Fclose(srcfile[0]) < 0)
1568         TEST_ERROR
1569     srcfile[0] = -1;
1570     if(H5Fclose(vfile) < 0)
1571         TEST_ERROR
1572     vfile = -1;
1573     if(H5Sclose(srcspace[0]) < 0)
1574         TEST_ERROR
1575     srcspace[0] = -1;
1576     if(H5Sclose(vspace[0]) < 0)
1577         TEST_ERROR
1578     vspace[0] = -1;
1579 
1580 
1581     /*
1582      * Test 2: 2 Source datasets, hyperslab virtual mappings, '%' in source
1583      * dataset name, also test H5Ocopy()
1584      */
1585     /* Clear virtual layout in DCPL */
1586     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
1587         TEST_ERROR
1588 
1589     /* Create virtual dataspaces */
1590     if((vspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
1591         TEST_ERROR
1592     if((vspace[1] = H5Screate_simple(2, dims, NULL)) < 0)
1593         TEST_ERROR
1594 
1595     /* Create source dataspace */
1596     dims[1] = 13;
1597     if((srcspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
1598         TEST_ERROR
1599 
1600     /* Select all in source space (should not be necessary, but just to be sure)
1601      */
1602     if(H5Sselect_all(srcspace[0]) < 0)
1603         TEST_ERROR
1604 
1605     /* Select hyperslabs in virtual spaces */
1606     start[0] = 0;
1607     start[1] = 0;
1608     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
1609         TEST_ERROR
1610     start[1] = 13;
1611     if(H5Sselect_hyperslab(vspace[1], H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
1612         TEST_ERROR
1613 
1614     /* Add virtual layout mappings */
1615     if(H5Pset_virtual(dcpl, vspace[0], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "%%src_dset1", srcspace[0]) < 0)
1616         TEST_ERROR
1617     if(H5Pset_virtual(dcpl, vspace[1], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset2%%", srcspace[0]) < 0)
1618         TEST_ERROR
1619 
1620     /* Reset dims */
1621     dims[1] = 26;
1622 
1623     /* Create virtual file */
1624     if((vfile = H5Fcreate(vfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
1625         TEST_ERROR
1626 
1627     /* Create source file if requested */
1628     if(config & TEST_IO_DIFFERENT_FILE) {
1629         if((srcfile[0] = H5Fcreate(srcfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
1630             TEST_ERROR
1631     }
1632     else {
1633         srcfile[0] = vfile;
1634         if(H5Iinc_ref(srcfile[0]) < 0)
1635             TEST_ERROR
1636     }
1637 
1638     /* Create source datasets */
1639     if((srcdset[0] = H5Dcreate2(srcfile[0], "%src_dset1", H5T_NATIVE_INT, srcspace[0], H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
1640         TEST_ERROR
1641     if((srcdset[1] = H5Dcreate2(srcfile[0], "src_dset2%", H5T_NATIVE_INT, srcspace[0], H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
1642         TEST_ERROR
1643 
1644     /* Create virtual dataset */
1645     if((vdset = H5Dcreate2(vfile, "v_dset", H5T_NATIVE_INT, vspace[0], H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
1646         TEST_ERROR
1647 
1648     /* Populate write buffer */
1649     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
1650         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
1651             buf[i][j] = (i * (int)(sizeof(buf[0]) / sizeof(buf[0][0]))) + j;
1652 
1653     /* Write data directly to source datasets */
1654     if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, vspace[0], H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
1655         TEST_ERROR
1656     if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, vspace[1], H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
1657         TEST_ERROR
1658 
1659     /* Close srcdsets and srcfile if config option specified */
1660     if(config & TEST_IO_CLOSE_SRC) {
1661         if(H5Dclose(srcdset[0]) < 0)
1662             TEST_ERROR
1663         srcdset[0] = -1;
1664         if(H5Dclose(srcdset[1]) < 0)
1665             TEST_ERROR
1666         srcdset[1] = -1;
1667 
1668         if(config & TEST_IO_DIFFERENT_FILE) {
1669             if(H5Fclose(srcfile[0]) < 0)
1670                 TEST_ERROR
1671             srcfile[0] = -1;
1672         }
1673     }
1674 
1675     /* Reopen virtual dataset and file if config option specified */
1676     if(config & TEST_IO_REOPEN_VIRT) {
1677         if(H5Dclose(vdset) < 0)
1678             TEST_ERROR
1679         vdset = -1;
1680         if(H5Fclose(vfile) < 0)
1681             TEST_ERROR
1682         vfile = -1;
1683         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
1684             TEST_ERROR
1685         if((vdset = H5Dopen2(vfile, "v_dset", H5P_DEFAULT)) < 0)
1686             TEST_ERROR
1687     }
1688 
1689     /* Read data through virtual dataset */
1690     HDmemset(rbuf[0], 0, sizeof(rbuf));
1691     if(H5Dread(vdset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
1692         TEST_ERROR
1693 
1694     /* Verify read data */
1695     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
1696         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
1697             if(rbuf[i][j] != buf[i][j])
1698                 TEST_ERROR
1699 
1700     /* Adjust write buffer */
1701     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
1702         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
1703             buf[i][j] += (int)(sizeof(buf) / sizeof(buf[0][0]));
1704 
1705     /* Write data through virtual dataset */
1706     if(H5Dwrite(vdset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
1707         TEST_ERROR
1708 
1709     /* Reopen srcdsets and srcfile if config option specified */
1710     if(config & TEST_IO_CLOSE_SRC) {
1711         if(config & TEST_IO_DIFFERENT_FILE)
1712             if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
1713                 TEST_ERROR
1714         if((srcdset[0] = H5Dopen2(srcfile[0], "%src_dset1", H5P_DEFAULT)) < 0)
1715             TEST_ERROR
1716         if((srcdset[1] = H5Dopen2(srcfile[0], "src_dset2%", H5P_DEFAULT)) < 0)
1717             TEST_ERROR
1718     }
1719 
1720     /* Read data directly from source datasets */
1721     HDmemset(rbuf[0], 0, sizeof(rbuf));
1722     if(H5Dread(srcdset[0], H5T_NATIVE_INT, vspace[0], H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
1723         TEST_ERROR
1724     if(H5Dread(srcdset[1], H5T_NATIVE_INT, vspace[1], H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
1725         TEST_ERROR
1726 
1727     /* Verify read data */
1728     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
1729         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
1730             if(rbuf[i][j] != buf[i][j])
1731                 TEST_ERROR
1732 
1733     /* Test H5Ocopy() to same file */
1734     /* Copy virtual dataset */
1735     if(H5Ocopy(vfile, "v_dset", vfile, "v_dset2", H5P_DEFAULT, H5P_DEFAULT) < 0)
1736         TEST_ERROR
1737 
1738     /* Close v_dset */
1739     if(H5Dclose(vdset) < 0)
1740         TEST_ERROR
1741     vdset = -1;
1742 
1743     /* Adjust write buffer */
1744     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
1745         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
1746             buf[i][j] += (int)(sizeof(buf) / sizeof(buf[0][0]));
1747 
1748     /* Write data directly to source datasets */
1749     if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, vspace[0], H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
1750         TEST_ERROR
1751     if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, vspace[1], H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
1752         TEST_ERROR
1753 
1754     /* Close srcdsets and srcfile if config option specified */
1755     if(config & TEST_IO_CLOSE_SRC) {
1756         if(H5Dclose(srcdset[0]) < 0)
1757             TEST_ERROR
1758         srcdset[0] = -1;
1759         if(H5Dclose(srcdset[1]) < 0)
1760             TEST_ERROR
1761         srcdset[1] = -1;
1762 
1763         if(config & TEST_IO_DIFFERENT_FILE) {
1764             if(H5Fclose(srcfile[0]) < 0)
1765                 TEST_ERROR
1766             srcfile[0] = -1;
1767         }
1768     }
1769 
1770     /* Reopen virtual file if config option specified */
1771     if(config & TEST_IO_REOPEN_VIRT) {
1772         if(H5Fclose(vfile) < 0)
1773             TEST_ERROR
1774         vfile = -1;
1775         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
1776             TEST_ERROR
1777     }
1778 
1779     /* Open v_dset2 */
1780     if((vdset = H5Dopen2(vfile, "v_dset2", H5P_DEFAULT)) < 0)
1781         TEST_ERROR
1782 
1783     /* Read data through copied virtual dataset */
1784     HDmemset(rbuf[0], 0, sizeof(rbuf));
1785     if(H5Dread(vdset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
1786         TEST_ERROR
1787 
1788     /* Verify read data */
1789     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
1790         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
1791             if(rbuf[i][j] != buf[i][j])
1792                 TEST_ERROR
1793 
1794     /* Reopen srcdsets and srcfile if config option specified */
1795     if(config & TEST_IO_CLOSE_SRC) {
1796         if(config & TEST_IO_DIFFERENT_FILE)
1797             if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
1798                 TEST_ERROR
1799         if((srcdset[0] = H5Dopen2(srcfile[0], "%src_dset1", H5P_DEFAULT)) < 0)
1800             TEST_ERROR
1801         if((srcdset[1] = H5Dopen2(srcfile[0], "src_dset2%", H5P_DEFAULT)) < 0)
1802             TEST_ERROR
1803     }
1804 
1805     /* Only copy to a different file if the source datasets are in a different
1806      * file */
1807     if(config & TEST_IO_DIFFERENT_FILE) {
1808         /* Close v_dset2 */
1809         if(H5Dclose(vdset) < 0)
1810             TEST_ERROR
1811         vdset = -1;
1812 
1813         /* Create file to copy virtual dataset to */
1814         if((vfile2 = H5Fcreate(vfilename2, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
1815             TEST_ERROR
1816 
1817         /* Copy virtual dataset */
1818         if(H5Ocopy(vfile, "v_dset", vfile2, "v_dset3", H5P_DEFAULT, H5P_DEFAULT) < 0)
1819             TEST_ERROR
1820 
1821         /* Adjust write buffer */
1822         for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
1823             for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
1824                 buf[i][j] += (int)(sizeof(buf) / sizeof(buf[0][0]));
1825 
1826         /* Write data directly to source datasets */
1827         if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, vspace[0], H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
1828             TEST_ERROR
1829         if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, vspace[1], H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
1830             TEST_ERROR
1831 
1832         /* Close srcdsets and srcfile if config option specified */
1833         if(config & TEST_IO_CLOSE_SRC) {
1834             if(H5Dclose(srcdset[0]) < 0)
1835                 TEST_ERROR
1836             srcdset[0] = -1;
1837             if(H5Dclose(srcdset[1]) < 0)
1838                 TEST_ERROR
1839             srcdset[1] = -1;
1840 
1841             if(config & TEST_IO_DIFFERENT_FILE) {
1842                 if(H5Fclose(srcfile[0]) < 0)
1843                     TEST_ERROR
1844                 srcfile[0] = -1;
1845             }
1846         }
1847 
1848         /* Reopen copied virtual file if config option specified */
1849         if(config & TEST_IO_REOPEN_VIRT) {
1850             if(H5Fclose(vfile2) < 0)
1851                 TEST_ERROR
1852             vfile2 = -1;
1853             if((vfile2 = H5Fopen(vfilename2, H5F_ACC_RDWR, fapl)) < 0)
1854                 TEST_ERROR
1855         }
1856 
1857         /* Open v_dset3 */
1858         if((vdset = H5Dopen2(vfile2, "v_dset3", H5P_DEFAULT)) < 0)
1859             TEST_ERROR
1860 
1861         /* Read data through copied virtual dataset */
1862         HDmemset(rbuf[0], 0, sizeof(rbuf));
1863         if(H5Dread(vdset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
1864             TEST_ERROR
1865 
1866         /* Verify read data */
1867         for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
1868             for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
1869                 if(rbuf[i][j] != buf[i][j])
1870                     TEST_ERROR
1871 
1872         /* Reopen srcdsets and srcfile if config option specified */
1873         if(config & TEST_IO_CLOSE_SRC) {
1874             if(config & TEST_IO_DIFFERENT_FILE)
1875                 if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDONLY, fapl)) < 0)
1876                     TEST_ERROR
1877             if((srcdset[0] = H5Dopen2(srcfile[0], "%src_dset1", H5P_DEFAULT)) < 0)
1878                 TEST_ERROR
1879             if((srcdset[1] = H5Dopen2(srcfile[0], "src_dset2%", H5P_DEFAULT)) < 0)
1880                 TEST_ERROR
1881         }
1882 
1883         /* Close copied virtual file */
1884         if(H5Fclose(vfile2) < 0)
1885             TEST_ERROR
1886         vfile2 = -1;
1887     }
1888 
1889     /* Close */
1890     if(H5Dclose(srcdset[0]) < 0)
1891         TEST_ERROR
1892     srcdset[0] = -1;
1893     if(H5Dclose(srcdset[1]) < 0)
1894         TEST_ERROR
1895     srcdset[1] = -1;
1896     if(H5Dclose(vdset) < 0)
1897         TEST_ERROR
1898     vdset = -1;
1899     if(H5Fclose(srcfile[0]) < 0)
1900         TEST_ERROR
1901     srcfile[0] = -1;
1902     if(H5Fclose(vfile) < 0)
1903         TEST_ERROR
1904     vfile = -1;
1905     if(H5Sclose(srcspace[0]) < 0)
1906         TEST_ERROR
1907     srcspace[0] = -1;
1908     if(H5Sclose(vspace[0]) < 0)
1909         TEST_ERROR
1910     vspace[0] = -1;
1911     if(H5Sclose(vspace[1]) < 0)
1912         TEST_ERROR
1913     vspace[1] = -1;
1914 
1915 
1916     /*
1917      * Test 3: 2 Source datasets, hyperslab virtual mappings with offsets
1918      */
1919     /* Clear virtual layout in DCPL */
1920     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
1921         TEST_ERROR
1922 
1923     /* Create virtual dataspaces */
1924     if((vspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
1925         TEST_ERROR
1926 
1927     /* Create source dataspace */
1928     dims[1] = 13;
1929     if((srcspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
1930         TEST_ERROR
1931 
1932     /* Select all in source space (should not be necessary, but just to be sure)
1933      */
1934     if(H5Sselect_all(srcspace[0]) < 0)
1935         TEST_ERROR
1936 
1937     /* Select hyperslabs in virtual spaces */
1938     start[0] = 0;
1939     start[1] = 3;
1940     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
1941         TEST_ERROR
1942 
1943     /* Add virtual layout mappings */
1944     offset[1] = -3;
1945     if(H5Soffset_simple(vspace[0], offset) < 0)
1946         TEST_ERROR
1947     if(H5Pset_virtual(dcpl, vspace[0], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "%%src_dset1", srcspace[0]) < 0)
1948         TEST_ERROR
1949     offset[1] = 10;
1950     if(H5Soffset_simple(vspace[0], offset) < 0)
1951         TEST_ERROR
1952     if(H5Pset_virtual(dcpl, vspace[0], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset2%%", srcspace[0]) < 0)
1953         TEST_ERROR
1954 
1955     /* Reset dims */
1956     dims[1] = 26;
1957 
1958     /* Create virtual file */
1959     if((vfile = H5Fcreate(vfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
1960         TEST_ERROR
1961 
1962     /* Create source file if requested */
1963     if(config & TEST_IO_DIFFERENT_FILE) {
1964         if((srcfile[0] = H5Fcreate(srcfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
1965             TEST_ERROR
1966     }
1967     else {
1968         srcfile[0] = vfile;
1969         if(H5Iinc_ref(srcfile[0]) < 0)
1970             TEST_ERROR
1971     }
1972 
1973     /* Create source datasets */
1974     if((srcdset[0] = H5Dcreate2(srcfile[0], "%src_dset1", H5T_NATIVE_INT, srcspace[0], H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
1975         TEST_ERROR
1976     if((srcdset[1] = H5Dcreate2(srcfile[0], "src_dset2%", H5T_NATIVE_INT, srcspace[0], H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
1977         TEST_ERROR
1978 
1979     /* Create virtual dataset */
1980     if((vdset = H5Dcreate2(vfile, "v_dset", H5T_NATIVE_INT, vspace[0], H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
1981         TEST_ERROR
1982 
1983     /* Populate write buffer */
1984     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
1985         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
1986             buf[i][j] = (i * (int)(sizeof(buf[0]) / sizeof(buf[0][0]))) + j;
1987 
1988     /* Write data directly to source datasets */
1989     offset[1] = -3;
1990     if(H5Soffset_simple(vspace[0], offset) < 0)
1991         TEST_ERROR
1992     if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, vspace[0], H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
1993         TEST_ERROR
1994     offset[1] = 10;
1995     if(H5Soffset_simple(vspace[0], offset) < 0)
1996         TEST_ERROR
1997     if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, vspace[0], H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
1998         TEST_ERROR
1999 
2000     /* Close srcdsets and srcfile if config option specified */
2001     if(config & TEST_IO_CLOSE_SRC) {
2002         if(H5Dclose(srcdset[0]) < 0)
2003             TEST_ERROR
2004         srcdset[0] = -1;
2005         if(H5Dclose(srcdset[1]) < 0)
2006             TEST_ERROR
2007         srcdset[1] = -1;
2008 
2009         if(config & TEST_IO_DIFFERENT_FILE) {
2010             if(H5Fclose(srcfile[0]) < 0)
2011                 TEST_ERROR
2012             srcfile[0] = -1;
2013         }
2014     }
2015 
2016     /* Reopen virtual dataset and file if config option specified */
2017     if(config & TEST_IO_REOPEN_VIRT) {
2018         if(H5Dclose(vdset) < 0)
2019             TEST_ERROR
2020         vdset = -1;
2021         if(H5Fclose(vfile) < 0)
2022             TEST_ERROR
2023         vfile = -1;
2024         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
2025             TEST_ERROR
2026         if((vdset = H5Dopen2(vfile, "v_dset", H5P_DEFAULT)) < 0)
2027             TEST_ERROR
2028     }
2029 
2030     /* Read data through virtual dataset */
2031     HDmemset(rbuf[0], 0, sizeof(rbuf));
2032     if(H5Dread(vdset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
2033         TEST_ERROR
2034 
2035     /* Verify read data */
2036     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2037         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2038             if(rbuf[i][j] != buf[i][j])
2039                 TEST_ERROR
2040 
2041     /* Adjust write buffer */
2042     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2043         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2044             buf[i][j] += (int)(sizeof(buf) / sizeof(buf[0][0]));
2045 
2046     /* Write data through virtual dataset */
2047     if(H5Dwrite(vdset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
2048         TEST_ERROR
2049 
2050     /* Reopen srcdsets and srcfile if config option specified */
2051     if(config & TEST_IO_CLOSE_SRC) {
2052         if(config & TEST_IO_DIFFERENT_FILE)
2053             if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDONLY, fapl)) < 0)
2054                 TEST_ERROR
2055         if((srcdset[0] = H5Dopen2(srcfile[0], "%src_dset1", H5P_DEFAULT)) < 0)
2056             TEST_ERROR
2057         if((srcdset[1] = H5Dopen2(srcfile[0], "src_dset2%", H5P_DEFAULT)) < 0)
2058             TEST_ERROR
2059     }
2060 
2061     /* Read data directly from source datasets */
2062     HDmemset(rbuf[0], 0, sizeof(rbuf));
2063     offset[1] = -3;
2064     if(H5Soffset_simple(vspace[0], offset) < 0)
2065         TEST_ERROR
2066     if(H5Dread(srcdset[0], H5T_NATIVE_INT, vspace[0], H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
2067         TEST_ERROR
2068     offset[1] = 10;
2069     if(H5Soffset_simple(vspace[0], offset) < 0)
2070         TEST_ERROR
2071     if(H5Dread(srcdset[1], H5T_NATIVE_INT, vspace[0], H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
2072         TEST_ERROR
2073 
2074     /* Verify read data */
2075     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2076         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2077             if(rbuf[i][j] != buf[i][j])
2078                 TEST_ERROR
2079 
2080     /* Close */
2081     if(H5Dclose(srcdset[0]) < 0)
2082         TEST_ERROR
2083     srcdset[0] = -1;
2084     if(H5Dclose(srcdset[1]) < 0)
2085         TEST_ERROR
2086     srcdset[1] = -1;
2087     if(H5Dclose(vdset) < 0)
2088         TEST_ERROR
2089     vdset = -1;
2090     if(H5Fclose(srcfile[0]) < 0)
2091         TEST_ERROR
2092     srcfile[0] = -1;
2093     if(H5Fclose(vfile) < 0)
2094         TEST_ERROR
2095     vfile = -1;
2096     if(H5Sclose(srcspace[0]) < 0)
2097         TEST_ERROR
2098     srcspace[0] = -1;
2099     if(H5Sclose(vspace[0]) < 0)
2100         TEST_ERROR
2101     vspace[0] = -1;
2102 
2103 
2104     /*
2105      * Test 4: 2 Source datasets, hyperslab virtual mappings on one mapping at a
2106      * time, '%' in source file name
2107      */
2108     /* Clear virtual layout in DCPL */
2109     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
2110         TEST_ERROR
2111 
2112     /* Create virtual dataspaces */
2113     if((vspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
2114         TEST_ERROR
2115     if((vspace[1] = H5Screate_simple(2, dims, NULL)) < 0)
2116         TEST_ERROR
2117 
2118     /* Create source dataspace */
2119     dims[1] = 13;
2120     if((srcspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
2121         TEST_ERROR
2122 
2123     /* Select all in source space (should not be necessary, but just to be sure)
2124      */
2125     if(H5Sselect_all(srcspace[0]) < 0)
2126         TEST_ERROR
2127 
2128     /* Select hyperslabs in virtual spaces */
2129     start[0] = 0;
2130     start[1] = 0;
2131     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
2132         TEST_ERROR
2133     start[1] = 13;
2134     if(H5Sselect_hyperslab(vspace[1], H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
2135         TEST_ERROR
2136 
2137     /* Add virtual layout mappings */
2138     if(H5Pset_virtual(dcpl, vspace[0], config & TEST_IO_DIFFERENT_FILE ? srcfilenamepct_map : ".", "src_dset1", srcspace[0]) < 0)
2139         TEST_ERROR
2140     if(H5Pset_virtual(dcpl, vspace[1], config & TEST_IO_DIFFERENT_FILE ? srcfilenamepct_map : ".", "src_dset2", srcspace[0]) < 0)
2141         TEST_ERROR
2142 
2143     /* Reset dims */
2144     dims[1] = 26;
2145 
2146     /* Create virtual file */
2147     if((vfile = H5Fcreate(vfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
2148         TEST_ERROR
2149 
2150     /* Create source file if requested */
2151     if(config & TEST_IO_DIFFERENT_FILE) {
2152         if((srcfile[0] = H5Fcreate(srcfilenamepct, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
2153             TEST_ERROR
2154     }
2155     else {
2156         srcfile[0] = vfile;
2157         if(H5Iinc_ref(srcfile[0]) < 0)
2158             TEST_ERROR
2159     }
2160 
2161     /* Create source datasets */
2162     if((srcdset[0] = H5Dcreate2(srcfile[0], "src_dset1", H5T_NATIVE_INT, srcspace[0], H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
2163         TEST_ERROR
2164     if((srcdset[1] = H5Dcreate2(srcfile[0], "src_dset2", H5T_NATIVE_INT, srcspace[0], H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
2165         TEST_ERROR
2166 
2167     /* Create virtual dataset */
2168     if((vdset = H5Dcreate2(vfile, "v_dset", H5T_NATIVE_INT, vspace[0], H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
2169         TEST_ERROR
2170 
2171     /* Populate write buffer */
2172     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2173         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2174             buf[i][j] = (i * (int)(sizeof(buf[0]) / sizeof(buf[0][0]))) + j;
2175 
2176     /* Write data directly to source datasets */
2177     if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, vspace[0], H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
2178         TEST_ERROR
2179     if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, vspace[1], H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
2180         TEST_ERROR
2181 
2182     /* Close srcdsets and srcfile if config option specified */
2183     if(config & TEST_IO_CLOSE_SRC) {
2184         if(H5Dclose(srcdset[0]) < 0)
2185             TEST_ERROR
2186         srcdset[0] = -1;
2187         if(H5Dclose(srcdset[1]) < 0)
2188             TEST_ERROR
2189         srcdset[1] = -1;
2190 
2191         if(config & TEST_IO_DIFFERENT_FILE) {
2192             if(H5Fclose(srcfile[0]) < 0)
2193                 TEST_ERROR
2194             srcfile[0] = -1;
2195         }
2196     }
2197 
2198     /* Reopen virtual dataset and file if config option specified */
2199     if(config & TEST_IO_REOPEN_VIRT) {
2200         if(H5Dclose(vdset) < 0)
2201             TEST_ERROR
2202         vdset = -1;
2203         if(H5Fclose(vfile) < 0)
2204             TEST_ERROR
2205         vfile = -1;
2206         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
2207             TEST_ERROR
2208         if((vdset = H5Dopen2(vfile, "v_dset", H5P_DEFAULT)) < 0)
2209             TEST_ERROR
2210     }
2211 
2212     /* Read first source dataset through virtual dataset */
2213     HDmemset(rbuf[0], 0, sizeof(rbuf));
2214     if(H5Dread(vdset, H5T_NATIVE_INT, vspace[0], vspace[0], H5P_DEFAULT, rbuf[0]) < 0)
2215         TEST_ERROR
2216 
2217     /* Verify read data */
2218     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2219         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2220             if(rbuf[i][j] != (j < (int)(sizeof(buf[0]) / sizeof(buf[0][0]) / 2)
2221                     ? buf[i][j] : 0))
2222                 TEST_ERROR
2223 
2224     /* Read second source dataset through virtual dataset */
2225     HDmemset(rbuf[0], 0, sizeof(rbuf));
2226     if(H5Dread(vdset, H5T_NATIVE_INT, vspace[1], vspace[1], H5P_DEFAULT, rbuf[0]) < 0)
2227         TEST_ERROR
2228 
2229     /* Verify read data */
2230     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2231         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2232             if(rbuf[i][j] != (j < (int)(sizeof(buf[0]) / sizeof(buf[0][0]) / 2)
2233                     ? 0 : buf[i][j]))
2234                 TEST_ERROR
2235 
2236     /* Adjust write buffer */
2237     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2238         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2239             buf[i][j] += (int)(sizeof(buf) / sizeof(buf[0][0]));
2240 
2241     /* Write first source dataset through virtual dataset */
2242     if(H5Dwrite(vdset, H5T_NATIVE_INT, vspace[0], vspace[0], H5P_DEFAULT, buf[0]) < 0)
2243         TEST_ERROR
2244 
2245     /* Adjust write buffer */
2246     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2247         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2248             buf[i][j] += (int)(sizeof(buf) / sizeof(buf[0][0]));
2249 
2250     /* Write second source dataset through virtual dataset */
2251     if(H5Dwrite(vdset, H5T_NATIVE_INT, vspace[1], vspace[1], H5P_DEFAULT, buf[0]) < 0)
2252         TEST_ERROR
2253 
2254     /* Reopen srcdsets and srcfile if config option specified */
2255     if(config & TEST_IO_CLOSE_SRC) {
2256         if(config & TEST_IO_DIFFERENT_FILE)
2257             if((srcfile[0] = H5Fopen(srcfilenamepct, H5F_ACC_RDONLY, fapl)) < 0)
2258                 TEST_ERROR
2259         if((srcdset[0] = H5Dopen2(srcfile[0], "src_dset1", H5P_DEFAULT)) < 0)
2260             TEST_ERROR
2261         if((srcdset[1] = H5Dopen2(srcfile[0], "src_dset2", H5P_DEFAULT)) < 0)
2262             TEST_ERROR
2263     }
2264 
2265     /* Read data directly from source datasets */
2266     HDmemset(rbuf[0], 0, sizeof(rbuf));
2267     if(H5Dread(srcdset[0], H5T_NATIVE_INT, vspace[0], H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
2268         TEST_ERROR
2269     if(H5Dread(srcdset[1], H5T_NATIVE_INT, vspace[1], H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
2270         TEST_ERROR
2271 
2272     /* Verify read data */
2273     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2274         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2275             if(rbuf[i][j] != (j < (int)(sizeof(buf[0]) / sizeof(buf[0][0]) / 2)
2276                     ? (buf[i][j] - (int)(sizeof(buf) / sizeof(buf[0][0])))
2277                     : buf[i][j]))
2278                 TEST_ERROR
2279 
2280     /* Close */
2281     if(H5Dclose(srcdset[0]) < 0)
2282         TEST_ERROR
2283     srcdset[0] = -1;
2284     if(H5Dclose(srcdset[1]) < 0)
2285         TEST_ERROR
2286     srcdset[1] = -1;
2287     if(H5Dclose(vdset) < 0)
2288         TEST_ERROR
2289     vdset = -1;
2290     if(H5Fclose(srcfile[0]) < 0)
2291         TEST_ERROR
2292     srcfile[0] = -1;
2293     if(H5Fclose(vfile) < 0)
2294         TEST_ERROR
2295     vfile = -1;
2296     if(H5Sclose(srcspace[0]) < 0)
2297         TEST_ERROR
2298     srcspace[0] = -1;
2299     if(H5Sclose(vspace[0]) < 0)
2300         TEST_ERROR
2301     vspace[0] = -1;
2302     if(H5Sclose(vspace[1]) < 0)
2303         TEST_ERROR
2304     vspace[1] = -1;
2305 
2306 
2307     /*
2308      * Test 5: 2 Source datasets, hyperslab virtual mappings and selections
2309      */
2310     /* Clear virtual layout in DCPL */
2311     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
2312         TEST_ERROR
2313 
2314     /* Create virtual dataspaces */
2315     if((vspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
2316         TEST_ERROR
2317     if((vspace[1] = H5Screate_simple(2, dims, NULL)) < 0)
2318         TEST_ERROR
2319 
2320     /* Create source dataspaces */
2321     if((srcspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
2322         TEST_ERROR
2323     if((srcspace[1] = H5Screate_simple(2, dims, NULL)) < 0)
2324         TEST_ERROR
2325 
2326     /* Select hyperslabs in source space */
2327     start[0] = 0;
2328     start[1] = 0;
2329     count[0] = 10;
2330     count[1] = 13;
2331     if(H5Sselect_hyperslab(srcspace[0], H5S_SELECT_SET, start, NULL, count, NULL) < 0)
2332         TEST_ERROR
2333     start[1] = 13;
2334     if(H5Sselect_hyperslab(srcspace[1], H5S_SELECT_SET, start, NULL, count, NULL) < 0)
2335         TEST_ERROR
2336 
2337     /* Select hyperslabs in virtual spaces */
2338     start[0] = 0;
2339     start[1] = 0;
2340     count[0] = 5;
2341     count[1] = 26;
2342     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, NULL, count, NULL) < 0)
2343         TEST_ERROR
2344     start[0] = 5;
2345     if(H5Sselect_hyperslab(vspace[1], H5S_SELECT_SET, start, NULL, count, NULL) < 0)
2346         TEST_ERROR
2347 
2348     /* Add virtual layout mappings */
2349     if(H5Pset_virtual(dcpl, vspace[0], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset1", srcspace[0]) < 0)
2350         TEST_ERROR
2351     if(H5Pset_virtual(dcpl, vspace[1], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset2", srcspace[1]) < 0)
2352         TEST_ERROR
2353 
2354     /* Create virtual file */
2355     if((vfile = H5Fcreate(vfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
2356         TEST_ERROR
2357 
2358     /* Create source file if requested */
2359     if(config & TEST_IO_DIFFERENT_FILE) {
2360         if((srcfile[0] = H5Fcreate(srcfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
2361             TEST_ERROR
2362     }
2363     else {
2364         srcfile[0] = vfile;
2365         if(H5Iinc_ref(srcfile[0]) < 0)
2366             TEST_ERROR
2367     }
2368 
2369     /* Create source datasets */
2370     if((srcdset[0] = H5Dcreate2(srcfile[0], "src_dset1", H5T_NATIVE_INT, srcspace[0], H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
2371         TEST_ERROR
2372     if((srcdset[1] = H5Dcreate2(srcfile[0], "src_dset2", H5T_NATIVE_INT, srcspace[1], H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
2373         TEST_ERROR
2374 
2375     /* Create virtual dataset */
2376     if((vdset = H5Dcreate2(vfile, "v_dset", H5T_NATIVE_INT, vspace[0], H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
2377         TEST_ERROR
2378 
2379     /* Populate write buffer */
2380     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2381         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2382             buf[i][j] = (i * (int)(sizeof(buf[0]) / sizeof(buf[0][0]))) + j;
2383 
2384     /* Write data directly to source datasets */
2385     /* Write first dataset */
2386     if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
2387         TEST_ERROR
2388 
2389     /* Update evbuf */
2390     for(i = 0; i < 5; i++) {
2391         for(j = 0; j < 13; j++)
2392             evbuf[i][j] = buf[2 * i][j];
2393         for(/* j = 13 */; j < 26; j++)
2394             evbuf[i][j] = buf[2 * i + 1][j - 13];
2395     }
2396 
2397     /* Adjust write buffer */
2398     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2399         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2400             buf[i][j] += (int)(sizeof(buf) / sizeof(buf[0][0]));
2401 
2402     /* Write second dataset */
2403     if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
2404         TEST_ERROR
2405 
2406     /* Update evbuf */
2407     for(i = 0; i < 5; i++) {
2408         for(j = 0; j < 13; j++)
2409             evbuf[i + 5][j] = buf[2 * i][j + 13];
2410         for(/* j = 13 */; j < 26; j++)
2411             evbuf[i + 5][j] = buf[2 * i + 1][j];
2412     }
2413 
2414     /* Close srcdsets and srcfile if config option specified */
2415     if(config & TEST_IO_CLOSE_SRC) {
2416         if(H5Dclose(srcdset[0]) < 0)
2417             TEST_ERROR
2418         srcdset[0] = -1;
2419         if(H5Dclose(srcdset[1]) < 0)
2420             TEST_ERROR
2421         srcdset[1] = -1;
2422 
2423         if(config & TEST_IO_DIFFERENT_FILE) {
2424             if(H5Fclose(srcfile[0]) < 0)
2425                 TEST_ERROR
2426             srcfile[0] = -1;
2427         }
2428     }
2429 
2430     /* Reopen virtual dataset and file if config option specified */
2431     if(config & TEST_IO_REOPEN_VIRT) {
2432         if(H5Dclose(vdset) < 0)
2433             TEST_ERROR
2434         vdset = -1;
2435         if(H5Fclose(vfile) < 0)
2436             TEST_ERROR
2437         vfile = -1;
2438         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
2439             TEST_ERROR
2440         if((vdset = H5Dopen2(vfile, "v_dset", H5P_DEFAULT)) < 0)
2441             TEST_ERROR
2442     }
2443 
2444     /* Read data through virtual dataset by hyperslab */
2445     /* Reset rbuf */
2446     HDmemset(rbuf[0], 0, sizeof(rbuf));
2447 
2448     /* Read first slice */
2449     if(H5Dread(vdset, H5T_NATIVE_INT, vspace[0], srcspace[0], H5P_DEFAULT, rbuf[0]) < 0)
2450         TEST_ERROR
2451 
2452     /* Update erbuf */
2453     for(i = 0; i < 5; i++) {
2454         for(j = 0; j < 13; j++)
2455             erbuf[i][j] = evbuf[2 * i][j];
2456         for(/* j = 13 */; j < 26; j++)
2457             erbuf[i][j] = evbuf[2 * i + 1][j - 13];
2458     }
2459 
2460     /* Read second slice */
2461     if(H5Dread(vdset, H5T_NATIVE_INT, vspace[1], srcspace[1], H5P_DEFAULT, rbuf[0]) < 0)
2462         TEST_ERROR
2463 
2464     /* Update erbuf */
2465     for(i = 0; i < 5; i++) {
2466         for(j = 0; j < 13; j++)
2467             erbuf[i + 5][j] = evbuf[2 * i][j + 13];
2468         for(/* j = 13 */; j < 26; j++)
2469             erbuf[i + 5][j] = evbuf[2 * i + 1][j];
2470     }
2471 
2472     /* Verify read data */
2473     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2474         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2475             if(rbuf[i][j] != erbuf[i][j])
2476                 TEST_ERROR
2477 
2478     /* Adjust write buffer */
2479     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2480         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2481             buf[i][j] += (int)(sizeof(buf) / sizeof(buf[0][0]));
2482 
2483     /* Write data through virtual dataset */
2484     /* Write first slice */
2485     if(H5Dwrite(vdset, H5T_NATIVE_INT, vspace[0], srcspace[0], H5P_DEFAULT, buf[0]) < 0)
2486         TEST_ERROR
2487 
2488     /* Update evbuf */
2489     for(i = 0; i < 5; i++) {
2490         for(j = 0; j < 13; j++)
2491             evbuf[2 * i][j] = buf[i][j];
2492         for(/* j = 13 */; j < 26; j++)
2493             evbuf[2 * i + 1][j - 13] = buf[i][j];
2494     }
2495 
2496     /* Adjust write buffer */
2497     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2498         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2499             buf[i][j] += (int)(sizeof(buf) / sizeof(buf[0][0]));
2500 
2501     /* Write second slice */
2502     if(H5Dwrite(vdset, H5T_NATIVE_INT, vspace[1], srcspace[1], H5P_DEFAULT, buf[0]) < 0)
2503         TEST_ERROR
2504 
2505     /* Update evbuf */
2506     for(i = 0; i < 5; i++) {
2507         for(j = 0; j < 13; j++)
2508             evbuf[2 * i][j + 13] = buf[i + 5][j];
2509         for(/* j = 13 */; j < 26; j++)
2510             evbuf[2 * i + 1][j] = buf[i + 5][j];
2511     }
2512 
2513     /* Reopen srcdsets and srcfile if config option specified */
2514     if(config & TEST_IO_CLOSE_SRC) {
2515         if(config & TEST_IO_DIFFERENT_FILE)
2516             if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDONLY, fapl)) < 0)
2517                 TEST_ERROR
2518         if((srcdset[0] = H5Dopen2(srcfile[0], "src_dset1", H5P_DEFAULT)) < 0)
2519             TEST_ERROR
2520         if((srcdset[1] = H5Dopen2(srcfile[0], "src_dset2", H5P_DEFAULT)) < 0)
2521             TEST_ERROR
2522     }
2523 
2524     /* Read data directly from source datasets */
2525     /* Reset rbuf */
2526     HDmemset(rbuf[0], 0, sizeof(rbuf));
2527 
2528     /* Read first dataset */
2529     if(H5Dread(srcdset[0], H5T_NATIVE_INT, srcspace[0], srcspace[0], H5P_DEFAULT, rbuf[0]) < 0)
2530         TEST_ERROR
2531 
2532     /* Update erbuf */
2533     for(i = 0; i < 5; i++) {
2534         for(j = 0; j < 13; j++)
2535             erbuf[2 * i][j] = evbuf[i][j];
2536         for(/* j = 13 */; j < 26; j++)
2537             erbuf[2 * i + 1][j - 13] = evbuf[i][j];
2538     }
2539 
2540     /* Read second dataset */
2541     if(H5Dread(srcdset[1], H5T_NATIVE_INT, srcspace[1], srcspace[1], H5P_DEFAULT, rbuf[0]) < 0)
2542         TEST_ERROR
2543 
2544     /* Update erbuf */
2545     for(i = 0; i < 5; i++) {
2546         for(j = 0; j < 13; j++)
2547             erbuf[2 * i][j + 13] = evbuf[i + 5][j];
2548         for(/* j = 13 */; j < 26; j++)
2549             erbuf[2 * i + 1][j] = evbuf[i + 5][j];
2550     }
2551 
2552     /* Verify read data */
2553     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2554         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2555             if(rbuf[i][j] != erbuf[i][j])
2556                 TEST_ERROR
2557 
2558     /* Close */
2559     if(H5Dclose(srcdset[0]) < 0)
2560         TEST_ERROR
2561     srcdset[0] = -1;
2562     if(H5Dclose(srcdset[1]) < 0)
2563         TEST_ERROR
2564     srcdset[1] = -1;
2565     if(H5Dclose(vdset) < 0)
2566         TEST_ERROR
2567     vdset = -1;
2568     if(H5Fclose(srcfile[0]) < 0)
2569         TEST_ERROR
2570     srcfile[0] = -1;
2571     if(H5Fclose(vfile) < 0)
2572         TEST_ERROR
2573     vfile = -1;
2574     if(H5Sclose(srcspace[0]) < 0)
2575         TEST_ERROR
2576     srcspace[0] = -1;
2577     if(H5Sclose(srcspace[1]) < 0)
2578         TEST_ERROR
2579     srcspace[1] = -1;
2580     if(H5Sclose(vspace[0]) < 0)
2581         TEST_ERROR
2582     vspace[0] = -1;
2583     if(H5Sclose(vspace[1]) < 0)
2584         TEST_ERROR
2585     vspace[1] = -1;
2586 
2587 
2588     /*
2589      * Test 6: 2 Source datasets, checkerboard/stripe pattern to trigger
2590      * sequence list refresh internally
2591      */
2592     /* Clear virtual layout in DCPL */
2593     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
2594         TEST_ERROR
2595 
2596     /* Create memory dataspace */
2597     if((memspace = H5Screate_simple(2, dims, NULL)) < 0)
2598         TEST_ERROR
2599 
2600     /* Create virtual dataspaces */
2601     dims[1] = 52;
2602     if((vspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
2603         TEST_ERROR
2604     if((vspace[1] = H5Screate_simple(2, dims, NULL)) < 0)
2605         TEST_ERROR
2606 
2607     /* Create source dataspace and file space for second operation (srcspace[1])
2608      */
2609     if((srcspace[0] = H5Screate_simple(2, dims, NULL)) < 0)
2610         TEST_ERROR
2611     if((srcspace[1] = H5Screate_simple(2, dims, NULL)) < 0)
2612         TEST_ERROR
2613 
2614     /* Reset dims */
2615     dims[1] = 26;
2616 
2617     /* Select hyperslabs (stripe) in source space and file space for second
2618      * operation (srcspace[1]) */
2619     start[0] = 0;
2620     start[1] = 0;
2621     stride[0] = 1;
2622     stride[1] = 2;
2623     count[0] = 1;
2624     count[1] = 26;
2625     block[0] = 10;
2626     block[1] = 1;
2627     if(H5Sselect_hyperslab(srcspace[0], H5S_SELECT_SET, start, stride, count, block) < 0)
2628         TEST_ERROR
2629     start[1] = 1;
2630     if(H5Sselect_hyperslab(srcspace[1], H5S_SELECT_SET, start, stride, count, block) < 0)
2631         TEST_ERROR
2632 
2633     /* Select hyperslabs (checkerboard) in virtual spaces */
2634     start[0] = 0;
2635     start[1] = 0;
2636     stride[0] = 2;
2637     stride[1] = 2;
2638     count[0] = 5;
2639     count[1] = 26;
2640     block[0] = 1;
2641     block[1] = 1;
2642     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, stride, count, block) < 0)
2643         TEST_ERROR
2644     start[0] = 1;
2645     start[1] = 1;
2646     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_OR, start, stride, count, block) < 0)
2647         TEST_ERROR
2648     start[0] = 0;
2649     if(H5Sselect_hyperslab(vspace[1], H5S_SELECT_SET, start, stride, count, block) < 0)
2650         TEST_ERROR
2651     start[0] = 1;
2652     start[1] = 0;
2653     if(H5Sselect_hyperslab(vspace[1], H5S_SELECT_OR, start, stride, count, block) < 0)
2654         TEST_ERROR
2655 
2656     /* Add virtual layout mappings */
2657     if(H5Pset_virtual(dcpl, vspace[0], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset1", srcspace[0]) < 0)
2658         TEST_ERROR
2659     if(H5Pset_virtual(dcpl, vspace[1], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset2", srcspace[0]) < 0)
2660         TEST_ERROR
2661 
2662     /* Create virtual file */
2663     if((vfile = H5Fcreate(vfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
2664         TEST_ERROR
2665 
2666     /* Create source file if requested */
2667     if(config & TEST_IO_DIFFERENT_FILE) {
2668         if((srcfile[0] = H5Fcreate(srcfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
2669             TEST_ERROR
2670     }
2671     else {
2672         srcfile[0] = vfile;
2673         if(H5Iinc_ref(srcfile[0]) < 0)
2674             TEST_ERROR
2675     }
2676 
2677     /* Create source datasets */
2678     if((srcdset[0] = H5Dcreate2(srcfile[0], "src_dset1", H5T_NATIVE_INT, srcspace[0], H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
2679         TEST_ERROR
2680     if((srcdset[1] = H5Dcreate2(srcfile[0], "src_dset2", H5T_NATIVE_INT, srcspace[0], H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
2681         TEST_ERROR
2682 
2683     /* Create virtual dataset */
2684     if((vdset = H5Dcreate2(vfile, "v_dset", H5T_NATIVE_INT, vspace[0], H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
2685         TEST_ERROR
2686 
2687     /* Populate write buffer */
2688     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2689         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2690             buf[i][j] = (i * (int)(sizeof(buf[0]) / sizeof(buf[0][0]))) + j;
2691 
2692     /* Write data directly to source datasets */
2693     /* Write first dataset */
2694     if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, memspace, srcspace[0], H5P_DEFAULT, buf[0]) < 0)
2695         TEST_ERROR
2696 
2697     /* Update erbuf */
2698     for(i = 0; i < 10; i += 2)
2699         for(j = 0; j < 26; j++)
2700             erbuf[i][j] = buf[i][j];
2701 
2702     /* Adjust write buffer */
2703     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2704         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2705             buf[i][j] += (int)(sizeof(buf) / sizeof(buf[0][0]));
2706 
2707     /* Write second dataset */
2708     if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, memspace, srcspace[0], H5P_DEFAULT, buf[0]) < 0)
2709         TEST_ERROR
2710 
2711     /* Update erbuf */
2712     for(i = 1; i < 10; i += 2)
2713         for(j = 0; j < 26; j++)
2714             erbuf[i][j] = buf[i][j];
2715 
2716     /* Close srcdsets and srcfile if config option specified */
2717     if(config & TEST_IO_CLOSE_SRC) {
2718         if(H5Dclose(srcdset[0]) < 0)
2719             TEST_ERROR
2720         srcdset[0] = -1;
2721         if(H5Dclose(srcdset[1]) < 0)
2722             TEST_ERROR
2723         srcdset[1] = -1;
2724 
2725         if(config & TEST_IO_DIFFERENT_FILE) {
2726             if(H5Fclose(srcfile[0]) < 0)
2727                 TEST_ERROR
2728             srcfile[0] = -1;
2729         }
2730     }
2731 
2732     /* Reopen virtual dataset and file if config option specified */
2733     if(config & TEST_IO_REOPEN_VIRT) {
2734         if(H5Dclose(vdset) < 0)
2735             TEST_ERROR
2736         vdset = -1;
2737         if(H5Fclose(vfile) < 0)
2738             TEST_ERROR
2739         vfile = -1;
2740         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
2741             TEST_ERROR
2742         if((vdset = H5Dopen2(vfile, "v_dset", H5P_DEFAULT)) < 0)
2743             TEST_ERROR
2744     }
2745 
2746     /* Read data through virtual dataset by hyperslab */
2747     /* Reset rbuf */
2748     HDmemset(rbuf[0], 0, sizeof(rbuf));
2749 
2750     /* Read first stripe pattern */
2751     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, srcspace[0], H5P_DEFAULT, rbuf[0]) < 0)
2752         TEST_ERROR
2753 
2754     /* Verify read data */
2755     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2756         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2757             if(rbuf[i][j] != erbuf[i][j])
2758                 TEST_ERROR
2759 
2760     /* Read second stripe pattern */
2761     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, srcspace[1], H5P_DEFAULT, rbuf[0]) < 0)
2762         TEST_ERROR
2763 
2764     /* Update erbuf */
2765     for(i = 0; i < 10; i += 2)
2766         for(j = 0; j < 26; j++) {
2767             erbuf[i][j] += (int)(sizeof(buf) / sizeof(buf[0][0]));
2768             erbuf[i + 1][j] -= (int)(sizeof(buf) / sizeof(buf[0][0]));
2769         }
2770 
2771     /* Verify read data */
2772     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2773         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2774             if(rbuf[i][j] != erbuf[i][j])
2775                 TEST_ERROR
2776 
2777     /* Adjust write buffer */
2778     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2779         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2780             buf[i][j] += (int)(sizeof(buf) / sizeof(buf[0][0]));
2781 
2782     /* Write data through virtual dataset */
2783     /* Write first slice */
2784     if(H5Dwrite(vdset, H5T_NATIVE_INT, memspace, srcspace[0], H5P_DEFAULT, buf[0]) < 0)
2785         TEST_ERROR
2786 
2787     /* Update erbuf */
2788     for(i = 0; i < 10; i += 2)
2789         for(j = 0; j < 26; j++)
2790             erbuf[i][j] = buf[i][j];
2791 
2792     /* Adjust write buffer */
2793     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2794         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2795             buf[i][j] += (int)(sizeof(buf) / sizeof(buf[0][0]));
2796 
2797     /* Write second slice */
2798     if(H5Dwrite(vdset, H5T_NATIVE_INT, memspace, srcspace[1], H5P_DEFAULT, buf[0]) < 0)
2799         TEST_ERROR
2800 
2801     /* Update erbuf */
2802     for(i = 1; i < 10; i += 2)
2803         for(j = 0; j < 26; j++)
2804             erbuf[i][j] = buf[i][j];
2805 
2806     /* Reopen srcdsets and srcfile if config option specified */
2807     if(config & TEST_IO_CLOSE_SRC) {
2808         if(config & TEST_IO_DIFFERENT_FILE)
2809             if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDONLY, fapl)) < 0)
2810                 TEST_ERROR
2811         if((srcdset[0] = H5Dopen2(srcfile[0], "src_dset1", H5P_DEFAULT)) < 0)
2812             TEST_ERROR
2813         if((srcdset[1] = H5Dopen2(srcfile[0], "src_dset2", H5P_DEFAULT)) < 0)
2814             TEST_ERROR
2815     }
2816 
2817     /* Read data directly from source datasets */
2818     /* Reset rbuf */
2819     HDmemset(rbuf[0], 0, sizeof(rbuf));
2820 
2821     /* Read first dataset */
2822     if(H5Dread(srcdset[0], H5T_NATIVE_INT, memspace, srcspace[0], H5P_DEFAULT, rbuf[0]) < 0)
2823         TEST_ERROR
2824 
2825     /* Verify read data */
2826     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2827         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2828             if(rbuf[i][j] != erbuf[i][j])
2829                 TEST_ERROR
2830 
2831     /* Update erbuf */
2832     for(i = 0; i < 10; i += 2)
2833         for(j = 0; j < 26; j++) {
2834             erbuf[i][j] += (int)(sizeof(buf) / sizeof(buf[0][0]));
2835             erbuf[i + 1][j] -= (int)(sizeof(buf) / sizeof(buf[0][0]));
2836         }
2837 
2838     /* Read second dataset */
2839     if(H5Dread(srcdset[1], H5T_NATIVE_INT, memspace, srcspace[0], H5P_DEFAULT, rbuf[0]) < 0)
2840         TEST_ERROR
2841 
2842     /* Verify read data */
2843     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
2844         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
2845             if(rbuf[i][j] != erbuf[i][j])
2846                 TEST_ERROR
2847 
2848     /* Close */
2849     if(H5Dclose(srcdset[0]) < 0)
2850         TEST_ERROR
2851     srcdset[0] = -1;
2852     if(H5Dclose(srcdset[1]) < 0)
2853         TEST_ERROR
2854     srcdset[1] = -1;
2855     if(H5Dclose(vdset) < 0)
2856         TEST_ERROR
2857     vdset = -1;
2858     if(H5Fclose(srcfile[0]) < 0)
2859         TEST_ERROR
2860     srcfile[0] = -1;
2861     if(H5Fclose(vfile) < 0)
2862         TEST_ERROR
2863     vfile = -1;
2864     if(H5Sclose(srcspace[0]) < 0)
2865         TEST_ERROR
2866     srcspace[0] = -1;
2867     if(H5Sclose(srcspace[1]) < 0)
2868         TEST_ERROR
2869     srcspace[1] = -1;
2870     if(H5Sclose(vspace[0]) < 0)
2871         TEST_ERROR
2872     vspace[0] = -1;
2873     if(H5Sclose(vspace[1]) < 0)
2874         TEST_ERROR
2875     vspace[1] = -1;
2876     if(H5Sclose(memspace) < 0)
2877         TEST_ERROR
2878     memspace = -1;
2879 
2880 
2881     /*
2882      * Test 7: 1 Source dataset, two mappings, 4 dimensional virtual dataset
2883      * and 3 dimensional source dataset
2884      */
2885     /* Clear virtual layout in DCPL */
2886     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
2887         TEST_ERROR
2888 
2889     /* Create memory dataspace */
2890     if((memspace = H5Screate_simple(2, dims, NULL)) < 0)
2891         TEST_ERROR
2892 
2893     /* Create virtual dataspaces */
2894     dims[0] = 3;
2895     dims[1] = 3;
2896     dims[2] = 3;
2897     dims[3] = 3;
2898     if((vspace[0] = H5Screate_simple(4, dims, NULL)) < 0)
2899         TEST_ERROR
2900     if((vspace[1] = H5Screate_simple(4, dims, NULL)) < 0)
2901         TEST_ERROR
2902 
2903     /* Create source dataspaces */
2904     dims[0] = 2;
2905     dims[1] = 4;
2906     dims[2] = 4;
2907     if((srcspace[0] = H5Screate_simple(3, dims, NULL)) < 0)
2908         TEST_ERROR
2909     if((srcspace[1] = H5Screate_simple(3, dims, NULL)) < 0)
2910         TEST_ERROR
2911 
2912     /* Reset dims */
2913     dims[0] = 10;
2914     dims[1] = 26;
2915 
2916     /* Select hyperslabs (stripes) in source spaces */
2917     start[0] = 0;
2918     start[1] = 0;
2919     start[2] = 0;
2920     stride[0] = 1;
2921     stride[1] = 2;
2922     stride[2] = 1;
2923     count[0] = 1;
2924     count[1] = 2;
2925     count[2] = 1;
2926     block[0] = 2;
2927     block[1] = 1;
2928     block[2] = 4;
2929     if(H5Sselect_hyperslab(srcspace[0], H5S_SELECT_SET, start, stride, count, block) < 0)
2930         TEST_ERROR
2931     start[1] = 1;
2932     if(H5Sselect_hyperslab(srcspace[1], H5S_SELECT_SET, start, stride, count, block) < 0)
2933         TEST_ERROR
2934 
2935     /* Select hyperslabs (corners) in first virtual space */
2936     start[0] = 0;
2937     start[1] = 0;
2938     start[2] = 0;
2939     start[3] = 0;
2940     stride[0] = 2;
2941     stride[1] = 2;
2942     stride[2] = 2;
2943     stride[3] = 2;
2944     count[0] = 2;
2945     count[1] = 2;
2946     count[2] = 2;
2947     count[3] = 2;
2948     block[0] = 1;
2949     block[1] = 1;
2950     block[2] = 1;
2951     block[3] = 1;
2952     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, stride, count, block) < 0)
2953         TEST_ERROR
2954 
2955     /* Select hyperslabs ("+" pattern) in second virtual space */
2956     start[0] = 1;
2957     start[1] = 1;
2958     start[2] = 0;
2959     start[3] = 0;
2960     stride[0] = 2;
2961     stride[1] = 2;
2962     stride[2] = 2;
2963     stride[3] = 2;
2964     count[0] = 1;
2965     count[1] = 1;
2966     count[2] = 2;
2967     count[3] = 2;
2968     block[0] = 1;
2969     block[1] = 1;
2970     block[2] = 1;
2971     block[3] = 1;
2972     if(H5Sselect_hyperslab(vspace[1], H5S_SELECT_SET, start, stride, count, block) < 0)
2973         TEST_ERROR
2974     start[1] = 0;
2975     start[2] = 1;
2976     count[1] = 2;
2977     count[2] = 1;
2978     if(H5Sselect_hyperslab(vspace[1], H5S_SELECT_OR, start, stride, count, block) < 0)
2979         TEST_ERROR
2980     start[0] = 0;
2981     start[1] = 1;
2982     count[0] = 2;
2983     count[1] = 1;
2984     if(H5Sselect_hyperslab(vspace[1], H5S_SELECT_OR, start, stride, count, block) < 0)
2985         TEST_ERROR
2986     start[0] = 1;
2987     count[0] = 1;
2988     if(H5Sselect_hyperslab(vspace[1], H5S_SELECT_OR, start, stride, count, block) < 0)
2989         TEST_ERROR
2990     start[1] = 0;
2991     start[3] = 1;
2992     count[1] = 2;
2993     count[3] = 1;
2994     if(H5Sselect_hyperslab(vspace[1], H5S_SELECT_OR, start, stride, count, block) < 0)
2995         TEST_ERROR
2996 
2997     /* Add virtual layout mappings */
2998     if(H5Pset_virtual(dcpl, vspace[0], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset1", srcspace[0]) < 0)
2999         TEST_ERROR
3000     if(H5Pset_virtual(dcpl, vspace[1], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset1", srcspace[1]) < 0)
3001         TEST_ERROR
3002 
3003     /* Create virtual file */
3004     if((vfile = H5Fcreate(vfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
3005         TEST_ERROR
3006 
3007     /* Create source file if requested */
3008     if(config & TEST_IO_DIFFERENT_FILE) {
3009         if((srcfile[0] = H5Fcreate(srcfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
3010             TEST_ERROR
3011     }
3012     else {
3013         srcfile[0] = vfile;
3014         if(H5Iinc_ref(srcfile[0]) < 0)
3015             TEST_ERROR
3016     }
3017 
3018     /* Create source dataset */
3019     if((srcdset[0] = H5Dcreate2(srcfile[0], "src_dset1", H5T_NATIVE_INT, srcspace[0], H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
3020         TEST_ERROR
3021 
3022     /* Create virtual dataset */
3023     if((vdset = H5Dcreate2(vfile, "v_dset", H5T_NATIVE_INT, vspace[0], H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
3024         TEST_ERROR
3025 
3026     /* Populate write buffer */
3027     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
3028         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
3029             buf[i][j] = (i * (int)(sizeof(buf[0]) / sizeof(buf[0][0]))) + j;
3030 
3031     /* Select hyperslab in memory space */
3032     start[0] = 0;
3033     start[1] = 0;
3034     count[0] = 2;
3035     count[1] = 16;
3036     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL ,count, NULL) < 0)
3037         TEST_ERROR
3038 
3039     /* Write data directly to source dataset */
3040     if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
3041         TEST_ERROR
3042 
3043     /* Close srcdset and srcfile if config option specified */
3044     if(config & TEST_IO_CLOSE_SRC) {
3045         if(H5Dclose(srcdset[0]) < 0)
3046             TEST_ERROR
3047         srcdset[0] = -1;
3048 
3049         if(config & TEST_IO_DIFFERENT_FILE) {
3050             if(H5Fclose(srcfile[0]) < 0)
3051                 TEST_ERROR
3052             srcfile[0] = -1;
3053         }
3054     }
3055 
3056     /* Reopen virtual dataset and file if config option specified */
3057     if(config & TEST_IO_REOPEN_VIRT) {
3058         if(H5Dclose(vdset) < 0)
3059             TEST_ERROR
3060         vdset = -1;
3061         if(H5Fclose(vfile) < 0)
3062             TEST_ERROR
3063         vfile = -1;
3064         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
3065             TEST_ERROR
3066         if((vdset = H5Dopen2(vfile, "v_dset", H5P_DEFAULT)) < 0)
3067             TEST_ERROR
3068     }
3069 
3070     /* Read data through virtual dataset */
3071     /* Reset rbuf */
3072     HDmemset(rbuf[0], 0, sizeof(rbuf));
3073 
3074     /* Select hyperslab in memory space */
3075     start[0] = 0;
3076     start[1] = 0;
3077     count[0] = 9;
3078     count[1] = 3;
3079     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL ,count, NULL) < 0)
3080         TEST_ERROR
3081 
3082     /* Read data through virtual dataset by hyperslab */
3083     /* Reset rbuf */
3084     HDmemset(rbuf[0], 0, sizeof(rbuf));
3085 
3086     /* Select stripe */
3087     start[0] = 0;
3088     start[1] = 0;
3089     start[2] = 0;
3090     start[3] = 0;
3091     count[0] = 3;
3092     count[1] = 3;
3093     count[2] = 1;
3094     count[3] = 3;
3095     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, NULL ,count, NULL) < 0)
3096         TEST_ERROR
3097 
3098     /* Read first stripe pattern */
3099     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, vspace[0], H5P_DEFAULT, rbuf[0]) < 0)
3100         TEST_ERROR
3101 
3102     /* Update erbuf */
3103     HDmemset(erbuf, 0, sizeof(erbuf));
3104     for(i = 0; i < 9; i++)
3105         for(j = 0; j < 3; j++)
3106             erbuf[i][j] = fill;
3107     erbuf[0][0] = buf[0][0];
3108     erbuf[0][2] = buf[0][1];
3109     erbuf[2][0] = buf[0][8];
3110     erbuf[2][2] = buf[0][9];
3111     erbuf[6][0] = buf[1][0];
3112     erbuf[6][2] = buf[1][1];
3113     erbuf[8][0] = buf[1][8];
3114     erbuf[8][2] = buf[1][9];
3115     erbuf[4][0] = buf[0][13];
3116     erbuf[4][2] = buf[0][14];
3117 
3118     /* Verify read data */
3119     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
3120         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
3121             if(rbuf[i][j] != erbuf[i][j])
3122                 TEST_ERROR
3123 
3124     /* Reset rbuf */
3125     HDmemset(rbuf[0], 0, sizeof(rbuf));
3126 
3127     /* Select stripe */
3128     start[0] = 0;
3129     start[1] = 0;
3130     start[2] = 1;
3131     start[3] = 0;
3132     count[0] = 3;
3133     count[1] = 3;
3134     count[2] = 1;
3135     count[3] = 3;
3136     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, NULL ,count, NULL) < 0)
3137         TEST_ERROR
3138 
3139     /* Select hyperslab in memory space */
3140     start[0] = 0;
3141     start[1] = 3;
3142     count[0] = 9;
3143     count[1] = 3;
3144     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL ,count, NULL) < 0)
3145         TEST_ERROR
3146 
3147     /* Read second stripe pattern */
3148     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, vspace[0], H5P_DEFAULT, rbuf[0]) < 0)
3149         TEST_ERROR
3150 
3151     /* Update erbuf */
3152     for(i = 0; i < 9; i++)
3153         for(j = 3; j < 6; j++)
3154             erbuf[i][j] = fill;
3155     erbuf[1][3] = buf[0][4];
3156     erbuf[1][5] = buf[0][5];
3157     erbuf[3][3] = buf[0][6];
3158     erbuf[3][4] = buf[0][7];
3159     erbuf[3][5] = buf[0][12];
3160     erbuf[4][3] = buf[0][15];
3161     erbuf[4][5] = buf[1][4];
3162     erbuf[5][3] = buf[1][7];
3163     erbuf[5][4] = buf[1][12];
3164     erbuf[5][5] = buf[1][13];
3165     erbuf[7][3] = buf[1][14];
3166     erbuf[7][5] = buf[1][15];
3167 
3168     /* Verify read data */
3169     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
3170         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
3171             if((j >= 3) && (j < 6)) {
3172                 if(rbuf[i][j] != erbuf[i][j])
3173                     TEST_ERROR
3174             }
3175             else
3176                 if(rbuf[i][j] != 0)
3177                     TEST_ERROR
3178 
3179     /* Reset rbuf */
3180     HDmemset(rbuf[0], 0, sizeof(rbuf));
3181 
3182     /* Select stripe */
3183     start[0] = 0;
3184     start[1] = 0;
3185     start[2] = 2;
3186     start[3] = 0;
3187     count[0] = 3;
3188     count[1] = 3;
3189     count[2] = 1;
3190     count[3] = 3;
3191     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, NULL ,count, NULL) < 0)
3192         TEST_ERROR
3193 
3194     /* Select hyperslab in memory space */
3195     start[0] = 0;
3196     start[1] = 6;
3197     count[0] = 9;
3198     count[1] = 3;
3199     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL ,count, NULL) < 0)
3200         TEST_ERROR
3201 
3202     /* Read third stripe pattern */
3203     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, vspace[0], H5P_DEFAULT, rbuf[0]) < 0)
3204         TEST_ERROR
3205 
3206     /* Update erbuf */
3207     for(i = 0; i < 9; i++)
3208         for(j = 6; j < 9; j++)
3209             erbuf[i][j] = fill;
3210     erbuf[0][6] = buf[0][2];
3211     erbuf[0][8] = buf[0][3];
3212     erbuf[2][6] = buf[0][10];
3213     erbuf[2][8] = buf[0][11];
3214     erbuf[6][6] = buf[1][2];
3215     erbuf[6][8] = buf[1][3];
3216     erbuf[8][6] = buf[1][10];
3217     erbuf[8][8] = buf[1][11];
3218     erbuf[4][6] = buf[1][5];
3219     erbuf[4][8] = buf[1][6];
3220 
3221     /* Verify read data */
3222     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
3223         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
3224             if((j >= 6) && (j < 9)) {
3225                 if(rbuf[i][j] != erbuf[i][j])
3226                     TEST_ERROR
3227             }
3228             else
3229                 if(rbuf[i][j] != 0)
3230                     TEST_ERROR
3231 
3232     /* Now read entire VDS */
3233     /* Set memory space extent to 9x9, select all in order to reach part of the
3234      * code in H5S_select_subtract() */
3235     dims[0] = 9;
3236     dims[1] = 9;
3237     if(H5Sset_extent_simple(memspace, 2, dims, NULL) < 0)
3238         TEST_ERROR
3239     if(H5Sselect_all(memspace) < 0)
3240         TEST_ERROR
3241 
3242     /* Read third stripe pattern */
3243     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf99[0]) < 0)
3244         TEST_ERROR
3245 
3246     /* Verify read data */
3247     for(i = 0; i < (int)(sizeof(rbuf99) / sizeof(rbuf99[0])); i++)
3248         for(j = 0; j < (int)(sizeof(rbuf99[0]) / sizeof(rbuf99[0][0])); j++)
3249             if(rbuf99[i][j] != erbuf[i][j])
3250                 TEST_ERROR
3251 
3252     /* Adjust write buffer */
3253     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
3254         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
3255             buf[i][j] += (int)(sizeof(buf) / sizeof(buf[0][0]));
3256 
3257     /* Write data through virtual dataset by hyperslab */
3258     /* Select stripe (only select mapped elements) */
3259     start[0] = 0;
3260     start[1] = 0;
3261     start[2] = 0;
3262     start[3] = 0;
3263     stride[0] = 2;
3264     stride[1] = 2;
3265     stride[2] = 1;
3266     stride[3] = 2;
3267     count[0] = 2;
3268     count[1] = 2;
3269     count[2] = 1;
3270     count[3] = 2;
3271     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, stride ,count, NULL) < 0)
3272         TEST_ERROR
3273     start[0] = 1;
3274     start[1] = 1;
3275     start[2] = 0;
3276     start[3] = 0;
3277     stride[0] = 1;
3278     stride[1] = 1;
3279     stride[2] = 1;
3280     stride[3] = 2;
3281     count[0] = 1;
3282     count[1] = 1;
3283     count[2] = 1;
3284     count[3] = 2;
3285     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_OR, start, stride ,count, NULL) < 0)
3286         TEST_ERROR
3287 
3288     /* Reset extent of memspace, select hyperslab */
3289     dims[0] = 10;
3290     dims[1] = 26;
3291     if(H5Sset_extent_simple(memspace, 2, dims, NULL) < 0)
3292         TEST_ERROR
3293     start[0] = 0;
3294     start[1] = 0;
3295     count[0] = 1;
3296     count[1] = 10;
3297     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL ,count, NULL) < 0)
3298         TEST_ERROR
3299 
3300     /* Write data through virtual dataset by hyperslab */
3301     /* Write first stripe pattern */
3302     if(H5Dwrite(vdset, H5T_NATIVE_INT, memspace, vspace[0], H5P_DEFAULT, buf[0]) < 0)
3303         TEST_ERROR
3304 
3305     /* Update erbuf */
3306     HDmemset(erbuf, 0, sizeof(erbuf));
3307     erbuf[0][0] = buf[0][0];
3308     erbuf[0][1] = buf[0][1];
3309     erbuf[0][8] = buf[0][2];
3310     erbuf[0][9] = buf[0][3];
3311     erbuf[1][0] = buf[0][6];
3312     erbuf[1][1] = buf[0][7];
3313     erbuf[1][8] = buf[0][8];
3314     erbuf[1][9] = buf[0][9];
3315     erbuf[0][13] = buf[0][4];
3316     erbuf[0][14] = buf[0][5];
3317 
3318     /* Adjust write buffer */
3319     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
3320         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
3321             buf[i][j] += (int)(sizeof(buf) / sizeof(buf[0][0]));
3322 
3323     /* Select stripe (only select mapped elements) */
3324     start[0] = 0;
3325     start[1] = 1;
3326     start[2] = 1;
3327     start[3] = 0;
3328     stride[0] = 1;
3329     stride[1] = 1;
3330     stride[2] = 1;
3331     stride[3] = 2;
3332     count[0] = 3;
3333     count[1] = 1;
3334     count[2] = 1;
3335     count[3] = 2;
3336     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, stride ,count, NULL) < 0)
3337         TEST_ERROR
3338     start[0] = 1;
3339     start[1] = 0;
3340     start[2] = 1;
3341     start[3] = 0;
3342     stride[0] = 1;
3343     stride[1] = 2;
3344     stride[2] = 1;
3345     stride[3] = 1;
3346     count[0] = 1;
3347     count[1] = 2;
3348     count[2] = 1;
3349     count[3] = 3;
3350     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_OR, start, stride ,count, NULL) < 0)
3351         TEST_ERROR
3352 
3353     /* Select hyperslab in memory space */
3354     start[0] = 0;
3355     start[1] = 0;
3356     count[0] = 1;
3357     count[1] = 12;
3358     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL ,count, NULL) < 0)
3359         TEST_ERROR
3360 
3361     /* Write second slice */
3362     if(H5Dwrite(vdset, H5T_NATIVE_INT, memspace, vspace[0], H5P_DEFAULT, buf[0]) < 0)
3363         TEST_ERROR
3364 
3365     /* Update erbuf */
3366     erbuf[0][4] = buf[0][0];
3367     erbuf[0][5] = buf[0][1];
3368     erbuf[0][6] = buf[0][2];
3369     erbuf[0][7] = buf[0][3];
3370     erbuf[0][12] = buf[0][4];
3371     erbuf[0][15] = buf[0][5];
3372     erbuf[1][4] = buf[0][6];
3373     erbuf[1][7] = buf[0][7];
3374     erbuf[1][12] = buf[0][8];
3375     erbuf[1][13] = buf[0][9];
3376     erbuf[1][14] = buf[0][10];
3377     erbuf[1][15] = buf[0][11];
3378 
3379     /* Adjust write buffer */
3380     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
3381         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
3382             buf[i][j] += (int)(sizeof(buf) / sizeof(buf[0][0]));
3383 
3384     /* Select stripe (only select mapped elements) */
3385     start[0] = 0;
3386     start[1] = 0;
3387     start[2] = 2;
3388     start[3] = 0;
3389     stride[0] = 2;
3390     stride[1] = 2;
3391     stride[2] = 1;
3392     stride[3] = 2;
3393     count[0] = 2;
3394     count[1] = 2;
3395     count[2] = 1;
3396     count[3] = 2;
3397     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, stride ,count, NULL) < 0)
3398         TEST_ERROR
3399     start[0] = 1;
3400     start[1] = 1;
3401     start[2] = 2;
3402     start[3] = 0;
3403     stride[0] = 1;
3404     stride[1] = 1;
3405     stride[2] = 1;
3406     stride[3] = 2;
3407     count[0] = 1;
3408     count[1] = 1;
3409     count[2] = 1;
3410     count[3] = 2;
3411     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_OR, start, stride ,count, NULL) < 0)
3412         TEST_ERROR
3413 
3414     /* Select hyperslab in memory space */
3415     start[0] = 0;
3416     start[1] = 0;
3417     count[0] = 1;
3418     count[1] = 10;
3419     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL ,count, NULL) < 0)
3420         TEST_ERROR
3421 
3422     /* Write third slice */
3423     if(H5Dwrite(vdset, H5T_NATIVE_INT, memspace, vspace[0], H5P_DEFAULT, buf[0]) < 0)
3424         TEST_ERROR
3425 
3426     /* Update erbuf */
3427     erbuf[0][2] = buf[0][0];
3428     erbuf[0][3] = buf[0][1];
3429     erbuf[0][10] = buf[0][2];
3430     erbuf[0][11] = buf[0][3];
3431     erbuf[1][2] = buf[0][6];
3432     erbuf[1][3] = buf[0][7];
3433     erbuf[1][10] = buf[0][8];
3434     erbuf[1][11] = buf[0][9];
3435     erbuf[1][5] = buf[0][4];
3436     erbuf[1][6] = buf[0][5];
3437 
3438     /* Reopen srcdset and srcfile if config option specified */
3439     if(config & TEST_IO_CLOSE_SRC) {
3440         if(config & TEST_IO_DIFFERENT_FILE)
3441             if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDONLY, fapl)) < 0)
3442                 TEST_ERROR
3443         if((srcdset[0] = H5Dopen2(srcfile[0], "src_dset1", H5P_DEFAULT)) < 0)
3444             TEST_ERROR
3445     }
3446 
3447     /* Read data directly from source dataset */
3448     /* Select hyperslab in memory space */
3449     start[0] = 0;
3450     start[1] = 0;
3451     count[0] = 2;
3452     count[1] = 16;
3453     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL ,count, NULL) < 0)
3454         TEST_ERROR
3455 
3456     /* Reset rbuf */
3457     HDmemset(rbuf[0], 0, sizeof(rbuf));
3458 
3459     /* Read dataset */
3460     if(H5Dread(srcdset[0], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
3461         TEST_ERROR
3462 
3463     /* Verify read data */
3464     for(i = 0; i < (int)(sizeof(buf) / sizeof(buf[0])); i++)
3465         for(j = 0; j < (int)(sizeof(buf[0]) / sizeof(buf[0][0])); j++)
3466             if(rbuf[i][j] != erbuf[i][j])
3467                 TEST_ERROR
3468 
3469     /* Now try writing to whole VDS (should fail due to unmapped elements) */
3470     count[0] = 9;
3471     count[1] = 9;
3472     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
3473         TEST_ERROR
3474     H5E_BEGIN_TRY {
3475         ret = H5Dwrite(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]);
3476     } H5E_END_TRY
3477     if(ret >= 0)
3478         TEST_ERROR
3479 
3480     /* Close */
3481     if(H5Dclose(srcdset[0]) < 0)
3482         TEST_ERROR
3483     srcdset[0] = -1;
3484     if(H5Dclose(vdset) < 0)
3485         TEST_ERROR
3486     vdset = -1;
3487     if(H5Fclose(srcfile[0]) < 0)
3488         TEST_ERROR
3489     srcfile[0] = -1;
3490     if(H5Fclose(vfile) < 0)
3491         TEST_ERROR
3492     vfile = -1;
3493     if(H5Sclose(srcspace[0]) < 0)
3494         TEST_ERROR
3495     srcspace[0] = -1;
3496     if(H5Sclose(srcspace[1]) < 0)
3497         TEST_ERROR
3498     srcspace[1] = -1;
3499     if(H5Sclose(vspace[0]) < 0)
3500         TEST_ERROR
3501     vspace[0] = -1;
3502     if(H5Sclose(vspace[1]) < 0)
3503         TEST_ERROR
3504     vspace[1] = -1;
3505     if(H5Sclose(memspace) < 0)
3506         TEST_ERROR
3507     memspace = -1;
3508 
3509 
3510     /* Close */
3511     if(H5Pclose(dcpl) < 0)
3512         TEST_ERROR
3513     dcpl = -1;
3514 
3515     PASSED();
3516     return 0;
3517 
3518 error:
3519     H5E_BEGIN_TRY {
3520         for(i = 0; i < (int)(sizeof(srcdset) / sizeof(srcdset[0])); i++)
3521             H5Dclose(srcdset[i]);
3522         H5Dclose(vdset);
3523         for(i = 0; i < (int)(sizeof(srcfile) / sizeof(srcfile[0])); i++)
3524             H5Fclose(srcfile[i]);
3525         H5Fclose(vfile);
3526         H5Fclose(vfile2);
3527         for(i = 0; i < (int)(sizeof(srcspace) / sizeof(srcspace[0])); i++)
3528             H5Sclose(srcspace[i]);
3529         for(i = 0; i < (int)(sizeof(vspace) / sizeof(vspace[0])); i++)
3530             H5Sclose(vspace[i]);
3531         H5Sclose(memspace);
3532         H5Pclose(dcpl);
3533     } H5E_END_TRY;
3534 
3535      return 1;
3536 } /* end test_basic_io() */
3537 
3538 
3539 /*-------------------------------------------------------------------------
3540  * Function:    test_unlim
3541  *
3542  * Purpose:     Tests VDS with unlimited selections
3543  *
3544  * Return:      Success:        0
3545  *              Failure:        number of errors
3546  *-------------------------------------------------------------------------
3547  */
3548 static int
test_unlim(unsigned config,hid_t fapl)3549 test_unlim(unsigned config, hid_t fapl)
3550 {
3551     char        srcfilename[FILENAME_BUF_SIZE];
3552     char        srcfilename_map[FILENAME_BUF_SIZE];
3553     char        vfilename[FILENAME_BUF_SIZE];
3554     hid_t       srcfile[4] = {-1, -1, -1, -1}; /* Files with source dsets */
3555     hid_t       vfile = -1;     /* File with virtual dset */
3556     hid_t       dcpl = -1;      /* Dataset creation property list */
3557     hid_t       srcdcpl = -1;   /* DCPL for source dset */
3558     hid_t       dapl = -1;      /* Dataset access property list */
3559     hid_t       srcspace[4] = {-1, -1, -1, -1}; /* Source dataspaces */
3560     hid_t       vspace[4] = {-1, -1, -1, -1}; /* Virtual dset dataspaces */
3561     hid_t       memspace = -1;  /* Memory dataspace */
3562     hid_t       filespace = -1; /* File dataspace */
3563     hid_t       srcdset[4] = {-1, -1, -1, -1}; /* Source datsets */
3564     hid_t       vdset = -1;     /* Virtual dataset */
3565     hsize_t     dims[2] = {10, 10}; /* Data space current size */
3566     hsize_t     mdims[2] = {10, 20}; /* Data space maximum size */
3567     hsize_t     cdims[2] = {4, 4}; /* Chunk dimensions */
3568     hsize_t     start[4];       /* Hyperslab start */
3569     hsize_t     stride[4];      /* Hyperslab stride */
3570     hsize_t     count[4];       /* Hyperslab count */
3571     hsize_t     block[4];       /* Hyperslab block */
3572     int         buf[10][20];    /* Write and expected read buffer */
3573     int         rbuf[10][20];   /* Read buffer */
3574     int         erbuf[10][20];  /* Expected read buffer */
3575     int         ndims;          /* Number of dimensions */
3576     int         fill = -1;      /* Fill value */
3577     H5D_vds_view_t virtual_view; /* Virtual view property */
3578     int         i, j;
3579 
3580     TESTING("virtual dataset I/O with unlimited selections")
3581 
3582     h5_fixname(FILENAME[0], fapl, vfilename, sizeof vfilename);
3583     h5_fixname(FILENAME[2], fapl, srcfilename, sizeof srcfilename);
3584     h5_fixname_printf(FILENAME[2], fapl, srcfilename_map, sizeof srcfilename_map);
3585 
3586     /* Create DCPLs */
3587     if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
3588         TEST_ERROR
3589     if((srcdcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
3590         TEST_ERROR
3591 
3592     /* Set fill value */
3593     if(H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fill) < 0)
3594         TEST_ERROR
3595 
3596     /* Set chunk dimensions */
3597     if(H5Pset_chunk(srcdcpl, 2, cdims) < 0)
3598         TEST_ERROR
3599 
3600     /* Create DAPL */
3601     if((dapl = H5Pcreate(H5P_DATASET_ACCESS)) < 0)
3602         TEST_ERROR
3603 
3604     /* Create memory space */
3605     if((memspace = H5Screate_simple(2, mdims, NULL)) < 0)
3606         TEST_ERROR
3607 
3608 
3609     /*
3610      * Test 1: 2 Source datasets, single unlimited hyperslab virtual mappings
3611      */
3612     /* Clear virtual layout in DCPL */
3613     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
3614         TEST_ERROR
3615 
3616     /* Create virtual dataspaces */
3617     if((vspace[0] = H5Screate_simple(2, dims, mdims)) < 0)
3618         TEST_ERROR
3619     if((vspace[1] = H5Screate_simple(2, dims, mdims)) < 0)
3620         TEST_ERROR
3621 
3622     /* Create source dataspace */
3623     dims[0] = 5;
3624     mdims[0] = 5;
3625     if((srcspace[0] = H5Screate_simple(2, dims, mdims)) < 0)
3626         TEST_ERROR
3627     mdims[0] = 10;
3628 
3629     /* Select hyperslab in source space */
3630     start[0] = 0;
3631     start[1] = 0;
3632     count[0] = 5;
3633     count[1] = H5S_UNLIMITED;
3634     if(H5Sselect_hyperslab(srcspace[0], H5S_SELECT_SET, start, NULL, count, NULL) < 0)
3635         TEST_ERROR
3636 
3637     /* Select hyperslabs in virtual spaces */
3638     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, NULL, count, NULL) < 0)
3639         TEST_ERROR
3640     start[0] = 5;
3641     if(H5Sselect_hyperslab(vspace[1], H5S_SELECT_SET, start, NULL, count, NULL) < 0)
3642         TEST_ERROR
3643 
3644     /* Add virtual layout mappings */
3645     if(H5Pset_virtual(dcpl, vspace[0], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset1", srcspace[0]) < 0)
3646         TEST_ERROR
3647     if(H5Pset_virtual(dcpl, vspace[1], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset2", srcspace[0]) < 0)
3648         TEST_ERROR
3649 
3650     /* Create virtual file */
3651     if((vfile = H5Fcreate(vfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
3652         TEST_ERROR
3653 
3654     /* Create source file if requested */
3655     if(config & TEST_IO_DIFFERENT_FILE) {
3656         if((srcfile[0] = H5Fcreate(srcfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
3657             TEST_ERROR
3658     }
3659     else {
3660         srcfile[0] = vfile;
3661         if(H5Iinc_ref(srcfile[0]) < 0)
3662             TEST_ERROR
3663     }
3664 
3665     /* Create source datasets */
3666     if((srcdset[0] = H5Dcreate2(srcfile[0], "src_dset1", H5T_NATIVE_INT, srcspace[0], H5P_DEFAULT, srcdcpl, H5P_DEFAULT)) < 0)
3667         TEST_ERROR
3668     if((srcdset[1] = H5Dcreate2(srcfile[0], "src_dset2", H5T_NATIVE_INT, srcspace[0], H5P_DEFAULT, srcdcpl, H5P_DEFAULT)) < 0)
3669         TEST_ERROR
3670 
3671     /* Create virtual dataset */
3672     if((vdset = H5Dcreate2(vfile, "v_dset", H5T_NATIVE_INT, vspace[0], H5P_DEFAULT, dcpl, dapl)) < 0)
3673         TEST_ERROR
3674 
3675     /* Populate write buffer */
3676     for(i = 0; i < (int)mdims[0]; i++)
3677         for(j = 0; j < (int)mdims[1]; j++)
3678             buf[i][j] = (i * (int)mdims[1]) + j;
3679 
3680     /* Initialize erbuf */
3681     for(i = 0; i < (int)mdims[0]; i++)
3682         for(j = 0; j < (int)mdims[1]; j++)
3683             erbuf[i][j] = fill;
3684 
3685     /* Write data directly to source datasets */
3686     /* Select hyperslab in memory */
3687     start[0] = 0;
3688     count[1] = 10;
3689     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
3690         TEST_ERROR
3691 
3692     /* Write first dataset */
3693     if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
3694         TEST_ERROR
3695 
3696     /* Update erbuf */
3697     for(i = 0; i < 5; i++)
3698         for(j = 0; j < 10; j++)
3699             erbuf[i][j] = buf[i][j];
3700 
3701     /* Adjust write buffer */
3702     for(i = 0; i < (int)mdims[0]; i++)
3703         for(j = 0; j < (int)mdims[1]; j++)
3704             buf[i][j] += (int)mdims[0] * (int)mdims[1];
3705 
3706     /* Write second dataset */
3707     if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
3708         TEST_ERROR
3709 
3710     /* Update erbuf */
3711     for(i = 0; i < 5; i++)
3712         for(j = 0; j < 10; j++)
3713             erbuf[i + 5][j] = buf[i][j];
3714 
3715     /* Close srcdsets and srcfile if config option specified */
3716     if(config & TEST_IO_CLOSE_SRC) {
3717         if(H5Dclose(srcdset[0]) < 0)
3718             TEST_ERROR
3719         srcdset[0] = -1;
3720         if(H5Dclose(srcdset[1]) < 0)
3721             TEST_ERROR
3722         srcdset[1] = -1;
3723 
3724         if(config & TEST_IO_DIFFERENT_FILE) {
3725             if(H5Fclose(srcfile[0]) < 0)
3726                 TEST_ERROR
3727             srcfile[0] = -1;
3728         }
3729     }
3730 
3731     /* Reopen virtual dataset and file if config option specified */
3732     if(config & TEST_IO_REOPEN_VIRT) {
3733         if(H5Dclose(vdset) < 0)
3734             TEST_ERROR
3735         vdset = -1;
3736         if(H5Fclose(vfile) < 0)
3737             TEST_ERROR
3738         vfile = -1;
3739         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
3740             TEST_ERROR
3741         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
3742             TEST_ERROR
3743     }
3744 
3745     /* Get VDS space */
3746     if((filespace = H5Dget_space(vdset)) < 0)
3747         TEST_ERROR
3748 
3749     /* Get VDS space dimensions */
3750     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
3751         TEST_ERROR
3752     if(ndims != 2)
3753         TEST_ERROR
3754     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
3755         TEST_ERROR
3756     if(dims[0] != 10)
3757         TEST_ERROR
3758     if(dims[1] != 10)
3759         TEST_ERROR
3760     if(mdims[0] != 10)
3761         TEST_ERROR
3762     if(mdims[1] != 20)
3763         TEST_ERROR
3764 
3765     /* Close filespace */
3766     if(H5Sclose(filespace) < 0)
3767         TEST_ERROR
3768 
3769     /* Read data through virtual dataset */
3770     /* Reset rbuf */
3771     HDmemset(rbuf[0], 0, sizeof(rbuf));
3772 
3773     /* Select hyperslab in memory space */
3774     start[0] = 0;
3775     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
3776         TEST_ERROR
3777 
3778     /* Read data */
3779     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
3780         TEST_ERROR
3781 
3782     /* Verify read data */
3783     for(i = 0; i < (int)mdims[0]; i++)
3784         for(j = 0; j < (int)mdims[1]; j++) {
3785             if(j >= (int)dims[1]) {
3786                 if(rbuf[i][j] != 0)
3787                     TEST_ERROR
3788             }
3789             else
3790                 if(rbuf[i][j] != erbuf[i][j])
3791                     TEST_ERROR
3792         }
3793 
3794     /* Test H5Pget_virtual_view() */
3795     if(H5Pget_virtual_view(dapl, &virtual_view) < 0)
3796         TEST_ERROR
3797     if(virtual_view != H5D_VDS_LAST_AVAILABLE)
3798         TEST_ERROR
3799 
3800     /* Close VDS and reopen with view set to H5D_VDS_FIRST_MISSING, reopen file
3801      * as well if config option specified */
3802     if(H5Dclose(vdset) < 0)
3803         TEST_ERROR
3804     if(H5Pset_virtual_view(dapl, H5D_VDS_FIRST_MISSING) < 0)
3805         TEST_ERROR
3806     if(config & TEST_IO_REOPEN_VIRT) {
3807         if(H5Fclose(vfile) < 0)
3808             TEST_ERROR
3809         vfile = -1;
3810         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
3811             TEST_ERROR
3812     }
3813     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
3814         TEST_ERROR
3815 
3816     /* Test H5Pget_virtual_view() */
3817     if(H5Pget_virtual_view(dapl, &virtual_view) < 0)
3818         TEST_ERROR
3819     if(virtual_view != H5D_VDS_FIRST_MISSING)
3820         TEST_ERROR
3821 
3822     /* Get VDS space */
3823     if((filespace = H5Dget_space(vdset)) < 0)
3824         TEST_ERROR
3825 
3826     /* Get VDS space dimensions */
3827     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
3828         TEST_ERROR
3829     if(ndims != 2)
3830         TEST_ERROR
3831     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
3832         TEST_ERROR
3833     if(dims[0] != 10)
3834         TEST_ERROR
3835     if(dims[1] != 10)
3836         TEST_ERROR
3837     if(mdims[0] != 10)
3838         TEST_ERROR
3839     if(mdims[1] != 20)
3840         TEST_ERROR
3841 
3842     /* Close filespace */
3843     if(H5Sclose(filespace) < 0)
3844         TEST_ERROR
3845 
3846     /* Read data through virtual dataset */
3847     /* Reset rbuf */
3848     HDmemset(rbuf[0], 0, sizeof(rbuf));
3849 
3850     /* Read data */
3851     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
3852         TEST_ERROR
3853 
3854     /* Verify read data */
3855     for(i = 0; i < (int)mdims[0]; i++)
3856         for(j = 0; j < (int)mdims[1]; j++) {
3857             if(j >= (int)dims[1]) {
3858                 if(rbuf[i][j] != 0)
3859                     TEST_ERROR
3860             }
3861             else
3862                 if(rbuf[i][j] != erbuf[i][j])
3863                     TEST_ERROR
3864         }
3865 
3866     /* Reopen srcdset[0] and srcfile if config option specified */
3867     if(config & TEST_IO_CLOSE_SRC) {
3868         if(config & TEST_IO_DIFFERENT_FILE)
3869             if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
3870                 TEST_ERROR
3871         if((srcdset[0] = H5Dopen2(srcfile[0], "src_dset1", H5P_DEFAULT)) < 0)
3872             TEST_ERROR
3873     }
3874 
3875     /* Extend srcdset[0] */
3876     dims[0] = 5;
3877     dims[1] = 15;
3878     if(H5Dset_extent(srcdset[0], dims) < 0)
3879         TEST_ERROR
3880 
3881     /* Adjust write buffer */
3882     for(i = 0; i < (int)mdims[0]; i++)
3883         for(j = 0; j < (int)mdims[1]; j++)
3884             buf[i][j] += (int)mdims[0] * (int)mdims[1];
3885 
3886     /* Write to new area of srcdset */
3887     count[1] = 5;
3888     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
3889         TEST_ERROR
3890     if((filespace = H5Dget_space(srcdset[0])) < 0)
3891         TEST_ERROR
3892     start[1] = 10;
3893     if(H5Sselect_hyperslab(filespace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
3894         TEST_ERROR
3895     if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT, buf[0]) < 0)
3896         TEST_ERROR
3897     if(H5Sclose(filespace) < 0)
3898         TEST_ERROR
3899 
3900     /* Close srcdset[0] and srcfile if config option specified */
3901     if(config & TEST_IO_CLOSE_SRC) {
3902         if(H5Dclose(srcdset[0]) < 0)
3903             TEST_ERROR
3904         srcdset[0] = -1;
3905 
3906         if(config & TEST_IO_DIFFERENT_FILE) {
3907             if(H5Fclose(srcfile[0]) < 0)
3908                 TEST_ERROR
3909             srcfile[0] = -1;
3910         }
3911     }
3912 
3913     /* Reopen virtual dataset and file if config option specified */
3914     if(config & TEST_IO_REOPEN_VIRT) {
3915         if(H5Dclose(vdset) < 0)
3916             TEST_ERROR
3917         vdset = -1;
3918         if(H5Fclose(vfile) < 0)
3919             TEST_ERROR
3920         vfile = -1;
3921         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
3922             TEST_ERROR
3923         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
3924             TEST_ERROR
3925     }
3926 
3927     /* Get VDS space */
3928     if((filespace = H5Dget_space(vdset)) < 0)
3929         TEST_ERROR
3930 
3931     /* Get VDS space dimensions.  Note that since we are using
3932      * H5D_VDS_FIRST_MISSING and we only extended one source dataset the
3933      * dimensions will not have changed. */
3934     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
3935         TEST_ERROR
3936     if(ndims != 2)
3937         TEST_ERROR
3938     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
3939         TEST_ERROR
3940     if(dims[0] != 10)
3941         TEST_ERROR
3942     if(dims[1] != 10)
3943         TEST_ERROR
3944     if(mdims[0] != 10)
3945         TEST_ERROR
3946     if(mdims[1] != 20)
3947         TEST_ERROR
3948 
3949     /* Close filespace */
3950     if(H5Sclose(filespace) < 0)
3951         TEST_ERROR
3952 
3953     /* Read data through virtual dataset */
3954     /* Reset rbuf */
3955     HDmemset(rbuf[0], 0, sizeof(rbuf));
3956 
3957     /* Select hyperslab in memory space */
3958     start[1] = 0;
3959     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
3960         TEST_ERROR
3961 
3962     /* Read data */
3963     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
3964         TEST_ERROR
3965 
3966     /* Verify read data */
3967     for(i = 0; i < (int)mdims[0]; i++)
3968         for(j = 0; j < (int)mdims[1]; j++) {
3969             if(j >= (int)dims[1]) {
3970                 if(rbuf[i][j] != 0)
3971                     TEST_ERROR
3972             }
3973             else
3974                 if(rbuf[i][j] != erbuf[i][j])
3975                     TEST_ERROR
3976         }
3977 
3978     /* Close VDS and reopen with view set to H5D_VDS_LAST_AVAILABLE, reopen file
3979      * as well if config option specified */
3980     if(H5Dclose(vdset) < 0)
3981         TEST_ERROR
3982     if(H5Pset_virtual_view(dapl, H5D_VDS_LAST_AVAILABLE) < 0)
3983         TEST_ERROR
3984     if(config & TEST_IO_REOPEN_VIRT) {
3985         if(H5Fclose(vfile) < 0)
3986             TEST_ERROR
3987         vfile = -1;
3988         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
3989             TEST_ERROR
3990     }
3991     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
3992         TEST_ERROR
3993 
3994     /* Update erbuf to reflect new data that is now visible due to the change to
3995      * H5D_VDS_LAST_AVAILABLE */
3996     for(i = 0; i < 5; i++)
3997         for(j = 0; j < 5; j++)
3998             erbuf[i][j + 10] = buf[i][j];
3999 
4000     /* Get VDS space */
4001     if((filespace = H5Dget_space(vdset)) < 0)
4002         TEST_ERROR
4003 
4004     /* Get VDS space dimensions */
4005     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
4006         TEST_ERROR
4007     if(ndims != 2)
4008         TEST_ERROR
4009     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
4010         TEST_ERROR
4011     if(dims[0] != 10)
4012         TEST_ERROR
4013     if(dims[1] != 15)
4014         TEST_ERROR
4015     if(mdims[0] != 10)
4016         TEST_ERROR
4017     if(mdims[1] != 20)
4018         TEST_ERROR
4019 
4020     /* Close filespace */
4021     if(H5Sclose(filespace) < 0)
4022         TEST_ERROR
4023 
4024     /* Read data through virtual dataset */
4025     /* Reset rbuf */
4026     HDmemset(rbuf[0], 0, sizeof(rbuf));
4027 
4028     /* Select hyperslab in memory space */
4029     start[1] = 0;
4030     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
4031         TEST_ERROR
4032 
4033     /* Read data */
4034     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
4035         TEST_ERROR
4036 
4037     /* Verify read data */
4038     for(i = 0; i < (int)mdims[0]; i++)
4039         for(j = 0; j < (int)mdims[1]; j++) {
4040             if(j >= (int)dims[1]) {
4041                 if(rbuf[i][j] != 0)
4042                     TEST_ERROR
4043             }
4044             else
4045                 if(rbuf[i][j] != erbuf[i][j])
4046                     TEST_ERROR
4047         }
4048 
4049     /* Reopen srcdset[1] and srcfile if config option specified */
4050     if(config & TEST_IO_CLOSE_SRC) {
4051         if(config & TEST_IO_DIFFERENT_FILE)
4052             if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
4053                 TEST_ERROR
4054         if((srcdset[1] = H5Dopen2(srcfile[0], "src_dset2", H5P_DEFAULT)) < 0)
4055             TEST_ERROR
4056     }
4057 
4058     /* Extend srcdset[1] */
4059     dims[0] = 5;
4060     dims[1] = 20;
4061     if(H5Dset_extent(srcdset[1], dims) < 0)
4062         TEST_ERROR
4063 
4064     /* Adjust write buffer */
4065     for(i = 0; i < (int)mdims[0]; i++)
4066         for(j = 0; j < (int)mdims[1]; j++)
4067             buf[i][j] += (int)mdims[0] * (int)mdims[1];
4068 
4069     /* Write to new area of srcdset */
4070     count[1] = 10;
4071     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
4072         TEST_ERROR
4073     if((filespace = H5Dget_space(srcdset[1])) < 0)
4074         TEST_ERROR
4075     start[1] = 10;
4076     if(H5Sselect_hyperslab(filespace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
4077         TEST_ERROR
4078     if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT, buf[0]) < 0)
4079         TEST_ERROR
4080     if(H5Sclose(filespace) < 0)
4081         TEST_ERROR
4082 
4083     /* Update erbuf */
4084     for(i = 0; i < 5; i++)
4085         for(j = 0; j < 10; j++)
4086             erbuf[i + 5][j + 10] = buf[i][j];
4087 
4088     /* Close srcdset[1] and srcfile if config option specified */
4089     if(config & TEST_IO_CLOSE_SRC) {
4090         if(H5Dclose(srcdset[1]) < 0)
4091             TEST_ERROR
4092         srcdset[1] = -1;
4093 
4094         if(config & TEST_IO_DIFFERENT_FILE) {
4095             if(H5Fclose(srcfile[0]) < 0)
4096                 TEST_ERROR
4097             srcfile[0] = -1;
4098         }
4099     }
4100 
4101     /* Reopen virtual dataset and file if config option specified */
4102     if(config & TEST_IO_REOPEN_VIRT) {
4103         if(H5Dclose(vdset) < 0)
4104             TEST_ERROR
4105         vdset = -1;
4106         if(H5Fclose(vfile) < 0)
4107             TEST_ERROR
4108         vfile = -1;
4109         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
4110             TEST_ERROR
4111         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
4112             TEST_ERROR
4113     }
4114 
4115     /* Get VDS space */
4116     if((filespace = H5Dget_space(vdset)) < 0)
4117         TEST_ERROR
4118 
4119     /* Get VDS space dimensions */
4120     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
4121         TEST_ERROR
4122     if(ndims != 2)
4123         TEST_ERROR
4124     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
4125         TEST_ERROR
4126     if(dims[0] != 10)
4127         TEST_ERROR
4128     if(dims[1] != 20)
4129         TEST_ERROR
4130     if(mdims[0] != 10)
4131         TEST_ERROR
4132     if(mdims[1] != 20)
4133         TEST_ERROR
4134 
4135     /* Close filespace */
4136     if(H5Sclose(filespace) < 0)
4137         TEST_ERROR
4138 
4139     /* Read data through virtual dataset */
4140     /* Reset rbuf */
4141     HDmemset(rbuf[0], 0, sizeof(rbuf));
4142 
4143     /* Select hyperslab in memory space */
4144     start[1] = 0;
4145     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
4146         TEST_ERROR
4147 
4148     /* Read data */
4149     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
4150         TEST_ERROR
4151 
4152     /* Verify read data */
4153     for(i = 0; i < (int)mdims[0]; i++)
4154         for(j = 0; j < (int)mdims[1]; j++)
4155             if(rbuf[i][j] != erbuf[i][j])
4156                 TEST_ERROR
4157 
4158     /* Now just read middle 2 rows */
4159     HDmemset(rbuf[0], 0, sizeof(rbuf));
4160     start[0] = 4;
4161     count[0] = 2;
4162     count[1] = 20;
4163     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
4164         TEST_ERROR
4165     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, memspace, H5P_DEFAULT, rbuf[0]) < 0)
4166         TEST_ERROR
4167 
4168     /* Verify read data - algorithmically check for only 2 middle rows being
4169      * read so we don't have to wipe out erbuf and then restore it afterwards */
4170     for(i = 0; i < (int)mdims[0]; i++)
4171         for(j = 0; j < (int)mdims[1]; j++)
4172             if((i == 4) || (i == 5)) {
4173                 if(rbuf[i][j] != erbuf[i][j])
4174                     TEST_ERROR
4175             }
4176             else
4177                 if(rbuf[i][j] != 0)
4178                     TEST_ERROR
4179 
4180     /* Now test reopening virtual dataset without calling H5Dget_space, if
4181      * REOPEN_VIRT flag set */
4182     if(config & TEST_IO_REOPEN_VIRT) {
4183         if(H5Dclose(vdset) < 0)
4184             TEST_ERROR
4185         vdset = -1;
4186         if(H5Fclose(vfile) < 0)
4187             TEST_ERROR
4188         vfile = -1;
4189         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
4190             TEST_ERROR
4191         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
4192             TEST_ERROR
4193 
4194         /* Read data through virtual dataset */
4195         /* Reset rbuf */
4196         HDmemset(rbuf[0], 0, sizeof(rbuf));
4197 
4198         /* Select hyperslab in memory space */
4199         start[0] = 0;
4200         start[1] = 0;
4201         if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
4202             TEST_ERROR
4203 
4204         /* Read data */
4205         if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
4206             TEST_ERROR
4207 
4208         /* Verify read data */
4209         for(i = 0; i < (int)mdims[0]; i++)
4210             for(j = 0; j < (int)mdims[1]; j++)
4211                 if(rbuf[i][j] != erbuf[i][j])
4212                     TEST_ERROR
4213 
4214         /* Now try setting extent manually */
4215         /* Shrink to 18 */
4216         dims[1] = 18;
4217         if(H5Dset_extent(vdset, dims) < 0)
4218             TEST_ERROR
4219 
4220         /* Read data through virtual dataset */
4221         /* Reset rbuf */
4222         HDmemset(rbuf[0], 0, sizeof(rbuf));
4223 
4224         /* Select hyperslab in memory space */
4225         start[0] = 0;
4226         start[1] = 0;
4227         if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
4228             TEST_ERROR
4229 
4230         /* Read data */
4231         if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
4232             TEST_ERROR
4233 
4234         /* Verify read data */
4235         for(i = 0; i < (int)mdims[0]; i++)
4236             for(j = 0; j < (int)mdims[1]; j++) {
4237                 if(j >= (int)dims[1]) {
4238                     if(rbuf[i][j] != 0)
4239                         TEST_ERROR
4240                 }
4241                 else
4242                     if(rbuf[i][j] != erbuf[i][j])
4243                         TEST_ERROR
4244             }
4245 
4246         /* Shrink to 15 */
4247         dims[1] = 15;
4248         if(H5Dset_extent(vdset, dims) < 0)
4249             TEST_ERROR
4250 
4251         /* Read data through virtual dataset */
4252         /* Reset rbuf */
4253         HDmemset(rbuf[0], 0, sizeof(rbuf));
4254 
4255         /* Select hyperslab in memory space */
4256         start[0] = 0;
4257         start[1] = 0;
4258         if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
4259             TEST_ERROR
4260 
4261         /* Read data */
4262         if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
4263             TEST_ERROR
4264 
4265         /* Verify read data */
4266         for(i = 0; i < (int)mdims[0]; i++)
4267             for(j = 0; j < (int)mdims[1]; j++) {
4268                 if(j >= (int)dims[1]) {
4269                     if(rbuf[i][j] != 0)
4270                         TEST_ERROR
4271                 }
4272                 else
4273                     if(rbuf[i][j] != erbuf[i][j])
4274                         TEST_ERROR
4275             }
4276     }
4277 
4278     /* Close VDS and reopen with view set to H5D_VDS_FIRST_MISSING, reopen file
4279      * as well if config option specified */
4280     if(H5Dclose(vdset) < 0)
4281         TEST_ERROR
4282     if(H5Pset_virtual_view(dapl, H5D_VDS_FIRST_MISSING) < 0)
4283         TEST_ERROR
4284     if(config & TEST_IO_REOPEN_VIRT) {
4285         if(H5Fclose(vfile) < 0)
4286             TEST_ERROR
4287         vfile = -1;
4288         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
4289             TEST_ERROR
4290     }
4291     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
4292         TEST_ERROR
4293 
4294     /* Get VDS space */
4295     if((filespace = H5Dget_space(vdset)) < 0)
4296         TEST_ERROR
4297 
4298     /* Get VDS space dimensions */
4299     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
4300         TEST_ERROR
4301     if(ndims != 2)
4302         TEST_ERROR
4303     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
4304         TEST_ERROR
4305     if(dims[0] != 10)
4306         TEST_ERROR
4307     if(dims[1] != 15)
4308         TEST_ERROR
4309     if(mdims[0] != 10)
4310         TEST_ERROR
4311     if(mdims[1] != 20)
4312         TEST_ERROR
4313 
4314     /* Close filespace */
4315     if(H5Sclose(filespace) < 0)
4316         TEST_ERROR
4317 
4318     /* Read data through virtual dataset */
4319     /* Reset rbuf */
4320     HDmemset(rbuf[0], 0, sizeof(rbuf));
4321 
4322     /* Select hyperslab in memory space */
4323     start[0] = 0;
4324     start[1] = 0;
4325     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
4326         TEST_ERROR
4327 
4328     /* Read data */
4329     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
4330         TEST_ERROR
4331 
4332     /* Verify read data */
4333     for(i = 0; i < (int)mdims[0]; i++)
4334         for(j = 0; j < (int)mdims[1]; j++) {
4335             if(j >= (int)dims[1]) {
4336                 if(rbuf[i][j] != 0)
4337                     TEST_ERROR
4338             }
4339             else
4340                 if(rbuf[i][j] != erbuf[i][j])
4341                     TEST_ERROR
4342         }
4343 
4344     /* Now test reopening virtual dataset without calling H5Dget_space, if
4345      * REOPEN_VIRT flag set */
4346     if(config & TEST_IO_REOPEN_VIRT) {
4347         if(H5Dclose(vdset) < 0)
4348             TEST_ERROR
4349         vdset = -1;
4350         if(H5Fclose(vfile) < 0)
4351             TEST_ERROR
4352         vfile = -1;
4353         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
4354             TEST_ERROR
4355         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
4356             TEST_ERROR
4357 
4358         /* Read data through virtual dataset */
4359         /* Reset rbuf */
4360         HDmemset(rbuf[0], 0, sizeof(rbuf));
4361 
4362         /* Select hyperslab in memory space */
4363         start[1] = 0;
4364         if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
4365             TEST_ERROR
4366 
4367         /* Read data */
4368         if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
4369             TEST_ERROR
4370 
4371         /* Verify read data */
4372         for(i = 0; i < (int)mdims[0]; i++)
4373             for(j = 0; j < (int)mdims[1]; j++) {
4374                 if(j >= (int)dims[1]) {
4375                     if(rbuf[i][j] != 0)
4376                         TEST_ERROR
4377                 }
4378                 else
4379                     if(rbuf[i][j] != erbuf[i][j])
4380                         TEST_ERROR
4381             }
4382 
4383         /* Now try setting extent manually */
4384         /* Grow to 18 */
4385         dims[1] = 18;
4386         if(H5Dset_extent(vdset, dims) < 0)
4387             TEST_ERROR
4388 
4389         /* Read data through virtual dataset */
4390         /* Reset rbuf */
4391         HDmemset(rbuf[0], 0, sizeof(rbuf));
4392 
4393         /* Select hyperslab in memory space */
4394         start[0] = 0;
4395         start[1] = 0;
4396         if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
4397             TEST_ERROR
4398 
4399         /* Read data */
4400         if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
4401             TEST_ERROR
4402 
4403         /* Verify read data */
4404         for(i = 0; i < (int)mdims[0]; i++)
4405             for(j = 0; j < (int)mdims[1]; j++) {
4406                 if(j >= (int)dims[1]) {
4407                     if(rbuf[i][j] != 0)
4408                         TEST_ERROR
4409                 }
4410                 else
4411                     if(rbuf[i][j] != erbuf[i][j])
4412                         TEST_ERROR
4413             }
4414 
4415         /* Grow to 20 */
4416         dims[1] = 20;
4417         if(H5Dset_extent(vdset, dims) < 0)
4418             TEST_ERROR
4419 
4420         /* Read data through virtual dataset */
4421         /* Reset rbuf */
4422         HDmemset(rbuf[0], 0, sizeof(rbuf));
4423 
4424         /* Select hyperslab in memory space */
4425         start[0] = 0;
4426         start[1] = 0;
4427         if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
4428             TEST_ERROR
4429 
4430         /* Read data */
4431         if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
4432             TEST_ERROR
4433 
4434         /* Verify read data */
4435         for(i = 0; i < (int)mdims[0]; i++)
4436             for(j = 0; j < (int)mdims[1]; j++)
4437                 if(rbuf[i][j] != erbuf[i][j])
4438                     TEST_ERROR
4439     }
4440 
4441     /* Close */
4442     if(!(config & TEST_IO_CLOSE_SRC)) {
4443         if(H5Dclose(srcdset[0]) < 0)
4444             TEST_ERROR
4445         srcdset[0] = -1;
4446         if(H5Dclose(srcdset[1]) < 0)
4447             TEST_ERROR
4448         srcdset[1] = -1;
4449         if(H5Fclose(srcfile[0]) < 0)
4450             TEST_ERROR
4451         srcfile[0] = -1;
4452     }
4453     else if(!(config & TEST_IO_DIFFERENT_FILE)) {
4454         if(H5Fclose(srcfile[0]) < 0)
4455             TEST_ERROR
4456         srcfile[0] = -1;
4457     }
4458     if(H5Dclose(vdset) < 0)
4459         TEST_ERROR
4460     vdset = -1;
4461     if(H5Fclose(vfile) < 0)
4462         TEST_ERROR
4463     vfile = -1;
4464     if(H5Sclose(srcspace[0]) < 0)
4465         TEST_ERROR
4466     srcspace[0] = -1;
4467     if(H5Sclose(vspace[0]) < 0)
4468         TEST_ERROR
4469     vspace[0] = -1;
4470     if(H5Sclose(vspace[1]) < 0)
4471         TEST_ERROR
4472     vspace[1] = -1;
4473 
4474 
4475     /*
4476      * Test 2: 2 Source datasets, interleaved slices, single element wide
4477      */
4478     /* Clear virtual layout in DCPL */
4479     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
4480         TEST_ERROR
4481 
4482     /* Create virtual dataspaces */
4483     dims[0] = 10;
4484     dims[1] = 10;
4485     if((vspace[0] = H5Screate_simple(2, dims, mdims)) < 0)
4486         TEST_ERROR
4487     if((vspace[1] = H5Screate_simple(2, dims, mdims)) < 0)
4488         TEST_ERROR
4489 
4490     /* Create source dataspace */
4491     dims[1] = 5;
4492     mdims[1] = 10;
4493     if((srcspace[0] = H5Screate_simple(2, dims, mdims)) < 0)
4494         TEST_ERROR
4495     mdims[1] = 20;
4496 
4497     /* Select hyperslab in source space */
4498     start[0] = 0;
4499     start[1] = 0;
4500     count[0] = 10;
4501     count[1] = H5S_UNLIMITED;
4502     if(H5Sselect_hyperslab(srcspace[0], H5S_SELECT_SET, start, NULL, count, NULL) < 0)
4503         TEST_ERROR
4504 
4505     /* Select hyperslabs in virtual spaces */
4506     stride[0] = 1;
4507     stride[1] = 2;
4508     count[0] = 1;
4509     count[1] = H5S_UNLIMITED;
4510     block[0] = 10;
4511     block[1] = 1;
4512     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, stride, count, block) < 0)
4513         TEST_ERROR
4514     start[1] = 1;
4515     if(H5Sselect_hyperslab(vspace[1], H5S_SELECT_SET, start, stride, count, block) < 0)
4516         TEST_ERROR
4517     start[1] = 0;
4518 
4519     /* Add virtual layout mappings */
4520     if(H5Pset_virtual(dcpl, vspace[0], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset1", srcspace[0]) < 0)
4521         TEST_ERROR
4522     if(H5Pset_virtual(dcpl, vspace[1], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset2", srcspace[0]) < 0)
4523         TEST_ERROR
4524 
4525     /* Create virtual file */
4526     if((vfile = H5Fcreate(vfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
4527         TEST_ERROR
4528 
4529     /* Create source file if requested */
4530     if(config & TEST_IO_DIFFERENT_FILE) {
4531         if((srcfile[0] = H5Fcreate(srcfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
4532             TEST_ERROR
4533     }
4534     else {
4535         srcfile[0] = vfile;
4536         if(H5Iinc_ref(srcfile[0]) < 0)
4537             TEST_ERROR
4538     }
4539 
4540     /* Create source datasets */
4541     if((srcdset[0] = H5Dcreate2(srcfile[0], "src_dset1", H5T_NATIVE_INT, srcspace[0], H5P_DEFAULT, srcdcpl, H5P_DEFAULT)) < 0)
4542         TEST_ERROR
4543     if((srcdset[1] = H5Dcreate2(srcfile[0], "src_dset2", H5T_NATIVE_INT, srcspace[0], H5P_DEFAULT, srcdcpl, H5P_DEFAULT)) < 0)
4544         TEST_ERROR
4545 
4546     /* Create virtual dataset */
4547     if((vdset = H5Dcreate2(vfile, "v_dset", H5T_NATIVE_INT, vspace[0], H5P_DEFAULT, dcpl, dapl)) < 0)
4548         TEST_ERROR
4549 
4550     /* Populate write buffer */
4551     for(i = 0; i < (int)mdims[0]; i++)
4552         for(j = 0; j < (int)mdims[1]; j++)
4553             buf[i][j] = (i * (int)mdims[1]) + j;
4554 
4555     /* Initialize erbuf */
4556     for(i = 0; i < (int)mdims[0]; i++)
4557         for(j = 0; j < (int)mdims[1]; j++)
4558             erbuf[i][j] = fill;
4559 
4560     /* Write data directly to source datasets */
4561     /* Select hyperslab in memory */
4562     count[0] = 10;
4563     count[1] = 5;
4564     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
4565         TEST_ERROR
4566 
4567     /* Write first dataset */
4568     if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
4569         TEST_ERROR
4570 
4571     /* Update erbuf */
4572     for(i = 0; i < 10; i++)
4573         for(j = 0; j < 5; j++)
4574             erbuf[i][2 * j] = buf[i][j];
4575 
4576     /* Adjust write buffer */
4577     for(i = 0; i < (int)mdims[0]; i++)
4578         for(j = 0; j < (int)mdims[1]; j++)
4579             buf[i][j] += (int)mdims[0] * (int)mdims[1];
4580 
4581     /* Write second dataset */
4582     if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
4583         TEST_ERROR
4584 
4585     /* Update erbuf */
4586     for(i = 0; i < 10; i++)
4587         for(j = 0; j < 5; j++)
4588             erbuf[i][(2 * j) + 1] = buf[i][j];
4589 
4590     /* Close srcdsets and srcfile if config option specified */
4591     if(config & TEST_IO_CLOSE_SRC) {
4592         if(H5Dclose(srcdset[0]) < 0)
4593             TEST_ERROR
4594         srcdset[0] = -1;
4595         if(H5Dclose(srcdset[1]) < 0)
4596             TEST_ERROR
4597         srcdset[1] = -1;
4598 
4599         if(config & TEST_IO_DIFFERENT_FILE) {
4600             if(H5Fclose(srcfile[0]) < 0)
4601                 TEST_ERROR
4602             srcfile[0] = -1;
4603         }
4604     }
4605 
4606     /* Reopen virtual dataset and file if config option specified */
4607     if(config & TEST_IO_REOPEN_VIRT) {
4608         if(H5Dclose(vdset) < 0)
4609             TEST_ERROR
4610         vdset = -1;
4611         if(H5Fclose(vfile) < 0)
4612             TEST_ERROR
4613         vfile = -1;
4614         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
4615             TEST_ERROR
4616         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
4617             TEST_ERROR
4618     }
4619 
4620     /* Get VDS space */
4621     if((filespace = H5Dget_space(vdset)) < 0)
4622         TEST_ERROR
4623 
4624     /* Get VDS space dimensions */
4625     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
4626         TEST_ERROR
4627     if(ndims != 2)
4628         TEST_ERROR
4629     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
4630         TEST_ERROR
4631     if(dims[0] != 10)
4632         TEST_ERROR
4633     if(dims[1] != 10)
4634         TEST_ERROR
4635     if(mdims[0] != 10)
4636         TEST_ERROR
4637     if(mdims[1] != 20)
4638         TEST_ERROR
4639 
4640     /* Close filespace */
4641     if(H5Sclose(filespace) < 0)
4642         TEST_ERROR
4643 
4644     /* Read data through virtual dataset */
4645     /* Reset rbuf */
4646     HDmemset(rbuf[0], 0, sizeof(rbuf));
4647 
4648     /* Select hyperslab in memory space */
4649     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
4650         TEST_ERROR
4651 
4652     /* Read data */
4653     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
4654         TEST_ERROR
4655 
4656     /* Verify read data */
4657     for(i = 0; i < (int)mdims[0]; i++)
4658         for(j = 0; j < (int)mdims[1]; j++) {
4659             if(j >= (int)dims[1]) {
4660                 if(rbuf[i][j] != 0)
4661                     TEST_ERROR
4662             }
4663             else
4664                 if(rbuf[i][j] != erbuf[i][j])
4665                     TEST_ERROR
4666         }
4667 
4668     /* Close VDS and reopen with view set to H5D_VDS_FIRST_MISSING, reopen file
4669      * as well if config option specified */
4670     if(H5Dclose(vdset) < 0)
4671         TEST_ERROR
4672     if(H5Pset_virtual_view(dapl, H5D_VDS_FIRST_MISSING) < 0)
4673         TEST_ERROR
4674     if(config & TEST_IO_REOPEN_VIRT) {
4675         if(H5Fclose(vfile) < 0)
4676             TEST_ERROR
4677         vfile = -1;
4678         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
4679             TEST_ERROR
4680     }
4681     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
4682         TEST_ERROR
4683 
4684     /* Get VDS space */
4685     if((filespace = H5Dget_space(vdset)) < 0)
4686         TEST_ERROR
4687 
4688     /* Get VDS space dimensions */
4689     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
4690         TEST_ERROR
4691     if(ndims != 2)
4692         TEST_ERROR
4693     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
4694         TEST_ERROR
4695     if(dims[0] != 10)
4696         TEST_ERROR
4697     if(dims[1] != 10)
4698         TEST_ERROR
4699     if(mdims[0] != 10)
4700         TEST_ERROR
4701     if(mdims[1] != 20)
4702         TEST_ERROR
4703 
4704     /* Close filespace */
4705     if(H5Sclose(filespace) < 0)
4706         TEST_ERROR
4707 
4708     /* Read data through virtual dataset */
4709     /* Reset rbuf */
4710     HDmemset(rbuf[0], 0, sizeof(rbuf));
4711 
4712     /* Read data */
4713     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
4714         TEST_ERROR
4715 
4716     /* Verify read data */
4717     for(i = 0; i < (int)mdims[0]; i++)
4718         for(j = 0; j < (int)mdims[1]; j++) {
4719             if(j >= (int)dims[1]) {
4720                 if(rbuf[i][j] != 0)
4721                     TEST_ERROR
4722             }
4723             else
4724                 if(rbuf[i][j] != erbuf[i][j])
4725                     TEST_ERROR
4726         }
4727 
4728     /* Reopen srcdset[0] and srcfile if config option specified */
4729     if(config & TEST_IO_CLOSE_SRC) {
4730         if(config & TEST_IO_DIFFERENT_FILE)
4731             if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
4732                 TEST_ERROR
4733         if((srcdset[0] = H5Dopen2(srcfile[0], "src_dset1", H5P_DEFAULT)) < 0)
4734             TEST_ERROR
4735     }
4736 
4737     /* Extend srcdset[0] */
4738     dims[1] = 7;
4739     if(H5Dset_extent(srcdset[0], dims) < 0)
4740         TEST_ERROR
4741 
4742     /* Adjust write buffer */
4743     for(i = 0; i < (int)mdims[0]; i++)
4744         for(j = 0; j < (int)mdims[1]; j++)
4745             buf[i][j] += (int)mdims[0] * (int)mdims[1];
4746 
4747     /* Write to new area of srcdset */
4748     count[1] = 2;
4749     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
4750         TEST_ERROR
4751     if((filespace = H5Dget_space(srcdset[0])) < 0)
4752         TEST_ERROR
4753     start[1] = 5;
4754     if(H5Sselect_hyperslab(filespace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
4755         TEST_ERROR
4756     start[1] = 0;
4757     if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT, buf[0]) < 0)
4758         TEST_ERROR
4759     if(H5Sclose(filespace) < 0)
4760         TEST_ERROR
4761 
4762     /* Update erbuf to reflect only new data that is now visible under
4763      * H5D_VDS_FIRST_MISSING (first slice) */
4764     for(i = 0; i < 10; i++)
4765         erbuf[i][10] = buf[i][0];
4766 
4767     /* Close srcdset[0] and srcfile if config option specified */
4768     if(config & TEST_IO_CLOSE_SRC) {
4769         if(H5Dclose(srcdset[0]) < 0)
4770             TEST_ERROR
4771         srcdset[0] = -1;
4772 
4773         if(config & TEST_IO_DIFFERENT_FILE) {
4774             if(H5Fclose(srcfile[0]) < 0)
4775                 TEST_ERROR
4776             srcfile[0] = -1;
4777         }
4778     }
4779 
4780     /* Reopen virtual dataset and file if config option specified */
4781     if(config & TEST_IO_REOPEN_VIRT) {
4782         if(H5Dclose(vdset) < 0)
4783             TEST_ERROR
4784         vdset = -1;
4785         if(H5Fclose(vfile) < 0)
4786             TEST_ERROR
4787         vfile = -1;
4788         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
4789             TEST_ERROR
4790         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
4791             TEST_ERROR
4792     }
4793 
4794     /* Get VDS space */
4795     if((filespace = H5Dget_space(vdset)) < 0)
4796         TEST_ERROR
4797 
4798     /* Get VDS space dimensions.  Note that since we are using
4799      * H5D_VDS_FIRST_MISSING and we only extended one source dataset the
4800      * dimension will only have changed to add one more slice. */
4801     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
4802         TEST_ERROR
4803     if(ndims != 2)
4804         TEST_ERROR
4805     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
4806         TEST_ERROR
4807     if(dims[0] != 10)
4808         TEST_ERROR
4809     if(dims[1] != 11)
4810         TEST_ERROR
4811     if(mdims[0] != 10)
4812         TEST_ERROR
4813     if(mdims[1] != 20)
4814         TEST_ERROR
4815 
4816     /* Close filespace */
4817     if(H5Sclose(filespace) < 0)
4818         TEST_ERROR
4819 
4820     /* Read data through virtual dataset */
4821     /* Reset rbuf */
4822     HDmemset(rbuf[0], 0, sizeof(rbuf));
4823 
4824     /* Select hyperslab in memory space */
4825     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
4826         TEST_ERROR
4827 
4828     /* Read data */
4829     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
4830         TEST_ERROR
4831 
4832     /* Verify read data */
4833     for(i = 0; i < (int)mdims[0]; i++)
4834         for(j = 0; j < (int)mdims[1]; j++) {
4835             if(j >= (int)dims[1]) {
4836                 if(rbuf[i][j] != 0)
4837                     TEST_ERROR
4838             }
4839             else
4840                 if(rbuf[i][j] != erbuf[i][j])
4841                     TEST_ERROR
4842         }
4843 
4844     /* Close VDS and reopen with view set to H5D_VDS_LAST_AVAILABLE, reopen file
4845      * as well if config option specified */
4846     if(H5Dclose(vdset) < 0)
4847         TEST_ERROR
4848     if(H5Pset_virtual_view(dapl, H5D_VDS_LAST_AVAILABLE) < 0)
4849         TEST_ERROR
4850     if(config & TEST_IO_REOPEN_VIRT) {
4851         if(H5Fclose(vfile) < 0)
4852             TEST_ERROR
4853         vfile = -1;
4854         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
4855             TEST_ERROR
4856     }
4857     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
4858         TEST_ERROR
4859 
4860     /* Update erbuf to reflect new data that is now visible due to the change to
4861      * H5D_VDS_LAST_AVAILABLE (second new slice) */
4862     for(i = 0; i < 10; i++)
4863             erbuf[i][12] = buf[i][1];
4864 
4865     /* Get VDS space */
4866     if((filespace = H5Dget_space(vdset)) < 0)
4867         TEST_ERROR
4868 
4869     /* Get VDS space dimensions */
4870     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
4871         TEST_ERROR
4872     if(ndims != 2)
4873         TEST_ERROR
4874     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
4875         TEST_ERROR
4876     if(dims[0] != 10)
4877         TEST_ERROR
4878     if(dims[1] != 13)
4879         TEST_ERROR
4880     if(mdims[0] != 10)
4881         TEST_ERROR
4882     if(mdims[1] != 20)
4883         TEST_ERROR
4884 
4885     /* Close filespace */
4886     if(H5Sclose(filespace) < 0)
4887         TEST_ERROR
4888 
4889     /* Read data through virtual dataset */
4890     /* Reset rbuf */
4891     HDmemset(rbuf[0], 0, sizeof(rbuf));
4892 
4893     /* Select hyperslab in memory space */
4894     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
4895         TEST_ERROR
4896 
4897     /* Read data */
4898     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
4899         TEST_ERROR
4900 
4901     /* Verify read data */
4902     for(i = 0; i < (int)mdims[0]; i++)
4903         for(j = 0; j < (int)mdims[1]; j++) {
4904             if(j >= (int)dims[1]) {
4905                 if(rbuf[i][j] != 0)
4906                     TEST_ERROR
4907             }
4908             else
4909                 if(rbuf[i][j] != erbuf[i][j])
4910                     TEST_ERROR
4911         }
4912 
4913     /* Reopen srcdset[1] and srcfile if config option specified */
4914     if(config & TEST_IO_CLOSE_SRC) {
4915         if(config & TEST_IO_DIFFERENT_FILE)
4916             if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
4917                 TEST_ERROR
4918         if((srcdset[1] = H5Dopen2(srcfile[0], "src_dset2", H5P_DEFAULT)) < 0)
4919             TEST_ERROR
4920     }
4921 
4922     /* Extend srcdset[1] */
4923     dims[1] = 10;
4924     if(H5Dset_extent(srcdset[1], dims) < 0)
4925         TEST_ERROR
4926 
4927     /* Adjust write buffer */
4928     for(i = 0; i < (int)mdims[0]; i++)
4929         for(j = 0; j < (int)mdims[1]; j++)
4930             buf[i][j] += (int)mdims[0] * (int)mdims[1];
4931 
4932     /* Write to new area of srcdset */
4933     count[1] = 5;
4934     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
4935         TEST_ERROR
4936     if((filespace = H5Dget_space(srcdset[1])) < 0)
4937         TEST_ERROR
4938     start[1] = 5;
4939     if(H5Sselect_hyperslab(filespace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
4940         TEST_ERROR
4941     start[1] = 0;
4942     if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT, buf[0]) < 0)
4943         TEST_ERROR
4944     if(H5Sclose(filespace) < 0)
4945         TEST_ERROR
4946 
4947     /* Update erbuf */
4948     for(i = 0; i < 10; i++)
4949         for(j = 0; j < 5; j++)
4950             erbuf[i][(2 * j) + 11] = buf[i][j];
4951 
4952     /* Close srcdset[1] and srcfile if config option specified */
4953     if(config & TEST_IO_CLOSE_SRC) {
4954         if(H5Dclose(srcdset[1]) < 0)
4955             TEST_ERROR
4956         srcdset[1] = -1;
4957 
4958         if(config & TEST_IO_DIFFERENT_FILE) {
4959             if(H5Fclose(srcfile[0]) < 0)
4960                 TEST_ERROR
4961             srcfile[0] = -1;
4962         }
4963     }
4964 
4965     /* Reopen virtual dataset and file if config option specified */
4966     if(config & TEST_IO_REOPEN_VIRT) {
4967         if(H5Dclose(vdset) < 0)
4968             TEST_ERROR
4969         vdset = -1;
4970         if(H5Fclose(vfile) < 0)
4971             TEST_ERROR
4972         vfile = -1;
4973         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
4974             TEST_ERROR
4975         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
4976             TEST_ERROR
4977     }
4978 
4979     /* Get VDS space */
4980     if((filespace = H5Dget_space(vdset)) < 0)
4981         TEST_ERROR
4982 
4983     /* Get VDS space dimensions */
4984     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
4985         TEST_ERROR
4986     if(ndims != 2)
4987         TEST_ERROR
4988     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
4989         TEST_ERROR
4990     if(dims[0] != 10)
4991         TEST_ERROR
4992     if(dims[1] != 20)
4993         TEST_ERROR
4994     if(mdims[0] != 10)
4995         TEST_ERROR
4996     if(mdims[1] != 20)
4997         TEST_ERROR
4998 
4999     /* Close filespace */
5000     if(H5Sclose(filespace) < 0)
5001         TEST_ERROR
5002 
5003     /* Read data through virtual dataset */
5004     /* Reset rbuf */
5005     HDmemset(rbuf[0], 0, sizeof(rbuf));
5006 
5007     /* Select hyperslab in memory space */
5008     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
5009         TEST_ERROR
5010 
5011     /* Read data */
5012     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
5013         TEST_ERROR
5014 
5015     /* Verify read data */
5016     for(i = 0; i < (int)mdims[0]; i++)
5017         for(j = 0; j < (int)mdims[1]; j++)
5018             if(rbuf[i][j] != erbuf[i][j])
5019                 TEST_ERROR
5020 
5021     /* Now just read middle 2 rows */
5022     HDmemset(rbuf[0], 0, sizeof(rbuf));
5023     start[0] = 4;
5024     count[0] = 2;
5025     count[1] = 20;
5026     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
5027         TEST_ERROR
5028     start[0] = 0;
5029     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, memspace, H5P_DEFAULT, rbuf[0]) < 0)
5030         TEST_ERROR
5031 
5032     /* Verify read data - algorithmically check for only 2 middle rows being
5033      * read so we don't have to wipe out erbuf and then restore it afterwards */
5034     for(i = 0; i < (int)mdims[0]; i++)
5035         for(j = 0; j < (int)mdims[1]; j++)
5036             if((i == 4) || (i == 5)) {
5037                 if(rbuf[i][j] != erbuf[i][j])
5038                     TEST_ERROR
5039             }
5040             else
5041                 if(rbuf[i][j] != 0)
5042                     TEST_ERROR
5043 
5044     /* Close VDS and reopen with view set to H5D_VDS_FIRST_MISSING, reopen file
5045      * as well if config option specified */
5046     if(H5Dclose(vdset) < 0)
5047         TEST_ERROR
5048     if(H5Pset_virtual_view(dapl, H5D_VDS_FIRST_MISSING) < 0)
5049         TEST_ERROR
5050     if(config & TEST_IO_REOPEN_VIRT) {
5051         if(H5Fclose(vfile) < 0)
5052             TEST_ERROR
5053         vfile = -1;
5054         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
5055             TEST_ERROR
5056     }
5057     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
5058         TEST_ERROR
5059 
5060     /* Update erbuf to reflect new data that is no longer visible due to the
5061      * change to H5D_VDS_FIRST_MISSING */
5062     for(i = 0; i < 10; i++)
5063         for(j = 15; j < 20; j += 2)
5064             erbuf[i][j] = fill;
5065 
5066     /* Get VDS space */
5067     if((filespace = H5Dget_space(vdset)) < 0)
5068         TEST_ERROR
5069 
5070     /* Get VDS space dimensions */
5071     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
5072         TEST_ERROR
5073     if(ndims != 2)
5074         TEST_ERROR
5075     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
5076         TEST_ERROR
5077     if(dims[0] != 10)
5078         TEST_ERROR
5079     if(dims[1] != 14)
5080         TEST_ERROR
5081     if(mdims[0] != 10)
5082         TEST_ERROR
5083     if(mdims[1] != 20)
5084         TEST_ERROR
5085 
5086     /* Close filespace */
5087     if(H5Sclose(filespace) < 0)
5088         TEST_ERROR
5089 
5090     /* Read data through virtual dataset */
5091     /* Reset rbuf */
5092     HDmemset(rbuf[0], 0, sizeof(rbuf));
5093 
5094     /* Select hyperslab in memory space */
5095     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
5096         TEST_ERROR
5097 
5098     /* Read data */
5099     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
5100         TEST_ERROR
5101 
5102     /* Verify read data */
5103     for(i = 0; i < (int)mdims[0]; i++)
5104         for(j = 0; j < (int)mdims[1]; j++) {
5105             if(j >= (int)dims[1]) {
5106                 if(rbuf[i][j] != 0)
5107                     TEST_ERROR
5108             }
5109             else
5110                 if(rbuf[i][j] != erbuf[i][j])
5111                     TEST_ERROR
5112         }
5113 
5114     /* Close */
5115     if(!(config & TEST_IO_CLOSE_SRC)) {
5116         if(H5Dclose(srcdset[0]) < 0)
5117             TEST_ERROR
5118         srcdset[0] = -1;
5119         if(H5Dclose(srcdset[1]) < 0)
5120             TEST_ERROR
5121         srcdset[1] = -1;
5122         if(H5Fclose(srcfile[0]) < 0)
5123             TEST_ERROR
5124         srcfile[0] = -1;
5125     }
5126     else if(!(config & TEST_IO_DIFFERENT_FILE)) {
5127         if(H5Fclose(srcfile[0]) < 0)
5128             TEST_ERROR
5129         srcfile[0] = -1;
5130     }
5131     if(H5Dclose(vdset) < 0)
5132         TEST_ERROR
5133     vdset = -1;
5134     if(H5Fclose(vfile) < 0)
5135         TEST_ERROR
5136     vfile = -1;
5137     if(H5Sclose(srcspace[0]) < 0)
5138         TEST_ERROR
5139     srcspace[0] = -1;
5140     if(H5Sclose(vspace[0]) < 0)
5141         TEST_ERROR
5142     vspace[0] = -1;
5143     if(H5Sclose(vspace[1]) < 0)
5144         TEST_ERROR
5145     vspace[1] = -1;
5146 
5147 
5148     /*
5149      * Test 3: 3 Source datasets, interleaved slices, two elements wide
5150      */
5151     /* Clear virtual layout in DCPL */
5152     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
5153         TEST_ERROR
5154 
5155     /* Create virtual dataspaces */
5156     dims[0] = 10;
5157     dims[1] = 10;
5158     if((vspace[0] = H5Screate_simple(2, dims, mdims)) < 0)
5159         TEST_ERROR
5160     if((vspace[1] = H5Screate_simple(2, dims, mdims)) < 0)
5161         TEST_ERROR
5162     if((vspace[2] = H5Screate_simple(2, dims, mdims)) < 0)
5163         TEST_ERROR
5164 
5165     /* Create source dataspaces */
5166     dims[1] = 4;
5167     mdims[1] = 8;
5168     if((srcspace[0] = H5Screate_simple(2, dims, mdims)) < 0)
5169         TEST_ERROR
5170     dims[1] = 4;
5171     mdims[1] = 6;
5172     if((srcspace[1] = H5Screate_simple(2, dims, mdims)) < 0)
5173         TEST_ERROR
5174     dims[1] = 2;
5175     mdims[1] = 6;
5176     if((srcspace[2] = H5Screate_simple(2, dims, mdims)) < 0)
5177         TEST_ERROR
5178     mdims[1] = 20;
5179 
5180     /* Select hyperslab in source spaces */
5181     start[0] = 0;
5182     start[1] = 0;
5183     count[0] = 10;
5184     count[1] = H5S_UNLIMITED;
5185     if(H5Sselect_hyperslab(srcspace[0], H5S_SELECT_SET, start, NULL, count, NULL) < 0)
5186         TEST_ERROR
5187     if(H5Sselect_hyperslab(srcspace[1], H5S_SELECT_SET, start, NULL, count, NULL) < 0)
5188         TEST_ERROR
5189     if(H5Sselect_hyperslab(srcspace[2], H5S_SELECT_SET, start, NULL, count, NULL) < 0)
5190         TEST_ERROR
5191 
5192     /* Select hyperslabs in virtual spaces */
5193     stride[0] = 1;
5194     stride[1] = 6;
5195     count[0] = 1;
5196     count[1] = H5S_UNLIMITED;
5197     block[0] = 10;
5198     block[1] = 2;
5199     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, stride, count, block) < 0)
5200         TEST_ERROR
5201     start[1] = 2;
5202     if(H5Sselect_hyperslab(vspace[1], H5S_SELECT_SET, start, stride, count, block) < 0)
5203         TEST_ERROR
5204     start[1] = 4;
5205     if(H5Sselect_hyperslab(vspace[2], H5S_SELECT_SET, start, stride, count, block) < 0)
5206         TEST_ERROR
5207     start[1] = 0;
5208 
5209     /* Add virtual layout mappings */
5210     if(H5Pset_virtual(dcpl, vspace[0], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset1", srcspace[0]) < 0)
5211         TEST_ERROR
5212     if(H5Pset_virtual(dcpl, vspace[1], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset2", srcspace[1]) < 0)
5213         TEST_ERROR
5214     if(H5Pset_virtual(dcpl, vspace[2], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset3", srcspace[2]) < 0)
5215         TEST_ERROR
5216 
5217     /* Create virtual file */
5218     if((vfile = H5Fcreate(vfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
5219         TEST_ERROR
5220 
5221     /* Create source file if requested */
5222     if(config & TEST_IO_DIFFERENT_FILE) {
5223         if((srcfile[0] = H5Fcreate(srcfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
5224             TEST_ERROR
5225     }
5226     else {
5227         srcfile[0] = vfile;
5228         if(H5Iinc_ref(srcfile[0]) < 0)
5229             TEST_ERROR
5230     }
5231 
5232     /* Create source datasets */
5233     if((srcdset[0] = H5Dcreate2(srcfile[0], "src_dset1", H5T_NATIVE_INT, srcspace[0], H5P_DEFAULT, srcdcpl, H5P_DEFAULT)) < 0)
5234         TEST_ERROR
5235     if((srcdset[1] = H5Dcreate2(srcfile[0], "src_dset2", H5T_NATIVE_INT, srcspace[1], H5P_DEFAULT, srcdcpl, H5P_DEFAULT)) < 0)
5236         TEST_ERROR
5237     if((srcdset[2] = H5Dcreate2(srcfile[0], "src_dset3", H5T_NATIVE_INT, srcspace[2], H5P_DEFAULT, srcdcpl, H5P_DEFAULT)) < 0)
5238         TEST_ERROR
5239 
5240     /* Create virtual dataset */
5241     if((vdset = H5Dcreate2(vfile, "v_dset", H5T_NATIVE_INT, vspace[0], H5P_DEFAULT, dcpl, dapl)) < 0)
5242         TEST_ERROR
5243 
5244     /* Populate write buffer */
5245     for(i = 0; i < (int)mdims[0]; i++)
5246         for(j = 0; j < (int)mdims[1]; j++)
5247             buf[i][j] = (i * (int)mdims[1]) + j;
5248 
5249     /* Initialize erbuf */
5250     for(i = 0; i < (int)mdims[0]; i++)
5251         for(j = 0; j < (int)mdims[1]; j++)
5252             erbuf[i][j] = fill;
5253 
5254     /* Write data directly to source datasets */
5255     /* Select hyperslab in memory */
5256     count[0] = 10;
5257     count[1] = 4;
5258     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
5259         TEST_ERROR
5260 
5261     /* Write first dataset */
5262     if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
5263         TEST_ERROR
5264 
5265     /* Update erbuf */
5266     for(i = 0; i < 10; i++)
5267         for(j = 0; j < 2; j++) {
5268             erbuf[i][6 * j] = buf[i][2 * j];
5269             erbuf[i][(6 * j) + 1] = buf[i][(2 * j) + 1];
5270         }
5271 
5272     /* Adjust write buffer */
5273     for(i = 0; i < (int)mdims[0]; i++)
5274         for(j = 0; j < (int)mdims[1]; j++)
5275             buf[i][j] += (int)mdims[0] * (int)mdims[1];
5276 
5277     /* Write second dataset */
5278     if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
5279         TEST_ERROR
5280 
5281     /* Update erbuf */
5282     for(i = 0; i < 10; i++)
5283         for(j = 0; j < 2; j++) {
5284             erbuf[i][(6 * j) + 2] = buf[i][2 * j];
5285             erbuf[i][(6 * j) + 3] = buf[i][(2 * j) + 1];
5286         }
5287 
5288     /* Adjust write buffer */
5289     for(i = 0; i < (int)mdims[0]; i++)
5290         for(j = 0; j < (int)mdims[1]; j++)
5291             buf[i][j] += (int)mdims[0] * (int)mdims[1];
5292 
5293     /* Select hyperslab in memory */
5294     count[0] = 10;
5295     count[1] = 2;
5296     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
5297         TEST_ERROR
5298 
5299     /* Write third dataset */
5300     if(H5Dwrite(srcdset[2], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
5301         TEST_ERROR
5302 
5303     /* Update erbuf */
5304     for(i = 0; i < 10; i++) {
5305         erbuf[i][4] = buf[i][0];
5306         erbuf[i][5] = buf[i][1];
5307     }
5308 
5309     /* Close srcdsets and srcfile if config option specified */
5310     if(config & TEST_IO_CLOSE_SRC) {
5311         if(H5Dclose(srcdset[0]) < 0)
5312             TEST_ERROR
5313         srcdset[0] = -1;
5314         if(H5Dclose(srcdset[1]) < 0)
5315             TEST_ERROR
5316         srcdset[1] = -1;
5317         if(H5Dclose(srcdset[2]) < 0)
5318             TEST_ERROR
5319         srcdset[2] = -1;
5320 
5321         if(config & TEST_IO_DIFFERENT_FILE) {
5322             if(H5Fclose(srcfile[0]) < 0)
5323                 TEST_ERROR
5324             srcfile[0] = -1;
5325         }
5326     }
5327 
5328     /* Reopen virtual dataset and file if config option specified */
5329     if(config & TEST_IO_REOPEN_VIRT) {
5330         if(H5Dclose(vdset) < 0)
5331             TEST_ERROR
5332         vdset = -1;
5333         if(H5Fclose(vfile) < 0)
5334             TEST_ERROR
5335         vfile = -1;
5336         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
5337             TEST_ERROR
5338         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
5339             TEST_ERROR
5340     }
5341 
5342     /* Get VDS space */
5343     if((filespace = H5Dget_space(vdset)) < 0)
5344         TEST_ERROR
5345 
5346     /* Get VDS space dimensions */
5347     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
5348         TEST_ERROR
5349     if(ndims != 2)
5350         TEST_ERROR
5351     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
5352         TEST_ERROR
5353     if(dims[0] != 10)
5354         TEST_ERROR
5355     if(dims[1] != 10)
5356         TEST_ERROR
5357     if(mdims[0] != 10)
5358         TEST_ERROR
5359     if(mdims[1] != 20)
5360         TEST_ERROR
5361 
5362     /* Close filespace */
5363     if(H5Sclose(filespace) < 0)
5364         TEST_ERROR
5365 
5366     /* Read data through virtual dataset */
5367     /* Reset rbuf */
5368     HDmemset(rbuf[0], 0, sizeof(rbuf));
5369 
5370     /* Select hyperslab in memory space */
5371     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
5372         TEST_ERROR
5373 
5374     /* Read data */
5375     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
5376         TEST_ERROR
5377 
5378     /* Verify read data */
5379     for(i = 0; i < (int)mdims[0]; i++)
5380         for(j = 0; j < (int)mdims[1]; j++) {
5381             if(j >= (int)dims[1]) {
5382                 if(rbuf[i][j] != 0)
5383                     TEST_ERROR
5384             }
5385             else
5386                 if(rbuf[i][j] != erbuf[i][j])
5387                     TEST_ERROR
5388         }
5389 
5390     /* Close VDS and reopen with view set to H5D_VDS_FIRST_MISSING, reopen file
5391      * as well if config option specified */
5392     if(H5Dclose(vdset) < 0)
5393         TEST_ERROR
5394     if(H5Pset_virtual_view(dapl, H5D_VDS_FIRST_MISSING) < 0)
5395         TEST_ERROR
5396     if(config & TEST_IO_REOPEN_VIRT) {
5397         if(H5Fclose(vfile) < 0)
5398             TEST_ERROR
5399         vfile = -1;
5400         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
5401             TEST_ERROR
5402     }
5403     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
5404         TEST_ERROR
5405 
5406     /* Get VDS space */
5407     if((filespace = H5Dget_space(vdset)) < 0)
5408         TEST_ERROR
5409 
5410     /* Get VDS space dimensions */
5411     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
5412         TEST_ERROR
5413     if(ndims != 2)
5414         TEST_ERROR
5415     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
5416         TEST_ERROR
5417     if(dims[0] != 10)
5418         TEST_ERROR
5419     if(dims[1] != 10)
5420         TEST_ERROR
5421     if(mdims[0] != 10)
5422         TEST_ERROR
5423     if(mdims[1] != 20)
5424         TEST_ERROR
5425 
5426     /* Close filespace */
5427     if(H5Sclose(filespace) < 0)
5428         TEST_ERROR
5429 
5430     /* Read data through virtual dataset */
5431     /* Reset rbuf */
5432     HDmemset(rbuf[0], 0, sizeof(rbuf));
5433 
5434     /* Read data */
5435     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
5436         TEST_ERROR
5437 
5438     /* Verify read data */
5439     for(i = 0; i < (int)mdims[0]; i++)
5440         for(j = 0; j < (int)mdims[1]; j++) {
5441             if(j >= (int)dims[1]) {
5442                 if(rbuf[i][j] != 0)
5443                     TEST_ERROR
5444             }
5445             else
5446                 if(rbuf[i][j] != erbuf[i][j])
5447                     TEST_ERROR
5448         }
5449 
5450     /* Reopen srcdset[0] and srcfile if config option specified */
5451     if(config & TEST_IO_CLOSE_SRC) {
5452         if(config & TEST_IO_DIFFERENT_FILE)
5453             if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
5454                 TEST_ERROR
5455         if((srcdset[0] = H5Dopen2(srcfile[0], "src_dset1", H5P_DEFAULT)) < 0)
5456             TEST_ERROR
5457     }
5458 
5459     /* Extend srcdset[0] */
5460     dims[1] = 7;
5461     if(H5Dset_extent(srcdset[0], dims) < 0)
5462         TEST_ERROR
5463 
5464     /* Adjust write buffer */
5465     for(i = 0; i < (int)mdims[0]; i++)
5466         for(j = 0; j < (int)mdims[1]; j++)
5467             buf[i][j] += (int)mdims[0] * (int)mdims[1];
5468 
5469     /* Write to new area of srcdset */
5470     count[1] = 3;
5471     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
5472         TEST_ERROR
5473     if((filespace = H5Dget_space(srcdset[0])) < 0)
5474         TEST_ERROR
5475     start[1] = 4;
5476     if(H5Sselect_hyperslab(filespace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
5477         TEST_ERROR
5478     start[1] = 0;
5479     if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT, buf[0]) < 0)
5480         TEST_ERROR
5481     if(H5Sclose(filespace) < 0)
5482         TEST_ERROR
5483 
5484     /* Close srcdset[0] and srcfile if config option specified */
5485     if(config & TEST_IO_CLOSE_SRC) {
5486         if(H5Dclose(srcdset[0]) < 0)
5487             TEST_ERROR
5488         srcdset[0] = -1;
5489 
5490         if(config & TEST_IO_DIFFERENT_FILE) {
5491             if(H5Fclose(srcfile[0]) < 0)
5492                 TEST_ERROR
5493             srcfile[0] = -1;
5494         }
5495     }
5496 
5497     /* Reopen virtual dataset and file if config option specified */
5498     if(config & TEST_IO_REOPEN_VIRT) {
5499         if(H5Dclose(vdset) < 0)
5500             TEST_ERROR
5501         vdset = -1;
5502         if(H5Fclose(vfile) < 0)
5503             TEST_ERROR
5504         vfile = -1;
5505         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
5506             TEST_ERROR
5507         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
5508             TEST_ERROR
5509     }
5510 
5511     /* Get VDS space */
5512     if((filespace = H5Dget_space(vdset)) < 0)
5513         TEST_ERROR
5514 
5515     /* Get VDS space dimensions.  Note that since we are using
5516      * H5D_VDS_FIRST_MISSING the size will not have changed. */
5517     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
5518         TEST_ERROR
5519     if(ndims != 2)
5520         TEST_ERROR
5521     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
5522         TEST_ERROR
5523     if(dims[0] != 10)
5524         TEST_ERROR
5525     if(dims[1] != 10)
5526         TEST_ERROR
5527     if(mdims[0] != 10)
5528         TEST_ERROR
5529     if(mdims[1] != 20)
5530         TEST_ERROR
5531 
5532     /* Close filespace */
5533     if(H5Sclose(filespace) < 0)
5534         TEST_ERROR
5535 
5536     /* Read data through virtual dataset */
5537     /* Reset rbuf */
5538     HDmemset(rbuf[0], 0, sizeof(rbuf));
5539 
5540     /* Select hyperslab in memory space */
5541     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
5542         TEST_ERROR
5543 
5544     /* Read data */
5545     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
5546         TEST_ERROR
5547 
5548     /* Verify read data */
5549     for(i = 0; i < (int)mdims[0]; i++)
5550         for(j = 0; j < (int)mdims[1]; j++) {
5551             if(j >= (int)dims[1]) {
5552                 if(rbuf[i][j] != 0)
5553                     TEST_ERROR
5554             }
5555             else
5556                 if(rbuf[i][j] != erbuf[i][j])
5557                     TEST_ERROR
5558         }
5559 
5560     /* Close VDS and reopen with view set to H5D_VDS_LAST_AVAILABLE, reopen file
5561      * as well if config option specified */
5562     if(H5Dclose(vdset) < 0)
5563         TEST_ERROR
5564     if(H5Pset_virtual_view(dapl, H5D_VDS_LAST_AVAILABLE) < 0)
5565         TEST_ERROR
5566     if(config & TEST_IO_REOPEN_VIRT) {
5567         if(H5Fclose(vfile) < 0)
5568             TEST_ERROR
5569         vfile = -1;
5570         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
5571             TEST_ERROR
5572     }
5573     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
5574         TEST_ERROR
5575 
5576     /* Update erbuf to reflect new data that is now visible due to the change to
5577      * H5D_VDS_LAST_AVAILABLE */
5578     for(i = 0; i < 10; i++) {
5579         erbuf[i][12] = buf[i][0];
5580         erbuf[i][13] = buf[i][1];
5581         erbuf[i][18] = buf[i][2];
5582     }
5583 
5584     /* Get VDS space */
5585     if((filespace = H5Dget_space(vdset)) < 0)
5586         TEST_ERROR
5587 
5588     /* Get VDS space dimensions */
5589     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
5590         TEST_ERROR
5591     if(ndims != 2)
5592         TEST_ERROR
5593     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
5594         TEST_ERROR
5595     if(dims[0] != 10)
5596         TEST_ERROR
5597     if(dims[1] != 19)
5598         TEST_ERROR
5599     if(mdims[0] != 10)
5600         TEST_ERROR
5601     if(mdims[1] != 20)
5602         TEST_ERROR
5603 
5604     /* Close filespace */
5605     if(H5Sclose(filespace) < 0)
5606         TEST_ERROR
5607 
5608     /* Read data through virtual dataset */
5609     /* Reset rbuf */
5610     HDmemset(rbuf[0], 0, sizeof(rbuf));
5611 
5612     /* Select hyperslab in memory space */
5613     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
5614         TEST_ERROR
5615 
5616     /* Read data */
5617     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
5618         TEST_ERROR
5619 
5620     /* Verify read data */
5621     for(i = 0; i < (int)mdims[0]; i++)
5622         for(j = 0; j < (int)mdims[1]; j++) {
5623             if(j >= (int)dims[1]) {
5624                 if(rbuf[i][j] != 0)
5625                     TEST_ERROR
5626             }
5627             else
5628                 if(rbuf[i][j] != erbuf[i][j])
5629                     TEST_ERROR
5630         }
5631 
5632     /* Reopen srcdset[2] and srcfile if config option specified */
5633     if(config & TEST_IO_CLOSE_SRC) {
5634         if(config & TEST_IO_DIFFERENT_FILE)
5635             if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
5636                 TEST_ERROR
5637         if((srcdset[2] = H5Dopen2(srcfile[0], "src_dset3", H5P_DEFAULT)) < 0)
5638             TEST_ERROR
5639     }
5640 
5641     /* Extend srcdset[2] */
5642     dims[1] = 5;
5643     if(H5Dset_extent(srcdset[2], dims) < 0)
5644         TEST_ERROR
5645 
5646     /* Adjust write buffer */
5647     for(i = 0; i < (int)mdims[0]; i++)
5648         for(j = 0; j < (int)mdims[1]; j++)
5649             buf[i][j] += (int)mdims[0] * (int)mdims[1];
5650 
5651     /* Write to new area of srcdset */
5652     count[1] = 3;
5653     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
5654         TEST_ERROR
5655     if((filespace = H5Dget_space(srcdset[2])) < 0)
5656         TEST_ERROR
5657     start[1] = 2;
5658     if(H5Sselect_hyperslab(filespace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
5659         TEST_ERROR
5660     start[1] = 0;
5661     if(H5Dwrite(srcdset[2], H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT, buf[0]) < 0)
5662         TEST_ERROR
5663     if(H5Sclose(filespace) < 0)
5664         TEST_ERROR
5665 
5666     /* Update erbuf */
5667     for(i = 0; i < 10; i++) {
5668         erbuf[i][10] = buf[i][0];
5669         erbuf[i][11] = buf[i][1];
5670         erbuf[i][16] = buf[i][2];
5671     }
5672 
5673     /* Close srcdset[2] and srcfile if config option specified */
5674     if(config & TEST_IO_CLOSE_SRC) {
5675         if(H5Dclose(srcdset[2]) < 0)
5676             TEST_ERROR
5677         srcdset[2] = -1;
5678 
5679         if(config & TEST_IO_DIFFERENT_FILE) {
5680             if(H5Fclose(srcfile[0]) < 0)
5681                 TEST_ERROR
5682             srcfile[0] = -1;
5683         }
5684     }
5685 
5686     /* Reopen virtual dataset and file if config option specified */
5687     if(config & TEST_IO_REOPEN_VIRT) {
5688         if(H5Dclose(vdset) < 0)
5689             TEST_ERROR
5690         vdset = -1;
5691         if(H5Fclose(vfile) < 0)
5692             TEST_ERROR
5693         vfile = -1;
5694         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
5695             TEST_ERROR
5696         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
5697             TEST_ERROR
5698     }
5699 
5700     /* Get VDS space */
5701     if((filespace = H5Dget_space(vdset)) < 0)
5702         TEST_ERROR
5703 
5704     /* Get VDS space dimensions.  Note that the dimensions will not have
5705      * changed. */
5706     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
5707         TEST_ERROR
5708     if(ndims != 2)
5709         TEST_ERROR
5710     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
5711         TEST_ERROR
5712     if(dims[0] != 10)
5713         TEST_ERROR
5714     if(dims[1] != 19)
5715         TEST_ERROR
5716     if(mdims[0] != 10)
5717         TEST_ERROR
5718     if(mdims[1] != 20)
5719         TEST_ERROR
5720 
5721     /* Close filespace */
5722     if(H5Sclose(filespace) < 0)
5723         TEST_ERROR
5724 
5725     /* Read data through virtual dataset */
5726     /* Reset rbuf */
5727     HDmemset(rbuf[0], 0, sizeof(rbuf));
5728 
5729     /* Select hyperslab in memory space */
5730     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
5731         TEST_ERROR
5732 
5733     /* Read data */
5734     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
5735         TEST_ERROR
5736 
5737     /* Verify read data */
5738     for(i = 0; i < (int)mdims[0]; i++)
5739         for(j = 0; j < (int)mdims[1]; j++) {
5740             if(j >= (int)dims[1]) {
5741                 if(rbuf[i][j] != 0)
5742                     TEST_ERROR
5743             }
5744             else
5745                 if(rbuf[i][j] != erbuf[i][j])
5746                     TEST_ERROR
5747         }
5748 
5749     /* Close VDS and reopen with view set to H5D_VDS_FIRST_MISSING, reopen file
5750      * as well if config option specified */
5751     if(H5Dclose(vdset) < 0)
5752         TEST_ERROR
5753     if(H5Pset_virtual_view(dapl, H5D_VDS_FIRST_MISSING) < 0)
5754         TEST_ERROR
5755     if(config & TEST_IO_REOPEN_VIRT) {
5756         if(H5Fclose(vfile) < 0)
5757             TEST_ERROR
5758         vfile = -1;
5759         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
5760             TEST_ERROR
5761     }
5762     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
5763         TEST_ERROR
5764 
5765     /* Get VDS space */
5766     if((filespace = H5Dget_space(vdset)) < 0)
5767         TEST_ERROR
5768 
5769     /* Get VDS space dimensions */
5770     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
5771         TEST_ERROR
5772     if(ndims != 2)
5773         TEST_ERROR
5774     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
5775         TEST_ERROR
5776     if(dims[0] != 10)
5777         TEST_ERROR
5778     if(dims[1] != 14)
5779         TEST_ERROR
5780     if(mdims[0] != 10)
5781         TEST_ERROR
5782     if(mdims[1] != 20)
5783         TEST_ERROR
5784 
5785     /* Close filespace */
5786     if(H5Sclose(filespace) < 0)
5787         TEST_ERROR
5788 
5789     /* Read data through virtual dataset */
5790     /* Reset rbuf */
5791     HDmemset(rbuf[0], 0, sizeof(rbuf));
5792 
5793     /* Select hyperslab in memory space */
5794     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
5795         TEST_ERROR
5796 
5797     /* Read data */
5798     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
5799         TEST_ERROR
5800 
5801     /* Verify read data */
5802     for(i = 0; i < (int)mdims[0]; i++)
5803         for(j = 0; j < (int)mdims[1]; j++) {
5804             if(j >= (int)dims[1]) {
5805                 if(rbuf[i][j] != 0)
5806                     TEST_ERROR
5807             }
5808             else
5809                 if(rbuf[i][j] != erbuf[i][j])
5810                     TEST_ERROR
5811         }
5812 
5813     /* Reopen srcdset[1] and srcfile if config option specified */
5814     if(config & TEST_IO_CLOSE_SRC) {
5815         if(config & TEST_IO_DIFFERENT_FILE)
5816             if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
5817                 TEST_ERROR
5818         if((srcdset[1] = H5Dopen2(srcfile[0], "src_dset2", H5P_DEFAULT)) < 0)
5819             TEST_ERROR
5820     }
5821 
5822     /* Extend srcdset[1] */
5823     dims[1] = 6;
5824     if(H5Dset_extent(srcdset[1], dims) < 0)
5825         TEST_ERROR
5826 
5827     /* Adjust write buffer */
5828     for(i = 0; i < (int)mdims[0]; i++)
5829         for(j = 0; j < (int)mdims[1]; j++)
5830             buf[i][j] += (int)mdims[0] * (int)mdims[1];
5831 
5832     /* Write to new area of srcdset */
5833     count[1] = 2;
5834     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
5835         TEST_ERROR
5836     if((filespace = H5Dget_space(srcdset[1])) < 0)
5837         TEST_ERROR
5838     start[1] = 4;
5839     if(H5Sselect_hyperslab(filespace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
5840         TEST_ERROR
5841     start[1] = 0;
5842     if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT, buf[0]) < 0)
5843         TEST_ERROR
5844     if(H5Sclose(filespace) < 0)
5845         TEST_ERROR
5846 
5847     /* Update erbuf */
5848     for(i = 0; i < 10; i++) {
5849         erbuf[i][14] = buf[i][0];
5850         erbuf[i][15] = buf[i][1];
5851     }
5852 
5853     /* Close srcdset[1] and srcfile if config option specified */
5854     if(config & TEST_IO_CLOSE_SRC) {
5855         if(H5Dclose(srcdset[1]) < 0)
5856             TEST_ERROR
5857         srcdset[1] = -1;
5858 
5859         if(config & TEST_IO_DIFFERENT_FILE) {
5860             if(H5Fclose(srcfile[0]) < 0)
5861                 TEST_ERROR
5862             srcfile[0] = -1;
5863         }
5864     }
5865 
5866     /* Reopen virtual dataset and file if config option specified */
5867     if(config & TEST_IO_REOPEN_VIRT) {
5868         if(H5Dclose(vdset) < 0)
5869             TEST_ERROR
5870         vdset = -1;
5871         if(H5Fclose(vfile) < 0)
5872             TEST_ERROR
5873         vfile = -1;
5874         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
5875             TEST_ERROR
5876         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
5877             TEST_ERROR
5878     }
5879 
5880     /* Get VDS space */
5881     if((filespace = H5Dget_space(vdset)) < 0)
5882         TEST_ERROR
5883 
5884     /* Get VDS space dimensions */
5885     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
5886         TEST_ERROR
5887     if(ndims != 2)
5888         TEST_ERROR
5889     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
5890         TEST_ERROR
5891     if(dims[0] != 10)
5892         TEST_ERROR
5893     if(dims[1] != 17)
5894         TEST_ERROR
5895     if(mdims[0] != 10)
5896         TEST_ERROR
5897     if(mdims[1] != 20)
5898         TEST_ERROR
5899 
5900     /* Close filespace */
5901     if(H5Sclose(filespace) < 0)
5902         TEST_ERROR
5903 
5904     /* Read data through virtual dataset */
5905     /* Reset rbuf */
5906     HDmemset(rbuf[0], 0, sizeof(rbuf));
5907 
5908     /* Select hyperslab in memory space */
5909     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
5910         TEST_ERROR
5911 
5912     /* Read data */
5913     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
5914         TEST_ERROR
5915 
5916     /* Verify read data */
5917     for(i = 0; i < (int)mdims[0]; i++)
5918         for(j = 0; j < (int)mdims[1]; j++) {
5919             if(j >= (int)dims[1]) {
5920                 if(rbuf[i][j] != 0)
5921                     TEST_ERROR
5922             }
5923             else
5924                 if(rbuf[i][j] != erbuf[i][j])
5925                     TEST_ERROR
5926         }
5927 
5928     /* Close VDS and reopen with view set to H5D_VDS_LAST_AVAILABLE, reopen file
5929      * as well if config option specified */
5930     if(H5Dclose(vdset) < 0)
5931         TEST_ERROR
5932     if(H5Pset_virtual_view(dapl, H5D_VDS_LAST_AVAILABLE) < 0)
5933         TEST_ERROR
5934     if(config & TEST_IO_REOPEN_VIRT) {
5935         if(H5Fclose(vfile) < 0)
5936             TEST_ERROR
5937         vfile = -1;
5938         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
5939             TEST_ERROR
5940     }
5941     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
5942         TEST_ERROR
5943 
5944     /* Get VDS space */
5945     if((filespace = H5Dget_space(vdset)) < 0)
5946         TEST_ERROR
5947 
5948     /* Get VDS space dimensions */
5949     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
5950         TEST_ERROR
5951     if(ndims != 2)
5952         TEST_ERROR
5953     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
5954         TEST_ERROR
5955     if(dims[0] != 10)
5956         TEST_ERROR
5957     if(dims[1] != 19)
5958         TEST_ERROR
5959     if(mdims[0] != 10)
5960         TEST_ERROR
5961     if(mdims[1] != 20)
5962         TEST_ERROR
5963 
5964     /* Read data through virtual dataset */
5965     /* Reset rbuf */
5966     HDmemset(rbuf[0], 0, sizeof(rbuf));
5967 
5968     /* Select hyperslab in memory space */
5969     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
5970         TEST_ERROR
5971 
5972     /* Read data */
5973     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
5974         TEST_ERROR
5975 
5976     /* Verify read data */
5977     for(i = 0; i < (int)mdims[0]; i++)
5978         for(j = 0; j < (int)mdims[1]; j++) {
5979             if(j >= (int)dims[1]) {
5980                 if(rbuf[i][j] != 0)
5981                     TEST_ERROR
5982             }
5983             else
5984                 if(rbuf[i][j] != erbuf[i][j])
5985                     TEST_ERROR
5986         }
5987 
5988     /* Now just read middle 2 rows */
5989     HDmemset(rbuf[0], 0, sizeof(rbuf));
5990     start[0] = 4;
5991     count[0] = 2;
5992     count[1] = 19;
5993     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
5994         TEST_ERROR
5995     if(H5Sselect_hyperslab(filespace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
5996         TEST_ERROR
5997     start[0] = 0;
5998     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT, rbuf[0]) < 0)
5999         TEST_ERROR
6000 
6001     /* Close filespace */
6002     if(H5Sclose(filespace) < 0)
6003         TEST_ERROR
6004 
6005     /* Verify read data - algorithmically check for only 2 middle rows being
6006      * read */
6007     for(i = 0; i < (int)mdims[0]; i++)
6008         for(j = 0; j < (int)mdims[1]; j++)
6009             if(j >= (int)dims[1]) {
6010                 if(rbuf[i][j] != 0)
6011                     TEST_ERROR
6012             }
6013             else if((i == 4) || (i == 5)) {
6014                 if(rbuf[i][j] != erbuf[i][j])
6015                     TEST_ERROR
6016             }
6017             else
6018                 if(rbuf[i][j] != 0)
6019                     TEST_ERROR
6020 
6021     /* Close */
6022     if(!(config & TEST_IO_CLOSE_SRC)) {
6023         if(H5Dclose(srcdset[0]) < 0)
6024             TEST_ERROR
6025         srcdset[0] = -1;
6026         if(H5Dclose(srcdset[1]) < 0)
6027             TEST_ERROR
6028         srcdset[1] = -1;
6029         if(H5Dclose(srcdset[2]) < 0)
6030             TEST_ERROR
6031         srcdset[2] = -1;
6032         if(H5Fclose(srcfile[0]) < 0)
6033             TEST_ERROR
6034         srcfile[0] = -1;
6035     }
6036     else if(!(config & TEST_IO_DIFFERENT_FILE)) {
6037         if(H5Fclose(srcfile[0]) < 0)
6038             TEST_ERROR
6039         srcfile[0] = -1;
6040     }
6041     if(H5Dclose(vdset) < 0)
6042         TEST_ERROR
6043     vdset = -1;
6044     if(H5Fclose(vfile) < 0)
6045         TEST_ERROR
6046     vfile = -1;
6047     if(H5Sclose(srcspace[0]) < 0)
6048         TEST_ERROR
6049     srcspace[0] = -1;
6050     if(H5Sclose(srcspace[1]) < 0)
6051         TEST_ERROR
6052     srcspace[1] = -1;
6053     if(H5Sclose(srcspace[2]) < 0)
6054         TEST_ERROR
6055     srcspace[2] = -1;
6056     if(H5Sclose(vspace[0]) < 0)
6057         TEST_ERROR
6058     vspace[0] = -1;
6059     if(H5Sclose(vspace[1]) < 0)
6060         TEST_ERROR
6061     vspace[1] = -1;
6062 
6063 
6064     /*
6065      * Test 4: 2 Source datasets, offset starts
6066      */
6067     /* Clear virtual layout in DCPL */
6068     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
6069         TEST_ERROR
6070 
6071     /* Create virtual dataspaces */
6072     if((vspace[0] = H5Screate_simple(2, dims, mdims)) < 0)
6073         TEST_ERROR
6074     if((vspace[1] = H5Screate_simple(2, dims, mdims)) < 0)
6075         TEST_ERROR
6076 
6077     /* Create source dataspaces */
6078     dims[0] = 5;
6079     dims[1] = 0;
6080     mdims[0] = 5;
6081     if((srcspace[0] = H5Screate_simple(2, dims, mdims)) < 0)
6082         TEST_ERROR
6083     dims[1] = 5;
6084     if((srcspace[1] = H5Screate_simple(2, dims, mdims)) < 0)
6085         TEST_ERROR
6086     mdims[0] = 10;
6087 
6088     /* Select hyperslab in source spaces */
6089     start[0] = 0;
6090     start[1] = 0;
6091     count[0] = 5;
6092     count[1] = H5S_UNLIMITED;
6093     if(H5Sselect_hyperslab(srcspace[0], H5S_SELECT_SET, start, NULL, count, NULL) < 0)
6094         TEST_ERROR
6095     if(H5Sselect_hyperslab(srcspace[1], H5S_SELECT_SET, start, NULL, count, NULL) < 0)
6096         TEST_ERROR
6097 
6098     /* Select hyperslabs in virtual spaces */
6099     start[1] = 10;
6100     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, NULL, count, NULL) < 0)
6101         TEST_ERROR
6102     start[0] = 5;
6103     start[1] = 0;
6104     if(H5Sselect_hyperslab(vspace[1], H5S_SELECT_SET, start, NULL, count, NULL) < 0)
6105         TEST_ERROR
6106 
6107     /* Add virtual layout mappings */
6108     if(H5Pset_virtual(dcpl, vspace[0], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset1", srcspace[0]) < 0)
6109         TEST_ERROR
6110     if(H5Pset_virtual(dcpl, vspace[1], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset2", srcspace[1]) < 0)
6111         TEST_ERROR
6112 
6113     /* Create virtual file */
6114     if((vfile = H5Fcreate(vfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
6115         TEST_ERROR
6116 
6117     /* Create source file if requested */
6118     if(config & TEST_IO_DIFFERENT_FILE) {
6119         if((srcfile[0] = H5Fcreate(srcfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
6120             TEST_ERROR
6121     }
6122     else {
6123         srcfile[0] = vfile;
6124         if(H5Iinc_ref(srcfile[0]) < 0)
6125             TEST_ERROR
6126     }
6127 
6128     /* Create source datasets */
6129     if((srcdset[0] = H5Dcreate2(srcfile[0], "src_dset1", H5T_NATIVE_INT, srcspace[0], H5P_DEFAULT, srcdcpl, H5P_DEFAULT)) < 0)
6130         TEST_ERROR
6131     if((srcdset[1] = H5Dcreate2(srcfile[0], "src_dset2", H5T_NATIVE_INT, srcspace[1], H5P_DEFAULT, srcdcpl, H5P_DEFAULT)) < 0)
6132         TEST_ERROR
6133 
6134     /* Create virtual dataset */
6135     if((vdset = H5Dcreate2(vfile, "v_dset", H5T_NATIVE_INT, vspace[0], H5P_DEFAULT, dcpl, dapl)) < 0)
6136         TEST_ERROR
6137 
6138     /* Populate write buffer */
6139     for(i = 0; i < (int)mdims[0]; i++)
6140         for(j = 0; j < (int)mdims[1]; j++)
6141             buf[i][j] = (i * (int)mdims[1]) + j;
6142 
6143     /* Initialize erbuf */
6144     for(i = 0; i < (int)mdims[0]; i++)
6145         for(j = 0; j < (int)mdims[1]; j++)
6146             erbuf[i][j] = fill;
6147 
6148     /* Write data directly to second source dataset */
6149     /* Select hyperslab in memory */
6150     start[0] = 0;
6151     start[1] = 0;
6152     count[0] = 5;
6153     count[1] = 5;
6154     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
6155         TEST_ERROR
6156 
6157     /* Write second dataset */
6158     if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
6159         TEST_ERROR
6160 
6161     /* Update erbuf */
6162     for(i = 0; i < 5; i++)
6163         for(j = 0; j < 5; j++)
6164             erbuf[i + 5][j] = buf[i][j];
6165 
6166     /* Close srcdsets and srcfile if config option specified */
6167     if(config & TEST_IO_CLOSE_SRC) {
6168         if(H5Dclose(srcdset[0]) < 0)
6169             TEST_ERROR
6170         srcdset[0] = -1;
6171         if(H5Dclose(srcdset[1]) < 0)
6172             TEST_ERROR
6173         srcdset[1] = -1;
6174 
6175         if(config & TEST_IO_DIFFERENT_FILE) {
6176             if(H5Fclose(srcfile[0]) < 0)
6177                 TEST_ERROR
6178             srcfile[0] = -1;
6179         }
6180     }
6181 
6182     /* Reopen virtual dataset and file if config option specified */
6183     if(config & TEST_IO_REOPEN_VIRT) {
6184         if(H5Dclose(vdset) < 0)
6185             TEST_ERROR
6186         vdset = -1;
6187         if(H5Fclose(vfile) < 0)
6188             TEST_ERROR
6189         vfile = -1;
6190         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
6191             TEST_ERROR
6192         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
6193             TEST_ERROR
6194     }
6195 
6196     /* Get VDS space */
6197     if((filespace = H5Dget_space(vdset)) < 0)
6198         TEST_ERROR
6199 
6200     /* Get VDS space dimensions */
6201     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
6202         TEST_ERROR
6203     if(ndims != 2)
6204         TEST_ERROR
6205     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
6206         TEST_ERROR
6207     if(dims[0] != 10)
6208         TEST_ERROR
6209     if(dims[1] != 5)
6210         TEST_ERROR
6211     if(mdims[0] != 10)
6212         TEST_ERROR
6213     if(mdims[1] != 20)
6214         TEST_ERROR
6215 
6216     /* Close filespace */
6217     if(H5Sclose(filespace) < 0)
6218         TEST_ERROR
6219 
6220     /* Read data through virtual dataset */
6221     /* Reset rbuf */
6222     HDmemset(rbuf[0], 0, sizeof(rbuf));
6223 
6224     /* Select hyperslab in memory space */
6225     start[0] = 0;
6226     start[1] = 0;
6227     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
6228         TEST_ERROR
6229 
6230     /* Read data */
6231     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
6232         TEST_ERROR
6233 
6234     /* Verify read data */
6235     for(i = 0; i < (int)mdims[0]; i++)
6236         for(j = 0; j < (int)mdims[1]; j++) {
6237             if(j >= (int)dims[1]) {
6238                 if(rbuf[i][j] != 0)
6239                     TEST_ERROR
6240             }
6241             else
6242                 if(rbuf[i][j] != erbuf[i][j])
6243                     TEST_ERROR
6244         }
6245 
6246     /* Close VDS and reopen with view set to H5D_VDS_FIRST_MISSING, reopen file
6247      * as well if config option specified */
6248     if(H5Dclose(vdset) < 0)
6249         TEST_ERROR
6250     if(H5Pset_virtual_view(dapl, H5D_VDS_FIRST_MISSING) < 0)
6251         TEST_ERROR
6252     if(config & TEST_IO_REOPEN_VIRT) {
6253         if(H5Fclose(vfile) < 0)
6254             TEST_ERROR
6255         vfile = -1;
6256         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
6257             TEST_ERROR
6258     }
6259     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
6260         TEST_ERROR
6261 
6262     /* Get VDS space */
6263     if((filespace = H5Dget_space(vdset)) < 0)
6264         TEST_ERROR
6265 
6266     /* Get VDS space dimensions */
6267     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
6268         TEST_ERROR
6269     if(ndims != 2)
6270         TEST_ERROR
6271     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
6272         TEST_ERROR
6273     if(dims[0] != 10)
6274         TEST_ERROR
6275     if(dims[1] != 5)
6276         TEST_ERROR
6277     if(mdims[0] != 10)
6278         TEST_ERROR
6279     if(mdims[1] != 20)
6280         TEST_ERROR
6281 
6282     /* Close filespace */
6283     if(H5Sclose(filespace) < 0)
6284         TEST_ERROR
6285 
6286     /* Read data through virtual dataset */
6287     /* Reset rbuf */
6288     HDmemset(rbuf[0], 0, sizeof(rbuf));
6289 
6290     /* Read data */
6291     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
6292         TEST_ERROR
6293 
6294     /* Verify read data */
6295     for(i = 0; i < (int)mdims[0]; i++)
6296         for(j = 0; j < (int)mdims[1]; j++) {
6297             if(j >= (int)dims[1]) {
6298                 if(rbuf[i][j] != 0)
6299                     TEST_ERROR
6300             }
6301             else
6302                 if(rbuf[i][j] != erbuf[i][j])
6303                     TEST_ERROR
6304         }
6305 
6306     /* Reopen srcdset[0] and srcfile if config option specified */
6307     if(config & TEST_IO_CLOSE_SRC) {
6308         if(config & TEST_IO_DIFFERENT_FILE)
6309             if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
6310                 TEST_ERROR
6311         if((srcdset[0] = H5Dopen2(srcfile[0], "src_dset1", H5P_DEFAULT)) < 0)
6312             TEST_ERROR
6313     }
6314 
6315     /* Extend srcdset[0] */
6316     dims[0] = 5;
6317     dims[1] = 5;
6318     if(H5Dset_extent(srcdset[0], dims) < 0)
6319         TEST_ERROR
6320 
6321     /* Adjust write buffer */
6322     for(i = 0; i < (int)mdims[0]; i++)
6323         for(j = 0; j < (int)mdims[1]; j++)
6324             buf[i][j] += (int)mdims[0] * (int)mdims[1];
6325 
6326     /* Write to srcdset[0] */
6327     start[0] = 0;
6328     start[1] = 0;
6329     count[0] = 5;
6330     count[1] = 5;
6331     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
6332         TEST_ERROR
6333     if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
6334         TEST_ERROR
6335 
6336     /* Update erbuf */
6337     for(i = 0; i < 5; i++)
6338         for(j = 0; j < 5; j++)
6339             erbuf[i][j + 10] = buf[i][j];
6340 
6341     /* Close srcdset[0] and srcfile if config option specified */
6342     if(config & TEST_IO_CLOSE_SRC) {
6343         if(H5Dclose(srcdset[0]) < 0)
6344             TEST_ERROR
6345         srcdset[0] = -1;
6346 
6347         if(config & TEST_IO_DIFFERENT_FILE) {
6348             if(H5Fclose(srcfile[0]) < 0)
6349                 TEST_ERROR
6350             srcfile[0] = -1;
6351         }
6352     }
6353 
6354     /* Reopen virtual dataset and file if config option specified */
6355     if(config & TEST_IO_REOPEN_VIRT) {
6356         if(H5Dclose(vdset) < 0)
6357             TEST_ERROR
6358         vdset = -1;
6359         if(H5Fclose(vfile) < 0)
6360             TEST_ERROR
6361         vfile = -1;
6362         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
6363             TEST_ERROR
6364         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
6365             TEST_ERROR
6366     }
6367 
6368     /* Get VDS space */
6369     if((filespace = H5Dget_space(vdset)) < 0)
6370         TEST_ERROR
6371 
6372     /* Get VDS space dimensions */
6373     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
6374         TEST_ERROR
6375     if(ndims != 2)
6376         TEST_ERROR
6377     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
6378         TEST_ERROR
6379     if(dims[0] != 10)
6380         TEST_ERROR
6381     if(dims[1] != 5)
6382         TEST_ERROR
6383     if(mdims[0] != 10)
6384         TEST_ERROR
6385     if(mdims[1] != 20)
6386         TEST_ERROR
6387 
6388     /* Close filespace */
6389     if(H5Sclose(filespace) < 0)
6390         TEST_ERROR
6391 
6392     /* Read data through virtual dataset */
6393     /* Reset rbuf */
6394     HDmemset(rbuf[0], 0, sizeof(rbuf));
6395 
6396     /* Select hyperslab in memory space */
6397     start[0] = 0;
6398     start[1] = 0;
6399     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
6400         TEST_ERROR
6401 
6402     /* Read data */
6403     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
6404         TEST_ERROR
6405 
6406     /* Verify read data */
6407     for(i = 0; i < (int)mdims[0]; i++)
6408         for(j = 0; j < (int)mdims[1]; j++) {
6409             if(j >= (int)dims[1]) {
6410                 if(rbuf[i][j] != 0)
6411                     TEST_ERROR
6412             }
6413             else
6414                 if(rbuf[i][j] != erbuf[i][j])
6415                     TEST_ERROR
6416         }
6417 
6418     /* Close VDS and reopen with view set to H5D_VDS_LAST_AVAILABLE, reopen file
6419      * as well if config option specified */
6420     if(H5Dclose(vdset) < 0)
6421         TEST_ERROR
6422     if(H5Pset_virtual_view(dapl, H5D_VDS_LAST_AVAILABLE) < 0)
6423         TEST_ERROR
6424     if(config & TEST_IO_REOPEN_VIRT) {
6425         if(H5Fclose(vfile) < 0)
6426             TEST_ERROR
6427         vfile = -1;
6428         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
6429             TEST_ERROR
6430     }
6431     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
6432         TEST_ERROR
6433 
6434     /* Get VDS space */
6435     if((filespace = H5Dget_space(vdset)) < 0)
6436         TEST_ERROR
6437 
6438     /* Get VDS space dimensions */
6439     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
6440         TEST_ERROR
6441     if(ndims != 2)
6442         TEST_ERROR
6443     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
6444         TEST_ERROR
6445     if(dims[0] != 10)
6446         TEST_ERROR
6447     if(dims[1] != 15)
6448         TEST_ERROR
6449     if(mdims[0] != 10)
6450         TEST_ERROR
6451     if(mdims[1] != 20)
6452         TEST_ERROR
6453 
6454     /* Close filespace */
6455     if(H5Sclose(filespace) < 0)
6456         TEST_ERROR
6457 
6458     /* Read data through virtual dataset */
6459     /* Reset rbuf */
6460     HDmemset(rbuf[0], 0, sizeof(rbuf));
6461 
6462     /* Select hyperslab in memory space */
6463     start[0] = 0;
6464     start[1] = 0;
6465     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
6466         TEST_ERROR
6467 
6468     /* Read data */
6469     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
6470         TEST_ERROR
6471 
6472     /* Verify read data */
6473     for(i = 0; i < (int)mdims[0]; i++)
6474         for(j = 0; j < (int)mdims[1]; j++) {
6475             if(j >= (int)dims[1]) {
6476                 if(rbuf[i][j] != 0)
6477                     TEST_ERROR
6478             }
6479             else
6480                 if(rbuf[i][j] != erbuf[i][j])
6481                     TEST_ERROR
6482         }
6483 
6484     /* Close */
6485     if(!(config & TEST_IO_CLOSE_SRC)) {
6486         if(H5Dclose(srcdset[0]) < 0)
6487             TEST_ERROR
6488         srcdset[0] = -1;
6489         if(H5Dclose(srcdset[1]) < 0)
6490             TEST_ERROR
6491         srcdset[1] = -1;
6492         if(H5Fclose(srcfile[0]) < 0)
6493             TEST_ERROR
6494         srcfile[0] = -1;
6495     }
6496     else if(!(config & TEST_IO_DIFFERENT_FILE)) {
6497         if(H5Fclose(srcfile[0]) < 0)
6498             TEST_ERROR
6499         srcfile[0] = -1;
6500     }
6501     if(H5Dclose(vdset) < 0)
6502         TEST_ERROR
6503     vdset = -1;
6504     if(H5Fclose(vfile) < 0)
6505         TEST_ERROR
6506     vfile = -1;
6507     if(H5Sclose(srcspace[0]) < 0)
6508         TEST_ERROR
6509     srcspace[0] = -1;
6510     if(H5Sclose(srcspace[1]) < 0)
6511         TEST_ERROR
6512     srcspace[1] = -1;
6513     if(H5Sclose(vspace[0]) < 0)
6514         TEST_ERROR
6515     vspace[0] = -1;
6516     if(H5Sclose(vspace[1]) < 0)
6517         TEST_ERROR
6518     vspace[1] = -1;
6519 
6520 
6521     /* Close */
6522     if(H5Pclose(dcpl) < 0)
6523         TEST_ERROR
6524     dcpl = -1;
6525     if(H5Pclose(srcdcpl) < 0)
6526         TEST_ERROR
6527     dcpl = -1;
6528     if(H5Pclose(dapl) < 0)
6529         TEST_ERROR
6530     dapl = -1;
6531     if(H5Sclose(memspace) < 0)
6532         TEST_ERROR
6533     memspace = -1;
6534 
6535     PASSED();
6536     return 0;
6537 
6538 error:
6539     H5E_BEGIN_TRY {
6540         for(i = 0; i < (int)(sizeof(srcdset) / sizeof(srcdset[0])); i++)
6541             H5Dclose(srcdset[i]);
6542         H5Dclose(vdset);
6543         for(i = 0; i < (int)(sizeof(srcfile) / sizeof(srcfile[0])); i++)
6544             H5Fclose(srcfile[i]);
6545         H5Fclose(vfile);
6546         for(i = 0; i < (int)(sizeof(srcspace) / sizeof(srcspace[0])); i++)
6547             H5Sclose(srcspace[i]);
6548         for(i = 0; i < (int)(sizeof(vspace) / sizeof(vspace[0])); i++)
6549             H5Sclose(vspace[i]);
6550         H5Sclose(filespace);
6551         H5Sclose(memspace);
6552         H5Pclose(dcpl);
6553         H5Pclose(srcdcpl);
6554         H5Pclose(dapl);
6555     } H5E_END_TRY;
6556 
6557      return 1;
6558 } /* end test_unlim() */
6559 
6560 
6561 /*-------------------------------------------------------------------------
6562  * Function:    test_printf
6563  *
6564  * Purpose:     Tests VDS with unlimited selections and printf style
6565  *              source dataset resolution
6566  *
6567  * Return:      Success:        0
6568  *              Failure:        number of errors
6569  *-------------------------------------------------------------------------
6570  */
6571 static int
test_printf(unsigned config,hid_t fapl)6572 test_printf(unsigned config, hid_t fapl)
6573 {
6574     char        srcfilename[FILENAME_BUF_SIZE];
6575     char        srcfilename_map[FILENAME_BUF_SIZE];
6576     char        srcfilename2[FILENAME_BUF_SIZE];
6577     char        srcfilename2_map[FILENAME_BUF_SIZE];
6578     char        vfilename[FILENAME_BUF_SIZE];
6579     char        printf_srcfilename_map[FILENAME_BUF_SIZE];
6580     const char *printf_srcfilename_map_orig = "vds_src_%b";
6581     char        srcfilenamepct[FILENAME_BUF_SIZE];
6582     char        srcfilenamepct_map[FILENAME_BUF_SIZE];
6583     const char *srcfilenamepct_map_orig = "vds%%%%_src";
6584     hid_t       srcfile[4] = {-1, -1, -1, -1}; /* Files with source dsets */
6585     hid_t       vfile = -1;     /* File with virtual dset */
6586     hid_t       dcpl = -1;      /* Dataset creation property list */
6587     hid_t       dapl = -1;      /* Dataset access property list */
6588     hid_t       srcspace = -1;  /* Source dataspace */
6589     hid_t       vspace[2] = {-1, -1}; /* Virtual dset dataspaces */
6590     hid_t       memspace = -1;  /* Memory dataspace */
6591     hid_t       filespace = -1; /* File dataspace */
6592     hid_t       srcdset[6] = {-1, -1, -1, -1, -1, -1}; /* Source datsets */
6593     hid_t       vdset = -1;     /* Virtual dataset */
6594     hsize_t     dims[2] = {10, 0}; /* Data space current size */
6595     hsize_t     mdims[2] = {10, 20}; /* Data space maximum size */
6596     hsize_t     start[2] = {0, 0}; /* Hyperslab start */
6597     hsize_t     stride[2];      /* Hyperslab stride */
6598     hsize_t     count[2];       /* Hyperslab count */
6599     hsize_t     block[2];       /* Hyperslab block */
6600     int         buf[10][20];    /* Write and expected read buffer */
6601     int         rbuf[10][20];   /* Read buffer */
6602     int         erbuf[10][20];  /* Expected read buffer */
6603     int         ndims;          /* Number of dimensions */
6604     int         fill = -1;      /* Fill value */
6605     hsize_t     gap_size;       /* Gap size property */
6606     int         i, j;
6607 
6608     TESTING("virtual dataset I/O with printf source")
6609 
6610     h5_fixname(FILENAME[0], fapl, vfilename, sizeof vfilename);
6611     h5_fixname(FILENAME[2], fapl, srcfilename, sizeof srcfilename);
6612     h5_fixname_printf(FILENAME[2], fapl, srcfilename_map, sizeof srcfilename_map);
6613     h5_fixname(FILENAME[3], fapl, srcfilename2, sizeof srcfilename2);
6614     h5_fixname_printf(FILENAME[2], fapl, srcfilename2_map, sizeof srcfilename2_map);
6615     h5_fixname_printf(printf_srcfilename_map_orig, fapl, printf_srcfilename_map, sizeof printf_srcfilename_map);
6616     h5_fixname(FILENAME[4], fapl, srcfilenamepct, sizeof srcfilenamepct);
6617     h5_fixname_printf(srcfilenamepct_map_orig, fapl, srcfilenamepct_map, sizeof srcfilenamepct_map);
6618 
6619     /* Create DCPL */
6620     if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
6621         TEST_ERROR
6622 
6623     /* Set fill value */
6624     if(H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fill) < 0)
6625         TEST_ERROR
6626 
6627     /* Create DAPL */
6628     if((dapl = H5Pcreate(H5P_DATASET_ACCESS)) < 0)
6629         TEST_ERROR
6630 
6631     /* Create memory space */
6632     if((memspace = H5Screate_simple(2, mdims, NULL)) < 0)
6633         TEST_ERROR
6634 
6635 
6636     /*
6637      * Test 1: 1 Source dataset mapping, 10x5 blocks
6638      */
6639     /* Clear virtual layout in DCPL */
6640     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
6641         TEST_ERROR
6642 
6643     /* Create virtual dataspace */
6644     if((vspace[0] = H5Screate_simple(2, dims, mdims)) < 0)
6645         TEST_ERROR
6646 
6647     /* Create source dataspace */
6648     dims[1] = 5;
6649     if((srcspace = H5Screate_simple(2, dims, NULL)) < 0)
6650         TEST_ERROR
6651 
6652     /* Select hyperslabs in virtual space */
6653     stride[0] = 1;
6654     stride[1] = 5;
6655     count[0] = 1;
6656     count[1] = H5S_UNLIMITED;
6657     block[0] = 10;
6658     block[1] = 5;
6659     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, stride, count, block) < 0)
6660         TEST_ERROR
6661 
6662     /* Add virtual layout mapping */
6663     if(H5Pset_virtual(dcpl, vspace[0], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset%b", srcspace) < 0)
6664         TEST_ERROR
6665 
6666     /* Create virtual file */
6667     if((vfile = H5Fcreate(vfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
6668         TEST_ERROR
6669 
6670     /* Create source file if requested */
6671     if(config & TEST_IO_DIFFERENT_FILE) {
6672         if((srcfile[0] = H5Fcreate(srcfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
6673             TEST_ERROR
6674     }
6675     else {
6676         srcfile[0] = vfile;
6677         if(H5Iinc_ref(srcfile[0]) < 0)
6678             TEST_ERROR
6679     }
6680 
6681     /* Create virtual dataset */
6682     if((vdset = H5Dcreate2(vfile, "v_dset", H5T_NATIVE_INT, vspace[0], H5P_DEFAULT, dcpl, dapl)) < 0)
6683         TEST_ERROR
6684 
6685     /* Close srcfile if config option specified */
6686     if(config & TEST_IO_CLOSE_SRC)
6687         if(config & TEST_IO_DIFFERENT_FILE) {
6688             if(H5Fclose(srcfile[0]) < 0)
6689                 TEST_ERROR
6690             srcfile[0] = -1;
6691         }
6692 
6693     /* Reopen virtual dataset and file if config option specified */
6694     if(config & TEST_IO_REOPEN_VIRT) {
6695         if(H5Dclose(vdset) < 0)
6696             TEST_ERROR
6697         vdset = -1;
6698         if(H5Fclose(vfile) < 0)
6699             TEST_ERROR
6700         vfile = -1;
6701         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
6702             TEST_ERROR
6703         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
6704             TEST_ERROR
6705     }
6706 
6707     /* Get VDS space */
6708     if((filespace = H5Dget_space(vdset)) < 0)
6709         TEST_ERROR
6710 
6711     /* Get VDS space dimensions */
6712     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
6713         TEST_ERROR
6714     if(ndims != 2)
6715         TEST_ERROR
6716     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
6717         TEST_ERROR
6718     if(dims[0] != 10)
6719         TEST_ERROR
6720     if(dims[1] != 0)
6721         TEST_ERROR
6722     if(mdims[0] != 10)
6723         TEST_ERROR
6724     if(mdims[1] != 20)
6725         TEST_ERROR
6726 
6727     /* Close filespace */
6728     if(H5Sclose(filespace) < 0)
6729         TEST_ERROR
6730 
6731     /* Reopen srcfile if config option specified */
6732     if(config & TEST_IO_CLOSE_SRC)
6733         if(config & TEST_IO_DIFFERENT_FILE)
6734             if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
6735                 TEST_ERROR
6736 
6737     /* Create 2 source datasets */
6738     if((srcdset[0] = H5Dcreate2(srcfile[0], "src_dset0", H5T_NATIVE_INT, srcspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
6739         TEST_ERROR
6740     if((srcdset[1] = H5Dcreate2(srcfile[0], "src_dset1", H5T_NATIVE_INT, srcspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
6741         TEST_ERROR
6742 
6743     /* Populate write buffer */
6744     for(i = 0; i < (int)mdims[0]; i++)
6745         for(j = 0; j < (int)mdims[1]; j++)
6746             buf[i][j] = (i * (int)mdims[1]) + j;
6747 
6748     /* Initialize erbuf */
6749     for(i = 0; i < (int)mdims[0]; i++)
6750         for(j = 0; j < (int)mdims[1]; j++)
6751             erbuf[i][j] = fill;
6752 
6753     /* Write to srcdset[0] */
6754     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
6755         TEST_ERROR
6756     if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
6757         TEST_ERROR
6758 
6759     /* Update erbuf */
6760     for(i = 0; i < 10; i++)
6761         for(j = 0; j < 5; j++)
6762             erbuf[i][j] = buf[i][j];
6763 
6764     /* Adjust write buffer */
6765     for(i = 0; i < (int)mdims[0]; i++)
6766         for(j = 0; j < (int)mdims[1]; j++)
6767             buf[i][j] += (int)mdims[0] * (int)mdims[1];
6768 
6769     /* Write to srcdset[1] */
6770     if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
6771         TEST_ERROR
6772 
6773     /* Update erbuf */
6774     for(i = 0; i < 10; i++)
6775         for(j = 0; j < 5; j++)
6776             erbuf[i][j + 5] = buf[i][j];
6777 
6778     /* Close srcdsets and srcfile if config option specified */
6779     if(config & TEST_IO_CLOSE_SRC) {
6780         if(H5Dclose(srcdset[0]) < 0)
6781             TEST_ERROR
6782         srcdset[0] = -1;
6783         if(H5Dclose(srcdset[1]) < 0)
6784             TEST_ERROR
6785         srcdset[1] = -1;
6786 
6787         if(config & TEST_IO_DIFFERENT_FILE) {
6788             if(H5Fclose(srcfile[0]) < 0)
6789                 TEST_ERROR
6790             srcfile[0] = -1;
6791         }
6792     }
6793 
6794     /* Reopen virtual dataset and file if config option specified */
6795     if(config & TEST_IO_REOPEN_VIRT) {
6796         if(H5Dclose(vdset) < 0)
6797             TEST_ERROR
6798         vdset = -1;
6799         if(H5Fclose(vfile) < 0)
6800             TEST_ERROR
6801         vfile = -1;
6802         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
6803             TEST_ERROR
6804         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
6805             TEST_ERROR
6806     }
6807 
6808     /* Get VDS space */
6809     if((filespace = H5Dget_space(vdset)) < 0)
6810         TEST_ERROR
6811 
6812     /* Get VDS space dimensions */
6813     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
6814         TEST_ERROR
6815     if(ndims != 2)
6816         TEST_ERROR
6817     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
6818         TEST_ERROR
6819     if(dims[0] != 10)
6820         TEST_ERROR
6821     if(dims[1] != 10)
6822         TEST_ERROR
6823     if(mdims[0] != 10)
6824         TEST_ERROR
6825     if(mdims[1] != 20)
6826         TEST_ERROR
6827 
6828     /* Close filespace */
6829     if(H5Sclose(filespace) < 0)
6830         TEST_ERROR
6831 
6832     /* Read data through virtual dataset */
6833     /* Reset rbuf */
6834     HDmemset(rbuf[0], 0, sizeof(rbuf));
6835 
6836     /* Select hyperslab in memory space */
6837     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
6838         TEST_ERROR
6839 
6840     /* Read data */
6841     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
6842         TEST_ERROR
6843 
6844     /* Verify read data */
6845     for(i = 0; i < (int)mdims[0]; i++)
6846         for(j = 0; j < (int)mdims[1]; j++) {
6847             if(j >= (int)dims[1]) {
6848                 if(rbuf[i][j] != 0)
6849                     TEST_ERROR
6850             }
6851             else
6852                 if(rbuf[i][j] != erbuf[i][j])
6853                     TEST_ERROR
6854         }
6855 
6856     /* Reopen srcfile if config option specified */
6857     if((config & TEST_IO_CLOSE_SRC) && (config & TEST_IO_DIFFERENT_FILE))
6858         if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
6859             TEST_ERROR
6860 
6861     /* Create 3rd source dataset */
6862     if((srcdset[2] = H5Dcreate2(srcfile[0], "src_dset2", H5T_NATIVE_INT, srcspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
6863         TEST_ERROR
6864 
6865     /* Adjust write buffer */
6866     for(i = 0; i < (int)mdims[0]; i++)
6867         for(j = 0; j < (int)mdims[1]; j++)
6868             buf[i][j] += (int)mdims[0] * (int)mdims[1];
6869 
6870     /* Write to srcdset[2] */
6871     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
6872         TEST_ERROR
6873     if(H5Dwrite(srcdset[2], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
6874         TEST_ERROR
6875 
6876     /* Update erbuf */
6877     for(i = 0; i < 10; i++)
6878         for(j = 0; j < 5; j++)
6879             erbuf[i][j + 10] = buf[i][j];
6880 
6881     /* Close srcdset[2] and srcfile if config option specified */
6882     if(config & TEST_IO_CLOSE_SRC) {
6883         if(H5Dclose(srcdset[2]) < 0)
6884             TEST_ERROR
6885         srcdset[2] = -1;
6886 
6887         if(config & TEST_IO_DIFFERENT_FILE) {
6888             if(H5Fclose(srcfile[0]) < 0)
6889                 TEST_ERROR
6890             srcfile[0] = -1;
6891         }
6892     }
6893 
6894     /* Reopen virtual dataset and file if config option specified */
6895     if(config & TEST_IO_REOPEN_VIRT) {
6896         if(H5Dclose(vdset) < 0)
6897             TEST_ERROR
6898         vdset = -1;
6899         if(H5Fclose(vfile) < 0)
6900             TEST_ERROR
6901         vfile = -1;
6902         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
6903             TEST_ERROR
6904         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
6905             TEST_ERROR
6906     }
6907 
6908     /* Get VDS space */
6909     if((filespace = H5Dget_space(vdset)) < 0)
6910         TEST_ERROR
6911 
6912     /* Get VDS space dimensions */
6913     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
6914         TEST_ERROR
6915     if(ndims != 2)
6916         TEST_ERROR
6917     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
6918         TEST_ERROR
6919     if(dims[0] != 10)
6920         TEST_ERROR
6921     if(dims[1] != 15)
6922         TEST_ERROR
6923     if(mdims[0] != 10)
6924         TEST_ERROR
6925     if(mdims[1] != 20)
6926         TEST_ERROR
6927 
6928     /* Read data through virtual dataset */
6929     /* Reset rbuf */
6930     HDmemset(rbuf[0], 0, sizeof(rbuf));
6931 
6932     /* Select hyperslab in memory space */
6933     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
6934         TEST_ERROR
6935 
6936     /* Read data */
6937     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
6938         TEST_ERROR
6939 
6940     /* Verify read data */
6941     for(i = 0; i < (int)mdims[0]; i++)
6942         for(j = 0; j < (int)mdims[1]; j++) {
6943             if(j >= (int)dims[1]) {
6944                 if(rbuf[i][j] != 0)
6945                     TEST_ERROR
6946             }
6947             else
6948                 if(rbuf[i][j] != erbuf[i][j])
6949                     TEST_ERROR
6950         }
6951 
6952     /* Now try with different selections */
6953     count[0] = 10;
6954     for(start[1] = (hsize_t)0; start[1] < (hsize_t)5; start[1]++)
6955         for(count[1] = (hsize_t)1; count[1] < (hsize_t)11; count[1]++) {
6956             /* Reset rbuf */
6957             HDmemset(rbuf[0], 0, sizeof(rbuf));
6958 
6959             /* Select hyperslab in memory space */
6960             if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
6961                 TEST_ERROR
6962 
6963             /* Select hyperslab in file space */
6964             if(H5Sselect_hyperslab(filespace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
6965                 TEST_ERROR
6966 
6967             /* Read data */
6968             if(H5Dread(vdset, H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT, rbuf[0]) < 0)
6969                 TEST_ERROR
6970 
6971             /* Verify read data */
6972             for(i = 0; i < (int)mdims[0]; i++)
6973                 for(j = 0; j < (int)mdims[1]; j++) {
6974                     if((j < (int)start[1]) || (j >= (int)(start[1] + count[1]))) {
6975                         if(rbuf[i][j] != 0)
6976                             TEST_ERROR
6977                     }
6978                     else
6979                         if(rbuf[i][j] != erbuf[i][j])
6980                             TEST_ERROR
6981                 }
6982         }
6983     start[1] = 0;
6984 
6985     /* Now try writing through VDS */
6986     /* Select hyperslab in memory space */
6987     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
6988         TEST_ERROR
6989 
6990     /* Select hyperslab in file space */
6991     if(H5Sselect_hyperslab(filespace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
6992         TEST_ERROR
6993 
6994     /* Adjust write buffer */
6995     for(i = 0; i < (int)mdims[0]; i++)
6996         for(j = 0; j < (int)mdims[1]; j++)
6997             buf[i][j] += (int)mdims[0] * (int)mdims[1];
6998 
6999     /* Write data through VDS */
7000     if(H5Dwrite(vdset, H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT, buf[0]) < 0)
7001         TEST_ERROR
7002 
7003     /* Close filespace */
7004     if(H5Sclose(filespace) < 0)
7005         TEST_ERROR
7006 
7007     /* Reopen srcdsets and srcfile if config option specified */
7008     if(config & TEST_IO_CLOSE_SRC) {
7009         if(config & TEST_IO_DIFFERENT_FILE)
7010             if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
7011                 TEST_ERROR
7012         if((srcdset[0] = H5Dopen2(srcfile[0], "src_dset0", H5P_DEFAULT)) < 0)
7013             TEST_ERROR
7014         if((srcdset[1] = H5Dopen2(srcfile[0], "src_dset1", H5P_DEFAULT)) < 0)
7015             TEST_ERROR
7016         if((srcdset[2] = H5Dopen2(srcfile[0], "src_dset2", H5P_DEFAULT)) < 0)
7017             TEST_ERROR
7018     }
7019 
7020     /* Read srcdset[0] */
7021     count[0] = 10;
7022     count[1] = 5;
7023     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
7024         TEST_ERROR
7025     if(H5Dread(srcdset[0], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
7026         TEST_ERROR
7027 
7028     /* Verify read data */
7029     for(i = 0; i < 10; i++)
7030         for(j = 0; j < 5; j++)
7031             if(rbuf[i][j] != buf[i][j])
7032                 TEST_ERROR
7033 
7034     /* Read srcdset[1] */
7035     if(H5Dread(srcdset[1], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
7036         TEST_ERROR
7037 
7038     /* Verify read data */
7039     for(i = 0; i < 10; i++)
7040         for(j = 0; j < 5; j++)
7041             if(rbuf[i][j] != buf[i][j + 5])
7042                 TEST_ERROR
7043 
7044     /* Read srcdset[2] */
7045     if(H5Dread(srcdset[2], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
7046         TEST_ERROR
7047 
7048     /* Verify read data */
7049     for(i = 0; i < 10; i++)
7050         for(j = 0; j < 5; j++)
7051             if(rbuf[i][j] != buf[i][j + 10])
7052                 TEST_ERROR
7053 
7054     /* Close */
7055     if(H5Dclose(srcdset[0]) < 0)
7056         TEST_ERROR
7057     srcdset[0] = -1;
7058     if(H5Dclose(srcdset[1]) < 0)
7059         TEST_ERROR
7060     srcdset[1] = -1;
7061     if(H5Dclose(srcdset[2]) < 0)
7062         TEST_ERROR
7063     srcdset[2] = -1;
7064     if(H5Fclose(srcfile[0]) < 0)
7065         TEST_ERROR
7066     srcfile[0] = -1;
7067     if(H5Dclose(vdset) < 0)
7068         TEST_ERROR
7069     vdset = -1;
7070     if(H5Fclose(vfile) < 0)
7071         TEST_ERROR
7072     vfile = -1;
7073     if(H5Sclose(srcspace) < 0)
7074         TEST_ERROR
7075     srcspace = -1;
7076     if(H5Sclose(vspace[0]) < 0)
7077         TEST_ERROR
7078     vspace[0] = -1;
7079 
7080 
7081     /*
7082      * Test 2: 1 Source dataset mapping, 10x1 blocks, test printf gap setting,
7083      * '%' in source file name
7084      */
7085     /* Clear virtual layout in DCPL */
7086     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
7087         TEST_ERROR
7088 
7089     /* Create virtual dataspaces */
7090     if((vspace[0] = H5Screate_simple(2, dims, mdims)) < 0)
7091         TEST_ERROR
7092 
7093     /* Create source dataspace */
7094     dims[1] = 1;
7095     if((srcspace = H5Screate_simple(2, dims, NULL)) < 0)
7096         TEST_ERROR
7097 
7098     /* Select hyperslabs in virtual space */
7099     stride[0] = 1;
7100     stride[1] = 1;
7101     count[0] = 1;
7102     count[1] = H5S_UNLIMITED;
7103     block[0] = 10;
7104     block[1] = 1;
7105     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, stride, count, block) < 0)
7106         TEST_ERROR
7107 
7108     /* Add virtual layout mapping */
7109     if(H5Pset_virtual(dcpl, vspace[0], config & TEST_IO_DIFFERENT_FILE ? srcfilenamepct_map : ".", "src_dset%b", srcspace) < 0)
7110         TEST_ERROR
7111 
7112     /* Create virtual file */
7113     if((vfile = H5Fcreate(vfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
7114         TEST_ERROR
7115 
7116     /* Create source file if requested */
7117     if(config & TEST_IO_DIFFERENT_FILE) {
7118         if((srcfile[0] = H5Fcreate(srcfilenamepct, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
7119             TEST_ERROR
7120     }
7121     else {
7122         srcfile[0] = vfile;
7123         if(H5Iinc_ref(srcfile[0]) < 0)
7124             TEST_ERROR
7125     }
7126 
7127     /* Create virtual dataset */
7128     if((vdset = H5Dcreate2(vfile, "v_dset", H5T_NATIVE_INT, vspace[0], H5P_DEFAULT, dcpl, dapl)) < 0)
7129         TEST_ERROR
7130 
7131     /* Close srcfile if config option specified */
7132     if(config & TEST_IO_CLOSE_SRC)
7133         if(config & TEST_IO_DIFFERENT_FILE) {
7134             if(H5Fclose(srcfile[0]) < 0)
7135                 TEST_ERROR
7136             srcfile[0] = -1;
7137         }
7138 
7139     /* Reopen virtual dataset and file if config option specified */
7140     if(config & TEST_IO_REOPEN_VIRT) {
7141         if(H5Dclose(vdset) < 0)
7142             TEST_ERROR
7143         vdset = -1;
7144         if(H5Fclose(vfile) < 0)
7145             TEST_ERROR
7146         vfile = -1;
7147         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
7148             TEST_ERROR
7149         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
7150             TEST_ERROR
7151     }
7152 
7153     /* Get VDS space */
7154     if((filespace = H5Dget_space(vdset)) < 0)
7155         TEST_ERROR
7156 
7157     /* Get VDS space dimensions */
7158     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
7159         TEST_ERROR
7160     if(ndims != 2)
7161         TEST_ERROR
7162     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
7163         TEST_ERROR
7164     if(dims[0] != 10)
7165         TEST_ERROR
7166     if(dims[1] != 0)
7167         TEST_ERROR
7168     if(mdims[0] != 10)
7169         TEST_ERROR
7170     if(mdims[1] != 20)
7171         TEST_ERROR
7172 
7173     /* Close filespace */
7174     if(H5Sclose(filespace) < 0)
7175         TEST_ERROR
7176 
7177     /* Reopen srcfile if config option specified */
7178     if(config & TEST_IO_CLOSE_SRC)
7179         if(config & TEST_IO_DIFFERENT_FILE)
7180             if((srcfile[0] = H5Fopen(srcfilenamepct, H5F_ACC_RDWR, fapl)) < 0)
7181                 TEST_ERROR
7182 
7183     /* Create source datasets in a pattern with increasing gaps:
7184      * XX-X--X---X----X */
7185     if((srcdset[0] = H5Dcreate2(srcfile[0], "src_dset0", H5T_NATIVE_INT, srcspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
7186         TEST_ERROR
7187     if((srcdset[1] = H5Dcreate2(srcfile[0], "src_dset1", H5T_NATIVE_INT, srcspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
7188         TEST_ERROR
7189     if((srcdset[2] = H5Dcreate2(srcfile[0], "src_dset3", H5T_NATIVE_INT, srcspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
7190         TEST_ERROR
7191     if((srcdset[3] = H5Dcreate2(srcfile[0], "src_dset6", H5T_NATIVE_INT, srcspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
7192         TEST_ERROR
7193     if((srcdset[4] = H5Dcreate2(srcfile[0], "src_dset10", H5T_NATIVE_INT, srcspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
7194         TEST_ERROR
7195     if((srcdset[5] = H5Dcreate2(srcfile[0], "src_dset15", H5T_NATIVE_INT, srcspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
7196         TEST_ERROR
7197 
7198     /* Populate write buffer */
7199     for(i = 0; i < (int)mdims[0]; i++)
7200         for(j = 0; j < (int)mdims[1]; j++)
7201             buf[i][j] = (i * (int)mdims[1]) + j;
7202 
7203     /* Initialize erbuf */
7204     for(i = 0; i < (int)mdims[0]; i++)
7205         for(j = 0; j < (int)mdims[1]; j++)
7206             erbuf[i][j] = fill;
7207 
7208     /* Write to srcdset[0] */
7209     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
7210         TEST_ERROR
7211     if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
7212         TEST_ERROR
7213 
7214     /* Update erbuf */
7215     for(i = 0; i < 10; i++)
7216         erbuf[i][0] = buf[i][0];
7217 
7218     /* Adjust write buffer */
7219     for(i = 0; i < (int)mdims[0]; i++)
7220         for(j = 0; j < (int)mdims[1]; j++)
7221             buf[i][j] += (int)mdims[0] * (int)mdims[1];
7222 
7223     /* Write to srcdset[1] */
7224     if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
7225         TEST_ERROR
7226 
7227     /* Update erbuf */
7228     for(i = 0; i < 10; i++)
7229         erbuf[i][1] = buf[i][0];
7230 
7231     /* Adjust write buffer */
7232     for(i = 0; i < (int)mdims[0]; i++)
7233         for(j = 0; j < (int)mdims[1]; j++)
7234             buf[i][j] += (int)mdims[0] * (int)mdims[1];
7235 
7236     /* Write to srcdset[2] */
7237     if(H5Dwrite(srcdset[2], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
7238         TEST_ERROR
7239 
7240     /* Update erbuf */
7241     for(i = 0; i < 10; i++)
7242         erbuf[i][3] = buf[i][0];
7243 
7244     /* Adjust write buffer */
7245     for(i = 0; i < (int)mdims[0]; i++)
7246         for(j = 0; j < (int)mdims[1]; j++)
7247             buf[i][j] += (int)mdims[0] * (int)mdims[1];
7248 
7249     /* Write to srcdset[3] */
7250     if(H5Dwrite(srcdset[3], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
7251         TEST_ERROR
7252 
7253     /* Update erbuf */
7254     for(i = 0; i < 10; i++)
7255         erbuf[i][6] = buf[i][0];
7256 
7257     /* Adjust write buffer */
7258     for(i = 0; i < (int)mdims[0]; i++)
7259         for(j = 0; j < (int)mdims[1]; j++)
7260             buf[i][j] += (int)mdims[0] * (int)mdims[1];
7261 
7262     /* Write to srcdset[4] */
7263     if(H5Dwrite(srcdset[4], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
7264         TEST_ERROR
7265 
7266     /* Update erbuf */
7267     for(i = 0; i < 10; i++)
7268         erbuf[i][10] = buf[i][0];
7269 
7270     /* Adjust write buffer */
7271     for(i = 0; i < (int)mdims[0]; i++)
7272         for(j = 0; j < (int)mdims[1]; j++)
7273             buf[i][j] += (int)mdims[0] * (int)mdims[1];
7274 
7275     /* Write to srcdset[5] */
7276     if(H5Dwrite(srcdset[5], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
7277         TEST_ERROR
7278 
7279     /* Update erbuf */
7280     for(i = 0; i < 10; i++)
7281         erbuf[i][15] = buf[i][0];
7282 
7283     /* Close srcdsets and srcfile if config option specified */
7284     if(config & TEST_IO_CLOSE_SRC) {
7285         for(i = 0; i < 6; i++) {
7286             if(H5Dclose(srcdset[i]) < 0)
7287                 TEST_ERROR
7288             srcdset[i] = -1;
7289         }
7290 
7291         if(config & TEST_IO_DIFFERENT_FILE) {
7292             if(H5Fclose(srcfile[0]) < 0)
7293                 TEST_ERROR
7294             srcfile[0] = -1;
7295         }
7296     }
7297 
7298     /* Reopen virtual dataset and file if config option specified */
7299     if(config & TEST_IO_REOPEN_VIRT) {
7300         if(H5Dclose(vdset) < 0)
7301             TEST_ERROR
7302         vdset = -1;
7303         if(H5Fclose(vfile) < 0)
7304             TEST_ERROR
7305         vfile = -1;
7306         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
7307             TEST_ERROR
7308         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
7309             TEST_ERROR
7310     }
7311 
7312     /* Get VDS space */
7313     if((filespace = H5Dget_space(vdset)) < 0)
7314         TEST_ERROR
7315 
7316     /* Get VDS space dimensions */
7317     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
7318         TEST_ERROR
7319     if(ndims != 2)
7320         TEST_ERROR
7321     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
7322         TEST_ERROR
7323     if(dims[0] != 10)
7324         TEST_ERROR
7325     if(dims[1] != 2)
7326         TEST_ERROR
7327     if(mdims[0] != 10)
7328         TEST_ERROR
7329     if(mdims[1] != 20)
7330         TEST_ERROR
7331 
7332     /* Close filespace */
7333     if(H5Sclose(filespace) < 0)
7334         TEST_ERROR
7335 
7336     /* Read data through virtual dataset */
7337     /* Reset rbuf */
7338     HDmemset(rbuf[0], 0, sizeof(rbuf));
7339 
7340     /* Select hyperslab in memory space */
7341     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
7342         TEST_ERROR
7343 
7344     /* Read data */
7345     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
7346         TEST_ERROR
7347 
7348     /* Verify read data */
7349     for(i = 0; i < (int)mdims[0]; i++)
7350         for(j = 0; j < (int)mdims[1]; j++) {
7351             if(j >= (int)dims[1]) {
7352                 if(rbuf[i][j] != 0)
7353                     TEST_ERROR
7354             }
7355             else
7356                 if(rbuf[i][j] != erbuf[i][j])
7357                     TEST_ERROR
7358         }
7359 
7360     /* Test H5Pget_virtual_printf_gap() */
7361     if(H5Pget_virtual_printf_gap(dapl, &gap_size) < 0)
7362         TEST_ERROR
7363     if(gap_size != (hsize_t)0)
7364         TEST_ERROR
7365 
7366     /* Close VDS and reopen with printf gap set to 1, reopen file as well if
7367      * config option specified */
7368     if(H5Dclose(vdset) < 0)
7369         TEST_ERROR
7370     if(H5Pset_virtual_printf_gap(dapl, (hsize_t)1) < 0)
7371         TEST_ERROR
7372     if(config & TEST_IO_REOPEN_VIRT) {
7373         if(H5Fclose(vfile) < 0)
7374             TEST_ERROR
7375         vfile = -1;
7376         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
7377             TEST_ERROR
7378     }
7379     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
7380         TEST_ERROR
7381 
7382     /* Test H5Pget_virtual_printf_gap() */
7383     if(H5Pget_virtual_printf_gap(dapl, &gap_size) < 0)
7384         TEST_ERROR
7385     if(gap_size != (hsize_t)1)
7386         TEST_ERROR
7387 
7388     /* Get VDS space */
7389     if((filespace = H5Dget_space(vdset)) < 0)
7390         TEST_ERROR
7391 
7392     /* Get VDS space dimensions */
7393     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
7394         TEST_ERROR
7395     if(ndims != 2)
7396         TEST_ERROR
7397     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
7398         TEST_ERROR
7399     if(dims[0] != 10)
7400         TEST_ERROR
7401     if(dims[1] != 4)
7402         TEST_ERROR
7403     if(mdims[0] != 10)
7404         TEST_ERROR
7405     if(mdims[1] != 20)
7406         TEST_ERROR
7407 
7408     /* Close filespace */
7409     if(H5Sclose(filespace) < 0)
7410         TEST_ERROR
7411 
7412     /* Read data through virtual dataset */
7413     /* Reset rbuf */
7414     HDmemset(rbuf[0], 0, sizeof(rbuf));
7415 
7416     /* Select hyperslab in memory space */
7417     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
7418         TEST_ERROR
7419 
7420     /* Read data */
7421     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
7422         TEST_ERROR
7423 
7424     /* Verify read data */
7425     for(i = 0; i < (int)mdims[0]; i++)
7426         for(j = 0; j < (int)mdims[1]; j++) {
7427             if(j >= (int)dims[1]) {
7428                 if(rbuf[i][j] != 0)
7429                     TEST_ERROR
7430             }
7431             else
7432                 if(rbuf[i][j] != erbuf[i][j])
7433                     TEST_ERROR
7434         }
7435 
7436     /* Close VDS and reopen with printf gap set to 2, reopen file as well if
7437      * config option specified */
7438     if(H5Dclose(vdset) < 0)
7439         TEST_ERROR
7440     if(H5Pset_virtual_printf_gap(dapl, (hsize_t)2) < 0)
7441         TEST_ERROR
7442     if(config & TEST_IO_REOPEN_VIRT) {
7443         if(H5Fclose(vfile) < 0)
7444             TEST_ERROR
7445         vfile = -1;
7446         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
7447             TEST_ERROR
7448     }
7449     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
7450         TEST_ERROR
7451 
7452     /* Test H5Pget_virtual_printf_gap() */
7453     if(H5Pget_virtual_printf_gap(dapl, &gap_size) < 0)
7454         TEST_ERROR
7455     if(gap_size != (hsize_t)2)
7456         TEST_ERROR
7457 
7458     /* Get VDS space */
7459     if((filespace = H5Dget_space(vdset)) < 0)
7460         TEST_ERROR
7461 
7462     /* Get VDS space dimensions */
7463     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
7464         TEST_ERROR
7465     if(ndims != 2)
7466         TEST_ERROR
7467     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
7468         TEST_ERROR
7469     if(dims[0] != 10)
7470         TEST_ERROR
7471     if(dims[1] != 7)
7472         TEST_ERROR
7473     if(mdims[0] != 10)
7474         TEST_ERROR
7475     if(mdims[1] != 20)
7476         TEST_ERROR
7477 
7478     /* Close filespace */
7479     if(H5Sclose(filespace) < 0)
7480         TEST_ERROR
7481 
7482     /* Read data through virtual dataset */
7483     /* Reset rbuf */
7484     HDmemset(rbuf[0], 0, sizeof(rbuf));
7485 
7486     /* Select hyperslab in memory space */
7487     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
7488         TEST_ERROR
7489 
7490     /* Read data */
7491     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
7492         TEST_ERROR
7493 
7494     /* Verify read data */
7495     for(i = 0; i < (int)mdims[0]; i++)
7496         for(j = 0; j < (int)mdims[1]; j++) {
7497             if(j >= (int)dims[1]) {
7498                 if(rbuf[i][j] != 0)
7499                     TEST_ERROR
7500             }
7501             else
7502                 if(rbuf[i][j] != erbuf[i][j])
7503                     TEST_ERROR
7504         }
7505 
7506     /* Close VDS and reopen with printf gap set to 3, reopen file as well if
7507      * config option specified */
7508     if(H5Dclose(vdset) < 0)
7509         TEST_ERROR
7510     if(H5Pset_virtual_printf_gap(dapl, (hsize_t)3) < 0)
7511         TEST_ERROR
7512     if(config & TEST_IO_REOPEN_VIRT) {
7513         if(H5Fclose(vfile) < 0)
7514             TEST_ERROR
7515         vfile = -1;
7516         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
7517             TEST_ERROR
7518     }
7519     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
7520         TEST_ERROR
7521 
7522     /* Test H5Pget_virtual_printf_gap() */
7523     if(H5Pget_virtual_printf_gap(dapl, &gap_size) < 0)
7524         TEST_ERROR
7525     if(gap_size != (hsize_t)3)
7526         TEST_ERROR
7527 
7528     /* Get VDS space */
7529     if((filespace = H5Dget_space(vdset)) < 0)
7530         TEST_ERROR
7531 
7532     /* Get VDS space dimensions */
7533     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
7534         TEST_ERROR
7535     if(ndims != 2)
7536         TEST_ERROR
7537     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
7538         TEST_ERROR
7539     if(dims[0] != 10)
7540         TEST_ERROR
7541     if(dims[1] != 11)
7542         TEST_ERROR
7543     if(mdims[0] != 10)
7544         TEST_ERROR
7545     if(mdims[1] != 20)
7546         TEST_ERROR
7547 
7548     /* Close filespace */
7549     if(H5Sclose(filespace) < 0)
7550         TEST_ERROR
7551 
7552     /* Read data through virtual dataset */
7553     /* Reset rbuf */
7554     HDmemset(rbuf[0], 0, sizeof(rbuf));
7555 
7556     /* Select hyperslab in memory space */
7557     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
7558         TEST_ERROR
7559 
7560     /* Read data */
7561     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
7562         TEST_ERROR
7563 
7564     /* Verify read data */
7565     for(i = 0; i < (int)mdims[0]; i++)
7566         for(j = 0; j < (int)mdims[1]; j++) {
7567             if(j >= (int)dims[1]) {
7568                 if(rbuf[i][j] != 0)
7569                     TEST_ERROR
7570             }
7571             else
7572                 if(rbuf[i][j] != erbuf[i][j])
7573                     TEST_ERROR
7574         }
7575 
7576     /* Close VDS and reopen with printf gap set to 4, reopen file as well if
7577      * config option specified */
7578     if(H5Dclose(vdset) < 0)
7579         TEST_ERROR
7580     if(H5Pset_virtual_printf_gap(dapl, (hsize_t)4) < 0)
7581         TEST_ERROR
7582     if(config & TEST_IO_REOPEN_VIRT) {
7583         if(H5Fclose(vfile) < 0)
7584             TEST_ERROR
7585         vfile = -1;
7586         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
7587             TEST_ERROR
7588     }
7589     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
7590         TEST_ERROR
7591 
7592     /* Test H5Pget_virtual_printf_gap() */
7593     if(H5Pget_virtual_printf_gap(dapl, &gap_size) < 0)
7594         TEST_ERROR
7595     if(gap_size != (hsize_t)4)
7596         TEST_ERROR
7597 
7598     /* Get VDS space */
7599     if((filespace = H5Dget_space(vdset)) < 0)
7600         TEST_ERROR
7601 
7602     /* Get VDS space dimensions */
7603     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
7604         TEST_ERROR
7605     if(ndims != 2)
7606         TEST_ERROR
7607     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
7608         TEST_ERROR
7609     if(dims[0] != 10)
7610         TEST_ERROR
7611     if(dims[1] != 16)
7612         TEST_ERROR
7613     if(mdims[0] != 10)
7614         TEST_ERROR
7615     if(mdims[1] != 20)
7616         TEST_ERROR
7617 
7618     /* Close filespace */
7619     if(H5Sclose(filespace) < 0)
7620         TEST_ERROR
7621 
7622     /* Read data through virtual dataset */
7623     /* Reset rbuf */
7624     HDmemset(rbuf[0], 0, sizeof(rbuf));
7625 
7626     /* Select hyperslab in memory space */
7627     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
7628         TEST_ERROR
7629 
7630     /* Read data */
7631     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
7632         TEST_ERROR
7633 
7634     /* Verify read data */
7635     for(i = 0; i < (int)mdims[0]; i++)
7636         for(j = 0; j < (int)mdims[1]; j++) {
7637             if(j >= (int)dims[1]) {
7638                 if(rbuf[i][j] != 0)
7639                     TEST_ERROR
7640             }
7641             else
7642                 if(rbuf[i][j] != erbuf[i][j])
7643                     TEST_ERROR
7644         }
7645 
7646     /* Close VDS and reopen with view set to H5D_VDS_FIRST_MISSING, reopen file
7647      * as well if config option specified */
7648     if(H5Dclose(vdset) < 0)
7649         TEST_ERROR
7650     if(H5Pset_virtual_view(dapl, H5D_VDS_FIRST_MISSING) < 0)
7651         TEST_ERROR
7652     if(config & TEST_IO_REOPEN_VIRT) {
7653         if(H5Fclose(vfile) < 0)
7654             TEST_ERROR
7655         vfile = -1;
7656         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
7657             TEST_ERROR
7658     }
7659     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
7660         TEST_ERROR
7661 
7662     /* Get VDS space */
7663     if((filespace = H5Dget_space(vdset)) < 0)
7664         TEST_ERROR
7665 
7666     /* Get VDS space dimensions */
7667     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
7668         TEST_ERROR
7669     if(ndims != 2)
7670         TEST_ERROR
7671     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
7672         TEST_ERROR
7673     if(dims[0] != 10)
7674         TEST_ERROR
7675     if(dims[1] != 2)
7676         TEST_ERROR
7677     if(mdims[0] != 10)
7678         TEST_ERROR
7679     if(mdims[1] != 20)
7680         TEST_ERROR
7681 
7682     /* Close filespace */
7683     if(H5Sclose(filespace) < 0)
7684         TEST_ERROR
7685 
7686     /* Read data through virtual dataset */
7687     /* Reset rbuf */
7688     HDmemset(rbuf[0], 0, sizeof(rbuf));
7689 
7690     /* Select hyperslab in memory space */
7691     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
7692         TEST_ERROR
7693 
7694     /* Read data */
7695     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
7696         TEST_ERROR
7697 
7698     /* Verify read data */
7699     for(i = 0; i < (int)mdims[0]; i++)
7700         for(j = 0; j < (int)mdims[1]; j++) {
7701             if(j >= (int)dims[1]) {
7702                 if(rbuf[i][j] != 0)
7703                     TEST_ERROR
7704             }
7705             else
7706                 if(rbuf[i][j] != erbuf[i][j])
7707                     TEST_ERROR
7708         }
7709 
7710     /* Reset dapl */
7711     if(H5Pset_virtual_printf_gap(dapl, (hsize_t)0) < 0)
7712         TEST_ERROR
7713     if(H5Pset_virtual_view(dapl, H5D_VDS_LAST_AVAILABLE) < 0)
7714         TEST_ERROR
7715 
7716     /* Close */
7717     if(!(config & TEST_IO_CLOSE_SRC)) {
7718         for(i = 0; i < 6; i++) {
7719             if(H5Dclose(srcdset[i]) < 0)
7720                 TEST_ERROR
7721             srcdset[i] = -1;
7722         }
7723         if(H5Fclose(srcfile[0]) < 0)
7724             TEST_ERROR
7725         srcfile[0] = -1;
7726     }
7727     else if(!(config & TEST_IO_DIFFERENT_FILE)) {
7728         if(H5Fclose(srcfile[0]) < 0)
7729             TEST_ERROR
7730         srcfile[0] = -1;
7731     }
7732     if(H5Dclose(vdset) < 0)
7733         TEST_ERROR
7734     vdset = -1;
7735     if(H5Fclose(vfile) < 0)
7736         TEST_ERROR
7737     vfile = -1;
7738     if(H5Sclose(srcspace) < 0)
7739         TEST_ERROR
7740     srcspace = -1;
7741     if(H5Sclose(vspace[0]) < 0)
7742         TEST_ERROR
7743     vspace[0] = -1;
7744 
7745 
7746     /* Next 2 tests are always run with a different source file, so only run if
7747      * that config option is set (so they're not run twice with the same
7748      * configuration) */
7749     if(config & TEST_IO_DIFFERENT_FILE) {
7750         /*
7751          * Test 3: 1 Source dataset mapping, 10x5 blocks, printf source file
7752          */
7753         /* Clean up files so the source files do not exist yet */
7754         H5Iinc_ref(fapl);       /* Prevent FAPL from being closed */
7755         h5_clean_files(FILENAME, fapl);
7756 
7757         /* Clear virtual layout in DCPL */
7758         if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
7759             TEST_ERROR
7760 
7761         /* Create virtual dataspaces */
7762         if((vspace[0] = H5Screate_simple(2, dims, mdims)) < 0)
7763             TEST_ERROR
7764 
7765         /* Create source dataspace */
7766         dims[1] = 5;
7767         if((srcspace = H5Screate_simple(2, dims, NULL)) < 0)
7768             TEST_ERROR
7769 
7770         /* Select hyperslabs in virtual space */
7771         stride[0] = 1;
7772         stride[1] = 5;
7773         count[0] = 1;
7774         count[1] = H5S_UNLIMITED;
7775         block[0] = 10;
7776         block[1] = 5;
7777         if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, stride, count, block) < 0)
7778             TEST_ERROR
7779 
7780         /* Add virtual layout mapping */
7781         if(H5Pset_virtual(dcpl, vspace[0], printf_srcfilename_map, "src_dset", srcspace) < 0)
7782             TEST_ERROR
7783 
7784         /* Create virtual file */
7785         if((vfile = H5Fcreate(vfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
7786             TEST_ERROR
7787 
7788         /* Create virtual dataset */
7789         if((vdset = H5Dcreate2(vfile, "v_dset", H5T_NATIVE_INT, vspace[0], H5P_DEFAULT, dcpl, dapl)) < 0)
7790             TEST_ERROR
7791 
7792         /* Reopen virtual dataset and file if config option specified */
7793         if(config & TEST_IO_REOPEN_VIRT) {
7794             if(H5Dclose(vdset) < 0)
7795                 TEST_ERROR
7796             vdset = -1;
7797             if(H5Fclose(vfile) < 0)
7798                 TEST_ERROR
7799             vfile = -1;
7800             if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
7801                 TEST_ERROR
7802             if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
7803                 TEST_ERROR
7804         }
7805 
7806         /* Get VDS space */
7807         if((filespace = H5Dget_space(vdset)) < 0)
7808             TEST_ERROR
7809 
7810         /* Get VDS space dimensions */
7811         if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
7812             TEST_ERROR
7813         if(ndims != 2)
7814             TEST_ERROR
7815         if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
7816             TEST_ERROR
7817         if(dims[0] != 10)
7818             TEST_ERROR
7819         if(dims[1] != 0)
7820             TEST_ERROR
7821         if(mdims[0] != 10)
7822             TEST_ERROR
7823         if(mdims[1] != 20)
7824             TEST_ERROR
7825 
7826         /* Close filespace */
7827         if(H5Sclose(filespace) < 0)
7828             TEST_ERROR
7829 
7830         /* Create 2 source files, one source dataset */
7831         if((srcfile[0] = H5Fcreate(srcfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
7832             TEST_ERROR
7833         if((srcdset[0] = H5Dcreate2(srcfile[0], "src_dset", H5T_NATIVE_INT, srcspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
7834             TEST_ERROR
7835         if((srcfile[1] = H5Fcreate(srcfilename2, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
7836             TEST_ERROR
7837 
7838         /* Populate write buffer */
7839         for(i = 0; i < (int)mdims[0]; i++)
7840             for(j = 0; j < (int)mdims[1]; j++)
7841                 buf[i][j] = (i * (int)mdims[1]) + j;
7842 
7843         /* Initialize erbuf */
7844         for(i = 0; i < (int)mdims[0]; i++)
7845             for(j = 0; j < (int)mdims[1]; j++)
7846                 erbuf[i][j] = fill;
7847 
7848         /* Write to srcdset[0] */
7849         if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
7850             TEST_ERROR
7851         if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
7852             TEST_ERROR
7853 
7854         /* Update erbuf */
7855         for(i = 0; i < 10; i++)
7856             for(j = 0; j < 5; j++)
7857                 erbuf[i][j] = buf[i][j];
7858 
7859         /* Close srcdset and srcfiles if config option specified */
7860         if(config & TEST_IO_CLOSE_SRC) {
7861             if(H5Dclose(srcdset[0]) < 0)
7862                 TEST_ERROR
7863             srcdset[0] = -1;
7864             if(H5Fclose(srcfile[0]) < 0)
7865                 TEST_ERROR
7866             srcfile[0] = -1;
7867             if(H5Fclose(srcfile[1]) < 0)
7868                 TEST_ERROR
7869             srcfile[1] = -1;
7870         }
7871 
7872         /* Reopen virtual dataset and file if config option specified */
7873         if(config & TEST_IO_REOPEN_VIRT) {
7874             if(H5Dclose(vdset) < 0)
7875                 TEST_ERROR
7876             vdset = -1;
7877             if(H5Fclose(vfile) < 0)
7878                 TEST_ERROR
7879             vfile = -1;
7880             if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
7881                 TEST_ERROR
7882             if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
7883                 TEST_ERROR
7884         }
7885 
7886         /* Get VDS space */
7887         if((filespace = H5Dget_space(vdset)) < 0)
7888             TEST_ERROR
7889 
7890         /* Get VDS space dimensions */
7891         if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
7892             TEST_ERROR
7893         if(ndims != 2)
7894             TEST_ERROR
7895         if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
7896             TEST_ERROR
7897         if(dims[0] != 10)
7898             TEST_ERROR
7899         if(dims[1] != 5)
7900             TEST_ERROR
7901         if(mdims[0] != 10)
7902             TEST_ERROR
7903         if(mdims[1] != 20)
7904             TEST_ERROR
7905 
7906         /* Close filespace */
7907         if(H5Sclose(filespace) < 0)
7908             TEST_ERROR
7909 
7910         /* Read data through virtual dataset */
7911         /* Reset rbuf */
7912         HDmemset(rbuf[0], 0, sizeof(rbuf));
7913 
7914         /* Select hyperslab in memory space */
7915         if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
7916             TEST_ERROR
7917 
7918         /* Read data */
7919         if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
7920             TEST_ERROR
7921 
7922         /* Verify read data */
7923         for(i = 0; i < (int)mdims[0]; i++)
7924             for(j = 0; j < (int)mdims[1]; j++) {
7925                 if(j >= (int)dims[1]) {
7926                     if(rbuf[i][j] != 0)
7927                         TEST_ERROR
7928                 }
7929                 else
7930                     if(rbuf[i][j] != erbuf[i][j])
7931                         TEST_ERROR
7932             }
7933 
7934         /* Reopen srcfile[1] if config option specified */
7935         if(config & TEST_IO_CLOSE_SRC)
7936             if((srcfile[1] = H5Fopen(srcfilename2, H5F_ACC_RDWR, fapl)) < 0)
7937                 TEST_ERROR
7938 
7939         /* Create 2nd source dataset */
7940         if((srcdset[1] = H5Dcreate2(srcfile[1], "src_dset", H5T_NATIVE_INT, srcspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
7941             TEST_ERROR
7942 
7943         /* Adjust write buffer */
7944         for(i = 0; i < (int)mdims[0]; i++)
7945             for(j = 0; j < (int)mdims[1]; j++)
7946                 buf[i][j] += (int)mdims[0] * (int)mdims[1];
7947 
7948         /* Write to srcdset[1] */
7949         if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
7950             TEST_ERROR
7951         if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
7952             TEST_ERROR
7953 
7954         /* Update erbuf */
7955         for(i = 0; i < 10; i++)
7956             for(j = 0; j < 5; j++)
7957                 erbuf[i][j + 5] = buf[i][j];
7958 
7959         /* Close srcdset[1] and srcfile[1] if config option specified */
7960         if(config & TEST_IO_CLOSE_SRC) {
7961             if(H5Dclose(srcdset[1]) < 0)
7962                 TEST_ERROR
7963             srcdset[1] = -1;
7964             if(H5Fclose(srcfile[1]) < 0)
7965                 TEST_ERROR
7966             srcfile[1] = -1;
7967         }
7968 
7969         /* Reopen virtual dataset and file if config option specified */
7970         if(config & TEST_IO_REOPEN_VIRT) {
7971             if(H5Dclose(vdset) < 0)
7972                 TEST_ERROR
7973             vdset = -1;
7974             if(H5Fclose(vfile) < 0)
7975                 TEST_ERROR
7976             vfile = -1;
7977             if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
7978                 TEST_ERROR
7979             if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
7980                 TEST_ERROR
7981         }
7982 
7983         /* Get VDS space */
7984         if((filespace = H5Dget_space(vdset)) < 0)
7985             TEST_ERROR
7986 
7987         /* Get VDS space dimensions */
7988         if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
7989             TEST_ERROR
7990         if(ndims != 2)
7991             TEST_ERROR
7992         if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
7993             TEST_ERROR
7994         if(dims[0] != 10)
7995             TEST_ERROR
7996         if(dims[1] != 10)
7997             TEST_ERROR
7998         if(mdims[0] != 10)
7999             TEST_ERROR
8000         if(mdims[1] != 20)
8001             TEST_ERROR
8002 
8003         /* Close filespace */
8004         if(H5Sclose(filespace) < 0)
8005             TEST_ERROR
8006 
8007         /* Read data through virtual dataset */
8008         /* Reset rbuf */
8009         HDmemset(rbuf[0], 0, sizeof(rbuf));
8010 
8011         /* Select hyperslab in memory space */
8012         if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
8013             TEST_ERROR
8014 
8015         /* Read data */
8016         if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
8017             TEST_ERROR
8018 
8019         /* Verify read data */
8020         for(i = 0; i < (int)mdims[0]; i++)
8021             for(j = 0; j < (int)mdims[1]; j++) {
8022                 if(j >= (int)dims[1]) {
8023                     if(rbuf[i][j] != 0)
8024                         TEST_ERROR
8025                 }
8026                 else
8027                     if(rbuf[i][j] != erbuf[i][j])
8028                         TEST_ERROR
8029             }
8030 
8031         /* Close */
8032         if(!(config & TEST_IO_CLOSE_SRC)) {
8033             if(H5Dclose(srcdset[0]) < 0)
8034                 TEST_ERROR
8035             srcdset[0] = -1;
8036             if(H5Dclose(srcdset[1]) < 0)
8037                 TEST_ERROR
8038             srcdset[1] = -1;
8039             if(H5Fclose(srcfile[0]) < 0)
8040                 TEST_ERROR
8041             srcfile[0] = -1;
8042             if(H5Fclose(srcfile[1]) < 0)
8043                 TEST_ERROR
8044             srcfile[1] = -1;
8045         }
8046         if(H5Dclose(vdset) < 0)
8047             TEST_ERROR
8048         vdset = -1;
8049         if(H5Fclose(vfile) < 0)
8050             TEST_ERROR
8051         vfile = -1;
8052         if(H5Sclose(srcspace) < 0)
8053             TEST_ERROR
8054         srcspace = -1;
8055         if(H5Sclose(vspace[0]) < 0)
8056             TEST_ERROR
8057         vspace[0] = -1;
8058 
8059 
8060         /*
8061          * Test 4: 1 Source dataset mapping, 10x5 blocks, printf source file and
8062          * source dset, extra %%s in source dataset name
8063          */
8064         /* Clean up files so the source files do not exist yet */
8065         H5Iinc_ref(fapl);       /* Prevent FAPL from being closed */
8066         h5_clean_files(FILENAME, fapl);
8067 
8068         /* Clear virtual layout in DCPL */
8069         if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
8070             TEST_ERROR
8071 
8072         /* Create virtual dataspaces */
8073         if((vspace[0] = H5Screate_simple(2, dims, mdims)) < 0)
8074             TEST_ERROR
8075 
8076         /* Create source dataspace */
8077         dims[1] = 5;
8078         if((srcspace = H5Screate_simple(2, dims, NULL)) < 0)
8079             TEST_ERROR
8080 
8081         /* Select hyperslabs in virtual space */
8082         stride[0] = 1;
8083         stride[1] = 5;
8084         count[0] = 1;
8085         count[1] = H5S_UNLIMITED;
8086         block[0] = 10;
8087         block[1] = 5;
8088         if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, stride, count, block) < 0)
8089             TEST_ERROR
8090 
8091         /* Add virtual layout mapping */
8092         if(H5Pset_virtual(dcpl, vspace[0], printf_srcfilename_map, "%%src%%_dset%%%b", srcspace) < 0)
8093             TEST_ERROR
8094 
8095         /* Create virtual file */
8096         if((vfile = H5Fcreate(vfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
8097             TEST_ERROR
8098 
8099         /* Create virtual dataset */
8100         if((vdset = H5Dcreate2(vfile, "v_dset", H5T_NATIVE_INT, vspace[0], H5P_DEFAULT, dcpl, dapl)) < 0)
8101             TEST_ERROR
8102 
8103         /* Reopen virtual dataset and file if config option specified */
8104         if(config & TEST_IO_REOPEN_VIRT) {
8105             if(H5Dclose(vdset) < 0)
8106                 TEST_ERROR
8107             vdset = -1;
8108             if(H5Fclose(vfile) < 0)
8109                 TEST_ERROR
8110             vfile = -1;
8111             if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
8112                 TEST_ERROR
8113             if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
8114                 TEST_ERROR
8115         }
8116 
8117         /* Get VDS space */
8118         if((filespace = H5Dget_space(vdset)) < 0)
8119             TEST_ERROR
8120 
8121         /* Get VDS space dimensions */
8122         if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
8123             TEST_ERROR
8124         if(ndims != 2)
8125             TEST_ERROR
8126         if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
8127             TEST_ERROR
8128         if(dims[0] != 10)
8129             TEST_ERROR
8130         if(dims[1] != 0)
8131             TEST_ERROR
8132         if(mdims[0] != 10)
8133             TEST_ERROR
8134         if(mdims[1] != 20)
8135             TEST_ERROR
8136 
8137         /* Close filespace */
8138         if(H5Sclose(filespace) < 0)
8139             TEST_ERROR
8140 
8141         /* Create 2 source files, one source dataset */
8142         if((srcfile[0] = H5Fcreate(srcfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
8143             TEST_ERROR
8144         if((srcdset[0] = H5Dcreate2(srcfile[0], "%src%_dset%0", H5T_NATIVE_INT, srcspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
8145             TEST_ERROR
8146         if((srcfile[1] = H5Fcreate(srcfilename2, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
8147             TEST_ERROR
8148 
8149         /* Populate write buffer */
8150         for(i = 0; i < (int)mdims[0]; i++)
8151             for(j = 0; j < (int)mdims[1]; j++)
8152                 buf[i][j] = (i * (int)mdims[1]) + j;
8153 
8154         /* Initialize erbuf */
8155         for(i = 0; i < (int)mdims[0]; i++)
8156             for(j = 0; j < (int)mdims[1]; j++)
8157                 erbuf[i][j] = fill;
8158 
8159         /* Write to srcdset[0] */
8160         if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
8161             TEST_ERROR
8162         if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
8163             TEST_ERROR
8164 
8165         /* Update erbuf */
8166         for(i = 0; i < 10; i++)
8167             for(j = 0; j < 5; j++)
8168                 erbuf[i][j] = buf[i][j];
8169 
8170         /* Close srcdset and srcfiles if config option specified */
8171         if(config & TEST_IO_CLOSE_SRC) {
8172             if(H5Dclose(srcdset[0]) < 0)
8173                 TEST_ERROR
8174             srcdset[0] = -1;
8175             if(H5Fclose(srcfile[0]) < 0)
8176                 TEST_ERROR
8177             srcfile[0] = -1;
8178             if(H5Fclose(srcfile[1]) < 0)
8179                 TEST_ERROR
8180             srcfile[1] = -1;
8181         }
8182 
8183         /* Reopen virtual dataset and file if config option specified */
8184         if(config & TEST_IO_REOPEN_VIRT) {
8185             if(H5Dclose(vdset) < 0)
8186                 TEST_ERROR
8187             vdset = -1;
8188             if(H5Fclose(vfile) < 0)
8189                 TEST_ERROR
8190             vfile = -1;
8191             if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
8192                 TEST_ERROR
8193             if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
8194                 TEST_ERROR
8195         }
8196 
8197         /* Get VDS space */
8198         if((filespace = H5Dget_space(vdset)) < 0)
8199             TEST_ERROR
8200 
8201         /* Get VDS space dimensions */
8202         if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
8203             TEST_ERROR
8204         if(ndims != 2)
8205             TEST_ERROR
8206         if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
8207             TEST_ERROR
8208         if(dims[0] != 10)
8209             TEST_ERROR
8210         if(dims[1] != 5)
8211             TEST_ERROR
8212         if(mdims[0] != 10)
8213             TEST_ERROR
8214         if(mdims[1] != 20)
8215             TEST_ERROR
8216 
8217         /* Close filespace */
8218         if(H5Sclose(filespace) < 0)
8219             TEST_ERROR
8220 
8221         /* Read data through virtual dataset */
8222         /* Reset rbuf */
8223         HDmemset(rbuf[0], 0, sizeof(rbuf));
8224 
8225         /* Select hyperslab in memory space */
8226         if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
8227             TEST_ERROR
8228 
8229         /* Read data */
8230         if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
8231             TEST_ERROR
8232 
8233         /* Verify read data */
8234         for(i = 0; i < (int)mdims[0]; i++)
8235             for(j = 0; j < (int)mdims[1]; j++) {
8236                 if(j >= (int)dims[1]) {
8237                     if(rbuf[i][j] != 0)
8238                         TEST_ERROR
8239                 }
8240                 else
8241                     if(rbuf[i][j] != erbuf[i][j])
8242                         TEST_ERROR
8243             }
8244 
8245         /* Reopen srcfile[1] if config option specified */
8246         if(config & TEST_IO_CLOSE_SRC)
8247             if((srcfile[1] = H5Fopen(srcfilename2, H5F_ACC_RDWR, fapl)) < 0)
8248                 TEST_ERROR
8249 
8250         /* Create 2nd source dataset */
8251         if((srcdset[1] = H5Dcreate2(srcfile[1], "%src%_dset%1", H5T_NATIVE_INT, srcspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
8252             TEST_ERROR
8253 
8254         /* Adjust write buffer */
8255         for(i = 0; i < (int)mdims[0]; i++)
8256             for(j = 0; j < (int)mdims[1]; j++)
8257                 buf[i][j] += (int)mdims[0] * (int)mdims[1];
8258 
8259         /* Write to srcdset[1] */
8260         if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
8261             TEST_ERROR
8262         if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
8263             TEST_ERROR
8264 
8265         /* Update erbuf */
8266         for(i = 0; i < 10; i++)
8267             for(j = 0; j < 5; j++)
8268                 erbuf[i][j + 5] = buf[i][j];
8269 
8270         /* Close srcdset[1] and srcfile[1] if config option specified */
8271         if(config & TEST_IO_CLOSE_SRC) {
8272             if(H5Dclose(srcdset[1]) < 0)
8273                 TEST_ERROR
8274             srcdset[1] = -1;
8275             if(H5Fclose(srcfile[1]) < 0)
8276                 TEST_ERROR
8277             srcfile[1] = -1;
8278         }
8279 
8280         /* Reopen virtual dataset and file if config option specified */
8281         if(config & TEST_IO_REOPEN_VIRT) {
8282             if(H5Dclose(vdset) < 0)
8283                 TEST_ERROR
8284             vdset = -1;
8285             if(H5Fclose(vfile) < 0)
8286                 TEST_ERROR
8287             vfile = -1;
8288             if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
8289                 TEST_ERROR
8290             if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
8291                 TEST_ERROR
8292         }
8293 
8294         /* Get VDS space */
8295         if((filespace = H5Dget_space(vdset)) < 0)
8296             TEST_ERROR
8297 
8298         /* Get VDS space dimensions */
8299         if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
8300             TEST_ERROR
8301         if(ndims != 2)
8302             TEST_ERROR
8303         if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
8304             TEST_ERROR
8305         if(dims[0] != 10)
8306             TEST_ERROR
8307         if(dims[1] != 10)
8308             TEST_ERROR
8309         if(mdims[0] != 10)
8310             TEST_ERROR
8311         if(mdims[1] != 20)
8312             TEST_ERROR
8313 
8314         /* Close filespace */
8315         if(H5Sclose(filespace) < 0)
8316             TEST_ERROR
8317 
8318         /* Read data through virtual dataset */
8319         /* Reset rbuf */
8320         HDmemset(rbuf[0], 0, sizeof(rbuf));
8321 
8322         /* Select hyperslab in memory space */
8323         if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
8324             TEST_ERROR
8325 
8326         /* Read data */
8327         if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
8328             TEST_ERROR
8329 
8330         /* Verify read data */
8331         for(i = 0; i < (int)mdims[0]; i++)
8332             for(j = 0; j < (int)mdims[1]; j++) {
8333                 if(j >= (int)dims[1]) {
8334                     if(rbuf[i][j] != 0)
8335                         TEST_ERROR
8336                 }
8337                 else
8338                     if(rbuf[i][j] != erbuf[i][j])
8339                         TEST_ERROR
8340             }
8341 
8342         /* Close */
8343         if(!(config & TEST_IO_CLOSE_SRC)) {
8344             if(H5Dclose(srcdset[0]) < 0)
8345                 TEST_ERROR
8346             srcdset[0] = -1;
8347             if(H5Dclose(srcdset[1]) < 0)
8348                 TEST_ERROR
8349             srcdset[1] = -1;
8350             if(H5Fclose(srcfile[0]) < 0)
8351                 TEST_ERROR
8352             srcfile[0] = -1;
8353             if(H5Fclose(srcfile[1]) < 0)
8354                 TEST_ERROR
8355             srcfile[1] = -1;
8356         }
8357         if(H5Dclose(vdset) < 0)
8358             TEST_ERROR
8359         vdset = -1;
8360         if(H5Fclose(vfile) < 0)
8361             TEST_ERROR
8362         vfile = -1;
8363         if(H5Sclose(srcspace) < 0)
8364             TEST_ERROR
8365         srcspace = -1;
8366         if(H5Sclose(vspace[0]) < 0)
8367             TEST_ERROR
8368         vspace[0] = -1;
8369     }
8370 
8371 
8372     /*
8373      * Test 5: 2 Source mappings, interleaved slices, single element wide,
8374      * hyperslab selection in source, extra %%s in source dataset names
8375      */
8376     /* Clear virtual layout in DCPL */
8377     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
8378         TEST_ERROR
8379 
8380     /* Create virtual dataspaces */
8381     dims[0] = 10;
8382     dims[1] = 10;
8383     if((vspace[0] = H5Screate_simple(2, dims, mdims)) < 0)
8384         TEST_ERROR
8385     if((vspace[1] = H5Screate_simple(2, dims, mdims)) < 0)
8386         TEST_ERROR
8387 
8388     /* Create source dataspace (2 elements wide) */
8389     dims[1] = 2;
8390     if((srcspace = H5Screate_simple(2, dims, NULL)) < 0)
8391         TEST_ERROR
8392 
8393     /* Select hyperslab in source space */
8394     count[0] = 10;
8395     count[1] = 1;
8396     if(H5Sselect_hyperslab(srcspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
8397         TEST_ERROR
8398 
8399     /* Select hyperslabs in virtual spaces */
8400     stride[0] = 1;
8401     stride[1] = 2;
8402     count[0] = 1;
8403     count[1] = H5S_UNLIMITED;
8404     block[0] = 10;
8405     block[1] = 1;
8406     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, stride, count, block) < 0)
8407         TEST_ERROR
8408     start[1] = 1;
8409     if(H5Sselect_hyperslab(vspace[1], H5S_SELECT_SET, start, stride, count, block) < 0)
8410         TEST_ERROR
8411     start[1] = 0;
8412 
8413     /* Add virtual layout mappings */
8414     if(H5Pset_virtual(dcpl, vspace[0], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "%bsrc_dset_a%b%%", srcspace) < 0)
8415         TEST_ERROR
8416     if(H5Pset_virtual(dcpl, vspace[1], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset_b%b%%%%", srcspace) < 0)
8417         TEST_ERROR
8418 
8419     /* Create virtual file */
8420     if((vfile = H5Fcreate(vfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
8421         TEST_ERROR
8422 
8423     /* Create source file if requested */
8424     if(config & TEST_IO_DIFFERENT_FILE) {
8425         if((srcfile[0] = H5Fcreate(srcfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
8426             TEST_ERROR
8427     }
8428     else {
8429         srcfile[0] = vfile;
8430         if(H5Iinc_ref(srcfile[0]) < 0)
8431             TEST_ERROR
8432     }
8433 
8434     /* Create virtual dataset */
8435     if((vdset = H5Dcreate2(vfile, "v_dset", H5T_NATIVE_INT, vspace[0], H5P_DEFAULT, dcpl, dapl)) < 0)
8436         TEST_ERROR
8437 
8438     /* Close srcfile if config option specified */
8439     if(config & TEST_IO_CLOSE_SRC)
8440         if(config & TEST_IO_DIFFERENT_FILE) {
8441             if(H5Fclose(srcfile[0]) < 0)
8442                 TEST_ERROR
8443             srcfile[0] = -1;
8444         }
8445 
8446     /* Reopen virtual dataset and file if config option specified */
8447     if(config & TEST_IO_REOPEN_VIRT) {
8448         if(H5Dclose(vdset) < 0)
8449             TEST_ERROR
8450         vdset = -1;
8451         if(H5Fclose(vfile) < 0)
8452             TEST_ERROR
8453         vfile = -1;
8454         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
8455             TEST_ERROR
8456         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
8457             TEST_ERROR
8458     }
8459 
8460     /* Get VDS space */
8461     if((filespace = H5Dget_space(vdset)) < 0)
8462         TEST_ERROR
8463 
8464     /* Get VDS space dimensions */
8465     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
8466         TEST_ERROR
8467     if(ndims != 2)
8468         TEST_ERROR
8469     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
8470         TEST_ERROR
8471     if(dims[0] != 10)
8472         TEST_ERROR
8473     if(dims[1] != 0)
8474         TEST_ERROR
8475     if(mdims[0] != 10)
8476         TEST_ERROR
8477     if(mdims[1] != 20)
8478         TEST_ERROR
8479 
8480     /* Close filespace */
8481     if(H5Sclose(filespace) < 0)
8482         TEST_ERROR
8483 
8484     /* Reopen srcfile if config option specified */
8485     if(config & TEST_IO_CLOSE_SRC)
8486         if(config & TEST_IO_DIFFERENT_FILE)
8487             if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
8488                 TEST_ERROR
8489 
8490     /* Create 2 source datasets */
8491     if((srcdset[0] = H5Dcreate2(srcfile[0], "0src_dset_a0%", H5T_NATIVE_INT, srcspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
8492         TEST_ERROR
8493     if((srcdset[1] = H5Dcreate2(srcfile[0], "src_dset_b0%%", H5T_NATIVE_INT, srcspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
8494         TEST_ERROR
8495 
8496     /* Populate write buffer */
8497     for(i = 0; i < (int)mdims[0]; i++)
8498         for(j = 0; j < (int)mdims[1]; j++)
8499             buf[i][j] = (i * (int)mdims[1]) + j;
8500 
8501     /* Initialize erbuf */
8502     for(i = 0; i < (int)mdims[0]; i++)
8503         for(j = 0; j < (int)mdims[1]; j++)
8504             erbuf[i][j] = fill;
8505 
8506     /* Write to srcdset[0] */
8507     block[0] = 10;
8508     block[1] = 2;
8509     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
8510         TEST_ERROR
8511     if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
8512         TEST_ERROR
8513 
8514     /* Update erbuf */
8515     for(i = 0; i < 10; i++)
8516         erbuf[i][0] = buf[i][0];
8517 
8518     /* Adjust write buffer */
8519     for(i = 0; i < (int)mdims[0]; i++)
8520         for(j = 0; j < (int)mdims[1]; j++)
8521             buf[i][j] += (int)mdims[0] * (int)mdims[1];
8522 
8523     /* Write to srcdset[1] */
8524     if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
8525         TEST_ERROR
8526 
8527     /* Update erbuf */
8528     for(i = 0; i < 10; i++)
8529         erbuf[i][1] = buf[i][0];
8530 
8531     /* Close srcdsets and srcfile if config option specified */
8532     if(config & TEST_IO_CLOSE_SRC) {
8533         if(H5Dclose(srcdset[0]) < 0)
8534             TEST_ERROR
8535         srcdset[0] = -1;
8536         if(H5Dclose(srcdset[1]) < 0)
8537             TEST_ERROR
8538         srcdset[1] = -1;
8539 
8540         if(config & TEST_IO_DIFFERENT_FILE) {
8541             if(H5Fclose(srcfile[0]) < 0)
8542                 TEST_ERROR
8543             srcfile[0] = -1;
8544         }
8545     }
8546 
8547     /* Reopen virtual dataset and file if config option specified */
8548     if(config & TEST_IO_REOPEN_VIRT) {
8549         if(H5Dclose(vdset) < 0)
8550             TEST_ERROR
8551         vdset = -1;
8552         if(H5Fclose(vfile) < 0)
8553             TEST_ERROR
8554         vfile = -1;
8555         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
8556             TEST_ERROR
8557         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
8558             TEST_ERROR
8559     }
8560 
8561     /* Get VDS space */
8562     if((filespace = H5Dget_space(vdset)) < 0)
8563         TEST_ERROR
8564 
8565     /* Get VDS space dimensions */
8566     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
8567         TEST_ERROR
8568     if(ndims != 2)
8569         TEST_ERROR
8570     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
8571         TEST_ERROR
8572     if(dims[0] != 10)
8573         TEST_ERROR
8574     if(dims[1] != 2)
8575         TEST_ERROR
8576     if(mdims[0] != 10)
8577         TEST_ERROR
8578     if(mdims[1] != 20)
8579         TEST_ERROR
8580 
8581     /* Close filespace */
8582     if(H5Sclose(filespace) < 0)
8583         TEST_ERROR
8584 
8585     /* Read data through virtual dataset */
8586     /* Reset rbuf */
8587     HDmemset(rbuf[0], 0, sizeof(rbuf));
8588 
8589     /* Select hyperslab in memory space */
8590     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
8591         TEST_ERROR
8592 
8593     /* Read data */
8594     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
8595         TEST_ERROR
8596 
8597     /* Verify read data */
8598     for(i = 0; i < (int)mdims[0]; i++)
8599         for(j = 0; j < (int)mdims[1]; j++) {
8600             if(j >= (int)dims[1]) {
8601                 if(rbuf[i][j] != 0)
8602                     TEST_ERROR
8603             }
8604             else
8605                 if(rbuf[i][j] != erbuf[i][j])
8606                     TEST_ERROR
8607         }
8608 
8609     /* Reopen srcfile if config option specified */
8610     if((config & TEST_IO_CLOSE_SRC) && (config & TEST_IO_DIFFERENT_FILE))
8611         if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
8612             TEST_ERROR
8613 
8614     /* Create 3rd source dataset */
8615     if((srcdset[2] = H5Dcreate2(srcfile[0], "src_dset_b1%%", H5T_NATIVE_INT, srcspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
8616         TEST_ERROR
8617 
8618     /* Adjust write buffer */
8619     for(i = 0; i < (int)mdims[0]; i++)
8620         for(j = 0; j < (int)mdims[1]; j++)
8621             buf[i][j] += (int)mdims[0] * (int)mdims[1];
8622 
8623     /* Write to srcdset[2] */
8624     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
8625         TEST_ERROR
8626     if(H5Dwrite(srcdset[2], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
8627         TEST_ERROR
8628 
8629     /* Update erbuf */
8630     for(i = 0; i < 10; i++)
8631         erbuf[i][3] = buf[i][0];
8632 
8633     /* Close srcdset[2] and srcfile if config option specified */
8634     if(config & TEST_IO_CLOSE_SRC) {
8635         if(H5Dclose(srcdset[2]) < 0)
8636             TEST_ERROR
8637         srcdset[2] = -1;
8638 
8639         if(config & TEST_IO_DIFFERENT_FILE) {
8640             if(H5Fclose(srcfile[0]) < 0)
8641                 TEST_ERROR
8642             srcfile[0] = -1;
8643         }
8644     }
8645 
8646     /* Reopen virtual dataset and file if config option specified */
8647     if(config & TEST_IO_REOPEN_VIRT) {
8648         if(H5Dclose(vdset) < 0)
8649             TEST_ERROR
8650         vdset = -1;
8651         if(H5Fclose(vfile) < 0)
8652             TEST_ERROR
8653         vfile = -1;
8654         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
8655             TEST_ERROR
8656         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
8657             TEST_ERROR
8658     }
8659 
8660     /* Get VDS space */
8661     if((filespace = H5Dget_space(vdset)) < 0)
8662         TEST_ERROR
8663 
8664     /* Get VDS space dimensions */
8665     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
8666         TEST_ERROR
8667     if(ndims != 2)
8668         TEST_ERROR
8669     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
8670         TEST_ERROR
8671     if(dims[0] != 10)
8672         TEST_ERROR
8673     if(dims[1] != 4)
8674         TEST_ERROR
8675     if(mdims[0] != 10)
8676         TEST_ERROR
8677     if(mdims[1] != 20)
8678         TEST_ERROR
8679 
8680     /* Close filespace */
8681     if(H5Sclose(filespace) < 0)
8682         TEST_ERROR
8683 
8684     /* Read data through virtual dataset */
8685     /* Reset rbuf */
8686     HDmemset(rbuf[0], 0, sizeof(rbuf));
8687 
8688     /* Select hyperslab in memory space */
8689     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
8690         TEST_ERROR
8691 
8692     /* Read data */
8693     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
8694         TEST_ERROR
8695 
8696     /* Verify read data */
8697     for(i = 0; i < (int)mdims[0]; i++)
8698         for(j = 0; j < (int)mdims[1]; j++) {
8699             if(j >= (int)dims[1]) {
8700                 if(rbuf[i][j] != 0)
8701                     TEST_ERROR
8702             }
8703             else
8704                 if(rbuf[i][j] != erbuf[i][j])
8705                     TEST_ERROR
8706         }
8707 
8708     /* Close VDS and reopen with view set to H5D_VDS_FIRST_MISSING, reopen file
8709      * as well if config option specified */
8710     if(H5Dclose(vdset) < 0)
8711         TEST_ERROR
8712     if(H5Pset_virtual_view(dapl, H5D_VDS_FIRST_MISSING) < 0)
8713         TEST_ERROR
8714     if(config & TEST_IO_REOPEN_VIRT) {
8715         if(H5Fclose(vfile) < 0)
8716             TEST_ERROR
8717         vfile = -1;
8718         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
8719             TEST_ERROR
8720     }
8721     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
8722         TEST_ERROR
8723 
8724     /* Get VDS space */
8725     if((filespace = H5Dget_space(vdset)) < 0)
8726         TEST_ERROR
8727 
8728     /* Get VDS space dimensions.  Make sure that the 4th slice is no longer
8729      * visible due to the change to H5D_VDS_FIRST_MISSING. */
8730     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
8731         TEST_ERROR
8732     if(ndims != 2)
8733         TEST_ERROR
8734     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
8735         TEST_ERROR
8736     if(dims[0] != 10)
8737         TEST_ERROR
8738     if(dims[1] != 2)
8739         TEST_ERROR
8740     if(mdims[0] != 10)
8741         TEST_ERROR
8742     if(mdims[1] != 20)
8743         TEST_ERROR
8744 
8745     /* Close filespace */
8746     if(H5Sclose(filespace) < 0)
8747         TEST_ERROR
8748 
8749     /* Read data through virtual dataset */
8750     /* Reset rbuf */
8751     HDmemset(rbuf[0], 0, sizeof(rbuf));
8752 
8753     /* Select hyperslab in memory space */
8754     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
8755         TEST_ERROR
8756 
8757     /* Read data */
8758     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
8759         TEST_ERROR
8760 
8761     /* Verify read data */
8762     for(i = 0; i < (int)mdims[0]; i++)
8763         for(j = 0; j < (int)mdims[1]; j++) {
8764             if(j >= (int)dims[1]) {
8765                 if(rbuf[i][j] != 0)
8766                     TEST_ERROR
8767             }
8768             else
8769                 if(rbuf[i][j] != erbuf[i][j])
8770                     TEST_ERROR
8771         }
8772 
8773     /* Reopen srcfile if config option specified */
8774     if((config & TEST_IO_CLOSE_SRC) && (config & TEST_IO_DIFFERENT_FILE))
8775         if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
8776             TEST_ERROR
8777 
8778     /* Create 4th source dataset */
8779     if((srcdset[3] = H5Dcreate2(srcfile[0], "2src_dset_a2%", H5T_NATIVE_INT, srcspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
8780         TEST_ERROR
8781 
8782     /* Adjust write buffer */
8783     for(i = 0; i < (int)mdims[0]; i++)
8784         for(j = 0; j < (int)mdims[1]; j++)
8785             buf[i][j] += (int)mdims[0] * (int)mdims[1];
8786 
8787     /* Write to srcdset[3] */
8788     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
8789         TEST_ERROR
8790     if(H5Dwrite(srcdset[3], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
8791         TEST_ERROR
8792 
8793     /* Update erbuf */
8794     for(i = 0; i < 10; i++)
8795         erbuf[i][4] = buf[i][0];
8796 
8797     /* Close srcdset[3] and srcfile if config option specified */
8798     if(config & TEST_IO_CLOSE_SRC) {
8799         if(H5Dclose(srcdset[3]) < 0)
8800             TEST_ERROR
8801         srcdset[3] = -1;
8802 
8803         if(config & TEST_IO_DIFFERENT_FILE) {
8804             if(H5Fclose(srcfile[0]) < 0)
8805                 TEST_ERROR
8806             srcfile[0] = -1;
8807         }
8808     }
8809 
8810     /* Reopen virtual dataset and file if config option specified */
8811     if(config & TEST_IO_REOPEN_VIRT) {
8812         if(H5Dclose(vdset) < 0)
8813             TEST_ERROR
8814         vdset = -1;
8815         if(H5Fclose(vfile) < 0)
8816             TEST_ERROR
8817         vfile = -1;
8818         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
8819             TEST_ERROR
8820         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
8821             TEST_ERROR
8822     }
8823 
8824     /* Get VDS space */
8825     if((filespace = H5Dget_space(vdset)) < 0)
8826         TEST_ERROR
8827 
8828     /* Get VDS space dimensions */
8829     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
8830         TEST_ERROR
8831     if(ndims != 2)
8832         TEST_ERROR
8833     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
8834         TEST_ERROR
8835     if(dims[0] != 10)
8836         TEST_ERROR
8837     if(dims[1] != 2)
8838         TEST_ERROR
8839     if(mdims[0] != 10)
8840         TEST_ERROR
8841     if(mdims[1] != 20)
8842         TEST_ERROR
8843 
8844     /* Close filespace */
8845     if(H5Sclose(filespace) < 0)
8846         TEST_ERROR
8847 
8848     /* Read data through virtual dataset */
8849     /* Reset rbuf */
8850     HDmemset(rbuf[0], 0, sizeof(rbuf));
8851 
8852     /* Select hyperslab in memory space */
8853     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
8854         TEST_ERROR
8855 
8856     /* Read data */
8857     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
8858         TEST_ERROR
8859 
8860     /* Verify read data */
8861     for(i = 0; i < (int)mdims[0]; i++)
8862         for(j = 0; j < (int)mdims[1]; j++) {
8863             if(j >= (int)dims[1]) {
8864                 if(rbuf[i][j] != 0)
8865                     TEST_ERROR
8866             }
8867             else
8868                 if(rbuf[i][j] != erbuf[i][j])
8869                     TEST_ERROR
8870         }
8871 
8872     /* Close VDS and reopen with view set to H5D_VDS_LAST_AVAILABLE, reopen file
8873      * as well if config option specified */
8874     if(H5Dclose(vdset) < 0)
8875         TEST_ERROR
8876     if(H5Pset_virtual_view(dapl, H5D_VDS_LAST_AVAILABLE) < 0)
8877         TEST_ERROR
8878     if(config & TEST_IO_REOPEN_VIRT) {
8879         if(H5Fclose(vfile) < 0)
8880             TEST_ERROR
8881         vfile = -1;
8882         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
8883             TEST_ERROR
8884     }
8885     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
8886         TEST_ERROR
8887 
8888     /* Get VDS space */
8889     if((filespace = H5Dget_space(vdset)) < 0)
8890         TEST_ERROR
8891 
8892     /* Get VDS space dimensions.  Make sure that the 4th slice is now visible
8893      * due to the change to H5D_VDS_LAST_AVAILABLE. */
8894     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
8895         TEST_ERROR
8896     if(ndims != 2)
8897         TEST_ERROR
8898     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
8899         TEST_ERROR
8900     if(dims[0] != 10)
8901         TEST_ERROR
8902     if(dims[1] != 4)
8903         TEST_ERROR
8904     if(mdims[0] != 10)
8905         TEST_ERROR
8906     if(mdims[1] != 20)
8907         TEST_ERROR
8908 
8909     /* Close filespace */
8910     if(H5Sclose(filespace) < 0)
8911         TEST_ERROR
8912 
8913     /* Read data through virtual dataset */
8914     /* Reset rbuf */
8915     HDmemset(rbuf[0], 0, sizeof(rbuf));
8916 
8917     /* Select hyperslab in memory space */
8918     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
8919         TEST_ERROR
8920 
8921     /* Read data */
8922     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
8923         TEST_ERROR
8924 
8925     /* Verify read data */
8926     for(i = 0; i < (int)mdims[0]; i++)
8927         for(j = 0; j < (int)mdims[1]; j++) {
8928             if(j >= (int)dims[1]) {
8929                 if(rbuf[i][j] != 0)
8930                     TEST_ERROR
8931             }
8932             else
8933                 if(rbuf[i][j] != erbuf[i][j])
8934                     TEST_ERROR
8935         }
8936 
8937     /* Close VDS and reopen with printf_gap set to 1, reopen file as well if
8938      * config option specified */
8939     if(H5Dclose(vdset) < 0)
8940         TEST_ERROR
8941     if(H5Pset_virtual_printf_gap(dapl, (hsize_t)1) < 0)
8942         TEST_ERROR
8943     if(config & TEST_IO_REOPEN_VIRT) {
8944         if(H5Fclose(vfile) < 0)
8945             TEST_ERROR
8946         vfile = -1;
8947         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
8948             TEST_ERROR
8949     }
8950     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
8951         TEST_ERROR
8952 
8953     /* Get VDS space */
8954     if((filespace = H5Dget_space(vdset)) < 0)
8955         TEST_ERROR
8956 
8957     /* Get VDS space dimensions.  Make sure that the 6th slice is now visible
8958      * due to the change to printf_gap. */
8959     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
8960         TEST_ERROR
8961     if(ndims != 2)
8962         TEST_ERROR
8963     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
8964         TEST_ERROR
8965     if(dims[0] != 10)
8966         TEST_ERROR
8967     if(dims[1] != 5)
8968         TEST_ERROR
8969     if(mdims[0] != 10)
8970         TEST_ERROR
8971     if(mdims[1] != 20)
8972         TEST_ERROR
8973 
8974     /* Close filespace */
8975     if(H5Sclose(filespace) < 0)
8976         TEST_ERROR
8977 
8978     /* Read data through virtual dataset */
8979     /* Reset rbuf */
8980     HDmemset(rbuf[0], 0, sizeof(rbuf));
8981 
8982     /* Select hyperslab in memory space */
8983     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
8984         TEST_ERROR
8985 
8986     /* Read data */
8987     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
8988         TEST_ERROR
8989 
8990     /* Verify read data */
8991     for(i = 0; i < (int)mdims[0]; i++)
8992         for(j = 0; j < (int)mdims[1]; j++) {
8993             if(j >= (int)dims[1]) {
8994                 if(rbuf[i][j] != 0)
8995                     TEST_ERROR
8996             }
8997             else
8998                 if(rbuf[i][j] != erbuf[i][j])
8999                     TEST_ERROR
9000         }
9001 
9002     /* Reset dapl */
9003     if(H5Pset_virtual_printf_gap(dapl, (hsize_t)0) < 0)
9004         TEST_ERROR
9005     if(H5Pset_virtual_view(dapl, H5D_VDS_LAST_AVAILABLE) < 0)
9006         TEST_ERROR
9007 
9008     /* Close */
9009     if(!(config & TEST_IO_CLOSE_SRC)) {
9010         for(i = 0; i < 4; i++) {
9011             if(H5Dclose(srcdset[i]) < 0)
9012                 TEST_ERROR
9013             srcdset[i] = -1;
9014         }
9015         if(H5Fclose(srcfile[0]) < 0)
9016             TEST_ERROR
9017         srcfile[0] = -1;
9018     }
9019     else if(!(config & TEST_IO_DIFFERENT_FILE)) {
9020         if(H5Fclose(srcfile[0]) < 0)
9021             TEST_ERROR
9022         srcfile[0] = -1;
9023     }
9024     if(H5Dclose(vdset) < 0)
9025         TEST_ERROR
9026     vdset = -1;
9027     if(H5Fclose(vfile) < 0)
9028         TEST_ERROR
9029     vfile = -1;
9030     if(H5Sclose(srcspace) < 0)
9031         TEST_ERROR
9032     srcspace = -1;
9033     if(H5Sclose(vspace[0]) < 0)
9034         TEST_ERROR
9035     vspace[0] = -1;
9036     if(H5Sclose(vspace[1]) < 0)
9037         TEST_ERROR
9038     vspace[1] = -1;
9039 
9040 
9041     /*
9042      * Test 6: 2 Source mappings, side-by-side, 5x5 and 5x10 blocks
9043      */
9044     /* Clear virtual layout in DCPL */
9045     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
9046         TEST_ERROR
9047 
9048     /* Create virtual dataspaces */
9049     dims[0] = 10;
9050     dims[1] = 10;
9051     if((vspace[0] = H5Screate_simple(2, dims, mdims)) < 0)
9052         TEST_ERROR
9053     if((vspace[1] = H5Screate_simple(2, dims, mdims)) < 0)
9054         TEST_ERROR
9055 
9056     /* Create source dataspace (1 dimensional) */
9057     dims[0] = 50;
9058     if((srcspace = H5Screate_simple(1, dims, NULL)) < 0)
9059         TEST_ERROR
9060 
9061     /* Select hyperslab in source space */
9062     count[0] = 25;
9063     if(H5Sselect_hyperslab(srcspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
9064         TEST_ERROR
9065 
9066     /* Select hyperslabs in virtual spaces */
9067     stride[0] = 1;
9068     stride[1] = 5;
9069     count[0] = 1;
9070     count[1] = H5S_UNLIMITED;
9071     block[0] = 5;
9072     block[1] = 5;
9073     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, stride, count, block) < 0)
9074         TEST_ERROR
9075     start[0] = 5;
9076     stride[1] = 10;
9077     block[1] = 10;
9078     if(H5Sselect_hyperslab(vspace[1], H5S_SELECT_SET, start, stride, count, block) < 0)
9079         TEST_ERROR
9080     start[0] = 0;
9081 
9082     /* Add virtual layout mappings (select ALL in source space for second
9083      * mapping) */
9084     if(H5Pset_virtual(dcpl, vspace[0], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset_a%b", srcspace) < 0)
9085         TEST_ERROR
9086     if(H5Sselect_all(srcspace) < 0)
9087         TEST_ERROR
9088     if(H5Pset_virtual(dcpl, vspace[1], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset_b%b", srcspace) < 0)
9089         TEST_ERROR
9090 
9091     /* Create virtual file */
9092     if((vfile = H5Fcreate(vfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
9093         TEST_ERROR
9094 
9095     /* Create source file if requested */
9096     if(config & TEST_IO_DIFFERENT_FILE) {
9097         if((srcfile[0] = H5Fcreate(srcfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
9098             TEST_ERROR
9099     }
9100     else {
9101         srcfile[0] = vfile;
9102         if(H5Iinc_ref(srcfile[0]) < 0)
9103             TEST_ERROR
9104     }
9105 
9106     /* Create virtual dataset */
9107     if((vdset = H5Dcreate2(vfile, "v_dset", H5T_NATIVE_INT, vspace[0], H5P_DEFAULT, dcpl, dapl)) < 0)
9108         TEST_ERROR
9109 
9110     /* Close srcfile if config option specified */
9111     if(config & TEST_IO_CLOSE_SRC)
9112         if(config & TEST_IO_DIFFERENT_FILE) {
9113             if(H5Fclose(srcfile[0]) < 0)
9114                 TEST_ERROR
9115             srcfile[0] = -1;
9116         }
9117 
9118     /* Reopen virtual dataset and file if config option specified */
9119     if(config & TEST_IO_REOPEN_VIRT) {
9120         if(H5Dclose(vdset) < 0)
9121             TEST_ERROR
9122         vdset = -1;
9123         if(H5Fclose(vfile) < 0)
9124             TEST_ERROR
9125         vfile = -1;
9126         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
9127             TEST_ERROR
9128         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
9129             TEST_ERROR
9130     }
9131 
9132     /* Get VDS space */
9133     if((filespace = H5Dget_space(vdset)) < 0)
9134         TEST_ERROR
9135 
9136     /* Get VDS space dimensions */
9137     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
9138         TEST_ERROR
9139     if(ndims != 2)
9140         TEST_ERROR
9141     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
9142         TEST_ERROR
9143     if(dims[0] != 10)
9144         TEST_ERROR
9145     if(dims[1] != 0)
9146         TEST_ERROR
9147     if(mdims[0] != 10)
9148         TEST_ERROR
9149     if(mdims[1] != 20)
9150         TEST_ERROR
9151 
9152     /* Close filespace */
9153     if(H5Sclose(filespace) < 0)
9154         TEST_ERROR
9155 
9156     /* Reopen srcfile if config option specified */
9157     if(config & TEST_IO_CLOSE_SRC)
9158         if(config & TEST_IO_DIFFERENT_FILE)
9159             if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
9160                 TEST_ERROR
9161 
9162     /* Create 2 source datasets */
9163     if((srcdset[0] = H5Dcreate2(srcfile[0], "src_dset_a0", H5T_NATIVE_INT, srcspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
9164         TEST_ERROR
9165     if((srcdset[1] = H5Dcreate2(srcfile[0], "src_dset_b0", H5T_NATIVE_INT, srcspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
9166         TEST_ERROR
9167 
9168     /* Populate write buffer */
9169     for(i = 0; i < (int)mdims[0]; i++)
9170         for(j = 0; j < (int)mdims[1]; j++)
9171             buf[i][j] = (i * (int)mdims[1]) + j;
9172 
9173     /* Initialize erbuf */
9174     for(i = 0; i < (int)mdims[0]; i++)
9175         for(j = 0; j < (int)mdims[1]; j++)
9176             erbuf[i][j] = fill;
9177 
9178     /* Write to srcdset[0] */
9179     block[0] = 5;
9180     block[1] = 5;
9181     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
9182         TEST_ERROR
9183     count[0] = 25;
9184     if(H5Sselect_hyperslab(srcspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
9185         TEST_ERROR
9186     if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, memspace, srcspace, H5P_DEFAULT, buf[0]) < 0)
9187         TEST_ERROR
9188 
9189     /* Update erbuf */
9190     for(i = 0; i < 5; i++)
9191         for(j = 0; j < 5; j++)
9192             erbuf[i][j] = buf[i][j];
9193 
9194     /* Adjust write buffer */
9195     for(i = 0; i < (int)mdims[0]; i++)
9196         for(j = 0; j < (int)mdims[1]; j++)
9197             buf[i][j] += (int)mdims[0] * (int)mdims[1];
9198 
9199     /* Write to srcdset[1] */
9200     block[1] = 10;
9201     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
9202         TEST_ERROR
9203     if(H5Sselect_all(srcspace) < 0)
9204         TEST_ERROR
9205     if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, memspace, srcspace, H5P_DEFAULT, buf[0]) < 0)
9206         TEST_ERROR
9207 
9208     /* Update erbuf */
9209     for(i = 0; i < 5; i++)
9210         for(j = 0; j < 10; j++)
9211             erbuf[i + 5][j] = buf[i][j];
9212 
9213     /* Close srcdsets and srcfile if config option specified */
9214     if(config & TEST_IO_CLOSE_SRC) {
9215         if(H5Dclose(srcdset[0]) < 0)
9216             TEST_ERROR
9217         srcdset[0] = -1;
9218         if(H5Dclose(srcdset[1]) < 0)
9219             TEST_ERROR
9220         srcdset[1] = -1;
9221 
9222         if(config & TEST_IO_DIFFERENT_FILE) {
9223             if(H5Fclose(srcfile[0]) < 0)
9224                 TEST_ERROR
9225             srcfile[0] = -1;
9226         }
9227     }
9228 
9229     /* Reopen virtual dataset and file if config option specified */
9230     if(config & TEST_IO_REOPEN_VIRT) {
9231         if(H5Dclose(vdset) < 0)
9232             TEST_ERROR
9233         vdset = -1;
9234         if(H5Fclose(vfile) < 0)
9235             TEST_ERROR
9236         vfile = -1;
9237         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
9238             TEST_ERROR
9239         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
9240             TEST_ERROR
9241     }
9242 
9243     /* Get VDS space */
9244     if((filespace = H5Dget_space(vdset)) < 0)
9245         TEST_ERROR
9246 
9247     /* Get VDS space dimensions */
9248     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
9249         TEST_ERROR
9250     if(ndims != 2)
9251         TEST_ERROR
9252     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
9253         TEST_ERROR
9254     if(dims[0] != 10)
9255         TEST_ERROR
9256     if(dims[1] != 10)
9257         TEST_ERROR
9258     if(mdims[0] != 10)
9259         TEST_ERROR
9260     if(mdims[1] != 20)
9261         TEST_ERROR
9262 
9263     /* Close filespace */
9264     if(H5Sclose(filespace) < 0)
9265         TEST_ERROR
9266 
9267     /* Read data through virtual dataset */
9268     /* Reset rbuf */
9269     HDmemset(rbuf[0], 0, sizeof(rbuf));
9270 
9271     /* Select hyperslab in memory space */
9272     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
9273         TEST_ERROR
9274 
9275     /* Read data */
9276     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
9277         TEST_ERROR
9278 
9279     /* Verify read data */
9280     for(i = 0; i < (int)mdims[0]; i++)
9281         for(j = 0; j < (int)mdims[1]; j++) {
9282             if(j >= (int)dims[1]) {
9283                 if(rbuf[i][j] != 0)
9284                     TEST_ERROR
9285             }
9286             else
9287                 if(rbuf[i][j] != erbuf[i][j])
9288                     TEST_ERROR
9289         }
9290 
9291     /* Close VDS and reopen with view set to H5D_VDS_FIRST_MISSING, reopen file
9292      * as well if config option specified */
9293     if(H5Dclose(vdset) < 0)
9294         TEST_ERROR
9295     if(H5Pset_virtual_view(dapl, H5D_VDS_FIRST_MISSING) < 0)
9296         TEST_ERROR
9297     if(config & TEST_IO_REOPEN_VIRT) {
9298         if(H5Fclose(vfile) < 0)
9299             TEST_ERROR
9300         vfile = -1;
9301         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
9302             TEST_ERROR
9303     }
9304     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
9305         TEST_ERROR
9306 
9307     /* Get VDS space */
9308     if((filespace = H5Dget_space(vdset)) < 0)
9309         TEST_ERROR
9310 
9311     /* Get VDS space dimensions.  Make sure that the 4th slice is no longer
9312      * visible due to the change to H5D_VDS_FIRST_MISSING. */
9313     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
9314         TEST_ERROR
9315     if(ndims != 2)
9316         TEST_ERROR
9317     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
9318         TEST_ERROR
9319     if(dims[0] != 10)
9320         TEST_ERROR
9321     if(dims[1] != 5)
9322         TEST_ERROR
9323     if(mdims[0] != 10)
9324         TEST_ERROR
9325     if(mdims[1] != 20)
9326         TEST_ERROR
9327 
9328     /* Close filespace */
9329     if(H5Sclose(filespace) < 0)
9330         TEST_ERROR
9331 
9332     /* Read data through virtual dataset */
9333     /* Reset rbuf */
9334     HDmemset(rbuf[0], 0, sizeof(rbuf));
9335 
9336     /* Select hyperslab in memory space */
9337     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
9338         TEST_ERROR
9339 
9340     /* Read data */
9341     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
9342         TEST_ERROR
9343 
9344     /* Verify read data */
9345     for(i = 0; i < (int)mdims[0]; i++)
9346         for(j = 0; j < (int)mdims[1]; j++) {
9347             if(j >= (int)dims[1]) {
9348                 if(rbuf[i][j] != 0)
9349                     TEST_ERROR
9350             }
9351             else
9352                 if(rbuf[i][j] != erbuf[i][j])
9353                     TEST_ERROR
9354         }
9355 
9356     /* Reopen srcfile if config option specified */
9357     if((config & TEST_IO_CLOSE_SRC) && (config & TEST_IO_DIFFERENT_FILE))
9358         if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
9359             TEST_ERROR
9360 
9361     /* Create 3rd source dataset */
9362     if((srcdset[2] = H5Dcreate2(srcfile[0], "src_dset_a1", H5T_NATIVE_INT, srcspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
9363         TEST_ERROR
9364 
9365     /* Adjust write buffer */
9366     for(i = 0; i < (int)mdims[0]; i++)
9367         for(j = 0; j < (int)mdims[1]; j++)
9368             buf[i][j] += (int)mdims[0] * (int)mdims[1];
9369 
9370     /* Write to srcdset[2] */
9371     block[1] = 5;
9372     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
9373         TEST_ERROR
9374     if(H5Sselect_hyperslab(srcspace, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
9375         TEST_ERROR
9376     if(H5Dwrite(srcdset[2], H5T_NATIVE_INT, memspace, srcspace, H5P_DEFAULT, buf[0]) < 0)
9377         TEST_ERROR
9378 
9379     /* Update erbuf */
9380     for(i = 0; i < 5; i++)
9381         for(j = 0; j < 5; j++)
9382             erbuf[i][j + 5] = buf[i][j];
9383 
9384     /* Close srcdset[2] and srcfile if config option specified */
9385     if(config & TEST_IO_CLOSE_SRC) {
9386         if(H5Dclose(srcdset[2]) < 0)
9387             TEST_ERROR
9388         srcdset[2] = -1;
9389 
9390         if(config & TEST_IO_DIFFERENT_FILE) {
9391             if(H5Fclose(srcfile[0]) < 0)
9392                 TEST_ERROR
9393             srcfile[0] = -1;
9394         }
9395     }
9396 
9397     /* Reopen virtual dataset and file if config option specified */
9398     if(config & TEST_IO_REOPEN_VIRT) {
9399         if(H5Dclose(vdset) < 0)
9400             TEST_ERROR
9401         vdset = -1;
9402         if(H5Fclose(vfile) < 0)
9403             TEST_ERROR
9404         vfile = -1;
9405         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
9406             TEST_ERROR
9407         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
9408             TEST_ERROR
9409     }
9410 
9411     /* Get VDS space */
9412     if((filespace = H5Dget_space(vdset)) < 0)
9413         TEST_ERROR
9414 
9415     /* Get VDS space dimensions */
9416     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
9417         TEST_ERROR
9418     if(ndims != 2)
9419         TEST_ERROR
9420     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
9421         TEST_ERROR
9422     if(dims[0] != 10)
9423         TEST_ERROR
9424     if(dims[1] != 10)
9425         TEST_ERROR
9426     if(mdims[0] != 10)
9427         TEST_ERROR
9428     if(mdims[1] != 20)
9429         TEST_ERROR
9430 
9431     /* Close filespace */
9432     if(H5Sclose(filespace) < 0)
9433         TEST_ERROR
9434 
9435     /* Read data through virtual dataset */
9436     /* Reset rbuf */
9437     HDmemset(rbuf[0], 0, sizeof(rbuf));
9438 
9439     /* Select hyperslab in memory space */
9440     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
9441         TEST_ERROR
9442 
9443     /* Read data */
9444     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
9445         TEST_ERROR
9446 
9447     /* Verify read data */
9448     for(i = 0; i < (int)mdims[0]; i++)
9449         for(j = 0; j < (int)mdims[1]; j++) {
9450             if(j >= (int)dims[1]) {
9451                 if(rbuf[i][j] != 0)
9452                     TEST_ERROR
9453             }
9454             else
9455                 if(rbuf[i][j] != erbuf[i][j])
9456                     TEST_ERROR
9457         }
9458 
9459     /* Close VDS and reopen with view set to H5D_VDS_LAST_AVAILABLE, reopen file
9460      * as well if config option specified */
9461     if(H5Dclose(vdset) < 0)
9462         TEST_ERROR
9463     if(H5Pset_virtual_view(dapl, H5D_VDS_LAST_AVAILABLE) < 0)
9464         TEST_ERROR
9465     if(config & TEST_IO_REOPEN_VIRT) {
9466         if(H5Fclose(vfile) < 0)
9467             TEST_ERROR
9468         vfile = -1;
9469         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
9470             TEST_ERROR
9471     }
9472     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
9473         TEST_ERROR
9474 
9475     /* Get VDS space */
9476     if((filespace = H5Dget_space(vdset)) < 0)
9477         TEST_ERROR
9478 
9479     /* Get VDS space dimensions.  There should be no change. */
9480     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
9481         TEST_ERROR
9482     if(ndims != 2)
9483         TEST_ERROR
9484     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
9485         TEST_ERROR
9486     if(dims[0] != 10)
9487         TEST_ERROR
9488     if(dims[1] != 10)
9489         TEST_ERROR
9490     if(mdims[0] != 10)
9491         TEST_ERROR
9492     if(mdims[1] != 20)
9493         TEST_ERROR
9494 
9495     /* Close filespace */
9496     if(H5Sclose(filespace) < 0)
9497         TEST_ERROR
9498 
9499     /* Read data through virtual dataset */
9500     /* Reset rbuf */
9501     HDmemset(rbuf[0], 0, sizeof(rbuf));
9502 
9503     /* Select hyperslab in memory space */
9504     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
9505         TEST_ERROR
9506 
9507     /* Read data */
9508     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
9509         TEST_ERROR
9510 
9511     /* Verify read data */
9512     for(i = 0; i < (int)mdims[0]; i++)
9513         for(j = 0; j < (int)mdims[1]; j++) {
9514             if(j >= (int)dims[1]) {
9515                 if(rbuf[i][j] != 0)
9516                     TEST_ERROR
9517             }
9518             else
9519                 if(rbuf[i][j] != erbuf[i][j])
9520                     TEST_ERROR
9521         }
9522 
9523     /* Reopen srcfile if config option specified */
9524     if((config & TEST_IO_CLOSE_SRC) && (config & TEST_IO_DIFFERENT_FILE))
9525         if((srcfile[0] = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
9526             TEST_ERROR
9527 
9528     /* Create 4th source dataset */
9529     if((srcdset[3] = H5Dcreate2(srcfile[0], "src_dset_a2", H5T_NATIVE_INT, srcspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
9530         TEST_ERROR
9531 
9532     /* Adjust write buffer */
9533     for(i = 0; i < (int)mdims[0]; i++)
9534         for(j = 0; j < (int)mdims[1]; j++)
9535             buf[i][j] += (int)mdims[0] * (int)mdims[1];
9536 
9537     /* Write to srcdset[3] */
9538     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
9539         TEST_ERROR
9540     if(H5Dwrite(srcdset[3], H5T_NATIVE_INT, memspace, srcspace, H5P_DEFAULT, buf[0]) < 0)
9541         TEST_ERROR
9542 
9543     /* Update erbuf */
9544     for(i = 0; i < 5; i++)
9545         for(j = 0; j < 5; j++)
9546             erbuf[i][j + 10] = buf[i][j];
9547 
9548     /* Close srcdset[3] and srcfile if config option specified */
9549     if(config & TEST_IO_CLOSE_SRC) {
9550         if(H5Dclose(srcdset[3]) < 0)
9551             TEST_ERROR
9552         srcdset[3] = -1;
9553 
9554         if(config & TEST_IO_DIFFERENT_FILE) {
9555             if(H5Fclose(srcfile[0]) < 0)
9556                 TEST_ERROR
9557             srcfile[0] = -1;
9558         }
9559     }
9560 
9561     /* Reopen virtual dataset and file if config option specified */
9562     if(config & TEST_IO_REOPEN_VIRT) {
9563         if(H5Dclose(vdset) < 0)
9564             TEST_ERROR
9565         vdset = -1;
9566         if(H5Fclose(vfile) < 0)
9567             TEST_ERROR
9568         vfile = -1;
9569         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
9570             TEST_ERROR
9571         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
9572             TEST_ERROR
9573     }
9574 
9575     /* Get VDS space */
9576     if((filespace = H5Dget_space(vdset)) < 0)
9577         TEST_ERROR
9578 
9579     /* Get VDS space dimensions */
9580     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
9581         TEST_ERROR
9582     if(ndims != 2)
9583         TEST_ERROR
9584     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
9585         TEST_ERROR
9586     if(dims[0] != 10)
9587         TEST_ERROR
9588     if(dims[1] != 15)
9589         TEST_ERROR
9590     if(mdims[0] != 10)
9591         TEST_ERROR
9592     if(mdims[1] != 20)
9593         TEST_ERROR
9594 
9595     /* Close filespace */
9596     if(H5Sclose(filespace) < 0)
9597         TEST_ERROR
9598 
9599     /* Read data through virtual dataset */
9600     /* Reset rbuf */
9601     HDmemset(rbuf[0], 0, sizeof(rbuf));
9602 
9603     /* Select hyperslab in memory space */
9604     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
9605         TEST_ERROR
9606 
9607     /* Read data */
9608     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
9609         TEST_ERROR
9610 
9611     /* Verify read data */
9612     for(i = 0; i < (int)mdims[0]; i++)
9613         for(j = 0; j < (int)mdims[1]; j++) {
9614             if(j >= (int)dims[1]) {
9615                 if(rbuf[i][j] != 0)
9616                     TEST_ERROR
9617             }
9618             else
9619                 if(rbuf[i][j] != erbuf[i][j])
9620                     TEST_ERROR
9621         }
9622 
9623     /* Now test reopening virtual dataset without calling H5Dget_space, if
9624      * REOPEN_VIRT flag set */
9625     if(config & TEST_IO_REOPEN_VIRT) {
9626         if(H5Dclose(vdset) < 0)
9627             TEST_ERROR
9628         vdset = -1;
9629         if(H5Fclose(vfile) < 0)
9630             TEST_ERROR
9631         vfile = -1;
9632         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
9633             TEST_ERROR
9634         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
9635             TEST_ERROR
9636 
9637         /* Read data through virtual dataset */
9638         /* Reset rbuf */
9639         HDmemset(rbuf[0], 0, sizeof(rbuf));
9640 
9641         /* Select hyperslab in memory space */
9642         if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
9643             TEST_ERROR
9644 
9645         /* Read data */
9646         if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
9647             TEST_ERROR
9648 
9649         /* Verify read data */
9650         for(i = 0; i < (int)mdims[0]; i++)
9651             for(j = 0; j < (int)mdims[1]; j++) {
9652                 if(j >= (int)dims[1]) {
9653                     if(rbuf[i][j] != 0)
9654                         TEST_ERROR
9655                 }
9656                 else
9657                     if(rbuf[i][j] != erbuf[i][j])
9658                         TEST_ERROR
9659             }
9660 
9661         /* Now try setting extent manually */
9662         /* Shrink to 12 */
9663         dims[1] = 12;
9664         if(H5Dset_extent(vdset, dims) < 0)
9665             TEST_ERROR
9666 
9667         /* Read data through virtual dataset */
9668         /* Reset rbuf */
9669         HDmemset(rbuf[0], 0, sizeof(rbuf));
9670 
9671         /* Select hyperslab in memory space */
9672         if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
9673             TEST_ERROR
9674 
9675         /* Read data */
9676         if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
9677             TEST_ERROR
9678 
9679         /* Verify read data */
9680         for(i = 0; i < (int)mdims[0]; i++)
9681             for(j = 0; j < (int)mdims[1]; j++) {
9682                 if(j >= (int)dims[1]) {
9683                     if(rbuf[i][j] != 0)
9684                         TEST_ERROR
9685                 }
9686                 else
9687                     if(rbuf[i][j] != erbuf[i][j])
9688                         TEST_ERROR
9689             }
9690 
9691         /* Shrink to 10 */
9692         dims[1] = 12;
9693         if(H5Dset_extent(vdset, dims) < 0)
9694             TEST_ERROR
9695 
9696         /* Read data through virtual dataset */
9697         /* Reset rbuf */
9698         HDmemset(rbuf[0], 0, sizeof(rbuf));
9699 
9700         /* Select hyperslab in memory space */
9701         if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
9702             TEST_ERROR
9703 
9704         /* Read data */
9705         if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
9706             TEST_ERROR
9707 
9708         /* Verify read data */
9709         for(i = 0; i < (int)mdims[0]; i++)
9710             for(j = 0; j < (int)mdims[1]; j++) {
9711                 if(j >= (int)dims[1]) {
9712                     if(rbuf[i][j] != 0)
9713                         TEST_ERROR
9714                 }
9715                 else
9716                     if(rbuf[i][j] != erbuf[i][j])
9717                         TEST_ERROR
9718             }
9719     }
9720 
9721     /* Close VDS and reopen with view set to H5D_VDS_FIRST_MISSING, reopen file
9722      * as well if config option specified */
9723     if(H5Dclose(vdset) < 0)
9724         TEST_ERROR
9725     if(H5Pset_virtual_view(dapl, H5D_VDS_FIRST_MISSING) < 0)
9726         TEST_ERROR
9727     if(config & TEST_IO_REOPEN_VIRT) {
9728         if(H5Fclose(vfile) < 0)
9729             TEST_ERROR
9730         vfile = -1;
9731         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
9732             TEST_ERROR
9733     }
9734     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
9735         TEST_ERROR
9736 
9737     /* Get VDS space */
9738     if((filespace = H5Dget_space(vdset)) < 0)
9739         TEST_ERROR
9740 
9741     /* Get VDS space dimensions */
9742     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
9743         TEST_ERROR
9744     if(ndims != 2)
9745         TEST_ERROR
9746     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
9747         TEST_ERROR
9748     if(dims[0] != 10)
9749         TEST_ERROR
9750     if(dims[1] != 10)
9751         TEST_ERROR
9752     if(mdims[0] != 10)
9753         TEST_ERROR
9754     if(mdims[1] != 20)
9755         TEST_ERROR
9756 
9757     /* Close filespace */
9758     if(H5Sclose(filespace) < 0)
9759         TEST_ERROR
9760 
9761     /* Read data through virtual dataset */
9762     /* Reset rbuf */
9763     HDmemset(rbuf[0], 0, sizeof(rbuf));
9764 
9765     /* Select hyperslab in memory space */
9766     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
9767         TEST_ERROR
9768 
9769     /* Read data */
9770     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
9771         TEST_ERROR
9772 
9773     /* Verify read data */
9774     for(i = 0; i < (int)mdims[0]; i++)
9775         for(j = 0; j < (int)mdims[1]; j++) {
9776             if(j >= (int)dims[1]) {
9777                 if(rbuf[i][j] != 0)
9778                     TEST_ERROR
9779             }
9780             else
9781                 if(rbuf[i][j] != erbuf[i][j])
9782                     TEST_ERROR
9783         }
9784 
9785     /* Now test reopening virtual dataset without calling H5Dget_space, if
9786      * REOPEN_VIRT flag set */
9787     if(config & TEST_IO_REOPEN_VIRT) {
9788         if(H5Dclose(vdset) < 0)
9789             TEST_ERROR
9790         vdset = -1;
9791         if(H5Fclose(vfile) < 0)
9792             TEST_ERROR
9793         vfile = -1;
9794         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
9795             TEST_ERROR
9796         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
9797             TEST_ERROR
9798 
9799         /* Read data through virtual dataset */
9800         /* Reset rbuf */
9801         HDmemset(rbuf[0], 0, sizeof(rbuf));
9802 
9803         /* Select hyperslab in memory space */
9804         if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
9805             TEST_ERROR
9806 
9807         /* Read data */
9808         if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
9809             TEST_ERROR
9810 
9811         /* Verify read data */
9812         for(i = 0; i < (int)mdims[0]; i++)
9813             for(j = 0; j < (int)mdims[1]; j++) {
9814                 if(j >= (int)dims[1]) {
9815                     if(rbuf[i][j] != 0)
9816                         TEST_ERROR
9817                 }
9818                 else
9819                     if(rbuf[i][j] != erbuf[i][j])
9820                         TEST_ERROR
9821             }
9822 
9823         /* Now try setting extent manually */
9824         /* Grow to 12 */
9825         dims[1] = 12;
9826         if(H5Dset_extent(vdset, dims) < 0)
9827             TEST_ERROR
9828 
9829         /* Read data through virtual dataset */
9830         /* Reset rbuf */
9831         HDmemset(rbuf[0], 0, sizeof(rbuf));
9832 
9833         /* Select hyperslab in memory space */
9834         if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
9835             TEST_ERROR
9836 
9837         /* Read data */
9838         if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
9839             TEST_ERROR
9840 
9841         /* Verify read data */
9842         for(i = 0; i < (int)mdims[0]; i++)
9843             for(j = 0; j < (int)mdims[1]; j++) {
9844                 if(j >= (int)dims[1]) {
9845                     if(rbuf[i][j] != 0)
9846                         TEST_ERROR
9847                 }
9848                 else
9849                     if(rbuf[i][j] != erbuf[i][j])
9850                         TEST_ERROR
9851             }
9852 
9853         /* Grow to 15 */
9854         dims[1] = 15;
9855         if(H5Dset_extent(vdset, dims) < 0)
9856             TEST_ERROR
9857 
9858         /* Read data through virtual dataset */
9859         /* Reset rbuf */
9860         HDmemset(rbuf[0], 0, sizeof(rbuf));
9861 
9862         /* Select hyperslab in memory space */
9863         if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
9864             TEST_ERROR
9865 
9866         /* Read data */
9867         if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
9868             TEST_ERROR
9869 
9870         /* Verify read data */
9871         for(i = 0; i < (int)mdims[0]; i++)
9872             for(j = 0; j < (int)mdims[1]; j++) {
9873                 if(j >= (int)dims[1]) {
9874                     if(rbuf[i][j] != 0)
9875                         TEST_ERROR
9876                 }
9877                 else
9878                     if(rbuf[i][j] != erbuf[i][j])
9879                         TEST_ERROR
9880             }
9881     }
9882 
9883     /* Reset dapl */
9884     if(H5Pset_virtual_view(dapl, H5D_VDS_LAST_AVAILABLE) < 0)
9885         TEST_ERROR
9886 
9887     /* Close */
9888     if(!(config & TEST_IO_CLOSE_SRC)) {
9889         for(i = 0; i < 4; i++) {
9890             if(H5Dclose(srcdset[i]) < 0)
9891                 TEST_ERROR
9892             srcdset[i] = -1;
9893         }
9894         if(H5Fclose(srcfile[0]) < 0)
9895             TEST_ERROR
9896         srcfile[0] = -1;
9897     }
9898     else if(!(config & TEST_IO_DIFFERENT_FILE)) {
9899         if(H5Fclose(srcfile[0]) < 0)
9900             TEST_ERROR
9901         srcfile[0] = -1;
9902     }
9903     if(H5Dclose(vdset) < 0)
9904         TEST_ERROR
9905     vdset = -1;
9906     if(H5Fclose(vfile) < 0)
9907         TEST_ERROR
9908     vfile = -1;
9909     if(H5Sclose(srcspace) < 0)
9910         TEST_ERROR
9911     srcspace = -1;
9912     if(H5Sclose(vspace[0]) < 0)
9913         TEST_ERROR
9914     vspace[0] = -1;
9915     if(H5Sclose(vspace[1]) < 0)
9916         TEST_ERROR
9917     vspace[1] = -1;
9918 
9919 
9920     /*
9921      * Test 7: 1 Source dataset mapping, 10x1 blocks, test reallocating sub_dset
9922      * array
9923      */
9924     /* Clear virtual layout in DCPL */
9925     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
9926         TEST_ERROR
9927 
9928     /* Create virtual dataspaces */
9929     if((vspace[0] = H5Screate_simple(2, dims, mdims)) < 0)
9930         TEST_ERROR
9931 
9932     /* Create source dataspace */
9933     dims[1] = 1;
9934     if((srcspace = H5Screate_simple(2, dims, NULL)) < 0)
9935         TEST_ERROR
9936 
9937     /* Select hyperslabs in virtual space */
9938     stride[0] = 1;
9939     stride[1] = 1;
9940     count[0] = 1;
9941     count[1] = H5S_UNLIMITED;
9942     block[0] = 10;
9943     block[1] = 1;
9944     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, stride, count, block) < 0)
9945         TEST_ERROR
9946 
9947     /* Add virtual layout mapping */
9948     if(H5Pset_virtual(dcpl, vspace[0], config & TEST_IO_DIFFERENT_FILE ? srcfilenamepct_map : ".", "src_dset%b", srcspace) < 0)
9949         TEST_ERROR
9950 
9951     /* Create virtual file */
9952     if((vfile = H5Fcreate(vfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
9953         TEST_ERROR
9954 
9955     /* Create source file if requested */
9956     if(config & TEST_IO_DIFFERENT_FILE) {
9957         if((srcfile[0] = H5Fcreate(srcfilenamepct, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
9958             TEST_ERROR
9959     }
9960     else {
9961         srcfile[0] = vfile;
9962         if(H5Iinc_ref(srcfile[0]) < 0)
9963             TEST_ERROR
9964     }
9965 
9966     /* Create virtual dataset */
9967     if((vdset = H5Dcreate2(vfile, "v_dset", H5T_NATIVE_INT, vspace[0], H5P_DEFAULT, dcpl, dapl)) < 0)
9968         TEST_ERROR
9969 
9970     /* Close srcfile if config option specified */
9971     if(config & TEST_IO_CLOSE_SRC)
9972         if(config & TEST_IO_DIFFERENT_FILE) {
9973             if(H5Fclose(srcfile[0]) < 0)
9974                 TEST_ERROR
9975             srcfile[0] = -1;
9976         }
9977 
9978     /* Reopen virtual dataset and file if config option specified */
9979     if(config & TEST_IO_REOPEN_VIRT) {
9980         if(H5Dclose(vdset) < 0)
9981             TEST_ERROR
9982         vdset = -1;
9983         if(H5Fclose(vfile) < 0)
9984             TEST_ERROR
9985         vfile = -1;
9986         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
9987             TEST_ERROR
9988         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
9989             TEST_ERROR
9990     }
9991 
9992     /* Get VDS space */
9993     if((filespace = H5Dget_space(vdset)) < 0)
9994         TEST_ERROR
9995 
9996     /* Get VDS space dimensions */
9997     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
9998         TEST_ERROR
9999     if(ndims != 2)
10000         TEST_ERROR
10001     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
10002         TEST_ERROR
10003     if(dims[0] != 10)
10004         TEST_ERROR
10005     if(dims[1] != 0)
10006         TEST_ERROR
10007     if(mdims[0] != 10)
10008         TEST_ERROR
10009     if(mdims[1] != 20)
10010         TEST_ERROR
10011 
10012     /* Close filespace */
10013     if(H5Sclose(filespace) < 0)
10014         TEST_ERROR
10015 
10016     /* Reopen srcfile if config option specified */
10017     if(config & TEST_IO_CLOSE_SRC)
10018         if(config & TEST_IO_DIFFERENT_FILE)
10019             if((srcfile[0] = H5Fopen(srcfilenamepct, H5F_ACC_RDWR, fapl)) < 0)
10020                 TEST_ERROR
10021 
10022     /* Create 1 source dataset */
10023     if((srcdset[0] = H5Dcreate2(srcfile[0], "src_dset0", H5T_NATIVE_INT, srcspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
10024         TEST_ERROR
10025 
10026     /* Populate write buffer */
10027     for(i = 0; i < (int)mdims[0]; i++)
10028         for(j = 0; j < (int)mdims[1]; j++)
10029             buf[i][j] = (i * (int)mdims[1]) + j;
10030 
10031     /* Initialize erbuf */
10032     for(i = 0; i < (int)mdims[0]; i++)
10033         for(j = 0; j < (int)mdims[1]; j++)
10034             erbuf[i][j] = fill;
10035 
10036     /* Write to srcdset[0] */
10037     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
10038         TEST_ERROR
10039     if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
10040         TEST_ERROR
10041 
10042     /* Update erbuf */
10043     for(i = 0; i < 10; i++)
10044         erbuf[i][0] = buf[i][0];
10045 
10046     /* Close srcdset[0] and srcfile if config option specified */
10047     if(config & TEST_IO_CLOSE_SRC) {
10048         if(H5Dclose(srcdset[0]) < 0)
10049             TEST_ERROR
10050         srcdset[0] = -1;
10051 
10052         if(config & TEST_IO_DIFFERENT_FILE) {
10053             if(H5Fclose(srcfile[0]) < 0)
10054                 TEST_ERROR
10055             srcfile[0] = -1;
10056         }
10057     }
10058 
10059     /* Reopen virtual dataset and file if config option specified */
10060     if(config & TEST_IO_REOPEN_VIRT) {
10061         if(H5Dclose(vdset) < 0)
10062             TEST_ERROR
10063         vdset = -1;
10064         if(H5Fclose(vfile) < 0)
10065             TEST_ERROR
10066         vfile = -1;
10067         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
10068             TEST_ERROR
10069         if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
10070             TEST_ERROR
10071     }
10072 
10073     /* Get VDS space */
10074     if((filespace = H5Dget_space(vdset)) < 0)
10075         TEST_ERROR
10076 
10077     /* Get VDS space dimensions */
10078     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
10079         TEST_ERROR
10080     if(ndims != 2)
10081         TEST_ERROR
10082     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
10083         TEST_ERROR
10084     if(dims[0] != 10)
10085         TEST_ERROR
10086     if(dims[1] != 1)
10087         TEST_ERROR
10088     if(mdims[0] != 10)
10089         TEST_ERROR
10090     if(mdims[1] != 20)
10091         TEST_ERROR
10092 
10093     /* Close filespace */
10094     if(H5Sclose(filespace) < 0)
10095         TEST_ERROR
10096 
10097     /* Read data through virtual dataset */
10098     /* Reset rbuf */
10099     HDmemset(rbuf[0], 0, sizeof(rbuf));
10100 
10101     /* Select hyperslab in memory space */
10102     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
10103         TEST_ERROR
10104 
10105     /* Read data */
10106     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
10107         TEST_ERROR
10108 
10109     /* Verify read data */
10110     for(i = 0; i < (int)mdims[0]; i++)
10111         for(j = 0; j < (int)mdims[1]; j++) {
10112             if(j >= (int)dims[1]) {
10113                 if(rbuf[i][j] != 0)
10114                     TEST_ERROR
10115             }
10116             else
10117                 if(rbuf[i][j] != erbuf[i][j])
10118                     TEST_ERROR
10119         }
10120 
10121     /* Close VDS and reopen with printf gap set to 127, reopen file as well if
10122      * config option specified */
10123     if(H5Dclose(vdset) < 0)
10124         TEST_ERROR
10125     if(H5Pset_virtual_printf_gap(dapl, (hsize_t)127) < 0)
10126         TEST_ERROR
10127     if(config & TEST_IO_REOPEN_VIRT) {
10128         if(H5Fclose(vfile) < 0)
10129             TEST_ERROR
10130         vfile = -1;
10131         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
10132             TEST_ERROR
10133     }
10134     if((vdset = H5Dopen2(vfile, "v_dset", dapl)) < 0)
10135         TEST_ERROR
10136 
10137     /* Get VDS space */
10138     if((filespace = H5Dget_space(vdset)) < 0)
10139         TEST_ERROR
10140 
10141     /* Get VDS space dimensions */
10142     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
10143         TEST_ERROR
10144     if(ndims != 2)
10145         TEST_ERROR
10146     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
10147         TEST_ERROR
10148     if(dims[0] != 10)
10149         TEST_ERROR
10150     if(dims[1] != 1)
10151         TEST_ERROR
10152     if(mdims[0] != 10)
10153         TEST_ERROR
10154     if(mdims[1] != 20)
10155         TEST_ERROR
10156 
10157     /* Close filespace */
10158     if(H5Sclose(filespace) < 0)
10159         TEST_ERROR
10160 
10161     /* Read data through virtual dataset */
10162     /* Reset rbuf */
10163     HDmemset(rbuf[0], 0, sizeof(rbuf));
10164 
10165     /* Select hyperslab in memory space */
10166     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
10167         TEST_ERROR
10168 
10169     /* Read data */
10170     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
10171         TEST_ERROR
10172 
10173     /* Verify read data */
10174     for(i = 0; i < (int)mdims[0]; i++)
10175         for(j = 0; j < (int)mdims[1]; j++) {
10176             if(j >= (int)dims[1]) {
10177                 if(rbuf[i][j] != 0)
10178                     TEST_ERROR
10179             }
10180             else
10181                 if(rbuf[i][j] != erbuf[i][j])
10182                     TEST_ERROR
10183         }
10184 
10185     /* Reset dapl */
10186     if(H5Pset_virtual_printf_gap(dapl, (hsize_t)0) < 0)
10187         TEST_ERROR
10188 
10189     /* Close */
10190     if(!(config & TEST_IO_CLOSE_SRC)) {
10191         if(H5Dclose(srcdset[0]) < 0)
10192             TEST_ERROR
10193         srcdset[0] = -1;
10194         if(H5Fclose(srcfile[0]) < 0)
10195             TEST_ERROR
10196         srcfile[0] = -1;
10197     }
10198     else if(!(config & TEST_IO_DIFFERENT_FILE)) {
10199         if(H5Fclose(srcfile[0]) < 0)
10200             TEST_ERROR
10201         srcfile[0] = -1;
10202     }
10203     if(H5Dclose(vdset) < 0)
10204         TEST_ERROR
10205     vdset = -1;
10206     if(H5Fclose(vfile) < 0)
10207         TEST_ERROR
10208     vfile = -1;
10209     if(H5Sclose(srcspace) < 0)
10210         TEST_ERROR
10211     srcspace = -1;
10212     if(H5Sclose(vspace[0]) < 0)
10213         TEST_ERROR
10214     vspace[0] = -1;
10215 
10216 
10217     /* Close */
10218     if(H5Pclose(dcpl) < 0)
10219         TEST_ERROR
10220     dcpl = -1;
10221     if(H5Pclose(dapl) < 0)
10222         TEST_ERROR
10223     dapl = -1;
10224     if(H5Sclose(memspace) < 0)
10225         TEST_ERROR
10226     memspace = -1;
10227 
10228     PASSED();
10229     return 0;
10230 
10231 error:
10232     H5E_BEGIN_TRY {
10233         for(i = 0; i < (int)(sizeof(srcdset) / sizeof(srcdset[0])); i++)
10234             H5Dclose(srcdset[i]);
10235         H5Dclose(vdset);
10236         for(i = 0; i < (int)(sizeof(srcfile) / sizeof(srcfile[0])); i++)
10237             H5Fclose(srcfile[i]);
10238         H5Fclose(vfile);
10239         H5Sclose(srcspace);
10240         for(i = 0; i < (int)(sizeof(vspace) / sizeof(vspace[0])); i++)
10241             H5Sclose(vspace[i]);
10242         H5Sclose(filespace);
10243         H5Sclose(memspace);
10244         H5Pclose(dcpl);
10245         H5Pclose(dapl);
10246     } H5E_END_TRY;
10247 
10248      return 1;
10249 } /* end test_printf() */
10250 
10251 
10252 /*-------------------------------------------------------------------------
10253  * Function:    test_all
10254  *
10255  * Purpose:     Tests fixed, unlimited, and printf selections in the same
10256  *              VDS
10257  *
10258  * Return:      Success:        0
10259  *              Failure:        number of errors
10260  *-------------------------------------------------------------------------
10261  */
10262 static int
test_all(unsigned config,hid_t fapl)10263 test_all(unsigned config, hid_t fapl)
10264 {
10265     char        vfilename[FILENAME_BUF_SIZE];
10266     char        srcfilename[FILENAME_BUF_SIZE];
10267     char        srcfilename_map[FILENAME_BUF_SIZE];
10268     hid_t       srcfile = -1;   /* File with source dsets */
10269     hid_t       vfile = -1;     /* File with virtual dset */
10270     hid_t       dcpl = -1;      /* Dataset creation property list */
10271     hid_t       srcdcpl = -1;   /* DCPL for source dset */
10272     hid_t       srcspace[3] = {-1, -1, -1};  /* Source dataspaces */
10273     hid_t       vspace[3] = {-1, -1, -1}; /* Virtual dset dataspaces */
10274     hid_t       memspace = -1;  /* Memory dataspace */
10275     hid_t       filespace = -1; /* File dataspace */
10276     hid_t       srcdset[5] = {-1, -1, -1, -1, -1}; /* Source datsets */
10277     hid_t       vdset = -1;     /* Virtual dataset */
10278     hsize_t     dims[2] = {6, 6}; /* Data space current size */
10279     hsize_t     mdims[2] = {10, 10}; /* Data space maximum size */
10280     hsize_t     cdims[2] = {2, 2}; /* Chunk dimensions */
10281     hsize_t     start[2];       /* Hyperslab start */
10282     hsize_t     stride[2];      /* Hyperslab stride */
10283     hsize_t     count[2];       /* Hyperslab count */
10284     hsize_t     block[2];       /* Hyperslab block */
10285     int         buf[10][10];    /* Write and expected read buffer */
10286     int         rbuf[10][10];   /* Read buffer */
10287     int         erbuf[10][10];  /* Expected read buffer */
10288     int         ndims;          /* Number of dimensions */
10289     int         fill = -1;      /* Fill value */
10290     int         i, j;
10291 
10292     TESTING("virtual dataset I/O with mixed selection types")
10293 
10294     h5_fixname(FILENAME[0], fapl, vfilename, sizeof vfilename);
10295     h5_fixname(FILENAME[2], fapl, srcfilename, sizeof srcfilename);
10296     h5_fixname_printf(FILENAME[2], fapl, srcfilename_map, sizeof srcfilename_map);
10297 
10298     /* Create DCPLs */
10299     if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
10300         TEST_ERROR
10301     if((srcdcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
10302         TEST_ERROR
10303 
10304     /* Set fill value */
10305     if(H5Pset_fill_value(dcpl, H5T_NATIVE_INT, &fill) < 0)
10306         TEST_ERROR
10307 
10308     /* Set chunk dimensions */
10309     if(H5Pset_chunk(srcdcpl, 2, cdims) < 0)
10310         TEST_ERROR
10311 
10312     /* Create memory space */
10313     if((memspace = H5Screate_simple(2, mdims, NULL)) < 0)
10314         TEST_ERROR
10315 
10316     /* Clear virtual layout in DCPL */
10317     if(H5Pset_layout(dcpl, H5D_VIRTUAL) < 0)
10318         TEST_ERROR
10319 
10320     /* Create fixed mapping */
10321     if((vspace[0] = H5Screate_simple(2, dims, mdims)) < 0)
10322         TEST_ERROR
10323     start[0] = 3;
10324     start[1] = 3;
10325     count[0] = 3;
10326     count[1] = 3;
10327     if(H5Sselect_hyperslab(vspace[0], H5S_SELECT_SET, start, NULL, count, NULL) < 0)
10328         TEST_ERROR
10329     if((srcspace[0] = H5Screate_simple(2, count, NULL)) < 0)
10330         TEST_ERROR
10331     if(H5Pset_virtual(dcpl, vspace[0], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset_fixed", srcspace[0]) < 0)
10332         TEST_ERROR
10333 
10334     /* Create unlimited mapping */
10335     if((vspace[1] = H5Screate_simple(2, dims, mdims)) < 0)
10336         TEST_ERROR
10337     start[0] = 3;
10338     start[1] = 0;
10339     count[0] = 1;
10340     count[1] = 1;
10341     block[0] = H5S_UNLIMITED;
10342     block[1] = 3;
10343     if(H5Sselect_hyperslab(vspace[1], H5S_SELECT_SET, start, NULL, count, block) < 0)
10344         TEST_ERROR
10345     dims[0] = 0;
10346     dims[1] = 3;
10347     if((srcspace[1] = H5Screate_simple(2, dims, block)) < 0)
10348         TEST_ERROR
10349     start[0] = 0;
10350     if(H5Sselect_hyperslab(srcspace[1], H5S_SELECT_SET, start, NULL, block, NULL) < 0)
10351         TEST_ERROR
10352     if(H5Pset_virtual(dcpl, vspace[1], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset_unlim", srcspace[1]) < 0)
10353         TEST_ERROR
10354 
10355     /* Create printf mapping */
10356     if((vspace[2] = H5Screate_simple(2, dims, mdims)) < 0)
10357         TEST_ERROR
10358     start[0] = 0;
10359     start[1] = 2;
10360     stride[0] = 1;
10361     stride[1] = 3;
10362     count[0] = 1;
10363     count[1] = H5S_UNLIMITED;
10364     block[0] = 3;
10365     block[1] = 2;
10366     if(H5Sselect_hyperslab(vspace[2], H5S_SELECT_SET, start, stride, count, block) < 0)
10367         TEST_ERROR
10368     if((srcspace[2] = H5Screate_simple(2, block, NULL)) < 0)
10369         TEST_ERROR
10370     if(H5Pset_virtual(dcpl, vspace[2], config & TEST_IO_DIFFERENT_FILE ? srcfilename_map : ".", "src_dset_printf_%b", srcspace[2]) < 0)
10371         TEST_ERROR
10372 
10373     /* Create virtual file */
10374     if((vfile = H5Fcreate(vfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
10375         TEST_ERROR
10376 
10377     /* Create source file if requested */
10378     if(config & TEST_IO_DIFFERENT_FILE) {
10379         if((srcfile = H5Fcreate(srcfilename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
10380             TEST_ERROR
10381     }
10382     else {
10383         srcfile = vfile;
10384         if(H5Iinc_ref(srcfile) < 0)
10385             TEST_ERROR
10386     }
10387 
10388     /* Create virtual dataset */
10389     if((vdset = H5Dcreate2(vfile, "v_dset", H5T_NATIVE_INT, vspace[0], H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
10390         TEST_ERROR
10391 
10392     /* Close srcfile if config option specified */
10393     if(config & TEST_IO_CLOSE_SRC)
10394         if(config & TEST_IO_DIFFERENT_FILE) {
10395             if(H5Fclose(srcfile) < 0)
10396                 TEST_ERROR
10397             srcfile = -1;
10398         }
10399 
10400     /* Reopen virtual dataset and file if config option specified */
10401     if(config & TEST_IO_REOPEN_VIRT) {
10402         if(H5Dclose(vdset) < 0)
10403             TEST_ERROR
10404         vdset = -1;
10405         if(H5Fclose(vfile) < 0)
10406             TEST_ERROR
10407         vfile = -1;
10408         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
10409             TEST_ERROR
10410         if((vdset = H5Dopen2(vfile, "v_dset", H5P_DEFAULT)) < 0)
10411             TEST_ERROR
10412     }
10413 
10414     /* Get VDS space */
10415     if((filespace = H5Dget_space(vdset)) < 0)
10416         TEST_ERROR
10417 
10418     /* Get VDS space dimensions */
10419     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
10420         TEST_ERROR
10421     if(ndims != 2)
10422         TEST_ERROR
10423     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
10424         TEST_ERROR
10425     if(dims[0] != 6)
10426         TEST_ERROR
10427     if(dims[1] != 6)
10428         TEST_ERROR
10429     if(mdims[0] != 10)
10430         TEST_ERROR
10431     if(mdims[1] != 10)
10432         TEST_ERROR
10433 
10434     /* Close filespace */
10435     if(H5Sclose(filespace) < 0)
10436         TEST_ERROR
10437 
10438     /* Reopen srcfile if config option specified */
10439     if(config & TEST_IO_CLOSE_SRC)
10440         if(config & TEST_IO_DIFFERENT_FILE)
10441             if((srcfile = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
10442                 TEST_ERROR
10443 
10444     /* Create fixed source dataset */
10445     if((srcdset[0] = H5Dcreate2(srcfile, "src_dset_fixed", H5T_NATIVE_INT, srcspace[0], H5P_DEFAULT, srcdcpl, H5P_DEFAULT)) < 0)
10446         TEST_ERROR
10447 
10448     /* Create unlimited source_dataset */
10449     if((srcdset[1] = H5Dcreate2(srcfile, "src_dset_unlim", H5T_NATIVE_INT, srcspace[1], H5P_DEFAULT, srcdcpl, H5P_DEFAULT)) < 0)
10450         TEST_ERROR
10451 
10452     /* Populate write buffer */
10453     for(i = 0; i < (int)mdims[0]; i++)
10454         for(j = 0; j < (int)mdims[1]; j++)
10455             buf[i][j] = (i * (int)mdims[1]) + j;
10456 
10457     /* Initialize erbuf */
10458     for(i = 0; i < (int)mdims[0]; i++)
10459         for(j = 0; j < (int)mdims[1]; j++)
10460             erbuf[i][j] = fill;
10461 
10462     /* Write to srcdset[0] */
10463     start[0] = 0;
10464     start[1] = 0;
10465     block[0] = 3;
10466     block[1] = 3;
10467     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
10468         TEST_ERROR
10469     if(H5Dwrite(srcdset[0], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
10470         TEST_ERROR
10471 
10472     /* Update erbuf */
10473     for(i = 0; i < 3; i++)
10474         for(j = 0; j < 3; j++)
10475             erbuf[i + 3][j + 3] = buf[i][j];
10476 
10477     /* Close srcdsets and srcfile if config option specified */
10478     if(config & TEST_IO_CLOSE_SRC) {
10479         for(i = 0; i < 2; i++) {
10480             if(H5Dclose(srcdset[i]) < 0)
10481                 TEST_ERROR
10482             srcdset[i] = -1;
10483         }
10484 
10485         if(config & TEST_IO_DIFFERENT_FILE) {
10486             if(H5Fclose(srcfile) < 0)
10487                 TEST_ERROR
10488             srcfile = -1;
10489         }
10490     }
10491 
10492     /* Reopen virtual dataset and file if config option specified */
10493     if(config & TEST_IO_REOPEN_VIRT) {
10494         if(H5Dclose(vdset) < 0)
10495             TEST_ERROR
10496         vdset = -1;
10497         if(H5Fclose(vfile) < 0)
10498             TEST_ERROR
10499         vfile = -1;
10500         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
10501             TEST_ERROR
10502         if((vdset = H5Dopen2(vfile, "v_dset", H5P_DEFAULT)) < 0)
10503             TEST_ERROR
10504     }
10505 
10506     /* Get VDS space */
10507     if((filespace = H5Dget_space(vdset)) < 0)
10508         TEST_ERROR
10509 
10510     /* Get VDS space dimensions */
10511     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
10512         TEST_ERROR
10513     if(ndims != 2)
10514         TEST_ERROR
10515     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
10516         TEST_ERROR
10517     if(dims[0] != 6)
10518         TEST_ERROR
10519     if(dims[1] != 6)
10520         TEST_ERROR
10521     if(mdims[0] != 10)
10522         TEST_ERROR
10523     if(mdims[1] != 10)
10524         TEST_ERROR
10525 
10526     /* Close filespace */
10527     if(H5Sclose(filespace) < 0)
10528         TEST_ERROR
10529 
10530     /* Read data through virtual dataset */
10531     /* Reset rbuf */
10532     HDmemset(rbuf[0], 0, sizeof(rbuf));
10533 
10534     /* Select hyperslab in memory space */
10535     start[0] = 0;
10536     start[1] = 0;
10537     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
10538         TEST_ERROR
10539 
10540     /* Read data */
10541     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
10542         TEST_ERROR
10543 
10544     /* Verify read data */
10545     for(i = 0; i < (int)mdims[0]; i++)
10546         for(j = 0; j < (int)mdims[1]; j++) {
10547             if((i >= (int)dims[0]) || (j >= (int)dims[1])) {
10548                 if(rbuf[i][j] != 0)
10549                     TEST_ERROR
10550             }
10551             else
10552                 if(rbuf[i][j] != erbuf[i][j])
10553                     TEST_ERROR
10554         }
10555 
10556     /* Reopen srcdset[1] and srcfile if config option specified */
10557     if(config & TEST_IO_CLOSE_SRC) {
10558         if(config & TEST_IO_DIFFERENT_FILE)
10559             if((srcfile = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
10560                 TEST_ERROR
10561         if((srcdset[1] = H5Dopen2(srcfile, "src_dset_unlim", H5P_DEFAULT)) < 0)
10562             TEST_ERROR
10563     }
10564 
10565     /* Extend srcdset[1] */
10566     dims[0] = 2;
10567     dims[1] = 3;
10568     if(H5Dset_extent(srcdset[1], dims) < 0)
10569         TEST_ERROR
10570 
10571     /* Adjust write buffer */
10572     for(i = 0; i < (int)mdims[0]; i++)
10573         for(j = 0; j < (int)mdims[1]; j++)
10574             buf[i][j] += (int)mdims[0] * (int)mdims[1];
10575 
10576     /* Write to srcdset[1] */
10577     start[0] = 0;
10578     start[1] = 0;
10579     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
10580         TEST_ERROR
10581     if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
10582         TEST_ERROR
10583 
10584     /* Update erbuf */
10585     for(i = 0; i < 2; i++)
10586         for(j = 0; j < 3; j++)
10587             erbuf[i + 3][j] = buf[i][j];
10588 
10589     /* Close srcdset[1] and srcfile if config option specified */
10590     if(config & TEST_IO_CLOSE_SRC) {
10591         if(H5Dclose(srcdset[1]) < 0)
10592             TEST_ERROR
10593         srcdset[1] = -1;
10594         if(config & TEST_IO_DIFFERENT_FILE) {
10595             if(H5Fclose(srcfile) < 0)
10596                 TEST_ERROR
10597             srcfile = -1;
10598         }
10599     }
10600 
10601     /* Reopen virtual dataset and file if config option specified */
10602     if(config & TEST_IO_REOPEN_VIRT) {
10603         if(H5Dclose(vdset) < 0)
10604             TEST_ERROR
10605         vdset = -1;
10606         if(H5Fclose(vfile) < 0)
10607             TEST_ERROR
10608         vfile = -1;
10609         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
10610             TEST_ERROR
10611         if((vdset = H5Dopen2(vfile, "v_dset", H5P_DEFAULT)) < 0)
10612             TEST_ERROR
10613     }
10614 
10615     /* Get VDS space */
10616     if((filespace = H5Dget_space(vdset)) < 0)
10617         TEST_ERROR
10618 
10619     /* Get VDS space dimensions */
10620     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
10621         TEST_ERROR
10622     if(ndims != 2)
10623         TEST_ERROR
10624     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
10625         TEST_ERROR
10626     if(dims[0] != 6)
10627         TEST_ERROR
10628     if(dims[1] != 6)
10629         TEST_ERROR
10630     if(mdims[0] != 10)
10631         TEST_ERROR
10632     if(mdims[1] != 10)
10633         TEST_ERROR
10634 
10635     /* Close filespace */
10636     if(H5Sclose(filespace) < 0)
10637         TEST_ERROR
10638 
10639     /* Read data through virtual dataset */
10640     /* Reset rbuf */
10641     HDmemset(rbuf[0], 0, sizeof(rbuf));
10642 
10643     /* Select hyperslab in memory space */
10644     start[0] = 0;
10645     start[1] = 0;
10646     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
10647         TEST_ERROR
10648 
10649     /* Read data */
10650     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
10651         TEST_ERROR
10652 
10653     /* Verify read data */
10654     for(i = 0; i < (int)mdims[0]; i++)
10655         for(j = 0; j < (int)mdims[1]; j++) {
10656             if((i >= (int)dims[0]) || (j >= (int)dims[1])) {
10657                 if(rbuf[i][j] != 0)
10658                     TEST_ERROR
10659             }
10660             else
10661                 if(rbuf[i][j] != erbuf[i][j])
10662                     TEST_ERROR
10663         }
10664 
10665     /* Reopen srcfile if config option specified */
10666     if((config & TEST_IO_CLOSE_SRC) && (config & TEST_IO_DIFFERENT_FILE))
10667         if((srcfile = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
10668             TEST_ERROR
10669 
10670     /* Create first printf source dataset */
10671     if((srcdset[2] = H5Dcreate2(srcfile, "src_dset_printf_0", H5T_NATIVE_INT, srcspace[2], H5P_DEFAULT, srcdcpl, H5P_DEFAULT)) < 0)
10672         TEST_ERROR
10673 
10674     /* Adjust write buffer */
10675     for(i = 0; i < (int)mdims[0]; i++)
10676         for(j = 0; j < (int)mdims[1]; j++)
10677             buf[i][j] += (int)mdims[0] * (int)mdims[1];
10678 
10679     /* Write to srcdset[2] */
10680     start[0] = 0;
10681     start[1] = 0;
10682     block[0] = 3;
10683     block[1] = 2;
10684     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
10685         TEST_ERROR
10686     if(H5Dwrite(srcdset[2], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
10687         TEST_ERROR
10688 
10689     /* Update erbuf */
10690     for(i = 0; i < 3; i++)
10691         for(j = 0; j < 2; j++)
10692             erbuf[i][j + 2] = buf[i][j];
10693 
10694     /* Close srcdset[2] srcfile if config option specified */
10695     if(config & TEST_IO_CLOSE_SRC) {
10696         if(H5Dclose(srcdset[2]) < 0)
10697             TEST_ERROR
10698         srcdset[2] = -1;
10699         if(config & TEST_IO_DIFFERENT_FILE) {
10700             if(H5Fclose(srcfile) < 0)
10701                 TEST_ERROR
10702             srcfile = -1;
10703         }
10704     }
10705 
10706     /* Reopen virtual dataset and file if config option specified */
10707     if(config & TEST_IO_REOPEN_VIRT) {
10708         if(H5Dclose(vdset) < 0)
10709             TEST_ERROR
10710         vdset = -1;
10711         if(H5Fclose(vfile) < 0)
10712             TEST_ERROR
10713         vfile = -1;
10714         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
10715             TEST_ERROR
10716         if((vdset = H5Dopen2(vfile, "v_dset", H5P_DEFAULT)) < 0)
10717             TEST_ERROR
10718     }
10719 
10720     /* Get VDS space */
10721     if((filespace = H5Dget_space(vdset)) < 0)
10722         TEST_ERROR
10723 
10724     /* Get VDS space dimensions */
10725     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
10726         TEST_ERROR
10727     if(ndims != 2)
10728         TEST_ERROR
10729     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
10730         TEST_ERROR
10731     if(dims[0] != 6)
10732         TEST_ERROR
10733     if(dims[1] != 6)
10734         TEST_ERROR
10735     if(mdims[0] != 10)
10736         TEST_ERROR
10737     if(mdims[1] != 10)
10738         TEST_ERROR
10739 
10740     /* Close filespace */
10741     if(H5Sclose(filespace) < 0)
10742         TEST_ERROR
10743 
10744     /* Read data through virtual dataset */
10745     /* Reset rbuf */
10746     HDmemset(rbuf[0], 0, sizeof(rbuf));
10747 
10748     /* Select hyperslab in memory space */
10749     start[0] = 0;
10750     start[1] = 0;
10751     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
10752         TEST_ERROR
10753 
10754     /* Read data */
10755     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
10756         TEST_ERROR
10757 
10758     /* Verify read data */
10759     for(i = 0; i < (int)mdims[0]; i++)
10760         for(j = 0; j < (int)mdims[1]; j++) {
10761             if((i >= (int)dims[0]) || (j >= (int)dims[1])) {
10762                 if(rbuf[i][j] != 0)
10763                     TEST_ERROR
10764             }
10765             else
10766                 if(rbuf[i][j] != erbuf[i][j])
10767                     TEST_ERROR
10768         }
10769 
10770     /* Reopen srcdset[1] and srcfile if config option specified */
10771     if(config & TEST_IO_CLOSE_SRC) {
10772         if(config & TEST_IO_DIFFERENT_FILE)
10773             if((srcfile = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
10774                 TEST_ERROR
10775         if((srcdset[1] = H5Dopen2(srcfile, "src_dset_unlim", H5P_DEFAULT)) < 0)
10776             TEST_ERROR
10777     }
10778 
10779     /* Extend srcdset[1] */
10780     dims[0] = 3;
10781     dims[1] = 3;
10782     if(H5Dset_extent(srcdset[1], dims) < 0)
10783         TEST_ERROR
10784 
10785     /* Adjust write buffer */
10786     for(i = 0; i < (int)mdims[0]; i++)
10787         for(j = 0; j < (int)mdims[1]; j++)
10788             buf[i][j] += (int)mdims[0] * (int)mdims[1];
10789 
10790     /* Write to new area of srcdset[1] */
10791     start[0] = 0;
10792     start[1] = 0;
10793     block[0] = 1;
10794     block[1] = 3;
10795     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
10796         TEST_ERROR
10797     if((filespace = H5Dget_space(srcdset[1])) < 0)
10798         TEST_ERROR
10799     start[0] = 2;
10800     start[1] = 0;
10801     if(H5Sselect_hyperslab(filespace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
10802         TEST_ERROR
10803     if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT, buf[0]) < 0)
10804         TEST_ERROR
10805     if(H5Sclose(filespace) < 0)
10806         TEST_ERROR
10807 
10808     /* Update erbuf */
10809     for(i = 0; i < 3; i++)
10810         erbuf[5][i] = buf[0][i];
10811 
10812     /* Close srcdset[1] and srcfile if config option specified */
10813     if(config & TEST_IO_CLOSE_SRC) {
10814         if(H5Dclose(srcdset[1]) < 0)
10815             TEST_ERROR
10816         srcdset[1] = -1;
10817         if(config & TEST_IO_DIFFERENT_FILE) {
10818             if(H5Fclose(srcfile) < 0)
10819                 TEST_ERROR
10820             srcfile = -1;
10821         }
10822     }
10823 
10824     /* Reopen virtual dataset and file if config option specified */
10825     if(config & TEST_IO_REOPEN_VIRT) {
10826         if(H5Dclose(vdset) < 0)
10827             TEST_ERROR
10828         vdset = -1;
10829         if(H5Fclose(vfile) < 0)
10830             TEST_ERROR
10831         vfile = -1;
10832         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
10833             TEST_ERROR
10834         if((vdset = H5Dopen2(vfile, "v_dset", H5P_DEFAULT)) < 0)
10835             TEST_ERROR
10836     }
10837 
10838     /* Get VDS space */
10839     if((filespace = H5Dget_space(vdset)) < 0)
10840         TEST_ERROR
10841 
10842     /* Get VDS space dimensions */
10843     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
10844         TEST_ERROR
10845     if(ndims != 2)
10846         TEST_ERROR
10847     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
10848         TEST_ERROR
10849     if(dims[0] != 6)
10850         TEST_ERROR
10851     if(dims[1] != 6)
10852         TEST_ERROR
10853     if(mdims[0] != 10)
10854         TEST_ERROR
10855     if(mdims[1] != 10)
10856         TEST_ERROR
10857 
10858     /* Close filespace */
10859     if(H5Sclose(filespace) < 0)
10860         TEST_ERROR
10861 
10862     /* Read data through virtual dataset */
10863     /* Reset rbuf */
10864     HDmemset(rbuf[0], 0, sizeof(rbuf));
10865 
10866     /* Select hyperslab in memory space */
10867     start[0] = 0;
10868     start[1] = 0;
10869     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
10870         TEST_ERROR
10871 
10872     /* Read data */
10873     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
10874         TEST_ERROR
10875 
10876     /* Verify read data */
10877     for(i = 0; i < (int)mdims[0]; i++)
10878         for(j = 0; j < (int)mdims[1]; j++) {
10879             if((i >= (int)dims[0]) || (j >= (int)dims[1])) {
10880                 if(rbuf[i][j] != 0)
10881                     TEST_ERROR
10882             }
10883             else
10884                 if(rbuf[i][j] != erbuf[i][j])
10885                     TEST_ERROR
10886         }
10887 
10888     /* Reopen srcfile if config option specified */
10889     if((config & TEST_IO_CLOSE_SRC) && (config & TEST_IO_DIFFERENT_FILE))
10890         if((srcfile = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
10891             TEST_ERROR
10892 
10893     /* Create second printf source dataset, this time without using srcdcpl */
10894     if((srcdset[3] = H5Dcreate2(srcfile, "src_dset_printf_1", H5T_NATIVE_INT, srcspace[2], H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
10895         TEST_ERROR
10896 
10897     /* Adjust write buffer */
10898     for(i = 0; i < (int)mdims[0]; i++)
10899         for(j = 0; j < (int)mdims[1]; j++)
10900             buf[i][j] += (int)mdims[0] * (int)mdims[1];
10901 
10902     /* Write to srcdset[3] */
10903     start[0] = 0;
10904     start[1] = 0;
10905     block[0] = 3;
10906     block[1] = 2;
10907     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
10908         TEST_ERROR
10909     if(H5Dwrite(srcdset[3], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
10910         TEST_ERROR
10911 
10912     /* Update erbuf */
10913     for(i = 0; i < 3; i++)
10914         for(j = 0; j < 2; j++)
10915             erbuf[i][j + 5] = buf[i][j];
10916 
10917     /* Close srcdset[3] srcfile if config option specified */
10918     if(config & TEST_IO_CLOSE_SRC) {
10919         if(H5Dclose(srcdset[3]) < 0)
10920             TEST_ERROR
10921         srcdset[3] = -1;
10922         if(config & TEST_IO_DIFFERENT_FILE) {
10923             if(H5Fclose(srcfile) < 0)
10924                 TEST_ERROR
10925             srcfile = -1;
10926         }
10927     }
10928 
10929     /* Reopen virtual dataset and file if config option specified */
10930     if(config & TEST_IO_REOPEN_VIRT) {
10931         if(H5Dclose(vdset) < 0)
10932             TEST_ERROR
10933         vdset = -1;
10934         if(H5Fclose(vfile) < 0)
10935             TEST_ERROR
10936         vfile = -1;
10937         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
10938             TEST_ERROR
10939         if((vdset = H5Dopen2(vfile, "v_dset", H5P_DEFAULT)) < 0)
10940             TEST_ERROR
10941     }
10942 
10943     /* Get VDS space */
10944     if((filespace = H5Dget_space(vdset)) < 0)
10945         TEST_ERROR
10946 
10947     /* Get VDS space dimensions */
10948     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
10949         TEST_ERROR
10950     if(ndims != 2)
10951         TEST_ERROR
10952     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
10953         TEST_ERROR
10954     if(dims[0] != 6)
10955         TEST_ERROR
10956     if(dims[1] != 7)
10957         TEST_ERROR
10958     if(mdims[0] != 10)
10959         TEST_ERROR
10960     if(mdims[1] != 10)
10961         TEST_ERROR
10962 
10963     /* Close filespace */
10964     if(H5Sclose(filespace) < 0)
10965         TEST_ERROR
10966 
10967     /* Read data through virtual dataset */
10968     /* Reset rbuf */
10969     HDmemset(rbuf[0], 0, sizeof(rbuf));
10970 
10971     /* Select hyperslab in memory space */
10972     start[0] = 0;
10973     start[1] = 0;
10974     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
10975         TEST_ERROR
10976 
10977     /* Read data */
10978     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
10979         TEST_ERROR
10980 
10981     /* Verify read data */
10982     for(i = 0; i < (int)mdims[0]; i++)
10983         for(j = 0; j < (int)mdims[1]; j++) {
10984             if((i >= (int)dims[0]) || (j >= (int)dims[1])) {
10985                 if(rbuf[i][j] != 0)
10986                     TEST_ERROR
10987             }
10988             else
10989                 if(rbuf[i][j] != erbuf[i][j])
10990                     TEST_ERROR
10991         }
10992 
10993     /* Reopen srcdset[1] and srcfile if config option specified */
10994     if(config & TEST_IO_CLOSE_SRC) {
10995         if(config & TEST_IO_DIFFERENT_FILE)
10996             if((srcfile = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
10997                 TEST_ERROR
10998         if((srcdset[1] = H5Dopen2(srcfile, "src_dset_unlim", H5P_DEFAULT)) < 0)
10999             TEST_ERROR
11000     }
11001 
11002     /* Extend srcdset[1] */
11003     dims[0] = 7;
11004     dims[1] = 3;
11005     if(H5Dset_extent(srcdset[1], dims) < 0)
11006         TEST_ERROR
11007 
11008     /* Adjust write buffer */
11009     for(i = 0; i < (int)mdims[0]; i++)
11010         for(j = 0; j < (int)mdims[1]; j++)
11011             buf[i][j] += (int)mdims[0] * (int)mdims[1];
11012 
11013     /* Write to new area of srcdset[1] */
11014     start[0] = 0;
11015     start[1] = 0;
11016     block[0] = 4;
11017     block[1] = 3;
11018     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
11019         TEST_ERROR
11020     if((filespace = H5Dget_space(srcdset[1])) < 0)
11021         TEST_ERROR
11022     start[0] = 3;
11023     start[1] = 0;
11024     if(H5Sselect_hyperslab(filespace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
11025         TEST_ERROR
11026     if(H5Dwrite(srcdset[1], H5T_NATIVE_INT, memspace, filespace, H5P_DEFAULT, buf[0]) < 0)
11027         TEST_ERROR
11028     if(H5Sclose(filespace) < 0)
11029         TEST_ERROR
11030 
11031     /* Update erbuf */
11032     for(i = 0; i < 4; i++)
11033         for(j = 0; j < 3; j++)
11034             erbuf[i + 6][j] = buf[i][j];
11035 
11036     /* Close srcdset[1] and srcfile if config option specified */
11037     if(config & TEST_IO_CLOSE_SRC) {
11038         if(H5Dclose(srcdset[1]) < 0)
11039             TEST_ERROR
11040         srcdset[1] = -1;
11041         if(config & TEST_IO_DIFFERENT_FILE) {
11042             if(H5Fclose(srcfile) < 0)
11043                 TEST_ERROR
11044             srcfile = -1;
11045         }
11046     }
11047 
11048     /* Reopen virtual dataset and file if config option specified */
11049     if(config & TEST_IO_REOPEN_VIRT) {
11050         if(H5Dclose(vdset) < 0)
11051             TEST_ERROR
11052         vdset = -1;
11053         if(H5Fclose(vfile) < 0)
11054             TEST_ERROR
11055         vfile = -1;
11056         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
11057             TEST_ERROR
11058         if((vdset = H5Dopen2(vfile, "v_dset", H5P_DEFAULT)) < 0)
11059             TEST_ERROR
11060     }
11061 
11062     /* Get VDS space */
11063     if((filespace = H5Dget_space(vdset)) < 0)
11064         TEST_ERROR
11065 
11066     /* Get VDS space dimensions */
11067     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
11068         TEST_ERROR
11069     if(ndims != 2)
11070         TEST_ERROR
11071     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
11072         TEST_ERROR
11073     if(dims[0] != 10)
11074         TEST_ERROR
11075     if(dims[1] != 7)
11076         TEST_ERROR
11077     if(mdims[0] != 10)
11078         TEST_ERROR
11079     if(mdims[1] != 10)
11080         TEST_ERROR
11081 
11082     /* Close filespace */
11083     if(H5Sclose(filespace) < 0)
11084         TEST_ERROR
11085 
11086     /* Read data through virtual dataset */
11087     /* Reset rbuf */
11088     HDmemset(rbuf[0], 0, sizeof(rbuf));
11089 
11090     /* Select hyperslab in memory space */
11091     start[0] = 0;
11092     start[1] = 0;
11093     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
11094         TEST_ERROR
11095 
11096     /* Read data */
11097     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
11098         TEST_ERROR
11099 
11100     /* Verify read data */
11101     for(i = 0; i < (int)mdims[0]; i++)
11102         for(j = 0; j < (int)mdims[1]; j++) {
11103             if(j >= (int)dims[1]) {
11104                 if(rbuf[i][j] != 0)
11105                     TEST_ERROR
11106             }
11107             else
11108                 if(rbuf[i][j] != erbuf[i][j])
11109                     TEST_ERROR
11110         }
11111 
11112     /* Reopen srcfile if config option specified */
11113     if((config & TEST_IO_CLOSE_SRC) && (config & TEST_IO_DIFFERENT_FILE))
11114         if((srcfile = H5Fopen(srcfilename, H5F_ACC_RDWR, fapl)) < 0)
11115             TEST_ERROR
11116 
11117     /* Create third printf source dataset */
11118     if((srcdset[4] = H5Dcreate2(srcfile, "src_dset_printf_2", H5T_NATIVE_INT, srcspace[2], H5P_DEFAULT, srcdcpl, H5P_DEFAULT)) < 0)
11119         TEST_ERROR
11120 
11121     /* Adjust write buffer */
11122     for(i = 0; i < (int)mdims[0]; i++)
11123         for(j = 0; j < (int)mdims[1]; j++)
11124             buf[i][j] += (int)mdims[0] * (int)mdims[1];
11125 
11126     /* Write to srcdset[4] */
11127     start[0] = 0;
11128     start[1] = 0;
11129     block[0] = 3;
11130     block[1] = 2;
11131     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, block, NULL) < 0)
11132         TEST_ERROR
11133     if(H5Dwrite(srcdset[4], H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, buf[0]) < 0)
11134         TEST_ERROR
11135 
11136     /* Update erbuf */
11137     for(i = 0; i < 3; i++)
11138         for(j = 0; j < 2; j++)
11139             erbuf[i][j + 8] = buf[i][j];
11140 
11141     /* Close srcdset[4] srcfile if config option specified */
11142     if(config & TEST_IO_CLOSE_SRC) {
11143         if(H5Dclose(srcdset[4]) < 0)
11144             TEST_ERROR
11145         srcdset[4] = -1;
11146         if(config & TEST_IO_DIFFERENT_FILE) {
11147             if(H5Fclose(srcfile) < 0)
11148                 TEST_ERROR
11149             srcfile = -1;
11150         }
11151     }
11152 
11153     /* Reopen virtual dataset and file if config option specified */
11154     if(config & TEST_IO_REOPEN_VIRT) {
11155         if(H5Dclose(vdset) < 0)
11156             TEST_ERROR
11157         vdset = -1;
11158         if(H5Fclose(vfile) < 0)
11159             TEST_ERROR
11160         vfile = -1;
11161         if((vfile = H5Fopen(vfilename, H5F_ACC_RDWR, fapl)) < 0)
11162             TEST_ERROR
11163         if((vdset = H5Dopen2(vfile, "v_dset", H5P_DEFAULT)) < 0)
11164             TEST_ERROR
11165     }
11166 
11167     /* Get VDS space */
11168     if((filespace = H5Dget_space(vdset)) < 0)
11169         TEST_ERROR
11170 
11171     /* Get VDS space dimensions */
11172     if((ndims = H5Sget_simple_extent_ndims(filespace)) < 0)
11173         TEST_ERROR
11174     if(ndims != 2)
11175         TEST_ERROR
11176     if(H5Sget_simple_extent_dims(filespace, dims, mdims) < 0)
11177         TEST_ERROR
11178     if(dims[0] != 10)
11179         TEST_ERROR
11180     if(dims[1] != 10)
11181         TEST_ERROR
11182     if(mdims[0] != 10)
11183         TEST_ERROR
11184     if(mdims[1] != 10)
11185         TEST_ERROR
11186 
11187     /* Close filespace */
11188     if(H5Sclose(filespace) < 0)
11189         TEST_ERROR
11190 
11191     /* Read data through virtual dataset */
11192     /* Reset rbuf */
11193     HDmemset(rbuf[0], 0, sizeof(rbuf));
11194 
11195     /* Select hyperslab in memory space */
11196     start[0] = 0;
11197     start[1] = 0;
11198     if(H5Sselect_hyperslab(memspace, H5S_SELECT_SET, start, NULL, dims, NULL) < 0)
11199         TEST_ERROR
11200 
11201     /* Read data */
11202     if(H5Dread(vdset, H5T_NATIVE_INT, memspace, H5S_ALL, H5P_DEFAULT, rbuf[0]) < 0)
11203         TEST_ERROR
11204 
11205     /* Verify read data */
11206     for(i = 0; i < (int)mdims[0]; i++)
11207         for(j = 0; j < (int)mdims[1]; j++)
11208             if(rbuf[i][j] != erbuf[i][j])
11209                 TEST_ERROR
11210 
11211     /* Close */
11212     if(!(config & TEST_IO_CLOSE_SRC)) {
11213         for(i = 0; i < 5; i++) {
11214             if(H5Dclose(srcdset[i]) < 0)
11215                 TEST_ERROR
11216             srcdset[i] = -1;
11217         }
11218         if(H5Fclose(srcfile) < 0)
11219             TEST_ERROR
11220         srcfile = -1;
11221     }
11222     else if(!(config & TEST_IO_DIFFERENT_FILE)) {
11223         if(H5Fclose(srcfile) < 0)
11224             TEST_ERROR
11225         srcfile = -1;
11226     }
11227     if(H5Dclose(vdset) < 0)
11228         TEST_ERROR
11229     vdset = -1;
11230     if(H5Fclose(vfile) < 0)
11231         TEST_ERROR
11232     vfile = -1;
11233     for(i = 0; i < (int)(sizeof(srcspace) / sizeof(srcspace[0])); i++) {
11234         if(H5Sclose(srcspace[i]) < 0)
11235             TEST_ERROR
11236         srcspace[i] = -1;
11237     }
11238     for(i = 0; i < (int)(sizeof(vspace) / sizeof(vspace[0])); i++) {
11239         if(H5Sclose(vspace[i]) < 0)
11240             TEST_ERROR
11241         vspace[i] = -1;
11242     }
11243     if(H5Pclose(dcpl) < 0)
11244         TEST_ERROR
11245     dcpl = -1;
11246     if(H5Pclose(srcdcpl) < 0)
11247         TEST_ERROR
11248     srcdcpl = -1;
11249     if(H5Sclose(memspace) < 0)
11250         TEST_ERROR
11251     memspace = -1;
11252 
11253     PASSED();
11254     return 0;
11255 
11256 error:
11257     H5E_BEGIN_TRY {
11258         for(i = 0; i < (int)(sizeof(srcdset) / sizeof(srcdset[0])); i++)
11259             H5Dclose(srcdset[i]);
11260         H5Dclose(vdset);
11261         H5Fclose(srcfile);
11262         H5Fclose(vfile);
11263         for(i = 0; i < (int)(sizeof(srcspace) / sizeof(srcspace[0])); i++)
11264             H5Sclose(srcspace[i]);
11265         for(i = 0; i < (int)(sizeof(vspace) / sizeof(vspace[0])); i++)
11266             H5Sclose(vspace[i]);
11267         H5Sclose(filespace);
11268         H5Sclose(memspace);
11269         H5Pclose(dcpl);
11270         H5Pclose(srcdcpl);
11271     } H5E_END_TRY;
11272 
11273      return 1;
11274 } /* end test_all() */
11275 
11276 
11277 /*-------------------------------------------------------------------------
11278  * Function:    test_dapl_values
11279  *
11280  * Purpose:     Ensure that H5Dget_access_plist returns correct values.
11281  *
11282  * Return:      Success:    0
11283  *              Failure:    1
11284  *-------------------------------------------------------------------------
11285  */
11286 static int
test_dapl_values(hid_t fapl_id)11287 test_dapl_values(hid_t fapl_id)
11288 {
11289     hid_t    fid = -1;           /* file to write to                     */
11290     hid_t    dcpl_id = -1;       /* dataset creation properties          */
11291     hid_t    dapl_id1 = -1;      /* dataset access properties            */
11292     hid_t    dapl_id2 = -1;      /* dataset access properties            */
11293     hid_t    vds_sid = -1;       /* vds data space                       */
11294     hid_t    src_sid = -1;       /* source data space                    */
11295     hid_t    did1 = -1;          /* dataset                              */
11296     hid_t    did2 = -1;          /* dataset                              */
11297     hsize_t  start;              /* hyperslab start                      */
11298     hsize_t  stride;             /* hyperslab count                      */
11299     hsize_t  count;              /* hyperslab count                      */
11300     hsize_t  block;              /* hyperslab count                      */
11301     hsize_t  dims;               /* dataset size                         */
11302     hsize_t  max_dims;           /* dataset max size                     */
11303     H5D_vds_view_t  view;        /* view from dapl                       */
11304     hsize_t  gap_size;           /* gap size from dapl                   */
11305     char     filename[1024];     /* file names                           */
11306 
11307     TESTING("H5Dget_access_plist() returns dapl w/ correct values");
11308 
11309     /* Create the file */
11310     h5_fixname(FILENAME[5], fapl_id, filename, sizeof(filename));
11311     if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id)) < 0)
11312         FAIL_STACK_ERROR
11313 
11314     /* Create the dcpl and set up VDS mapping */
11315     if((dcpl_id = H5Pcreate(H5P_DATASET_CREATE)) < 0)
11316         FAIL_STACK_ERROR
11317     /* source */
11318     dims = 42;
11319     if((src_sid = H5Screate_simple(1, &dims, NULL)) < 0)
11320         FAIL_STACK_ERROR
11321     /* vds */
11322     dims = 0;
11323     max_dims = H5S_UNLIMITED;
11324     if((vds_sid = H5Screate_simple(1, &dims, &max_dims)) < 0)
11325         FAIL_STACK_ERROR
11326     start = 0;
11327     stride = 42;
11328     count = H5S_UNLIMITED;
11329     block = 42;
11330     if(H5Sselect_hyperslab(vds_sid, H5S_SELECT_SET, &start, &stride, &count, &block) < 0)
11331         FAIL_STACK_ERROR
11332     /* map */
11333     if(H5Pset_virtual(dcpl_id, vds_sid, "f-%b.h5", "/dset1", src_sid) < 0)
11334         FAIL_STACK_ERROR
11335 
11336     /* Create the dapls and set values
11337      * There are two of them. The reason for this is that the only way
11338      * to set the printf gap is to use the default view and using the
11339      * default isn't the best way to test setting and getting the view.
11340      */
11341     /* dapl 1 */
11342     if((dapl_id1 = H5Pcreate(H5P_DATASET_ACCESS)) < 0)
11343         FAIL_STACK_ERROR
11344     if(H5Pset_virtual_view(dapl_id1, H5D_VDS_FIRST_MISSING) < 0)
11345         FAIL_STACK_ERROR
11346     /* dapl 2 */
11347     if((dapl_id2 = H5Pcreate(H5P_DATASET_ACCESS)) < 0)
11348         FAIL_STACK_ERROR
11349     /* default but we set it explicitly to be sure */
11350     if(H5Pset_virtual_view(dapl_id2, H5D_VDS_LAST_AVAILABLE) < 0)
11351         FAIL_STACK_ERROR
11352     if(H5Pset_virtual_printf_gap(dapl_id2, 123) < 0)
11353         FAIL_STACK_ERROR
11354 
11355     /* Create the datasets */
11356     if((did1 = H5Dcreate2(fid, "dset1", H5T_NATIVE_INT, vds_sid, H5P_DEFAULT, dcpl_id, dapl_id1)) < 0)
11357         FAIL_STACK_ERROR
11358     if((did2 = H5Dcreate2(fid, "dset2", H5T_NATIVE_INT, vds_sid, H5P_DEFAULT, dcpl_id, dapl_id2)) < 0)
11359         FAIL_STACK_ERROR
11360 
11361     /* Close the dapls */
11362     if(H5Pclose(dapl_id1) < 0)
11363         FAIL_STACK_ERROR
11364     dapl_id1 = -1;
11365     if(H5Pclose(dapl_id2) < 0)
11366         FAIL_STACK_ERROR
11367     dapl_id2 = -1;
11368 
11369     /* Get a data access property lists from the dataset */
11370     if((dapl_id1 = H5Dget_access_plist(did1)) < 0)
11371         FAIL_STACK_ERROR
11372     if((dapl_id2 = H5Dget_access_plist(did2)) < 0)
11373         FAIL_STACK_ERROR
11374 
11375     /* Check the values from the dapls */
11376     /* dapl 1 */
11377     if(H5Pget_virtual_view(dapl_id1, &view) < 0)
11378         FAIL_STACK_ERROR
11379     if(H5D_VDS_FIRST_MISSING != view)
11380         TEST_ERROR
11381     /* dapl 2 */
11382     if(H5Pget_virtual_view(dapl_id2, &view) < 0)
11383         FAIL_STACK_ERROR
11384     if(H5D_VDS_LAST_AVAILABLE != view)
11385         TEST_ERROR
11386     if(H5Pget_virtual_printf_gap(dapl_id2, &gap_size) < 0)
11387         FAIL_STACK_ERROR
11388     if(gap_size != 123)
11389         TEST_ERROR
11390 
11391     /* Close everything */
11392     if(H5Sclose(vds_sid) < 0) FAIL_STACK_ERROR
11393     if(H5Sclose(src_sid) < 0) FAIL_STACK_ERROR
11394     if(H5Dclose(did1) < 0) FAIL_STACK_ERROR
11395     if(H5Dclose(did2) < 0) FAIL_STACK_ERROR
11396     if(H5Pclose(dapl_id1) < 0) FAIL_STACK_ERROR
11397     if(H5Pclose(dapl_id2) < 0) FAIL_STACK_ERROR
11398     if(H5Pclose(dcpl_id) < 0) FAIL_STACK_ERROR
11399     if(H5Fclose(fid) < 0) FAIL_STACK_ERROR
11400 
11401     PASSED();
11402     return 0;
11403 
11404  error:
11405     H5E_BEGIN_TRY {
11406         H5Dclose(did1);
11407         H5Dclose(did2);
11408         H5Pclose(dapl_id1);
11409         H5Pclose(dapl_id2);
11410         H5Pclose(dcpl_id);
11411         H5Sclose(vds_sid);
11412         H5Sclose(src_sid);
11413         H5Fclose(fid);
11414     } H5E_END_TRY;
11415     return 1;
11416 } /* end test_dapl_values() */
11417 
11418 
11419 /*-------------------------------------------------------------------------
11420  * Function:    main
11421  *
11422  * Purpose:     Tests datasets with virtual layout
11423  *
11424  * Return:      EXIT_SUCCESS/EXIT_FAILURE
11425  *-------------------------------------------------------------------------
11426  */
11427 int
main(void)11428 main(void)
11429 {
11430     char filename[FILENAME_BUF_SIZE];
11431     hid_t fapl;
11432     int test_api_config;
11433     unsigned bit_config;
11434     int nerrors = 0;
11435 
11436     /* Testing setup */
11437     h5_reset();
11438     fapl = h5_fileaccess();
11439 
11440     h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));
11441 
11442     for(test_api_config = (int)TEST_API_BASIC; test_api_config < (int)TEST_API_NTESTS; test_api_config++)
11443         nerrors += test_api((test_api_config_t)test_api_config, fapl);
11444     for(bit_config = 0; bit_config < TEST_IO_NTESTS; bit_config++) {
11445         printf("Config: %s%s%s\n", bit_config & TEST_IO_CLOSE_SRC ? "closed source dataset, " : "", bit_config & TEST_IO_DIFFERENT_FILE ? "different source file" : "same source file", bit_config & TEST_IO_REOPEN_VIRT ? ", reopen virtual file" : "");
11446         nerrors += test_basic_io(bit_config, fapl);
11447         nerrors += test_vds_prefix_first(bit_config, fapl);
11448         nerrors += test_unlim(bit_config, fapl);
11449         nerrors += test_printf(bit_config, fapl);
11450         nerrors += test_all(bit_config, fapl);
11451     }
11452 
11453     nerrors += test_dapl_values(fapl);
11454 
11455     /* Verify symbol table messages are cached */
11456     nerrors += (h5_verify_cached_stabs(FILENAME, fapl) < 0 ? 1 : 0);
11457 
11458     if(nerrors)
11459         goto error;
11460     HDprintf("All virtual dataset tests passed.\n");
11461     h5_cleanup(FILENAME, fapl);
11462 
11463     return EXIT_SUCCESS;
11464 
11465 error:
11466     nerrors = MAX(1, nerrors);
11467     HDprintf("***** %d VIRTUAL DATASET TEST%s FAILED! *****\n",
11468             nerrors, 1 == nerrors ? "" : "S");
11469     return EXIT_FAILURE;
11470 } /* end main() */
11471 
11472