summaryrefslogtreecommitdiffstats
path: root/test/vfd_swmr_indep_rw_writer.c
blob: 77eee741b9e3f4170b3d31743130351b74e21c3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by Akadio, Inc.                                                 *
 * All rights reserved.                                                      *
 *                                                                           *
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
 * terms governing use, modification, and redistribution, is contained in    *
 * the COPYING file, which can be found at the root of the source code       *
 * distribution tree, or in https://www.hdfgroup.org/licenses.               *
 * If you do not have access to either file, you may request a copy from     *
 * help@hdfgroup.org.                                                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/* This program checks independence of writer and reader for VFD SWMR.
 * A writer can also be a reader of another writer. A reader can also be a
 * writer. The program adapts from the "many small" and the "few big" tests.
 * One can test the program as follows:
 * Run ./vfd_swmr_indep_wr_p0 at one terminal
 * Run ./vfd_swmr_indep_wr_p1 at another terminal
 * You should see something like:
 * Successfully write the dataset /dataset-0 for file vfd_swmr_indep_wr_p0.h5.
 * Successfully open the dataset /dataset-1 for file vfd_swmr_indep_wr_p1.h5.
 * Successfully verify a dataset.
 * and
 * Successfully open the dataset /dataset-0 for file vfd_swmr_indep_wr_p0.h5.
 * Successfully verify a dataset.
 * Successfully write the dataset /dataset-1 for file vfd_swmr_indep_wr_p1.h5.
 */

#define H5C_FRIEND /*suppress error about including H5Cpkg   */
#define H5F_FRIEND /*suppress error about including H5Fpkg   */

#include "hdf5.h"
#include "H5Cpkg.h"
#include "H5Fpkg.h"
#include "H5HGprivate.h"
#include "H5VLprivate.h"

#include "testhdf5.h"
#include "vfd_swmr_common.h"

#ifndef H5_HAVE_WIN32_API

#define DATA_ROWS    256
#define DATA_COLS    512
#define DATA_RANK    2
#define NUM_ATTEMPTS 100

/* Structure for filling the dataset values. Adapted from vfd_swmr_bigset_writer.c. */
typedef struct _mat {
    unsigned rows, cols;
    uint32_t elt[1];
} mat_t;

/* Structure to hold the information of various parameters used in the program. */
typedef struct {
    hid_t        file[2];
    const char * filename[2];
    char         progname[PATH_MAX];
    hid_t        r_dsetid;
    hid_t        dtype, fapl, fcpl;
    unsigned int rows, cols;
    int          rank;
    hsize_t      dims[DATA_RANK];
    uint32_t     max_lag;
    uint32_t     tick_len;
    uint32_t     ps;
    uint32_t     pbs;
    uint32_t     check_interval;
    hbool_t      use_vfd_swmr;
    hbool_t      first_proc;
} state_t;

/* Assign the initialized values to struct state_t declared above */
static inline state_t
state_initializer(void)
{
    return (state_t){.file           = {H5I_INVALID_HID, H5I_INVALID_HID},
                     .filename       = {"", ""},
                     .r_dsetid       = H5I_INVALID_HID,
                     .dtype          = H5T_NATIVE_UINT32,
                     .fapl           = H5I_INVALID_HID,
                     .fcpl           = H5I_INVALID_HID,
                     .rows           = DATA_ROWS,
                     .cols           = DATA_COLS,
                     .rank           = DATA_RANK,
                     .dims           = {DATA_ROWS, DATA_COLS},
                     .max_lag        = 7,
                     .tick_len       = 4,
                     .ps             = 4096,
                     .pbs            = 4096,
                     .check_interval = 1,
                     .use_vfd_swmr   = TRUE,
                     .first_proc     = TRUE};
}

/* Obtain the data value at index [i][j] for the 2D matrix.
   All the routines related to the matrix are adapted from the vfd_swmr_bigset_writer.c. */
