1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group.                                               *
3  * Copyright by the Board of Trustees of the University of Illinois.         *
4  * All rights reserved.                                                      *
5  *                                                                           *
6  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
7  * terms governing use, modification, and redistribution, is contained in    *
8  * the COPYING file, which can be found at the root of the source code       *
9  * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
10  * If you do not have access to either file, you may request a copy from     *
11  * help@hdfgroup.org.                                                        *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 /***********************************************************
15 *
16 * Test program:  swmr
17 *
18 *   To test new public routines from SWMR project:
19 *       H5Pget/set_metadata_read_attempts()
20 *       H5Fget_metadata_read_retry_info()
21 *       H5Fstart_swmr_write()
22 *       H5Pget/set_object_flush_cb()
23 *       H5Pget/set_append_flush()
24 *
25 *************************************************************/
26 
27 #include "h5test.h"
28 #include "H5Iprivate.h"
29 
30 /*
31  * This file needs to access private information from the H5F package.
32  * This file also needs to access the file, file driver, dataset,
33  * and object header testing code.
34  */
35 #define H5F_FRIEND      /*suppress error about including H5Fpkg   */
36 #define H5F_TESTING
37 #include "H5Fpkg.h"     /* File access              */
38 
39 #define H5D_FRIEND      /*suppress error about including H5Dpkg          */
40 #define H5D_TESTING
41 #include "H5Dpkg.h"    /* Datasets                 */
42 
43 #define H5FD_FRIEND     /*suppress error about including H5FDpkg      */
44 #define H5FD_TESTING
45 #include "H5FDpkg.h"    /* File drivers             */
46 
47 #define H5O_FRIEND    /*suppress error about including H5Opkg      */
48 #define H5O_TESTING
49 #include "H5Opkg.h"     /* Object headers            */
50 
51 
52 const char *FILENAME[] = {
53     "swmr0",        /* 0 */
54     "swmr1",        /* 1 */
55     "swmr2",        /* 2 */
56     NULL
57 };
58 
59 
60 #define NAME_BUF_SIZE   1024        /* Length of file name */
61 
62 /* Tests for H5Pget/set_metadata_read_attempts(), H5Fget_metadata_read_retry_info */
63 static int test_metadata_read_attempts(hid_t in_fapl);
64 static int test_metadata_read_retry_info(hid_t in_fapl);
65 
66 /* Tests for H5Fstart_swmr_write() */
67 static int test_start_swmr_write(hid_t in_fapl, hbool_t new_format);
68 static int test_err_start_swmr_write(hid_t in_fapl, hbool_t new_format);
69 static int test_start_swmr_write_concur(hid_t in_fapl, hbool_t new_format);
70 static int test_start_swmr_write_stress_ohdr(hid_t in_fapl);
71 
72 /* Tests for H5Pget/set_object_flush_cb() */
73 static herr_t flush_cb(hid_t obj_id, void *_udata);
74 static int test_object_flush_cb(hid_t in_fapl);
75 
76 /* Tests for H5Pget/set_append_flush() */
77 static herr_t append_cb(hid_t dset_id, hsize_t *cur_dims, void *_udata);
78 static herr_t append_cb2(hid_t dset_id, hsize_t *cur_dims, void *_udata);
79 static int test_append_flush_generic(void);
80 static int test_append_flush_dataset_chunked(hid_t in_fapl);
81 static int test_append_flush_dataset_fixed(hid_t in_fapl);
82 static int test_append_flush_dataset_multiple(hid_t in_fapl);
83 
84 /* Tests for file open flags/SWMR flags: single process access */
85 static int test_file_lock_same(hid_t fapl);
86 static int test_file_lock_swmr_same(hid_t fapl);
87 
88 /* Tests for file open flags/SWMR flags: concurrent process access */
89 static int test_file_lock_concur(hid_t fapl);
90 static int test_file_lock_swmr_concur(hid_t fapl);
91 
92 /* Test file lock environment variable */
93 static int test_file_lock_env_var(hid_t fapl);
94 
95 /* Tests for SWMR VFD flag */
96 static int test_swmr_vfd_flag(void);
97 
98 /* Tests for H5Drefresh: concurrent access */
99 static int test_refresh_concur(hid_t in_fapl, hbool_t new_format);
100 
101 /* Tests for multiple opens of files and datasets with H5Drefresh() & H5Fstart_swmr_write(): same process */
102 static int test_multiple_same(hid_t in_fapl, hbool_t new_format);
103 
104 /*
105  * Tests for H5Pget/set_metadata_read_attemps(), H5Fget_metadata_read_retry_info()
106  */
107 
108 /*
109  *  test_metadata_read_attempts():
110  *
111  *  Checks the following two public routines work as specified:
112  *  H5Pset_metadata_read_attempts()
113  *  H5Pget_metadata_read_attempts()
114  */
115 static int
test_metadata_read_attempts(hid_t in_fapl)116 test_metadata_read_attempts(hid_t in_fapl)
117 {
118     hid_t fapl = -1;                        /* File access property list            */
119     hid_t file_fapl = -1;                   /* The file's access property list      */
120     hid_t fid = -1, fid1 = -1, fid2 = -1;   /* File IDs                             */
121     hid_t driver_id = -1;                   /* ID for this VFD                      */
122     unsigned long driver_flags = 0;         /* VFD feature flags                    */
123     hbool_t compat_w_default_vfd;           /* current VFD compat w/ H5P_DEFAULT?   */
124     unsigned attempts;                      /* The # of read attempts               */
125     char filename[NAME_BUF_SIZE];           /* File name                            */
126     herr_t ret;                             /* Generic return value                 */
127 
128     /* Output message about test being performed */
129     TESTING("H5Pget/set_metadata_read_attempts()");
130 
131     /* Check if the driver is compatible with the default VFD.
132      * Most of the tests will attempt to create and open files with both the
133      * VFD specified in the passed-in fapl and the default VFD. Since this
134      * will clearly not work with VFDs that are not compatible with the default
135      * fapl (e.g.: split/multi), we just skip this entire test.
136      */
137     if ((driver_id = H5Pget_driver(in_fapl)) < 0)
138         FAIL_STACK_ERROR
139     if (H5FDdriver_query(driver_id, &driver_flags) < 0)
140         FAIL_STACK_ERROR
141     compat_w_default_vfd = (driver_flags & H5FD_FEAT_DEFAULT_VFD_COMPATIBLE) ? TRUE : FALSE;
142 
143     if (!compat_w_default_vfd) {
144         SKIPPED()
145         HDputs("    The current VFD is not compatible with the default VFD.");
146         return 0;
147     }
148 
149     /* Get a copy of the parameter fapl */
150     if((fapl = H5Pcopy(in_fapl)) < 0)
151         FAIL_STACK_ERROR
152 
153     /* Set the filename to use for this test (dependent on fapl) */
154     h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));
155 
156     /*
157      * Set A:
158      *  Tests on verifying the # of read attempts when:
159      *    --setting/getting read attempts from a
160      *      file access property list.
161      */
162     /* Get # of read attempts -- should be the default: 1 */
163     if(H5Pget_metadata_read_attempts(fapl, &attempts) < 0)
164         FAIL_STACK_ERROR
165     if(attempts != 1)
166         TEST_ERROR
167 
168     /* Set the # of read attempts to 0--should fail */
169     H5E_BEGIN_TRY {
170         ret = H5Pset_metadata_read_attempts(fapl, 0);
171     } H5E_END_TRY;
172     if(ret >= 0)
173         TEST_ERROR
174 
175     /* Set the # of read attempts to a # > 0--should succeed */
176     if(H5Pset_metadata_read_attempts(fapl, 9) < 0)
177         TEST_ERROR
178 
179     /* Retrieve the # of read attempts -- should be 9 */
180     if(H5Pget_metadata_read_attempts(fapl, &attempts) < 0)
181         FAIL_STACK_ERROR
182     if(attempts != 9)
183         TEST_ERROR
184 
185     /* Set the # of read attempts to the default for non-SWMR access: H5F_METADATA_READ_ATTEMPTS --should succeed */
186     if(H5Pset_metadata_read_attempts(fapl, H5F_METADATA_READ_ATTEMPTS) < 0)
187         TEST_ERROR
188 
189     /* Retrieve the # of read attempts -- should be H5F_METADATA_READ_ATTEMPTS */
190     if(H5Pget_metadata_read_attempts(fapl, &attempts) < 0)
191         FAIL_STACK_ERROR
192     if(attempts != H5F_METADATA_READ_ATTEMPTS)
193         TEST_ERROR
194 
195     /* Set the # of read attempts to the default for SWMR access: H5F_SWMR_METADATA_READ_ATEMPTS --should succeed */
196     if(H5Pset_metadata_read_attempts(fapl, H5F_SWMR_METADATA_READ_ATTEMPTS) < 0)
197         TEST_ERROR
198 
199     /* Retrieve the # of read attempts -- should be H5F_SWMR_METADATA_READ_ATTEMPTS */
200     if(H5Pget_metadata_read_attempts(fapl, &attempts) < 0)
201         FAIL_STACK_ERROR
202     if(attempts != H5F_SWMR_METADATA_READ_ATTEMPTS)
203         TEST_ERROR
204 
205     /* Close the property list */
206     if(H5Pclose(fapl) < 0)
207         FAIL_STACK_ERROR
208 
209     /*
210      * Set B:
211      *  Tests on verifying read attempts when:
212      *    --create a file with non-SWMR access
213      *    --opening files with SWMR access
214      *    --using default or non-default file access property list
215      */
216     /* Test 1 */
217     /* Create a file with non-SWMR access and default fapl */
218     if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
219         FAIL_STACK_ERROR
220 
221     /* Get file's fapl */
222     if((file_fapl = H5Fget_access_plist(fid)) < 0)
223         FAIL_STACK_ERROR
224 
225     /* Retrieve the # of read attempts from file's fapl -- should be H5F_METADATA_READ_ATTEMPTS */
226     if(H5Pget_metadata_read_attempts(file_fapl, &attempts) < 0)
227         FAIL_STACK_ERROR
228     if(attempts != H5F_METADATA_READ_ATTEMPTS)
229         TEST_ERROR
230 
231     /* Close the file */
232     if(H5Fclose(fid) < 0)
233         FAIL_STACK_ERROR
234 
235     /* Close file's fapl */
236     if(H5Pclose(file_fapl) < 0)
237         FAIL_STACK_ERROR
238 
239     /* Test 2 */
240     /* Get a copy of the parameter fapl */
241     if((fapl = H5Pcopy(in_fapl)) < 0)
242         FAIL_STACK_ERROR
243 
244     /* Set to use latest library format */
245     if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
246         FAIL_STACK_ERROR
247 
248     /* Open the file with SWMR access and default read attempts */
249     if((fid = H5Fopen(filename, (H5F_ACC_RDONLY | H5F_ACC_SWMR_READ), fapl)) < 0)
250         FAIL_STACK_ERROR
251 
252     /* Close fapl */
253     if(H5Pclose(fapl) < 0)
254         FAIL_STACK_ERROR
255 
256     /* Get file's fapl */
257     if((file_fapl = H5Fget_access_plist(fid)) < 0)
258         FAIL_STACK_ERROR
259 
260     /* Retrieve the # of read attempts from file's fapl -- should be H5F_SWMR_METADATA_READ_ATTEMPTS */
261     if(H5Pget_metadata_read_attempts(file_fapl, &attempts) < 0)
262         FAIL_STACK_ERROR
263     if(attempts != H5F_SWMR_METADATA_READ_ATTEMPTS)
264         TEST_ERROR
265 
266     /* Close the file */
267     if(H5Fclose(fid) < 0)
268         FAIL_STACK_ERROR
269 
270     /* Close file's fapl */
271     if(H5Pclose(file_fapl) < 0)
272         FAIL_STACK_ERROR
273 
274     /* Test 3 */
275     /* Get a copy of the parameter fapl */
276     if((fapl = H5Pcopy(in_fapl)) < 0)
277         FAIL_STACK_ERROR
278 
279     /* Set to use latest library format */
280     if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
281         FAIL_STACK_ERROR
282 
283     /* Set the # of read attempts */
284     if(H5Pset_metadata_read_attempts(fapl, 9) < 0)
285         FAIL_STACK_ERROR
286 
287     /* Open the file with SWMR access and fapl (non-default & set to 9) */
288     if((fid = H5Fopen(filename, (H5F_ACC_RDONLY | H5F_ACC_SWMR_READ), fapl)) < 0)
289         FAIL_STACK_ERROR
290 
291     /* Close fapl */
292     if(H5Pclose(fapl) < 0)
293         FAIL_STACK_ERROR
294 
295     /* Get file's fapl */
296     if((file_fapl = H5Fget_access_plist(fid)) < 0)
297         FAIL_STACK_ERROR
298 
299     /* Retrieve the # of read attempts from file's fapl -- should be 9 */
300     if(H5Pget_metadata_read_attempts(file_fapl, &attempts) < 0)
301         FAIL_STACK_ERROR
302     if(attempts != 9)
303         TEST_ERROR
304 
305     /* Close the file */
306     if(H5Fclose(fid) < 0)
307     FAIL_STACK_ERROR
308 
309     /* Close file's fapl */
310     if(H5Pclose(file_fapl) < 0)
311         FAIL_STACK_ERROR
312 
313     /* Test 4 */
314     /* Get a copy of the parameter fapl */
315     if((fapl = H5Pcopy(in_fapl)) < 0)
316         FAIL_STACK_ERROR
317 
318     /* Set to use latest library format */
319     if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
320         FAIL_STACK_ERROR
321 
322     /* Set the # of read attempts */
323     if(H5Pset_metadata_read_attempts(fapl, 1) < 0)
324         FAIL_STACK_ERROR
325 
326     /* Open the file with SWMR access and fapl (non-default & set to 1) */
327     if((fid = H5Fopen(filename, (H5F_ACC_RDONLY | H5F_ACC_SWMR_READ), fapl)) < 0)
328         FAIL_STACK_ERROR
329 
330     /* Close fapl */
331     if(H5Pclose(fapl) < 0)
332         FAIL_STACK_ERROR
333 
334     /* Get file's fapl */
335     if((file_fapl = H5Fget_access_plist(fid)) < 0)
336         FAIL_STACK_ERROR
337 
338     /* Retrieve the # of read attempts from file fapl -- should be 1 */
339     if(H5Pget_metadata_read_attempts(file_fapl, &attempts) < 0)
340         FAIL_STACK_ERROR
341     if(attempts != 1)
342         TEST_ERROR
343 
344     /* Close the file */
345     if(H5Fclose(fid) < 0)
346         FAIL_STACK_ERROR
347 
348     /* Close file's fapl */
349     if(H5Pclose(file_fapl) < 0)
350         FAIL_STACK_ERROR
351 
352     /* Test 5 */
353     /* Get a copy of the parameter fapl */
354     if((fapl = H5Pcopy(in_fapl)) < 0)
355         FAIL_STACK_ERROR
356 
357     /* Set to use latest library format */
358     if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
359         FAIL_STACK_ERROR
360 
361     /* Open the file with SWMR_READ and fapl (non-default read attempts but unset) */
362     if((fid = H5Fopen(filename, (H5F_ACC_RDONLY | H5F_ACC_SWMR_READ), fapl)) < 0)
363         FAIL_STACK_ERROR
364 
365     /* Close fapl */
366     if(H5Pclose(fapl) < 0)
367         FAIL_STACK_ERROR
368 
369     /* Get file's fapl */
370     if((file_fapl = H5Fget_access_plist(fid)) < 0)
371         FAIL_STACK_ERROR
372 
373     /* Retrieve the # of read attempts from file's fapl -- should be H5F_SWMR_METADATA_READ_ATTEMPTS */
374     if(H5Pget_metadata_read_attempts(file_fapl, &attempts) < 0)
375         FAIL_STACK_ERROR
376     if(attempts != H5F_SWMR_METADATA_READ_ATTEMPTS)
377         TEST_ERROR
378 
379     /* Close the file */
380     if(H5Fclose(fid) < 0)
381         FAIL_STACK_ERROR
382 
383     /* Close file's fapl */
384     if(H5Pclose(file_fapl) < 0)
385         FAIL_STACK_ERROR
386 
387     /*
388      * Set C:
389      *  Tests on verifying read attempts when:
390      *    --create a file with SWMR access
391      *    --opening files with non-SWMR access
392      *    --using default or non-default file access property list
393      */
394     /* Test 1 */
395     /* Get a copy of the parameter fapl */
396     if((fapl = H5Pcopy(in_fapl)) < 0)
397         FAIL_STACK_ERROR
398 
399     /* Set to use latest library format */
400     if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
401         FAIL_STACK_ERROR
402 
403     /* Create a file with non-SWMR access and default read attempts */
404     if((fid = H5Fcreate(filename, H5F_ACC_TRUNC|H5F_ACC_SWMR_WRITE, H5P_DEFAULT, fapl)) < 0)
405         FAIL_STACK_ERROR
406 
407     /* Close fapl */
408     if(H5Pclose(fapl) < 0)
409         FAIL_STACK_ERROR
410 
411     /* Get file's fapl */
412     if((file_fapl = H5Fget_access_plist(fid)) < 0)
413         FAIL_STACK_ERROR
414 
415     /* Retrieve the # of read attempts from file's fapl -- should be H5F_SWMR_METADATA_READ_ATTEMPTS */
416     if(H5Pget_metadata_read_attempts(file_fapl, &attempts) < 0)
417         FAIL_STACK_ERROR
418     if(attempts != H5F_SWMR_METADATA_READ_ATTEMPTS)
419         TEST_ERROR
420 
421     /* Close the file */
422     if(H5Fclose(fid) < 0)
423         FAIL_STACK_ERROR
424 
425     /* Close file's fapl */
426     if(H5Pclose(file_fapl) < 0)
427         FAIL_STACK_ERROR
428 
429     /* Test 2 */
430     /* Open the file with non-SWMR access and default fapl */
431     if((fid = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
432         FAIL_STACK_ERROR
433 
434     /* Get file's fapl */
435     if((file_fapl = H5Fget_access_plist(fid)) < 0)
436         FAIL_STACK_ERROR
437 
438     /* Retrieve the # of read attempts from file's fapl -- should be H5F_METADATA_READ_ATTEMPTS */
439     if(H5Pget_metadata_read_attempts(file_fapl, &attempts) < 0)
440         FAIL_STACK_ERROR
441     if(attempts != H5F_METADATA_READ_ATTEMPTS)
442         TEST_ERROR
443 
444     /* Close the file */
445     if(H5Fclose(fid) < 0)
446         FAIL_STACK_ERROR
447 
448     /* Close file's fapl */
449     if(H5Pclose(file_fapl) < 0)
450         FAIL_STACK_ERROR
451 
452     /* Test 3 */
453     /* Get a copy of the parameter fapl */
454     if((fapl = H5Pcopy(in_fapl)) < 0)
455         FAIL_STACK_ERROR
456 
457     /* Set the # of read attempts */
458     if(H5Pset_metadata_read_attempts(fapl, 9) < 0)
459         FAIL_STACK_ERROR
460 
461     /* Open the file with non-SWMR access and fapl (non-default & set to 9) */
462     if((fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
463         FAIL_STACK_ERROR
464 
465     /* Close fapl */
466     if(H5Pclose(fapl) < 0)
467         FAIL_STACK_ERROR
468 
469     /* Get file's fapl */
470     if((file_fapl = H5Fget_access_plist(fid)) < 0)
471         FAIL_STACK_ERROR
472 
473     /* Retrieve the # of read attempts from file's fapl -- should be 9 */
474     if(H5Pget_metadata_read_attempts(file_fapl, &attempts) < 0)
475         FAIL_STACK_ERROR
476     if(attempts != 9)
477         TEST_ERROR
478 
479     /* Close the file */
480     if(H5Fclose(fid) < 0)
481         FAIL_STACK_ERROR
482 
483     /* Close file's fapl */
484     if(H5Pclose(file_fapl) < 0)
485         FAIL_STACK_ERROR
486 
487     /* Test 4 */
488     /* Get a copy of the parameter fapl */
489     if((fapl = H5Pcopy(in_fapl)) < 0)
490         FAIL_STACK_ERROR
491 
492     /* Set the # of read attempts */
493     if(H5Pset_metadata_read_attempts(fapl, 1) < 0)
494         FAIL_STACK_ERROR
495 
496     /* Open the file with non-SWMR access and fapl (non-default & set to 1) */
497     if((fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
498         FAIL_STACK_ERROR
499 
500     /* Close fapl */
501     if(H5Pclose(fapl) < 0)
502         FAIL_STACK_ERROR
503 
504     /* Get file's fapl */
505     if((file_fapl = H5Fget_access_plist(fid)) < 0)
506         FAIL_STACK_ERROR
507 
508     /* Retrieve the # of read attempts from file fapl -- should be 1 */
509     if(H5Pget_metadata_read_attempts(file_fapl, &attempts) < 0)
510         FAIL_STACK_ERROR
511     if(attempts != 1)
512         TEST_ERROR
513 
514     /* Close the file */
515     if(H5Fclose(fid) < 0)
516         FAIL_STACK_ERROR
517 
518     /* Close file's fapl */
519     if(H5Pclose(file_fapl) < 0)
520         FAIL_STACK_ERROR
521 
522     /* Test 5 */
523     /* Get a copy of the parameter fapl */
524     if((fapl = H5Pcopy(in_fapl)) < 0)
525         FAIL_STACK_ERROR
526 
527     /* Open the file with non-SWMR_READ and fapl (non-default but unset) */
528     if((fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
529         FAIL_STACK_ERROR
530 
531     /* Close fapl */
532     if(H5Pclose(fapl) < 0)
533         FAIL_STACK_ERROR
534 
535     /* Get file's fapl */
536     if((file_fapl = H5Fget_access_plist(fid)) < 0)
537         FAIL_STACK_ERROR
538 
539     /* Retrieve the # of read attempts from file's fapl -- should be H5F_METADATA_READ_ATTEMPTS */
540     if(H5Pget_metadata_read_attempts(file_fapl, &attempts) < 0)
541         FAIL_STACK_ERROR
542     if(attempts != H5F_METADATA_READ_ATTEMPTS)
543         TEST_ERROR
544 
545     /* Close the file */
546     if(H5Fclose(fid) < 0)
547         FAIL_STACK_ERROR
548 
549     /* Close file's fapl */
550     if(H5Pclose(file_fapl) < 0)
551         FAIL_STACK_ERROR
552 
553     /* Get a copy of the parameter fapl */
554     if((fapl = H5Pcopy(in_fapl)) < 0)
555         FAIL_STACK_ERROR
556 
557     /* Set to use latest library format */
558     if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
559         FAIL_STACK_ERROR
560 
561     /* Set the # of read attempts */
562     if(H5Pset_metadata_read_attempts(fapl, 9) < 0)
563         FAIL_STACK_ERROR
564 
565     /* Create a file */
566     if((fid = H5Fcreate(filename, H5F_ACC_TRUNC|H5F_ACC_SWMR_WRITE, H5P_DEFAULT, fapl)) < 0)
567         FAIL_STACK_ERROR
568 
569     /* Close fapl */
570     if(H5Pclose(fapl) < 0)
571         FAIL_STACK_ERROR
572 
573     /* Close the file */
574     if(H5Fclose(fid) < 0)
575         FAIL_STACK_ERROR
576 
577     /* Open file again with non-SWMR access and default fapl */
578     if((fid = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
579         FAIL_STACK_ERROR
580 
581     /* Get file's fapl */
582     if((file_fapl = H5Fget_access_plist(fid)) < 0)
583         FAIL_STACK_ERROR
584 
585     /* Retrieve the # of read attempts from file fapl -- should be H5F_METADATA_READ_ATTEMPTS */
586     if(H5Pget_metadata_read_attempts(file_fapl, &attempts) < 0)
587         FAIL_STACK_ERROR
588     if(attempts != H5F_METADATA_READ_ATTEMPTS)
589         TEST_ERROR
590 
591     /* Close the file's fapl */
592     if(H5Pclose(file_fapl) < 0)
593         FAIL_STACK_ERROR
594 
595     /* Close the file */
596     if(H5Fclose(fid) < 0)
597         FAIL_STACK_ERROR
598 
599     /* Get a copy of the parameter fapl */
600     if((fapl = H5Pcopy(in_fapl)) < 0)
601         FAIL_STACK_ERROR
602 
603     /* Set to use latest library format */
604     if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
605         FAIL_STACK_ERROR
606 
607     /* Open file again with SWMR access and default read attempts */
608     if((fid = H5Fopen(filename, H5F_ACC_SWMR_READ, fapl)) < 0)
609         FAIL_STACK_ERROR
610 
611     /* Close fapl */
612     if(H5Pclose(fapl) < 0)
613         FAIL_STACK_ERROR
614 
615     /* Get file's fapl */
616     if((file_fapl = H5Fget_access_plist(fid)) < 0)
617         FAIL_STACK_ERROR
618 
619     /* Retrieve the # of read attempts from file fapl -- should be H5F_SWMR_METADATA_READ_ATTEMPTS */
620     if(H5Pget_metadata_read_attempts(file_fapl, &attempts) < 0)
621         FAIL_STACK_ERROR
622     if(attempts != H5F_SWMR_METADATA_READ_ATTEMPTS)
623         TEST_ERROR
624 
625     /* Close the file's fapl */
626     if(H5Pclose(file_fapl) < 0)
627         FAIL_STACK_ERROR
628 
629     /* Close the file */
630     if(H5Fclose(fid) < 0)
631         FAIL_STACK_ERROR
632 
633     /*
634      * Set D:
635      *  Tests on verifying read attempts when:
636      *    --create with non-SWMR access
637      *    --opening files with SWMR access
638      *    --H5reopen the files
639      */
640 
641     /* Create a file */
642     if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
643         FAIL_STACK_ERROR
644 
645     /* Close the file */
646     if(H5Fclose(fid) < 0)
647         FAIL_STACK_ERROR
648 
649     /* Get a copy of the parameter fapl */
650     if((fapl = H5Pcopy(in_fapl)) < 0)
651         FAIL_STACK_ERROR
652 
653     /* Set to use latest library format */
654     if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
655         FAIL_STACK_ERROR
656 
657     /* Open file again with SWMR access and default read attempts */
658     if((fid1 = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl)) < 0)
659         FAIL_STACK_ERROR
660 
661     /* Set the # of read attempts */
662     if(H5Pset_metadata_read_attempts(fapl, 9) < 0)
663         FAIL_STACK_ERROR
664 
665     /* Open file again with SWMR access and fapl (non-default & set to 9) */
666     if((fid2 = H5Fopen(filename, (H5F_ACC_RDONLY | H5F_ACC_SWMR_READ), fapl)) < 0)
667         FAIL_STACK_ERROR
668 
669     /* Close fapl */
670     if(H5Pclose(fapl) < 0)
671         FAIL_STACK_ERROR
672 
673     /* Re-open fid1 */
674     if((fid = H5Freopen(fid1)) < 0)
675         FAIL_STACK_ERROR
676 
677     /* Get file's fapl */
678     if((file_fapl = H5Fget_access_plist(fid)) < 0)
679         FAIL_STACK_ERROR
680 
681     /* Retrieve the # of read attempts from file fapl -- should be H5F_SWMR_METADATA_READ_ATTEMPTS */
682     if(H5Pget_metadata_read_attempts(file_fapl, &attempts) < 0)
683         FAIL_STACK_ERROR
684     if(attempts != H5F_SWMR_METADATA_READ_ATTEMPTS)
685         TEST_ERROR
686 
687     /* Close the file's fapl */
688     if(H5Pclose(file_fapl) < 0)
689         FAIL_STACK_ERROR
690 
691     /* Close the file */
692     if(H5Fclose(fid) < 0)
693         FAIL_STACK_ERROR
694 
695     /* Re-open fid2 */
696     if((fid = H5Freopen(fid2)) < 0)
697         FAIL_STACK_ERROR
698 
699     /* Get file's fapl */
700     if((file_fapl = H5Fget_access_plist(fid)) < 0)
701         FAIL_STACK_ERROR
702 
703     /* Retrieve the # of read attempts from file fapl -- should be H5F_SWMR_METADATA_READ_ATTEMPTS, not 9 */
704     if(H5Pget_metadata_read_attempts(file_fapl, &attempts) < 0)
705         FAIL_STACK_ERROR
706     if(attempts != H5F_SWMR_METADATA_READ_ATTEMPTS)
707         TEST_ERROR
708 
709     /* Close the file's fapl */
710     if(H5Pclose(file_fapl) < 0)
711         FAIL_STACK_ERROR
712 
713     /* Close the file */
714     if(H5Fclose(fid) < 0)
715         FAIL_STACK_ERROR
716 
717     /* Close all the files */
718     if(H5Fclose(fid1) < 0)
719         FAIL_STACK_ERROR
720     if(H5Fclose(fid2) < 0)
721         FAIL_STACK_ERROR
722 
723     /*
724      * Set E:
725      *  Tests on verifying read attempts when:
726      *    --create with SWMR access
727      *    --opening files with non-SWMR access
728      *    --H5reopen the files
729      */
730 
731     /* Get a copy of the parameter fapl */
732     if((fapl = H5Pcopy(in_fapl)) < 0)
733         FAIL_STACK_ERROR
734 
735     /* Set to use latest library format */
736     if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
737         FAIL_STACK_ERROR
738 
739     /* Create a file */
740     if((fid = H5Fcreate(filename, H5F_ACC_TRUNC|H5F_ACC_SWMR_WRITE, H5P_DEFAULT, fapl)) < 0)
741         FAIL_STACK_ERROR
742 
743     /* Close fapl */
744     if(H5Pclose(fapl) < 0)
745         FAIL_STACK_ERROR
746 
747     /* Close the file */
748     if(H5Fclose(fid) < 0)
749         FAIL_STACK_ERROR
750 
751     /* Open file again with non-SWMR access and default fapl */
752     if((fid1 = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
753         FAIL_STACK_ERROR
754 
755     /* Get a copy of the parameter fapl */
756     if((fapl = H5Pcopy(in_fapl)) < 0)
757         FAIL_STACK_ERROR
758 
759     /* Set the # of read attempts */
760     if(H5Pset_metadata_read_attempts(fapl, 9) < 0)
761         FAIL_STACK_ERROR
762 
763     /* Open file again with non-SWMR access and fapl (non-default & set to 9) */
764     if((fid2 = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
765         FAIL_STACK_ERROR
766 
767     /* Close fapl */
768     if(H5Pclose(fapl) < 0)
769         FAIL_STACK_ERROR
770 
771     /* Re-open fid1 */
772     if((fid = H5Freopen(fid1)) < 0)
773         FAIL_STACK_ERROR
774 
775     /* Get file's fapl */
776     if((file_fapl = H5Fget_access_plist(fid)) < 0)
777         FAIL_STACK_ERROR
778 
779     /* Retrieve the # of read attempts from file fapl -- should be H5F_METADATA_READ_ATTEMPTS */
780     if(H5Pget_metadata_read_attempts(file_fapl, &attempts) < 0)
781         FAIL_STACK_ERROR
782     if(attempts != H5F_METADATA_READ_ATTEMPTS)
783         TEST_ERROR
784 
785     /* Close the file's fapl */
786     if(H5Pclose(file_fapl) < 0)
787         FAIL_STACK_ERROR
788 
789     /* Close the file */
790     if(H5Fclose(fid) < 0)
791         FAIL_STACK_ERROR
792 
793     /* Re-open fid2 */
794     if((fid = H5Freopen(fid2)) < 0)
795         FAIL_STACK_ERROR
796 
797     /* Get file's fapl */
798     if((file_fapl = H5Fget_access_plist(fid)) < 0)
799         FAIL_STACK_ERROR
800 
801     /* Retrieve the # of read attempts from file fapl -- should be H5F_METADATA_READ_ATTEMPTS */
802     if(H5Pget_metadata_read_attempts(file_fapl, &attempts) < 0)
803         FAIL_STACK_ERROR
804     if(attempts != H5F_METADATA_READ_ATTEMPTS)
805         TEST_ERROR
806 
807     /* Close the file's fapl */
808     if(H5Pclose(file_fapl) < 0)
809         FAIL_STACK_ERROR
810 
811     /* Close the file */
812     if(H5Fclose(fid) < 0)
813         FAIL_STACK_ERROR
814 
815     /* Close all the files */
816     if(H5Fclose(fid1) < 0)
817         FAIL_STACK_ERROR
818     if(H5Fclose(fid2) < 0)
819         FAIL_STACK_ERROR
820 
821     PASSED();
822     return 0;
823 
824 error:
825     H5E_BEGIN_TRY {
826         H5Pclose(fapl);
827         H5Pclose(file_fapl);
828         H5Fclose(fid);
829         H5Fclose(fid1);
830         H5Fclose(fid2);
831     } H5E_END_TRY;
832 
833     return -1;
834 
835 
836 } /* test_metadata_read_attempts() */
837 
838 /*
839  *  test_metadata_read_retry_info():
840  *
841  *  Checks whether the public routine H5Fget_metadata_read_retry_info
842  *  works as specified.
843  *
844  */
845 static int
test_metadata_read_retry_info(hid_t in_fapl)846 test_metadata_read_retry_info(hid_t in_fapl)
847 {
848     hid_t fapl, new_fapl;       /* File access property list */
849     hid_t fid, fid1;            /* File IDs */
850     H5F_retry_info_t info, info1;   /* The collection of metadata retries */
851     H5F_t *f = NULL, *f1 = NULL;    /* Internal file object pointers */
852     unsigned i, j, n;           /* Local index variables */
853     hid_t did1, did2;           /* Dataset IDs */
854     hid_t sid;              /* Dataspace ID */
855     hid_t dcpl;             /* Dataset creation property list */
856     hsize_t dims[2] = {6, 10};      /* Dataset dimensions */
857     char filename[NAME_BUF_SIZE];       /* File name */
858     int buf[6][10], chkbuf1[6][10], chkbuf2[6][10];     /* Buffers for data */
859     hsize_t max_dims_1un[2] = {H5S_UNLIMITED, H5S_UNLIMITED};   /* Dataset maximum dimensions */
860     hsize_t max_dims_2un[2] = {500, H5S_UNLIMITED};         /* Dataset maximum dimensions */
861     hsize_t chunk_dims[2] = {2, 2};                 /* Chunk dimensions */
862 
863     /* Output message about test being performed */
864     TESTING("H5Fset_metadata_read_retry_info()");
865 
866     /* Get a copy of the parameter in_fapl */
867     if((fapl = H5Pcopy(in_fapl)) < 0)
868         FAIL_STACK_ERROR
869 
870     /* Set the filename to use for this test (dependent on fapl) */
871     h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));
872 
873     /* Set to use latest library format */
874     if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
875         FAIL_STACK_ERROR
876 
877     /* Create a file without SWMR access */
878     if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
879         FAIL_STACK_ERROR
880 
881     /* Create a chunked dataset with 1 unlimited dimension: extensible array indexing will be used */
882     if((sid = H5Screate_simple(2, dims, max_dims_1un)) < 0)
883         FAIL_STACK_ERROR
884     if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
885         FAIL_STACK_ERROR
886     if(H5Pset_chunk(dcpl, 2, chunk_dims) < 0)
887         FAIL_STACK_ERROR
888     if((did1 = H5Dcreate2(fid, "DSET_1UNLIM", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
889         FAIL_STACK_ERROR
890 
891     /* Create a chunked dataset with 2 unlimited dimension: v2 Btree indexing will be used */
892     if((sid = H5Screate_simple(2, dims, max_dims_2un)) < 0)
893         FAIL_STACK_ERROR
894     if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
895         FAIL_STACK_ERROR
896     if(H5Pset_chunk(dcpl, 2, chunk_dims) < 0)
897         FAIL_STACK_ERROR
898     if((did2 = H5Dcreate2(fid, "DSET_2UNLIM", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
899         FAIL_STACK_ERROR
900 
901     /* Initialize buffer data */
902     for(i = n = 0; i < 6; i++)
903         for(j = 0; j < 10; j++)
904               buf[i][j] = (int)n++;
905 
906     /* Write to the 2 datasets */
907     if(H5Dwrite(did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0)
908         FAIL_STACK_ERROR
909     if(H5Dwrite(did2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0)
910         FAIL_STACK_ERROR
911 
912     /* Closing */
913     if(H5Dclose(did1) < 0)
914         FAIL_STACK_ERROR
915     if(H5Dclose(did2) < 0)
916         FAIL_STACK_ERROR
917     if(H5Sclose(sid) < 0)
918         FAIL_STACK_ERROR
919     if(H5Pclose(dcpl) < 0)
920         FAIL_STACK_ERROR
921     if(H5Fclose(fid) < 0)
922         FAIL_STACK_ERROR
923 
924     /*
925      *  Case 1: tests on nbins
926      */
927     /*
928      * Open a file without SWMR access, default # of read attempts--
929      *   info.nbins should be 0
930      *   info.retries should all be NULL
931      */
932     /* Open the file without SWMR access */
933     if((fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
934         FAIL_STACK_ERROR
935 
936     /* Open the dataset */
937     if((did1 = H5Dopen2(fid, "DSET_1UNLIM", H5P_DEFAULT)) < 0)
938         FAIL_STACK_ERROR
939 
940     if(H5Dread(did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, chkbuf1) < 0)
941         FAIL_STACK_ERROR
942 
943     /* Open the dataset */
944     if((did2 = H5Dopen2(fid, "DSET_2UNLIM", H5P_DEFAULT)) < 0)
945         FAIL_STACK_ERROR
946     if(H5Dread(did2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, chkbuf2) < 0)
947         FAIL_STACK_ERROR
948 
949     /* Retrieve retries information */
950     if(H5Fget_metadata_read_retry_info(fid, &info) < 0)
951         FAIL_STACK_ERROR
952 
953     /* Should be 0 */
954     if(info.nbins != 0)
955         TEST_ERROR
956 
957     /* Should be all NULL */
958     for(i = 0; i < H5F_NUM_METADATA_READ_RETRY_TYPES; i++)
959         if(info.retries[i] != NULL)
960             TEST_ERROR
961 
962     /* Closing */
963     if(H5Dclose(did1) < 0)
964         FAIL_STACK_ERROR
965     if(H5Dclose(did2) < 0)
966         FAIL_STACK_ERROR
967     if(H5Fclose(fid) < 0)
968         FAIL_STACK_ERROR
969 
970 
971     /*
972      * Open a file with SWMR access, default # of read attempts--
973      *   info.nbins should be 2
974      *   info.retries should all be NULL
975      */
976     /* Open the file with SWMR access */
977     if((fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl)) < 0)
978         FAIL_STACK_ERROR
979 
980     /* Retrieve retries information */
981     if(H5Fget_metadata_read_retry_info(fid, &info) < 0)
982         FAIL_STACK_ERROR
983 
984     /* Should be 2 */
985     if(info.nbins != 2)
986         TEST_ERROR
987 
988     /* Should be all NULL */
989     for(i = 0; i < H5F_NUM_METADATA_READ_RETRY_TYPES; i++)
990         if(info.retries[i] != NULL)
991             TEST_ERROR
992 
993     /* Closing */
994     if(H5Fclose(fid) < 0)
995         FAIL_STACK_ERROR
996 
997     /*
998      * Open a file with SWMR access, # of read_attempts is 10:
999      *   info.nbins should be 1
1000      *   info.retries should all be NULL
1001      */
1002     if((new_fapl = H5Pcopy(fapl)) < 0)
1003         FAIL_STACK_ERROR
1004 
1005     if(H5Pset_metadata_read_attempts(new_fapl, 10) < 0)
1006         FAIL_STACK_ERROR
1007 
1008     /* Open the file with SWMR access */
1009     if((fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, new_fapl)) < 0)
1010         FAIL_STACK_ERROR
1011 
1012     /* Retrieve retry information */
1013     if(H5Fget_metadata_read_retry_info(fid, &info) < 0)
1014         FAIL_STACK_ERROR
1015 
1016     /* Should be 1 */
1017     if(info.nbins != 1)
1018         TEST_ERROR
1019 
1020     /* Should be all NULL */
1021     for(i = 0; i < H5F_NUM_METADATA_READ_RETRY_TYPES; i++)
1022         if(info.retries[i] != NULL)
1023             TEST_ERROR
1024 
1025     /* Closing */
1026     if(H5Pclose(new_fapl) < 0)
1027         FAIL_STACK_ERROR
1028     if(H5Fclose(fid) < 0)
1029         FAIL_STACK_ERROR
1030 
1031     /*
1032      * Open a file with SWMR access, # of read attempts is 101:
1033      *   info.nbins should be 3
1034      *   info.retries should all be NULL
1035      */
1036     if((new_fapl = H5Pcopy(fapl)) < 0)
1037         FAIL_STACK_ERROR
1038     if(H5Pset_metadata_read_attempts(new_fapl, 101) < 0)
1039         FAIL_STACK_ERROR
1040 
1041     /* Open the file with SWMR access */
1042     if((fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, new_fapl)) < 0)
1043         FAIL_STACK_ERROR
1044 
1045     /* Retrieve retry information */
1046     if(H5Fget_metadata_read_retry_info(fid, &info) < 0)
1047         FAIL_STACK_ERROR
1048 
1049     /* Should be 3 */
1050     if(info.nbins != 3)
1051         TEST_ERROR
1052 
1053     /* Should be all NULL */
1054     for(i = 0; i < H5F_NUM_METADATA_READ_RETRY_TYPES; i++)
1055         if(info.retries[i] != NULL)
1056             TEST_ERROR
1057 
1058     /* Closing */
1059     if(H5Pclose(new_fapl) < 0)
1060         FAIL_STACK_ERROR
1061     if(H5Fclose(fid) < 0)
1062         FAIL_STACK_ERROR
1063 
1064     /*
1065      * Open a file with SWMR access, # of read_attempts is 10000:
1066      *   info.nbins should be 4
1067      *   info.retries should all be NULL
1068      */
1069     if((new_fapl = H5Pcopy(fapl)) < 0)
1070         FAIL_STACK_ERROR
1071 
1072     if(H5Pset_metadata_read_attempts(new_fapl, 10000) < 0)
1073         FAIL_STACK_ERROR
1074 
1075     /* Open the file with SWMR access */
1076     if((fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, new_fapl)) < 0)
1077         FAIL_STACK_ERROR
1078 
1079     /* Retrieve retry information */
1080     if(H5Fget_metadata_read_retry_info(fid, &info) < 0)
1081         FAIL_STACK_ERROR
1082 
1083     /* Should be 4 */
1084     if(info.nbins != 4)
1085         TEST_ERROR
1086 
1087     /* Should be all NULL */
1088     for(i = 0; i < H5F_NUM_METADATA_READ_RETRY_TYPES; i++)
1089         if(info.retries[i] != NULL)
1090             TEST_ERROR
1091 
1092     /* Closing */
1093     if(H5Pclose(new_fapl) < 0)
1094         FAIL_STACK_ERROR
1095     if(H5Fclose(fid) < 0)
1096         FAIL_STACK_ERROR
1097 
1098     /*
1099      * Open a file with SWMR access, # of read_attempts is 1:
1100      *   info.nbins should be 0
1101      *   info.retries should all be NULL
1102      */
1103     if((new_fapl = H5Pcopy(fapl)) < 0)
1104         FAIL_STACK_ERROR
1105 
1106     if(H5Pset_metadata_read_attempts(new_fapl, 1) < 0)
1107         FAIL_STACK_ERROR
1108 
1109     /* Open the file with SWMR access */
1110     if((fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, new_fapl)) < 0)
1111         FAIL_STACK_ERROR
1112 
1113     /* Retrieve retry information */
1114     if(H5Fget_metadata_read_retry_info(fid, &info) < 0)
1115         FAIL_STACK_ERROR
1116 
1117     /* Should be 0 */
1118     if(info.nbins != 0)
1119         TEST_ERROR
1120 
1121     /* Should be all NULL */
1122     for(i = 0; i < H5F_NUM_METADATA_READ_RETRY_TYPES; i++)
1123         if(info.retries[i] != NULL)
1124             TEST_ERROR
1125 
1126     /* Closing */
1127     if(H5Pclose(new_fapl) < 0)
1128         FAIL_STACK_ERROR
1129     if(H5Fclose(fid) < 0)
1130         FAIL_STACK_ERROR
1131 
1132 
1133     /*
1134      * Case 2: tests on retries info
1135      */
1136 
1137     /* Open the file with SWMR access */
1138     if((fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl)) < 0)
1139         FAIL_STACK_ERROR
1140 
1141     /* Open the dataset */
1142     if((did1 = H5Dopen2(fid, "DSET_1UNLIM", H5P_DEFAULT)) < 0)
1143         FAIL_STACK_ERROR
1144 
1145     /* Read data from the dataset */
1146     if(H5Dread(did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, chkbuf1) < 0)
1147         FAIL_STACK_ERROR
1148 
1149     /* Open the dataset */
1150     if((did2 = H5Dopen2(fid, "DSET_2UNLIM", H5P_DEFAULT)) < 0)
1151         FAIL_STACK_ERROR
1152 
1153     /* Read data from the dataset */
1154     if(H5Dread(did2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, chkbuf2) < 0)
1155         FAIL_STACK_ERROR
1156 
1157     /* Retrieve retry information */
1158     if(H5Fget_metadata_read_retry_info(fid, &info) < 0)
1159         FAIL_STACK_ERROR
1160 
1161     /* Should be 2 */
1162     if(info.nbins != 2)
1163         TEST_ERROR
1164 
1165     /* Should be all NULL */
1166     for(i = 0; i < H5F_NUM_METADATA_READ_RETRY_TYPES; i++)
1167         if(info.retries[i] != NULL)
1168             TEST_ERROR
1169 
1170     /* Get a pointer to the internal file object */
1171     if((f = (H5F_t *)H5I_object(fid)) == NULL)
1172         FAIL_STACK_ERROR
1173 
1174     /*
1175      * Increment 1st set of retries for metadata items:
1176      *   a) v2 B-tree leaf node--retries[4][1]
1177      *   b) Extensive array data block--retries[15][1]
1178      *   c) File's superblock--retries[20][0]
1179      */
1180 
1181     /* v2 B-tree leaf node: log retry 99 for 500 times */
1182     for(i = 0; i < 500; i++) {
1183         if(H5F_track_metadata_read_retries(f, H5AC_BT2_LEAF_ID, 99) < 0)
1184             FAIL_STACK_ERROR
1185     }
1186 
1187     /* Extensive array data block: log retry 10 for 1000 times */
1188     for(i = 0; i < 1000; i++)
1189         if(H5F_track_metadata_read_retries(f, H5AC_EARRAY_DBLOCK_ID, 10) < 0)
1190             FAIL_STACK_ERROR
1191 
1192     /* File's superblock: log retry 1 for 1 time */
1193     if(H5F_track_metadata_read_retries(f, H5AC_SUPERBLOCK_ID, 1) < 0)
1194         FAIL_STACK_ERROR
1195 
1196     /* Retrieve the collection of metadata read retries */
1197     if(H5Fget_metadata_read_retry_info(fid, &info) < 0)
1198         FAIL_STACK_ERROR
1199 
1200     /* Verify retries for v2 B-tree leaf node */
1201     if(info.retries[4][0] != 0)
1202         TEST_ERROR
1203     if(info.retries[4][1] != 500)
1204         TEST_ERROR
1205 
1206     /* Verify retries for extensive array data block */
1207     if(info.retries[15][0] != 0)
1208         TEST_ERROR
1209     if(info.retries[15][1] != 1000)
1210         TEST_ERROR
1211 
1212     /* Verify retries for file's superblock */
1213     if(info.retries[20][0] != 1)
1214         TEST_ERROR
1215     if(info.retries[20][1] != 0)
1216         TEST_ERROR
1217 
1218     /* Free memory for info.retries */
1219     for(i = 0; i < H5F_NUM_METADATA_READ_RETRY_TYPES; i++)  {
1220         if(info.retries[i] != NULL)
1221             H5free_memory(info.retries[i]);
1222     }
1223 
1224     /*
1225      * Increment 2nd set of retries for metadata items:
1226      *   a) Object header--retries[0][0]
1227      *   b) Extensive array datablock--retries[15][0]
1228      *   c) Fixed array header--retries[17][1]
1229      *   d) File's superblock--retries[20][0]
1230      */
1231 
1232     /* Object header: log retry 5 for 5 times */
1233     for(i = 0; i < 5; i++) {
1234         if(H5F_track_metadata_read_retries(f, H5AC_OHDR_ID, 5) < 0)
1235             TEST_ERROR
1236     }
1237 
1238     /* Extensive array data block: log retry 4 for 1 time */
1239     if(H5F_track_metadata_read_retries(f, H5AC_EARRAY_DBLOCK_ID, 4) < 0)
1240         TEST_ERROR
1241 
1242     /* Fixed array header : log retry 50 for 10000 times */
1243     for(i = 0; i < 10000; i++) {
1244         if(H5F_track_metadata_read_retries(f, H5AC_FARRAY_HDR_ID, 50) < 0)
1245             TEST_ERROR
1246     }
1247 
1248     /* File's superblock: log retry 1 for 1 more time */
1249     if(H5F_track_metadata_read_retries(f, H5AC_SUPERBLOCK_ID, 1) < 0)
1250         FAIL_STACK_ERROR
1251 
1252     /* Retrieve the collection of metadata read retries */
1253     if(H5Fget_metadata_read_retry_info(fid, &info) < 0)
1254         FAIL_STACK_ERROR
1255 
1256     /*
1257      * Verify info has both previous + current retries information:
1258      */
1259     for(i = 0; i < H5F_NUM_METADATA_READ_RETRY_TYPES; i++) {
1260         switch(i) {
1261             case 0: /* Object header */
1262                 if(info.retries[i][0] != 5)
1263                     TEST_ERROR
1264                 if(info.retries[i][1] != 0)
1265                     TEST_ERROR
1266                 break;
1267 
1268             case 4: /* v2 B-tree leaf node */
1269                 if(info.retries[i][0] != 0)
1270                     TEST_ERROR
1271                 if(info.retries[i][1] != 500)
1272                     TEST_ERROR
1273                 break;
1274 
1275             case 15: /* Extensive array data block */
1276                 if(info.retries[i][0] != 1)
1277                     TEST_ERROR
1278                 if(info.retries[i][1] != 1000)
1279                     TEST_ERROR
1280                 break;
1281 
1282             case 17: /* Fixed array header */
1283                 if(info.retries[i][0] != 0)
1284                     TEST_ERROR
1285                 if(info.retries[i][1] != 10000)
1286                     TEST_ERROR
1287                 break;
1288 
1289             case 20: /* File's superblock */
1290                 if(info.retries[i][0] != 2)
1291                     TEST_ERROR
1292                 if(info.retries[i][1] != 0)
1293                     TEST_ERROR
1294                 break;
1295 
1296             default:
1297                 if(info.retries[i] != NULL)
1298                     TEST_ERROR
1299                 break;
1300         }
1301     }
1302 
1303     /* Free memory for info.retries */
1304     for(i = 0; i < H5F_NUM_METADATA_READ_RETRY_TYPES; i++)
1305         if(info.retries[i] != NULL)
1306             H5free_memory(info.retries[i]);
1307 
1308     /* Closing */
1309     if(H5Dclose(did1) < 0)
1310         FAIL_STACK_ERROR
1311     if(H5Dclose(did2) < 0)
1312         FAIL_STACK_ERROR
1313     if(H5Fclose(fid) < 0)
1314         FAIL_STACK_ERROR
1315 
1316     /* Get a copy of the file access property list */
1317     if((new_fapl = H5Pcopy(fapl)) < 0)
1318         FAIL_STACK_ERROR
1319 
1320     /* Set the number of metadata read attempts to 101 */
1321     if(H5Pset_metadata_read_attempts(new_fapl, 101) < 0)
1322         FAIL_STACK_ERROR
1323 
1324     /* Open the file with SWMR access */
1325     if((fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, new_fapl)) < 0)
1326         FAIL_STACK_ERROR
1327 
1328     /* Get a pointer to the internal file object */
1329     if((f = (H5F_t *)H5I_object(fid)) == NULL)
1330         FAIL_STACK_ERROR
1331 
1332     /* File's superblock: log retry 1 for 1 time */
1333     if(H5F_track_metadata_read_retries(f, H5AC_SUPERBLOCK_ID, 1) < 0)
1334         FAIL_STACK_ERROR
1335 
1336     /* Retrieve the collection of metadata read retries */
1337     if(H5Fget_metadata_read_retry_info(fid, &info) < 0)
1338         FAIL_STACK_ERROR
1339 
1340     /* Should be 3 */
1341     if(info.nbins != 3)
1342         TEST_ERROR
1343 
1344     /* Verify retries info */
1345     for(i = 0; i < H5F_NUM_METADATA_READ_RETRY_TYPES; i++) {
1346         switch(i) {
1347             case 20: /* File's superblock */
1348                 if(info.retries[i][0] != 1)
1349                     TEST_ERROR
1350                 if(info.retries[i][1] != 0)
1351                     TEST_ERROR
1352                 if(info.retries[i][2] != 0)
1353                     TEST_ERROR
1354                 break;
1355 
1356             default:
1357                 if(info.retries[i] != NULL)
1358                     TEST_ERROR
1359                 break;
1360         }
1361     }
1362 
1363     /* Free memory */
1364     for(i = 0; i < H5F_NUM_METADATA_READ_RETRY_TYPES; i++)
1365         if(info.retries[i] != NULL)
1366             H5free_memory(info.retries[i]);
1367 
1368     /* Closing */
1369     if(H5Pclose(new_fapl) < 0)
1370         FAIL_STACK_ERROR
1371     if(H5Fclose(fid) < 0)
1372         FAIL_STACK_ERROR
1373 
1374     /*
1375      * Case 3: Tests on retrieving the collection of retries
1376      *         when H5Fopen and H5Freopen the same file.
1377      */
1378 
1379     /*
1380      * Open a file without SWMR access, default # of read attempts--
1381      * H5Freopen the same file--
1382      * Both files should:
1383      *   nbins should be 0
1384      *   retries should all be NULL
1385      */
1386     /* Open the file without SWMR access */
1387     if((fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
1388         FAIL_STACK_ERROR
1389 
1390     /* Re-open fid */
1391     if((fid1 = H5Freopen(fid)) < 0)
1392         FAIL_STACK_ERROR
1393 
1394     /* Retrieve retries information for fid */
1395     if(H5Fget_metadata_read_retry_info(fid, &info) < 0)
1396         FAIL_STACK_ERROR
1397 
1398     /* Retrieve retries information for fid1*/
1399     if(H5Fget_metadata_read_retry_info(fid1, &info1)< 0)
1400         FAIL_STACK_ERROR
1401 
1402     /* Should be 0 */
1403     if(info.nbins != 0)
1404         TEST_ERROR
1405     if(info1.nbins != 0)
1406         TEST_ERROR
1407 
1408     /* Should be all NULL */
1409     for(i = 0; i < H5F_NUM_METADATA_READ_RETRY_TYPES; i++) {
1410         if(info.retries[i] != NULL)
1411             TEST_ERROR
1412         if(info1.retries[i] != NULL)
1413             TEST_ERROR
1414     }
1415 
1416     /* Closing */
1417     if(H5Fclose(fid) < 0)
1418         FAIL_STACK_ERROR
1419     if(H5Fclose(fid1) < 0)
1420         FAIL_STACK_ERROR
1421 
1422     /*
1423      * Open a file with SWMR access, default # of read attempts:
1424      *   --increment retries for metadata item: fixed array data block page (retries[19][0])
1425      * H5Freopen the same file:
1426      *   --increment retries for metadata item: free-space sections (retries[9][1])--
1427      */
1428     /* Open the file with SWMR access */
1429     if((fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl)) < 0)
1430         FAIL_STACK_ERROR
1431 
1432     /* Get a pointer to the internal file object for fid */
1433     if((f = (H5F_t *)H5I_object(fid)) == NULL)
1434         FAIL_STACK_ERROR
1435 
1436     /* Re-open fid */
1437     if((fid1 = H5Freopen(fid)) < 0)
1438         FAIL_STACK_ERROR
1439 
1440     /* Get a pointer to the internal file object for fid1 */
1441     if((f1 = (H5F_t *)H5I_object(fid1)) == NULL)
1442         FAIL_STACK_ERROR
1443 
1444     /* For fid: fixed array data block page--log retry 9 for 500 times */
1445     for(i = 0; i < 500; i++) {
1446         if(H5F_track_metadata_read_retries(f, H5AC_FARRAY_DBLK_PAGE_ID, 9) < 0)
1447             FAIL_STACK_ERROR
1448     }
1449 
1450     /* For fid1: free-space sections--log retry 99 for 1000 times */
1451     for(i = 0; i < 1000; i++) {
1452         if(H5F_track_metadata_read_retries(f1, H5AC_FSPACE_SINFO_ID, 99) < 0)
1453             FAIL_STACK_ERROR
1454     }
1455 
1456     /* Retrieve the collection of metadata read retries for fid */
1457     if(H5Fget_metadata_read_retry_info(fid, &info) < 0)
1458         FAIL_STACK_ERROR
1459 
1460     /* Retrieve the collection of metadata read retries for fid1 */
1461     if(H5Fget_metadata_read_retry_info(fid1, &info1) < 0)
1462         FAIL_STACK_ERROR
1463 
1464     /* Verify nbins for fid & fid1: should be 2 */
1465     if(info.nbins != 2)
1466         TEST_ERROR
1467     if(info1.nbins != 2)
1468         TEST_ERROR
1469 
1470     /* Verify retries for fid: fixed array data block page */
1471     if(info.retries[19][0] != 500)
1472         TEST_ERROR
1473     if(info.retries[19][1] != 0)
1474         TEST_ERROR
1475 
1476     /* Verify retries for fid: free-space sections */
1477     /* (Since file was re-opened) */
1478     if(info.retries[9][0] != 0)
1479         TEST_ERROR
1480     if(info.retries[9][1] != 1000)
1481         TEST_ERROR
1482 
1483     /* Verify retries for fid1: free-space sections */
1484     if(info1.retries[9][0] != 0)
1485         TEST_ERROR
1486     if(info1.retries[9][1] != 1000)
1487         TEST_ERROR
1488 
1489     /* Verify retries for fid1: fixed array data block page */
1490     /* (Since file was re-opened) */
1491     if(info1.retries[19][0] != 500)
1492         TEST_ERROR
1493     if(info1.retries[19][1] != 0)
1494         TEST_ERROR
1495 
1496     /* Free memory for info.retries and info1.retries */
1497     for(i = 0; i < H5F_NUM_METADATA_READ_RETRY_TYPES; i++) {
1498         if(info.retries[i] != NULL)
1499             H5free_memory(info.retries[i]);
1500         if(info1.retries[i] != NULL)
1501             H5free_memory(info1.retries[i]);
1502     } /* end for */
1503 
1504     /* Closing */
1505     if(H5Fclose(fid) < 0)
1506         FAIL_STACK_ERROR
1507     if(H5Fclose(fid1) < 0)
1508         FAIL_STACK_ERROR
1509 
1510     if(H5Pclose(fapl) < 0)
1511         FAIL_STACK_ERROR
1512 
1513     PASSED();
1514     return 0;
1515 
1516 error:
1517     H5E_BEGIN_TRY {
1518         H5Pclose(fapl);
1519         H5Pclose(new_fapl);
1520         H5Dclose(did1);
1521         H5Dclose(did2);
1522         H5Sclose(sid);
1523         H5Pclose(dcpl);
1524         H5Fclose(fid);
1525         H5Fclose(fid1);
1526     } H5E_END_TRY;
1527 
1528     return -1;
1529 
1530 } /* test_metadata_read_retry_info() */
1531 
1532 
1533 
1534 /*
1535  * Tests for H5Fstart_swmr_write()
1536  */
1537 
1538 /*
1539  *  test_start_swmr_write():
1540  *
1541  *  Verify SWMR writing is enabled via H5Fstart_swmr_write():
1542  *  Mainly test for file created with SWMR_WRITE + with/without latest format:
1543  *  --file will have v3 superblock and all latest version support enabled
1544  *
1545  *  (A) Creating a file
1546  *      Create a file with SWMR_WRITE + non-latest-format
1547  *      Create a chunked dataset "dataset1" in the file -- should be using latest chunk indexing
1548  *      Should fail to enable SWMR as the file is already in SWMR writing mode
1549  *      Close the file
1550  *
1551  *  (B) Opening a file
1552  *      Open the file with write + non-latest-format
1553  *      --file has v3 superblock and all latest version support enabled
1554  *      Open dataset "dataset1" 3 times--keep it open
1555  *    Write to "dataset1"
1556  *    Create a group in the file
1557  *      Create a chunked dataset "dataset2" in the group--should be using latest chunk indexing--keep it open
1558  *      Should succeed in enabling SWMR
1559  *    Should succeed in reading from multiple opens of "dataset1"
1560  *      Close multiple opens of "dataset1"
1561  *    Close "dataset2"
1562  *      Create "dataset3"--should be using latest chunk indexing
1563  *      Close "dataset3"
1564  *      Close the group and file
1565  */
1566 static int
test_start_swmr_write(hid_t in_fapl,hbool_t new_format)1567 test_start_swmr_write(hid_t in_fapl, hbool_t new_format)
1568 {
1569     hid_t fid = -1;             /* File ID */
1570     hid_t fapl = -1;                /* File access property */
1571     hid_t gid = -1;             /* Group ID */
1572     hid_t dcpl = -1;                /* Dataset creation property */
1573     hid_t file_fapl = -1;           /* File access property for the file */
1574     hid_t did1 = -1, did2 = -1, did3 = -1;  /* Dataset IDs */
1575     hid_t did1_a = -1, did1_b = -1;
1576     hid_t sid1 = -1, sid2 = -1, sid3 = -1;  /* Dataspace IDs */
1577     hsize_t dim[1] = {1};           /* Dimension sizes */
1578     hsize_t max_dim[1] = {H5S_UNLIMITED};   /* Maximum dimension sizes */
1579     hsize_t chunk_dim[1] = {2};         /* Chunk dimension sizes */
1580     hsize_t dim2[2] = {5, 10};          /* Dimension sizes */
1581     hsize_t max_dim2[2] = {H5S_UNLIMITED, H5S_UNLIMITED};   /* Maximum dimension sizes */
1582     hsize_t chunk_dim2[2] = {2, 7};     /* Chunk dimension sizes */
1583     H5D_chunk_index_t idx_type;         /* Dataset chunk index type */
1584     int wdata = 99;             /* Data to write */
1585     int rdata;                  /* Data read */
1586     unsigned attempts;              /* The retrieved # of read attempts */
1587     char filename[NAME_BUF_SIZE];       /* File name */
1588     herr_t ret;                             /* Return value */
1589 
1590 
1591     /* Get a copy of the parameter fapl (non-latest-format) */
1592     if((fapl = H5Pcopy(in_fapl)) < 0)
1593         FAIL_STACK_ERROR
1594 
1595     if(new_format) {
1596         TESTING("H5Fstart_swmr_write() when creating/opening a file with latest format");
1597 
1598     /* Set to use the latest library format */
1599     if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
1600         FAIL_STACK_ERROR
1601     } else {
1602         TESTING("H5Fstart_swmr_write() when creating/opening a file without latest format");
1603     } /* end if */
1604 
1605     /* Set the filename to use for this test (dependent on fapl) */
1606     h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));
1607 
1608     /*
1609      * Case A: when creating a file
1610      */
1611 
1612     /* Create the file with SWMR write + non-latest-format */
1613     if((fid = H5Fcreate(filename, H5F_ACC_TRUNC | (new_format ? 0 : H5F_ACC_SWMR_WRITE), H5P_DEFAULT, fapl)) < 0)
1614         FAIL_STACK_ERROR
1615 
1616     /* Get the file's access_property list */
1617     if((file_fapl = H5Fget_access_plist(fid)) < 0)
1618         FAIL_STACK_ERROR
1619 
1620     /* Retrieve the # of read attempts from the file's fapl */
1621     if(H5Pget_metadata_read_attempts(file_fapl, &attempts) < 0)
1622         FAIL_STACK_ERROR
1623 
1624     /* Should be 100 */
1625     if(attempts != (new_format ? H5F_METADATA_READ_ATTEMPTS : H5F_SWMR_METADATA_READ_ATTEMPTS))
1626         TEST_ERROR;
1627 
1628     /* Close the property list */
1629     if(H5Pclose(file_fapl) < 0)
1630         FAIL_STACK_ERROR
1631 
1632     /* Create "dataset1" */
1633     if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
1634         FAIL_STACK_ERROR
1635     if(H5Pset_chunk(dcpl, 1, chunk_dim) < 0)
1636         FAIL_STACK_ERROR
1637     if((sid1 = H5Screate_simple(1, dim, max_dim)) < 0)
1638         FAIL_STACK_ERROR;
1639     if((did1 = H5Dcreate2(fid, "dataset1", H5T_NATIVE_INT, sid1, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
1640         FAIL_STACK_ERROR;
1641 
1642     /* Get the chunk index type */
1643     if(H5D__layout_idx_type_test(did1, &idx_type) < 0)
1644         FAIL_STACK_ERROR;
1645     if(idx_type != H5D_CHUNK_IDX_EARRAY)
1646         FAIL_PUTS_ERROR("should be using extensible array as index");
1647 
1648     /* Write to the dataset */
1649     if(H5Dwrite(did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wdata) < 0)
1650         FAIL_STACK_ERROR;
1651 
1652     /* Should fail to enable SWMR for non-latest-format */
1653     /* Should succeed in enabling SWMR for latest format */
1654     H5E_BEGIN_TRY {
1655         ret = H5Fstart_swmr_write(fid);
1656     } H5E_END_TRY;
1657     if(new_format) {
1658         if(ret < 0) TEST_ERROR
1659     } else if(ret >= 0)
1660         TEST_ERROR
1661 
1662     /* Read from the dataset */
1663     if(H5Dread(did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata) < 0)
1664         FAIL_STACK_ERROR;
1665 
1666     /* Verify the data is correct */
1667     if(wdata != rdata)
1668         TEST_ERROR
1669 
1670     /* Close "dataset1", dataspace, dataset creation property list */
1671     if(H5Dclose(did1) < 0)
1672         FAIL_STACK_ERROR;
1673     if(H5Sclose(sid1) < 0)
1674         FAIL_STACK_ERROR;
1675     if(H5Pclose(dcpl) < 0)
1676         FAIL_STACK_ERROR;
1677 
1678     /* Get the file's access_property list */
1679     if((file_fapl = H5Fget_access_plist(fid)) < 0)
1680         FAIL_STACK_ERROR
1681 
1682     /* Retrieve the # of read attempts */
1683     if(H5Pget_metadata_read_attempts(file_fapl, &attempts) < 0)
1684         FAIL_STACK_ERROR
1685 
1686     /* Should be 100 */
1687     if(attempts != H5F_SWMR_METADATA_READ_ATTEMPTS)
1688         TEST_ERROR;
1689 
1690     /* Close the file access property list */
1691     if(H5Pclose(file_fapl) < 0)
1692         FAIL_STACK_ERROR;
1693 
1694     /* Close the file */
1695     if(H5Fclose(fid) < 0)
1696         FAIL_STACK_ERROR;
1697 
1698     /*
1699      * Case B: when opening a file
1700      */
1701 
1702     /* Open the file again with write + non-latest-format */
1703     if((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
1704         FAIL_STACK_ERROR;
1705 
1706     /* Get the file's access_property list */
1707     if((file_fapl = H5Fget_access_plist(fid)) < 0)
1708         FAIL_STACK_ERROR
1709 
1710     /* Retrieve the # of read attempts */
1711     if(H5Pget_metadata_read_attempts(file_fapl, &attempts) < 0)
1712         FAIL_STACK_ERROR
1713 
1714     /* Should be 1 */
1715     if(attempts != H5F_METADATA_READ_ATTEMPTS)
1716         TEST_ERROR;
1717 
1718     /* Close the property list */
1719     if(H5Pclose(file_fapl) < 0)
1720         FAIL_STACK_ERROR;
1721 
1722     /* open "dataset1", keep it open */
1723     if((did1 = H5Dopen2(fid, "dataset1", H5P_DEFAULT)) < 0)
1724         FAIL_STACK_ERROR;
1725 
1726     /* open "dataset1" second time */
1727     if((did1_a = H5Dopen2(fid, "dataset1", H5P_DEFAULT)) < 0)
1728         FAIL_STACK_ERROR;
1729 
1730     /* open "dataset1" third time */
1731     if((did1_b = H5Dopen2(fid, "dataset1", H5P_DEFAULT)) < 0)
1732         FAIL_STACK_ERROR;
1733 
1734     /* Write to "dataset1" */
1735     wdata = 88;
1736     if(H5Dwrite(did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wdata) < 0)
1737         FAIL_STACK_ERROR;
1738 
1739     /* Create a group */
1740     if((gid = H5Gcreate2(fid, "group", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
1741         FAIL_STACK_ERROR
1742 
1743     /* Create "dataset2" in the group, keep it open */
1744     if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
1745         FAIL_STACK_ERROR
1746     if(H5Pset_chunk(dcpl, 2, chunk_dim2) < 0)
1747         FAIL_STACK_ERROR
1748     if((sid2 = H5Screate_simple(2, dim2, max_dim2)) < 0)
1749         FAIL_STACK_ERROR;
1750     if((did2 = H5Dcreate2(gid, "dataset2", H5T_NATIVE_INT, sid2, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
1751         FAIL_STACK_ERROR;
1752 
1753     /* Get the chunk index type for "dataset2" */
1754     if(H5D__layout_idx_type_test(did2, &idx_type) < 0)
1755         FAIL_STACK_ERROR;
1756     if(idx_type != H5D_CHUNK_IDX_BT2)
1757         FAIL_PUTS_ERROR("should be using v2 B-tree chunk indexing");
1758 
1759     /* Should succeed in enabling SWMR writing */
1760     if(H5Fstart_swmr_write(fid) < 0)
1761         FAIL_STACK_ERROR;
1762 
1763     /* Get the file's access_property list */
1764     if((file_fapl = H5Fget_access_plist(fid)) < 0)
1765         FAIL_STACK_ERROR
1766 
1767     /* Retrieve the # of read attempts */
1768     if(H5Pget_metadata_read_attempts(file_fapl, &attempts) < 0)
1769         FAIL_STACK_ERROR
1770 
1771     /* Should be 100 */
1772     if(attempts != H5F_SWMR_METADATA_READ_ATTEMPTS)
1773         TEST_ERROR;
1774 
1775     /* Close the property list */
1776     if(H5Pclose(file_fapl) < 0)
1777         FAIL_STACK_ERROR;
1778 
1779     rdata = 0;
1780     /* Read from "dataset1" via did1_b (multiple opens) */
1781     if(H5Dread(did1_b, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata) < 0)
1782         FAIL_STACK_ERROR;
1783     if(wdata != rdata)
1784         FAIL_STACK_ERROR;
1785     if(H5Dclose(did1_b) < 0)
1786         FAIL_STACK_ERROR;
1787 
1788     /* Read from "dataset1" */
1789     rdata = 0;
1790     if(H5Dread(did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata) < 0)
1791         FAIL_STACK_ERROR;
1792     if(wdata != rdata)
1793         FAIL_STACK_ERROR;
1794     if(H5Dclose(did1) < 0)
1795         FAIL_STACK_ERROR;
1796 
1797     rdata = 0;
1798     /* Read from "dataset1" via did1_a (multiple opens) */
1799     if(H5Dread(did1_a, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata) < 0)
1800         FAIL_STACK_ERROR;
1801     if(wdata != rdata)
1802         FAIL_STACK_ERROR;
1803     if(H5Dclose(did1_a) < 0)
1804         FAIL_STACK_ERROR;
1805 
1806     /* Close "dataset2", dataspace, dataset creation property list */
1807     if(H5Dclose(did2) < 0)
1808         FAIL_STACK_ERROR;
1809     if(H5Sclose(sid2) < 0)
1810         FAIL_STACK_ERROR;
1811     if(H5Pclose(dcpl) < 0)
1812         FAIL_STACK_ERROR;
1813 
1814     /* Create "dataset3" */
1815     if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
1816         FAIL_STACK_ERROR
1817     if(H5Pset_chunk(dcpl, 2, chunk_dim2) < 0)
1818         FAIL_STACK_ERROR
1819     if((sid3 = H5Screate_simple(2, dim2, max_dim2)) < 0)
1820         FAIL_STACK_ERROR;
1821     if((did3 = H5Dcreate2(fid, "dataset3", H5T_NATIVE_INT, sid3, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
1822         FAIL_STACK_ERROR;
1823 
1824     /* Get the chunk index type for "dataset3" */
1825     if(H5D__layout_idx_type_test(did3, &idx_type) < 0)
1826         FAIL_STACK_ERROR;
1827     if(idx_type != H5D_CHUNK_IDX_BT2)
1828         FAIL_PUTS_ERROR("should be using v2 B-tree as index");
1829 
1830     /* Close "dataset3", dataspace, dataset creation property list */
1831     if(H5Dclose(did3) < 0)
1832         FAIL_STACK_ERROR;
1833     if(H5Sclose(sid3) < 0)
1834         FAIL_STACK_ERROR;
1835     if(H5Pclose(dcpl) < 0)
1836         FAIL_STACK_ERROR;
1837 
1838     /* Close the group */
1839     if(H5Gclose(gid) < 0)
1840         FAIL_STACK_ERROR;
1841 
1842     /* Close the file access property list */
1843     if(H5Pclose(fapl) < 0)
1844         FAIL_STACK_ERROR;
1845 
1846     /* Close the file */
1847     if(H5Fclose(fid) < 0)
1848         FAIL_STACK_ERROR;
1849 
1850     PASSED();
1851 
1852     return 0;
1853 
1854 error:
1855     H5E_BEGIN_TRY {
1856         H5Fclose(fid);
1857         H5Pclose(fapl);
1858         H5Pclose(file_fapl);
1859         H5Gclose(gid);
1860         H5Pclose(dcpl);
1861         H5Dclose(did1);
1862         H5Dclose(did1_a);
1863         H5Dclose(did1_b);
1864         H5Dclose(did2);
1865         H5Dclose(did3);
1866         H5Sclose(sid1);
1867         H5Sclose(sid2);
1868         H5Sclose(sid3);
1869     } H5E_END_TRY;
1870 
1871     return -1;
1872 } /* test_start_swmr_write() */
1873 
1874 /*
1875  *  test_err_start_swmr_write():
1876  *
1877  *  Verify failure conditions in enabling SWMR writing mode via H5Fstart_swmr_write():
1878  *  (A) When creating a file:
1879  *      (1) Create a file with SWMR write + with/without latest format
1880  *      --fail to enable SWMR because the file is already in SWMR writing mode
1881  *      If (latest-format):
1882  *      (2a) Create a file with write + latest format and with opened named datatype
1883  *      --fail to enable SWMR because there are opened datatype
1884  *      If !(latest-format):
1885  *      (2b) Create a file with write + non-latest-format
1886  *              --fail to enable SWMR because superblock version is not at least 3
1887  *
1888  *  (B) When opening a file which is created with write + latest format:
1889  *      (1) Open the file with SWMR write + with/without latest format
1890  *      --fail to enable SWMR because the file is already in SWMR writing mode
1891  *      (2) Open the file with read only + with/without latest format
1892  *      --fail to enable SWMR because the file is not opened with write
1893  *      (3) Open the file with SWMR read only + with/without latest format
1894  *      --fail to enable SWMR because the file is not opened with write
1895  *      (4) Open the file with write + with/without latest format and with opened named datatype/attribute
1896  *      --fail to enable SWMR because there are opened datatype/attribute
1897  *
1898  *  (C) When doing multiple opens for a file:
1899  *      Create a file with (a) write + latest format or (b) SMWR write + non-latest-format
1900  *      Close the file
1901  *      (1) --Open the file with write + with/without latest format
1902  *      --Enable SWMR writing mode twice
1903  *      --First time succeed, second time fail
1904  *      --Close the file
1905         (2) --Open the file with write + with/without latest format
1906  *      --Succeed to enable SWMR writing mode
1907  *      --Reopen the same file
1908  *          --fail to enable SWMR writing mode for the reopened file
1909  *      --Close the file
1910         (3) --Open the file with write + with/without latest format
1911  *      --Open the same file again
1912  *          --succeed to enable SWMR for the first opened file
1913  *          --fail to enable SWMR for the second opened file
1914  *      --Close the file
1915  *
1916  *  (D) (!new_format): When opening a file which is created with write + non-latest-format:
1917  *          (1) Open the file with SWMR write+latest format
1918  *              --fail to open due to superblock version not 3
1919  *          (2) Open the file with SWMR write+non-latest-format
1920  *              --fail to open due to superblock version not 3
1921 
1922  *          (3) Open the file with write+latest format
1923  *              --fail to enable SWMR due to superblock version not 3
1924  *          (4) Open the file with write+non-latest-format
1925  *              --fail to enable SWMR due to superblock version not 3
1926  */
1927 static int
test_err_start_swmr_write(hid_t in_fapl,hbool_t new_format)1928 test_err_start_swmr_write(hid_t in_fapl, hbool_t new_format)
1929 {
1930     hid_t fid = -1;         /* File ID */
1931     hid_t fid2 = -1;            /* File ID */
1932     hid_t fapl = -1;            /* A copy of file access property */
1933     hid_t new_fapl = -1;        /* A copy of file access property */
1934     hid_t gid = -1;         /* Group ID */
1935     hid_t did = -1;         /* Dataset ID */
1936     hid_t sid = -1;         /* Dataspace ID */
1937     hid_t aid = -1;         /* Attribute ID */
1938     hid_t tid = -1;         /* Datatype ID */
1939     hid_t bad_fid = -1;     /* Test fid (should never represent a real ID) */
1940     herr_t ret;             /* Return value */
1941     char filename[NAME_BUF_SIZE];   /* File name */
1942 
1943     /* Create a copy of the input parameter in_fapl */
1944     if((fapl = H5Pcopy(in_fapl)) < 0)
1945         FAIL_STACK_ERROR
1946 
1947     if((new_fapl = H5Pcopy(in_fapl)) < 0)
1948         FAIL_STACK_ERROR
1949     /* Set to use the latest library format */
1950     if(H5Pset_libver_bounds(new_fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
1951         FAIL_STACK_ERROR
1952 
1953     if(new_format) {
1954         TESTING("H5Fstart_swmr_write() on failure conditions for latest format");
1955 
1956     if((fapl = H5Pcopy(new_fapl)) < 0)
1957         FAIL_STACK_ERROR
1958     } else {
1959         TESTING("H5Fstart_swmr_write() on failure conditions for without latest format");
1960     }
1961 
1962     /* Set the filename to use for this test (dependent on fapl) */
1963     h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));
1964 
1965 
1966     /*
1967      * (A) When creating a file:
1968      */
1969 
1970     /* Case 1 */
1971 
1972     /* Create the file with SWMR_WRITE + with/without latest format */
1973     fid = H5Fcreate(filename, H5F_ACC_TRUNC|H5F_ACC_SWMR_WRITE, H5P_DEFAULT, fapl);
1974 
1975     /* Should fail to enable SWMR writing when the file is already in SWMR writing mode */
1976     H5E_BEGIN_TRY {
1977         ret = H5Fstart_swmr_write(fid);
1978     } H5E_END_TRY;
1979     if(ret >= 0)
1980         TEST_ERROR
1981 
1982     if(H5Fclose(fid) < 0)
1983         FAIL_STACK_ERROR;
1984 
1985     /* Case 2 */
1986 
1987     if(new_format) {
1988 
1989         /* Create the file with write + latest format */
1990         if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
1991             FAIL_STACK_ERROR
1992 
1993         /* Create and commit a named datatype */
1994         if((tid = H5Tcopy(H5T_NATIVE_INT)) < 0)
1995             FAIL_STACK_ERROR;
1996         if(H5Tcommit2(fid, "TID", tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0)
1997             FAIL_STACK_ERROR;
1998 
1999         /* Should fail to enable SWMR writing when there is an opened named datatype */
2000         H5E_BEGIN_TRY {
2001             ret = H5Fstart_swmr_write(fid);
2002         } H5E_END_TRY;
2003         if(ret >= 0)
2004             TEST_ERROR
2005 
2006         /* Close the datatype */
2007         if(H5Tclose(tid) < 0)
2008             FAIL_STACK_ERROR;
2009 
2010         /* Should succeed in enabling SWMR writing */
2011         if(H5Fstart_swmr_write(fid) < 0)
2012             TEST_ERROR;
2013 
2014         /* Close the file */
2015         if(H5Fclose(fid) < 0)
2016             FAIL_STACK_ERROR;
2017 
2018     } else {
2019 
2020         /* Create a file with write + non-latest-format */
2021         if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
2022             TEST_ERROR
2023 
2024         /* Should fail to enable SWMR writing because the file's superblock version is not at least 3 */
2025         H5E_BEGIN_TRY {
2026             ret = H5Fstart_swmr_write(fid);
2027         } H5E_END_TRY;
2028         if(ret >= 0)
2029             TEST_ERROR
2030 
2031         if(H5Fclose(fid) < 0)
2032             FAIL_STACK_ERROR;
2033     } /* end if */
2034 
2035     /*
2036      * (B) When opening a file which is created with the latest format
2037      */
2038 
2039     /* Create a file with write + latest format */
2040     if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, new_fapl)) < 0)
2041         FAIL_STACK_ERROR;
2042     if(H5Fclose(fid) < 0)
2043         FAIL_STACK_ERROR;
2044 
2045     /* Case 1 */
2046 
2047     /* Open the file with SWMR write + with/without latest format */
2048     if((fid = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl)) < 0)
2049         FAIL_STACK_ERROR;
2050 
2051     /* Should fail to enable SWMR writing when the file is already in SWMR writing mode */
2052     H5E_BEGIN_TRY {
2053         ret = H5Fstart_swmr_write(fid);
2054     } H5E_END_TRY;
2055     if(ret >= 0)
2056         TEST_ERROR
2057 
2058     /* Close the file */
2059     if(H5Fclose(fid) < 0)
2060         FAIL_STACK_ERROR;
2061 
2062     /* Case 2 */
2063 
2064     /* Open the file with read only access + with/without latest format */
2065     if((fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
2066         FAIL_STACK_ERROR;
2067 
2068     /* Should fail to enable SWMR writing when the file is opened with read only access */
2069     H5E_BEGIN_TRY {
2070         ret = H5Fstart_swmr_write(fid);
2071     } H5E_END_TRY;
2072     if(ret >= 0)
2073         TEST_ERROR
2074 
2075     /* Close the file */
2076     if(H5Fclose(fid) < 0)
2077         FAIL_STACK_ERROR;
2078 
2079     /* Case 3 */
2080 
2081     /* Open the file file with SWMR read access + with/without latest format */
2082     if((fid = H5Fopen(filename, H5F_ACC_SWMR_READ, fapl)) < 0)
2083         FAIL_STACK_ERROR;
2084 
2085     /* Should fail to enable SWMR writing when the file is opened with SWMR read access only */
2086     H5E_BEGIN_TRY {
2087         ret = H5Fstart_swmr_write(fid);
2088     } H5E_END_TRY;
2089     if(ret >= 0)
2090         TEST_ERROR
2091 
2092     /* Close the file */
2093     if(H5Fclose(fid) < 0)
2094         FAIL_STACK_ERROR;
2095 
2096     /* Case 4 */
2097 
2098     /* Open the file with write + with/without latest format */
2099     if((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
2100         FAIL_STACK_ERROR;
2101 
2102     /* Create and commit a named datatype */
2103     if((tid = H5Tcopy(H5T_NATIVE_INT)) < 0)
2104         FAIL_STACK_ERROR;
2105     if(H5Tcommit2(fid, "TID", tid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0)
2106         FAIL_STACK_ERROR;
2107 
2108     /* Create dataspace */
2109     if((sid = H5Screate(H5S_SCALAR)) < 0)
2110         FAIL_STACK_ERROR;
2111 
2112     /* Attach an attribute to the named datatype */
2113     if((aid = H5Acreate2(tid, "attr", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
2114         FAIL_STACK_ERROR;
2115 
2116     /* Should fail to enable SWMR writing when there are opened named datatype and attribute */
2117     H5E_BEGIN_TRY {
2118         ret = H5Fstart_swmr_write(fid);
2119     } H5E_END_TRY;
2120     if(ret >= 0)
2121         TEST_ERROR
2122 
2123     /* Close the datatype */
2124     if(H5Tclose(tid) < 0)
2125         FAIL_STACK_ERROR;
2126 
2127     /* Still fail to enable SWMR writing when the attribute is still opened */
2128     H5E_BEGIN_TRY {
2129         ret = H5Fstart_swmr_write(fid);
2130     } H5E_END_TRY;
2131     if(ret >= 0)
2132         TEST_ERROR
2133 
2134     /* Close the attribute */
2135     if(H5Aclose(aid) < 0)
2136         FAIL_STACK_ERROR;
2137 
2138     /* Should succeed in enabling SWMR writing */
2139     if(H5Fstart_swmr_write(fid) < 0)
2140         TEST_ERROR;
2141 
2142     /* Close the dataspace */
2143     if(H5Sclose(sid) < 0)
2144         FAIL_STACK_ERROR;
2145 
2146     /* Close the file */
2147     if(H5Fclose(fid) < 0)
2148         FAIL_STACK_ERROR;
2149 
2150 
2151     /*
2152      * (C) Failure cases for multiple opens
2153      */
2154 
2155     /* Case 1 */
2156 
2157     /* Create a file with write + with/without latest format */
2158     if((fid = H5Fcreate(filename, H5F_ACC_TRUNC | (new_format ? 0 : H5F_ACC_SWMR_WRITE), H5P_DEFAULT, fapl)) < 0)
2159         FAIL_STACK_ERROR;
2160 
2161     /* Close the file */
2162     if(H5Fclose(fid) < 0)
2163         FAIL_STACK_ERROR;
2164 
2165     /* Open the file with write + with/without latest format */
2166     if((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
2167         FAIL_STACK_ERROR;
2168 
2169     /* Should succeed in enabling SWMR writing mode */
2170     if(H5Fstart_swmr_write(fid) < 0)
2171         TEST_ERROR
2172 
2173     /* Should fail for a second call to enable SWMR writing mode */
2174     H5E_BEGIN_TRY {
2175         ret = H5Fstart_swmr_write(fid);
2176     } H5E_END_TRY;
2177     if(ret >= 0)
2178         TEST_ERROR
2179 
2180     /* Close the file */
2181     if(H5Fclose(fid) < 0)
2182         FAIL_STACK_ERROR;
2183 
2184 
2185     /* Case 2 */
2186 
2187     /* Open the file with write + with/without latest format */
2188     if((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
2189         FAIL_STACK_ERROR;
2190 
2191     /* Should succeed in enabling SWMR writing mode */
2192     if(H5Fstart_swmr_write(fid) < 0)
2193         TEST_ERROR
2194 
2195     /* Re-open the same file */
2196     if((fid2 = H5Freopen(fid)) < 0)
2197         FAIL_STACK_ERROR;
2198 
2199     /* Should fail to enable SWMR writing mode for fid2 */
2200     H5E_BEGIN_TRY {
2201         ret = H5Fstart_swmr_write(fid2);
2202     } H5E_END_TRY;
2203     if(ret >= 0)
2204         TEST_ERROR
2205 
2206     /* Close the files */
2207     if(H5Fclose(fid) < 0)
2208         FAIL_STACK_ERROR;
2209     if(H5Fclose(fid2) < 0)
2210         FAIL_STACK_ERROR;
2211 
2212     /* Case 3 */
2213 
2214     /* Open the file with write + with/without latest format */
2215     if((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
2216         FAIL_STACK_ERROR;
2217 
2218     /* Open the same file */
2219     if((fid2 = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
2220         FAIL_STACK_ERROR;
2221 
2222     /* Should succeed in enabling SWMR writing for fid */
2223     if(H5Fstart_swmr_write(fid) < 0)
2224         TEST_ERROR
2225 
2226     /* Should fail to enable SWMR writing for fid2 */
2227     H5E_BEGIN_TRY {
2228         ret = H5Fstart_swmr_write(fid2);
2229     } H5E_END_TRY;
2230     if(ret >= 0)
2231         TEST_ERROR
2232 
2233     /* Close the files */
2234     if(H5Fclose(fid) < 0)
2235         FAIL_STACK_ERROR;
2236     if(H5Fclose(fid2) < 0)
2237         FAIL_STACK_ERROR;
2238 
2239     if(!new_format) {
2240 
2241         /*
2242          * (D) When opening a file which is created without the latest format:
2243          */
2244 
2245          /* Create a file with write + without latest format */
2246         if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
2247             FAIL_STACK_ERROR;
2248         if(H5Fclose(fid) < 0)
2249             FAIL_STACK_ERROR;
2250 
2251         /* Case 1 */
2252 
2253         /* Should fail to open the file with SWMR write + latest format due to superblock version not at least 3 */
2254         H5E_BEGIN_TRY {
2255             bad_fid = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, new_fapl);
2256         } H5E_END_TRY;
2257         if(bad_fid >= 0)
2258             TEST_ERROR
2259 
2260         /* Case 2 */
2261 
2262         /* Should fail to open the file with SWMR write + non-latest-format due to superblock version not at least 3 */
2263         H5E_BEGIN_TRY {
2264             bad_fid = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl);
2265         } H5E_END_TRY;
2266         if(bad_fid >= 0)
2267             TEST_ERROR
2268 
2269         /* Case 3 */
2270 
2271         /* Open the file with write + latest format */
2272         if((fid = H5Fopen(filename, H5F_ACC_RDWR, new_fapl)) < 0)
2273             FAIL_STACK_ERROR;
2274 
2275         /* Should fail to enable SWMR writing due to superblock version not at least 3 */
2276         H5E_BEGIN_TRY {
2277             ret = H5Fstart_swmr_write(fid);
2278         } H5E_END_TRY;
2279         if(ret >= 0)
2280             TEST_ERROR
2281 
2282         if(H5Fclose(fid) < 0)
2283             FAIL_STACK_ERROR;
2284 
2285 
2286         /* Case 4 */
2287 
2288         /* Open the file with write + non-latest-format */
2289         if((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
2290             FAIL_STACK_ERROR;
2291 
2292         /* Should fail to enable SWMR writing because the file's superblock version is not at least 3 */
2293         H5E_BEGIN_TRY {
2294             ret = H5Fstart_swmr_write(fid);
2295         } H5E_END_TRY;
2296         if(ret >= 0)
2297             TEST_ERROR
2298 
2299         if(H5Fclose(fid) < 0)
2300             FAIL_STACK_ERROR;
2301 
2302     } /* not new */
2303 
2304     /* Close the file access property list */
2305     if(H5Pclose(fapl) < 0)
2306         FAIL_STACK_ERROR;
2307     if(H5Pclose(new_fapl) < 0)
2308         FAIL_STACK_ERROR;
2309 
2310     PASSED();
2311     return 0;
2312 
2313 error:
2314     H5E_BEGIN_TRY {
2315         H5Sclose(sid);
2316         H5Gclose(gid);
2317         H5Dclose(did);
2318         H5Fclose(fid);
2319         H5Fclose(fid2);
2320         H5Pclose(fapl);
2321         H5Pclose(new_fapl);
2322         /* bad_fid should only represent a read ID in the error case.
2323          * It never needs to be closed in the normal case.
2324          */
2325         H5Fclose(bad_fid);
2326     } H5E_END_TRY;
2327 
2328     return -1;
2329 } /* test_err_start_swmr_write() */
2330 
2331 /*
2332  * test_start_swmr_write_concur():
2333  *
2334  * The "new_format" parameter indicates whether to create the file with latest format or not.
2335  *  To have SWMR support, can use either one of the following in creating a file:
2336  *  (a) Create the file with write + latest format:
2337  *      --result in v3 superblock with latest chunk indexing types
2338  *  (b) Create the file with SWMR write + non-latest-format:
2339  *      --result in v3 superblock with latest chunk indexing types
2340  *  Create a chunked dataset with 1 extendible dimension in the file
2341  *
2342  * Verify concurrent access for H5Fstart_swmr_write()--
2343  *  (1) Parent: open a file with write access
2344  *      Child: concurrent open of the file with read & SWMR read (fail)
2345  *  (2) Parent: open a file with write access; enable SWMR writing mode
2346  *      Child: open the file 2 times with read & SWMR read (succeed)
2347  *           open the dataset 2 times with the 2 file opens
2348  *           verify data read from multiple opens of the dataset is correct
2349  *  (3) Parent: open a file with write access; enable SWMR writing mode
2350  *      Child: Concurrent open of the file with read only (fail)
2351  *  (4) Parent: open a file with write access; enable SWMR writing mode
2352  *      Child: concurrent open of the file with write access (fail)
2353  *  (5) Parent: open a file with write access; enable SWMR writing mode
2354  *      Child: concurrent open of the file with write and SWMR write access (fail)
2355  */
2356 #if !(defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID))
2357 
2358 static int
test_start_swmr_write_concur(hid_t H5_ATTR_UNUSED in_fapl,hbool_t H5_ATTR_UNUSED new_format)2359 test_start_swmr_write_concur(hid_t H5_ATTR_UNUSED in_fapl, hbool_t H5_ATTR_UNUSED new_format)
2360 {
2361     SKIPPED();
2362     HDputs("    Test skipped due to fork or waitpid not defined.");
2363     return 0;
2364 } /* test_start_swmr_write_concur() */
2365 
2366 #else /* defined(H5_HAVE_FORK && defined(H5_HAVE_WAITPID) */
2367 
2368 static int
test_start_swmr_write_concur(hid_t in_fapl,hbool_t new_format)2369 test_start_swmr_write_concur(hid_t in_fapl, hbool_t new_format)
2370 {
2371     hid_t fid = -1, fid1 = -1, fid2 = -1;    /* File IDs */
2372     hid_t fapl;             /* File access property list */
2373     pid_t childpid=0;           /* Child process ID */
2374     pid_t tmppid;           /* Child process ID returned by waitpid */
2375     int child_status;           /* Status passed to waitpid */
2376     int child_wait_option=0;        /* Options passed to waitpid */
2377     int child_exit_val;         /* Exit status of the child */
2378     char filename[NAME_BUF_SIZE];   /* File name */
2379 
2380     hid_t did = -1, did1 = -1, did2 = -1, did3 = -1;
2381     hid_t sid = -1;
2382     hid_t dcpl = -1;
2383     hsize_t chunk_dims[1] = {1};
2384     hsize_t maxdims[1] = {H5S_UNLIMITED};
2385     hsize_t dims[1] = {1};
2386     int wdata = 0;
2387 
2388     int out_pdf[2];
2389     int in_pdf[2];
2390     int notify = 0;
2391 
2392     /* Output message about test being performed */
2393     if(new_format) {
2394         TESTING("H5Fstart_swmr_write()--concurrent access for latest format");
2395     } else {
2396         TESTING("H5Fstart_swmr_write()--concurrent access for non-latest-format");
2397     } /* end if */
2398 
2399     if((fapl = H5Pcopy(in_fapl)) < 0)
2400         FAIL_STACK_ERROR
2401 
2402     /* Set the filename to use for this test (dependent on fapl) */
2403     h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));
2404 
2405     if(new_format) {
2406         /* Set to use the latest library format */
2407         if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
2408             FAIL_STACK_ERROR
2409 
2410         /* Create the test file */
2411         if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
2412             FAIL_STACK_ERROR
2413     } else {
2414         /* Create the test file without latest format but with SWMR write */
2415         if((fid = H5Fcreate(filename, H5F_ACC_TRUNC|H5F_ACC_SWMR_WRITE, H5P_DEFAULT, fapl)) < 0)
2416             FAIL_STACK_ERROR
2417     } /* end if */
2418 
2419      /* Create a chunked dataset with 1 extendible dimension */
2420     if((sid = H5Screate_simple(1, dims, maxdims)) < 0)
2421         FAIL_STACK_ERROR;
2422     if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
2423         FAIL_STACK_ERROR
2424     if(H5Pset_chunk(dcpl, 1, chunk_dims) < 0)
2425         FAIL_STACK_ERROR;
2426     if((did = H5Dcreate2(fid, "dataset", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
2427         FAIL_STACK_ERROR;
2428 
2429     /* Close the dataset */
2430     if(H5Dclose(did) < 0)
2431         FAIL_STACK_ERROR
2432     if(H5Sclose(sid) < 0)
2433         FAIL_STACK_ERROR
2434 
2435     /* Close the file */
2436     if(H5Fclose(fid) < 0)
2437         FAIL_STACK_ERROR
2438 
2439     /* Create 1 pipe */
2440     if(HDpipe(out_pdf) < 0)
2441         FAIL_STACK_ERROR
2442 
2443     /*
2444      *  Case (1):
2445      *  Verify concurrent file open with H5F_ACC_RDONLY|H5F_ACC_SWMR_READ
2446      *  will fail without H5Fstart_swmr_write()
2447      */
2448 
2449     /* Fork child process */
2450     if((childpid = HDfork()) < 0)
2451         FAIL_STACK_ERROR
2452 
2453     if(childpid == 0) { /* Child process */
2454     int child_notify = 0;
2455 
2456     /* Close unused write end for out_pdf */
2457         if(HDclose(out_pdf[1]) < 0)
2458             HDexit(EXIT_FAILURE);
2459 
2460         /* Wait for notification from parent process */
2461         while(child_notify != 1) {
2462             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
2463                 HDexit(EXIT_FAILURE);
2464         }
2465 
2466         /* Should fail */
2467         H5E_BEGIN_TRY {
2468             /* Open the test file */
2469             fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl);
2470         } H5E_END_TRY;
2471         if(fid >= 0)
2472             HDexit(EXIT_FAILURE);
2473 
2474     /* Close the pipe */
2475         if(HDclose(out_pdf[0]) < 0)
2476         HDexit(EXIT_FAILURE);
2477 
2478         HDexit(EXIT_SUCCESS);
2479     }
2480 
2481     /* close unused read end for out_pdf */
2482     if(HDclose(out_pdf[0]) < 0)
2483         FAIL_STACK_ERROR
2484 
2485     /* Open the test file */
2486     if((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
2487         FAIL_STACK_ERROR
2488 
2489     /* Notify child process */
2490     notify = 1;
2491     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
2492         FAIL_STACK_ERROR;
2493 
2494     /* Close the pipe */
2495     if(HDclose(out_pdf[1]) < 0)
2496         FAIL_STACK_ERROR;
2497 
2498     /* Wait for child process to complete */
2499     if((tmppid = HDwaitpid(childpid, &child_status, child_wait_option)) < 0)
2500         FAIL_STACK_ERROR
2501 
2502     /* Check exit status of child process */
2503     if(WIFEXITED(child_status)) {
2504         if((child_exit_val = WEXITSTATUS(child_status)) != 0)
2505             TEST_ERROR
2506     } else  /* child process terminated abnormally */
2507         TEST_ERROR
2508 
2509     /* Close the file */
2510     if(H5Fclose(fid) < 0)
2511         FAIL_STACK_ERROR
2512 
2513     /*
2514      *  Case (2):
2515      *  Verify concurrent file open with H5F_ACC_RDONLY|H5F_ACC_SWMR_READ
2516      *  will succeed with H5Fstart_swmr_write()
2517      */
2518 
2519     /* Create 2 pipes */
2520     if(HDpipe(out_pdf) < 0)
2521         FAIL_STACK_ERROR
2522     if(HDpipe(in_pdf) < 0)
2523         FAIL_STACK_ERROR
2524 
2525     /* Fork child process */
2526     if((childpid = HDfork()) < 0)
2527         FAIL_STACK_ERROR
2528 
2529     if(childpid == 0) { /* Child process */
2530         hid_t child_fid1 = -1, child_fid2;    /* File IDs */
2531         hid_t child_did1 = -1, child_did2 = -1;    /* Dataset IDs */
2532     int child_notify = 0;
2533     int rdata = 0;
2534 
2535         /* Close unused write end for out_pdf */
2536         if(HDclose(out_pdf[1]) < 0)
2537             HDexit(EXIT_FAILURE);
2538     /* close unused read end for in_pdf */
2539         if(HDclose(in_pdf[0]) < 0)
2540             HDexit(EXIT_FAILURE);
2541 
2542         /* Wait for notification from parent process */
2543         while(child_notify != 1) {
2544             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
2545                 HDexit(EXIT_FAILURE);
2546         }
2547 
2548         /* Should succeed in opening the test file 2 times */
2549         if((child_fid1 = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl)) < 0)
2550             HDexit(EXIT_FAILURE);
2551         if((child_fid2 = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl)) < 0)
2552             HDexit(EXIT_FAILURE);
2553 
2554     /* open "dataset" 2 times */
2555     if((child_did1 = H5Dopen2(child_fid1, "dataset", H5P_DEFAULT)) < 0)
2556             HDexit(EXIT_FAILURE);
2557     if((child_did2 = H5Dopen2(child_fid2, "dataset", H5P_DEFAULT)) < 0)
2558             HDexit(EXIT_FAILURE);
2559 
2560     /* Read from "dataset" via child_did1 */
2561     rdata = 0;
2562     if(H5Dread(child_did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata) < 0)
2563             HDexit(EXIT_FAILURE);
2564     if(rdata != 88)
2565             HDexit(EXIT_FAILURE);
2566 
2567     /* Notify parent process */
2568         child_notify = 2;
2569     if(HDwrite(in_pdf[1], &child_notify, sizeof(int)) < 0)
2570         HDexit(EXIT_FAILURE);
2571 
2572         /* Wait for notification from parent process */
2573         while(child_notify != 3) {
2574             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
2575                 HDexit(EXIT_FAILURE);
2576         }
2577 
2578     /* Refresh "dataset" via child_did2 */
2579     if(H5Drefresh(child_did2) < 0)
2580             HDexit(EXIT_FAILURE);
2581 
2582     /* Read from "dataset" child_did2 */
2583     rdata = 0;
2584     if(H5Dread(child_did2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata) < 0)
2585             HDexit(EXIT_FAILURE);
2586     if(rdata != 99)
2587             HDexit(EXIT_FAILURE);
2588 
2589     /* Read from "dataset" child_did1 */
2590     rdata = 0;
2591     if(H5Dread(child_did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata) < 0)
2592             HDexit(EXIT_FAILURE);
2593     if(rdata != 99)
2594             HDexit(EXIT_FAILURE);
2595 
2596     /* Close the dataset */
2597     if(H5Dclose(child_did1))
2598             HDexit(EXIT_FAILURE);
2599     if(H5Dclose(child_did2))
2600             HDexit(EXIT_FAILURE);
2601 
2602     /* Close the file */
2603         if(H5Fclose(child_fid1) < 0)
2604             HDexit(EXIT_FAILURE);
2605         if(H5Fclose(child_fid2) < 0)
2606             HDexit(EXIT_FAILURE);
2607 
2608     /* Close the pipe */
2609         if(HDclose(out_pdf[0]) < 0)
2610         HDexit(EXIT_FAILURE);
2611     if(HDclose(in_pdf[1]) < 0)
2612         HDexit(EXIT_FAILURE);
2613 
2614         HDexit(EXIT_SUCCESS);
2615     }
2616 
2617     /* close unused read end for out_pdf */
2618     if(HDclose(out_pdf[0]) < 0)
2619         FAIL_STACK_ERROR
2620     /* Close unused write end for in_pdf */
2621     if(HDclose(in_pdf[1]) < 0)
2622         FAIL_STACK_ERROR
2623 
2624     /* Open the test file */
2625     if((fid1 = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
2626         FAIL_STACK_ERROR
2627     if((fid2 = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
2628         FAIL_STACK_ERROR
2629 
2630     /* open "dataset", keep it open */
2631     if((did1 = H5Dopen2(fid1, "dataset", H5P_DEFAULT)) < 0)
2632         FAIL_STACK_ERROR;
2633     if((did2 = H5Dopen2(fid2, "dataset", H5P_DEFAULT)) < 0)
2634         FAIL_STACK_ERROR;
2635     if((did3 = H5Dopen2(fid1, "dataset", H5P_DEFAULT)) < 0)
2636         FAIL_STACK_ERROR;
2637 
2638      /* Write to "dataset" */
2639     wdata = 88;
2640     if(H5Dwrite(did2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wdata) < 0)
2641         FAIL_STACK_ERROR;
2642 
2643     /* Flush to disk */
2644     if(H5Fflush(fid1, H5F_SCOPE_LOCAL) < 0)
2645         FAIL_STACK_ERROR;
2646 
2647     /* Enable SWMR writing mode */
2648     if(H5Fstart_swmr_write(fid1) < 0)
2649         TEST_ERROR
2650 
2651     /* Notify child process */
2652     notify = 1;
2653     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
2654         FAIL_STACK_ERROR;
2655 
2656     /* Wait for notification from child process */
2657     while(notify != 2) {
2658         if(HDread(in_pdf[0], &notify, sizeof(int)) < 0)
2659             FAIL_STACK_ERROR;
2660     }
2661 
2662      /* Write to "dataset" */
2663     wdata = 99;
2664     if(H5Dwrite(did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wdata) < 0)
2665         FAIL_STACK_ERROR;
2666 
2667     /* Flush to disk */
2668     if(H5Fflush(fid1, H5F_SCOPE_LOCAL) < 0)
2669         FAIL_STACK_ERROR;
2670 
2671     /* Notify child process */
2672     notify = 3;
2673     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
2674         FAIL_STACK_ERROR;
2675 
2676     /* Close the dataset */
2677     if(H5Dclose(did1) < 0)
2678         FAIL_STACK_ERROR
2679     if(H5Dclose(did2) < 0)
2680         FAIL_STACK_ERROR
2681     if(H5Dclose(did3) < 0)
2682         FAIL_STACK_ERROR
2683 
2684     /* Close the pipes */
2685     if(HDclose(out_pdf[1]) < 0)
2686         FAIL_STACK_ERROR;
2687     if(HDclose(in_pdf[0]) < 0)
2688         FAIL_STACK_ERROR;
2689 
2690     /* Wait for child process to complete */
2691     if((tmppid = HDwaitpid(childpid, &child_status, child_wait_option)) < 0)
2692         FAIL_STACK_ERROR
2693 
2694     /* Check exit status of child process */
2695     if(WIFEXITED(child_status)) {
2696         if((child_exit_val = WEXITSTATUS(child_status)) != 0)
2697             TEST_ERROR
2698     } else  /* Child process terminated abnormally */
2699         TEST_ERROR
2700 
2701     /* Close the file */
2702     if(H5Fclose(fid1) < 0)
2703         FAIL_STACK_ERROR
2704     if(H5Fclose(fid2) < 0)
2705         FAIL_STACK_ERROR
2706 
2707 
2708     /*
2709      *  Case (3):
2710      *  Verify concurrent file open with H5F_ACC_RDONLY
2711      *  will fail with H5Fstart_swmr_write()
2712      */
2713     /* Create 1 pipe */
2714     if(HDpipe(out_pdf) < 0)
2715         FAIL_STACK_ERROR
2716 
2717     /* Fork child process */
2718     if((childpid = HDfork()) < 0)
2719         FAIL_STACK_ERROR
2720 
2721     if(childpid == 0) { /* Child process */
2722     int child_notify = 0;
2723 
2724     /* Close unused write end for out_pdf */
2725         if(HDclose(out_pdf[1]) < 0)
2726             HDexit(EXIT_FAILURE);
2727 
2728         /* Wait for notification from parent process */
2729         while(child_notify != 1) {
2730             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
2731                 HDexit(EXIT_FAILURE);
2732         }
2733 
2734         /* Should fail in opening the test file */
2735         H5E_BEGIN_TRY {
2736             fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl);
2737         } H5E_END_TRY;
2738         if(fid >= 0)
2739             HDexit(EXIT_FAILURE);
2740 
2741         HDexit(EXIT_SUCCESS);
2742     } /* end if */
2743 
2744     /* close unused read end for out_pdf */
2745     if(HDclose(out_pdf[0]) < 0)
2746         FAIL_STACK_ERROR
2747 
2748     /* Open the test file */
2749     if((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
2750         FAIL_STACK_ERROR
2751 
2752     /* Enable SWMR writing mode */
2753     if(H5Fstart_swmr_write(fid) < 0)
2754         TEST_ERROR
2755 
2756     /* Notify child process */
2757     notify = 1;
2758     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
2759         FAIL_STACK_ERROR;
2760 
2761     /* Close the pipe */
2762     if(HDclose(out_pdf[1]) < 0)
2763         FAIL_STACK_ERROR;
2764 
2765     /* Wait for child process to complete */
2766     if((tmppid = HDwaitpid(childpid, &child_status, child_wait_option)) < 0)
2767         FAIL_STACK_ERROR
2768 
2769     /* Check exit status of child process */
2770     if(WIFEXITED(child_status)) {
2771         if((child_exit_val = WEXITSTATUS(child_status)) != 0)
2772             TEST_ERROR
2773     } else  /* Child process terminated abnormally */
2774         TEST_ERROR
2775 
2776     /* Close the file */
2777     if(H5Fclose(fid) < 0)
2778         FAIL_STACK_ERROR
2779 
2780     /*
2781      *  Case (4):
2782      *  Verify concurrent file open with H5F_ACC_RDWR
2783      *  will fail with H5Fstart_swmr_write()
2784      */
2785 
2786     /* Create 1 pipe */
2787     if(HDpipe(out_pdf) < 0)
2788         FAIL_STACK_ERROR
2789 
2790     /* Fork child process */
2791     if((childpid = HDfork()) < 0)
2792         FAIL_STACK_ERROR
2793 
2794     if(childpid == 0) { /* Child process */
2795     int child_notify = 0;
2796 
2797     /* Close unused write end for out_pdf */
2798         if(HDclose(out_pdf[1]) < 0)
2799             HDexit(EXIT_FAILURE);
2800 
2801         /* Wait for notification from parent process */
2802         while(child_notify != 1) {
2803             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
2804                 HDexit(EXIT_FAILURE);
2805         }
2806 
2807         /* Should fail in opening the test file */
2808         H5E_BEGIN_TRY {
2809             fid = H5Fopen(filename, H5F_ACC_RDWR, fapl);
2810         } H5E_END_TRY;
2811         if(fid >= 0)
2812             HDexit(EXIT_FAILURE);
2813 
2814     /* Close the pipe */
2815     if(HDclose(out_pdf[0]) < 0)
2816         HDexit(EXIT_FAILURE);
2817 
2818         HDexit(EXIT_SUCCESS);
2819     } /* end if */
2820 
2821     /* close unused read end for out_pdf */
2822     if(HDclose(out_pdf[0]) < 0)
2823         FAIL_STACK_ERROR
2824 
2825     /* Open the test file */
2826     if((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
2827         FAIL_STACK_ERROR
2828 
2829     /* Enable SWMR writing mode */
2830     if(H5Fstart_swmr_write(fid) < 0)
2831         TEST_ERROR
2832 
2833     /* Notify child process */
2834     notify = 1;
2835     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
2836         FAIL_STACK_ERROR;
2837 
2838     /* Close the pipe */
2839     if(HDclose(out_pdf[1]) < 0)
2840         FAIL_STACK_ERROR
2841 
2842     /* Wait for child process to complete */
2843     if((tmppid = HDwaitpid(childpid, &child_status, child_wait_option)) < 0)
2844         FAIL_STACK_ERROR
2845 
2846     /* Check exit status of child process */
2847     if(WIFEXITED(child_status)) {
2848         if((child_exit_val = WEXITSTATUS(child_status)) != 0)
2849             TEST_ERROR
2850     } else  /* Child process terminated abnormally */
2851         TEST_ERROR
2852 
2853     /* Close the file */
2854     if(H5Fclose(fid) < 0)
2855         FAIL_STACK_ERROR
2856 
2857     /*
2858      *  Case (5):
2859      *  Verify concurrent file open with H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE
2860      *  will fail with H5Fstart_swmr_write()
2861      */
2862 
2863     /* Create 1 pipe */
2864     if(HDpipe(out_pdf) < 0)
2865         FAIL_STACK_ERROR
2866 
2867     /* Fork child process */
2868     if((childpid = HDfork()) < 0)
2869         FAIL_STACK_ERROR
2870 
2871     if(childpid == 0) { /* Child process */
2872     int child_notify = 0;
2873 
2874     /* Close unused write end for out_pdf */
2875         if(HDclose(out_pdf[1]) < 0)
2876             HDexit(EXIT_FAILURE);
2877 
2878         /* Wait for notification from parent process */
2879         while(child_notify != 1) {
2880             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
2881                 HDexit(EXIT_FAILURE);
2882         }
2883 
2884         /* Should fail in opening the test file */
2885         H5E_BEGIN_TRY {
2886             fid = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl);
2887         } H5E_END_TRY;
2888         if(fid >= 0)
2889             HDexit(EXIT_FAILURE);
2890 
2891     /* Close the pipe */
2892         if(HDclose(out_pdf[0]) < 0)
2893         HDexit(EXIT_FAILURE);
2894 
2895         HDexit(EXIT_SUCCESS);
2896     }
2897 
2898     /* close unused read end for out_pdf */
2899     if(HDclose(out_pdf[0]) < 0)
2900         FAIL_STACK_ERROR
2901 
2902     /* Open the test file */
2903     if((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
2904         FAIL_STACK_ERROR
2905 
2906     /* Enable SWMR writing mode */
2907     if(H5Fstart_swmr_write(fid) < 0)
2908         TEST_ERROR
2909 
2910     /* Notify child process */
2911     notify = 1;
2912     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
2913         FAIL_STACK_ERROR;
2914 
2915     /* Close the pipe */
2916     if(HDclose(out_pdf[1]) < 0)
2917         FAIL_STACK_ERROR;
2918 
2919     /* Wait for child process to complete */
2920     if((tmppid = HDwaitpid(childpid, &child_status, child_wait_option)) < 0)
2921         FAIL_STACK_ERROR
2922 
2923     /* Check exit status of child process */
2924     if(WIFEXITED(child_status)) {
2925         if((child_exit_val = WEXITSTATUS(child_status)) != 0)
2926             TEST_ERROR
2927     } else  /* Child process terminated abnormally */
2928         TEST_ERROR
2929 
2930     /* Close the file */
2931     if(H5Fclose(fid) < 0)
2932         FAIL_STACK_ERROR
2933 
2934     /* Close the property list */
2935     if(H5Pclose(fapl) < 0)
2936         FAIL_STACK_ERROR
2937 
2938     PASSED();
2939     return 0;
2940 
2941 error:
2942     H5E_BEGIN_TRY {
2943         H5Sclose(sid);
2944         H5Pclose(dcpl);
2945         H5Pclose(fapl);
2946         H5Fclose(fid);
2947     } H5E_END_TRY;
2948 
2949     return -1;
2950 
2951 } /* test_start_swmr_write_concur() */
2952 #endif /* !(defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID)) */
2953 
2954 /*
2955  * test_start_swmr_write_stress_ohdr():
2956  *
2957  * Verify that H5Fswmr_start_write() works correctly when the dataspace header
2958  * message is not located in chunk #0 of the object header.
2959  *
2960  */
2961 static int
test_start_swmr_write_stress_ohdr(hid_t in_fapl)2962 test_start_swmr_write_stress_ohdr(hid_t in_fapl)
2963 {
2964     hid_t fid = -1;            /* File IDs */
2965     hid_t fapl;                         /* File access property list */
2966     char filename[NAME_BUF_SIZE];       /* File name */
2967     hid_t did = -1, did2 = -1;          /* Dataset IDs */
2968     hid_t sid = -1;                     /* Dataspace ID */
2969     hid_t tid = -1;                     /* Datatype ID */
2970     hid_t dcpl = -1;                    /* Dataset creation property list ID */
2971     hid_t aid = -1;                     /* Attribute ID */
2972     hsize_t chunk_dims[2] = {10, 10};
2973     hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED};
2974     char fill[256];                     /* Fill value for dataset */
2975     char attr_data[32];                 /* Data value for attribute */
2976     hsize_t dims[2] = {1,1};
2977     unsigned chunk_num;                 /* Object header chunk # for dataspace message */
2978 
2979     /* Output message about test being performed */
2980     TESTING("H5Fstart_swmr_write()--stress object header messages");
2981 
2982     /* Initialize buffers */
2983     HDmemset(fill, 0, sizeof(fill));
2984     HDmemset(attr_data, 0, sizeof(attr_data));
2985 
2986     if((fapl = H5Pcopy(in_fapl)) < 0)
2987         FAIL_STACK_ERROR
2988 
2989     /* Set the filename to use for this test (dependent on fapl) */
2990     h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));
2991 
2992     /* Set to use the latest library format */
2993     if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
2994         FAIL_STACK_ERROR
2995 
2996     /* Create the test file */
2997     if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
2998         FAIL_STACK_ERROR
2999 
3000     /* Create a chunked dataset with 2 extendible dimensions */
3001     if((sid = H5Screate_simple(1, dims, maxdims)) < 0)
3002         FAIL_STACK_ERROR;
3003     if((tid = H5Tcopy(H5T_C_S1)) < 0)
3004         FAIL_STACK_ERROR;
3005     if(H5Tset_size(tid, 256) < 0)
3006         FAIL_STACK_ERROR;
3007     if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
3008         FAIL_STACK_ERROR
3009     if(H5Pset_chunk(dcpl, 1, chunk_dims) < 0)
3010         FAIL_STACK_ERROR;
3011     if(H5Pset_fill_value(dcpl, tid, &fill) < 0)
3012         FAIL_STACK_ERROR;
3013     if((did = H5Dcreate2(fid, "dataset", tid, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
3014         FAIL_STACK_ERROR;
3015 
3016     /* Retrieve the chunk # for the dataspace message */
3017     chunk_num = UINT_MAX;
3018     if(H5O_msg_get_chunkno_test(did, H5O_SDSPACE_ID, &chunk_num) < 0)
3019         FAIL_STACK_ERROR;
3020     /* Should be in chunk #0 for now */
3021     if(0 != chunk_num)
3022         TEST_ERROR;
3023 
3024     /* Create a second chunked dataset with 2 extendible dimensions */
3025     /* (So that the original dataset's object header can't be extended) */
3026     if((sid = H5Screate_simple(1, dims, maxdims)) < 0)
3027         FAIL_STACK_ERROR;
3028     if((tid = H5Tcopy(H5T_C_S1)) < 0)
3029         FAIL_STACK_ERROR;
3030     if(H5Tset_size(tid, 256) < 0)
3031         FAIL_STACK_ERROR;
3032     if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
3033         FAIL_STACK_ERROR
3034     if(H5Pset_chunk(dcpl, 1, chunk_dims) < 0)
3035         FAIL_STACK_ERROR;
3036     if(H5Pset_fill_value(dcpl, tid, &fill) < 0)
3037         FAIL_STACK_ERROR;
3038     if((did2 = H5Dcreate2(fid, "dataset2", tid, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
3039         FAIL_STACK_ERROR;
3040 
3041     /* Close the second dataset */
3042     if(H5Dclose(did2) < 0)
3043         FAIL_STACK_ERROR
3044 
3045     /* Close the objects for the dataset creation */
3046     if(H5Sclose(sid) < 0)
3047         FAIL_STACK_ERROR
3048     if(H5Tclose(tid) < 0)
3049         FAIL_STACK_ERROR
3050     if(H5Pclose(dcpl) < 0)
3051         FAIL_STACK_ERROR
3052 
3053     /* Create attribute on original dataset, to push dataspace header message out of header chunk #0 */
3054     if((sid = H5Screate(H5S_SCALAR)) < 0)
3055         FAIL_STACK_ERROR;
3056     if((tid = H5Tcopy(H5T_C_S1)) < 0)
3057         FAIL_STACK_ERROR;
3058     if(H5Tset_size(tid, 32) < 0)
3059         FAIL_STACK_ERROR;
3060     if(H5Tset_strpad(tid, H5T_STR_NULLTERM) < 0)
3061         FAIL_STACK_ERROR;
3062     if((aid = H5Acreate2(did, "attr", tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
3063         FAIL_STACK_ERROR;
3064     if(H5Awrite(aid, tid, attr_data) < 0)
3065         FAIL_STACK_ERROR;
3066     if(H5Sclose(sid) < 0)
3067         FAIL_STACK_ERROR
3068     if(H5Tclose(tid) < 0)
3069         FAIL_STACK_ERROR
3070     if(H5Aclose(aid) < 0)
3071         FAIL_STACK_ERROR
3072 
3073     /* Retrieve the chunk # for the dataspace message */
3074     chunk_num = UINT_MAX;
3075     if(H5O_msg_get_chunkno_test(did, H5O_SDSPACE_ID, &chunk_num) < 0)
3076         FAIL_STACK_ERROR;
3077     /* Should be in chunk #0 for now */
3078     if(1 != chunk_num)
3079         TEST_ERROR;
3080 
3081     /* Enable SWMR write */
3082     if(H5Fstart_swmr_write(fid) < 0)
3083         FAIL_STACK_ERROR;
3084 
3085     /* Close the dataset */
3086     if(H5Dclose(did) < 0)
3087         FAIL_STACK_ERROR
3088 
3089     /* Close the file */
3090     if(H5Fclose(fid) < 0)
3091         FAIL_STACK_ERROR
3092 
3093     /* Close the FAPL */
3094     if(H5Pclose(fapl) < 0)
3095         FAIL_STACK_ERROR
3096 
3097     PASSED();
3098     return 0;
3099 
3100 error:
3101     H5E_BEGIN_TRY {
3102         H5Sclose(aid);
3103         H5Sclose(tid);
3104         H5Sclose(sid);
3105         H5Sclose(did);
3106         H5Sclose(did2);
3107         H5Pclose(dcpl);
3108         H5Pclose(fapl);
3109         H5Fclose(fid);
3110     } H5E_END_TRY;
3111 
3112     return -1;
3113 } /* test_start_swmr_write_stress_ohdr() */
3114 
3115 /*
3116  * Tests for H5Pset/get_object_flush_cb()
3117  */
3118 
3119 /* The callback function for object flush property */
3120 static herr_t
flush_cb(hid_t H5_ATTR_UNUSED obj_id,void * _udata)3121 flush_cb(hid_t H5_ATTR_UNUSED obj_id, void *_udata)
3122 {
3123     unsigned *flush_ct = (unsigned*)_udata;
3124     ++(*flush_ct);
3125     return 0;
3126 }
3127 
3128 /*
3129  * test_object_flush_cb()
3130  *
3131  * Verify the public routines H5Pget/set_object_flush_cb() work as specified:
3132  *  1) To verify the failure condition in setting object flush property
3133  *  2) To verify the object flush property values retrieved from a default
3134  *     file access property list.
3135  *  3) To verify the object flush property values retrieved from a non-default
3136  *     file access property list.
3137  *  4) To verify the object flush property values retrieved from a default
3138  *     file access property list of a file
3139  *  5) To verify the object flush property values retrieved from a non-default
3140  *     file access property list of a file
3141  *     To verify the object flush callback is invoked when doing H5Oflush(),
3142  *     H5Dflush(), H5Gflush() and H5Tflush().
3143  */
3144 static int
test_object_flush_cb(hid_t in_fapl)3145 test_object_flush_cb(hid_t in_fapl)
3146 {
3147     hid_t fapl = -1;            /* A copy of file access property list */
3148     hid_t ffapl = -1;           /* A file's file access property list */
3149     hid_t fid = -1;         /* File ID */
3150     hid_t gid = -1;         /* Group ID */
3151     hid_t did1 = -1, did2 = -1;     /* Dataset IDs */
3152     hid_t sid = -1;         /* Dataspace ID */
3153     hsize_t dims[2] = {5, 10};      /* Dataset dimension sizes */
3154     int buf[50];            /* Data buffer */
3155     H5F_flush_cb_t ret_cb;      /* The callback function set in object flush property */
3156     void *ret_ct;           /* The user data set in object flush property */
3157     unsigned flush_ct = 0;      /* The user data for object flush property */
3158     char filename[NAME_BUF_SIZE];   /* File name */
3159     int i;              /* Local index variable */
3160     herr_t ret;                 /* Generic return value */
3161 
3162     TESTING("H5Pget/set_obj_flush_cb()");
3163 
3164     /*
3165      * Case (1)
3166      *  To verify the failure condition in setting object flush property
3167      */
3168     /* Should fail if the callback function is not defined but user data is defined */
3169     H5E_BEGIN_TRY {
3170         ret = H5Pset_object_flush_cb(fapl, NULL, &flush_ct);
3171     } H5E_END_TRY;
3172     if(ret >= 0)
3173         TEST_ERROR
3174 
3175     /*
3176      * Case (2)
3177      *  To verify the object flush property values retrieved from a
3178      *  default file access property list.
3179      */
3180 
3181     /* Create a copy of file access property list */
3182     if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
3183         FAIL_STACK_ERROR
3184 
3185     /* Retrieve object flush property values for the default file access property list */
3186     if(H5Pget_object_flush_cb(fapl, &ret_cb, &ret_ct) < 0)
3187         TEST_ERROR
3188     /* Should be null */
3189     if(ret_cb != NULL || ret_ct != NULL)
3190         TEST_ERROR
3191 
3192     /*
3193      * Case (3)
3194      *  To verify the object flush property values retrieved from a
3195      *  non-default file access property list.
3196      */
3197     /* Set the object flush property */
3198     if(H5Pset_object_flush_cb(fapl, flush_cb, &flush_ct) < 0)
3199         TEST_ERROR
3200 
3201     /* Increment the counter */
3202     ++flush_ct;
3203 
3204     /* Retrieve object flush property values for the non-default file access property list */
3205     if(H5Pget_object_flush_cb(fapl, &ret_cb, &ret_ct) < 0)
3206         TEST_ERROR
3207 
3208     /* Verify expected values */
3209     if(ret_cb != flush_cb || *(unsigned *)ret_ct != 1)
3210         TEST_ERROR
3211 
3212     /* Close the property list */
3213     if(H5Pclose(fapl) < 0)
3214         FAIL_STACK_ERROR;
3215 
3216     /*
3217      * Case (4)
3218      *  To verify the object flush property values retrieved from a
3219      *  default file access property list of a file
3220      */
3221 
3222     /* Reset values */
3223     flush_ct = 0;
3224     ret_cb = NULL;
3225     ret_ct = NULL;
3226 
3227     /* Make a copy of the input parameter in_fapl */
3228     if((fapl = H5Pcopy(in_fapl)) < 0)
3229         FAIL_STACK_ERROR
3230 
3231     /* Set to use the latest library format */
3232     if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
3233         FAIL_STACK_ERROR
3234 
3235     /* Set the filename to use for this test (dependent on fapl) */
3236     h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));
3237 
3238     /* Create the test file: without setting object flush property in fapl */
3239     if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
3240         FAIL_STACK_ERROR
3241 
3242     /* Get the file's file access property list */
3243     if((ffapl = H5Fget_access_plist(fid)) < 0)
3244         FAIL_STACK_ERROR;
3245 
3246     /* Retrieve the object flush property values */
3247     if(H5Pget_object_flush_cb(ffapl, &ret_cb, &ret_ct) < 0)
3248         TEST_ERROR
3249 
3250     /* Verify expected values */
3251     if(ret_cb != NULL || ret_ct != NULL)
3252         TEST_ERROR
3253 
3254     /* Closing */
3255     if(H5Pclose(ffapl) < 0)
3256         FAIL_STACK_ERROR;
3257     if(H5Fclose(fid) < 0)
3258         FAIL_STACK_ERROR;
3259 
3260     /*
3261      * Cases (5)
3262      *  To verify the object flush property values retrieved from a non-default
3263      *  file access property list of a file.
3264      *  To verify the object flush callback is invoked when doing H5Oflush(),
3265      *  H5Dflush(), H5Gflush() and H5Tflush().
3266      */
3267     /* Reset values */
3268     flush_ct = 0;
3269     ret_cb = NULL;
3270     ret_ct = NULL;
3271 
3272     /* Set the object flush property */
3273     if(H5Pset_object_flush_cb(fapl, flush_cb, &flush_ct) < 0)
3274         FAIL_STACK_ERROR
3275 
3276     /* Open the test file: with object flush property setting in fapl */
3277     if((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
3278         FAIL_STACK_ERROR;
3279 
3280     /* Create a dataset */
3281     if((sid = H5Screate_simple(2, dims, dims)) < 0)
3282         FAIL_STACK_ERROR;
3283 
3284     /* Create a dataset */
3285     if((did1 = H5Dcreate2(fid, "dataset1", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
3286         FAIL_STACK_ERROR
3287 
3288     /* Initialize data buffer */
3289     for(i = 0; i < 50; i++)
3290     buf[i] = i + 1;
3291 
3292     /* Write to the dataset */
3293     if(H5Dwrite(did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, buf) < 0)
3294         FAIL_STACK_ERROR;
3295 
3296     /* Flush the dataset object */
3297     if(H5Oflush(did1) < 0)
3298         FAIL_STACK_ERROR;
3299 
3300     /* Get the file's file access property list */
3301     if((ffapl = H5Fget_access_plist(fid)) < 0)
3302         FAIL_STACK_ERROR;
3303 
3304     /* Retrieve the object flush property values */
3305     if(H5Pget_object_flush_cb(ffapl, &ret_cb, &ret_ct) < 0)
3306         TEST_ERROR
3307 
3308     /* Verify expected values */
3309     if(ret_cb != flush_cb || *(unsigned *)ret_ct != 1)
3310         TEST_ERROR
3311 
3312     /* Create a group */
3313     if((gid = H5Gcreate2(fid, "group", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
3314         FAIL_STACK_ERROR
3315 
3316     /* Flush the group */
3317     if(H5Gflush(gid) < 0)
3318         TEST_ERROR
3319 
3320     /* Retrieve the object flush property values */
3321     if(H5Pget_object_flush_cb(ffapl, &ret_cb, &ret_ct) < 0)
3322         TEST_ERROR
3323 
3324     /* Verify expected values */
3325     if(ret_cb != flush_cb || *(unsigned *)ret_ct != 2)
3326         TEST_ERROR
3327 
3328     /* Create a dataset */
3329     if((did2 = H5Dcreate2(gid, "dataset2", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
3330         FAIL_STACK_ERROR
3331 
3332     /* Flush the dataset */
3333     if(H5Dflush(did2) < 0)
3334         FAIL_STACK_ERROR;
3335 
3336     /* Retrieve the object flush property values */
3337     if(H5Pget_object_flush_cb(ffapl, &ret_cb, &ret_ct) < 0)
3338         TEST_ERROR
3339 
3340     /* Verify expected values */
3341     if(ret_cb != flush_cb || *(unsigned *)ret_ct != 3)
3342         TEST_ERROR
3343 
3344     /* Closing */
3345     if(H5Sclose(sid) < 0)
3346         FAIL_STACK_ERROR;
3347     if(H5Dclose(did1) < 0)
3348         FAIL_STACK_ERROR;
3349     if(H5Dclose(did2) < 0)
3350         FAIL_STACK_ERROR;
3351     if(H5Gclose(gid) < 0)
3352         FAIL_STACK_ERROR;
3353     if(H5Pclose(fapl) < 0)
3354         FAIL_STACK_ERROR;
3355     if(H5Pclose(ffapl) < 0)
3356         FAIL_STACK_ERROR;
3357     if(H5Fclose(fid) < 0)
3358         FAIL_STACK_ERROR;
3359 
3360     PASSED();
3361 
3362     return 0;
3363 
3364 error:
3365     H5E_BEGIN_TRY {
3366         H5Pclose(fapl);
3367         H5Pclose(ffapl);
3368         H5Sclose(sid);
3369         H5Dclose(did1);
3370         H5Dclose(did2);
3371         H5Gclose(gid);
3372         H5Fclose(fid);
3373     } H5E_END_TRY;
3374 
3375     return -1;
3376 } /* test_object_flush_cb() */
3377 
3378 /*
3379  * Tests for H5Pset/get_append_flush()
3380  */
3381 
3382 
3383 /* The callback function for append flush property */
3384 static herr_t
append_cb(hid_t H5_ATTR_UNUSED dset_id,hsize_t H5_ATTR_UNUSED * cur_dims,void * _udata)3385 append_cb(hid_t H5_ATTR_UNUSED dset_id, hsize_t H5_ATTR_UNUSED *cur_dims, void *_udata)
3386 {
3387     unsigned *count = (unsigned *)_udata;
3388     ++(*count++);
3389     return 0;
3390 } /* append_cb() */
3391 
3392 
3393 /* The callback function for append flush property */
3394 static herr_t
append_cb2(hid_t H5_ATTR_UNUSED dset_id,hsize_t H5_ATTR_UNUSED * cur_dims,void * _udata)3395 append_cb2(hid_t H5_ATTR_UNUSED dset_id, hsize_t H5_ATTR_UNUSED *cur_dims, void *_udata)
3396 {
3397     unsigned *count = (unsigned *)_udata;
3398     ++(*count++);
3399     return 0;
3400 } /* append_cb2() */
3401 
3402 
3403 
3404 /*
3405  * test_append_flush_generic()
3406  *
3407  * Verify H5Pget/set_append_flush() work as specified for a generic dataset
3408  * access property list:
3409  *  1) To verify the append flush property values retrieved from a default
3410  *     access property list.
3411  *      -- zero boundary, null callback function, null user data
3412  *  2) To verify the failure conditions in setting append flush property:
3413  *      -- an invalid dataset rank: <= 0, > H5S_MAX_RANK
3414  *      -- undefined callback but defined user data
3415  *      -- no boundary specified
3416  *      -- invalid boundary size: H5S_UNLIMITED, negative value
3417  *  3) To verify the append flush property values retrieved from a non-default
3418  *     access property list.
3419  *      -- the set callback function, the set user data
3420  *      -- the # of boundary sizes retrieved does not exceed MIN(input ndims, the ndims set)
3421  */
3422 static int
test_append_flush_generic(void)3423 test_append_flush_generic(void)
3424 {
3425     hid_t dapl = -1;            /* A copy of dataset access property */
3426     hsize_t boundary[3];        /* The boundary for append flush property */
3427     unsigned count = 0;         /* The user data for append flush property */
3428     hsize_t ret_boundary[3];        /* The boundary set in append flush property */
3429     H5D_append_cb_t ret_cb;     /* The callback function set in append flush property */
3430     unsigned *ret_count;        /* The user data set in append flush property */
3431     herr_t ret;             /* The return value */
3432 
3433     TESTING("H5Fget/set_append_flush() for a generic dataset access property list");
3434 
3435 
3436     /*
3437      * Case (1)
3438      *  To verify the retrieved append flush property values:
3439      *      -- zero boundary, null callback function, null user data
3440      */
3441 
3442     /* Create a copy of dataset access property list */
3443     if((dapl = H5Pcreate(H5P_DATASET_ACCESS)) < 0)
3444         FAIL_STACK_ERROR
3445 
3446     /* Retrieve the append flush property values */
3447     if(H5Pget_append_flush(dapl, 2, ret_boundary, &ret_cb, (void **)&ret_count) < 0)
3448         FAIL_STACK_ERROR
3449 
3450     /* Verify expected values */
3451     if(ret_boundary[0] != 0 || ret_boundary[1] != 0)
3452         TEST_ERROR;
3453     if(ret_cb != NULL || ret_count != NULL)
3454         TEST_ERROR
3455 
3456     /* Close the property list */
3457     if(H5Pclose(dapl) < 0)
3458         FAIL_STACK_ERROR;
3459 
3460     /*
3461      * Case (2)
3462      *  To verify the failure conditions in setting append flush property:
3463      *  -- an invalid dataset rank: <= 0, > H5S_MAX_RANK
3464      *  -- no boundary specified
3465      *  -- undefined callback but defined user data
3466      *  -- invalid boundary size: H5S_UNLIMITED, negative value
3467      */
3468 
3469     /* Create a copy of dataset access property list */
3470     if((dapl = H5Pcreate(H5P_DATASET_ACCESS)) < 0)
3471         FAIL_STACK_ERROR
3472 
3473     /* Invalid dataset rank: zero value */
3474     H5E_BEGIN_TRY {
3475         ret = H5Pset_append_flush(dapl, 0, NULL, NULL, &count);
3476     } H5E_END_TRY;
3477     if(ret >= 0)
3478         TEST_ERROR
3479 
3480     /* Invalid dataset rank: > H5S_MAX_RANK */
3481     H5E_BEGIN_TRY {
3482         ret = H5Pset_append_flush(dapl, H5S_MAX_RANK+1, NULL, NULL, &count);
3483     } H5E_END_TRY;
3484     if(ret >= 0)
3485         TEST_ERROR
3486 
3487     /* No boundary specified */
3488     H5E_BEGIN_TRY {
3489         ret = H5Pset_append_flush(dapl, 2, NULL, NULL, &count);
3490     } H5E_END_TRY;
3491     if(ret >= 0)
3492         TEST_ERROR
3493 
3494     /* Set up a valid boundary */
3495     boundary[0] = 1;
3496     boundary[1] = 1;
3497 
3498     /* Undefined callback function but defined user data */
3499     H5E_BEGIN_TRY {
3500         ret = H5Pset_append_flush(dapl, 2, boundary, NULL, &count);
3501     } H5E_END_TRY;
3502     if(ret >= 0)
3503         TEST_ERROR
3504 
3505     /* Invalid boundary size: negative value */
3506     boundary[0] = (hsize_t)-1;
3507     boundary[1] = 1;
3508     H5E_BEGIN_TRY {
3509         ret = H5Pset_append_flush(dapl, 2, boundary, append_cb, &count);
3510     } H5E_END_TRY;
3511     if(ret >= 0)
3512         TEST_ERROR
3513 
3514     /* Invalid boundary size: H5S_UNLIMITED */
3515     boundary[0] = 1;
3516     boundary[1] = H5S_UNLIMITED;
3517     H5E_BEGIN_TRY {
3518         ret = H5Pset_append_flush(dapl, 2, boundary, append_cb, &count);
3519     } H5E_END_TRY;
3520     if(ret >= 0)
3521         TEST_ERROR
3522 
3523     /*
3524      * Case (3)
3525      *  To verify the append flush property values retrieved from a non-default
3526      *  access property list:
3527      *      -- the set callback function, the set user data
3528      *      -- the # of boundary sizes retrieved does not exceed MIN(input ndims, the ndims set)
3529      */
3530     boundary[0] = boundary[1] = 1;
3531     boundary[2] = 0;
3532     count = 1;
3533     if(H5Pset_append_flush(dapl, 2, boundary, append_cb, &count) < 0)
3534         FAIL_STACK_ERROR;
3535     ++count;
3536 
3537     /* Verify expected values: with boundary rank > set boundary rank */
3538     if(H5Pget_append_flush(dapl, 3, ret_boundary, &ret_cb, (void **)&ret_count) < 0)
3539         TEST_ERROR
3540     if(ret_boundary[0] != 1 || ret_boundary[1] != 1 || boundary[2] != 0)
3541         TEST_ERROR;
3542     if(ret_cb == NULL || ret_count == NULL || *ret_count != 2)
3543         TEST_ERROR
3544 
3545     /* Verify expected values: with boundary rank < set boundary rank */
3546     HDmemset(ret_boundary, 0, sizeof(ret_boundary));
3547     if(H5Pget_append_flush(dapl, 1, ret_boundary, NULL, NULL) < 0)
3548         TEST_ERROR
3549     if(ret_boundary[0] != 1 || ret_boundary[1] != 0 || boundary[2] != 0)
3550         TEST_ERROR;
3551 
3552     /* Closing */
3553     if(H5Pclose(dapl) < 0)
3554         FAIL_STACK_ERROR;
3555 
3556     PASSED();
3557 
3558     return 0;
3559 
3560 error:
3561     H5E_BEGIN_TRY {
3562         H5Pclose(dapl);
3563     } H5E_END_TRY;
3564 
3565     return -1;
3566 } /* test_append_flush_generic() */
3567 
3568 /*
3569  * test_append_flush_dataset_chunked()
3570  *
3571  * Verify H5Pget/set_append_flush() work as specified for a chunked dataset's
3572  * access property list:
3573  *  1) To verify the append flush property values retrieved from a default
3574  *     access property list:
3575  *     -- zero boundary, null callback function, null user data
3576  *      2) To verify failure in creating dataset when:
3577  *     -- the rank set in append flush property is not the same as the dataset's rank
3578  *     -- boundary (non-zero) is set for a non-extendible dimension
3579  *      3) To verify the append flush property values retrieved from a non-default
3580  *     access property list:
3581  *     -- the set callback function, the set user data
3582  *     -- the # of boundary sizes retrieved does not exceed MIN(input ndims, the ndims set)
3583  */
3584 static int
test_append_flush_dataset_chunked(hid_t in_fapl)3585 test_append_flush_dataset_chunked(hid_t in_fapl)
3586 {
3587     hid_t fid = -1;         /* file ID */
3588     hid_t fapl = -1;            /* A copy of file access property */
3589     hid_t did1 = -1, did2 = -1;     /* The datset ID */
3590     hid_t sid = -1;         /* The dataspace ID */
3591     hid_t dcpl = -1;            /* A copy of dataset creation property */
3592     hid_t dapl = -1;            /* A copy of dataset access property */
3593     hid_t ddapl = -1;           /* The dataset access property of the opened dataset */
3594 
3595     hsize_t boundary[3];        /* Boundary size */
3596     unsigned count = 0;         /* User data */
3597 
3598     hsize_t ret_boundary[3];        /* Boundary size set in the append flush property */
3599     H5D_append_cb_t ret_cb;     /* The callback function set in the append flush property */
3600     unsigned *ret_count;        /* The user data set in the append flush property */
3601 
3602     char filename[NAME_BUF_SIZE];   /* file name */
3603 
3604     hsize_t dims[2] = {100, 0};         /* The dataset dimension sizes */
3605     hsize_t maxdims[2] = {100, H5S_UNLIMITED};  /* The dataset maximum dimension sizes */
3606     hsize_t chunk_dims[2] = {5,2};      /* The chunk dimesion sizes */
3607 
3608     TESTING("H5Fget/set_append_flush() for a chunked dataset's access property list");
3609 
3610     /*
3611      *  Case (1)--
3612      *  For a chunked dataset's access property list:
3613      *  --to verify the append flush property values retrieved from a default access
3614      *    a default access property list is:
3615      *      zero rank, zero boundary, null callback function, null user data
3616      */
3617 
3618     /* Get a copy of the input parameter in_fapl */
3619     if((fapl = H5Pcopy(in_fapl)) < 0)
3620         FAIL_STACK_ERROR
3621 
3622     /* Set to use the latest library format */
3623     if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
3624         FAIL_STACK_ERROR
3625 
3626 
3627     /* Set the filename to use for this test (dependent on fapl) */
3628     h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));
3629 
3630     /* Create the test file to work on */
3631     if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
3632         FAIL_STACK_ERROR
3633 
3634     /* Create a chunked dataset with 1 extendible dimension */
3635     if((sid = H5Screate_simple(2, dims, maxdims)) < 0)
3636         FAIL_STACK_ERROR;
3637     if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
3638         FAIL_STACK_ERROR
3639     if(H5Pset_chunk(dcpl, 2, chunk_dims) < 0)
3640         FAIL_STACK_ERROR;
3641     if((did1 = H5Dcreate2(fid, "dataset1", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
3642         TEST_ERROR
3643 
3644     /* Get the dataset's access property list */
3645     if((ddapl = H5Dget_access_plist(did1)) < 0)
3646         FAIL_STACK_ERROR
3647 
3648     /* Retrieve the append flush property values */
3649     if(H5Pget_append_flush(ddapl, 3, ret_boundary, &ret_cb, (void **)&ret_count) < 0)
3650         TEST_ERROR
3651 
3652     /* Verify expected values */
3653     if(ret_boundary[0] != 0 || ret_boundary[1] != 0 || ret_boundary[2] != 0)
3654         TEST_ERROR;
3655     if(ret_cb != NULL || ret_count != NULL)
3656         TEST_ERROR
3657 
3658     /* Close the dataset's access property list */
3659     if(H5Pclose(ddapl) < 0)
3660         FAIL_STACK_ERROR;
3661 
3662     /*
3663      *  Case (2)--
3664      *  For a chunked dataset's access property list:
3665      *  --to verify failure in creating the dataset when:
3666      *      --the rank set in append flush property is not the same as the dataset's rank
3667      *      -- boundary (non-zero) is set for a non-extendible dimension
3668      *  --to verify failure in opening the dataset
3669      *      -- boundary (non-zero) is set for a non-extendible dimension
3670      */
3671     /* Create a copy of dataset access property list */
3672     if((dapl = H5Pcreate(H5P_DATASET_ACCESS)) < 0)
3673         FAIL_STACK_ERROR
3674 
3675     /* Set boundary dimension rank > the rank of dataset to be created */
3676     HDmemset(boundary, 0, sizeof(boundary));
3677     if(H5Pset_append_flush(dapl, 3, boundary, NULL, NULL) < 0)
3678         FAIL_STACK_ERROR
3679 
3680     /* Should fail to Create the dataset */
3681     H5E_BEGIN_TRY {
3682         did2 = H5Dcreate2(fid, "dataset2", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, dapl);
3683     } H5E_END_TRY;
3684     if(did2 >= 0)
3685         TEST_ERROR
3686 
3687     /* Set boundary for a non-extendible dimension */
3688     boundary[0] = boundary[1] = 1;
3689     if(H5Pset_append_flush(dapl, 2, boundary, NULL, NULL) < 0)
3690         FAIL_STACK_ERROR
3691 
3692     /* Should fail to create the dataset */
3693     H5E_BEGIN_TRY {
3694         did2 = H5Dcreate2(fid, "dataset2", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, dapl);
3695     } H5E_END_TRY;
3696     if(did2 >= 0)
3697         TEST_ERROR
3698 
3699     /* Create and close the dataset */
3700     if((did2 = H5Dcreate2(fid, "dataset2", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
3701         FAIL_STACK_ERROR;
3702     if(H5Dclose(did2) < 0)
3703         FAIL_STACK_ERROR;
3704 
3705     /* Should fail to open the dataset */
3706     H5E_BEGIN_TRY {
3707     did2 = H5Dopen2(fid, "dataset2", dapl);
3708     } H5E_END_TRY;
3709     if(did2 >= 0)
3710         TEST_ERROR
3711 
3712     /*
3713      *  Case (3)--
3714      *  For a chunked dataset's access property list:
3715      *  --To verify the append flush property values retrieved from a non-default
3716      *    access property list:
3717      *      -- the set callback function, the set user data
3718      *      -- the # of boundary sizes retrieved does not exceed MIN(input ndims, the ndims set)
3719      */
3720 
3721     boundary[0] = 0;
3722     boundary[1] = 1;
3723     if(H5Pset_append_flush(dapl, 2, boundary, append_cb, &count) < 0)
3724         FAIL_STACK_ERROR
3725     if((did2 = H5Dopen2(fid, "dataset2", dapl)) < 0)
3726         FAIL_STACK_ERROR
3727 
3728     /* Get the dataset's access property list */
3729     if((ddapl = H5Dget_access_plist(did2)) < 0)
3730         FAIL_STACK_ERROR
3731 
3732     HDmemset(ret_boundary, 0, sizeof(ret_boundary));
3733     ret_cb = NULL;
3734     ret_count = NULL;
3735     /* Retrieve the append flush property values */
3736     if(H5Pget_append_flush(ddapl, 3, ret_boundary, &ret_cb, (void **)&ret_count) < 0)
3737         TEST_ERROR
3738 
3739     /* Verify expected values */
3740     if(ret_cb != append_cb || ret_count != &count)
3741         TEST_ERROR
3742     if(ret_boundary[0] != 0 || ret_boundary[1] != 1 || ret_boundary[2] != 0)
3743         TEST_ERROR
3744 
3745     HDmemset(ret_boundary, 0, sizeof(ret_boundary));
3746     /* Retrieve the append flush property values */
3747     if(H5Pget_append_flush(ddapl, 1, ret_boundary, NULL, NULL) < 0)
3748         TEST_ERROR
3749     if(ret_boundary[0] != 0 || ret_boundary[1] != 0 || ret_boundary[2] != 0)
3750         TEST_ERROR
3751 
3752     /* Closing */
3753     if(H5Pclose(ddapl) < 0)
3754         FAIL_STACK_ERROR;
3755     if(H5Pclose(dapl) < 0)
3756         FAIL_STACK_ERROR;
3757     if(H5Pclose(dcpl) < 0)
3758         FAIL_STACK_ERROR;
3759 
3760     if(H5Pclose(fapl) < 0)
3761         FAIL_STACK_ERROR;
3762     if(H5Dclose(did1) < 0)
3763         FAIL_STACK_ERROR;
3764     if(H5Dclose(did2) < 0)
3765         FAIL_STACK_ERROR;
3766     if(H5Sclose(sid) < 0)
3767         FAIL_STACK_ERROR;
3768     if(H5Fclose(fid) < 0)
3769         FAIL_STACK_ERROR;
3770 
3771     PASSED();
3772 
3773     return 0;
3774 
3775 error:
3776     H5E_BEGIN_TRY {
3777         H5Pclose(dcpl);
3778         H5Pclose(dapl);
3779         H5Pclose(ddapl);
3780         H5Dclose(did1);
3781         H5Dclose(did2);
3782         H5Pclose(fapl);
3783         H5Sclose(sid);
3784         H5Fclose(fid);
3785     } H5E_END_TRY;
3786 
3787     return -1;
3788 } /* test_append_flush_dataset_chunked() */
3789 
3790 /*
3791  * test_append_flush_dataset_fixed():
3792  *
3793  * Verify H5Pget/set_append_flush() work as specified for a
3794  * non-chunked (fixed size) dataset's access property list:
3795  *  (1) To verify success in creating the dataset--whatever is set for the append flush property setting
3796  *  (2) To verify that default append flush property values are retrieved for both
3797  *      default or non-default access property list:
3798  *      -- zero boundary, null callback function, null user data
3799  */
3800 static int
test_append_flush_dataset_fixed(hid_t in_fapl)3801 test_append_flush_dataset_fixed(hid_t in_fapl)
3802 {
3803     hid_t fid = -1;         /* file ID */
3804     hid_t fapl = -1;            /* A copy of file access property */
3805     hid_t did1 = -1, did2 = -1;     /* The datset ID */
3806     hid_t sid = -1;         /* The dataspace ID */
3807     hid_t dapl = -1;            /* A copy of dataset access property */
3808     hid_t ddapl = -1;           /* The dataset access property of the opened dataset */
3809 
3810     hsize_t boundary[3];        /* Boundary size */
3811     unsigned count = 0;         /* User data */
3812 
3813     hsize_t ret_boundary[3];        /* Boundary size set in the append flush property */
3814     H5D_append_cb_t ret_cb;     /* The callback function set in the append flush property */
3815     unsigned *ret_count;        /* The user data set in the append flush property */
3816 
3817     char filename[NAME_BUF_SIZE];   /* file name */
3818 
3819     hsize_t dims[1] = {100};
3820 
3821     TESTING("H5Fget/set_append_flush() for a non-chunked dataset's access property list");
3822 
3823     /*
3824      *  Case (1)--
3825      *  For a non-chunked dataset's access property list:
3826      *  --to verify the append flush property values retrieved from
3827      *    a default access property list is:
3828      *      zero boundary, null callback function, null user data
3829      */
3830 
3831     /* Get a copy of the input parameter in_fapl */
3832     if((fapl = H5Pcopy(in_fapl)) < 0)
3833         FAIL_STACK_ERROR
3834 
3835     /* Set to use the latest library format */
3836     if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
3837         FAIL_STACK_ERROR
3838 
3839 
3840     /* Set the filename to use for this test (dependent on fapl) */
3841     h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));
3842 
3843     /* Create the test file to work on */
3844     if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
3845         FAIL_STACK_ERROR
3846 
3847     /* Create a dataset */
3848     if((sid = H5Screate_simple(1, dims, dims)) < 0)
3849         FAIL_STACK_ERROR;
3850     if((did1 = H5Dcreate2(fid, "dataset1", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
3851         TEST_ERROR
3852 
3853     /* Get the dataset's access property list */
3854     if((ddapl = H5Dget_access_plist(did1)) < 0)
3855         FAIL_STACK_ERROR
3856 
3857     /* Retrieve the append flush property values */
3858     if(H5Pget_append_flush(ddapl, 3, ret_boundary, &ret_cb, (void **)&ret_count) < 0)
3859         TEST_ERROR
3860 
3861     /* Verify expected values */
3862     if(ret_boundary[0] != 0 || ret_boundary[1] != 0 || ret_boundary[2] != 0)
3863         TEST_ERROR;
3864     if(ret_cb != NULL || ret_count != NULL)
3865         TEST_ERROR
3866 
3867     /* Close the dataset's access property list */
3868     if(H5Pclose(ddapl) < 0)
3869         FAIL_STACK_ERROR;
3870 
3871     /*
3872      *  Case (2)--
3873      *  For a non-chunked dataset's access property list:
3874      *  --to verify success in creating and opening the dataset even when append flush property
3875      *    is setup with error conditions:
3876      *      --the rank set in append flush property is not the same as the dataset's rank
3877      *      --boundary is set
3878      *  --to verify the append flush property values are:
3879      *      zero boundary, null callback function, null user data
3880      */
3881     /* Create a copy of dataset access property list */
3882     if((dapl = H5Pcreate(H5P_DATASET_ACCESS)) < 0)
3883         FAIL_STACK_ERROR
3884 
3885     boundary[0] = 1;
3886     boundary[1] = boundary[2] = 0;
3887     if(H5Pset_append_flush(dapl, 3, boundary, append_cb, &count) < 0)
3888         FAIL_STACK_ERROR
3889 
3890     /* Should succeed to create the dataset: append flush property has no effect */
3891     if((did2 = H5Dcreate2(fid, "dataset2", H5T_NATIVE_INT, sid, H5P_DEFAULT, H5P_DEFAULT, dapl)) < 0)
3892         TEST_ERROR
3893 
3894     /* Get the dataset's access property list */
3895     if((ddapl = H5Dget_access_plist(did2)) < 0)
3896         FAIL_STACK_ERROR
3897 
3898     /* Retrieve the append flush property values */
3899     if(H5Pget_append_flush(ddapl, 3, ret_boundary, &ret_cb, (void **)&ret_count) < 0)
3900         TEST_ERROR
3901 
3902     /* Verify expected values */
3903     if(ret_cb != NULL || ret_count != NULL)
3904         TEST_ERROR
3905     if(ret_boundary[0] != 0 || ret_boundary[1] != 0 || ret_boundary[2] != 0)
3906         TEST_ERROR
3907 
3908     /* Closing */
3909     if(H5Pclose(ddapl) < 0)
3910         FAIL_STACK_ERROR;
3911     if(H5Dclose(did2) < 0)
3912         FAIL_STACK_ERROR;
3913 
3914     /* Should succeed in opening the dataset: append flush property has no effect */
3915     if((did2 = H5Dopen2(fid, "dataset2", dapl)) < 0)
3916         TEST_ERROR
3917 
3918     /* Get the dataset's access property list */
3919     if((ddapl = H5Dget_access_plist(did2)) < 0)
3920         FAIL_STACK_ERROR
3921 
3922     /* Retrieve the append flush property values */
3923     if(H5Pget_append_flush(ddapl, 3, ret_boundary, &ret_cb, (void **)&ret_count) < 0)
3924         TEST_ERROR
3925 
3926     /* Verify expected values */
3927     if(ret_cb != NULL || ret_count != NULL)
3928         TEST_ERROR
3929     if(ret_boundary[0] != 0 || ret_boundary[1] != 0 || ret_boundary[2] != 0)
3930         TEST_ERROR
3931 
3932     if(H5Dclose(did2) < 0)
3933         FAIL_STACK_ERROR
3934     /*
3935      *  Case (3)--
3936      *  For a non-chunked dataset's access property list:
3937      *  --To verify the append flush property values retrieved from a non-default
3938      *    access property list:
3939      *      zero boundary, null callback function, null user data
3940      */
3941 
3942     HDmemset(boundary, 0, sizeof(boundary));
3943     if(H5Pset_append_flush(dapl, 1, boundary, append_cb, &count) < 0)
3944         FAIL_STACK_ERROR
3945     if((did2 = H5Dopen2(fid, "dataset2", dapl)) < 0)
3946         FAIL_STACK_ERROR
3947 
3948     /* Get the dataset's access property list */
3949     if((ddapl = H5Dget_access_plist(did2)) < 0)
3950         FAIL_STACK_ERROR
3951 
3952     /* Retrieve the append flush property values */
3953     if(H5Pget_append_flush(ddapl, 1, ret_boundary, &ret_cb, (void **)&ret_count) < 0)
3954         TEST_ERROR
3955 
3956     /* Verify expected values */
3957     if(ret_cb != NULL || ret_count != NULL)
3958         TEST_ERROR
3959     if(ret_boundary[0] != 0 || ret_boundary[1] != 0 || ret_boundary[2] != 0)
3960         TEST_ERROR
3961 
3962     /* Closing */
3963     if(H5Pclose(ddapl) < 0)
3964         FAIL_STACK_ERROR;
3965     if(H5Pclose(dapl) < 0)
3966         FAIL_STACK_ERROR;
3967     if(H5Pclose(fapl) < 0)
3968         FAIL_STACK_ERROR;
3969     if(H5Dclose(did1) < 0)
3970         FAIL_STACK_ERROR;
3971     if(H5Dclose(did2) < 0)
3972         FAIL_STACK_ERROR;
3973     if(H5Sclose(sid) < 0)
3974         FAIL_STACK_ERROR;
3975     if(H5Fclose(fid) < 0)
3976         FAIL_STACK_ERROR;
3977 
3978     PASSED();
3979 
3980     return 0;
3981 
3982 error:
3983     H5E_BEGIN_TRY {
3984         H5Pclose(dapl);
3985         H5Pclose(ddapl);
3986         H5Dclose(did1);
3987         H5Dclose(did2);
3988         H5Pclose(fapl);
3989         H5Sclose(sid);
3990         H5Fclose(fid);
3991     } H5E_END_TRY;
3992 
3993     return -1;
3994 } /* test_append_flush_dataset_fixed() */
3995 
3996 /*
3997  * test_append_flush_multiple()
3998  *
3999  * Verify H5Pget/set_append_flush() work as specified for multiple opens
4000  * of a dataset:
4001  *  (1) did1 = H5Dcreate(...dapl1...)
4002  *      did2 = H5Dopen2(...dapl2)
4003  *      H5Pget_append_flush(did1...)
4004  *      H5Pget_append_flush(did2...)
4005  *      -- should return append flush property values set in dapl1
4006  *  (2) H5Dcreate(...H5P_DEFAULT...)
4007  *      H5Dclose()
4008  *      did1 = H5Dopen2(...dapl1)
4009  *      did2 = H5Dopen2(..dapl2)
4010  *      H5Pget_append_flush(did1, ...)
4011  *      H5Pget_append_flush(did2, ...)
4012  *      -- should return append flush property values set in dapl1
4013  *  NOTE:
4014  *    FOR NOW: return the append flush property values of the create or the very first open
4015  *    LATER ON: should REJECT subsequent dataset open if append flush property values differ
4016  */
4017 static int
test_append_flush_dataset_multiple(hid_t in_fapl)4018 test_append_flush_dataset_multiple(hid_t in_fapl)
4019 {
4020     hid_t fid = -1;         /* file ID */
4021     hid_t fapl = -1;            /* A copy of file access property */
4022     hid_t did1 = -1, did2 = -1;     /* The datset ID */
4023     hid_t sid = -1;         /* The dataspace ID */
4024     hid_t dcpl = -1;            /* A copy of dataset creation property */
4025     hid_t dapl1 = -1;           /* A copy of dataset access property */
4026     hid_t dapl2 = -1;           /* A copy of dataset access property */
4027     hid_t ddapl = -1;           /* The dataset access property of the opened dataset */
4028 
4029     hsize_t boundary1[3];       /* Boundary size */
4030     hsize_t boundary2[3];       /* Boundary size */
4031     unsigned count1 = 0;        /* User data */
4032     unsigned count2 = 0;        /* User data */
4033 
4034     hsize_t ret_boundary[3];        /* Boundary size set in the append flush property */
4035     H5D_append_cb_t ret_cb;     /* The callback function set in the append flush property */
4036     unsigned *ret_count;        /* The user data set in the append flush property */
4037 
4038     char filename[NAME_BUF_SIZE];   /* file name */
4039 
4040     hsize_t dims[2] = {0, 0};                   /* The dataset dimension sizes */
4041     hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED};    /* The dataset maximum dimension sizes */
4042     hsize_t chunk_dims[2] = {5,2};              /* The chunk dimesion sizes */
4043 
4044     TESTING("H5Fget/set_append_flush() for multiple opens of a chunked dataset");
4045 
4046     /*
4047      *  Case (1)
4048      *  For a chunked dataset's access property list:
4049      *      did1 = H5Dcreate(...dapl1...)
4050      *          did2 = H5Dopen2(...dapl2)
4051      *          H5Pget_append_flush(did1...)
4052      *          H5Pget_append_flush(did2...)
4053      *      -- should return append flush property values set in dapl1
4054      */
4055 
4056     /* Create a copy of dataset access property list */
4057     if((dapl1 = H5Pcreate(H5P_DATASET_ACCESS)) < 0)
4058         FAIL_STACK_ERROR
4059     if((dapl2 = H5Pcreate(H5P_DATASET_ACCESS)) < 0)
4060         FAIL_STACK_ERROR
4061 
4062     boundary1[0] = 0;
4063     boundary1[1] = 1;
4064     count1 = 0;
4065     if(H5Pset_append_flush(dapl1, 2, boundary1, append_cb, &count1) < 0)
4066         FAIL_STACK_ERROR
4067     boundary2[0] = 1;
4068     boundary2[1] = 0;
4069     count2 = 0;
4070     if(H5Pset_append_flush(dapl2, 2, boundary2, append_cb2, &count2) < 0)
4071         FAIL_STACK_ERROR
4072 
4073     /* Get a copy of the input parameter in_fapl */
4074     if((fapl = H5Pcopy(in_fapl)) < 0)
4075         FAIL_STACK_ERROR
4076 
4077     /* Set to use the latest library format */
4078     if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
4079         FAIL_STACK_ERROR
4080 
4081     /* Set the filename to use for this test (dependent on fapl) */
4082     h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));
4083 
4084     /* Create the test file to work on */
4085     if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
4086         FAIL_STACK_ERROR
4087 
4088     /* Create a chunked dataset with 2 extendible dimensions */
4089     if((sid = H5Screate_simple(2, dims, maxdims)) < 0)
4090         FAIL_STACK_ERROR;
4091     if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
4092         FAIL_STACK_ERROR
4093     if(H5Pset_chunk(dcpl, 2, chunk_dims) < 0)
4094         FAIL_STACK_ERROR;
4095     if((did1 = H5Dcreate2(fid, "dataset1", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, dapl1)) < 0)
4096         FAIL_STACK_ERROR;
4097 
4098     /* Open the dataset */
4099     if((did2 = H5Dopen2(fid, "dataset1", dapl2)) < 0)
4100         FAIL_STACK_ERROR;
4101 
4102     /* Get the dataset's access property list for did1 */
4103     if((ddapl = H5Dget_access_plist(did1)) < 0)
4104         FAIL_STACK_ERROR
4105 
4106     /* Retrieve the append flush property values */
4107     if(H5Pget_append_flush(ddapl, 3, ret_boundary, &ret_cb, (void **)&ret_count) < 0)
4108         TEST_ERROR
4109 
4110     /* Verify expected values: should be the setting in dapl1 */
4111     if(ret_boundary[0] != 0 || ret_boundary[1] != 1 || ret_boundary[2] != 0)
4112         TEST_ERROR;
4113     if(ret_cb != append_cb || ret_count != &count1)
4114         TEST_ERROR
4115 
4116     /* Close the dataset's access property list */
4117     if(H5Pclose(ddapl) < 0)
4118         FAIL_STACK_ERROR;
4119 
4120     /* Get the dataset's access property list for did2 */
4121     if((ddapl = H5Dget_access_plist(did2)) < 0)
4122         FAIL_STACK_ERROR
4123 
4124     /* Retrieve the append flush property values */
4125     if(H5Pget_append_flush(ddapl, 3, ret_boundary, &ret_cb, (void **)&ret_count) < 0)
4126         TEST_ERROR
4127 
4128     /* Verify expected values: should be the setting in dapl1 */
4129     if(ret_boundary[0] != 0 || ret_boundary[1] != 1 || ret_boundary[2] != 0)
4130         TEST_ERROR;
4131     if(ret_cb != append_cb || ret_count != &count1)
4132         TEST_ERROR
4133 
4134     /* Close the dataset's access property list */
4135     if(H5Pclose(ddapl) < 0)
4136         FAIL_STACK_ERROR;
4137     H5Dclose(did1);
4138     H5Dclose(did2);
4139 
4140     /*
4141      * Case (2)
4142      *  For a chunked dataset's access property list:
4143      *      H5Dcreate(...H5P_DEFAULT...)
4144      *          H5Dclose()
4145      *          did1 = H5Dopen2(...dapl1)
4146      *          did2 = H5Dopen2(..dapl2)
4147      *          H5Pget_append_flush(did1, ...)
4148      *          H5Pget_append_flush(did2, ...)
4149      *      -- should return append flush property values set in dapl1
4150      */
4151     if((did1 = H5Dcreate2(fid, "dataset2", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
4152         FAIL_STACK_ERROR;
4153     if(H5Dclose(did1) < 0)
4154         FAIL_STACK_ERROR;
4155 
4156     /* Open the dataset with append flush setting in dapl2 */
4157     if((did1 = H5Dopen2(fid, "dataset2", dapl2)) < 0)
4158         FAIL_STACK_ERROR;
4159 
4160     /* Open the dataset with append flush setting in dapl1 */
4161     if((did2 = H5Dopen2(fid, "dataset2", dapl1)) < 0)
4162         FAIL_STACK_ERROR;
4163 
4164     /* Get the dataset's access property list for did1 */
4165     if((ddapl = H5Dget_access_plist(did1)) < 0)
4166         FAIL_STACK_ERROR
4167 
4168     /* Retrieve the append flush property values */
4169     if(H5Pget_append_flush(ddapl, 3, ret_boundary, &ret_cb, (void **)&ret_count) < 0)
4170         TEST_ERROR
4171 
4172     /* Verify expected values: should be the setting in dapl2 */
4173     if(ret_boundary[0] != 1 || ret_boundary[1] != 0 || ret_boundary[2] != 0)
4174         TEST_ERROR;
4175     if(ret_cb != append_cb2 || ret_count != &count2)
4176         TEST_ERROR
4177 
4178     /* Close the access property list */
4179     if(H5Pclose(ddapl) < 0)
4180         FAIL_STACK_ERROR;
4181 
4182 
4183     /* Get the dataset's access property list for did2 */
4184     if((ddapl = H5Dget_access_plist(did2)) < 0)
4185         FAIL_STACK_ERROR
4186 
4187     /* Retrieve the append flush property values */
4188     if(H5Pget_append_flush(ddapl, 3, ret_boundary, &ret_cb, (void **)&ret_count) < 0)
4189         TEST_ERROR
4190 
4191     /* Verify expected values: should be the setting in dapl2 */
4192     if(ret_boundary[0] != 1 || ret_boundary[1] != 0 || ret_boundary[2] != 0)
4193         TEST_ERROR;
4194     if(ret_cb != append_cb2 || ret_count != &count2)
4195         TEST_ERROR
4196 
4197     /* Closing */
4198     if(H5Pclose(ddapl) < 0)
4199         FAIL_STACK_ERROR;
4200     if(H5Pclose(dapl2) < 0)
4201         FAIL_STACK_ERROR;
4202     if(H5Pclose(dapl1) < 0)
4203         FAIL_STACK_ERROR;
4204     if(H5Pclose(dcpl) < 0)
4205         FAIL_STACK_ERROR;
4206     if(H5Pclose(fapl) < 0)
4207         FAIL_STACK_ERROR;
4208     if(H5Dclose(did1) < 0)
4209         FAIL_STACK_ERROR;
4210     if(H5Dclose(did2) < 0)
4211         FAIL_STACK_ERROR;
4212     if(H5Sclose(sid) < 0)
4213         FAIL_STACK_ERROR;
4214     if(H5Fclose(fid) < 0)
4215         FAIL_STACK_ERROR;
4216 
4217     PASSED();
4218 
4219     return 0;
4220 
4221 error:
4222     H5E_BEGIN_TRY {
4223         H5Pclose(dcpl);
4224         H5Pclose(dapl1);
4225         H5Pclose(dapl2);
4226         H5Pclose(ddapl);
4227         H5Dclose(did1);
4228         H5Dclose(did2);
4229         H5Pclose(fapl);
4230         H5Sclose(sid);
4231         H5Fclose(fid);
4232     } H5E_END_TRY;
4233 
4234     return -1;
4235 } /* test_append_flush_dataset_multiple() */
4236 
4237 
4238 
4239 /****************************************************************
4240 **
4241 **  test_file_lock_same():
4242 **    With the implementation of file locking, this test checks file
4243 **    open with different combinations of flags.
4244 **    This is for single process access.
4245 **
4246 *****************************************************************/
4247 static int
test_file_lock_same(hid_t in_fapl)4248 test_file_lock_same(hid_t in_fapl)
4249 {
4250     hid_t fid = -1, fid2 = -1;          /* File IDs */
4251     hid_t fapl = -1;                /* File access property list */
4252     unsigned intent;            /* File access flags */
4253     char filename[NAME_BUF_SIZE];       /* file name */
4254 
4255     /* Output message about test being performed */
4256     TESTING("File open with different combinations of flags--single process access");
4257 
4258     if((fapl = H5Pcopy(in_fapl)) < 0)
4259         FAIL_STACK_ERROR
4260 
4261     /* Set the filename to use for this test (dependent on fapl) */
4262     h5_fixname(FILENAME[1], fapl, filename, sizeof(filename));
4263 
4264     /*
4265      * Case 1: 1) RDWR 2) RDWR : should succeed
4266      */
4267     /* Create file */
4268     if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
4269     FAIL_STACK_ERROR
4270 
4271     /* Get and check file intent */
4272     if(H5Fget_intent(fid, &intent) < 0)
4273     FAIL_STACK_ERROR
4274 
4275     if(intent != H5F_ACC_RDWR)
4276     TEST_ERROR
4277 
4278     /* Open the same file with RDWR */
4279     if((fid2 = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
4280     FAIL_STACK_ERROR
4281 
4282     /* Get and check the intent */
4283     if(H5Fget_intent(fid2, &intent) < 0)
4284     FAIL_STACK_ERROR
4285     if(intent != H5F_ACC_RDWR)
4286     TEST_ERROR
4287 
4288     /* Close file */
4289     if(H5Fclose(fid) < 0)
4290     FAIL_STACK_ERROR
4291 
4292     /* Close file */
4293     if(H5Fclose(fid2) < 0)
4294     FAIL_STACK_ERROR
4295 
4296     /*
4297      * Case 2: 1) RDWR 2) RDONLY : should succeed
4298      */
4299     /* Open file with RDWR */
4300     if((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
4301     FAIL_STACK_ERROR
4302 
4303     /* Get and check the intent */
4304     if(H5Fget_intent(fid, &intent) < 0)
4305     FAIL_STACK_ERROR
4306     if(intent != H5F_ACC_RDWR)
4307     TEST_ERROR
4308 
4309     /* Open file with RDONLY */
4310     if((fid2 = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
4311     FAIL_STACK_ERROR
4312 
4313     /* Get and check the intent: should get intent from 1st open */
4314     if(H5Fget_intent(fid2, &intent) < 0)
4315     FAIL_STACK_ERROR
4316     if(intent != H5F_ACC_RDWR)
4317     TEST_ERROR
4318 
4319     /* Close file */
4320     if(H5Fclose(fid) < 0)
4321     FAIL_STACK_ERROR
4322 
4323     /* Close file */
4324     if(H5Fclose(fid2) < 0)
4325     FAIL_STACK_ERROR
4326 
4327     /*
4328      * Case 3: 1) RDONLY 2) RDWR : should fail
4329      */
4330     /* Open file with RDONLY */
4331     if((fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
4332     FAIL_STACK_ERROR
4333 
4334     /* Get and check the intent */
4335     if(H5Fget_intent(fid, &intent) < 0)
4336     FAIL_STACK_ERROR
4337     if(intent != H5F_ACC_RDONLY)
4338     TEST_ERROR
4339 
4340     /* Open file with RDWR should fail */
4341     H5E_BEGIN_TRY {
4342         fid2 = H5Fopen(filename, H5F_ACC_RDWR, fapl);
4343     } H5E_END_TRY;
4344     if(fid2 >= 0)
4345     TEST_ERROR
4346 
4347     /* Close first file */
4348     if(H5Fclose(fid) < 0)
4349     FAIL_STACK_ERROR
4350 
4351     /*
4352      * Case 4: 1) RDONLY 2) RDONLY : should succeed
4353      */
4354     /* Open file with RDONLY */
4355     if((fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
4356     FAIL_STACK_ERROR
4357 
4358     /* Get and check the intent */
4359     if(H5Fget_intent(fid, &intent) < 0)
4360     FAIL_STACK_ERROR
4361     if(intent != H5F_ACC_RDONLY)
4362     TEST_ERROR
4363 
4364     /* Open file with RDONLY */
4365     if((fid2 = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
4366     FAIL_STACK_ERROR
4367 
4368     /* Get and check the intent */
4369     if(H5Fget_intent(fid2, &intent) < 0)
4370     FAIL_STACK_ERROR
4371     if(intent != H5F_ACC_RDONLY)
4372     TEST_ERROR
4373 
4374     /* Close file */
4375     if(H5Fclose(fid) < 0)
4376     FAIL_STACK_ERROR
4377 
4378     /* Close file */
4379     if(H5Fclose(fid2) < 0)
4380     FAIL_STACK_ERROR
4381 
4382     /* Close the property list */
4383     if(H5Pclose(fapl) < 0)
4384         FAIL_STACK_ERROR
4385 
4386     PASSED();
4387 
4388     return 0;
4389 
4390 error:
4391     H5E_BEGIN_TRY {
4392     H5Pclose(fapl);
4393     H5Fclose(fid);
4394     H5Fclose(fid2);
4395     } H5E_END_TRY;
4396 
4397     return -1;
4398 } /* end test_file_lock_same() */
4399 
4400 /****************************************************************
4401 **
4402 **  test_file_lock_swmr_same():
4403 **    With the implementation of file locking, this test checks file
4404 **    open with different combinations of flags + SWMR flags.
4405 **    This is for single process access.
4406 **
4407 *****************************************************************/
4408 static int
test_file_lock_swmr_same(hid_t in_fapl)4409 test_file_lock_swmr_same(hid_t in_fapl)
4410 {
4411     hid_t fid, fid2;    /* File IDs */
4412     hid_t fapl;     /* File access property list */
4413     char filename[NAME_BUF_SIZE];       /* file name */
4414 
4415     /* Output message about test being performed */
4416     TESTING("File open with different combinations of flags + SWMR flags--single process access");
4417 
4418     /* Get a copy of the parameter in_fapl */
4419     if((fapl = H5Pcopy(in_fapl)) < 0)
4420         FAIL_STACK_ERROR
4421 
4422     /* Set the filename to use for this test (dependent on fapl) */
4423     h5_fixname(FILENAME[1], fapl, filename, sizeof(filename));
4424 
4425     /* Set to use latest library format */
4426     if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
4427         FAIL_STACK_ERROR
4428 
4429     /* Create a file */
4430     if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
4431         FAIL_STACK_ERROR
4432 
4433     /* Close file */
4434     if(H5Fclose(fid) < 0)
4435         FAIL_STACK_ERROR
4436 
4437     /*
4438      * Cases a, b, c, d: H5Fopen failure cases
4439      */
4440 
4441     /*
4442      * Case a: RDWR|SWRM_READ : should fail
4443      */
4444     H5E_BEGIN_TRY {
4445     fid = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_READ, fapl);
4446     } H5E_END_TRY;
4447     if(fid >= 0)
4448     TEST_ERROR
4449 
4450     /*
4451      * Case b: RDWR|SWMM_WRTE|SWMR_READ : should fail
4452      */
4453     H5E_BEGIN_TRY {
4454     fid = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE|H5F_ACC_SWMR_READ, fapl);
4455     } H5E_END_TRY;
4456     if(fid >= 0)
4457     TEST_ERROR
4458 
4459     /*
4460      * Case c: RDONLY|SWMM_WRITE : should fail
4461      */
4462     H5E_BEGIN_TRY {
4463     fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_WRITE, fapl);
4464     } H5E_END_TRY;
4465     if(fid >= 0)
4466     TEST_ERROR
4467 
4468     /*
4469      * Case d: RDONLY|SWMM_WRITE|SWMR_READ : should fail
4470      */
4471     H5E_BEGIN_TRY {
4472     fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_WRITE|H5F_ACC_SWMR_READ, fapl);
4473     } H5E_END_TRY;
4474     if(fid >= 0)
4475     TEST_ERROR
4476 
4477     /*
4478      * Cases 1 - 12: combinations of different flags for 1st and 2nd opens
4479      */
4480 
4481     /*
4482      * Case 1: 1) RDWR 2) RDWR|SWMR_WRITE : should fail
4483      */
4484     if((fid = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0)
4485         FAIL_STACK_ERROR
4486 
4487     H5E_BEGIN_TRY {
4488     fid2 = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl);
4489     } H5E_END_TRY;
4490     if(fid2 >= 0)
4491     TEST_ERROR
4492 
4493     /* Close file */
4494     if(H5Fclose(fid) < 0)
4495         FAIL_STACK_ERROR
4496 
4497     /*
4498      * Case 2: 1) RDWR 2) RDONLY|SWMR_READ : should succeed
4499      */
4500     if((fid = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0)
4501     TEST_ERROR
4502     if((fid2 = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl)) < 0)
4503     TEST_ERROR
4504 
4505     /* Close file */
4506     if(H5Fclose(fid) < 0)
4507         FAIL_STACK_ERROR
4508     if(H5Fclose(fid2) < 0)
4509         FAIL_STACK_ERROR
4510 
4511     /*
4512      * Case 3: 1) RDWR|SWMR_WRITE 2)RDWR : should succeed
4513      */
4514     if((fid = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl)) < 0)
4515         FAIL_STACK_ERROR
4516     if((fid2 = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0)
4517         FAIL_STACK_ERROR
4518 
4519     /* Close file */
4520     if(H5Fclose(fid) < 0)
4521         FAIL_STACK_ERROR
4522 
4523     /* Close file */
4524     if(H5Fclose(fid2) < 0)
4525         FAIL_STACK_ERROR
4526 
4527     /*
4528      * Case 4: 1) RDWR|SWMR_WRITE 2) RDWR|SWMR_WRITE : should succeed
4529      */
4530     if((fid = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl)) < 0)
4531         FAIL_STACK_ERROR
4532     if((fid2 = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl)) < 0)
4533         FAIL_STACK_ERROR
4534 
4535     /* Close file */
4536     if(H5Fclose(fid) < 0)
4537         FAIL_STACK_ERROR
4538 
4539     /* Close file */
4540     if(H5Fclose(fid2) < 0)
4541         FAIL_STACK_ERROR
4542 
4543     /*
4544      * Case 5: 1) RDWR|SWMR_WRITE 2) RDONLY|SWMR_READ : should succeed
4545      */
4546     if((fid = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl)) < 0)
4547         FAIL_STACK_ERROR
4548     if((fid2 = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl)) < 0)
4549         FAIL_STACK_ERROR
4550 
4551     /* Close file */
4552     if(H5Fclose(fid) < 0)
4553         FAIL_STACK_ERROR
4554 
4555     /* Close file */
4556     if(H5Fclose(fid2) < 0)
4557         FAIL_STACK_ERROR
4558 
4559     /*
4560      * Case 6: 1) RDWR|SWMR_WRITE 2) RDONLY : should succeed
4561      */
4562     if((fid = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl)) < 0)
4563         FAIL_STACK_ERROR
4564     if((fid2 = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
4565         FAIL_STACK_ERROR
4566 
4567     /* Close file */
4568     if(H5Fclose(fid) < 0)
4569         FAIL_STACK_ERROR
4570 
4571     /* Close file */
4572     if(H5Fclose(fid2) < 0)
4573         FAIL_STACK_ERROR
4574 
4575     /*
4576      * Case 7: 1) RDONLY|SWMR_READ 2)RDWR : should fail
4577      */
4578     if((fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl)) < 0)
4579         FAIL_STACK_ERROR
4580 
4581     H5E_BEGIN_TRY {
4582     fid2 = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT);
4583     } H5E_END_TRY;
4584     if(fid2 >= 0)
4585     TEST_ERROR
4586 
4587     /* Close file */
4588     if(H5Fclose(fid) < 0)
4589         FAIL_STACK_ERROR
4590 
4591     /*
4592      * Case 8: 1) RDONLY|SWMR_READ 2) RDWR|SWMR_WRITE : should fail
4593      */
4594     if((fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl)) < 0)
4595         FAIL_STACK_ERROR
4596 
4597     H5E_BEGIN_TRY {
4598     fid2 = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl);
4599     } H5E_END_TRY;
4600     if(fid2 >= 0)
4601     TEST_ERROR
4602 
4603     /* Close file */
4604     if(H5Fclose(fid) < 0)
4605         FAIL_STACK_ERROR
4606 
4607     /*
4608      * Case 9: 1) RDONLY|SWMR_READ 2) RDONLY|SWMR_READ : should succeed
4609      */
4610     if((fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl)) < 0)
4611         FAIL_STACK_ERROR
4612     if((fid2 = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl)) < 0)
4613         FAIL_STACK_ERROR
4614 
4615     /* Close file */
4616     if(H5Fclose(fid) < 0)
4617         FAIL_STACK_ERROR
4618 
4619     /* Close file */
4620     if(H5Fclose(fid2) < 0)
4621         FAIL_STACK_ERROR
4622 
4623     /*
4624      * Case 10: 1) RDONLY|SWMR_READ 2) RDONLY : should succeed
4625      */
4626     if((fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl)) < 0)
4627         TEST_ERROR
4628     if((fid2 = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
4629         TEST_ERROR
4630 
4631     /* Close file */
4632     if(H5Fclose(fid) < 0)
4633         FAIL_STACK_ERROR
4634 
4635     /* Close file */
4636     if(H5Fclose(fid2) < 0)
4637         FAIL_STACK_ERROR
4638 
4639     /*
4640      * Case 11: 1) RDONLY 2) RDWR|SWMR_WRITE: should fail
4641      */
4642     if((fid = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
4643         FAIL_STACK_ERROR
4644 
4645     H5E_BEGIN_TRY {
4646     fid2 = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl);
4647     } H5E_END_TRY;
4648     if(fid2 >= 0)
4649     TEST_ERROR
4650 
4651     /* Close file */
4652     if(H5Fclose(fid) < 0)
4653         FAIL_STACK_ERROR
4654 
4655     /*
4656      * Case 12: 1) RDONLY 2) RDONLY|SWMR_READ : should fail
4657      */
4658     if((fid = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
4659         FAIL_STACK_ERROR
4660 
4661     H5E_BEGIN_TRY {
4662     fid2 = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl);
4663     } H5E_END_TRY;
4664     if(fid2 >=0 )
4665     TEST_ERROR
4666 
4667     /* Close file */
4668     if(H5Fclose(fid) < 0)
4669         FAIL_STACK_ERROR
4670 
4671     /* Close the property list */
4672     if(H5Pclose(fapl) < 0)
4673         FAIL_STACK_ERROR
4674 
4675     PASSED();
4676 
4677     return 0;
4678 
4679 error:
4680     H5E_BEGIN_TRY {
4681     H5Pclose(fapl);
4682     H5Fclose(fid);
4683     H5Fclose(fid2);
4684     } H5E_END_TRY;
4685 
4686     return -1;
4687 } /* end test_file_lock_swmr_same() */
4688 
4689 
4690 /****************************************************************
4691 **
4692 **  test_file_lock_concur():
4693 **    With the implementation of file locking, this test checks file
4694 **    open with different combinations of flags.
4695 **    This is for concurrent access.
4696 **
4697 *****************************************************************/
4698 #if !(defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID) && defined(H5_HAVE_FLOCK))
4699 
4700 static int
test_file_lock_concur(hid_t H5_ATTR_UNUSED in_fapl)4701 test_file_lock_concur(hid_t H5_ATTR_UNUSED in_fapl)
4702 {
4703     /* Output message about test being performed */
4704     TESTING("File open with different combinations of flags--concurrent access");
4705     SKIPPED();
4706     HDputs("    Test skipped due to fork, waitpid, or flock not defined.");
4707     return 0;
4708 
4709 } /* end test_file_lock_concur() */
4710 
4711 #else
4712 
4713 static int
test_file_lock_concur(hid_t in_fapl)4714 test_file_lock_concur(hid_t in_fapl)
4715 {
4716     hid_t fid = -1;             /* File ID */
4717     hid_t fapl = -1;                    /* File access property list */
4718     char filename[NAME_BUF_SIZE];       /* file name */
4719     pid_t childpid=0;           /* Child process ID */
4720     int child_status;           /* Status passed to waitpid */
4721     int child_wait_option=0;        /* Options passed to waitpid */
4722     int out_pdf[2];
4723     int notify = 0;
4724 
4725     /* Output message about test being performed */
4726     TESTING("File open with different combinations of flags--concurrent access");
4727 
4728     if((fapl = H5Pcopy(in_fapl)) < 0)
4729         FAIL_STACK_ERROR
4730 
4731     /* Set the filename to use for this test (dependent on fapl) */
4732     h5_fixname(FILENAME[1], fapl, filename, sizeof(filename));
4733 
4734     /* Create the test file */
4735     if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
4736         FAIL_STACK_ERROR
4737 
4738     /* Close the file */
4739     if(H5Fclose(fid) < 0)
4740         FAIL_STACK_ERROR
4741 
4742     /*
4743      * Case 1: 1) RDWR 2) RDWR : should fail
4744      */
4745 
4746     /* Create 1 pipe */
4747     if(HDpipe(out_pdf) < 0)
4748         FAIL_STACK_ERROR
4749 
4750     /* Fork child process */
4751     if((childpid = HDfork()) < 0)
4752         FAIL_STACK_ERROR
4753 
4754     if(childpid == 0) { /* Child process */
4755         hid_t child_fid;    /* File ID */
4756     int child_notify = 0;
4757 
4758         /* Close unused write end for out_pdf */
4759         if(HDclose(out_pdf[1]) < 0)
4760             HDexit(EXIT_FAILURE);
4761 
4762         /* Wait for notification from parent process */
4763         while(child_notify != 1) {
4764             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
4765                 HDexit(EXIT_FAILURE);
4766         }
4767 
4768         /* Open the test file */
4769         H5E_BEGIN_TRY {
4770             child_fid = H5Fopen(filename, H5F_ACC_RDWR, fapl);
4771         } H5E_END_TRY;
4772 
4773         /* Should fail */
4774         if(child_fid == FAIL)
4775             HDexit(EXIT_SUCCESS);
4776 
4777     /* Close the pipe */
4778         if(HDclose(out_pdf[0]) < 0)
4779             HDexit(EXIT_FAILURE);
4780 
4781         HDexit(EXIT_FAILURE);
4782     }
4783 
4784     /* close unused read end for out_pdf */
4785     if(HDclose(out_pdf[0]) < 0)
4786         FAIL_STACK_ERROR
4787 
4788     /* Open the test file */
4789     if((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
4790         FAIL_STACK_ERROR
4791 
4792     /* Notify child process */
4793     notify = 1;
4794     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
4795         FAIL_STACK_ERROR;
4796 
4797     /* Close the pipe */
4798     if(HDclose(out_pdf[1]) < 0)
4799         FAIL_STACK_ERROR;
4800 
4801     /* Wait for child process to complete */
4802     if(HDwaitpid(childpid, &child_status, child_wait_option) < 0)
4803         FAIL_STACK_ERROR
4804 
4805     /* Check if child terminated normally */
4806     if(WIFEXITED(child_status)) {
4807     /* Check exit status of the child */
4808     if(WEXITSTATUS(child_status) != 0)
4809         TEST_ERROR
4810     } else
4811         FAIL_STACK_ERROR
4812 
4813     /* Close the file */
4814     if(H5Fclose(fid) < 0)
4815         FAIL_STACK_ERROR
4816 
4817     /*
4818      * Case 2: 1) RDWR 2) RDONLY : should fail
4819      */
4820     /* Create 1 pipe */
4821     if(HDpipe(out_pdf) < 0)
4822         FAIL_STACK_ERROR
4823 
4824     /* Fork child process */
4825     if((childpid = HDfork()) < 0)
4826         FAIL_STACK_ERROR
4827 
4828     if(childpid == 0) { /* Child process */
4829         hid_t child_fid;    /* File ID */
4830     int child_notify = 0;
4831 
4832         /* Close unused write end for out_pdf */
4833         if(HDclose(out_pdf[1]) < 0)
4834             HDexit(EXIT_FAILURE);
4835 
4836         /* Wait for notification from parent process */
4837         while(child_notify != 1) {
4838             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
4839                 HDexit(EXIT_FAILURE);
4840         }
4841 
4842         /* Opens the test file */
4843         H5E_BEGIN_TRY {
4844             child_fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl);
4845         } H5E_END_TRY;
4846 
4847         /* Should fail */
4848         if(child_fid == FAIL)
4849             HDexit(EXIT_SUCCESS);
4850 
4851     /* Close the pipe */
4852         if(HDclose(out_pdf[0]) < 0)
4853             HDexit(EXIT_FAILURE);
4854 
4855         HDexit(EXIT_FAILURE);
4856     }
4857 
4858     /* close unused read end for out_pdf */
4859     if(HDclose(out_pdf[0]) < 0)
4860         FAIL_STACK_ERROR
4861 
4862     /* Opens the test file */
4863     if((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
4864         FAIL_STACK_ERROR
4865 
4866     /* Notify child process */
4867     notify = 1;
4868     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
4869         FAIL_STACK_ERROR;
4870 
4871     /* Close the pipe */
4872     if(HDclose(out_pdf[1]) < 0)
4873         FAIL_STACK_ERROR;
4874 
4875     /* Wait for child process to complete */
4876     if(HDwaitpid(childpid, &child_status, child_wait_option) < 0)
4877         FAIL_STACK_ERROR
4878 
4879     /* Check if child terminated normally */
4880     if(WIFEXITED(child_status)) {
4881         /* Check exit status of the child */
4882         if(WEXITSTATUS(child_status) != 0)
4883             TEST_ERROR
4884     } else
4885         FAIL_STACK_ERROR
4886 
4887     /* Close the file */
4888     if(H5Fclose(fid) < 0)
4889         FAIL_STACK_ERROR
4890 
4891     /*
4892      * Case 3: 1) RDONLY 2) RDWR : should fail
4893      */
4894 
4895     /* Create 1 pipe */
4896     if(HDpipe(out_pdf) < 0)
4897         FAIL_STACK_ERROR
4898 
4899     /* Fork child process */
4900     if((childpid = HDfork()) < 0)
4901         FAIL_STACK_ERROR
4902 
4903     if(childpid == 0) { /* Child process */
4904         hid_t child_fid;    /* File ID */
4905     int child_notify = 0;
4906 
4907         /* Close unused write end for out_pdf */
4908         if(HDclose(out_pdf[1]) < 0)
4909             HDexit(EXIT_FAILURE);
4910 
4911         /* Wait for notification from parent process */
4912         while(child_notify != 1) {
4913             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
4914                 HDexit(EXIT_FAILURE);
4915         }
4916 
4917         /* Opens the test file */
4918         H5E_BEGIN_TRY {
4919             child_fid = H5Fopen(filename, H5F_ACC_RDWR, fapl);
4920         } H5E_END_TRY;
4921 
4922         /* Should fail */
4923         if(child_fid == FAIL)
4924             HDexit(EXIT_SUCCESS);
4925 
4926     /* Close the pipe */
4927         if(HDclose(out_pdf[0]) < 0)
4928             HDexit(EXIT_FAILURE);
4929 
4930         HDexit(EXIT_FAILURE);
4931     } /* end if */
4932 
4933        /* close unused read end for out_pdf */
4934     if(HDclose(out_pdf[0]) < 0)
4935         FAIL_STACK_ERROR
4936 
4937     /* Opens the test file */
4938     if((fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
4939         FAIL_STACK_ERROR
4940 
4941     /* Notify child process */
4942     notify = 1;
4943     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
4944         FAIL_STACK_ERROR;
4945 
4946     /* Close the pipe */
4947     if(HDclose(out_pdf[1]) < 0)
4948         FAIL_STACK_ERROR;
4949 
4950     /* Wait for child process to complete */
4951     if(HDwaitpid(childpid, &child_status, child_wait_option) < 0)
4952         FAIL_STACK_ERROR
4953 
4954     /* Check if child terminated normally */
4955     if(WIFEXITED(child_status)) {
4956         /* Check exit status of the child */
4957         if(WEXITSTATUS(child_status) != 0)
4958             TEST_ERROR
4959     } else
4960         FAIL_STACK_ERROR
4961 
4962     /* Close the file */
4963     if(H5Fclose(fid) < 0)
4964         FAIL_STACK_ERROR
4965 
4966     /*
4967      * Case 4: 1) RDONLY 2) RDONLY : should succeed
4968      */
4969 
4970     /* Create 1 pipe */
4971     if(HDpipe(out_pdf) < 0)
4972         FAIL_STACK_ERROR
4973 
4974     /* Fork child process */
4975     if((childpid = HDfork()) < 0)
4976         FAIL_STACK_ERROR
4977 
4978     if(childpid == 0) { /* Child process */
4979         hid_t child_fid;    /* File ID */
4980     int child_notify = 0;
4981 
4982         /* Close unused write end for out_pdf */
4983         if(HDclose(out_pdf[1]) < 0)
4984             HDexit(EXIT_FAILURE);
4985 
4986         /* Wait for notification from parent process */
4987         while(child_notify != 1) {
4988             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
4989                 HDexit(EXIT_FAILURE);
4990         }
4991 
4992         /* Opens the test file */
4993         H5E_BEGIN_TRY {
4994             child_fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl);
4995         } H5E_END_TRY;
4996 
4997         /* Should succeed */
4998         if(child_fid >= 0) {
4999             /* Close the file */
5000             if(H5Fclose(child_fid) < 0)
5001         HDexit(EXIT_FAILURE);
5002 
5003         /* Close the pipe */
5004         if(HDclose(out_pdf[0]) < 0)
5005         HDexit(EXIT_FAILURE);
5006 
5007             HDexit(EXIT_SUCCESS);
5008         } /* end if */
5009 
5010         HDexit(EXIT_FAILURE);
5011     } /* end if */
5012 
5013     /* close unused read end for out_pdf */
5014     if(HDclose(out_pdf[0]) < 0)
5015         FAIL_STACK_ERROR
5016 
5017     /* Create file */
5018     if((fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
5019         FAIL_STACK_ERROR
5020 
5021     /* Notify child process */
5022     notify = 1;
5023     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
5024         FAIL_STACK_ERROR;
5025 
5026     /* Close the pipe */
5027     if(HDclose(out_pdf[1]) < 0)
5028         FAIL_STACK_ERROR;
5029 
5030     /* Wait for child process to complete */
5031     if(HDwaitpid(childpid, &child_status, child_wait_option) < 0)
5032         FAIL_STACK_ERROR
5033 
5034     /* Check if child terminated normally */
5035     if(WIFEXITED(child_status)) {
5036         /* Check exit status of the child */
5037         if(WEXITSTATUS(child_status) != 0)
5038             TEST_ERROR
5039     } else
5040         FAIL_STACK_ERROR
5041 
5042     /* Close the file */
5043     if(H5Fclose(fid) < 0)
5044         FAIL_STACK_ERROR
5045 
5046     /* Close the property list */
5047     if(H5Pclose(fapl) < 0)
5048         FAIL_STACK_ERROR
5049 
5050     PASSED();
5051 
5052     return 0;
5053 
5054 error:
5055     H5E_BEGIN_TRY {
5056         H5Pclose(fapl);
5057         H5Fclose(fid);
5058     } H5E_END_TRY;
5059 
5060     return -1;
5061 
5062 } /* end test_file_lock_concur() */
5063 
5064 #endif /* !(defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID) && defined(H5_HAVE_FLOCK)) */
5065 
5066 /****************************************************************
5067 **
5068 **  test_file_lock_swmr_concur(): low-level file test routine.
5069 **    With the implementation of file locking, this test checks file
5070 **    open with different combinations of flags + SWMR flags.
5071 **    This is for concurrent access.
5072 **
5073 *****************************************************************/
5074 #if !(defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID))
5075 
5076 static int
test_file_lock_swmr_concur(hid_t H5_ATTR_UNUSED in_fapl)5077 test_file_lock_swmr_concur(hid_t H5_ATTR_UNUSED in_fapl)
5078 {
5079     /* Output message about test being performed */
5080     TESTING("File open with different combintations of flags + SWMR flags--concurrent access");
5081     SKIPPED();
5082     HDputs("    Test skipped due to fork or waitpid not defined.");
5083     return 0;
5084 
5085 } /* end test_file_lock_swmr_concur() */
5086 
5087 #else
5088 
5089 static int
test_file_lock_swmr_concur(hid_t in_fapl)5090 test_file_lock_swmr_concur(hid_t in_fapl)
5091 {
5092     hid_t fid;              /* File ID */
5093     hid_t fapl;             /* File access property list */
5094     char filename[NAME_BUF_SIZE];       /* file name */
5095     pid_t childpid=0;           /* Child process ID */
5096     int child_status;           /* Status passed to waitpid */
5097     int child_wait_option=0;        /* Options passed to waitpid */
5098     int out_pdf[2];
5099     int notify = 0;
5100 
5101     /* Output message about test being performed */
5102     TESTING("File open with different combintations of flags + SWMR flags--concurrent access");
5103 
5104     if((fapl = H5Pcopy(in_fapl)) < 0)
5105         FAIL_STACK_ERROR
5106 
5107     /* Set the filename to use for this test (dependent on fapl) */
5108     h5_fixname(FILENAME[2], fapl, filename, sizeof(filename));
5109 
5110     /* Set to use latest library format */
5111     if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
5112         FAIL_STACK_ERROR
5113 
5114     /* Create the test file */
5115     if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
5116         FAIL_STACK_ERROR
5117 
5118     /* Close the file */
5119     if(H5Fclose(fid) < 0)
5120         FAIL_STACK_ERROR
5121 
5122     /*
5123      * Case 1: 1) RDWR 2) RDWR|SWMR_WRITE : should fail
5124      */
5125 
5126     /* Create 1 pipe */
5127     if(HDpipe(out_pdf) < 0)
5128         FAIL_STACK_ERROR
5129 
5130     /* Fork child process */
5131     if((childpid = HDfork()) < 0)
5132         FAIL_STACK_ERROR
5133 
5134     if(childpid == 0) { /* Child process */
5135         hid_t child_fid;    /* File ID */
5136     int child_notify = 0;
5137 
5138         /* Close unused write end for out_pdf */
5139         if(HDclose(out_pdf[1]) < 0)
5140             HDexit(EXIT_FAILURE);
5141 
5142         /* Wait for notification from parent process */
5143         while(child_notify != 1) {
5144             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
5145                 HDexit(EXIT_FAILURE);
5146         }
5147 
5148         /* Open the test file */
5149         H5E_BEGIN_TRY {
5150             child_fid = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl);
5151         } H5E_END_TRY;
5152 
5153         /* Should fail */
5154         if(child_fid == FAIL)
5155             HDexit(EXIT_SUCCESS);
5156 
5157     /* Close the pipe */
5158         if(HDclose(out_pdf[0]) < 0)
5159             HDexit(EXIT_FAILURE);
5160 
5161         HDexit(EXIT_FAILURE);
5162     }
5163 
5164     /* close unused read end for out_pdf */
5165     if(HDclose(out_pdf[0]) < 0)
5166         FAIL_STACK_ERROR
5167 
5168     /* Open the test file */
5169     if((fid = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0)
5170         FAIL_STACK_ERROR
5171 
5172     /* Notify child process */
5173     notify = 1;
5174     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
5175         FAIL_STACK_ERROR;
5176 
5177     /* Close the pipe */
5178     if(HDclose(out_pdf[1]) < 0)
5179         FAIL_STACK_ERROR;
5180 
5181     /* Wait for child process to complete */
5182     if(HDwaitpid(childpid, &child_status, child_wait_option) < 0)
5183         FAIL_STACK_ERROR
5184 
5185     /* Check if child terminated normally */
5186     if(WIFEXITED(child_status)) {
5187         /* Check exit status of the child */
5188         if(WEXITSTATUS(child_status) != 0)
5189             TEST_ERROR
5190     } else
5191         FAIL_STACK_ERROR
5192 
5193     /* Close the file */
5194     if(H5Fclose(fid) < 0)
5195         FAIL_STACK_ERROR
5196 
5197     /*
5198      * Case 2: 1) RDWR 2) RDONLY|SWMR_READ: should fail
5199      */
5200 
5201     /* Create 1 pipe */
5202     if(HDpipe(out_pdf) < 0)
5203         FAIL_STACK_ERROR
5204 
5205     /* Fork child process */
5206     if((childpid = HDfork()) < 0)
5207     FAIL_STACK_ERROR
5208 
5209     if(childpid == 0) { /* Child process */
5210         hid_t child_fid;    /* File ID */
5211     int child_notify = 0;
5212 
5213     /* Close unused write end for out_pdf */
5214         if(HDclose(out_pdf[1]) < 0)
5215             HDexit(EXIT_FAILURE);
5216 
5217         /* Wait for notification from parent process */
5218         while(child_notify != 1) {
5219             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
5220                 HDexit(EXIT_FAILURE);
5221         }
5222 
5223         /* Open the test file */
5224         H5E_BEGIN_TRY {
5225             child_fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl);
5226         } H5E_END_TRY;
5227 
5228         /* Should fail */
5229         if(child_fid == FAIL)
5230             HDexit(EXIT_SUCCESS);
5231 
5232     /* Close the pipe */
5233         if(HDclose(out_pdf[0]) < 0)
5234             HDexit(EXIT_FAILURE);
5235 
5236         HDexit(EXIT_FAILURE);
5237     }
5238 
5239     /* close unused read end for out_pdf */
5240     if(HDclose(out_pdf[0]) < 0)
5241         FAIL_STACK_ERROR
5242 
5243     /* Open the test file */
5244     if((fid = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0)
5245     FAIL_STACK_ERROR
5246 
5247     /* Notify child process */
5248     notify = 1;
5249     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
5250         FAIL_STACK_ERROR;
5251 
5252     /* Close the pipe */
5253     if(HDclose(out_pdf[1]) < 0)
5254         FAIL_STACK_ERROR;
5255 
5256     /* Wait for child process to complete */
5257     if(HDwaitpid(childpid, &child_status, child_wait_option) < 0)
5258     FAIL_STACK_ERROR
5259 
5260     /* Check if child terminated normally */
5261     if(WIFEXITED(child_status)) {
5262         /* Check exit status of the child */
5263         if(WEXITSTATUS(child_status) != 0)
5264             TEST_ERROR
5265     } else
5266         FAIL_STACK_ERROR
5267 
5268     /* Close the file */
5269     if(H5Fclose(fid) < 0)
5270         FAIL_STACK_ERROR
5271 
5272     /*
5273      * Case 3: 1) RDWR|SWMR_WRITE 2) RDWR : should fail
5274      */
5275 
5276     /* Create 1 pipe */
5277     if(HDpipe(out_pdf) < 0)
5278         FAIL_STACK_ERROR
5279 
5280     /* Fork child process */
5281     if((childpid = HDfork()) < 0)
5282         FAIL_STACK_ERROR
5283 
5284     if(childpid == 0) { /* Child process */
5285         hid_t child_fid;    /* File ID */
5286     int child_notify = 0;
5287 
5288         /* Close unused write end for out_pdf */
5289         if(HDclose(out_pdf[1]) < 0)
5290             HDexit(EXIT_FAILURE);
5291 
5292         /* Wait for notification from parent process */
5293         while(child_notify != 1) {
5294             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
5295                 HDexit(EXIT_FAILURE);
5296         }
5297 
5298         /* Open the test file */
5299         H5E_BEGIN_TRY {
5300             child_fid = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT);
5301         } H5E_END_TRY;
5302 
5303         /* Should fail */
5304         if(child_fid == FAIL)
5305             HDexit(EXIT_SUCCESS);
5306 
5307     /* Close the pipe */
5308         if(HDclose(out_pdf[0]) < 0)
5309             HDexit(EXIT_FAILURE);
5310 
5311         HDexit(EXIT_FAILURE);
5312     }
5313 
5314     /* close unused read end for out_pdf */
5315     if(HDclose(out_pdf[0]) < 0)
5316         FAIL_STACK_ERROR
5317 
5318     /* Open the test file */
5319     if((fid = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl)) < 0)
5320         FAIL_STACK_ERROR
5321 
5322      /* Notify child process */
5323     notify = 1;
5324     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
5325         FAIL_STACK_ERROR;
5326 
5327     /* Close the pipe */
5328     if(HDclose(out_pdf[1]) < 0)
5329         FAIL_STACK_ERROR;
5330 
5331     /* Wait for child process to complete */
5332     if(HDwaitpid(childpid, &child_status, child_wait_option) < 0)
5333         FAIL_STACK_ERROR
5334 
5335     /* Check if child terminated normally */
5336     if(WIFEXITED(child_status)) {
5337         /* Check exit status of the child */
5338         if(WEXITSTATUS(child_status) != 0)
5339             TEST_ERROR
5340     } else
5341         FAIL_STACK_ERROR
5342 
5343     /* Close the file */
5344     if(H5Fclose(fid) < 0)
5345         FAIL_STACK_ERROR
5346 
5347     /*
5348      * Case 4: 1) RDWR|SWMR_WRITE 2) RDWR|SWMR_WRITE : should fail
5349      */
5350 
5351     if(HDpipe(out_pdf) < 0)
5352         FAIL_STACK_ERROR
5353 
5354     /* Fork child process */
5355     if((childpid = HDfork()) < 0)
5356     FAIL_STACK_ERROR
5357 
5358     if(childpid == 0) { /* Child process */
5359         hid_t child_fid;    /* File ID */
5360     int child_notify = 0;
5361 
5362         /* Close unused write end for out_pdf */
5363         if(HDclose(out_pdf[1]) < 0)
5364             HDexit(EXIT_FAILURE);
5365 
5366         /* Wait for notification from parent process */
5367         while(child_notify != 1) {
5368             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
5369                 HDexit(EXIT_FAILURE);
5370         }
5371 
5372         /* Open the test file */
5373         H5E_BEGIN_TRY {
5374             child_fid = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl);
5375         } H5E_END_TRY;
5376 
5377         /* Should fail */
5378         if(child_fid == FAIL)
5379             HDexit(EXIT_SUCCESS);
5380 
5381     /* Close the pipe */
5382         if(HDclose(out_pdf[0]) < 0)
5383             HDexit(EXIT_FAILURE);
5384 
5385         HDexit(EXIT_FAILURE);
5386     }
5387 
5388     /* close unused read end for out_pdf */
5389     if(HDclose(out_pdf[0]) < 0)
5390         FAIL_STACK_ERROR
5391 
5392     /* Open the test file */
5393     if((fid = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl)) < 0)
5394     FAIL_STACK_ERROR
5395 
5396     /* Notify child process */
5397     notify = 1;
5398     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
5399         FAIL_STACK_ERROR;
5400 
5401     /* Close the pipe */
5402     if(HDclose(out_pdf[1]) < 0)
5403         FAIL_STACK_ERROR;
5404 
5405     /* Wait for child process to complete */
5406     if(HDwaitpid(childpid, &child_status, child_wait_option) < 0)
5407     FAIL_STACK_ERROR
5408 
5409     /* Check if child terminated normally */
5410     if(WIFEXITED(child_status)) {
5411         /* Check exit status of the child */
5412         if(WEXITSTATUS(child_status) != 0)
5413             TEST_ERROR
5414     } else
5415         FAIL_STACK_ERROR
5416 
5417     /* Close the file */
5418     if(H5Fclose(fid) < 0)
5419         FAIL_STACK_ERROR
5420 
5421     /*
5422      * Case 5: 1) RDWR|SWMR_WRITE 2) RDONLY|SWMR_READ : should succeed
5423      */
5424 
5425     if(HDpipe(out_pdf) < 0)
5426         FAIL_STACK_ERROR
5427 
5428     /* Fork child process */
5429     if((childpid = HDfork()) < 0)
5430     FAIL_STACK_ERROR
5431 
5432     if(childpid == 0) { /* Child process */
5433         hid_t child_fid;    /* File ID */
5434     int child_notify = 0;
5435 
5436         /* Close unused write end for out_pdf */
5437         if(HDclose(out_pdf[1]) < 0)
5438             HDexit(EXIT_FAILURE);
5439 
5440         /* Wait for notification from parent process */
5441         while(child_notify != 1) {
5442             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
5443                 HDexit(EXIT_FAILURE);
5444         }
5445 
5446         /* Open the test file */
5447         H5E_BEGIN_TRY {
5448             child_fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl);
5449         } H5E_END_TRY;
5450 
5451         /* Should succeed */
5452         if(child_fid >= 0) {
5453             if(H5Fclose(child_fid) < 0)
5454                 FAIL_STACK_ERROR
5455             HDexit(EXIT_SUCCESS);
5456         }
5457 
5458     /* Close the pipe */
5459         if(HDclose(out_pdf[0]) < 0)
5460             HDexit(EXIT_FAILURE);
5461 
5462         HDexit(EXIT_FAILURE);
5463     }
5464 
5465     /* close unused read end for out_pdf */
5466     if(HDclose(out_pdf[0]) < 0)
5467         FAIL_STACK_ERROR
5468 
5469     /* Open the test file */
5470     if((fid = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl)) < 0)
5471     FAIL_STACK_ERROR
5472 
5473     /* Notify child process */
5474     notify = 1;
5475     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
5476         FAIL_STACK_ERROR;
5477 
5478     /* Close the pipe */
5479     if(HDclose(out_pdf[1]) < 0)
5480         FAIL_STACK_ERROR;
5481 
5482     /* Wait for child process to complete */
5483     if(HDwaitpid(childpid, &child_status, child_wait_option) < 0)
5484     FAIL_STACK_ERROR
5485 
5486     /* Check if child terminated normally */
5487     if(WIFEXITED(child_status)) {
5488         /* Check exit status of the child */
5489         if(WEXITSTATUS(child_status) != 0)
5490             TEST_ERROR
5491     } else
5492         FAIL_STACK_ERROR
5493 
5494     /* Close the file */
5495     if(H5Fclose(fid) < 0)
5496         FAIL_STACK_ERROR
5497 
5498     /*
5499      * Case 6: 1) RDWR|SWMR_WRITE 2) RDONLY : should fail
5500      */
5501 
5502     if(HDpipe(out_pdf) < 0)
5503         FAIL_STACK_ERROR
5504 
5505     /* Fork child process */
5506     if((childpid = HDfork()) < 0)
5507         FAIL_STACK_ERROR
5508 
5509     if(childpid == 0) { /* Child process */
5510         hid_t child_fid;    /* File ID */
5511     int child_notify = 0;
5512 
5513         /* Close unused write end for out_pdf */
5514         if(HDclose(out_pdf[1]) < 0)
5515             HDexit(EXIT_FAILURE);
5516 
5517         /* Wait for notification from parent process */
5518         while(child_notify != 1) {
5519             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
5520                 HDexit(EXIT_FAILURE);
5521         }
5522 
5523         /* Open the test file */
5524         H5E_BEGIN_TRY {
5525             child_fid = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT);
5526         } H5E_END_TRY;
5527 
5528         /* Should fail */
5529         if(child_fid == FAIL)
5530             HDexit(EXIT_SUCCESS);
5531 
5532     /* Close the pipe */
5533         if(HDclose(out_pdf[0]) < 0)
5534             HDexit(EXIT_FAILURE);
5535 
5536         HDexit(EXIT_FAILURE);
5537     }
5538 
5539     /* close unused read end for out_pdf */
5540     if(HDclose(out_pdf[0]) < 0)
5541         FAIL_STACK_ERROR
5542 
5543     /* Open the test file */
5544     if((fid = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl)) < 0)
5545         FAIL_STACK_ERROR
5546 
5547      /* Notify child process */
5548     notify = 1;
5549     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
5550         FAIL_STACK_ERROR;
5551 
5552     /* Close the pipe */
5553     if(HDclose(out_pdf[1]) < 0)
5554         FAIL_STACK_ERROR;
5555 
5556     /* Wait for child process to complete */
5557     if(HDwaitpid(childpid, &child_status, child_wait_option) < 0)
5558         FAIL_STACK_ERROR
5559 
5560     /* Check if child terminated normally */
5561     if(WIFEXITED(child_status)) {
5562         /* Check exit status of the child */
5563         if(WEXITSTATUS(child_status) != 0)
5564             TEST_ERROR
5565     } else
5566         FAIL_STACK_ERROR
5567 
5568     /* Close the file */
5569     if(H5Fclose(fid) < 0)
5570         FAIL_STACK_ERROR
5571 
5572     /*
5573      * Case 7: 1) RDONLY|SWMR_READ 2) RDWR : should fail
5574      */
5575 
5576     /* Create 1 pipe */
5577     if(HDpipe(out_pdf) < 0)
5578         FAIL_STACK_ERROR
5579 
5580     /* Fork child process */
5581     if((childpid = HDfork()) < 0)
5582         FAIL_STACK_ERROR
5583 
5584     if(childpid == 0) { /* Child process */
5585         hid_t child_fid;    /* File ID */
5586     int child_notify = 0;
5587 
5588         /* Close unused write end for out_pdf */
5589         if(HDclose(out_pdf[1]) < 0)
5590             HDexit(EXIT_FAILURE);
5591 
5592         /* Wait for notification from parent process */
5593         while(child_notify != 1) {
5594             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
5595                 HDexit(EXIT_FAILURE);
5596         }
5597 
5598         /* Open the test file */
5599         H5E_BEGIN_TRY {
5600             child_fid = H5Fopen(filename, H5F_ACC_RDWR, H5P_DEFAULT);
5601         } H5E_END_TRY;
5602 
5603         /* Should fail */
5604         if(child_fid == FAIL)
5605             HDexit(EXIT_SUCCESS);
5606 
5607     /* Close the pipe */
5608         if(HDclose(out_pdf[0]) < 0)
5609             HDexit(EXIT_FAILURE);
5610 
5611         HDexit(EXIT_FAILURE);
5612     }
5613 
5614     /* close unused read end for out_pdf */
5615     if(HDclose(out_pdf[0]) < 0)
5616         FAIL_STACK_ERROR
5617 
5618     /* Open the test file */
5619     if((fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl)) < 0)
5620         FAIL_STACK_ERROR
5621 
5622      /* Notify child process */
5623     notify = 1;
5624     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
5625         FAIL_STACK_ERROR;
5626 
5627     /* Close the pipe */
5628     if(HDclose(out_pdf[1]) < 0)
5629         FAIL_STACK_ERROR;
5630 
5631     /* Wait for child process to complete */
5632     if(HDwaitpid(childpid, &child_status, child_wait_option) < 0)
5633         FAIL_STACK_ERROR
5634 
5635     /* Check if child terminated normally */
5636     if(WIFEXITED(child_status)) {
5637         /* Check exit status of the child */
5638         if(WEXITSTATUS(child_status) != 0)
5639             TEST_ERROR
5640     } else
5641         FAIL_STACK_ERROR
5642 
5643     /* Close the file */
5644     if(H5Fclose(fid) < 0)
5645         FAIL_STACK_ERROR
5646 
5647     /*
5648      * Case 8: 1) RDONLY|SWMR_READ 2) RDWR|SWMR_WRITE : should fail
5649      */
5650 
5651     /* Create 1 pipe */
5652     if(HDpipe(out_pdf) < 0)
5653         FAIL_STACK_ERROR
5654 
5655     /* Fork child process */
5656     if((childpid = HDfork()) < 0)
5657         FAIL_STACK_ERROR
5658 
5659     if(childpid == 0) { /* Child process */
5660         hid_t child_fid;    /* File ID */
5661     int child_notify = 0;
5662 
5663         /* Close unused write end for out_pdf */
5664         if(HDclose(out_pdf[1]) < 0)
5665             HDexit(EXIT_FAILURE);
5666 
5667         /* Wait for notification from parent process */
5668         while(child_notify != 1) {
5669             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
5670                 HDexit(EXIT_FAILURE);
5671         }
5672 
5673         /* Open the test file */
5674         H5E_BEGIN_TRY {
5675             child_fid = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl);
5676         } H5E_END_TRY;
5677 
5678         /* Should fail */
5679         if(child_fid == FAIL)
5680             HDexit(EXIT_SUCCESS);
5681 
5682         /* Close the pipe */
5683         if(HDclose(out_pdf[0]) < 0)
5684             HDexit(EXIT_FAILURE);
5685 
5686         HDexit(EXIT_FAILURE);
5687     }
5688 
5689     /* close unused read end for out_pdf */
5690     if(HDclose(out_pdf[0]) < 0)
5691         FAIL_STACK_ERROR
5692 
5693     /* Open the test file */
5694     if((fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl)) < 0)
5695         FAIL_STACK_ERROR
5696 
5697     /* Notify child process */
5698     notify = 1;
5699     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
5700         FAIL_STACK_ERROR;
5701 
5702     /* Close the pipe */
5703     if(HDclose(out_pdf[1]) < 0)
5704         FAIL_STACK_ERROR;
5705 
5706     /* Wait for child process to complete */
5707     if(HDwaitpid(childpid, &child_status, child_wait_option) < 0)
5708         FAIL_STACK_ERROR
5709 
5710     /* Check if child terminated normally */
5711     if(WIFEXITED(child_status)) {
5712         /* Check exit status of the child */
5713         if(WEXITSTATUS(child_status) != 0)
5714             TEST_ERROR
5715     } else
5716         FAIL_STACK_ERROR
5717 
5718     /* Close the file */
5719     if(H5Fclose(fid) < 0)
5720         FAIL_STACK_ERROR
5721 
5722     /*
5723      * Case 9: 1) RDONLY|SWMR_READ 2) RDONLY|SWMR_READ : should succeed
5724      */
5725 
5726     /* Create 1 pipe */
5727     if(HDpipe(out_pdf) < 0)
5728         FAIL_STACK_ERROR
5729 
5730     /* Fork child process */
5731     if((childpid = HDfork()) < 0)
5732         FAIL_STACK_ERROR
5733 
5734     if(childpid == 0) { /* Child process */
5735         hid_t child_fid;    /* File ID */
5736     int child_notify = 0;
5737 
5738         /* Close unused write end for out_pdf */
5739         if(HDclose(out_pdf[1]) < 0)
5740             HDexit(EXIT_FAILURE);
5741 
5742         /* Wait for notification from parent process */
5743         while(child_notify != 1) {
5744             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
5745                 HDexit(EXIT_FAILURE);
5746         }
5747 
5748         /* Open the test file */
5749         H5E_BEGIN_TRY {
5750             child_fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl);
5751         } H5E_END_TRY;
5752 
5753         /* Should succeed */
5754         if(child_fid >= 0) {
5755             if(H5Fclose(child_fid) < 0)
5756                 FAIL_STACK_ERROR
5757             HDexit(EXIT_SUCCESS);
5758         }
5759 
5760         /* Close the pipe */
5761         if(HDclose(out_pdf[0]) < 0)
5762             HDexit(EXIT_FAILURE);
5763 
5764         HDexit(EXIT_FAILURE);
5765     }
5766 
5767     /* close unused read end for out_pdf */
5768     if(HDclose(out_pdf[0]) < 0)
5769         FAIL_STACK_ERROR
5770 
5771     /* Open the test file */
5772     if((fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl)) < 0)
5773         FAIL_STACK_ERROR
5774 
5775     /* Notify child process */
5776     notify = 1;
5777     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
5778         FAIL_STACK_ERROR;
5779 
5780     /* Close the pipe */
5781     if(HDclose(out_pdf[1]) < 0)
5782         FAIL_STACK_ERROR;
5783 
5784     /* Wait for child process to complete */
5785     if(HDwaitpid(childpid, &child_status, child_wait_option) < 0)
5786         FAIL_STACK_ERROR
5787 
5788     /* Check if child terminated normally */
5789     if(WIFEXITED(child_status)) {
5790         /* Check exit status of the child */
5791         if(WEXITSTATUS(child_status) != 0)
5792             TEST_ERROR
5793     } else
5794         FAIL_STACK_ERROR
5795 
5796     /* Close the file */
5797     if(H5Fclose(fid) < 0)
5798         FAIL_STACK_ERROR
5799 
5800     /*
5801      * Case 10: 1) RDONLY|SWMR_READ 2) RDONLY : should succeed
5802      */
5803 
5804     /* Create 1 pipe */
5805     if(HDpipe(out_pdf) < 0)
5806         FAIL_STACK_ERROR
5807 
5808     /* Fork child process */
5809     if((childpid = HDfork()) < 0)
5810         FAIL_STACK_ERROR
5811 
5812     if(childpid == 0) { /* Child process */
5813         hid_t child_fid;    /* File ID */
5814     int child_notify = 0;
5815 
5816         /* Close unused write end for out_pdf */
5817         if(HDclose(out_pdf[1]) < 0)
5818             HDexit(EXIT_FAILURE);
5819 
5820         /* Wait for notification from parent process */
5821         while(child_notify != 1) {
5822             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
5823                 HDexit(EXIT_FAILURE);
5824         }
5825 
5826         /* Open the test file */
5827         if((child_fid = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
5828             FAIL_STACK_ERROR
5829 
5830         /* Should succeed */
5831         if(child_fid >= 0) {
5832             if(H5Fclose(child_fid) < 0)
5833                 FAIL_STACK_ERROR
5834             HDexit(EXIT_SUCCESS);
5835         }
5836 
5837     /* Close the pipe */
5838         if(HDclose(out_pdf[0]) < 0)
5839             HDexit(EXIT_FAILURE);
5840 
5841         HDexit(EXIT_FAILURE);
5842     }
5843 
5844     /* close unused read end for out_pdf */
5845     if(HDclose(out_pdf[0]) < 0)
5846         FAIL_STACK_ERROR
5847 
5848     /* Open the test file */
5849     if((fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl)) < 0)
5850         FAIL_STACK_ERROR
5851 
5852      /* Notify child process */
5853     notify = 1;
5854     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
5855         FAIL_STACK_ERROR;
5856 
5857     /* Close the pipe */
5858     if(HDclose(out_pdf[1]) < 0)
5859         FAIL_STACK_ERROR;
5860 
5861     /* Wait for child process to complete */
5862     if(HDwaitpid(childpid, &child_status, child_wait_option) < 0)
5863         FAIL_STACK_ERROR
5864 
5865     /* Check if child terminated normally */
5866     if(WIFEXITED(child_status)) {
5867         /* Check exit status of the child */
5868         if(WEXITSTATUS(child_status) != 0)
5869             TEST_ERROR
5870     } else
5871         FAIL_STACK_ERROR
5872 
5873     /* Close the file */
5874     if(H5Fclose(fid) < 0)
5875         FAIL_STACK_ERROR
5876 
5877     /*
5878      * Case 11: 1) RDONLY 2) RDWR|SWMR_WRITE : should fail
5879      */
5880 
5881     /* Create 1 pipe */
5882     if(HDpipe(out_pdf) < 0)
5883     FAIL_STACK_ERROR
5884 
5885     /* Fork child process */
5886     if((childpid = HDfork()) < 0)
5887         FAIL_STACK_ERROR
5888 
5889     if(childpid == 0) { /* Child process */
5890         hid_t child_fid;    /* File ID */
5891     int child_notify = 0;
5892 
5893         /* Close unused write end for out_pdf */
5894         if(HDclose(out_pdf[1]) < 0)
5895             HDexit(EXIT_FAILURE);
5896 
5897         /* Wait for notification from parent process */
5898         while(child_notify != 1) {
5899             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
5900                 HDexit(EXIT_FAILURE);
5901         }
5902 
5903         /* Open the test file */
5904         H5E_BEGIN_TRY {
5905             child_fid = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl);
5906         } H5E_END_TRY;
5907 
5908         /* Should fail */
5909         if(child_fid == FAIL)
5910             HDexit(EXIT_SUCCESS);
5911 
5912     /* Close the pipe */
5913         if(HDclose(out_pdf[0]) < 0)
5914             HDexit(EXIT_FAILURE);
5915 
5916         HDexit(EXIT_FAILURE);
5917     }
5918 
5919     /* Close unused read end for out_pdf */
5920     if(HDclose(out_pdf[0]) < 0)
5921         FAIL_STACK_ERROR
5922 
5923     /* Open the test file */
5924     if((fid = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
5925         FAIL_STACK_ERROR
5926 
5927     /* Notify child process */
5928     notify = 1;
5929     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
5930         FAIL_STACK_ERROR;
5931 
5932     /* Close the pipe */
5933     if(HDclose(out_pdf[1]) < 0)
5934         FAIL_STACK_ERROR;
5935 
5936     /* Wait for child process to complete */
5937     if(HDwaitpid(childpid, &child_status, child_wait_option) < 0)
5938         FAIL_STACK_ERROR
5939 
5940     /* Check if child terminated normally */
5941     if(WIFEXITED(child_status)) {
5942         /* Check exit status of the child */
5943         if(WEXITSTATUS(child_status) != 0)
5944             TEST_ERROR
5945     } else
5946         FAIL_STACK_ERROR
5947 
5948     /* Close the file */
5949     if(H5Fclose(fid) < 0)
5950         FAIL_STACK_ERROR
5951 
5952     /*
5953      * Case 12: 1) RDONLY 2) RDONLY|SWMR_READ : should succeed
5954      */
5955 
5956     /* Create 1 pipe */
5957     if(HDpipe(out_pdf) < 0)
5958         FAIL_STACK_ERROR
5959 
5960     /* Fork child process */
5961     if((childpid = HDfork()) < 0)
5962         FAIL_STACK_ERROR
5963 
5964     if(childpid == 0) { /* Child process */
5965         hid_t child_fid;    /* File ID */
5966     int child_notify = 0;
5967 
5968         /* Close unused write end for out_pdf */
5969         if(HDclose(out_pdf[1]) < 0)
5970             HDexit(EXIT_FAILURE);
5971 
5972         /* Wait for notification from parent process */
5973         while(child_notify != 1) {
5974             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
5975                 HDexit(EXIT_FAILURE);
5976         }
5977 
5978         /* Open the test file */
5979         H5E_BEGIN_TRY {
5980             child_fid = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl);
5981         } H5E_END_TRY;
5982 
5983         /* Should succeed */
5984         if(child_fid >= 0) {
5985             if(H5Fclose(child_fid) < 0)
5986                 FAIL_STACK_ERROR
5987             HDexit(EXIT_SUCCESS);
5988         }
5989 
5990         /* Close the pipe */
5991         if(HDclose(out_pdf[0]) < 0)
5992             HDexit(EXIT_FAILURE);
5993 
5994         HDexit(EXIT_FAILURE);
5995     }
5996 
5997     /* close unused read end for out_pdf */
5998     if(HDclose(out_pdf[0]) < 0)
5999         FAIL_STACK_ERROR
6000 
6001     /* Open the test file */
6002     if((fid = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0)
6003         FAIL_STACK_ERROR
6004 
6005     /* Notify child process */
6006     notify = 1;
6007     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
6008         FAIL_STACK_ERROR;
6009 
6010     /* Close the pipe */
6011     if(HDclose(out_pdf[1]) < 0)
6012         FAIL_STACK_ERROR;
6013 
6014     /* Wait for child process to complete */
6015     if(HDwaitpid(childpid, &child_status, child_wait_option) < 0)
6016         FAIL_STACK_ERROR
6017 
6018     /* Check if child terminated normally */
6019     if(WIFEXITED(child_status)) {
6020         /* Check exit status of the child */
6021         if(WEXITSTATUS(child_status) != 0)
6022             TEST_ERROR
6023     } else
6024         FAIL_STACK_ERROR
6025 
6026     /* Close the file */
6027     if(H5Fclose(fid) < 0)
6028         FAIL_STACK_ERROR
6029 
6030     /* Close the property list */
6031     if(H5Pclose(fapl) < 0)
6032         FAIL_STACK_ERROR
6033 
6034     PASSED();
6035 
6036     return 0;
6037 
6038 error:
6039     H5E_BEGIN_TRY {
6040         H5Pclose(fapl);
6041         H5Fclose(fid);
6042     } H5E_END_TRY;
6043 
6044     return -1;
6045 
6046 } /* end test_file_lock_swmr_concur() */
6047 
6048 
6049 
6050 #endif /* !(defined(H5_HAVE_FORK && defined(H5_HAVE_WAITPID)) */
6051 
6052 /****************************************************************
6053 **
6054 **  test_file_lock_swmr_concur(): low-level file test routine.
6055 **    With the implementation of file locking, this test checks file
6056 **    open with different combinations of flags + SWMR flags.
6057 **    This is for concurrent access.
6058 **
6059 *****************************************************************/
6060 static int
test_file_lock_env_var(hid_t in_fapl)6061 test_file_lock_env_var(hid_t in_fapl)
6062 {
6063 #if !(defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID))
6064     SKIPPED();
6065     HDputs("    Test skipped due to fork or waitpid not defined.");
6066     return 0;
6067 #else
6068     hid_t fid = -1;             /* File ID */
6069     hid_t fapl = -1;                    /* File access property list */
6070     char filename[NAME_BUF_SIZE];       /* file name */
6071     pid_t childpid=0;           /* Child process ID */
6072     int child_status;           /* Status passed to waitpid */
6073     int child_wait_option=0;        /* Options passed to waitpid */
6074     int out_pdf[2];
6075     int notify = 0;
6076 
6077 
6078     TESTING("File locking environment variable");
6079 
6080 
6081     /* Set the environment variable */
6082     if(HDsetenv("HDF5_USE_FILE_LOCKING", "FALSE", TRUE) < 0)
6083         TEST_ERROR
6084 
6085     if((fapl = H5Pcopy(in_fapl)) < 0)
6086         TEST_ERROR
6087 
6088     /* Set the filename to use for this test (dependent on fapl) */
6089     h5_fixname(FILENAME[1], fapl, filename, sizeof(filename));
6090 
6091     /* Create the test file */
6092     if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
6093         TEST_ERROR
6094 
6095     /* Close the file */
6096     if(H5Fclose(fid) < 0)
6097         TEST_ERROR
6098 
6099     /* Open a file for read-only and then read-write. This would
6100      * normally fail due to the file locking scheme but should
6101      * pass when the environment variable is set to disable file
6102      * locking.
6103      */
6104 
6105     /* Create 1 pipe */
6106     if(HDpipe(out_pdf) < 0)
6107         TEST_ERROR
6108 
6109     /* Fork child process */
6110     if((childpid = HDfork()) < 0)
6111         TEST_ERROR
6112 
6113     if(childpid == 0) {
6114 
6115         /* Child process */
6116 
6117         hid_t child_fid;    /* File ID */
6118         int child_notify = 0;
6119 
6120         /* Close unused write end for out_pdf */
6121         if(HDclose(out_pdf[1]) < 0)
6122             HDexit(EXIT_FAILURE);
6123 
6124         /* Wait for notification from parent process */
6125         while(child_notify != 1) {
6126             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
6127                 HDexit(EXIT_FAILURE);
6128         } /* end while */
6129 
6130         /* Open the test file */
6131         if((child_fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
6132             TEST_ERROR
6133 
6134         /* Close the pipe */
6135         if(HDclose(out_pdf[0]) < 0)
6136             HDexit(EXIT_FAILURE);
6137 
6138         HDexit(EXIT_SUCCESS);
6139     } /* end if */
6140 
6141     /* close unused read end for out_pdf */
6142     if(HDclose(out_pdf[0]) < 0)
6143         TEST_ERROR
6144 
6145     /* Open the test file */
6146     if((fid = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
6147         TEST_ERROR
6148 
6149     /* Notify child process */
6150     notify = 1;
6151     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
6152         TEST_ERROR;
6153 
6154     /* Close the pipe */
6155     if(HDclose(out_pdf[1]) < 0)
6156         TEST_ERROR;
6157 
6158     /* Wait for child process to complete */
6159     if(HDwaitpid(childpid, &child_status, child_wait_option) < 0)
6160         TEST_ERROR
6161 
6162     /* Check if child terminated normally */
6163     if(WIFEXITED(child_status)) {
6164         /* Check exit status of the child */
6165         if(WEXITSTATUS(child_status) != 0)
6166             TEST_ERROR
6167     } /* end if */
6168     else
6169         TEST_ERROR
6170 
6171     /* Close the file */
6172     if(H5Fclose(fid) < 0)
6173         TEST_ERROR
6174 
6175     /* Close the copied property list */
6176     if(H5Pclose(fapl) < 0)
6177         TEST_ERROR
6178 
6179     PASSED();
6180 
6181     return 0;
6182 
6183 error:
6184     H5E_BEGIN_TRY {
6185         H5Pclose(fapl);
6186         H5Fclose(fid);
6187     } H5E_END_TRY;
6188 
6189     return -1;
6190 
6191 
6192 #endif /* !(defined(H5_HAVE_FORK && defined(H5_HAVE_WAITPID)) */
6193 
6194 } /* end test_file_lock_env_var() */
6195 
6196 
6197 static int
test_swmr_vfd_flag(void)6198 test_swmr_vfd_flag(void)
6199 {
6200     hid_t fid = -1;         /* file ID */
6201     hid_t sec2_fapl = -1;   /* fapl ID of a VFD that supports SWMR writes (sec2) */
6202     hid_t bad_fapl = -1;    /* fapl ID of a VFD that does not support SWMR writes (stdio) */
6203     char filename[NAME_BUF_SIZE];   /* file name */
6204 
6205     TESTING("SWMR-enabled VFD flag functionality");
6206 
6207     /* Attempt to open a file using a SWMR-compatible VFD. */
6208 
6209     if((sec2_fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
6210         FAIL_STACK_ERROR;
6211     if(H5Pset_fapl_sec2(sec2_fapl) < 0)
6212         FAIL_STACK_ERROR;
6213     if(H5Pset_libver_bounds(sec2_fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
6214         FAIL_STACK_ERROR
6215 
6216     h5_fixname(FILENAME[0], sec2_fapl, filename, sizeof(filename));
6217     if((fid = H5Fcreate(filename, H5F_ACC_TRUNC | H5F_ACC_SWMR_WRITE, H5P_DEFAULT, sec2_fapl)) < 0)
6218         FAIL_STACK_ERROR;
6219     if(H5Fclose(fid) < 0)
6220         FAIL_STACK_ERROR;
6221 
6222     /* Attempt to open a file using a non-SWMR-compatible VFD. */
6223 
6224     if((bad_fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
6225         FAIL_STACK_ERROR;
6226     if(H5Pset_fapl_stdio(bad_fapl) < 0)
6227         FAIL_STACK_ERROR;
6228     if(H5Pset_libver_bounds(bad_fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
6229         FAIL_STACK_ERROR
6230 
6231     fid = -1;
6232     h5_fixname(FILENAME[0], bad_fapl, filename, sizeof(filename));
6233     H5E_BEGIN_TRY {
6234         fid = H5Fcreate(filename, H5F_ACC_TRUNC | H5F_ACC_SWMR_WRITE, H5P_DEFAULT, bad_fapl);
6235     } H5E_END_TRY;
6236     if(fid >= 0)
6237         TEST_ERROR;
6238 
6239     if(H5Pclose(sec2_fapl) < 0)
6240         FAIL_STACK_ERROR;
6241     if(H5Pclose(bad_fapl) < 0)
6242         FAIL_STACK_ERROR;
6243 
6244     PASSED();
6245 
6246     return 0;
6247 
6248 error:
6249     H5E_BEGIN_TRY {
6250         H5Pclose(sec2_fapl);
6251         H5Pclose(bad_fapl);
6252         H5Fclose(fid);
6253     } H5E_END_TRY;
6254 
6255     return -1;
6256 } /* test_swmr_vfd_flag() */
6257 
6258 #ifdef OUT
6259 /*
6260  * This exposes a bug for H5Orefresh while handling opened objects for H5Fstart_swmr_write().
6261  * The boolean to skip file truncation test when reading in superblock will fix the problem.
6262  * Will work to move that to test/flushrefresh.c later.
6263  */
6264 static int
test_bug_refresh(hid_t in_fapl)6265 test_bug_refresh(hid_t in_fapl)
6266 {
6267     hid_t fid = -1;         /* File ID */
6268     hid_t fapl;
6269     H5F_t *f;
6270     hid_t gid1, gid2, gid3, gid4, gid5, gid6, gid7, gid8, gid9;
6271     char filename[NAME_BUF_SIZE];   /* File name */
6272 
6273     /* Create a copy of the input parameter in_fapl */
6274     if((fapl = H5Pcopy(in_fapl)) < 0)
6275         FAIL_STACK_ERROR
6276 
6277     /* Set to use the latest library format */
6278     if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
6279         FAIL_STACK_ERROR
6280 
6281     /* Set the filename to use for this test (dependent on fapl) */
6282     h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));
6283 
6284     TESTING("H5Orefresh failure conditions");
6285 
6286     /* Create a file with the latest format */
6287     if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
6288         FAIL_STACK_ERROR
6289 
6290     /* Get a pointer to the internal file object */
6291     if(NULL == (f = (H5F_t *)H5I_object(fid)))
6292         FAIL_STACK_ERROR
6293 
6294     /* Create groups: compact to dense storage */
6295     if((gid1 = H5Gcreate2(fid, "group1", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
6296         FAIL_STACK_ERROR;
6297     if((gid2 = H5Gcreate2(fid, "group2", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
6298         FAIL_STACK_ERROR;
6299     if((gid3 = H5Gcreate2(fid, "group3", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
6300         FAIL_STACK_ERROR;
6301     if((gid4 = H5Gcreate2(fid, "group4", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
6302         FAIL_STACK_ERROR;
6303     if((gid5 = H5Gcreate2(fid, "group5", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
6304         FAIL_STACK_ERROR;
6305     if((gid6 = H5Gcreate2(fid, "group6", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
6306         FAIL_STACK_ERROR;
6307     if((gid7 = H5Gcreate2(fid, "group7", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
6308         FAIL_STACK_ERROR;
6309     if((gid8 = H5Gcreate2(fid, "group8", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
6310         FAIL_STACK_ERROR;
6311     if((gid9 = H5Gcreate2(fid, "group9", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
6312         FAIL_STACK_ERROR;
6313 
6314     if (H5Fflush(fid, H5F_SCOPE_GLOBAL) < 0)
6315         TEST_ERROR
6316 
6317     if(H5Grefresh(gid1) < 0) TEST_ERROR
6318     if(H5Grefresh(gid2) < 0) TEST_ERROR
6319     if(H5Grefresh(gid3) < 0) TEST_ERROR
6320     if(H5Grefresh(gid4) < 0) TEST_ERROR
6321     if(H5Grefresh(gid5) < 0) TEST_ERROR
6322     if(H5Grefresh(gid6) < 0) TEST_ERROR
6323     if(H5Grefresh(gid7) < 0) TEST_ERROR
6324     if(H5Grefresh(gid8) < 0) TEST_ERROR
6325     if(H5Grefresh(gid9) < 0) TEST_ERROR
6326 
6327     H5Gclose(gid1);
6328     H5Gclose(gid2);
6329     H5Gclose(gid3);
6330     H5Gclose(gid4);
6331     H5Gclose(gid5);
6332     H5Gclose(gid6);
6333     H5Gclose(gid7);
6334     H5Gclose(gid8);
6335     H5Gclose(gid9);
6336     H5Pclose(fapl);
6337     H5Fclose(fid);
6338     PASSED();
6339     return 0;
6340 
6341 error:
6342     H5E_BEGIN_TRY {
6343         H5Gclose(gid1);
6344         H5Gclose(gid2);
6345         H5Gclose(gid3);
6346         H5Gclose(gid4);
6347         H5Gclose(gid5);
6348         H5Gclose(gid6);
6349         H5Gclose(gid7);
6350         H5Gclose(gid8);
6351         H5Gclose(gid9);
6352         H5Pclose(fapl);
6353         H5Fclose(fid);
6354     } H5E_END_TRY;
6355 
6356     return -1;
6357 } /* test_bug_refresh() */
6358 #endif /* OUT */
6359 
6360 /*
6361  * test_refresh_concur():
6362  *
6363  * The "new_format" parameter indicates whether to create the file with latest format or not.
6364  *  To have SWMR support, can use either one of the following in creating a file:
6365  *  (a) Create the file with write + latest format:
6366  *      --result in v3 superblock with latest chunk indexing types
6367  *  (b) Create the file with SWMR write + non-latest-format:
6368  *      --result in v3 superblock with latest chunk indexing types
6369  *
6370  * Verify H5Drefresh() works correctly with concurrent access:
6371  *      Parent process:
6372  *              (1) Open the test file, write to the dataset
6373  *              (2) Notify child process #A
6374  *              (3) Wait for notification from child process #B
6375  *              (4) Extend the dataset, write to the dataset, flush the file
6376  *              (5) Notify child process #C
6377  *      Child process:
6378  *              (1) Wait for notification from parent process #A
6379  *              (2) Open the file 2 times
6380  *              (3) Open the dataset 2 times with the 2 files
6381  *              (4) Verify the dataset's dimension and data read are correct
6382  *              (5) Notify parent process #B
6383  *              (6) Wait for notification from parent process #C
6384  *              (7) Refresh the dataset
6385  *              (8) Verify the dataset's dimension and data are correct
6386  */
6387 #if !(defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID))
6388 
6389 static int
test_refresh_concur(hid_t H5_ATTR_UNUSED in_fapl,hbool_t H5_ATTR_UNUSED new_format)6390 test_refresh_concur(hid_t H5_ATTR_UNUSED in_fapl, hbool_t H5_ATTR_UNUSED new_format)
6391 {
6392     SKIPPED();
6393     HDputs("    Test skipped due to fork or waitpid not defined.");
6394     return 0;
6395 } /* test_refresh_concur() */
6396 
6397 #else /* defined(H5_HAVE_FORK && defined(H5_HAVE_WAITPID) */
6398 
6399 static int
test_refresh_concur(hid_t in_fapl,hbool_t new_format)6400 test_refresh_concur(hid_t in_fapl, hbool_t new_format)
6401 {
6402     hid_t fid;              /* File ID */
6403     hid_t fapl;             /* File access property list */
6404     pid_t childpid=0;           /* Child process ID */
6405     pid_t tmppid;           /* Child process ID returned by waitpid */
6406     int child_status;           /* Status passed to waitpid */
6407     int child_wait_option=0;        /* Options passed to waitpid */
6408     int child_exit_val;         /* Exit status of the child */
6409     char filename[NAME_BUF_SIZE];   /* File name */
6410 
6411     hid_t did = -1;
6412     hid_t sid = -1;
6413     hid_t dcpl = -1;
6414     hsize_t chunk_dims[1] = {1};
6415     hsize_t maxdims[1] = {H5S_UNLIMITED};
6416     hsize_t dims[1] = { 1 };
6417     hsize_t new_dims[1] = {2};
6418 
6419     int out_pdf[2];
6420     int in_pdf[2];
6421     int notify = 0;
6422     int wbuf[2];
6423 
6424     /* Output message about test being performed */
6425     if(new_format) {
6426         TESTING("H5Drefresh()--concurrent access for latest format");
6427     } else {
6428         TESTING("H5Drefresh()--concurrent access for non-latest-format");
6429     } /* end if */
6430 
6431 
6432     if((fapl = H5Pcopy(in_fapl)) < 0)
6433         FAIL_STACK_ERROR
6434 
6435     /* Set the filename to use for this test (dependent on fapl) */
6436     h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));
6437 
6438     if(new_format) {
6439         /* Set to use the latest library format */
6440         if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
6441             FAIL_STACK_ERROR
6442 
6443         /* Create the test file */
6444         if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
6445             FAIL_STACK_ERROR
6446     } else {
6447         /* Create the test file without latest format but with SWMR write */
6448         if((fid = H5Fcreate(filename, H5F_ACC_TRUNC|H5F_ACC_SWMR_WRITE, H5P_DEFAULT, fapl)) < 0)
6449             FAIL_STACK_ERROR
6450     } /* end if */
6451 
6452     /* Create a chunked dataset with 1 extendible dimension */
6453     if((sid = H5Screate_simple(1, dims, maxdims)) < 0)
6454         FAIL_STACK_ERROR;
6455     if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
6456         FAIL_STACK_ERROR
6457     if(H5Pset_chunk(dcpl, 1, chunk_dims) < 0)
6458         FAIL_STACK_ERROR;
6459     if((did = H5Dcreate2(fid, "dataset", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
6460         FAIL_STACK_ERROR;
6461 
6462     /* Closing */
6463     if(H5Dclose(did) < 0)
6464         FAIL_STACK_ERROR
6465     if(H5Sclose(sid) < 0)
6466         FAIL_STACK_ERROR
6467     if(H5Pclose(dcpl) < 0)
6468         FAIL_STACK_ERROR
6469 
6470     /* Close the file */
6471     if(H5Fclose(fid) < 0)
6472         FAIL_STACK_ERROR
6473 
6474     /* Create 2 pipes */
6475     if(HDpipe(out_pdf) < 0)
6476         FAIL_STACK_ERROR
6477     if(HDpipe(in_pdf) < 0)
6478         FAIL_STACK_ERROR
6479 
6480     /* Fork child process */
6481     if((childpid = HDfork()) < 0)
6482         FAIL_STACK_ERROR
6483 
6484     if(childpid == 0) { /* Child process */
6485         hid_t child_fid1 = -1;    /* File ID */
6486         hid_t child_fid2 = -1;    /* File ID */
6487         hid_t child_did1 = -1, child_did2 = -1;
6488         hid_t child_sid = -1;
6489         hsize_t tdims[1];
6490         int rbuf[2] = {0, 0};
6491         int child_notify = 0;
6492 
6493         /* Close unused write end for out_pdf */
6494         if(HDclose(out_pdf[1]) < 0)
6495             HDexit(EXIT_FAILURE);
6496 
6497         /* close unused read end for in_pdf */
6498         if(HDclose(in_pdf[0]) < 0)
6499             HDexit(EXIT_FAILURE);
6500 
6501         /* Wait for notification from parent process */
6502         while(child_notify != 1)
6503             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
6504                 HDexit(EXIT_FAILURE);
6505 
6506         /* Open the file 2 times */
6507         if((child_fid1 = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl)) < 0)
6508             HDexit(EXIT_FAILURE);
6509 
6510         if((child_fid2 = H5Fopen(filename, H5F_ACC_RDONLY|H5F_ACC_SWMR_READ, fapl)) < 0)
6511             HDexit(EXIT_FAILURE);
6512 
6513         /* Open the dataset 2 times */
6514         if((child_did1 = H5Dopen2(child_fid1, "dataset", H5P_DEFAULT)) < 0)
6515             HDexit(EXIT_FAILURE);
6516         if((child_did2 = H5Dopen2(child_fid2, "dataset", H5P_DEFAULT)) < 0)
6517             HDexit(EXIT_FAILURE);
6518 
6519         /* Get the dataset's dataspace via did1 */
6520         if((child_sid = H5Dget_space(child_did1)) < 0)
6521             HDexit(EXIT_FAILURE);
6522         if(H5Sget_simple_extent_dims(child_sid, tdims, NULL) < 0)
6523             HDexit(EXIT_FAILURE);
6524         if(tdims[0] != 1)
6525             HDexit(EXIT_FAILURE);
6526 
6527         /* Read from the dataset via did2 */
6528         if(H5Dread(child_did2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf) < 0)
6529             HDexit(EXIT_FAILURE);
6530 
6531         /* Verify the data is correct */
6532         if(rbuf[0] != 99)
6533             HDexit(EXIT_FAILURE);
6534 
6535         /* Notify parent process */
6536         child_notify = 2;
6537         if(HDwrite(in_pdf[1], &child_notify, sizeof(int)) < 0)
6538             HDexit(EXIT_FAILURE);
6539 
6540         /* Wait for notification from parent process */
6541         while(child_notify != 3)
6542             if(HDread(out_pdf[0], &child_notify, sizeof(int)) < 0)
6543                 HDexit(EXIT_FAILURE);
6544 
6545         /* Refresh dataset via did1 */
6546         if(H5Drefresh(child_did1) < 0)
6547             HDexit(EXIT_FAILURE);
6548 
6549         /* Get the dataset's dataspace and verify */
6550         if((child_sid = H5Dget_space(child_did1)) < 0)
6551             HDexit(EXIT_FAILURE);
6552         if(H5Sget_simple_extent_dims(child_sid, tdims, NULL) < 0)
6553             HDexit(EXIT_FAILURE);
6554 
6555         if(tdims[0] != 2)
6556             HDexit(EXIT_FAILURE);
6557 
6558         /* Read from the dataset */
6559         if(H5Dread(child_did2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, rbuf) < 0)
6560             HDexit(EXIT_FAILURE);
6561 
6562         /* Verify the data is correct */
6563         if(rbuf[0] != 100 || rbuf[1] != 100)
6564             HDexit(EXIT_FAILURE);
6565 
6566         /* Close the 2 datasets */
6567         if(H5Dclose(child_did1) < 0)
6568             HDexit(EXIT_FAILURE);
6569         if(H5Dclose(child_did2) < 0)
6570             HDexit(EXIT_FAILURE);
6571 
6572         /* Close the 2 files */
6573         if(H5Fclose(child_fid1) < 0)
6574             HDexit(EXIT_FAILURE);
6575         if(H5Fclose(child_fid2) < 0)
6576             HDexit(EXIT_FAILURE);
6577 
6578         /* Close the pipes */
6579         if(HDclose(out_pdf[0]) < 0)
6580             HDexit(EXIT_FAILURE);
6581         if(HDclose(in_pdf[1]) < 0)
6582             HDexit(EXIT_FAILURE);
6583 
6584         HDexit(EXIT_SUCCESS);
6585     }
6586 
6587     /* Close unused read end for out_pdf */
6588     if(HDclose(out_pdf[0]) < 0)
6589         FAIL_STACK_ERROR
6590     /* Close unused write end for in_pdf */
6591     if(HDclose(in_pdf[1]) < 0)
6592         FAIL_STACK_ERROR
6593 
6594     /* Open the test file */
6595     if((fid = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl)) < 0)
6596         FAIL_STACK_ERROR
6597 
6598     /* Open the dataset */
6599     if((did = H5Dopen2(fid, "dataset", H5P_DEFAULT)) < 0)
6600         FAIL_STACK_ERROR;
6601 
6602     /* Write to the dataset */
6603     wbuf[0] = wbuf[1] = 99;
6604     if(H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf) < 0)
6605         FAIL_STACK_ERROR;
6606 
6607     /* Flush to disk */
6608     if(H5Fflush(fid, H5F_SCOPE_LOCAL) < 0)
6609         FAIL_STACK_ERROR;
6610 
6611     /* Notify child process */
6612     notify = 1;
6613     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
6614         FAIL_STACK_ERROR;
6615 
6616 
6617     /* Wait for notification from child process */
6618     while(notify != 2) {
6619         if(HDread(in_pdf[0], &notify, sizeof(int)) < 0)
6620             FAIL_STACK_ERROR;
6621     }
6622 
6623     /* Cork the metadata cache, to prevent the object header from being
6624      * flushed before the data has been written */
6625     if(H5Odisable_mdc_flushes(did) < 0)
6626         FAIL_STACK_ERROR;
6627 
6628     /* Extend the dataset */
6629     if(H5Dset_extent(did, new_dims) < 0)
6630         FAIL_STACK_ERROR;
6631 
6632     /* Write to the dataset */
6633     wbuf[0] = wbuf[1] = 100;
6634     if(H5Dwrite(did, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, wbuf) < 0)
6635         FAIL_STACK_ERROR;
6636 
6637     /* Uncork the metadata cache */
6638     if(H5Oenable_mdc_flushes(did) < 0)
6639         FAIL_STACK_ERROR;
6640 
6641     /* Flush to disk */
6642     if(H5Fflush(fid, H5F_SCOPE_LOCAL) < 0)
6643         FAIL_STACK_ERROR;
6644 
6645     /* Notify child process */
6646     notify = 3;
6647     if(HDwrite(out_pdf[1], &notify, sizeof(int)) < 0)
6648         FAIL_STACK_ERROR;
6649 
6650     /* Close the pipes */
6651     if(HDclose(out_pdf[1]) < 0)
6652         FAIL_STACK_ERROR;
6653     if(HDclose(in_pdf[0]) < 0)
6654         FAIL_STACK_ERROR;
6655 
6656     /* Wait for child process to complete */
6657     if((tmppid = HDwaitpid(childpid, &child_status, child_wait_option)) < 0)
6658         FAIL_STACK_ERROR
6659 
6660     /* Check exit status of child process */
6661     if(WIFEXITED(child_status)) {
6662         if((child_exit_val = WEXITSTATUS(child_status)) != 0)
6663             TEST_ERROR
6664     } else  /* Child process terminated abnormally */
6665         TEST_ERROR
6666 
6667     /* Close the dataset */
6668     if(H5Dclose(did) < 0)
6669         FAIL_STACK_ERROR
6670 
6671     /* Close the file */
6672     if(H5Fclose(fid) < 0)
6673         FAIL_STACK_ERROR
6674 
6675     /* Close the property list */
6676     if(H5Pclose(fapl) < 0)
6677         FAIL_STACK_ERROR
6678 
6679     PASSED();
6680     return 0;
6681 
6682 error:
6683     H5E_BEGIN_TRY {
6684         H5Dclose(did);
6685         H5Sclose(sid);
6686         H5Pclose(dcpl);
6687         H5Pclose(fapl);
6688         H5Fclose(fid);
6689     } H5E_END_TRY;
6690 
6691     return -1;
6692 
6693 } /* test_refresh_concur() */
6694 #endif /* !(defined(H5_HAVE_FORK) && defined(H5_HAVE_WAITPID)) */
6695 
6696 /*
6697  * test_multiple_same():
6698  *
6699  * The "new_format" parameter indicates whether to create the file with latest format or not.
6700  *  To have SWMR support, can use either one of the following in creating a file:
6701  *  (a) Create the file with write + latest format:
6702  *      --result in v3 superblock with latest chunk indexing types
6703  *  (b) Create the file with SWMR write + non-latest-format:
6704  *      --result in v3 superblock with latest chunk indexing types
6705  *
6706  * Verify that H5Drefresh() and H5Fstart_swmr_write() work properly with multiple
6707  * opens of files and datasets.
6708  */
6709 static int
test_multiple_same(hid_t in_fapl,hbool_t new_format)6710 test_multiple_same(hid_t in_fapl, hbool_t new_format)
6711 {
6712     hid_t fid = -1, fid1 = -1, fid2 = -1, fid3 = -1;              /* File IDs */
6713     hid_t fapl;             /* File access property list */
6714     char filename[NAME_BUF_SIZE];   /* File name */
6715     hid_t did = -1, did1 = -1, did2 = -1, did3 = -1;
6716     hid_t sid = -1;
6717     hid_t dcpl = -1;
6718     hsize_t chunk_dims[2] = {1, 2};
6719     hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED};
6720     hsize_t dims[2] = {1, 1};
6721     int rbuf = 0;
6722     int wbuf = 0;
6723 
6724     /* Output message about test being performed */
6725     if(new_format) {
6726         TESTING("multiple--single process access for latest format");
6727     } else {
6728         TESTING("multiple--single process access for non-latest-format");
6729     } /* end if */
6730 
6731 
6732     if((fapl = H5Pcopy(in_fapl)) < 0)
6733         FAIL_STACK_ERROR
6734 
6735     /* Set the filename to use for this test (dependent on fapl) */
6736     h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));
6737 
6738     if(new_format) {
6739         /* Set to use the latest library format */
6740         if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
6741             FAIL_STACK_ERROR
6742 
6743         /* Create the test file */
6744         if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
6745             FAIL_STACK_ERROR
6746     } else {
6747         /* Create the test file without latest format but with SWMR write */
6748         if((fid = H5Fcreate(filename, H5F_ACC_TRUNC|H5F_ACC_SWMR_WRITE, H5P_DEFAULT, fapl)) < 0)
6749             FAIL_STACK_ERROR
6750     } /* end if */
6751 
6752     /* Create a chunked dataset with 1 extendible dimension */
6753     if((sid = H5Screate_simple(2, dims, maxdims)) < 0)
6754         FAIL_STACK_ERROR;
6755     if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
6756         FAIL_STACK_ERROR
6757     if(H5Pset_chunk(dcpl, 2, chunk_dims) < 0)
6758         FAIL_STACK_ERROR;
6759     if((did = H5Dcreate2(fid, "dataset", H5T_NATIVE_INT, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
6760         FAIL_STACK_ERROR;
6761 
6762     /* Closing */
6763     if(H5Dclose(did) < 0)
6764         FAIL_STACK_ERROR
6765     if(H5Sclose(sid) < 0)
6766         FAIL_STACK_ERROR
6767     if(H5Pclose(dcpl) < 0)
6768         FAIL_STACK_ERROR
6769 
6770     /* Close the file */
6771     if(H5Fclose(fid) < 0)
6772         FAIL_STACK_ERROR
6773 
6774     /* Case 1 */
6775 
6776     /* Open the file 3 times: SWMR-write, read-write, read-only */
6777     if((fid1 = H5Fopen(filename, H5F_ACC_RDWR|H5F_ACC_SWMR_WRITE, fapl)) < 0)
6778         FAIL_STACK_ERROR
6779     if((fid2 = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
6780         FAIL_STACK_ERROR
6781     if((fid3 = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
6782         FAIL_STACK_ERROR
6783 
6784     /* Open the dataset 3 times with fid1, fid2, fid3 */
6785     if((did1 = H5Dopen2(fid1, "dataset", H5P_DEFAULT)) < 0)
6786         FAIL_STACK_ERROR
6787     if((did2 = H5Dopen2(fid2, "dataset", H5P_DEFAULT)) < 0)
6788         FAIL_STACK_ERROR
6789     if((did3 = H5Dopen2(fid3, "dataset", H5P_DEFAULT)) < 0)
6790         FAIL_STACK_ERROR
6791 
6792 
6793     /* Write to the dataset via did1 */
6794     wbuf = 88;
6795     if(H5Dwrite(did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wbuf) < 0)
6796         FAIL_STACK_ERROR;
6797 
6798     /* Refresh via did2 */
6799     if(H5Drefresh(did2) < 0)
6800         FAIL_STACK_ERROR;
6801 
6802     /* Read from the dataset via did2 */
6803     rbuf = 0;
6804     if(H5Dread(did2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rbuf) < 0)
6805         FAIL_STACK_ERROR;
6806     /* Verify the data is correct */
6807     if(rbuf != 88)
6808         FAIL_STACK_ERROR;
6809 
6810     /* Write to the dataset via did3 */
6811     wbuf = 99;
6812     if(H5Dwrite(did3, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wbuf) < 0)
6813         FAIL_STACK_ERROR;
6814 
6815     /* Refresh via did1 */
6816     if(H5Drefresh(did1) < 0)
6817         FAIL_STACK_ERROR;
6818 
6819     /* Read from the dataset via did1 */
6820     rbuf = 0;
6821     if(H5Dread(did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rbuf) < 0)
6822         FAIL_STACK_ERROR;
6823     /* Verify the data is correct */
6824     if(rbuf != 99)
6825         FAIL_STACK_ERROR;
6826 
6827     /* Close datasets */
6828     if(H5Dclose(did1) < 0)
6829         FAIL_STACK_ERROR;
6830     if(H5Dclose(did2) < 0)
6831         FAIL_STACK_ERROR;
6832     if(H5Dclose(did3) < 0)
6833         FAIL_STACK_ERROR;
6834 
6835     /* Close files */
6836     if(H5Fclose(fid1) < 0)
6837         FAIL_STACK_ERROR
6838     if(H5Fclose(fid2) < 0)
6839         FAIL_STACK_ERROR
6840     if(H5Fclose(fid3) < 0)
6841         FAIL_STACK_ERROR
6842 
6843     /* Case 2 */
6844 
6845     /* Open the file 3 times: read-write, read-only, read-write */
6846     if((fid1 = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
6847         FAIL_STACK_ERROR
6848     if((fid2 = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
6849         FAIL_STACK_ERROR
6850     if((fid3 = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
6851         FAIL_STACK_ERROR
6852 
6853     /* Open the dataset 3 times with fid1, fid2, fid3 */
6854     if((did1 = H5Dopen2(fid1, "dataset", H5P_DEFAULT)) < 0)
6855         FAIL_STACK_ERROR
6856     if((did2 = H5Dopen2(fid2, "dataset", H5P_DEFAULT)) < 0)
6857         FAIL_STACK_ERROR
6858     if((did3 = H5Dopen2(fid3, "dataset", H5P_DEFAULT)) < 0)
6859         FAIL_STACK_ERROR
6860 
6861     /* Write to the dataset via did1 */
6862     wbuf = 88;
6863     if(H5Dwrite(did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wbuf) < 0)
6864         FAIL_STACK_ERROR;
6865 
6866     /* Refresh via did2 */
6867     if(H5Drefresh(did2) < 0)
6868         FAIL_STACK_ERROR;
6869 
6870     /* Read from dataset via did2 */
6871     rbuf = 0;
6872     if(H5Dread(did2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rbuf) < 0)
6873         FAIL_STACK_ERROR;
6874     if(rbuf != wbuf)
6875         FAIL_STACK_ERROR;
6876 
6877     /* Write to dataset via did3 */
6878     wbuf = 99;
6879     if(H5Dwrite(did3, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wbuf) < 0)
6880         FAIL_STACK_ERROR;
6881 
6882     /* Enable SWMR write */
6883     if(H5Fstart_swmr_write(fid1) < 0)
6884         FAIL_STACK_ERROR;
6885 
6886     /* Read from dataset via did1 and verify data is correct */
6887     rbuf = 0;
6888     if(H5Dread(did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rbuf) < 0)
6889         FAIL_STACK_ERROR;
6890     if(rbuf != wbuf)
6891         FAIL_STACK_ERROR;
6892 
6893     /* Write to dataset via did2 */
6894     wbuf = 100;
6895     if(H5Dwrite(did2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wbuf) < 0)
6896         FAIL_STACK_ERROR;
6897 
6898     /* Refresh dataset via did3 */
6899     if(H5Drefresh(did3) < 0)
6900         FAIL_STACK_ERROR;
6901 
6902     /* Read from dataset via did3 and verify data is correct */
6903     rbuf = 0;
6904     if(H5Dread(did3, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rbuf) < 0)
6905         FAIL_STACK_ERROR;
6906     if(rbuf != wbuf)
6907         FAIL_STACK_ERROR;
6908 
6909     /* Close datasets */
6910     if(H5Dclose(did1) < 0)
6911         FAIL_STACK_ERROR;
6912     if(H5Dclose(did2) < 0)
6913         FAIL_STACK_ERROR;
6914     if(H5Dclose(did3) < 0)
6915         FAIL_STACK_ERROR;
6916 
6917     /* Close files */
6918     if(H5Fclose(fid1) < 0)
6919         FAIL_STACK_ERROR
6920     if(H5Fclose(fid2) < 0)
6921         FAIL_STACK_ERROR;
6922     if(H5Fclose(fid3) < 0)
6923         FAIL_STACK_ERROR
6924 
6925     /* Case 3 */
6926 
6927     /* Open the file 3 times: read-write, read-only, read-only */
6928     if((fid1 = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
6929         FAIL_STACK_ERROR
6930     if((fid2 = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
6931         FAIL_STACK_ERROR
6932     if((fid3 = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
6933         FAIL_STACK_ERROR
6934 
6935     /* Open the dataset 3 times with fid1, fid2, fid3 */
6936     if((did1 = H5Dopen2(fid1, "dataset", H5P_DEFAULT)) < 0)
6937         FAIL_STACK_ERROR
6938     if((did2 = H5Dopen2(fid2, "dataset", H5P_DEFAULT)) < 0)
6939         FAIL_STACK_ERROR
6940     if((did3 = H5Dopen2(fid3, "dataset", H5P_DEFAULT)) < 0)
6941         FAIL_STACK_ERROR
6942 
6943     /* Write to the dataset via did1 */
6944     wbuf = 88;
6945     if(H5Dwrite(did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wbuf) < 0)
6946         FAIL_STACK_ERROR;
6947 
6948     /* Refresh dataset via did2 */
6949     if(H5Drefresh(did2) < 0)
6950         FAIL_STACK_ERROR;
6951 
6952     /* Read from dataset via did2 and verify data is correct */
6953     rbuf = 0;
6954     if(H5Dread(did2, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rbuf) < 0)
6955         FAIL_STACK_ERROR;
6956     if(rbuf != wbuf)
6957         FAIL_STACK_ERROR;
6958 
6959     /* Close dataset via did2 */
6960     if(H5Dclose(did2) < 0)
6961         FAIL_STACK_ERROR;
6962 
6963     /* Close file via fid2 */
6964     if(H5Fclose(fid2) < 0)
6965         FAIL_STACK_ERROR
6966 
6967     /* Write to dataset via did3 */
6968     wbuf = 99;
6969     if(H5Dwrite(did3, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wbuf) < 0)
6970         FAIL_STACK_ERROR;
6971 
6972     /* Close dataset via did3 */
6973     if(H5Dclose(did3) < 0)
6974         FAIL_STACK_ERROR;
6975 
6976     /* Close file via fid3 */
6977     if(H5Fclose(fid3) < 0)
6978         FAIL_STACK_ERROR
6979 
6980     /* Enable SWMR writing */
6981     if(H5Fstart_swmr_write(fid1) < 0)
6982         FAIL_STACK_ERROR;
6983 
6984     /* Read from dataset via did1 and verify data is correct */
6985     rbuf = 0;
6986     if(H5Dread(did1, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rbuf) < 0)
6987         FAIL_STACK_ERROR;
6988     if(rbuf != wbuf)
6989         FAIL_STACK_ERROR;
6990 
6991     /* Close dataset via did1 */
6992     if(H5Dclose(did1) < 0)
6993         FAIL_STACK_ERROR;
6994 
6995     /* Close file via fid1 */
6996     if(H5Fclose(fid1) < 0)
6997         FAIL_STACK_ERROR
6998 
6999     /* Close the property list */
7000     if(H5Pclose(fapl) < 0)
7001         FAIL_STACK_ERROR
7002 
7003     PASSED();
7004     return 0;
7005 
7006 error:
7007     H5E_BEGIN_TRY {
7008         H5Dclose(did);
7009         H5Dclose(did1);
7010         H5Dclose(did2);
7011         H5Dclose(did3);
7012         H5Sclose(sid);
7013         H5Pclose(dcpl);
7014         H5Pclose(fapl);
7015         H5Fclose(fid);
7016         H5Fclose(fid1);
7017         H5Fclose(fid2);
7018         H5Fclose(fid3);
7019     } H5E_END_TRY;
7020 
7021     return -1;
7022 
7023 } /* test_multiple_same() */
7024 
7025 /****************************************************************
7026 **
7027 **  Tests for new public routines introduced from the SWMR project.
7028 **
7029 ****************************************************************/
7030 int
main(void)7031 main(void)
7032 {
7033     int nerrors = 0;    /* The # of errors */
7034     hid_t fapl = -1;    /* File access property list ID */
7035     char *driver = NULL;    /* VFD string (from env variable) */
7036     char *lock_env_var = NULL; /* file locking env var pointer */
7037     hbool_t use_file_locking;   /* read from env var */
7038 
7039     /* Skip this test if SWMR I/O is not supported for the VFD specified
7040      * by the environment variable.
7041      */
7042     driver = HDgetenv("HDF5_DRIVER");
7043     if(!H5FD_supports_swmr_test(driver)) {
7044         HDprintf("This VFD does not support SWMR I/O\n");
7045         return EXIT_SUCCESS;
7046     } /* end if */
7047 
7048     /* Check the environment variable that determines if we care
7049      * about file locking. File locking should be used unless explicitly
7050      * disabled.
7051      */
7052     lock_env_var = HDgetenv("HDF5_USE_FILE_LOCKING");
7053     if(lock_env_var && !HDstrcmp(lock_env_var, "FALSE"))
7054         use_file_locking = FALSE;
7055     else
7056         use_file_locking = TRUE;
7057 
7058     /* Set up */
7059     h5_reset();
7060 
7061     /* Get file access property list */
7062     fapl = h5_fileaccess();
7063 
7064 #ifdef OUT
7065     nerrors += test_bug_refresh(fapl);
7066 #endif
7067     nerrors += test_refresh_concur(fapl, TRUE);
7068     nerrors += test_refresh_concur(fapl, FALSE);
7069     nerrors += test_multiple_same(fapl, TRUE);
7070     nerrors += test_multiple_same(fapl, FALSE);
7071 
7072     /* Tests on H5Pget/set_metadata_read_attempts() and H5Fget_metadata_read_retry_info() */
7073     nerrors += test_metadata_read_attempts(fapl);
7074     nerrors += test_metadata_read_retry_info(fapl);
7075 
7076     /* Tests on H5Fstart_swmr_write() */
7077     /*
7078      * Modify the following routines to test for files:
7079      *   H5Fcreate(write, latest format) or  H5Fcreate(SWMR write, non-latest-format)
7080      *   --both result in v3 superblock and latest version suppport
7081      */
7082     nerrors += test_start_swmr_write(fapl, TRUE);
7083     nerrors += test_start_swmr_write(fapl, FALSE);
7084     nerrors += test_err_start_swmr_write(fapl, TRUE);
7085     nerrors += test_err_start_swmr_write(fapl, FALSE);
7086     nerrors += test_start_swmr_write_concur(fapl, TRUE);
7087     nerrors += test_start_swmr_write_concur(fapl, FALSE);
7088     nerrors += test_start_swmr_write_stress_ohdr(fapl);
7089 
7090     /* Tests for H5Pget/set_object_flush_cb() */
7091     nerrors += test_object_flush_cb(fapl);
7092 
7093     /* Tests on H5Pget/set_append_flush() */
7094     nerrors += test_append_flush_generic();
7095     nerrors += test_append_flush_dataset_chunked(fapl);
7096     nerrors += test_append_flush_dataset_fixed(fapl);
7097     nerrors += test_append_flush_dataset_multiple(fapl);
7098 
7099     if(use_file_locking) {
7100         /*
7101          * Tests for:
7102          *   file open flags--single process access
7103          *   file open flags--concurrent access
7104          */
7105         nerrors += test_file_lock_same(fapl);
7106         nerrors += test_file_lock_concur(fapl);
7107         /*
7108          * Tests for:
7109          *   file open flags+SWMR flags--single process access
7110          *   file open flags+SWMR flags--concurrent access
7111          *
7112          * Modify the following 2 routines to test for files:
7113          *   H5Fcreate(write, latest format) or  H5Fcreate(SWMR write, non-latest-format)
7114          *   --both result in v3 superblock and latest version suppport
7115          */
7116         nerrors += test_file_lock_swmr_same(fapl);
7117         nerrors += test_file_lock_swmr_concur(fapl);
7118     } /* end if */
7119 
7120     /* Tests SWMR VFD compatibility flag.
7121      * Only needs to run when the VFD is the default (sec2).
7122      */
7123     if(NULL == driver || !HDstrcmp(driver, "") || !HDstrcmp(driver, "sec2"))
7124         nerrors += test_swmr_vfd_flag();
7125 
7126     /* This test changes the HDF5_USE_FILE_LOCKING environment variable
7127      * so it should be run last.
7128      */
7129     nerrors += test_file_lock_env_var(fapl);
7130 
7131     if(nerrors)
7132         goto error;
7133 
7134     HDprintf("All tests passed.\n");
7135 
7136     h5_cleanup(FILENAME, fapl);
7137 
7138     return EXIT_SUCCESS;
7139 
7140 error:
7141     nerrors = MAX(1, nerrors);
7142     HDprintf("***** %d SWMR TEST%s FAILED! *****\n",
7143         nerrors, 1 == nerrors ? "" : "S");
7144     return EXIT_FAILURE;
7145 
7146 } /* end main() */
7147 
7148