summaryrefslogtreecommitdiffstats
path: root/test/vfd_swmr_attrdset_writer.c
blob: 85ceb01e8c773cd7a8934a2467d4dddbf5255e08 (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
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * 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.                                                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*
 *  Purpose: To test attribute handling for different dataset types.
 *      Dataset types:
 *      --dataset with compact layout
 *      --dataset with contiguous layout
 *      --dataset with chunked layout:
 *              1. single indexing type
 *              2. implicit indexing type
 *              3. fixed array indexing type
 *              4. extensible array indexing type
 *              5. version btree 2 indexing type
 *      Attribute handling:
 *      -- Add attribute
 *      -- Delete attribute
 *      -- Modify attribute
 *      -- Add variable length attribute
 *      -- Delete variable length attribute
 *      -- Modify variable length attribute
 *      -- Add sufficient attributes to force creation of object header continuation block
 *      -- Remove sufficient attributes to allow deletion of object header continuation block
 *      -- Transition from compact to dense attribute storage
 *      -- Transition from dense to compact attribute storage
 *
 * Please see verify_storage_cont() on verification of
 * compact<->dense storage and with/without continuation block.
 *
 */

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

#ifndef H5_HAVE_WIN32_API

#define READER_WAIT_TICKS 4

/* Structure to hold info for options specified */
typedef struct {
    hid_t        file;               /* File ID */
    hid_t        filetype;           /* ID for default datatype */
    hid_t        one_by_one_sid;     /* ID for default dataspace */
    char         filename[PATH_MAX]; /* File name */
    char         progname[PATH_MAX]; /* Program name */
    unsigned int update_interval;    /* For -u option */
    unsigned int asteps;             /* For -a <nattrs> option */
    unsigned int csteps;             /* For -c <csteps> option */
    unsigned int dattrs;             /* For -d <dattrs> option */
    hbool_t      compact;            /* For -p option */
    hbool_t      contig;             /* For -g option */
    hbool_t      chunked;            /* For -k option */
    hbool_t      vl_attr;            /* For -v option */
    hbool_t      mod_attr;           /* For -m option */
    hbool_t      use_np;             /* For -N option */
    hbool_t      use_vfd_swmr;       /* For -S option */
} state_t;

/* Initializations for state_t */
#define ALL_HID_INITIALIZER                                                                                  \
    (state_t)                                                                                                \
    {                                                                                                        \
        .file = H5I_INVALID_HID, .one_by_one_sid = H5I_INVALID_HID, .filename = "",                          \
        .filetype = H5T_NATIVE_UINT32, .asteps = 0, .csteps = 1, .dattrs = 0, .use_np = TRUE,                \
        .use_vfd_swmr = TRUE, .compact = FALSE, .contig = FALSE, .chunked = FALSE, .vl_attr = FALSE,         \
        .mod_attr = FALSE, .update_interval = READER_WAIT_TICKS                                              \
    }

/* Structure to hold info for different dataset types */
typedef struct {
    hid_t    compact_did;          /* ID for compact dataset */
    hid_t    contig_did;           /* ID for contiguous dataset */
    hid_t    single_did;           /* ID for chunked dataset: single index */
    hid_t    implicit_did;         /* ID for chunked dataset: implicit index */
    hid_t    fa_did;               /* ID for chunked dataset: fixed array index  */
    hid_t    ea_did;               /* ID for chunked dataset: extensible array index */
    hid_t    bt2_did;              /* ID for chunked dataset: version 2 btree index */
    unsigned p_max_compact;        /* Value of max_compact storage for -p */
    unsigned g_max_compact;        /* Value of max_compact storage for -g */
    unsigned single_max_compact;   /* Value of max_compact storage for -k: single index */
    unsigned implicit_max_compact; /* Value of max_compact storage for -k: implicit index */
    unsigned fa_max_compact;       /* Value of max_compact storage for -k: fixed array index */
    unsigned ea_max_compact;       /* Value of max_compact storage for -k: extensible array index */
    unsigned bt2_max_compact;      /* Value of max_compact storage for -k: version 2 btree index */
    unsigned p_min_dense;          /* Value of min_dense storage for -p */
    unsigned g_min_dense;          /* Value of min_dense storage for -g */
    unsigned single_min_dense;     /* Value of min_dense storage for -k: single index */
    unsigned implicit_min_dense;   /* Value of min_dense storage for -k: implicit index */
    unsigned fa_min_dense;         /* Value of min_dense storage for -k: fixed array index */
    unsigned ea_min_dense;         /* Value of min_dense storage for -k: extensible array index */
    unsigned bt2_min_dense;        /* Value of min_dense storage for -k: version 2 btree index */
} dsets_state_t;

/* Initializations for dsets_state_t */
#define DSETS_INITIALIZER                                                                                    \
    (dsets_state_t)                                                                                          \
    {                                                                                                        \
        .compact_did = H5I_INVALID_HID, .contig_did = H5I_INVALID_HID, .single_did = H5I_INVALID_HID,        \
        .implicit_did = H5I_INVALID_HID, .fa_did = H5I_INVALID_HID, .ea_did = H5I_INVALID_HID,               \
        .bt2_did = H5I_INVALID_HID, .p_max_compact = 0, .g_max_compact = 0, .single_max_compact = 0,         \
        .implicit_max_compact = 0, .fa_max_compact = 0, .ea_max_compact = 0, .bt2_max_compact = 0            \
    }

/* Structure to hold info for named pipes */
typedef struct {
    const char *fifo_writer_to_reader; /* Name of fifo for writer to reader */
    const char *fifo_reader_to_writer; /* Name of fifo for reader to writer */
    int         fd_writer_to_reader;   /* File ID for fifo from writer to reader */
    int         fd_reader_to_writer;   /* File ID for fifo from reader to writer */
    int         notify;                /* Value to notify between writer and reader */
    int         verify;                /* Value to verify between writer and reader */
} np_state_t;

/* Initializations for np_state_t */
#define NP_INITIALIZER                                                                                       \
    (np_state_t)                                                                                             \
    {                                                                                                        \
        .fifo_writer_to_reader = "./fifo_attrdset_writer_to_reader",                                         \
        .fifo_reader_to_writer = "./fifo_attrdset_reader_to_writer", .fd_writer_to_reader = -1,              \
        .fd_reader_to_writer = -1, .notify = 0, .verify = 0                                                  \
    }

static hbool_t state_init(state_t *s, int argc, const char *const *argv);

static hbool_t np_init(np_state_t *np, hbool_t writer);
static hbool_t np_close(np_state_t *np, hbool_t writer);
static hbool_t np_writer(hbool_t result, unsigned step, const state_t *s, np_state_t *np,
                         H5F_vfd_swmr_config_t *config);
static hbool_t np_reader(hbool_t result, unsigned step, const state_t *s, np_state_t *np);
static hbool_t np_confirm_verify_notify(int fd, unsigned step, const state_t *s, np_state_t *np);
static hbool_t np_reader_no_verification(const state_t *s, np_state_t *np, H5F_vfd_swmr_config_t *config);

static hbool_t create_dsets(const state_t *s, dsets_state_t *ds);
static hbool_t open_dsets(const state_t *s, dsets_state_t *ds);
static hbool_t open_dset_real(hid_t fid, hid_t *did, const char *name, unsigned *max_compact,
                              unsigned *min_dense);
static hbool_t close_dsets(const dsets_state_t *ds);

static hbool_t perform_dsets_operations(state_t *s, dsets_state_t *ds, H5F_vfd_swmr_config_t *config,
                                        np_state_t *np);
static hbool_t attr_dsets_action(unsigned action, const state_t *s, const dsets_state_t *ds, unsigned which);
static hbool_t attr_action(unsigned action, const state_t *s, hid_t did, unsigned which);
static hbool_t add_attr(const state_t *s, hid_t did, unsigned int which);
static hbool_t modify_attr(const state_t *s, hid_t did, unsigned int which);
static hbool_t delete_attr(hid_t did, unsigned int which);

static hbool_t verify_dsets_operations(state_t *s, dsets_state_t *ds, H5F_vfd_swmr_config_t *config,
                                       np_state_t *np);
static hbool_t verify_attr_dsets_action(unsigned action, const state_t *s, const dsets_state_t *ds,
                                        unsigned which);
static hbool_t verify_attr_action(unsigned action, hid_t did, unsigned which);
static hbool_t verify_add_or_modify_attr(unsigned action, hid_t did, char *attr_name, unsigned int which);
static hbool_t verify_delete_attr(hid_t did, char *attr_name);
static hbool_t verify_storage_cont(unsigned action, hid_t did, unsigned int which, unsigned max_compact,
                                   unsigned min_dense, unsigned asteps);
static hbool_t verify_storage_cont_real(hid_t did, unsigned int which, unsigned cut_point);

/* Names for datasets */
#define DSET_COMPACT_NAME  "compact_dset"
#define DSET_CONTIG_NAME   "contig_dset"
#define DSET_SINGLE_NAME   "chunked_single"
#define DSET_IMPLICIT_NAME "chunked_implicit"
#define DSET_FA_NAME       "chunked_fa"
#define DSET_EA_NAME       "chunked_ea"
#define DSET_BT2_NAME      "chunked_bt2"

/* Action for attribute handling */
#define ADD_ATTR    1
#define MODIFY_ATTR 2
#define DELETE_ATTR 3

/* Test program usage info */
static void
usage(const char *progname)
{
    HDfprintf(stderr,
              "usage: %s -a nattrs [-p] [-g] [-k] [-v] [-m]\n"
              "    [-d dattrs] [-u nticks] [-c csteps] [-S] [-N]\n"
              "\n"
              "-p:	           create a dataset with compact layout\n"
              "-g:	           create a dataset with contiguous layout\n"
              "-k:	           create datasets with chunked layout for the 5 indexing types\n"
              "-m:	           modify attributes to all datasets after addition\n"
              "-v:	           add variable length attribute to datasets\n"
              "                   (default is H5T_NATIVE_UINT32)\n"
              "-a nattrs:	   add `nattrs` attributes to all datasets\n"
              "-d dattrs:	   delete `dattrs` attributes to all datasets after addition\n"
              "-u nticks:         `nticks` ticks for the reader to wait before verification\n"
              "                   (default is 4)\n"
              "-c csteps:         `csteps` steps communication interval between reader and writer\n"
              "                   (default is 1)\n"
              "-S:	           do not use VFD SWMR\n"
              "-N:	           do not use named pipes for test synchronization\n"
              "-b:	           write data in big-endian byte order if no -v option\n"
              "                   (default is H5T_NATIVE_UINT32)\n\n"
              "Note:\n"
              "1. Require to specify at least -p, -g or -k option\n"
              "2. -c <csteps> option cannot exceed -a <nattrs> option\n"
              "3. -d <dattrs> option cannot exceed -a <nattrs> option\n"
              "\n",
              progname);
    HDexit(EXIT_FAILURE);
} /* usage() */

/*
 * Initialize option info in state_t
 */
static hbool_t
state_init(state_t *s, int argc, const char *const *argv)
{
    unsigned long          tmp;
    int                    opt;
    const hsize_t          dims  = 1;
    char *                 tfile = NULL;
    char *                 end;
    const char *           s_opts   = "pgkvmbqSNa:d:u:c:";
    struct h5_long_options l_opts[] = {{NULL, 0, '\0'}};

    *s = ALL_HID_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, argv, s_opts, l_opts)) != EOF) {
        switch (opt) {

            case 'p':
                s->compact = TRUE;
                break;

            case 'g':
                s->contig = TRUE;
                break;

            case 'k':
                s->chunked = TRUE;
                break;

            case 'v':
                s->vl_attr = TRUE;
                break;

            case 'm':
                s->mod_attr = TRUE;
                break;
            case 'b':
                s->filetype = H5T_STD_U32BE;
                break;
            case 'q':
                verbosity = 0;
                break;
            case 'S':
                s->use_vfd_swmr = FALSE;
                break;
            case 'N':
                s->use_np = FALSE;
                break;
            case 'a':
            case 'd':
            case 'u':
            case 'c':
                errno = 0;
                tmp   = HDstrtoul(H5_optarg, &end, 0);
                if (end == H5_optarg || *end != '\0') {
                    HDprintf("couldn't parse `-%c` argument `%s`\n", opt, H5_optarg);
                    TEST_ERROR;
                }
                else if (errno != 0) {
                    HDprintf("couldn't parse `-%c` argument `%s`\n", opt, H5_optarg);
                    TEST_ERROR;
                }
                else if (tmp > UINT_MAX) {
                    HDprintf("`-%c` argument `%lu` too large\n", opt, tmp);
                    TEST_ERROR;
                }

                if (opt == 'a')
                    s->asteps = (unsigned)tmp;
                else if (opt == 'd')
                    s->dattrs = (unsigned)tmp;
                else if (opt == 'u')
                    s->update_interval = (unsigned)tmp;
                else if (opt == 'c')
                    s->csteps = (unsigned)tmp;
                break;

            case '?':
            default:
                usage(s->progname);
                break;
        }
    }
    argc -= H5_optind;
    argv += H5_optind;

    /* Require to specify at least -p, -g or -k option */
    if (!s->compact && !s->contig && !s->chunked) {
        HDprintf("Require to specify at least -p, -g or -k option\n");
        usage(s->progname);
        goto error;
    }

    /* -c <csteps> cannot be zero */
    if (!s->csteps) {
        HDprintf("communication interval cannot be zero\n");
        TEST_ERROR;
    }

    /* -c <csteps> and -a <nattrs> options */
    if (s->asteps && s->csteps > s->asteps) {
        HDprintf("communication interval is out of bounds\n");
        TEST_ERROR;
    }

    /* -d and -a */
    if (s->dattrs > s->asteps) {
        HDprintf("# of attributes to be deleted exceeds # of attributes created\n");
        TEST_ERROR;
    }

    /* Dataspace for attributes added to datasets */
    /* Dataspace for compact and contiguous datasets */
    if ((s->one_by_one_sid = H5Screate_simple(1, &dims, &dims)) < 0) {
        HDprintf("H5Screate_simple failed\n");
        TEST_ERROR;
    }

    /* The test file name */
    esnprintf(s->filename, sizeof(s->filename), "vfd_swmr_attrdset.h5");

    return true;