static uint32_t
matget(const mat_t *mat, unsigned i, unsigned j)
{
    return mat->elt[i * mat->cols + j];
}

/* Set the data value at index [i][j] for the 2D matrix. */
static hbool_t
matset(mat_t *mat, unsigned i, unsigned j, uint32_t v)
{
    if (i >= mat->rows || j >= mat->cols) {
        HDfprintf(stderr, "index out of boundary\n");
        TEST_ERROR;
    }

    mat->elt[i * mat->cols + j] = v;

    return TRUE;

error:
    return FALSE;
}

/* Allocate memory for the 2-D matrix. */
static mat_t *
newmat(state_t s)
{
    mat_t *mat;

    mat = HDmalloc(sizeof(*mat) + (s.rows * s.cols - 1) * sizeof(mat->elt[0]));
    if (mat == NULL) {
        HDfprintf(stderr, "HDmalloc failed\n");
        TEST_ERROR;
    }

    mat->rows = s.rows;
    mat->cols = s.cols;

    return mat;

error:
    return NULL;
}

/* Write or verify the dataset test pattern in the matrix `mat`.
 * If `do_set` is TRUE, write the pattern; otherwise, verify.
 *
 * The basic test pattern consists of increasing
 * integers written in nested corners of the dataset
 * starting at element (0, 0):
 *
 *  0
 *
 *  0  1
 *  3  2
 *
 *  0  1  4
 *  3  2  5
 *  8  7  6
 *
 *  0  1  4  9
 *  3  2  5 10
 *  8  7  6 11
 * 15 14 13 12
 *
 * In an actual pattern, the dataset number, `which`, is added to each integer.
 *
 */
static hbool_t
set_or_verify_matrix(mat_t *mat, unsigned int which, hbool_t do_set)
{
    unsigned row, col;
    hbool_t  ret = TRUE;

    for (row = 0; row < mat->rows; row++) {
        for (col = 0; col < mat->cols; col++) {
            uint32_t v;
            hsize_t  i = row, j = col, u;
            if (j <= i)
                u = (i + 1) * (i + 1) - 1 - j;
            else
                u = j * j + i;

            v = (uint32_t)(u + which);

            if (do_set) {
                if (!matset(mat, row, col, v)) {
                    HDfprintf(stderr, "data initialization failed\n");
                    ret = FALSE;
                    break;
                }
            }
            else if (matget(mat, row, col) != v) {
                /* If the data doesn't match, return FALSE
                 */
                dbgf(1, "vrfy_matrix failed at row %u,col %u\n", row, col);
                dbgf(1, "real value is %u\n", matget(mat, row, col));
                dbgf(1, "expected value is %u\n", v);
                ret = FALSE;
                break;
            }
        }
    }

    return ret;
}

/* Initialize the matrix values. The parameter 'which' determines the data value. */
static hbool_t
init_matrix(mat_t *mat, unsigned int which)
{
    return set_or_verify_matrix(mat, which, TRUE);
}

/* Verify the matrix values at each point. The parameter 'which" determines the data value. */
static hbool_t
verify_matrix(mat_t *mat, unsigned int which)
{
    return set_or_verify_matrix(mat, which, FALSE);
}

/* Usage of this program when running with the -h option */
static void
usage(const char *progname)
{
    HDfprintf(stderr,
              "usage: %s [-S] [-c cols] [-r rows] [-t tick_len] [-m max_lag] \n"
              "    [-B page_buffer_size] [-s page_size] [-u reader wait interval] [-q silent output] \n"
              "\n"
              "-S:	               do not use VFD SWMR\n"
              "-c cols:	       `cols` columns for the dataset\n"
              "                      The default value is 512.\n"
              "-r rows:	       `rows` rows for the dataset\n"
              "                      The default value is 256.\n"
              "-t tick_len:    length of a tick in tenths of a second.\n"
              "-m max_lag:     maximum expected lag(in ticks) between writer and readers\n"
              "-B pbs:         page buffer size in bytes:\n"
              "                The default value is 4K(4096).\n"
              "-s ps:          page size used by page aggregation, page buffer and \n"
              "                the metadata file. The default value is 4K(4096).\n"
              "-u 0.1s:        interval in tenth of seconds to check if a dataset is ready for the reader.\n"
              "-q:             silence printouts, few messages\n"
              "\n",
              progname);
    HDexit(EXIT_FAILURE);
}

/* Initialize the state_t with different options specified by the user. */
static hbool_t
state_init(state_t *s, int argc, char **argv)
{
    unsigned long          tmp;
    int                    opt;
    char *                 tfile = NULL;
    char *                 end;
    const char *           personality;
    const char *           s_opts   = "Sqc:r:t:m:B:s:u:";
    struct h5_long_options l_opts[] = {{NULL, 0, '\0'}};

    *s = state_initializer();

    if (H5_basename(argv[0], &tfile) < 0) {
        HDprintf("H5_basename failed\n");
        TEST_ERROR;
    }

    esnprintf(s->progname, sizeof(s->progname), "%s", tfile);

    if (tfile) {
        HDfree(tfile);
        tfile = NULL;
    }

    while ((opt = H5_get_option(argc, (const char *const *)argv, s_opts, l_opts)) != EOF) {
        switch (opt) {
            case 'S':
                s->use_vfd_swmr = FALSE;
                break;
            case 'c':
            case 'r':
            case 't':
            case 'm':
            case 'B':
            case 's':
            case 'u':
                errno = 0;
                tmp   = HDstrtoul(H5_optarg, &end, 0);
                if (end == H5_optarg || *end != '\0') {
                    HDfprintf(stderr, "couldn't parse -%c argument %s\n", opt, H5_optarg);
                    TEST_ERROR;
                }
                else if (errno != 0) {
                    HDfprintf(stderr, "couldn't parse -%c argument %s\n", opt, H5_optarg);
                    TEST_ERROR;
                }
                else if (tmp > UINT_MAX) {
                    HDfprintf(stderr, "-%c argument %lu too large", opt, tmp);
                    TEST_ERROR;
                }
                if ((opt == 'c' || opt == 'r') && tmp == 0) {
                    HDfprintf(stderr, "-%c argument %lu must be >= 1", opt, tmp);
                    TEST_ERROR;
                }

                if (opt == 'c')
                    s->cols = (unsigned)tmp;
                else if (opt == 'r')
                    s->rows = (unsigned)tmp;
                else if (opt == 't')
                    s->tick_len = (unsigned)tmp;
                else if (opt == 'm')
                    s->max_lag = (unsigned)tmp;
                else if (opt == 'B')
                    s->pbs = (unsigned)tmp;
                else if (opt == 's')
                    s->ps = (unsigned)tmp;
                else if (opt == 'u')
                    s->check_interval = (unsigned)tmp;
                break;
            case 'q':
                verbosity = 0;
                break;
            case '?':
            default:
                usage(s->progname);
                break;
        }
    }
    argc -= H5_optind;
    argv += H5_optind;

    if (argc > 0) {
        HDprintf("unexpected command-line arguments\n");
        TEST_ERROR;
    }

    s->filename[0] = "vfd_swmr_indep_wr_p0.h5";
    s->filename[1] = "vfd_swmr_indep_wr_p1.h5";
    s->dims[0]     = s->rows;
    s->dims[1]     = s->cols;

    personality = HDstrstr(s->progname, "vfd_swmr_indep_wr");

    if (personality != NULL && HDstrcmp(personality, "vfd_swmr_indep_wr_p0") == 0)
        s->first_proc = TRUE;
    else if (personality != NULL && HDstrcmp(personality, "vfd_swmr_indep_wr_p1") == 0)
        s->first_proc = FALSE;
    else {
        HDprintf("unknown personality, expected vfd_swmr_indep_wr_{p0,p1}\n");
        TEST_ERROR;
    }

    return TRUE;

error:
    if (tfile)
        HDfree(tfile);
    return FALSE;
}