error:
    if (tfile)
        HDfree(tfile);

    return false;

} /* state_init() */

/*
 *  Create the datasets as specified on the command line.
 */
static hbool_t
create_dsets(const state_t *s, dsets_state_t *ds)
{
    hid_t dcpl      = H5I_INVALID_HID;
    hid_t dtid      = H5I_INVALID_HID;
    hid_t tmp_did   = H5I_INVALID_HID;
    hid_t cmpd_tid  = H5I_INVALID_HID;
    hid_t array_tid = H5I_INVALID_HID;
    hid_t vl_tid    = H5I_INVALID_HID;
    hid_t sid       = H5I_INVALID_HID;

    *ds = DSETS_INITIALIZER;

    /* Dataset with compact layout, compound datatype */
    if (s->compact) {
        const hsize_t dims = 2;
        typedef struct {
            int a;
            int b[2];
        } cmpd;
        cmpd wdata; /* Data for compact dataset */

        wdata.a    = 1;
        wdata.b[0] = 2;
        wdata.b[1] = 3;

        if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) {
            HDprintf("H5Pcreate failed\n");
            TEST_ERROR;
        }
        if (H5Pset_layout(dcpl, H5D_COMPACT) < 0) {
            HDprintf("H5Pset_layout failed\n");
            TEST_ERROR;
        }

        /* Create compound datatype */
        if ((cmpd_tid = H5Tcreate(H5T_COMPOUND, sizeof(cmpd))) < 0) {
            HDprintf("H5Tcreate failed\n");
            TEST_ERROR;
        }

        /* Create the array for the second element in the compound type */
        if ((array_tid = H5Tarray_create2(H5T_NATIVE_INT, 1, &dims)) < 0) {
            HDprintf("H5Tarray_create2 failed\n");
            TEST_ERROR;
        }

        /* First element in the compound type */
        if (H5Tinsert(cmpd_tid, "a", HOFFSET(cmpd, a), H5T_NATIVE_INT) < 0) {
            HDprintf("H5Tinsert failed\n");
            TEST_ERROR;
        }
        /* Second element in the compound type */
        if (H5Tinsert(cmpd_tid, "b", HOFFSET(cmpd, b), array_tid) < 0) {
            HDprintf("H5Tinsert failed\n");
            TEST_ERROR;
        }

        /* Create the compact dataset with compound datatype */
        if ((ds->compact_did = H5Dcreate2(s->file, DSET_COMPACT_NAME, cmpd_tid, s->one_by_one_sid,
                                          H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) {
            HDprintf("H5Dcreate2 compact dataset failed\n");
            TEST_ERROR;
        }

        /* Write data to the dataset */
        if (H5Dwrite(ds->compact_did, cmpd_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wdata) < 0) {
            HDprintf("H5Dwrite to compact dataset failed\n");
            TEST_ERROR;
        }

        /* In order to trigger continuation block if -p is used alone by itself */
        if ((tmp_did = H5Dcreate2(s->file, "JUNK_IGNORE", cmpd_tid, s->one_by_one_sid, H5P_DEFAULT,
                                  H5P_DEFAULT, H5P_DEFAULT)) < 0) {
            HDprintf("H5Dcreate2 failed\n");
            TEST_ERROR;
        }
        if (H5Dclose(tmp_did) < 0) {
            HDprintf("H5Dclose failed\n");
            TEST_ERROR;
        }

        if (H5Pclose(dcpl) < 0) {
            HDprintf("H5Pclose failed\n");
            TEST_ERROR;
        }
    }

    /* Dataset with contiguous layout, early allocation, non-default attr phase change, named datatype */
    if (s->contig) {
        int      wdata1          = 9; /* Data for contiguous dataset */
        unsigned def_max_compact = 0;
        unsigned def_min_dense   = 0;

        if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) {
            HDprintf("H5Pcreate failed\n");
            TEST_ERROR;
        }

        if (H5Pset_layout(dcpl, H5D_CONTIGUOUS) < 0) {
            HDprintf("H5Pset_layout failed\n");
            TEST_ERROR;
        }

        if (H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_EARLY) < 0) {
            HDprintf("H5Pset_alloc_time failed\n");
            TEST_ERROR;
        }

        if (H5Pget_attr_phase_change(dcpl, &def_max_compact, &def_min_dense) < 0) {
            HDprintf("H5Pget_attr_phase_change failed\n");
            TEST_ERROR;
        }

        if (H5Pset_attr_phase_change(dcpl, def_max_compact + 2, def_min_dense + 2) < 0) {
            HDprintf("H5Pset_attr_phase_change failed\n");
            TEST_ERROR;
        }

        /* Create the named datatype */
        if ((dtid = H5Tcopy(H5T_NATIVE_INT)) < 0) {
            HDprintf("H5Tcopy failed\n");
            TEST_ERROR;
        }

        if (H5Tcommit2(s->file, "named_dtype", dtid, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT) < 0) {
            HDprintf("H5Tcommit2 failed\n");
            TEST_ERROR;
        }

        /* Create the contiguous dataset with the named datatype */
        if ((ds->contig_did = H5Dcreate2(s->file, DSET_CONTIG_NAME, dtid, s->one_by_one_sid, H5P_DEFAULT,
                                         dcpl, H5P_DEFAULT)) < 0) {
            HDprintf("H5Dcreate2 contiguous dataset failed\n");
            TEST_ERROR;
        }

        /* Write to the dataset */
        if (H5Dwrite(ds->contig_did, dtid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wdata1) < 0) {
            HDprintf("H5Dwrite to contiguous dataset failed\n");
            TEST_ERROR;
        }

        if (H5Pclose(dcpl) < 0) {
            HDprintf("H5Pclose failed\n");
            TEST_ERROR;
        }

        if (H5Tclose(dtid) < 0) {
            HDprintf("H5Tclose failed\n");
            TEST_ERROR;
        }
    }

    /* Datasets with the 5 indexes: single, implicit, fa, ea, bt2 */
    /* All with variable length datatype */
    if (s->chunked) {

        /* For index: single, implicit and fa */
        hsize_t dims1[1]       = {5};
        hsize_t max_dims1[1]   = {100};
        hsize_t chunk_dims1[1] = {2};

        /* The variable length data */
        const char *vdata[5] = {"one", "two", "three", "four", "five"};

        /* For index: ea and bt2 */
        hsize_t     dims2[2]       = {5, 5};
        hsize_t     max_dims2[2]   = {100, H5S_UNLIMITED};
        hsize_t     chunk_dims2[2] = {2, 2};
        const char *vdata2[5][5]   = {{"one", "two", "three", "four", "five"},
                                    {"two", "three", "four", "five", "six"},
                                    {"three", "four", "five", "six", "seven"},
                                    {"four", "five", "six", "seven", "eight"},
                                    {"five", "six", "seven", "eight", "nine"}};

        /* Create variable length datatype */
        if ((vl_tid = H5Tcopy(H5T_C_S1)) < 0) {
            HDprintf("H5Tcopy failed\n");
            TEST_ERROR;
        }

        if (H5Tset_size(vl_tid, H5T_VARIABLE) < 0) {
            HDprintf("H5Tset_size failed\n");
            TEST_ERROR;
        }

        if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) {
            HDprintf("H5Pcreate failed\n");
            TEST_ERROR;
        }

        if (H5Pset_layout(dcpl, H5D_CHUNKED) < 0) {
            HDprintf("H5Pset_layout failed\n");
            TEST_ERROR;
        }

        if (H5Pset_chunk(dcpl, 1, dims1) < 0) {
            HDprintf("H5Pset_chunk failed\n");
            TEST_ERROR;
        }

        /* Create 1-D chunked dataset with single index */
        /* Chunked, dims=max_dims=chunk_dims */

        if ((sid = H5Screate_simple(1, dims1, dims1)) < 0) {
            HDprintf("H5Screate_simple failed\n");
            TEST_ERROR;
        }

        if ((ds->single_did =
                 H5Dcreate2(s->file, DSET_SINGLE_NAME, vl_tid, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) {
            HDprintf("H5Dcreate2 chunked dataset: single index failed\n");
            TEST_ERROR;
        }

        if (H5Dwrite(ds->single_did, vl_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &vdata) < 0) {
            HDprintf("H5Dwrite to chunked dataset: single index failed\n");
            TEST_ERROR;
        }

        /* Create 1-D chunked dataset with implicit index */
        /* Chunked, dims=max_dims, early allocation */

        if (H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_EARLY) < 0) {
            HDprintf("H5Pset_alloc_time\n");
            TEST_ERROR;
        }

        if (H5Pset_chunk(dcpl, 1, chunk_dims1) < 0) {
            HDprintf("H5Pset_chunk failed\n");
            TEST_ERROR;
        }

        if ((ds->implicit_did =
                 H5Dcreate2(s->file, DSET_IMPLICIT_NAME, vl_tid, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0) {
            HDprintf("H5Dcreate2 chunked dataset: implicit index failed\n");
            TEST_ERROR;
        }

        if (H5Dwrite(ds->implicit_did, vl_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &vdata) < 0) {
            HDprintf("H5Dwrite to chunked dataset: implicit index failed\n");
            TEST_ERROR;
        }

        if (H5Pclose(dcpl) < 0) {
            HDprintf("H5Pclose failed\n");
            TEST_ERROR;
        }

        if (H5Sclose(sid) < 0) {
            HDprintf("H5Sclose failed\n");
            TEST_ERROR;
        }

        /* Create 1-D chunked dataset with fixed array index */
        /* Chunked, fixed max_dims */

        if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) {
            HDprintf("H5Pcreate failed\n");
            TEST_ERROR;
        }

        if (H5Pset_chunk(dcpl, 1, chunk_dims1) < 0) {
            HDprintf("H5Pset_chunk failed\n");
            TEST_ERROR;
        }

        if ((sid = H5Screate_simple(1, dims1, max_dims1)) < 0) {
            HDprintf("H5Screate_simple failed\n");
            TEST_ERROR;
        }

        if ((ds->fa_did = H5Dcreate2(s->file, DSET_FA_NAME, vl_tid, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) <
            0) {
            HDprintf("H5Dcreaet2 chunked dataset: fa index failed\n");
            TEST_ERROR;
        }

        if (H5Dwrite(ds->fa_did, vl_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &vdata) < 0) {
            HDprintf("H5Dwrite to chunked dataset: fa index failed\n");
            TEST_ERROR;
        }

        if (H5Pclose(dcpl) < 0) {
            HDprintf("H5Pclose failed\n");
            TEST_ERROR;
        }

        if (H5Sclose(sid) < 0) {
            HDprintf("H5Sclose failed\n");
            TEST_ERROR;
        }

        /* Create 2-D chunked dataset with extensible array index */
        /* Chunked, 1 unlimited max_dims */

        if ((sid = H5Screate_simple(2, dims2, max_dims2)) < 0) {
            HDprintf("H5Screate_simple failed\n");
            TEST_ERROR;
        }

        if ((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0) {
            HDprintf("H5Pcreate failed\n");
            TEST_ERROR;
        }

        if (H5Pset_chunk(dcpl, 2, chunk_dims2) < 0) {
            HDprintf("H5Pset_chunk failed\n");
            TEST_ERROR;
        }

        if ((ds->ea_did = H5Dcreate2(s->file, DSET_EA_NAME, vl_tid, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) <
            0) {
            HDprintf("H5Dcreate2 chunked dataset: ea index failed\n");
            TEST_ERROR;
        }

        if (H5Dwrite(ds->ea_did, vl_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &vdata2) < 0) {
            HDprintf("H5Dwrite to chunked dataset: ea index failed\n");
            TEST_ERROR;
        }

        /* Create 2-D chunked dataset with bt2 index */
        /* Chunked, 2 unlimited max_dims */
        max_dims2[0] = H5S_UNLIMITED;

        if ((sid = H5Screate_simple(2, dims2, max_dims2)) < 0) {
            HDprintf("H5Screate_simple failed\n");
            TEST_ERROR;
        }

        if ((ds->bt2_did = H5Dcreate2(s->file, DSET_BT2_NAME, vl_tid, sid, H5P_DEFAULT, dcpl, H5P_DEFAULT)) <
            0) {
            HDprintf("H5Dcreate2 chunked dataset: bt2 index failed\n");
            TEST_ERROR;
        }

        if (H5Dwrite(ds->bt2_did, vl_tid, H5S_ALL, H5S_ALL, H5P_DEFAULT, &vdata2) < 0) {
            HDprintf("H5Dwrite to chunked dataset: bt2 index failed\n");
            TEST_ERROR;
        }

        if (H5Pclose(dcpl) < 0) {
            HDprintf("H5Pclose failed\n");
            TEST_ERROR;
        }

        if (H5Sclose(sid) < 0) {
            HDprintf("H5Sclose failed\n");
            TEST_ERROR;
        }

        if (H5Tclose(vl_tid) < 0) {
            HDprintf("H5Tclose failed\n");
            TEST_ERROR;
        }
    }

    return true;

error:
    H5E_BEGIN_TRY
    {
        H5Pclose(dcpl);
        H5Tclose(cmpd_tid);
        H5Tclose(array_tid);
        H5Tclose(dtid);
        H5Tclose(vl_tid);
        H5Sclose(sid);
        H5Dclose(ds->compact_did);
        H5Dclose(tmp_did);
        H5Dclose(ds->contig_did);
        H5Dclose(ds->single_did);
        H5Dclose(ds->implicit_did);
        H5Dclose(ds->fa_did);
        H5Dclose(ds->ea_did);
        H5Dclose(ds->bt2_did);
    }
    H5E_END_TRY;

    return false;

} /* create_dsets() */

/*
 * Open the datasets as specified.
 */
static hbool_t
open_dsets(const state_t *s, dsets_state_t *ds)
{
    *ds = DSETS_INITIALIZER;

    if (s->compact) {
        if (!open_dset_real(s->file, &ds->compact_did, DSET_COMPACT_NAME, &ds->p_max_compact,
                            &ds->p_min_dense)) {
            HDprintf("open_dset_real() for compact dataset failed\n");
            TEST_ERROR;
        }
    }

    if (s->contig) {
        if (!open_dset_real(s->file, &ds->contig_did, DSET_CONTIG_NAME, &ds->g_max_compact,
                            &ds->g_min_dense)) {
            HDprintf("open_dset_real() for contiguous dataset failed\n");
            TEST_ERROR;
        }
    }

    if (s->chunked) {
        if (!open_dset_real(s->file, &ds->single_did, DSET_SINGLE_NAME, &ds->single_max_compact,
                            &ds->single_min_dense)) {
            HDprintf("open_dset_real() for chunked dataset: single failed\n");
            TEST_ERROR;
        }

        if (!open_dset_real(s->file, &ds->implicit_did, DSET_IMPLICIT_NAME, &ds->implicit_max_compact,
                            &ds->implicit_min_dense)) {
            HDprintf("open_dset_real() for chunked dataset: implicit failed\n");
            TEST_ERROR;
        }

        if (!open_dset_real(s->file, &ds->fa_did, DSET_FA_NAME, &ds->fa_max_compact, &ds->fa_min_dense)) {
            HDprintf("open_dset_real() for chunked dataset: fa failed\n");
            TEST_ERROR;
        }
        if (!open_dset_real(s->file, &ds->ea_did, DSET_FA_NAME, &ds->ea_max_compact, &ds->ea_min_dense)) {
            HDprintf("open_dset_real() for chunked dataset: ea failed\n");
            TEST_ERROR;
        }
        if (!open_dset_real(s->file, &ds->bt2_did, DSET_BT2_NAME, &ds->bt2_max_compact, &ds->bt2_min_dense)) {
            HDprintf("open_dset_real() for chunked dataset: bt2 failed\n");
            TEST_ERROR;
        }
    }

    return true;

error:
    return false;

} /* open_dsets() */

/*
 * Do the real work of opening the dataset.
 * Retrieve the max_compact and min_dense values for the dataset.
 */
static hbool_t
open_dset_real(hid_t fid, hid_t *did, const char *name, unsigned *max_compact, unsigned *min_dense)
{
    hid_t dcpl = H5I_INVALID_HID;

    if ((*did = H5Dopen2(fid, name, H5P_DEFAULT)) < 0) {
        HDprintf("H5Dopen dataset failed\n");
        TEST_ERROR;
    }

    if ((dcpl = H5Dget_create_plist(*did)) < 0) {
        HDprintf("H5Dget_create_plist failed\n");
        TEST_ERROR;
    }

    if (H5Pget_attr_phase_change(dcpl, max_compact, min_dense) < 0) {
        HDprintf("H5Dget_attr_phase_change failed\n");
        TEST_ERROR;
    }

    if (H5Pclose(dcpl) < 0) {
        HDprintf("H5Pclose failed\n");
        TEST_ERROR;
    }

    return true;

error:
    H5E_BEGIN_TRY
    {
        H5Dclose(*did);
        H5Pclose(dcpl);
    }
    H5E_END_TRY;

    return false;
} /* open_dset_real() */

/*
 * Close all the datasets as specified.
 */
static hbool_t
close_dsets(const dsets_state_t *ds)
{
    if (ds->compact_did != H5I_INVALID_HID && H5Dclose(ds->compact_did) < 0) {
        HDprintf("H5Dclose compact dataset failed\n");
        TEST_ERROR;
    }

    if (ds->contig_did != H5I_INVALID_HID && H5Dclose(ds->contig_did) < 0) {
        HDprintf("H5Dclose contig dataset failed\n");
        TEST_ERROR;
    }

    if (ds->single_did != H5I_INVALID_HID && H5Dclose(ds->single_did) < 0) {
        HDprintf("H5Dclose chunked dataset: single index failed\n");
        TEST_ERROR;
    }

    if (ds->implicit_did != H5I_INVALID_HID && H5Dclose(ds->implicit_did) < 0) {
        HDprintf("H5Dclose chunked dataset: implicit index failed\n");
        TEST_ERROR;
    }

    if (ds->fa_did >= 0 && H5Dclose(ds->fa_did) < 0) {
        HDprintf("H5Dclose chunked dataset: fa index failed\n");
        TEST_ERROR;
    }

    if (ds->ea_did >= 0 && H5Dclose(ds->ea_did) < 0) {
        HDprintf("H5Dclose chunked dataset: ea index failed\n");
        TEST_ERROR;
    }

    if (ds->bt2_did >= 0 && H5Dclose(ds->bt2_did) < 0) {
        HDprintf("H5Dclose chunked dataset: bt2 index failed\n");
        TEST_ERROR;
    }

    return true;

error:
    H5E_BEGIN_TRY
    {
        H5Dclose(ds->compact_did);
        H5Dclose(ds->contig_did);
        H5Dclose(ds->single_did);
        H5Dclose(ds->implicit_did);
        H5Dclose(ds->fa_did);
        H5Dclose(ds->ea_did);
        H5Dclose(ds->bt2_did);
    }
    H5E_END_TRY;

    return false;
} /* close_dsets() */

/*
 *  Writer
 */

/*
 * Perform the attribute operations specified on the command line.
 *      ADD_ATTR    : -a <nattrs> option
 *      MODIFY_ATTR : -m option
 *      DELETE_ATTR : -d <dattrs> option
 */
static hbool_t
perform_dsets_operations(state_t *s, dsets_state_t *ds, H5F_vfd_swmr_config_t *config, np_state_t *np)
{
    unsigned step;
    hbool_t  result;
    unsigned dd;

    for (step = 0; step < s->asteps; step++) {
        dbgf(2, "Adding attribute %d\n", step);

        result = attr_dsets_action(ADD_ATTR, s, ds, step);

        if (s->use_np && !np_writer(result, step, s, np, config)) {
            HDprintf("np_writer() for addition failed\n");
            TEST_ERROR;
        }
    }

    if (s->mod_attr) {

        /* Need to sync up writer/reader before moving onto the next phase */
        if (s->use_np && !np_writer(TRUE, 0, s, np, config)) {
            HDprintf("np_writer() for modification failed\n");
            TEST_ERROR;
        }

        /* Start modification */
        for (step = 0; step < s->asteps; step++) {
            dbgf(2, "Modifying attribute %d\n", step);

            result = attr_dsets_action(MODIFY_ATTR, s, ds, step);

            if (s->use_np && !np_writer(result, step, s, np, config)) {
                HDprintf("np_writer() for modification failed\n");
                TEST_ERROR;
            }
        }
    }

    if (s->dattrs) {

        /* Need to sync up writer/reader before moving onto the next phase */
        if (s->use_np && !np_writer(TRUE, 0, s, np, config)) {
            HDprintf("np_writer() for deletion failed\n");
            TEST_ERROR;
        }

        /* Start deletion */
        for (dd = 0, step = s->asteps - 1; dd < s->dattrs; dd++, --step) {
            dbgf(2, "Deleting attribute %d\n", step);

            result = attr_dsets_action(DELETE_ATTR, s, ds, step);

            if (s->use_np && !np_writer(result, step, s, np, config)) {
                HDprintf("np_writer() for deletion failed\n");
                TEST_ERROR;
            }
        }
    }

    return true;

error:
    return false;

} /* perform_dsets_operations() */

/*
 * Perform the "action" for each of the datasets specified on the command line.
 *      -p: compact dataset
 *      -g: contiguous dataset
 *      -k: 5 chunked datasets with 5 indexing types
 */
static hbool_t
attr_dsets_action(unsigned action, const state_t *s, const dsets_state_t *ds, unsigned which)
{
    int     nerrors = 0;
    hbool_t ret     = TRUE;

    if (s->compact) {
        HDassert(ds->compact_did != H5I_INVALID_HID);
        dbgf(2, "to compact dataset\n");
        if (!attr_action(action, s, ds->compact_did, which))
            ++nerrors;
    }

    if (s->contig) {
        HDassert(ds->contig_did != H5I_INVALID_HID);
        dbgf(2, "to contiguous dataset\n");
        if (!attr_action(action, s, ds->contig_did, which))
            ++nerrors;
    }

    if (s->chunked) {
        HDassert(ds->single_did != H5I_INVALID_HID);
        dbgf(2, "to chunked dataset: single index\n");
        if (!attr_action(action, s, ds->single_did, which))
            ++nerrors;

        HDassert(ds->implicit_did != H5I_INVALID_HID);
        dbgf(2, "to chunked dataset: implicit index\n");
        if (!attr_action(action, s, ds->implicit_did, which))
            ++nerrors;

        HDassert(ds->fa_did != H5I_INVALID_HID);
        dbgf(2, "to chunked dataset: fixed array index\n");
        if (!attr_action(action, s, ds->fa_did, which))
            ++nerrors;

        HDassert(ds->ea_did != H5I_INVALID_HID);
        dbgf(2, "to chunked dataset: extensible array index\n");
        if (!attr_action(action, s, ds->ea_did, which))
            ++nerrors;

        HDassert(ds->bt2_did != H5I_INVALID_HID);
        dbgf(2, "to chunked dataset: version 2 btree index\n");
        if (!attr_action(action, s, ds->bt2_did, which))
            ++nerrors;
    }

    if (nerrors)
        ret = false;

    return (ret);

} /* attr_dsets_action() */

/*
 * Perform the action on the specified dataset.
 *      ADD_ATTR    : add `which` attribute
 *      MODIFY_ATTR : modify `which` attribute
 *      DELETE_ATTR : delete `which` attribute
 */
static hbool_t
attr_action(unsigned action, const state_t *s, hid_t did, unsigned which)
{
    hbool_t ret;

    switch (action) {
        case ADD_ATTR:
            ret = add_attr(s, did, which);
            break;

        case MODIFY_ATTR:
            ret = modify_attr(s, did, which);
            break;

        case DELETE_ATTR:
            ret = delete_attr(did, which);
            break;

        default:
            HDassert(0 && "Unknown action?!?");
    } /* end switch */

    return ret;

} /* attr_action() */

/*
 * Add an attribute to the specified dataset.
 * The datatype can be:
 *      variable length (-v) or
 *      H5T_NATIVE_UINT32 (-b) or
 *      H5T_NATIVE_UINT32 (default)
 */
static hbool_t
add_attr(const state_t *s, hid_t did, unsigned int which)
{
    hid_t aid    = H5I_INVALID_HID;
    hid_t tid    = H5I_INVALID_HID;
    hid_t vl_tid = H5I_INVALID_HID;
    char  name[sizeof("attr-9999999999")];
    char *val = NULL;

    esnprintf(name, sizeof(name), "attr-%u", which);

    if (s->vl_attr) {
        if ((vl_tid = H5Tcopy(H5T_C_S1)) < 0) {
            HDprintf("H5Tcopy failed\n");
            TEST_ERROR;
        }

        if (H5Tset_size(vl_tid, H5T_VARIABLE) < 0) {
            HDprintf("H5Tset_size failed\n");
            TEST_ERROR;
        }

        if ((val = HDmalloc(sizeof("9999999999"))) == NULL) {
            HDprintf("H5Dmalloc failed\n");
            TEST_ERROR;
        }

        HDsprintf(val, "%u", which);

        tid = vl_tid;
    }
    else
        tid = s->filetype;

    /* Attach the attribute to the dataset */
    if ((aid = H5Acreate2(did, name, tid, s->one_by_one_sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
        HDprintf("H5Acreate2 failed\n");
        TEST_ERROR;
    }

    /* Write to the attribute */
    if (H5Awrite(aid, tid, s->vl_attr ? &val : (const void *)&which) < 0) {
        HDprintf("H5Awrite failed\n");
        TEST_ERROR;
    }

    /* Close the attribute */
    if (H5Aclose(aid) < 0) {
        HDprintf("H5Aclose failed\n");
        TEST_ERROR;
    }

    if (vl_tid >= 0 && H5Tclose(vl_tid) < 0) {
        HDprintf("H5Tclose failed\n");
        TEST_ERROR;
    }

    if (val)
        HDfree(val);

    return true;

error:
    H5E_BEGIN_TRY
    {
        H5Tclose(vl_tid);
        H5Aclose(aid);
    }
    H5E_END_TRY;

    if (val)
        HDfree(val);

    return false;

} /* add_attr() */

/*
 * Modify the attribute data.
 */
static hbool_t
modify_attr(const state_t *s, hid_t did, unsigned int which)
{
    hid_t    aid    = H5I_INVALID_HID;
    hid_t    tid    = H5I_INVALID_HID;
    hid_t    vl_tid = H5I_INVALID_HID;
    char     name[sizeof("attr-9999999999")];
    char *   val     = NULL;
    unsigned tmp_val = 0;

    esnprintf(name, sizeof(name), "attr-%u", which);

    if (s->vl_attr) {
        if ((vl_tid = H5Tcopy(H5T_C_S1)) < 0) {
            HDprintf("H5Tcopy failed\n");
            TEST_ERROR;
        }

        if (H5Tset_size(vl_tid, H5T_VARIABLE) < 0) {
            HDprintf("H5Tset_size failed\n");
            TEST_ERROR;
        }

        /* Needs to fit "%u %c", below */
        if ((val = HDmalloc(10 + 3)) == NULL) {
            HDprintf("HDmalloc failed\n");
            TEST_ERROR;
        }

        HDsprintf(val, "%u %c", which, 'M');

        tid = vl_tid;
    }
    else {
        tid     = s->filetype;
        tmp_val = which + 1;
    }

    /* Open the attribute to the dataset */
    if ((aid = H5Aopen(did, name, H5P_DEFAULT)) < 0) {
        HDprintf("H5Aopen failed\n");
        TEST_ERROR;
    }

    /* Write to the attribute */
    if (H5Awrite(aid, tid, s->vl_attr ? &val : (const void *)&tmp_val) < 0) {
        HDprintf("H5Awrite failed\n");
        TEST_ERROR;
    }

    /* Close the attribute */
    if (H5Aclose(aid) < 0) {
        HDprintf("H5Aclose failed\n");
        TEST_ERROR;
    }

    if (vl_tid >= 0 && H5Tclose(vl_tid) < 0) {
        HDprintf("H5Tclose failed\n");
        TEST_ERROR;
    }

    if (val)
        HDfree(val);

    return true;
error:
    H5E_BEGIN_TRY
    {
        H5Aclose(aid);
        H5Tclose(vl_tid);
    }
    H5E_END_TRY;

    if (val)
        HDfree(val);

    return false;
} /* modify_attr() */

/*
 * Delete the attribute
 */
static hbool_t
delete_attr(hid_t did, unsigned int which)
{
    char name[sizeof("attr-9999999999")];

    esnprintf(name, sizeof(name), "attr-%u", which);

    /* Delete the attribute to the dataset */
    if (H5Adelete(did, name) < 0) {
        HDprintf("H5Adelete failed\n");
        TEST_ERROR;
    }

    return true;

error:
    return false;

} /* delete_attr() */

/*
 * Verification by the reader
 */

/*
 * Verify the attribute operations specified on the command line:
 *      ADD_ATTR    : -a <nattrs> option
 *      MODIFY_ATTR : -m option
 *      DELETE_ATTR : -d <dattrs> option
 *
 * Also verify continuation block and compact<->dense storage if:
 *      --[-c <csteps>] is 1
 *      --not applicable for -m option
 */
static hbool_t
verify_dsets_operations(state_t *s, dsets_state_t *ds, H5F_vfd_swmr_config_t *config, np_state_t *np)
{
    unsigned step;
    hbool_t  result;
    unsigned dd;

    /* Start verifying addition */
    for (step = 0; step < s->asteps; step++) {
        dbgf(2, "Verifying...attribute %d\n", step);

        if (s->use_np && !np_confirm_verify_notify(np->fd_writer_to_reader, step, s, np)) {
            HDprintf("np_confirm_verify_notify() verify/notify not in sync failed\n");
            TEST_ERROR;
        }

        /* Wait for a few ticks for the update to happen */
        decisleep(config->tick_len * s->update_interval);

        result = verify_attr_dsets_action(ADD_ATTR, s, ds, step);

        if (s->use_np && !np_reader(result, step, s, np)) {
            HDprintf("np_reader() for verifying addition failed\n");
            TEST_ERROR;
        }
    }

    if (s->mod_attr) {
        /* Need to sync up writer/reader before moving onto the next phase */
        if (!np_reader_no_verification(s, np, config)) {
            HDprintf("np_reader_no_verification() for verifying modification failed\n");
            TEST_ERROR;
        }

        /* Start verifying modification */
        for (step = 0; step < s->asteps; step++) {
            dbgf(2, "Verifying...modify attribute %d\n", step);

            if (s->use_np && !np_confirm_verify_notify(np->fd_writer_to_reader, step, s, np)) {
                HDprintf("np_confirm_verify_notify() verify/notify not in sync failed\n");
                TEST_ERROR;
            }

            /* Wait for a few ticks for the update to happen */
            decisleep(config->tick_len * s->update_interval);

            result = verify_attr_dsets_action(MODIFY_ATTR, s, ds, step);

            if (s->use_np && !np_reader(result, step, s, np)) {
                HDprintf("np_reader() for verifying modification failed\n");
                TEST_ERROR;
            }
        }
    }

    if (s->dattrs) {

        /* Need to sync up writer/reader before moving onto the next phase */
        if (!np_reader_no_verification(s, np, config)) {
            HDprintf("np_reader_no_verification() for verifying modification failed\n");
            TEST_ERROR;
        }

        /* Start verifying deletion */
        for (dd = 0, step = s->asteps - 1; dd < s->dattrs; dd++, --step) {
            dbgf(2, "Verifying...delete attribute %d\n", step);

            if (s->use_np && !np_confirm_verify_notify(np->fd_writer_to_reader, step, s, np)) {
                HDprintf("np_confirm_verify_notify() verify/notify not in sync failed\n");
                TEST_ERROR;
            }

            /* Wait for a few ticks for the update to happen */
            decisleep(config->tick_len * s->update_interval);

            result = verify_attr_dsets_action(DELETE_ATTR, s, ds, step);

            if (s->use_np && !np_reader(result, step, s, np)) {
                HDprintf("np_reader() for verifying deletion failed\n");
                TEST_ERROR;
            }
        }
    }

    return true;

error:

    return false;
} /* verify_dsets_operations() */

/*
 * Verify the "action" for each of the datasets specified on the command line.
 *      -p: compact dataset
 *      -g: contiguous dataset
 *      -k: 5 chunked datasets with 5 indexing types
 */
static hbool_t
verify_attr_dsets_action(unsigned action, const state_t *s, const dsets_state_t *ds, unsigned which)
{
    int     nerrors = 0;
    hbool_t ret     = TRUE;

    if (s->compact) {
        HDassert(ds->compact_did != H5I_INVALID_HID);
        dbgf(2, "Verifying attribute to compact dataset\n");
        if (!verify_attr_action(action, ds->compact_did, which))
            ++nerrors;
        if (s->csteps == 1 && (action != MODIFY_ATTR)) {
            if (!verify_storage_cont(action, ds->compact_did, which, ds->p_max_compact, ds->p_min_dense,
                                     s->asteps))
                ++nerrors;
        }
    }

    if (s->contig) {
        HDassert(ds->contig_did != H5I_INVALID_HID);
        dbgf(2, "Verifying attribute to contiguous dataset\n");
        if (!verify_attr_action(action, ds->contig_did, which))
            ++nerrors;
        if (s->csteps == 1 && (action != MODIFY_ATTR)) {
            if (!verify_storage_cont(action, ds->contig_did, which, ds->g_max_compact, ds->g_min_dense,
                                     s->asteps))
                ++nerrors;
        }
    }

    if (s->chunked) {
        HDassert(ds->single_did != H5I_INVALID_HID);
        dbgf(2, "Verifying attribute to chunked dataset: single indedx\n");
        if (!verify_attr_action(action, ds->single_did, which))
            ++nerrors;
        if (s->csteps == 1 && (action != MODIFY_ATTR)) {
            if (!verify_storage_cont(action, ds->single_did, which, ds->single_max_compact,
                                     ds->single_min_dense, s->asteps))
                ++nerrors;
        }

        HDassert(ds->implicit_did != H5I_INVALID_HID);
        dbgf(2, "Verifying attribute to chunked dataset: implicit index\n");
        if (!verify_attr_action(action, ds->implicit_did, which))
            ++nerrors;
        if (s->csteps == 1 && (action != MODIFY_ATTR)) {
            if (!verify_storage_cont(action, ds->implicit_did, which, ds->implicit_max_compact,
                                     ds->implicit_min_dense, s->asteps))
                ++nerrors;
        }

        HDassert(ds->fa_did != H5I_INVALID_HID);
        dbgf(2, "Verifying attribute to chunked dataset: fa index\n");
        if (!verify_attr_action(action, ds->fa_did, which))
            ++nerrors;
        if (s->csteps == 1 && (action != MODIFY_ATTR)) {
            if (!verify_storage_cont(action, ds->fa_did, which, ds->fa_max_compact, ds->fa_min_dense,
                                     s->asteps))
                ++nerrors;
        }

        HDassert(ds->ea_did != H5I_INVALID_HID);
        dbgf(2, "Verifying attribute to chunked dataset: ea index\n");
        if (!verify_attr_action(action, ds->ea_did, which))
            ++nerrors;
        if (s->csteps == 1 && (action != MODIFY_ATTR)) {
            if (!verify_storage_cont(action, ds->ea_did, which, ds->ea_max_compact, ds->ea_min_dense,
                                     s->asteps))
                ++nerrors;
        }

        HDassert(ds->bt2_did != H5I_INVALID_HID);
        dbgf(2, "Verifying attribute to chunked dataset: bt2 index\n");
        if (!verify_attr_action(action, ds->bt2_did, which))
            ++nerrors;
        if (s->csteps == 1 && (action != MODIFY_ATTR)) {
            if (!verify_storage_cont(action, ds->bt2_did, which, ds->bt2_max_compact, ds->bt2_min_dense,
                                     s->asteps))
                ++nerrors;
        }
    }

    if (nerrors)
        ret = FALSE;

    return (ret);

} /* verify_attr_dsets_action() */

/*
 * Verify the attribute action on the specified dataset.
 */
static hbool_t
verify_attr_action(unsigned action, hid_t did, unsigned which)
{
    char    name[sizeof("attr-9999999999")];
    hbool_t ret;

    esnprintf(name, sizeof(name), "attr-%u", which);

    switch (action) {
        case ADD_ATTR:
            ret = verify_add_or_modify_attr(action, did, name, which);
            break;

        case MODIFY_ATTR:
            ret = verify_add_or_modify_attr(action, did, name, which);
            break;

        case DELETE_ATTR:
            ret = verify_delete_attr(did, name);
            break;

        default:
            HDassert(0 && "Unknown action?!?");
    } /* end switch */

    return ret;
} /* verify_attr_action() */

/*
 * Verify the attribute is added or modified
 */
static hbool_t
verify_add_or_modify_attr(unsigned action, hid_t did, char *attr_name, unsigned int which)
{
    unsigned int read_which;
    unsigned int tmp_val;
    char         tmp_vl_val[sizeof("attr-9999999999")];
    char *       read_vl_which;
    hbool_t      is_vl = FALSE;
    hid_t        aid   = H5I_INVALID_HID;
    hid_t        atid  = H5I_INVALID_HID;
    hbool_t      ret   = FALSE;

    HDassert(did != H5I_INVALID_HID);
    HDassert(action == ADD_ATTR || action == MODIFY_ATTR);

    if ((aid = H5Aopen(did, attr_name, H5P_DEFAULT)) < 0) {
        HDprintf("H5Aopen failed\n");
        TEST_ERROR;
    }

    if ((atid = H5Aget_type(aid)) < 0) {
        HDprintf("H5Aget_type failed\n");
        TEST_ERROR;
    }

    if ((is_vl = H5Tis_variable_str(atid))) {
        if (action == ADD_ATTR)
            HDsprintf(tmp_vl_val, "%u", which);
        else
            HDsprintf(tmp_vl_val, "%u %c", which, 'M');
    }
    else {
        if (action == MODIFY_ATTR)
            tmp_val = which + 1;
        else
            tmp_val = which;
    }

    if (H5Aread(aid, atid, is_vl ? &read_vl_which : (void *)&read_which) < 0) {
        HDprintf("H5Aread failed\n");
        TEST_ERROR;
    }

    if (H5Aclose(aid) < 0) {
        HDprintf("H5Aclose failed\n");
        TEST_ERROR;
    }

    if (H5Tclose(atid) < 0) {
        HDprintf("H5Tclose failed\n");
        TEST_ERROR;
    }

    if (is_vl) {
        dbgf(2, "read_vl_which = %s, tmp_vl_val= %s\n", read_vl_which, tmp_vl_val);
        if (!HDstrcmp(read_vl_which, tmp_vl_val))
            ret = TRUE;
    }
    else {
        dbgf(2, "read_which = %u, tmp_val = %u\n", read_which, tmp_val);
        ret = (read_which == tmp_val);
    }

    if (is_vl)
        H5free_memory(read_vl_which);

    return ret;

error:
    H5E_BEGIN_TRY
    {
        H5Aclose(aid);
        H5Tclose(atid);
    }
    H5E_END_TRY;

    if (is_vl)
        H5free_memory(read_vl_which);

    return false;

} /* verify_add_or_modify_attr() */

/*
 * Verify the attribute does not exist.
 */
static hbool_t
verify_delete_attr(hid_t did, char *attr_name)
{
    int ret;

    if ((ret = H5Aexists(did, attr_name)) < 0) {
        HDprintf("H5Aexists failed\n");
        TEST_ERROR;
    }
    else if (!ret) /* attribute does not exist */
        ret = true;
    else /* attribute exist */
        ret = false;

    return ret;

error:
    return false;

} /* verify_delete_attr() */

/*
 * `which` is indexed by 0, 1, 2, 3...
 *
 * Checkpoints:
 *      --`which` is 0: no continuation block
 *
 *      For addition:
 *      For deletion but [-a <nattrs>] is not yet to dense storage:
 *          --`which` is at (max_compact - 1): compact storage, continuation block exists
 *          --`which` is at max_compact: dense storage, no continuation block
 *      For deletion:
 *          --`which` is at min_dense: dense storage, no continuation block
 *          --`which` is at (min_dense - 1): compact storage, continuation block exists
 */
static hbool_t
verify_storage_cont(unsigned action, hid_t did, unsigned int which, unsigned max_compact, unsigned min_dense,
                    unsigned asteps)
{
    hbool_t ret = true;

    HDassert(action == ADD_ATTR || action == DELETE_ATTR);

    /* Verify no cont */
    if (!which)
        ret = verify_storage_cont_real(did, which, max_compact);

    /* For addition: */
    /* For deletion, if [-a <nattrs>] is not yet to dense storage */
    else if (action == ADD_ATTR || (action == DELETE_ATTR && asteps <= max_compact)) {

        /* Verify compact storage & cont */
        if (which == (max_compact - 1))
            ret = verify_storage_cont_real(did, which, max_compact);

        /* Verify dense storage & no cont */
        else if (which == max_compact)
            ret = verify_storage_cont_real(did, which, max_compact);
    }
    /* For deletion */
    else if (action == DELETE_ATTR) {

        /* Verify compact storage & cont */
        if (which == (min_dense - 1))
            ret = verify_storage_cont_real(did, which, min_dense);

        /* Verify dense storage & no cont */
        else if (which == min_dense)
            ret = verify_storage_cont_real(did, which, min_dense);
    }

    return ret;

} /* verify_storage_cont() */

/*
 * Verify the storage condition at the specific checkpoint
 */
static hbool_t
verify_storage_cont_real(hid_t did, unsigned int which, unsigned cut_point)
{
    H5O_native_info_t ninfo;

    /* Get the object information */
    if (H5Oget_native_info(did, &ninfo, H5O_NATIVE_INFO_HDR | H5O_NATIVE_INFO_META_SIZE) < 0) {
        HDprintf("H5Oget_native_info failed\n");
        TEST_ERROR;
    }

    if (!which) {
        dbgf(2, "Verifying no cont\n");
        return (ninfo.hdr.nchunks == 1);
    }
    else if (which < cut_point) {
        dbgf(2, "Verifying storage compact & cont\n");
        return (ninfo.meta_size.attr.index_size == 0 && ninfo.meta_size.attr.heap_size == 0 &&
                ninfo.hdr.nchunks > 1);
    }
    else {
        dbgf(2, "Verifying storage dense & no cont\n");
        return (ninfo.meta_size.attr.index_size != 0 && ninfo.meta_size.attr.heap_size != 0 &&
                ninfo.hdr.nchunks == 1);
    }

error:
    return false;

} /* verify_storage_cont_real() */

/*
 * Named pipes handling
 */

/*
 * Initialize the named pipes for test synchronization.
 */
static hbool_t
np_init(np_state_t *np, hbool_t writer)
{
    *np = NP_INITIALIZER;

    /*
     * Use two named pipes(FIFO) to coordinate the writer and reader for
     * two-way communication so that the two sides can move forward together.
     * One is for the writer to write to the reader.
     * The other one is for the reader to signal the writer.
     */
    if (writer) {
        /* If the named pipes are present at the start of the test, remove them */
        if (HDaccess(np->fifo_writer_to_reader, F_OK) == 0)
            if (HDremove(np->fifo_writer_to_reader) != 0) {
                HDprintf("HDremove fifo_writer_to_reader failed\n");
                TEST_ERROR;
            }

        if (HDaccess(np->fifo_reader_to_writer, F_OK) == 0)
            if (HDremove(np->fifo_reader_to_writer) != 0) {
                HDprintf("HDremove fifo_reader_to_writer failed\n");
                TEST_ERROR;
            }

        /* Writer creates two named pipes(FIFO) */
        if (HDmkfifo(np->fifo_writer_to_reader, 0600) < 0) {
            HDprintf("HDmkfifo fifo_writer_to_reader failed\n");
            TEST_ERROR;
        }

        if (HDmkfifo(np->fifo_reader_to_writer, 0600) < 0) {
            HDprintf("HDmkfifo fifo_reader_to_writer failed\n");
            TEST_ERROR;
        }
    }

    /* Both the writer and reader open the pipes */
    if ((np->fd_writer_to_reader = HDopen(np->fifo_writer_to_reader, O_RDWR)) < 0) {
        HDprintf("HDopen fifo_writer_to_reader failed\n");
        TEST_ERROR;
    }

    if ((np->fd_reader_to_writer = HDopen(np->fifo_reader_to_writer, O_RDWR)) < 0) {
        HDprintf("HDopen fifo_reader_to_writer failed\n");
        TEST_ERROR;
    }

    return true;

error:
    return false;

} /* np_init() */

/*
 * Close the named pipes.
 */
static hbool_t
np_close(np_state_t *np, hbool_t writer)
{
    /* Both the writer and reader close the named pipes */
    if (HDclose(np->fd_writer_to_reader) < 0) {
        HDprintf("HDclose fd_writer_to_reader failed\n");
        TEST_ERROR;
    }

    if (HDclose(np->fd_reader_to_writer) < 0) {
        HDprintf("HDclose fd_reader_to_writer failed\n");
        TEST_ERROR;
    }

    /* Reader finishes last and deletes the named pipes */
    if (!writer) {
        if (HDremove(np->fifo_writer_to_reader) != 0) {
            HDprintf("HDremove fifo_writer_to_reader failed\n");
            TEST_ERROR;
        }

        if (HDremove(np->fifo_reader_to_writer) != 0) {
            HDprintf("HDremove fifo_reader_to_writer failed\n");
            TEST_ERROR;
        }
    }
    return true;

error:
    return false;
} /* np_close() */

/*
 *  Writer synchronization depending on the result from the attribute action performed.
 */
static hbool_t
np_writer(hbool_t result, unsigned step, const state_t *s, np_state_t *np, H5F_vfd_swmr_config_t *config)
{
    unsigned int i;

    /* The action fails */
    if (!result) {
        HDprintf("attribute action failed\n");
        H5_FAILED();
        AT();

        /* At communication interval, notify the reader about the failure and quit */
        if (step % s->csteps == 0) {
            np->notify = -1;
            if (HDwrite(np->fd_writer_to_reader, &np->notify, sizeof(int)) < 0) {
                HDprintf("HDwrite failed\n");
                TEST_ERROR;
            }
            goto error;
        }
        /* The action succeeds */
    }
    else {
        /* At communication interval, notify the reader and wait for its response */
        if (step % s->csteps == 0) {
            /* Bump up the value of notify to tell the reader to start reading */
            np->notify++;
            if (HDwrite(np->fd_writer_to_reader, &np->notify, sizeof(int)) < 0) {
                HDprintf("HDwrite failed\n");
                TEST_ERROR;
            }

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

            /* Handshake between writer and reader */
            if (!np_confirm_verify_notify(np->fd_reader_to_writer, step, s, np)) {
                HDprintf("np_confirm_verify_notify() verify/notify not in sync failed\n");
                TEST_ERROR;
            }
        }
    }
    return true;

error:
    return false;

} /* np_writer() */

/*
 *
 *  Reader synchronization depending on the result from the verification.
 */
static hbool_t
np_reader(hbool_t result, unsigned step, const state_t *s, np_state_t *np)
{
    /* The verification fails */
    if (!result) {
        HDprintf("verify action failed\n");
        H5_FAILED();
        AT();

        /* At communication interval, tell the writer about the failure and exit */
        if (step % s->csteps == 0) {
            np->notify = -1;
            if (HDwrite(np->fd_reader_to_writer, &np->notify, sizeof(int)) < 0) {
                HDprintf("HDwrite failed\n");
                TEST_ERROR;
            }
            goto error;
        }
        /* The verification succeeds */
    }
    else {
        if (step % s->csteps == 0) {
            /* Send back the same notify value for acknowledgement:
             *   --inform the writer to move to the next step */
            if (HDwrite(np->fd_reader_to_writer, &np->notify, sizeof(int)) < 0) {
                HDprintf("HDwrite failed\n");
                TEST_ERROR;
            }
        }
    }
    return true;

error:
    return false;

} /* np_reader() */

/*
 *  Handshake between writer and reader:
 *      Confirm `verify` is same as `notify`.
 */
static hbool_t
np_confirm_verify_notify(int fd, unsigned step, const state_t *s, np_state_t *np)
{
    if (step % s->csteps == 0) {
        np->verify++;
        if (HDread(fd, &np->notify, sizeof(int)) < 0) {
            HDprintf("HDread failed\n");
            TEST_ERROR;
        }

        if (np->notify == -1) {
            HDprintf("reader/writer failed to verify\n");
            TEST_ERROR;
        }

        if (np->notify != np->verify) {
            HDprintf("received message %d, expecting %d\n", np->notify, np->verify);
            TEST_ERROR;
        }
    }

    return true;

error:
    return false;
} /* confirm_verify_notify() */

/*
 * Synchronization done by the reader before moving onto the
 * next verification phase.
 */
static hbool_t
np_reader_no_verification(const state_t *s, np_state_t *np, H5F_vfd_swmr_config_t *config)
{
    if (s->use_np) {
        if (!np_confirm_verify_notify(np->fd_writer_to_reader, 0, s, np)) {
            HDprintf("np_confirm_verify_notify() verify/notify not in sync failed\n");
            TEST_ERROR;
        }
    }

    /* Wait for a few ticks for the update to happen */
    decisleep(config->tick_len * s->update_interval);

    if (s->use_np) {
        /* Send back the same notify value for acknowledgement:
         *   --inform the writer to move to the next step */
        if (HDwrite(np->fd_reader_to_writer, &np->notify, sizeof(int)) < 0) {
            HDprintf("HDwrite failed\n");
            TEST_ERROR;
        }
    }

    return true;

error:
    return false;

} /* np_reader_no_verification() */

int
main(int argc, char **argv)
{
    hid_t                 fapl   = H5I_INVALID_HID;
    hid_t                 fcpl   = H5I_INVALID_HID;
    hbool_t               writer = FALSE;
    state_t               s;
    const char *          personality;
    H5F_vfd_swmr_config_t config;
    np_state_t            np;
    dsets_state_t         ds;

    if (!state_init(&s, argc, (const char *const *)argv)) {
        HDprintf("state_init() failed\n");
        TEST_ERROR;
    }

    personality = HDstrstr(s.progname, "vfd_swmr_attrdset_");

    if (personality != NULL && HDstrcmp(personality, "vfd_swmr_attrdset_writer") == 0)
        writer = TRUE;
    else if (personality != NULL && HDstrcmp(personality, "vfd_swmr_attrdset_reader") == 0)
        writer = FALSE;
    else {
        HDprintf("unknown personality, expected vfd_swmr_attrdset_{reader,writer}\n");
        TEST_ERROR;
    }

    /* 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, 4, 7, FALSE, writer, TRUE, FALSE, TRUE, 128, "./", "attrdset-shadow", NULL);

    /* use_latest_format, use_vfd_swmr, only_meta_page, page_buf_size, config */
    if ((fapl = vfd_swmr_create_fapl(TRUE, s.use_vfd_swmr, TRUE, 4096, &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 ((fcpl = vfd_swmr_create_fcpl(H5F_FSPACE_STRATEGY_PAGE, 4096)) < 0) {
        HDprintf("vfd_swmr_create_fcpl() failed");
        TEST_ERROR;
    }

    if (writer) {
        if ((s.file = H5Fcreate(s.filename, H5F_ACC_TRUNC, fcpl, fapl)) < 0) {
            HDprintf("H5Fcreate failed\n");
            TEST_ERROR;
        }

        if (!create_dsets(&s, &ds)) {
            HDprintf("create_dsets() failed\n");
            TEST_ERROR;
        }
    }
    else {
        if ((s.file = H5Fopen(s.filename, H5F_ACC_RDONLY, fapl)) < 0) {
            HDprintf("H5Fopen failed\n");
            TEST_ERROR;
        }
        if (!open_dsets(&s, &ds)) {
            HDprintf("open_dsets() failed\n");
            TEST_ERROR;
        }
    }

    /* Initiailze named pipes */
    if (s.use_np && !np_init(&np, writer)) {
        HDprintf("np_init() failed\n");
        TEST_ERROR;
    }

    if (writer) {
        if (!perform_dsets_operations(&s, &ds, &config, &np)) {
            HDprintf("perform_dsets_operations() failed\n");
            TEST_ERROR;
        }
    }
    else {
        if (!verify_dsets_operations(&s, &ds, &config, &np)) {
            HDprintf("verify_dsets_operations() failed\n");
            TEST_ERROR;
        }
    }

    if (!close_dsets(&ds)) {
        HDprintf("close_dsets() failed\n");
        TEST_ERROR;
    }

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

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

    if (H5Fclose(s.file) < 0) {
        HDprintf("H5Fclose failed\n");
        TEST_ERROR;
    }

    if (H5Sclose(s.one_by_one_sid) < 0) {
        HDprintf("H5Sclose failed\n");
        TEST_ERROR;
    }

    if (s.use_np && !np_close(&np, writer)) {
        HDprintf("np_close() failed\n");
        TEST_ERROR;
    }

    return EXIT_SUCCESS;

error:
    H5E_BEGIN_TRY
    {
        H5Pclose(fapl);
        H5Pclose(fcpl);
        H5Fclose(s.file);
        H5Sclose(s.one_by_one_sid);
    }
    H5E_END_TRY;

    if (s.use_np && np.fd_writer_to_reader >= 0)
        HDclose(np.fd_writer_to_reader);

    if (s.use_np && np.fd_reader_to_writer >= 0)
        HDclose(np.fd_reader_to_writer);

    if (s.use_np && !writer) {
        HDremove(np.fifo_writer_to_reader);
        HDremove(np.fifo_reader_to_writer);
    }

    return EXIT_FAILURE;
} /* main */

#endif /* H5_HAVE_WIN32_API */