/* Initialize the configuration and the file creation and access property lists
 *  for the VFD SMWR independence of the reader/writer test.
 */
static hbool_t
indep_init_vfd_swmr_config_plist(state_t *s, hbool_t writer, const char *mdf_name)
{

    H5F_vfd_swmr_config_t config;

    /* config, tick_len, max_lag, presume_posix_semantics, writer,
     * maintain_metadata_file, generate_updater_files, flush_raw_data, md_pages_reserved,
     * md_file_path, md_file_name, updater_file_path */
    init_vfd_swmr_config(&config, s->tick_len, s->max_lag, FALSE, writer, TRUE, FALSE, TRUE, 128, "./",
                         mdf_name, NULL);

    /* Pass the use_vfd_swmr, only_meta_page, page buffer size, config to vfd_swmr_create_fapl().*/
    if ((s->fapl = vfd_swmr_create_fapl(TRUE, s->use_vfd_swmr, TRUE, s->pbs, &config)) < 0) {
        HDprintf("vfd_swmr_create_fapl failed\n");
        TEST_ERROR;
    }

    /* Set fs_strategy (file space strategy) and fs_page_size (file space page size) */
    if ((s->fcpl = vfd_swmr_create_fcpl(H5F_FSPACE_STRATEGY_PAGE, s->ps)) < 0) {
        HDprintf("vfd_swmr_create_fcpl() failed");
        TEST_ERROR;
    }

    return TRUE;

error:
    return FALSE;
}

/* Write the matrix mat to a dataset. The dataset name depends on the process it runs. */
static hbool_t
write_dataset(const state_t *s, mat_t *mat)
{

    char         dname[sizeof("/dataset-?")];
    hid_t        dset_id   = H5I_INVALID_HID;
    hid_t        filespace = H5I_INVALID_HID;
    unsigned int which     = 0;

    if (s->first_proc)
        esnprintf(dname, sizeof(dname), "/dataset-%d", 0);
    else {
        esnprintf(dname, sizeof(dname), "/dataset-%d", 1);
        which = 1;
    }

    filespace = H5Screate_simple(s->rank, s->dims, NULL);
    if (filespace < 0) {
        HDfprintf(stderr, "H5Screate_simple failed\n");
        TEST_ERROR;
    }

    if ((dset_id = H5Dcreate2(s->file[which], dname, s->dtype, filespace, H5P_DEFAULT, H5P_DEFAULT,
                              H5P_DEFAULT)) < 0) {
        HDfprintf(stderr, "H5Dcreate2 failed\n");
        TEST_ERROR;
    }

    if (H5Sclose(filespace) < 0) {
        HDfprintf(stderr, "H5Sclose failed\n");
        TEST_ERROR;
    }

    if (!init_matrix(mat, which)) {
        HDfprintf(stderr, "data initialization failed\n");
        TEST_ERROR;
    }

    if (H5Dwrite(dset_id, H5T_NATIVE_UINT32, H5S_ALL, H5S_ALL, H5P_DEFAULT, mat->elt) < 0) {
        HDfprintf(stderr, "H5Dwrite failed\n");
        TEST_ERROR;
    }

    if (H5Dclose(dset_id) < 0) {
        HDfprintf(stderr, "H5Dclose failed\n");
        TEST_ERROR;
    }

    if (s->first_proc)
        dbgf(1, "Process 0: Successfully write the dataset %s for file %s.\n", dname, s->filename[which]);
    else
        dbgf(1, "Process 1: Successfully write the dataset %s for file %s.\n", dname, s->filename[which]);

    return TRUE;

error:
    H5E_BEGIN_TRY
    {
        H5Sclose(filespace);
        H5Dclose(dset_id);
    }
    H5E_END_TRY;

    return FALSE;
}

/* Open the dataset according to the dataset name related to the process.
   The dataset ID is saved in the state_t s */
static hbool_t
open_dset(state_t *s)
{

    char         dname[sizeof("/dataset-?")];
    hid_t        dset_id;
    unsigned int i;
    unsigned int fopen_idx = 0;

    /* The first process reads the dataset from the second process
     * The second process reads the dataset from the first process
     */
    if (s->first_proc) {
        esnprintf(dname, sizeof(dname), "/dataset-%d", 1);
        fopen_idx = 1;
    }
    else {
        esnprintf(dname, sizeof(dname), "/dataset-%d", 0);
        fopen_idx = 0;
    }

    /* Same as the big dset test, tries to open the dataset repeatedly until successful.  After trying
     * NUM_ATTEMPTS times without success, report it as a failure
     */
    for (i = 0; i < NUM_ATTEMPTS; i++) {
        H5E_BEGIN_TRY
        {
            dset_id = H5Dopen2(s->file[fopen_idx], dname, H5P_DEFAULT);
        }
        H5E_END_TRY;

        if (dset_id >= 0)
            break;
        else
            decisleep(s->check_interval);
    }

    s->r_dsetid = dset_id;
    if (i == NUM_ATTEMPTS) {
        HDfprintf(stderr, "dataset opening reaches the maximal number of attempts\n");
        TEST_ERROR;
    }

    if (s->first_proc)
        dbgf(1, "Process 0: Successfully open the dataset %s for file %s.\n", dname, s->filename[fopen_idx]);
    else
        dbgf(1, "Process 1: Successfully open the dataset %s for file %s.\n", dname, s->filename[fopen_idx]);
    return TRUE;

error:
    return FALSE;
}

/* Verify a dataset, this routine must be called after the open_dset().
 * It will use the dataset ID assigned by open_dset().
 */
static hbool_t
vrfy_dset(const state_t *s, mat_t *mat)
{

    unsigned int i;
    unsigned int which = 0;
    herr_t       status;

    /* The approach is adapted from the big set test. A failure to read the data may indicate the data isn't
     * ready yet. For this case, we will not display the error stack, instead sleeping for one tenth of a
     * second, call H5Drefresh and try to call H5Dread again. After NUM_ATTEMPTS times, issue an error.
     */

    for (i = 0; i < NUM_ATTEMPTS; i++) {
        H5E_BEGIN_TRY
        {
            status = H5Dread(s->r_dsetid, H5T_NATIVE_UINT32, H5S_ALL, H5S_ALL, H5P_DEFAULT, mat->elt);
        }
        H5E_END_TRY;
        if (status < 0) {
            decisleep(1);
            /* Refresh the dataset and try it again */
            if (H5Drefresh(s->r_dsetid) < 0) {
                HDfprintf(stderr, "H5Drefresh failed\n");
                TEST_ERROR;
            }
        }
        else
            break;
    }
    if (i == NUM_ATTEMPTS) {
        HDfprintf(stderr, "dataset verification reached the maximal number of attempts\n");
        TEST_ERROR;
    }
    if (s->first_proc)
        which = 1;

    if (verify_matrix(mat, which) == FALSE) {
        HDfprintf(stderr, "dataset verification failed\n");
        TEST_ERROR;
    }

    if (s->first_proc)
        dbgf(1, "Process 0: Successfully verify a dataset.\n");
    else
        dbgf(1, "Process 1: Successfully verify a dataset.\n");

    return TRUE;

error:
    return FALSE;
}

/* The wrapper routine of open_dset() and vrfy_dset() for readers to verify a dataset.  */
static hbool_t
read_vrfy_dataset(state_t *s, mat_t *mat)
{

    if (FALSE == open_dset(s)) {
        HDfprintf(stderr, "Reader: open_dataset() failed\n");
        TEST_ERROR;
    }
    if (FALSE == vrfy_dset(s, mat)) {
        HDfprintf(stderr, "Reader: vrfy_dataset() failed\n");
        TEST_ERROR;
    }

    if (H5Dclose(s->r_dsetid) < 0) {
        HDfprintf(stderr, "Reader: H5Dclose() failed\n");
        TEST_ERROR;
    }
    return TRUE;

error:

    H5E_BEGIN_TRY
    {
        H5Dclose(s->r_dsetid);
    }
    H5E_END_TRY;
    return FALSE;
}

/* Close the file access and creation property lists. */
static hbool_t
close_pl(const state_t *s)
{

    if (H5Pclose(s->fapl) < 0) {
        HDprintf("H5Pclose failed\n");
        TEST_ERROR;
    }

    if (H5Pclose(s->fcpl) < 0) {
        HDprintf("H5Pclose failed\n");
        TEST_ERROR;
    }

    return TRUE;

error:
    H5E_BEGIN_TRY
    {
        H5Pclose(s->fapl);
        H5Pclose(s->fcpl);
    }
    H5E_END_TRY;

    return FALSE;
}

int
main(int argc, char **argv)
{
    hbool_t  writer = TRUE;
    state_t  s;
    hbool_t  ret = FALSE;
    unsigned i;
    mat_t *  mat = NULL;

    if (!state_init(&s, argc, argv)) {
        HDfprintf(stderr, "state_init failed\n");
        TEST_ERROR;
    }

    if ((mat = newmat(s)) == NULL) {
        HDfprintf(stderr, "could not allocate memory for dataset \n");
        TEST_ERROR;
    }

    /* The first process writes a dataset in the first file and then reads a dataset from the second file.*/
    if (s.first_proc) {

        writer = TRUE;
        if (FALSE == indep_init_vfd_swmr_config_plist(&s, writer, "file1-shadow")) {
            HDfprintf(stderr, "Writer: Cannot initialize file property lists for file %s\n", s.filename[0]);
            TEST_ERROR;
        }
        s.file[0] = H5Fcreate(s.filename[0], H5F_ACC_TRUNC, s.fcpl, s.fapl);
        if (s.file[0] < 0) {
            HDfprintf(stderr, "H5Fcreate failed for the file %s\n", s.filename[0]);
            TEST_ERROR;
        }

        ret = write_dataset(&s, mat);
        if (ret == FALSE) {
            HDfprintf(stderr, "write_dataset failed for the file %s\n", s.filename[0]);
            TEST_ERROR;
        }

        /* writer makes repeated HDF5 API calls
         * to trigger EOT at approximately the correct time */
        for (i = 0; i < s.max_lag + 1; i++) {
            decisleep(s.tick_len);
            H5E_BEGIN_TRY
            {
                H5Aexists(s.file[0], "nonexistent");
            }
            H5E_END_TRY;
        }

        if (FALSE == close_pl(&s)) {
            HDfprintf(stderr, "Fail to close file property lists for writing the file %s.\n", s.filename[0]);
            TEST_ERROR;
        }

        writer = FALSE;
        if (FALSE == indep_init_vfd_swmr_config_plist(&s, writer, "file2-shadow")) {
            HDfprintf(stderr, "Reader: Cannot initialize file property lists for file %s\n", s.filename[1]);
            TEST_ERROR;
        }
        s.file[1] = H5Fopen(s.filename[1], H5F_ACC_RDONLY, s.fapl);
        if (s.file[1] < 0) {
            HDfprintf(stderr, "H5Fopen failed for the file %s\n", s.filename[1]);
            TEST_ERROR;
        }

        ret = read_vrfy_dataset(&s, mat);
        if (ret == FALSE) {
            HDfprintf(stderr, "read and verify dataset failed for file %s\n", s.filename[1]);
            TEST_ERROR;
        }

        if (FALSE == close_pl(&s)) {
            HDfprintf(stderr, "Fail to close file property lists for reading the file %s.\n", s.filename[1]);
            TEST_ERROR;
        }

        if (H5Fclose(s.file[0]) < 0) {
            HDfprintf(stderr, "fail to close HDF5 file %s \n", s.filename[0]);
            TEST_ERROR;
        }

        if (H5Fclose(s.file[1]) < 0) {
            HDfprintf(stderr, "fail to close HDF5 file %s \n", s.filename[1]);
            TEST_ERROR;
        }
    }
    else {

        /* The second process reads the dataset of the first file generated by the first process,
         * then writes a dataset in the second file for the first process to read.
         */
        writer = FALSE;
        if (FALSE == indep_init_vfd_swmr_config_plist(&s, writer, "file1-shadow")) {
            HDfprintf(stderr, "Reader: Cannot initialize file property lists for file %s\n", s.filename[0]);
            TEST_ERROR;
        }

        s.file[0] = H5Fopen(s.filename[0], H5F_ACC_RDONLY, s.fapl);
        if (s.file[0] < 0) {
            HDfprintf(stderr, "H5Fopen failed for the file %s\n", s.filename[0]);
            TEST_ERROR;
        }
        ret = read_vrfy_dataset(&s, mat);
        if (ret == FALSE) {
            HDfprintf(stderr, "read and verify dataset failed for file %s\n", s.filename[0]);
            TEST_ERROR;
        }

        if (FALSE == close_pl(&s)) {
            HDfprintf(stderr, "Fail to close file property lists for reading the file %s.\n", s.filename[0]);
            TEST_ERROR;
        }

        writer = TRUE;
        if (FALSE == indep_init_vfd_swmr_config_plist(&s, writer, "file2-shadow")) {
            HDfprintf(stderr, "writer: Cannot initialize file property lists for file %s\n", s.filename[1]);
            TEST_ERROR;
        }

        s.file[1] = H5Fcreate(s.filename[1], H5F_ACC_TRUNC, s.fcpl, s.fapl);
        if (s.file[1] < 0) {
            HDfprintf(stderr, "H5Fcreate failed for the file %s\n", s.filename[1]);
            TEST_ERROR;
        }
        ret = write_dataset(&s, mat);
        if (ret == FALSE) {
            HDfprintf(stderr, "write_dataset failed for the file %s\n", s.filename[1]);
            TEST_ERROR;
        }

        /* writer makes repeated HDF5 API calls
         * to trigger EOT at approximately the correct time */
        for (i = 0; i < s.max_lag + 1; i++) {
            decisleep(s.tick_len);
            H5E_BEGIN_TRY
            {
                H5Aexists(s.file[1], "nonexistent");
            }
            H5E_END_TRY;
        }

        if (FALSE == close_pl(&s)) {
            HDfprintf(stderr, "Fail to close file property lists for writing the file %s.\n", s.filename[1]);
            TEST_ERROR;
        }

        if (H5Fclose(s.file[0]) < 0) {
            HDfprintf(stderr, "fail to close HDF5 file %s \n", s.filename[0]);
            TEST_ERROR;
        }

        if (H5Fclose(s.file[1]) < 0) {
            HDfprintf(stderr, "fail to close HDF5 file %s \n", s.filename[1]);
            TEST_ERROR;
        }
    }

    if (mat)
        HDfree(mat);

    return EXIT_SUCCESS;

error:
    H5E_BEGIN_TRY
    {
        H5Pclose(s.fapl);
        H5Pclose(s.fcpl);
        H5Fclose(s.file[0]);
        H5Fclose(s.file[1]);
    }
    H5E_END_TRY;

    if (mat)
        HDfree(mat);

    return EXIT_FAILURE;
}

#else /* H5_HAVE_WIN32_API */

int
main(void)
{
    HDfprintf(stderr, "Non-POSIX platform. Skipping.\n");
    return EXIT_SUCCESS;
}

#endif /* H5_HAVE_WIN32_API */