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
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* 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. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#define H5F_FRIEND /*suppress error about including H5Fpkg */
#include "hdf5.h"
#include "H5Fpkg.h"
#include "H5HGprivate.h"
#include "H5VLprivate.h"
#include "testhdf5.h"
#include "vfd_swmr_common.h"
#ifndef H5_HAVE_WIN32_API
#define READER_WAIT_TICKS 3
#define VS_ATTR_NAME_LEN 27
typedef struct {
hid_t file, filetype, one_by_one_sid;
char filename[PATH_MAX];
char progname[PATH_MAX];
unsigned int asteps;
unsigned int csteps;
unsigned int nsteps;
unsigned int update_interval;
bool use_vfd_swmr;
bool old_style_grp;
bool use_named_pipes;
char grp_op_pattern;
bool grp_op_test;
char at_pattern;
bool attr_test;
uint32_t max_lag;
uint32_t tick_len;
int np_fd_w_to_r;
int np_fd_r_to_w;
int np_notify;
int np_verify;
} 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 = 10, .csteps = 10, .nsteps = 100, \
.update_interval = READER_WAIT_TICKS, .use_vfd_swmr = true, .old_style_grp = false, \
.use_named_pipes = true, .grp_op_pattern = ' ', .grp_op_test = false, .at_pattern = ' ', \
.attr_test = false, .tick_len = 4, .max_lag = 7, .np_fd_w_to_r = -1, .np_fd_r_to_w = -1, \
.np_notify = 0, .np_verify = 0 \
}
static void
usage(const char *progname)
{
HDfprintf(stderr,
"usage: %s [-S] [-G] [-a steps] [-b] [-c] [-n iterations]\n"
" [-N] [-q] [-u numb_ticks] [-A at_pattern] [-O grp_op_pattern]\n"
"\n"
"-S: do not use VFD SWMR\n"
"-G: old-style type of group\n"
"-a steps: `steps` between adding attributes\n"
"-b: write data in big-endian byte order\n"
"-c steps: `steps` between communication between the writer and reader\n"
"-n ngroups: the number of groups\n"
"-N: do not use named pipes, \n"
" mainly for running the writer and reader seperately\n"
"-u numb_ticks: `numb_ticks` for the reader to wait before verification\n"
"-A at_pattern: `at_pattern' for different attribute tests\n"
" The value of `at_pattern` is one of the following:\n"
" `compact` - Attributes added in compact storage\n"
" `dense` - An attribute added in dense storage\n"
" `compact-del` - Attributes added and then one\n"
" attribute deleted, in compact \n"
" `dense-del` - Attributes added until the storage\n"
" is dense then an attribute deleted\n"
" the storge still in dense\n"
" `compact-add-to-dense` - Attributes added first in compact\n"
" then in dense storage\n"
" `dense-del-to-compact` - Attributes added until the storage\n"
" is dense, then several attributes \n"
" deleted, the storage changed to\n"
" compact\n"
" `modify` - An attribute added then modified\n"
" `add-vstr` - A VL string attribute added\n"
" `remove-vstr` - A VL string attribute added then\n"
" deleted\n"
" `modify-vstr` - A VL string attribute added then \n"
" modified \n"
" `add-ohr-block` - An attribute is added and this forces\n"
" the creation of object header\n"
" continuation block \n"
" `del-ohr-block` - An attribute is added and this forces\n"
" the creation of object header\n"
" continuation block and then this \n"
" attribute is deleted so the \n"
" object header continuation block is \n"
" removed. \n"
"-O grp_op_pattern: `grp_op_pattern' for different group operation tests\n"
" The value of `grp_op_pattern` is one of the following:\n"
" `grp-creation` - A group is created.\n"
" `grp-deletion` - An existing group is deleted.\n"
" `grp-move` - A group is moved to become \n"
" another group. \n"
" `grp-ins-links` - Links are inserted, including\n"
" both hard and soft links. \n"
" `grp-del-links` - Links are deleted, including\n"
" both hard ans soft links. \n"
" `grp-compact-t-dense` - Links are inserted to the group.\n"
" The link storage of this group \n"
" changed from compact to dense. \n"
" The links include both hard and\n"
" soft links. \n"
" `grp-dense-t-compact` - Links are inserted to the group\n"
" The link storage of this group \n"
" changed from compact to dense. \n"
" Then several links are deleted.\n"
" The link storage changed from \n"
" dense to compact again. \n"
" The links include both hard and\n"
" soft links. \n"
"-q: silence printouts, few messages\n"
"\n",
progname);
HDexit(EXIT_FAILURE);
}
static bool
state_init(state_t *s, int argc, char **argv)
{
unsigned long tmp;
int ch;
const hsize_t dims = 1;
char * tfile = NULL;
char * end;
*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);
while ((ch = getopt(argc, argv, "SGa:bc:n:Nqu:A:O:")) != -1) {
switch (ch) {
case 'S':
s->use_vfd_swmr = false;
break;
case 'G':
s->old_style_grp = true;
break;
case 'a':
case 'c':
case 'n':
case 'u':
errno = 0;
tmp = HDstrtoul(optarg, &end, 0);
if (end == optarg || *end != '\0') {
HDprintf("couldn't parse `-%c` argument `%s`\n", ch, optarg);
TEST_ERROR;
}
else if (errno != 0) {
HDprintf("couldn't parse `-%c` argument `%s`\n", ch, optarg);
TEST_ERROR;
}
else if (tmp > UINT_MAX) {
HDprintf("`-%c` argument `%lu` too large\n", ch, tmp);
TEST_ERROR;
}
if (ch == 'a')
s->asteps = (unsigned)tmp;
else if (ch == 'c')
s->csteps = (unsigned)tmp;
else if (ch == 'n')
s->nsteps = (unsigned)tmp;
else if (ch == 'u')
s->update_interval = (unsigned)tmp;
break;
case 'b':
s->filetype = H5T_STD_U32BE;
break;
case 'N':
s->use_named_pipes = false;
break;
case 'O':
if (HDstrcmp(optarg, "grp-creation") == 0)
s->grp_op_pattern = 'c';
else if (HDstrcmp(optarg, "grp-deletion") == 0)
s->grp_op_pattern = 'd';
else if (HDstrcmp(optarg, "grp-move") == 0)
s->grp_op_pattern = 'm';
else if (HDstrcmp(optarg, "grp-ins-links") == 0)
s->grp_op_pattern = 'i';
else if (HDstrcmp(optarg, "grp-del-links") == 0)
s->grp_op_pattern = 'D';
else if (HDstrcmp(optarg, "grp-compact-t-dense") == 0)
s->grp_op_pattern = 't';
else if (HDstrcmp(optarg, "grp-dense-t-compact") == 0)
s->grp_op_pattern = 'T';
else {
HDprintf("Invalid -O argument \"%s\"", optarg);
TEST_ERROR;
}
break;
case 'A':
if (HDstrcmp(optarg, "compact") == 0)
s->at_pattern = 'c';
else if (HDstrcmp(optarg, "dense") == 0)
s->at_pattern = 'd';
else if (HDstrcmp(optarg, "compact-add-to-dense") == 0)
s->at_pattern = 't';
else if (HDstrcmp(optarg, "compact-del") == 0)
s->at_pattern = 'C';
else if (HDstrcmp(optarg, "dense-del") == 0)
s->at_pattern = 'D';
else if (HDstrcmp(optarg, "dense-del-to-compact") == 0)
s->at_pattern = 'T';
else if (HDstrcmp(optarg, "modify") == 0)
s->at_pattern = 'M';
else if (HDstrcmp(optarg, "add-vstr") == 0)
s->at_pattern = 'v';
else if (HDstrcmp(optarg, "remove-vstr") == 0)
s->at_pattern = 'r';
else if (HDstrcmp(optarg, "modify-vstr") == 0)
s->at_pattern = 'm';
else if (HDstrcmp(optarg, "add-ohr-block") == 0)
s->at_pattern = 'a';
else if (HDstrcmp(optarg, "del-ohr-block") == 0)
s->at_pattern = 'R';
else {
HDprintf("Invalid -A argument \"%s\"", optarg);
TEST_ERROR;
}
break;
case 'q':
verbosity = 0;
break;
case '?':
default:
usage(s->progname);
break;
}
}
argc -= optind;
argv += optind;
if (s->grp_op_pattern != ' ')
s->grp_op_test = true;
if (s->at_pattern != ' ')
s->attr_test = true;
if (!s->grp_op_test) {
if (s->asteps < 1 || s->asteps > s->nsteps) {
HDprintf("attribute interval is out of bounds\n");
TEST_ERROR;
}
}
if (s->grp_op_test && s->attr_test) {
HDprintf("Cannot test both group operation and attribute tests!\n");
HDprintf("Attribute tests are ignored.\n");
}
if (s->csteps < 1 || s->csteps > s->nsteps) {
HDprintf("communication interval is out of bounds\n");
TEST_ERROR;
}
if (argc > 0) {
HDprintf("unexpected command-line arguments\n");
TEST_ERROR;
}
/* space for attributes */
if ((s->one_by_one_sid = H5Screate_simple(1, &dims, &dims)) < 0) {
HDprintf("H5Screate_simple failed\n");
TEST_ERROR;
}
esnprintf(s->filename, sizeof(s->filename), "vfd_swmr_group.h5");
return true;
error:
if (tfile)
HDfree(tfile);
return false;
}
/* Named Pipe Subroutine: np_wr_send_receive
* Description:
* The writer sends a message to the reader,
* then waits for max_lag ticks,
* then checks the returned message from the reader.
* Return:
* True if succeed
* False if an error occurs in any step above.
* An error is mostly caused by an unexpected
* notification number from the message sent
* by the reader.
*/
static bool
np_wr_send_receive(state_t *s)
{
unsigned int i;
/* Bump up the value of notify to notice the reader to start to read */
s->np_notify++;
if (HDwrite(s->np_fd_w_to_r, &(s->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 < s->max_lag + 1; i++) {
decisleep(s->tick_len);
H5E_BEGIN_TRY
{
H5Aexists(s->file, "nonexistent");
}
H5E_END_TRY;
}
/* Receive the same value from the reader and verify it before
* going to the next step */
(s->np_verify)++;
if (HDread(s->np_fd_r_to_w, &(s->np_notify), sizeof(int)) < 0) {
HDprintf("HDread failed\n");
TEST_ERROR;
}
if (s->np_notify == -1) {
HDprintf("reader failed to verify group or attribute operation.\n");
TEST_ERROR;
}
if (s->np_notify != s->np_verify) {
HDprintf("received message %d, expecting %d\n", s->np_notify, s->np_verify);
TEST_ERROR;
}
return true;
error:
return false;
}
/* Named Pipe Subroutine: np_rd_receive
* Description:
* The reader receives a message from the writer,
* then checks if the notification number from
* the writer is expected.
* Return:
* True if succeed
* False if an error occurs in any step above.
* An error is mostly caused by an unexpected
* notification number from the message sent
* by the writer.
*/
static bool
np_rd_receive(state_t *s)
{
/* The writer should have bumped up the value of notify.
* Do the same with verify and confirm it */
s->np_verify++;
/* Receive the notify that the writer bumped up the value */
if (HDread(s->np_fd_w_to_r, &(s->np_notify), sizeof(int)) < 0) {
HDprintf("HDread failed\n");
TEST_ERROR;
}
if (s->np_notify == -1) {
HDprintf("writer failed to create group or carry out an attribute operation.\n");
TEST_ERROR;
}
if (s->np_notify != s->np_verify) {
HDprintf("received message %d, expecting %d\n", s->np_notify, s->np_verify);
TEST_ERROR;
}
return true;
error:
return false;
}
/* Named Pipe Subroutine: np_rd_send
* Description:
* The reader sends an acknowledgement to the writer
* Return:
* True if succeed
* False if an error occurs in sending the message.
*/
static bool
np_rd_send(state_t *s)
{
if (HDwrite(s->np_fd_r_to_w, &(s->np_notify), sizeof(int)) < 0) {
H5_FAILED();
AT();
HDprintf("HDwrite failed\n");
return false;
}
else
return true;
}
/* Named Pipe Subroutine: np_send_error
* Description:
* An error (notification number is 1) message is sent
* either from the reader or the writer.
* A boolean input parameter is used to choose
* either reader or writer.
* Return:
* None
*/
static void
np_send_error(state_t *s, bool writer)
{
s->np_notify = -1;
if (writer)
HDwrite(s->np_fd_w_to_r, &(s->np_notify), sizeof(int));
else
HDwrite(s->np_fd_r_to_w, &(s->np_notify), sizeof(int));
}
/*-------------------------------------------------------------------------
* Function: check_ohr_num_chunk
*
* Purpose: Check if the number of object header chunks is as expected.
*
* Parameters: hid_t oid
* HDF5 object ID (in this file: means group ID)
*
* bool one_chunk_ohr
* flag to indicate if the object header chunk is 1 or greater
* 1: true
* greater than 1: false
*
* Return: Success: true
* Failure: false
*
*-------------------------------------------------------------------------
*/
static bool
check_ohr_num_chunk(hid_t g, bool one_chunk_ohr)
{
H5O_native_info_t ninfo;
/* Get the object information */
if (H5Oget_native_info(g, &ninfo, H5O_NATIVE_INFO_HDR) < 0) {
HDprintf("H5Oget_native_info failed\n");
TEST_ERROR;
}
if (true == one_chunk_ohr) {
if (ninfo.hdr.nchunks != 1) {
HDprintf("Object header should have only one chunk,but it is not.\n");
TEST_ERROR;
}
}
else {
if (ninfo.hdr.nchunks <= 1) {
HDprintf("Object header should have more than one chunk,but it is not.\n");
TEST_ERROR;
}
}
return true;
error:
return false;
}
/*-------------------------------------------------------------------------
* Function: add_attr
*
* Purpose: Add attributes to a group.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t oid
* HDF5 object ID (in this file: means group ID)
*
* unsigned int which
* The number of iterations for group creation, use to generate
* newly created group name. The group name is "group-which".
*
* unsigned num_attrs
* The number of attributes to be created
*
* const char*aname_fmt
* The attribute name template used to create unique attribute names.
*
* unsigned int g_which
* This parameter is used to generate correct group name in a key
* debugging message.
*
* Return: Success: true
* Failure: false
*
*-------------------------------------------------------------------------
*/
static bool
add_attr(state_t *s, hid_t oid, unsigned int which, unsigned num_attrs, const char *aname_fmt,
unsigned int g_which)
{
char attrname[VS_ATTR_NAME_LEN];
unsigned u;
unsigned attr_value;
hid_t aid = H5I_INVALID_HID;
hid_t amtype = H5I_INVALID_HID;
hid_t atype = s->filetype;
hid_t sid = s->one_by_one_sid;
/* Need to obtain native datatype for H5Aread */
if ((amtype = H5Tget_native_type(atype, H5T_DIR_ASCEND)) < 0) {
HDprintf("H5Tget_native_type failed\n");
TEST_ERROR;
}
for (u = 0; u < num_attrs; u++) {
/* Create attribute */
/* Construct attribute name like attr-0-0 */
HDsprintf(attrname, aname_fmt, which, u);
if ((aid = H5Acreate2(oid, attrname, atype, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
HDprintf("H5Acreate2 failed\n");
TEST_ERROR;
}
attr_value = u + which;
dbgf(1, "setting attribute %s on group %u to %u\n", attrname, g_which, u + which);
/* Write data into the attribute */
if (H5Awrite(aid, amtype, &attr_value) < 0) {
HDprintf("H5Awrite failed\n");
TEST_ERROR;
}
/* Close attribute */
if (H5Aclose(aid) < 0) {
HDprintf("H5Aclose failed\n");
TEST_ERROR;
}
/* If coming to an "object header continuation block" test,
* we need to check if this test behaves as expected. */
if (s->at_pattern == 'a' || s->at_pattern == 'R') {
if (false == check_ohr_num_chunk(oid, false)) {
HDprintf("An object header continuation block should be created. \n");
HDprintf("But it is not.\n");
TEST_ERROR;
}
}
/* Writer sends a message to reader: an attribute is successfully generated.
then wait for the reader to verify and send an acknowledgement message back.*/
if (s->use_named_pipes && s->attr_test == true) {
dbgf(2, "writer: write attr - ready to send/receive message: %d\n", s->np_notify + 1);
if (np_wr_send_receive(s) == false) {
H5_FAILED();
AT();
dbgf(2, "writer: write attr - verification failed.\n");
/* Note: This is (mostly) because the verification failure message
* from the reader. So don't send the error message back to
* the reader. Just stop the test. */
goto error2;
}
}
} /* end for */
if (H5Tclose(amtype) < 0) {
TEST_ERROR;
}
return true;
error:
/* Writer needs to send an error message to the reader to stop the test*/
if (s->use_named_pipes && s->attr_test == true)
np_send_error(s, true);
error2:
H5E_BEGIN_TRY
{
H5Aclose(aid);
H5Tclose(amtype);
}
H5E_END_TRY;
return false;
}
/*-------------------------------------------------------------------------
* Function: add_default_group_attr
*
* Purpose: Add an attribute to a group.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* unsigned int which
* The number of iterations for group creation, use to generate
* newly created group and attribute names.
* The group name is "group-which" and the attribute name
* is "attr-which".
*
*
* Return: Success: true
* Failure: false
*
* Note: This function is used for the "dense" storage test.
* It is also used by the group-only, "add-ohr-block"
* and "del-ohr-block" tests.
*-------------------------------------------------------------------------
*/
static bool
add_default_group_attr(state_t *s, hid_t g, unsigned int which)
{
const char *aname_format = "attr-%u";
/* Note: Since we only add one attribute, the parameter for
* the number of attributes is 1. */
return add_attr(s, g, which, 1, aname_format, which);
}
/*-------------------------------------------------------------------------
* Function: add_vlstr_attr
*
* Purpose: Add a variable length string attribute to a group.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* unsigned int which
* The number of iterations for group creation, use to generate
* newly created group and attribute names.
* The group name is "group-which" and the attribute name
* is "attr-which".
*
*
* Return: Success: true
* Failure: false
*
* Note: This is for the "vstr" test.
*-------------------------------------------------------------------------
*/
static bool
add_vlstr_attr(state_t *s, hid_t g, unsigned int which)
{
hid_t aid = H5I_INVALID_HID;
hid_t atype = H5I_INVALID_HID;
char name[VS_ATTR_NAME_LEN];
char *astr_val = NULL;
hid_t sid = s->one_by_one_sid;
/* Allocate buffer for the VL string value */
astr_val = HDmalloc(VS_ATTR_NAME_LEN);
if (astr_val == NULL) {
HDprintf("Allocate memory for VL string failed.\n");
TEST_ERROR;
}
/* Assign the VL string value and the attribute name.. */
HDsprintf(astr_val, "%u", which);
esnprintf(name, sizeof(name), "attr-%u", which);
dbgf(1, "setting attribute %s on group %u to %u\n", name, which, which);
/* Create a datatype to refer to. */
if ((atype = H5Tcopy(H5T_C_S1)) < 0) {
HDprintf("Cannot create variable length datatype.\n");
TEST_ERROR;
}
if (H5Tset_size(atype, H5T_VARIABLE) < 0) {
HDprintf("Cannot set variable length datatype.\n");
TEST_ERROR;
}
/* Generate the VL string attribute.*/
if ((aid = H5Acreate2(g, name, atype, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
HDprintf("H5Acreate2 failed.\n");
TEST_ERROR;
}
if (H5Awrite(aid, atype, &astr_val) < 0) {
HDprintf("H5Awrite failed.\n");
TEST_ERROR;
}
if (H5Tclose(atype) < 0) {
HDprintf("H5Tclose() failed\n");
TEST_ERROR;
}
if (H5Aclose(aid) < 0) {
HDprintf("H5Aclose() failed\n");
TEST_ERROR;
}
HDfree(astr_val);
/* Writer sends a message to reader: a VL string attribute is successfully generated.
then wait for the reader to verify and send an acknowledgement message back. */
if (s->use_named_pipes && s->attr_test == true) {
dbgf(2, "writer: write attr - ready to send the message: %d\n", s->np_notify + 1);
if (np_wr_send_receive(s) == false) {
H5_FAILED();
AT();
dbgf(2, "writer: write attr - verification failed.\n");
goto error2;
}
}
return true;
error:
/* Writer needs to send an error message to the reader to stop the test*/
if (s->use_named_pipes && s->attr_test == true)
np_send_error(s, true);
H5E_BEGIN_TRY
{
H5Aclose(aid);
H5Tclose(atype);
}
H5E_END_TRY;
if (astr_val)
HDfree(astr_val);
error2:
return false;
}
/*-------------------------------------------------------------------------
* Function: del_one_attr
*
* Purpose: delete one attribute in a group.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t obj_id
* HDF5 object ID (in this file: means group ID)
*
* bool is_dense
* if the deleted attribute is for checking the dense storage
*
* bool is_vl_or_ohrc
* if the deleted attribute is a VL string or for object header
* continuation check test
*
* unsigned int which
* The number of iterations for group creation, use to generate
* newly created group and attribute names.
* The group name is "group-which" and the attribute names
* according to if this attribute is a VL string or for checking
* the dense storage or the storage transition from dense to
* compact.
*
*
* Return: Success: true
* Failure: false
*
*-------------------------------------------------------------------------
*/
static bool
del_one_attr(state_t *s, hid_t obj_id, bool is_dense, bool is_vl_or_ohrc, unsigned int which)
{
char attrname[VS_ATTR_NAME_LEN];
/*attribute name template for the dense storage related deletion operation */
const char *aname_format_d = "attr-d-%u-%u";
/*attribute name template used for general attribute deletion operation */
const char *aname_format = "attr-%u-%u";
/*attribute name template used for VL string attribute deletion
* or object header continuation check operations */
const char *aname_format_vl = "attr-%u";
dbgf(2, "writer: coming to delete the attribute.\n");
/* Construct the attribute name */
if (is_dense == true)
HDsprintf(attrname, aname_format_d, which, 0);
else if (is_vl_or_ohrc == true)
HDsprintf(attrname, aname_format_vl, which, 0);
else
HDsprintf(attrname, aname_format, which, 0);
/* Delete the attribute */
if (H5Adelete(obj_id, attrname) < 0) {
HDprintf("H5Adelete() failed\n");
TEST_ERROR;
}
/* If coming to an "object header continuation block" test,
* we need to check if this test behaves as expected. */
if (s->at_pattern == 'R') {
if (false == check_ohr_num_chunk(obj_id, true)) {
HDprintf("The object header chunk should not continue. \n");
TEST_ERROR;
}
}
/* Writer sends a message to reader: an attribute is successfully generated.
then wait for the reader to verify and send an acknowledgement message back. */
if (s->use_named_pipes && s->attr_test == true) {
dbgf(2, "writer: delete attr - ready to send the message: %d\n", s->np_notify + 1);
if (np_wr_send_receive(s) == false) {
H5_FAILED();
AT();
dbgf(2, "writer: delete attr - verification failed.\n");
goto error2;
}
}
return true;
error:
if (s->use_named_pipes && s->attr_test == true)
np_send_error(s, true);
error2:
return false;
}
/*-------------------------------------------------------------------------
* Function: add_del_vlstr_attr
*
* Purpose: Add a variable length string attribute
* then delete this attribute in this a group.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* unsigned int which
* The number of iterations for group creation, use to generate
* newly created group and attribute names.
* The group name is "group-which" and the attribute name
* is "attr-which".
*
*
* Return: Success: true
* Failure: false
*
* Note: This is for the "remove-vstr" test.
*-------------------------------------------------------------------------
*/
static bool
add_del_vlstr_attr(state_t *s, hid_t g, unsigned int which)
{
bool ret_value = false;
/* Add a VL string attribute then delete it. */
ret_value = add_vlstr_attr(s, g, which);
if (ret_value == true)
ret_value = del_one_attr(s, g, false, true, which);
return ret_value;
}
/*-------------------------------------------------------------------------
* Function: modify_attr
*
* Purpose: Modify the value of an attribute in a group.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* const char*aname_fmt
* The attribute name template used to create unique attribute names.
*
* unsigned int which
* The number of iterations for group creation, use to generate
* newly created group name. The group name is "group-which".
*
*
* Return: Success: true
* Failure: false
*
*-------------------------------------------------------------------------
*/
static bool
modify_attr(state_t *s, hid_t g, const char *aname_fmt, unsigned int which)
{
char attrname[VS_ATTR_NAME_LEN];
hid_t aid = H5I_INVALID_HID;
hid_t amtype = H5I_INVALID_HID;
unsigned int modify_value;
HDsprintf(attrname, aname_fmt, which, 0);
if ((aid = H5Aopen(g, attrname, H5P_DEFAULT)) < 0) {
HDprintf("H5Aopen failed\n");
TEST_ERROR;
}
if ((amtype = H5Tget_native_type(s->filetype, H5T_DIR_ASCEND)) < 0) {
HDprintf("H5Tget_native_type failed\n");
TEST_ERROR;
}
/* Make a large number to verify the change easily */
modify_value = which + 10000;
if (H5Awrite(aid, amtype, &modify_value) < 0) {
HDprintf("H5Awrite failed\n");
TEST_ERROR;
}
if (H5Tclose(amtype) < 0) {
HDprintf("H5Tclose failed\n");
TEST_ERROR;
}
if (H5Aclose(aid) < 0) {
HDprintf("H5Aclose failed\n");
TEST_ERROR;
}
/* Writer sends a message to reader: an attribute is successfully modified.
then wait for the reader to verify and send an acknowledgement message back.*/
if (s->use_named_pipes && s->attr_test == true) {
dbgf(2, "writer: modify attr - ready to send the message: %d\n", s->np_notify + 1);
if (np_wr_send_receive(s) == false) {
H5_FAILED();
AT();
dbgf(2, "writer: write attr - verification failed.\n");
/* Note: This is (mostly) because the verification failure message
* from the reader. So don't send the error message back to
* the reader. Just stop the test. */
goto error2;
}
}
return true;
error:
/* Writer needs to send an error message to the reader to stop the test*/
if (s->use_named_pipes && s->attr_test == true)
np_send_error(s, true);
H5E_BEGIN_TRY
{
H5Aclose(aid);
H5Tclose(aid);
}
H5E_END_TRY;
error2:
return false;
}
/*-------------------------------------------------------------------------
* Function: modify_vlstr_attr
*
* Purpose: Modify the value of an VL string attribute in a group.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* unsigned int which
* The number of iterations for group creation, use to generate
* newly created group name. The group name is "group-which".
*
*
* Return: Success: true
* Failure: false
*
*-------------------------------------------------------------------------
*/
static bool
modify_vlstr_attr(state_t *s, hid_t g, unsigned int which)
{
hid_t aid = H5I_INVALID_HID;
hid_t atype = H5I_INVALID_HID;
char name[VS_ATTR_NAME_LEN];
char *astr_val = NULL;
astr_val = HDmalloc(VS_ATTR_NAME_LEN);
if (astr_val == NULL) {
HDprintf("Allocate memory for VL string failed.\n");
TEST_ERROR;
}
/* Change the VL string value and create the attribute name. */
HDsprintf(astr_val, "%u%c", which, 'A');
esnprintf(name, sizeof(name), "attr-%u", which);
dbgf(1, "setting attribute %s on group %u to %u\n", name, which, which);
/* Create a datatype to refer to. */
if ((atype = H5Tcopy(H5T_C_S1)) < 0) {
HDprintf("Cannot create variable length datatype.\n");
TEST_ERROR;
}
if (H5Tset_size(atype, H5T_VARIABLE) < 0) {
HDprintf("Cannot set variable length datatype.\n");
TEST_ERROR;
}
/* Open this attribute. */
if ((aid = H5Aopen(g, name, H5P_DEFAULT)) < 0) {
HDprintf("H5Aopen failed.\n");
TEST_ERROR;
}
dbgf(1, "The modified VL string value is %s \n", astr_val);
if (H5Awrite(aid, atype, &astr_val) < 0) {
HDprintf("H5Awrite failed.\n");
TEST_ERROR;
}
if (H5Tclose(atype) < 0) {
HDprintf("H5Tclose() failed\n");
TEST_ERROR;
}
if (H5Aclose(aid) < 0) {
HDprintf("H5Aclose() failed\n");
TEST_ERROR;
}
HDfree(astr_val);
/* Writer sends a message to reader: a VL string attribute is successfully generated.
then wait for the reader to verify and send an acknowledgement message back. */
if (s->use_named_pipes && s->attr_test == true) {
dbgf(2, "writer: modify vl attr - ready to send the message: %d\n", s->np_notify + 1);
if (np_wr_send_receive(s) == false) {
H5_FAILED();
AT();
dbgf(2, "writer: write attr - verification failed.\n");
goto error2;
}
}
return true;
error:
H5E_BEGIN_TRY
{
H5Aclose(aid);
H5Tclose(atype);
}
H5E_END_TRY;
if (astr_val)
HDfree(astr_val);
if (s->use_named_pipes && s->attr_test == true)
np_send_error(s, true);
error2:
return false;
}
/*-------------------------------------------------------------------------
* Function: add_modify_vlstr_attr
*
* Purpose: Add a variable length string attribute
* then modify this attribute in this a group.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* unsigned int which
* The number of iterations for group creation, use to generate
* newly created group and attribute names.
* The group name is "group-which" and the attribute name
* is "attr-which".
*
*
* Return: Success: true
* Failure: false
*
* Note: This is for the "modify-vstr" test.
*-------------------------------------------------------------------------
*/
static bool
add_modify_vlstr_attr(state_t *s, hid_t g, unsigned int which)
{
bool ret_value = false;
ret_value = add_vlstr_attr(s, g, which);
if (true == ret_value)
ret_value = modify_vlstr_attr(s, g, which);
return ret_value;
}
/*-------------------------------------------------------------------------
* Function: add_attrs_compact
*
* Purpose: Add some attributes to the group.
* the number of attributes should be the maximal number of
* attributes that the compact storage can hold
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* hid_t gcpl
* Object creation property list ID
*
* unsigned int which
* The number of iterations for group creation, use to generate
* newly created group and attribute names.
* The group name is "group-which" and the attribute name
* is "attr-which".
*
*
* Return: Success: true
* Failure: false
*
* Note: This is for the "modify-vstr" test.
* For attribute compact/dense storage, check the reference
* manual of H5Pget_attr_phase_change.
*-------------------------------------------------------------------------
*/
static bool
add_attrs_compact(state_t *s, hid_t g, hid_t gcpl, unsigned int which)
{
unsigned max_compact = 0;
unsigned min_dense = 0;
const char *aname_format = "attr-%u-%u";
if (s->old_style_grp)
max_compact = 2;
else {
/* Obtain the maximal number of attributes to be stored in compact
* storage and the minimal number of attributes to be stored in
* dense storage. */
if (H5Pget_attr_phase_change(gcpl, &max_compact, &min_dense) < 0) {
HDprintf("H5Pget_attr_phase_change() failed\n");
TEST_ERROR;
}
}
/* Add max_compact attributes, these attributes are stored in
* compact storage. */
return add_attr(s, g, which, max_compact, aname_format, which);
error:
if (s->use_named_pipes && s->attr_test == true)
np_send_error(s, true);
return false;
}
/*-------------------------------------------------------------------------
* Function: add_attrs_compact_dense
*
* Purpose: Add some attributes to the group.
* First, the number of attributes should be the maximal number
* of attributes that the compact storage can hold.
* Then, add another atribute, the storage becomes dense.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* hid_t gcpl
* Object creation property list ID
*
* unsigned int which
* The number of iterations for group creation, use to generate
* newly created group and attribute names.
*
* Return: Success: true
* Failure: false
*
* Note: This is for the "compact-to-dense" test.
* For attribute compact/dense storage, check the reference
* manual of H5Pget_attr_phase_change.
*-------------------------------------------------------------------------
*/
static bool
add_attrs_compact_dense(state_t *s, hid_t g, hid_t gcpl, unsigned int which)
{
unsigned max_compact = 0;
unsigned min_dense = 0;
const char *aname_format = "attr-d-%u-%u";
bool ret_value = false;
if (H5Pget_attr_phase_change(gcpl, &max_compact, &min_dense) < 0) {
HDprintf("H5Pget_attr_phase_change failed\n");
TEST_ERROR;
}
/* Add attributes, until just before converting to dense storage */
ret_value = add_attrs_compact(s, g, gcpl, which);
/* Add another attribute, the storage becomes dense. */
if (ret_value == true)
ret_value = add_attr(s, g, which + max_compact, 1, aname_format, which);
return ret_value;
error:
if (s->use_named_pipes && s->attr_test == true)
np_send_error(s, true);
return false;
}
/*-------------------------------------------------------------------------
* Function: del_attrs_compact_dense_compact
*
* Purpose: delete some attributes in the group.
* The number of attributes are deleted in such a way
* that the attribute storage changes from compact to
* dense then to compact again.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* hid_t gcpl
* Object creation property list ID
*
* unsigned int which
* The number of iterations for group creation, use to generate
* newly created group and attribute names.
*
* Return: Success: true
* Failure: false
*
* Note: This is an internal function used by the
* "dense-del-to-compact" test.
* For attribute compact/dense storage, check the reference
* manual of H5Pget_attr_phase_change.
*-------------------------------------------------------------------------
*/
static bool
del_attrs_compact_dense_compact(state_t *s, hid_t obj_id, hid_t gcpl, unsigned int which)
{
unsigned max_compact = 0;
unsigned min_dense = 0;
unsigned u = 0;
char attrname[VS_ATTR_NAME_LEN];
const char *aname_format = "attr-%u-%u";
const char *adname_format = "attr-d-%u-%u";
/* Obtain the maximal number of attributes to be stored in compact
* storage and the minimal number of attributes to be stored in
* dense storage. */
if (H5Pget_attr_phase_change(gcpl, &max_compact, &min_dense) < 0) {
HDprintf("H5Pget_attr_phase_change failed\n");
TEST_ERROR;
}
u = max_compact + 1;
/* delete a number of attributes so that the attribute storage just becomes dense.*/
for (u--; u >= (min_dense - 1); u--) {
HDsprintf(attrname, aname_format, which, max_compact - u);
if (H5Adelete(obj_id, attrname) < 0) {
HDprintf("H5Adelete failed\n");
TEST_ERROR;
}
/* For each attribute deletion, we want to ensure the verification
* from the reader.
* So writer sends a message to reader: an attribute is successfully deleted.
then wait for reader to verify and send an acknowledgement message back. */
if (s->use_named_pipes && s->attr_test == true) {
dbgf(2, "writer: delete attr - ready to send the message: %d\n", s->np_notify + 1);
if (np_wr_send_receive(s) == false) {
H5_FAILED();
AT();
dbgf(2, "writer: delete attr - verification failed.\n");
goto error2;
}
}
}
/* The writer deletes another attribute, the storage is
* still dense. However, the attribute to be deleted
* doesn't follow the previous for loop. It may be
* in different location in the object header. Just add
* a litter variation to check if this operation is successful.
* The attribute name to be deleted is attr-max_compact+which-0
*/
HDsprintf(attrname, adname_format, max_compact + which, 0);
if (H5Adelete(obj_id, attrname) < 0) {
HDprintf("H5Adelete failed\n");
TEST_ERROR;
}
/* Again we need to notify the reader via Named pipe. */
if (s->use_named_pipes && s->attr_test == true) {
dbgf(2, "writer: delete attr - ready to send the message: %d\n", s->np_notify + 1);
if (np_wr_send_receive(s) == false) {
H5_FAILED();
AT();
dbgf(2, "writer: delete attr - verification failed.\n");
goto error2;
}
}
/* The following comments are left here in case in the future we want to
* use HDF5 function to verify the attribute storage */
#if 0
// May H5Oget_info3 -- obtain the number of attributes.
//Check the number of attributes >=min_dense.
//We may use the internal function
//is_dense = H5O__is_attr_dense_test(dataset) to check if it is dense in the future.
//
#endif
return true;
error:
if (s->use_named_pipes && s->attr_test == true)
np_send_error(s, true);
error2:
return false;
}
/*-------------------------------------------------------------------------
* Function: add_del_attrs_compact
*
* Purpose: Add some attributes to the group and then delete one attribute.
* First, the number of attributes to be added should be the
* maximal number of attributes that the compact storage can hold.
* Then, delete one atribute, the storage is still compact.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* hid_t gcpl
* Object creation property list ID
*
* unsigned int which
* The number of iterations for group creation, use to generate
* newly created group and attribute names.
*
* Return: Success: true
* Failure: false
*
* Note: This is for the "compact-del" test.
* For attribute compact/dense storage, check the reference
* manual of H5Pget_attr_phase_change.
*-------------------------------------------------------------------------
*/
static bool
add_del_attrs_compact(state_t *s, hid_t g, hid_t gcpl, unsigned int which)
{
bool ret_value = false;
ret_value = add_attrs_compact(s, g, gcpl, which);
if (ret_value == true) {
dbgf(2, "writer: before deleting the attribute.\n");
ret_value = del_one_attr(s, g, false, false, which);
}
return ret_value;
}
/*-------------------------------------------------------------------------
* Function: add_del_attrs_compact_dense
*
* Purpose: Add some attributes to the group and then delete one attribute.
* First, the number of attributes to be added exceeds
* the maximal number of attributes that the compact storage can hold.
* The storage changes from compact to dense.
* Then, delete one atribute, the storage is still dense.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* hid_t gcpl
* Object creation property list ID
*
* unsigned int which
* The number of iterations for group creation, use to generate
* newly created group and attribute names.
*
* Return: Success: true
* Failure: false
*
* Note: This is for the "dense-del" test.
* For attribute compact/dense storage, check the reference
* manual of H5Pget_attr_phase_change.
*-------------------------------------------------------------------------
*/
static bool
add_del_attrs_compact_dense(state_t *s, hid_t g, hid_t gcpl, unsigned int which)
{
bool ret_value = false;
unsigned max_compact = 0;
unsigned min_dense = 0;
if (H5Pget_attr_phase_change(gcpl, &max_compact, &min_dense) < 0) {
HDprintf("H5Pget_attr_phase_change failed\n");
TEST_ERROR;
}
ret_value = add_attrs_compact_dense(s, g, gcpl, which);
if (ret_value == true)
ret_value = del_one_attr(s, g, true, false, which + max_compact);
return ret_value;
error:
if (s->use_named_pipes && s->attr_test == true)
np_send_error(s, true);
return false;
}
/*-------------------------------------------------------------------------
* Function: add_del_attrs_compact_dense_compact
*
* Purpose: Add attributes to the group and then delete some of them.
* First, the number of attributes to be added exceeds
* the maximal number of attributes that the compact storage can hold.
* The storage changes from compact to dense.
* Then, delete some attributes, the storage changes from
* dense to compact again.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* hid_t gcpl
* Object creation property list ID
*
* unsigned int which
* The number of iterations for group creation, use to generate
* newly created group and attribute names.
*
* Return: Success: true
* Failure: false
*
* Note: This is for the "dense-del-to-compact" test.
* For attribute compact/dense storage, check the reference
* manual of H5Pget_attr_phase_change.
*-------------------------------------------------------------------------
*/
static bool
add_del_attrs_compact_dense_compact(state_t *s, hid_t g, hid_t gcpl, unsigned int which)
{
bool ret_value = false;
ret_value = add_attrs_compact_dense(s, g, gcpl, which);
if (ret_value == true)
ret_value = del_attrs_compact_dense_compact(s, g, gcpl, which);
return ret_value;
}
/*-------------------------------------------------------------------------
* Function: add_modify_default_group_attr
*
* Purpose: Add an attribute then modify the value to a group.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* unsigned int which
* The number of iterations for group creation, use to generate
* newly created group and attribute names.
* The group name is "group-which" and the attribute name
* is "attr-which".
*
*
* Return: Success: true
* Failure: false
*
* Note: This function is used for the "modify" test.
*-------------------------------------------------------------------------
*/
static bool
add_modify_default_group_attr(state_t *s, hid_t g, unsigned int which)
{
bool ret_value = false;
const char *aname_format = "attr-%u";
ret_value = add_default_group_attr(s, g, which);
if (ret_value == true)
ret_value = modify_attr(s, g, aname_format, which);
return ret_value;
}
/*-------------------------------------------------------------------------
* Function: del_ohr_block_attr
*
* Purpose: Add an attribute to force creation of object header
* continuation block and remove this attribute to delete
* the object header continuation block
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* unsigned int which
* The number of iterations for group creation, use to generate
* newly created group and attribute names.
* The group name is "group-which" and the attribute name
* is "attr-which".
*
*
* Return: Success: true
* Failure: false
*
* Note: This function is used for the
* "deletion of object header continuation block" test.
*-------------------------------------------------------------------------
*/
static bool
del_ohr_block_attr(state_t *s, hid_t g, unsigned int which)
{
bool ret_value = false;
ret_value = add_default_group_attr(s, g, which);
if (ret_value == true)
ret_value = del_one_attr(s, g, false, true, which);
return ret_value;
}
/*-------------------------------------------------------------------------
* Function: add_group_attribute
*
* Purpose: Check the attribute test pattern and then call the
* correponding test function..
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* hid_t gcpl
* Object creation property list ID
*
* unsigned int which
* The number of iterations for group creation, use to generate
* newly created group and attribute names.
*
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the write_group() function.
*-------------------------------------------------------------------------
*/
static bool
add_group_attribute(state_t *s, hid_t g, hid_t gcpl, unsigned int which)
{
bool ret_value = false;
char test_pattern = s->at_pattern;
switch (test_pattern) {
case 'c':
ret_value = add_attrs_compact(s, g, gcpl, which);
break;
case 't':
ret_value = add_attrs_compact_dense(s, g, gcpl, which);
break;
case 'C':
ret_value = add_del_attrs_compact(s, g, gcpl, which);
break;
case 'D':
ret_value = add_del_attrs_compact_dense(s, g, gcpl, which);
break;
case 'T':
ret_value = add_del_attrs_compact_dense_compact(s, g, gcpl, which);
break;
case 'M':
ret_value = add_modify_default_group_attr(s, g, which);
break;
case 'v':
ret_value = add_vlstr_attr(s, g, which);
break;
case 'r':
ret_value = add_del_vlstr_attr(s, g, which);
break;
case 'm':
ret_value = add_modify_vlstr_attr(s, g, which);
break;
case 'R':
ret_value = del_ohr_block_attr(s, g, which);
break;
case 'a':
case 'd':
case ' ':
default:
ret_value = add_default_group_attr(s, g, which);
break;
}
return ret_value;
}
/*-------------------------------------------------------------------------
* Function: write_group
*
* Purpose: Create a group and carry out attribute operations(add,delete etc.)
* according to the attribute test pattern.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* unsigned int which
* The number of iterations for group creation
*
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the main() function.
*-------------------------------------------------------------------------
*/
static bool
write_group(state_t *s, unsigned int which)
{
char name[sizeof("/group-9999999999")];
hid_t g = H5I_INVALID_HID;
hid_t dummy_d = H5I_INVALID_HID;
hid_t gcpl = H5I_INVALID_HID;
bool result = true;
H5G_info_t group_info;
if (which >= s->nsteps) {
HDprintf("Number of created groups is out of bounds\n");
TEST_ERROR;
}
esnprintf(name, sizeof(name), "/group-%u", which);
if (s->old_style_grp)
gcpl = H5P_DEFAULT;
else {
gcpl = H5Pcreate(H5P_GROUP_CREATE);
if (gcpl < 0) {
HDprintf("H5Pcreate failed\n");
TEST_ERROR;
}
/* If we test the dense storage, change the attribute phase. */
if (s->at_pattern == 'd') {
if (H5Pset_attr_phase_change(gcpl, 0, 0) < 0) {
HDprintf("H5Pset_attr_phase_change failed for the dense storage.\n");
TEST_ERROR;
}
}
}
if ((g = H5Gcreate2(s->file, name, H5P_DEFAULT, gcpl, H5P_DEFAULT)) < 0) {
HDprintf("H5Gcreate2 failed\n");
TEST_ERROR;
}
/* We need to create a dummy dataset for the object header continuation block test. */
if (s->at_pattern == 'a' || s->at_pattern == 'R') {
if ((dummy_d = H5Dcreate2(g, "Dataset", H5T_NATIVE_INT, s->one_by_one_sid, H5P_DEFAULT, H5P_DEFAULT,
H5P_DEFAULT)) < 0) {
HDprintf("H5Dcreate2 failed\n");
TEST_ERROR;
}
}
if (H5Gget_info(g, &group_info) < 0) {
HDprintf("H5Gget_info failed\n");
TEST_ERROR;
}
if (s->old_style_grp) {
if (group_info.storage_type != H5G_STORAGE_TYPE_SYMBOL_TABLE) {
HDprintf("Old-styled group test: but the group is not in old-style. \n");
TEST_ERROR;
}
dbgf(2, "Writer: group is created with the old-style.\n");
}
else {
if (group_info.storage_type == H5G_STORAGE_TYPE_SYMBOL_TABLE) {
HDprintf("The created group should NOT be in old-style . \n");
TEST_ERROR;
}
dbgf(2, "Writer: group is created with the new-style.\n");
}
/* If coming to an "object header continuation block" test,
* we need to check if this test behaves as expected. */
if (s->at_pattern == 'a' || s->at_pattern == 'R') {
if (false == check_ohr_num_chunk(g, true)) {
HDprintf("An object header continuation block should NOT be created. \n");
HDprintf("But it is created.\n");
TEST_ERROR;
}
}
/* If an attribute test is turned on and named pipes are used,
* the writer should send and receive messages after the group creation.
* This will distinguish an attribute operation error from an
* group creation error.
* Writer sends a message to reader: an attribute is successfully generated.
* then wait for the reader to verify and send an acknowledgement message back.*/
if (s->use_named_pipes && s->attr_test == true) {
dbgf(2, "writer: ready to send the message: %d\n", s->np_notify + 1);
if (np_wr_send_receive(s) == false) {
H5_FAILED();
AT();
/* Note: This is (mostly) because the verification failure message
* from the reader. So don't send the error message back to
* the reader. Just stop the test. */
goto error2;
}
}
/* Then carry out the attribute operation. */
if (s->asteps != 0 && which % s->asteps == 0)
result = add_group_attribute(s, g, gcpl, which);
if (s->at_pattern == 'a' || s->at_pattern == 'R') {
if (H5Dclose(dummy_d) < 0) {
HDprintf("H5Dclose failed\n");
TEST_ERROR;
}
}
if (H5Gclose(g) < 0) {
HDprintf("H5Gclose failed\n");
TEST_ERROR;
}
if (!s->old_style_grp && H5Pclose(gcpl) < 0) {
HDprintf("H5Pclose failed\n");
TEST_ERROR;
}
return result;
error:
/* Writer needs to send an error message to the reader to stop the test*/
if (s->use_named_pipes && s->attr_test == true)
np_send_error(s, true);
error2:
H5E_BEGIN_TRY
{
if (s->at_pattern == 'a' || s->at_pattern == 'R')
H5Dclose(dummy_d);
H5Gclose(g);
if (!s->old_style_grp)
H5Pclose(gcpl);
}
H5E_END_TRY;
return false;
}
/*-------------------------------------------------------------------------
* Function: check_attr_storage_type
*
* Purpose: Check if the attribute storage type is correct
*
* Parameters: hid_t oid
* HDF5 object ID (in this file: means group ID)
*
* bool is_compact
* true if the attribute is stored in compact storage
* false if the attribute is stored in dense storage
*
*
* Return: Success: true
* Failure: false
*
*-------------------------------------------------------------------------
*/
static bool
check_attr_storage_type(hid_t g, bool is_compact)
{
H5O_native_info_t ninfo;
/* Get the object information */
if (H5Oget_native_info(g, &ninfo, H5O_NATIVE_INFO_HDR | H5O_NATIVE_INFO_META_SIZE) < 0) {
HDprintf("H5Oget_native_info failed\n");
TEST_ERROR;
}
if (is_compact) {
if (ninfo.meta_size.attr.index_size != 0 || ninfo.meta_size.attr.heap_size != 0) {
HDprintf("Should be in compact storage,but it is not.\n");
TEST_ERROR;
}
}
else {
if (ninfo.meta_size.attr.index_size == 0 || ninfo.meta_size.attr.heap_size == 0) {
HDprintf("Should be in dense storage,but it is not.\n");
TEST_ERROR;
}
}
return true;
error:
return false;
}
/*-------------------------------------------------------------------------
* Function: vrfy_attr
*
* Purpose: Verify is a group attribute value is as expected.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t oid
* HDF5 object ID (in this file: means group ID)
*
* unsigned int which
* The number of iterations for group creation, use to generate
* newly created group name. The group name is "group-which".
*
* const char*aname
* The attribute name
*
* unsigned int g_which
* This parameter is used to generate correct group name in a key
* debugging message.
*
* bool check_storage
* a flag to indicate if the storage check is on
*
* bool is_compact
* true if the attribute storage should be in compact
* false if the attribute storage should be in dense
* Note: this parameter is not used if the check_storage
* is set to false.
*
*
* Return: Success: true
* Failure: false
*
*-------------------------------------------------------------------------
*/
static bool
vrfy_attr(state_t *s, hid_t g, unsigned int which, const char *aname, unsigned int g_which,
bool check_storage, bool is_compact)
{
unsigned int read_which;
hid_t aid = H5I_INVALID_HID;
hid_t amtype = H5I_INVALID_HID;
/* The reader receives a message from the writer.Then sleep
* for a few ticks or stop the test if receiving an error
* message.
*/
if (s->use_named_pipes && true == s->attr_test) {
if (false == np_rd_receive(s)) {
H5_FAILED();
AT();
/* Since receiving the error message from the writer,
* just stop the test. */
goto error2;
}
decisleep(s->tick_len * s->update_interval);
dbgf(1, "Reader: finish reading the message: %d\n", s->np_notify);
}
/* Go ahead to read the attribute. */
dbgf(1, "verifying attribute %s on group %u equals %u\n", aname, g_which, which);
if ((amtype = H5Tget_native_type(s->filetype, H5T_DIR_ASCEND)) < 0) {
HDprintf("H5Tget_native_type failed\n");
TEST_ERROR;
}
if ((aid = H5Aopen(g, aname, H5P_DEFAULT)) < 0) {
HDprintf("H5Aopen failed\n");
TEST_ERROR;
}
if (H5Aread(aid, amtype, &read_which) < 0) {
HDprintf("H5Aread failed\n");
TEST_ERROR;
}
if (H5Aclose(aid) < 0) {
HDprintf("H5Aclose failed\n");
TEST_ERROR;
}
if (read_which != which) {
HDprintf("reader: the add_attribute verfication failed,expected value is %d\n", which);
HDprintf("reader: the add_attribute verfication failed, the value is %d\n", read_which);
HDprintf("The add_attribute verification failed\n");
TEST_ERROR;
}
if (!s->old_style_grp && check_storage == true) {
if (false == check_attr_storage_type(g, is_compact)) {
HDprintf("The attribute storage type is wrong. \n");
TEST_ERROR;
}
dbgf(2, "reader: finish checking the storage type: %d\n", s->np_notify);
}
/* If coming to an "object header continuation block" test,
* we need to check if this test behaves as expected. */
if (s->at_pattern == 'a' || s->at_pattern == 'R') {
if (false == check_ohr_num_chunk(g, false)) {
HDprintf("An object header continuation block should be created. \n");
HDprintf("But it is not.\n");
HDprintf("Verification of 'object header continuation block test' failed.\n");
TEST_ERROR;
}
}
/* If the read value is expected, send back an OK message to the writer. */
if (s->use_named_pipes && s->attr_test == true) {
if (np_rd_send(s) == false) {
HDprintf("named pipe reader send message error\n");
TEST_ERROR;
}
dbgf(2, "reader: finish sending back the message: %d\n", s->np_notify);
}
return true;
error:
H5E_BEGIN_TRY
{
H5Tclose(amtype);
H5Aclose(aid);
}
H5E_END_TRY;
/* Send back an error message to the writer so that the writer can stop. */
if (s->use_named_pipes && s->attr_test == true)
np_send_error(s, false);
error2:
return false;
}
/*-------------------------------------------------------------------------
* Function: verify_default_group_attr
*
* Purpose: Check if the reader can retrieve the correct value of a
* group attribute corrected by the writer.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* unsigned int which
* The expected attribute value. It is also used to construct the
* group name.
*
* Return: Success: true
* Failure: false
*
* Note: This function is used for the "dense" storage test.
* It is also used by the group-only, "add-ohr-block"
* and "del-ohr-block" tests.
*-------------------------------------------------------------------------
*/
static bool
verify_default_group_attr(state_t *s, hid_t g, unsigned int which)
{
char attrname[VS_ATTR_NAME_LEN];
const char *aname_format = "attr-%u";
HDsprintf(attrname, aname_format, which);
return vrfy_attr(s, g, which, attrname, which, false, true);
}
/*-------------------------------------------------------------------------
* Function: verify_modify_attr
*
* Purpose: Check if the reader can retrieve the correct value of
* an attribute in a group, first the original value then
* the modified value.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* unsigned int which
* The expected attribute value. It is also used to construct the
* group name. The modified attribute value can be derived from
* the expected attribute value.
*
* Return: Success: true
* Failure: false
*
* Note: This function is used for the "modified" test.
*-------------------------------------------------------------------------
*/
static bool
verify_modify_attr(state_t *s, hid_t g, unsigned int which)
{
bool ret = false;
const char * aname_fmt = "attr-%u";
unsigned int read_which;
hid_t aid = H5I_INVALID_HID;
hid_t amtype = H5I_INVALID_HID;
char attrname[VS_ATTR_NAME_LEN];
/* First verify the original attribute value */
ret = verify_default_group_attr(s, g, which);
/* Then the modified value */
if (ret == true) {
/* The reader receives a message from the writer.Then sleep
* for a few ticks or stop the test if receiving an error
* message.
*/
if (s->use_named_pipes && true == s->attr_test) {
if (false == np_rd_receive(s)) {
H5_FAILED();
AT();
goto error2;
}
decisleep(s->tick_len * s->update_interval);
dbgf(1, "Reader: finish reading the message: %d\n", s->np_notify);
}
/* Go ahead to read the attribute. */
esnprintf(attrname, sizeof(attrname), aname_fmt, which);
if ((amtype = H5Tget_native_type(s->filetype, H5T_DIR_ASCEND)) < 0) {
HDprintf("H5Tget_native_type failed\n");
TEST_ERROR;
}
if ((aid = H5Aopen(g, attrname, H5P_DEFAULT)) < 0) {
HDprintf("H5Aopen failed\n");
TEST_ERROR;
}
if (H5Aread(aid, amtype, &read_which) < 0) {
HDprintf("H5Aread failed\n");
TEST_ERROR;
}
if (H5Tclose(amtype) < 0) {
HDprintf("H5Tclose failed.\n");
TEST_ERROR;
}
if (H5Aclose(aid) < 0) {
HDprintf("H5Aclose failed\n");
TEST_ERROR;
}
/* verify the modified value */
if (read_which != (which + 10000)) {
HDprintf("reader: the modified_attr() expected value is %d\n", which + 10000);
HDprintf("reader: the modified_attr() actual value is %d\n", read_which);
HDprintf("The modify_attribute verification failed.\n");
TEST_ERROR;
}
/* The reader sends an OK message back to the writer. */
if (s->use_named_pipes && s->attr_test == true) {
if (np_rd_send(s) == false)
goto error2;
dbgf(2, "reader: modify_attr finish sending back the message: %d\n", s->np_notify);
}
return true;
}
return false;
error:
H5E_BEGIN_TRY
{
H5Aclose(aid);
H5Tclose(amtype);
}
H5E_END_TRY;
/* The reader needs to send an error message back to the writer to stop the test.*/
if (s->use_named_pipes && s->attr_test == true)
np_send_error(s, false);
error2:
return false;
}
/*-------------------------------------------------------------------------
* Function: verify_group_vlstr_attr
*
* Purpose: Check if the reader can retrieve the correct value of
* a variable length string attribute created by the writer.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* unsigned int which
* Use to derieve the expected attribute value. It is also used
* to construct the group name.
*
* bool vrfy_mod
* true if this function is used for the modified VL string test.
* false if this function is just used for the VL string test.
*
* Return: Success: true
* Failure: false
*
* Note: This function is an internal function used by
* both the "vlstr" and the "modify-vstr" tests.
*-------------------------------------------------------------------------
*/
static bool
verify_group_vlstr_attr(state_t *s, hid_t g, unsigned int which, bool vrfy_mod)
{
hid_t aid = H5I_INVALID_HID;
hid_t atype = H5I_INVALID_HID;
char name[VS_ATTR_NAME_LEN];
char *astr_val_exp;
char *astr_val;
/* The reader receives a message from the writer.Then sleep
* for a few ticks or stop the test if the received message
* is an error message.
*/
if (s->use_named_pipes && true == s->attr_test) {
if (false == np_rd_receive(s)) {
H5_FAILED();
AT();
goto error2;
}
decisleep(s->tick_len * s->update_interval);
dbgf(1, "Reader: finish reading the message: %d\n", s->np_notify);
}
/* Go ahead to read the VL string attribute. */
astr_val_exp = HDmalloc(VS_ATTR_NAME_LEN);
if (astr_val_exp == NULL) {
HDprintf("Allocate memory for expected buffer failed.\n");
TEST_ERROR;
}
esnprintf(name, sizeof(name), "attr-%u", which);
/* Construct the expected VL string value,depending if
* it is the modified value or the original value. */
if (vrfy_mod == true)
HDsprintf(astr_val_exp, "%u%c", which, 'A');
else
HDsprintf(astr_val_exp, "%u", which);
dbgf(1, "verifying attribute %s on group %u equals %u\n", name, which, which);
dbgf(1, "expected vl attr is= %s\n", astr_val_exp);
if ((aid = H5Aopen(g, name, H5P_DEFAULT)) < 0) {
HDprintf("H5Aopen failed\n");
TEST_ERROR;
}
/* Create a VL string datatype */
if ((atype = H5Tcopy(H5T_C_S1)) < 0) {
HDprintf("Cannot create variable length datatype.\n");
TEST_ERROR;
}
if (H5Tset_size(atype, H5T_VARIABLE) < 0) {
HDprintf("Cannot set variable length datatype.\n");
TEST_ERROR;
}
if (H5Aread(aid, atype, &astr_val) < 0) {
HDprintf("Cannot read the attribute.\n");
TEST_ERROR;
}
dbgf(1, "read attr is= %s\n", astr_val);
if (HDstrcmp(astr_val, astr_val_exp) != 0) {
HDprintf("reader: the vl add_attribute verfication failed,expected value is %s\n", astr_val_exp);
HDprintf("reader: the vl add_attribute verfication failed, the value is %s\n", astr_val);
HDprintf("The vl add_attribute verification failed\n");
TEST_ERROR;
}
if (H5Tclose(atype) < 0) {
HDprintf("H5Tclose failed.\n");
TEST_ERROR;
}
if (H5Aclose(aid) < 0) {
HDprintf("H5Aclose failed.\n");
TEST_ERROR;
}
H5free_memory(astr_val);
HDfree(astr_val_exp);
/* Reader sends an OK message back to the reader */
if (s->use_named_pipes && s->attr_test == true) {
if (np_rd_send(s) == false)
goto error2;
dbgf(2, "reader: finish sending back the message: %d\n", s->np_notify);
}
return true;
error:
H5E_BEGIN_TRY
{
H5Aclose(aid);
H5Tclose(atype);
}
H5E_END_TRY;
if (astr_val)
H5free_memory(astr_val);
if (astr_val_exp)
HDfree(astr_val_exp);
/* The reader sends an error message to the writer to stop the test.*/
if (s->use_named_pipes && s->attr_test == true)
np_send_error(s, false);
error2:
return false;
}
/*-------------------------------------------------------------------------
* Function: verify_del_one_attr
*
* Purpose: Verify if an attribute is successfully deleted.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* const char* aname
* The name of the attribute to be deleted.
*
* bool check_storage
* a flag to indicate if the storage check is on
*
* bool is_compact
* true if after this attribute is deleted,
* the storage should still be in compact, false
* if the storage should be in dense.
* Note: this parameter is not used if the check_storage
* is set to false.
* Return: Success: true
* Failure: false
*
* Note: This is an internal function used by "remove-vlstr",
* "compact-del","dense-del",dense-del-to-compact" tests.
*-------------------------------------------------------------------------
*/
static bool
verify_del_one_attr(state_t *s, hid_t g, const char *aname, bool check_storage, bool is_compact)
{
htri_t attr_exists = FALSE;
/* The reader receives a message from the writer.Then sleep
* for a few ticks or stop the test if the received message
* is an error message.
*/
if (s->use_named_pipes && true == s->attr_test) {
if (false == np_rd_receive(s)) {
H5_FAILED();
AT();
goto error2;
}
decisleep(s->tick_len * s->update_interval);
dbgf(1, "Reader: finish reading the message: %d\n", s->np_notify);
}
/* Check if the deleted attribute still exists. */
attr_exists = H5Aexists_by_name(g, ".", aname, H5P_DEFAULT);
if (attr_exists == FALSE) {
dbgf(1, "verify_del_attrs_compact() test: \n");
dbgf(1, " attribute %s is successfully deleted. \n", aname);
}
else if (attr_exists == TRUE) {
HDprintf("The supposed deleted attribute %s still exists \n", aname);
HDprintf("verify_del_attrs_compact() test failed \n");
TEST_ERROR;
}
else {
HDprintf("H5Aexists_by_name failed \n");
TEST_ERROR;
}
if (!s->old_style_grp && check_storage == true) {
if (false == check_attr_storage_type(g, is_compact)) {
HDprintf("The attribute storage type is wrong. \n");
TEST_ERROR;
}
dbgf(2, "reader: finish checking the storage type: %d\n", s->np_notify);
}
/* If coming to an "object header continuation block" test,
* we need to check if this test behaves as expected. */
if (s->at_pattern == 'R') {
if (false == check_ohr_num_chunk(g, true)) {
HDprintf("An object header continuation block should be removed. \n");
HDprintf("But it is NOT.\n");
HDprintf("Verification of an 'object header continuation block test' failed.\n");
TEST_ERROR;
}
}
/* Reader sends an OK message back to the reader */
if (s->use_named_pipes && s->attr_test == true) {
if (np_rd_send(s) == false)
TEST_ERROR;
dbgf(2, "reader: finish sending back the message: %d\n", s->np_notify);
}
return true;
error:
/* The reader sends an error message to the writer to stop the test.*/
if (s->use_named_pipes && s->attr_test == true)
np_send_error(s, false);
error2:
return false;
}
/*-------------------------------------------------------------------------
* Function: verify_remove_vlstr_attr
*
* Purpose: Verify if an variable length string attribute is
* successfully deleted by the writer.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* unsigned int which
* Use to derieve the expected attribute value added
* by the writer. It is also used to construct
* the attribute name.
*
*
* Return: Success: true
* Failure: false
*
* Note: This function is for the "remove-vstr" test.
* Also note this function first verifies if
* a variable length attribute is added then
* it verifies if it is deleted successfully.
*-------------------------------------------------------------------------
*/
static bool
verify_remove_vlstr_attr(state_t *s, hid_t g, unsigned int which)
{
bool ret = false;
char attrname[VS_ATTR_NAME_LEN];
const char *aname_format = "attr-%u";
ret = verify_group_vlstr_attr(s, g, which, false);
if (ret == true) {
HDsprintf(attrname, aname_format, which);
ret = verify_del_one_attr(s, g, attrname, false, false);
}
return ret;
}
/*-------------------------------------------------------------------------
* Function: verify_modify_vlstr_attr
*
* Purpose: Verify if an variable length string attribute is
* successfully modified by the writer.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* unsigned int which
* Use to derieve the expected attribute value added
* by the writer. It is also used to construct
* the attribute name.
*
*
* Return: Success: true
* Failure: false
*
* Note: This function is for the "modify-vstr" test.
* Also note this function first verifies if
* a variable length attribute is added then
* it verifies if it is modified successfully.
*-------------------------------------------------------------------------
*/
static bool
verify_modify_vlstr_attr(state_t *s, hid_t g, unsigned int which)
{
bool ret = false;
ret = verify_group_vlstr_attr(s, g, which, false);
if (ret == true)
ret = verify_group_vlstr_attr(s, g, which, true);
return ret;
}
/*-------------------------------------------------------------------------
* Function: verify_attrs_compact
*
* Purpose: Verify if attributes are successfully added for the compact
* storage.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* unsigend max_c
* The maximal number of attributes the compact storage
* can hold
*
* unsigned int which
* Use to derieve the expected attribute value added
* by the writer. It is also used to construct the
* attribute names.
*
*
* Return: Success: true
* Failure: false
*
* Note: This function is used by the "compact" test.
*-------------------------------------------------------------------------
*/
static bool
verify_attrs_compact(state_t *s, hid_t g, unsigned max_c, unsigned int which)
{
unsigned u;
bool ret = true;
const char *aname_format = "attr-%u-%u";
char attrname[VS_ATTR_NAME_LEN];
/* Need to verify the added attribute one by one. */
for (u = 0; u < max_c; u++) {
HDsprintf(attrname, aname_format, which, u);
if (false == vrfy_attr(s, g, u + which, attrname, which, true, true)) {
ret = false;
break;
}
}
return ret;
}
/*-------------------------------------------------------------------------
* Function: verify_attrs_compact_dense
*
* Purpose: Verify if attributes are successfully added first in the
* compact storage then in the dense storage.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* unsigend max_c
* The maximal number of attributes the compact storage
* can hold
*
* unsigned int which
* Use to derieve the expected attribute value added
* by the writer. It is also used to construct
* attribute names.
*
*
* Return: Success: true
* Failure: false
*
* Note: This function is used by the "compact-dense" test.
*-------------------------------------------------------------------------
*/
static bool
verify_attrs_compact_dense(state_t *s, hid_t g, unsigned max_c, unsigned int which)
{
const char *aname_format = "attr-d-%u-%u";
char attrname[VS_ATTR_NAME_LEN];
bool ret = verify_attrs_compact(s, g, max_c, which);
if (ret == true) {
/* Now the storage is in dense. Verify if the
* retrieved value is correct. */
HDsprintf(attrname, aname_format, max_c + which, 0);
ret = vrfy_attr(s, g, which + max_c, attrname, which, true, false);
}
return ret;
}
/*-------------------------------------------------------------------------
* Function: verify_del_attrs_compact
*
* Purpose: Verify if an attribute in compact storage is successfully
* deleted.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* unsigend max_c
* The maximal number of attributes the compact storage
* can hold
*
* unsigned int which
* Use to derieve the expected attribute value added
* by the writer. It is also used to construct
* attribute names.
*
*
* Return: Success: true
* Failure: false
*
* Note: This function is used by the "compact-del" test.
* Also note this function first verifies if
* attributes are successfully added in compact storage then
* it verifies if one added attribute is deleted successfully.
*-------------------------------------------------------------------------
*/
static bool
verify_del_attrs_compact(state_t *s, hid_t g, unsigned max_c, unsigned int which)
{
const char *aname_format = "attr-%u-%u";
char attrname[VS_ATTR_NAME_LEN];
bool ret = verify_attrs_compact(s, g, max_c, which);
if (ret == true) {
/* The writer only deletes the attribute attr-which-0 */
HDsprintf(attrname, aname_format, which, 0);
ret = verify_del_one_attr(s, g, attrname, true, true);
}
return ret;
}
/*-------------------------------------------------------------------------
* Function: verify_del_attrs_compact_dense
*
* Purpose: Verify if an attribute in dense storage is successfully
* deleted.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* unsigend max_c
* The maximal number of attributes the compact storage
* can hold
*
* unsigned int which
* Use to derieve the expected attribute value added
* by the writer. It is also used to construct
* attribute names.
*
*
* Return: Success: true
* Failure: false
*
* Note: This function is used by the "dense-del" test.
* Also note this function first verifies if
* attributes are successfully added in compact storage then
* in dense storage. Afterwards,
* it verifies if one added attribute is deleted successfully.
*-------------------------------------------------------------------------
*/
static bool
verify_del_attrs_compact_dense(state_t *s, hid_t g, unsigned max_c, unsigned int which)
{
const char *aname_format = "attr-d-%u-%u";
char attrname[VS_ATTR_NAME_LEN];
bool ret = verify_attrs_compact_dense(s, g, max_c, which);
if (ret == true) {
/* The writer only deletes the attribute attr-d-which-0 */
HDsprintf(attrname, aname_format, max_c + which, 0);
ret = verify_del_one_attr(s, g, attrname, true, false);
}
return ret;
}
/*-------------------------------------------------------------------------
* Function: verify_del_attrs_compact_dense_compact
*
* Purpose: verify that the attributes are deleted successfully
* even the attribute storage changes from dense to
* compact.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* unsigend max_c
* The maximal number of attributes the compact storage
* can hold
*
* unsigend min_d
* The minimal number of attributes to be stored in
* dense storage
*
* unsigned int which
* Use to derieve the expected attribute value added
* by the writer. It is also used to construct
* attribute names.
*
*
* Return: Success: true
* Failure: false
*
* Note: This function is used by the "dense-del-to-compact" test.
* Also note this function first verifies if
* attributes are successfully added in compact storage then
* in dense storage. Afterwards,
* it verifies if some added attributes are deleted successfully
* until the storage changes from dense to compact.
*-------------------------------------------------------------------------
*/
static bool
verify_del_attrs_compact_dense_compact(state_t *s, hid_t g, unsigned max_c, unsigned min_d,
unsigned int which)
{
unsigned u;
const char *aname_format = "attr-%u-%u";
char attrname[VS_ATTR_NAME_LEN];
/* Verify the attributes are added correctly from
* compact to dense storage*/
bool ret = verify_attrs_compact_dense(s, g, max_c, which);
if (ret == true) {
/* Then verify the deletion of attributes
* from dense to compact.
*/
u = max_c + 1;
for (u--; u >= (min_d - 1); u--) {
HDsprintf(attrname, aname_format, which, max_c - u);
if (u == (min_d - 1))
ret = verify_del_one_attr(s, g, attrname, true, true);
else
ret = verify_del_one_attr(s, g, attrname, true, false);
}
/* Just verify one more deleted attribute by the writer.
The storage is still compact. */
HDsprintf(attrname, aname_format, max_c + which, 0);
ret = verify_del_one_attr(s, g, attrname, true, true);
}
return ret;
}
/*-------------------------------------------------------------------------
* Function: verify_del_ohr_block_attr
*
* Purpose: Verify that an attribute is added to force creation of
* object header continuation block and remove this attribute
* to delete the object header continuation block
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* unsigned int which
* The number of iterations for group creation, use to generate
* group and attribute names.
*
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the verify_group() function.
*-------------------------------------------------------------------------
*/
static bool
verify_del_ohr_block_attr(state_t *s, hid_t g, unsigned int which)
{
bool ret_value = false;
char attrname[VS_ATTR_NAME_LEN];
const char *aname_format = "attr-%u";
ret_value = verify_default_group_attr(s, g, which);
if (ret_value == true) {
HDsprintf(attrname, aname_format, which);
ret_value = verify_del_one_attr(s, g, attrname, false, true);
}
return ret_value;
}
/*-------------------------------------------------------------------------
* Function: verify_group_attribute
*
* Purpose: Check the attribute test pattern and then call the
* correponding verification function.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* HDF5 object ID (in this file: means group ID)
*
* unsigned int which
* The number of iterations for group creation, use to generate
* group and attribute names.
*
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the verify_group() function.
*-------------------------------------------------------------------------
*/
static bool
verify_group_attribute(state_t *s, hid_t g, unsigned int which)
{
char test_pattern = s->at_pattern;
bool ret = false;
unsigned max_compact = 0;
unsigned min_dense = 0;
hid_t gcpl = H5I_INVALID_HID;
/* For tests "compact","compact-to-dense","compact-del",
* "dense-del", "dense-del-to-compact",
* the maximal number of attributes for the compact storage
* and the minimal number of attributes for the dense storage
* are needed. So obtain them here
* When testing the old-style group creation case, only max_compact
* matters. To reduce the testing time, we set max_compact to 2.*/
switch (test_pattern) {
case 'c':
case 't':
case 'C':
case 'D':
case 'T':
if (s->old_style_grp)
max_compact = 2;
else {
if ((gcpl = H5Gget_create_plist(g)) < 0) {
HDprintf("H5Gget_create_plist failed\n");
TEST_ERROR;
}
if (H5Pget_attr_phase_change(gcpl, &max_compact, &min_dense) < 0) {
HDprintf("H5Pget_attr_phase_change failed\n");
TEST_ERROR;
}
if (H5Pclose(gcpl) < 0) {
HDprintf("H5Pclose failed\n");
TEST_ERROR;
}
}
break;
case 'v':
case 'd':
case 'M':
case 'm':
case 'r':
case 'a':
case 'R':
case ' ':
default:
break;
}
/* Distribute the verification test. */
switch (test_pattern) {
case 'c':
ret = verify_attrs_compact(s, g, max_compact, which);
break;
case 't':
ret = verify_attrs_compact_dense(s, g, max_compact, which);
break;
case 'C':
ret = verify_del_attrs_compact(s, g, max_compact, which);
break;
case 'D':
ret = verify_del_attrs_compact_dense(s, g, max_compact, which);
break;
case 'T':
ret = verify_del_attrs_compact_dense_compact(s, g, max_compact, min_dense, which);
break;
case 'M':
ret = verify_modify_attr(s, g, which);
break;
case 'v':
ret = verify_group_vlstr_attr(s, g, which, false);
break;
case 'r':
ret = verify_remove_vlstr_attr(s, g, which);
break;
case 'm':
ret = verify_modify_vlstr_attr(s, g, which);
break;
case 'R':
ret = verify_del_ohr_block_attr(s, g, which);
break;
case 'a':
case 'd':
case ' ':
default:
ret = verify_default_group_attr(s, g, which);
break;
}
return ret;
error:
/* Still to finish the handshaking */
if (s->use_named_pipes && s->attr_test == true) {
np_rd_receive(s);
np_send_error(s, false);
}
return false;
}
/*-------------------------------------------------------------------------
* Function: verify_group
*
* Purpose: verify the success of group creation and
* carry out the test for attribute operations(add,delete etc.)
* according to the attribute test pattern.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* unsigned int which
* The number of iterations for group creation
*
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the main() function.
*-------------------------------------------------------------------------
*/
static bool
verify_group(state_t *s, unsigned int which)
{
char name[sizeof("/group-9999999999")];
hid_t g = H5I_INVALID_HID;
bool result = true;
H5G_info_t group_info;
/* The reader receives a message from the writer.Then sleep
* for a few ticks or stop the test if the received message
* is an error message.
*/
if (s->use_named_pipes && true == s->attr_test) {
if (false == np_rd_receive(s)) {
H5_FAILED();
AT();
goto error2;
}
decisleep(s->tick_len * s->update_interval);
dbgf(1, "reader: finish reading the message: %d\n", s->np_notify);
}
if (which >= s->nsteps) {
HDprintf("Number of created groups is out of bounds\n");
TEST_ERROR;
}
esnprintf(name, sizeof(name), "/group-%u", which);
if ((g = H5Gopen(s->file, name, H5P_DEFAULT)) < 0) {
HDprintf("H5Gopen failed\n");
TEST_ERROR;
}
if (H5Gget_info(g, &group_info) < 0) {
HDprintf("H5Gget_info failed\n");
TEST_ERROR;
}
dbgf(2, "Storage info is %d\n", group_info.storage_type);
if (s->old_style_grp) {
if (group_info.storage_type != H5G_STORAGE_TYPE_SYMBOL_TABLE) {
HDprintf("Reader - Old-styled group: but the group is not in old-style. \n");
TEST_ERROR;
}
dbgf(2, "Reader: verify that the group is created with the old-style.\n");
}
else {
if (group_info.storage_type == H5G_STORAGE_TYPE_SYMBOL_TABLE) {
HDprintf("Reader - The created group should NOT be in old-style . \n");
TEST_ERROR;
}
dbgf(2, "Reader: verify that the group is created with the new-style.\n");
}
/* If coming to an "object header continuation block" test,
* we need to check if this test behaves as expected. */
if (s->at_pattern == 'a' || s->at_pattern == 'R') {
if (false == check_ohr_num_chunk(g, true)) {
HDprintf("An object header continuation block should NOT be created. \n");
HDprintf("But it is created.\n");
HDprintf("Verification of an 'object header continuation block test' failed.\n");
TEST_ERROR;
}
}
/* Reader sends an OK message back to the writer */
if (s->use_named_pipes && s->attr_test == true) {
if (np_rd_send(s) == false)
TEST_ERROR;
dbgf(1, "Reader: finish sending back the message: %d\n", s->np_notify);
}
/* Check if we need to skip the attribute test for this group. */
if (s->asteps != 0 && which % s->asteps == 0)
result = verify_group_attribute(s, g, which);
else
result = true;
if (H5Gclose(g) < 0) {
HDprintf("H5Gclose failed\n");
TEST_ERROR;
}
return result;
error:
H5E_BEGIN_TRY
{
H5Gclose(g);
}
H5E_END_TRY;
/* The reader sends an error message to the writer to stop the test.*/
if (s->use_named_pipes && s->attr_test == true)
np_send_error(s, false);
error2:
return false;
}
/*-------------------------------------------------------------------------
* Function: create_group_id
*
* Purpose: Create a group and return the group ID.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* unsigned int which
* The number of iterations for group creation
* This is used to generate the group name.
*
* bool dense_to_compact
* true if this function is used to test the transition from dense to
* compact, false if the test is from compact to dense.
*
* Return: Success: the group ID
* Failure: -1
*
* Note: Only used by testing the link storage transit functions.
*-------------------------------------------------------------------------
*/
static hid_t
create_group_id(state_t *s, unsigned int which, bool dense_to_compact)
{
char name[sizeof("/group-9999999999")];
hid_t g = H5I_INVALID_HID;
hid_t gcpl = H5I_INVALID_HID;
H5G_info_t group_info;
if (which >= s->nsteps) {
HDprintf("Number of created groups is out of bounds\n");
TEST_ERROR;
}
gcpl = H5Pcreate(H5P_GROUP_CREATE);
if (gcpl < 0) {
HDprintf("H5Pcreate failed\n");
TEST_ERROR;
}
if (dense_to_compact) {
if (H5Pset_link_phase_change(gcpl, 2, 2) < 0) {
HDprintf("H5Pset_link_phase_change failed for dense to compact.\n");
TEST_ERROR;
}
}
else {
if (H5Pset_link_phase_change(gcpl, 1, 1) < 0) {
HDprintf("H5Pset_attr_phase_change failed for compact to dense.\n");
TEST_ERROR;
}
}
esnprintf(name, sizeof(name), "/group-%u", which);
if ((g = H5Gcreate2(s->file, name, H5P_DEFAULT, gcpl, H5P_DEFAULT)) < 0) {
HDprintf("H5Gcreate2 failed\n");
TEST_ERROR;
}
if (H5Gget_info(g, &group_info) < 0) {
HDprintf("H5Gget_info failed\n");
TEST_ERROR;
}
/* The storage type should always be compact when a group is created. */
if (group_info.storage_type != H5G_STORAGE_TYPE_COMPACT) {
HDprintf("New-style group link storage test:. \n");
HDprintf(" still be compact after group creation. \n");
TEST_ERROR;
}
if (H5Pclose(gcpl) < 0) {
HDprintf("H5Pclose failed\n");
TEST_ERROR;
}
/* If a grp_op_test is turned on and named pipes are used,
* the writer should send and receive messages after the group creation.
* Writer sends a message to reader: a group is successfully created.
* then wait for the reader to verify and send an acknowledgement message back.*/
if (s->use_named_pipes && s->grp_op_test == true) {
dbgf(2, "Writer: ready to send the message: %d\n", s->np_notify + 1);
if (np_wr_send_receive(s) == false) {
H5_FAILED();
AT();
/* Note: This is (mostly) because the verification failure message
* from the reader. So don't send the error message back to
* the reader. Just stop the test. */
goto error2;
}
}
return g;
error:
/* Writer needs to send an error message to the reader to stop the test*/
if (s->use_named_pipes && s->grp_op_test == true)
np_send_error(s, true);
error2:
H5E_BEGIN_TRY
{
H5Pclose(gcpl);
}
H5E_END_TRY;
return -1;
}
/*-------------------------------------------------------------------------
* Function: close_group_id
*
* Purpose: Verify is a group is closed successfully.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* The ID of the group to be closed.
*
* Return: Success: true
* Failure: false
*
* Note: This is used by the link storage transit functions.
*-------------------------------------------------------------------------
*/
static bool
close_group_id(state_t *s, hid_t g)
{
if (H5Gclose(g) < 0) {
HDprintf("H5Gclose failed\n");
TEST_ERROR;
}
/* If a grp_op_test is turned on and named pipes are used, for
* link storage test,
* Writer sends a message to reader: the group is successfully closed.
* then wait for the reader to verify and send an acknowledgement message back.*/
if (s->use_named_pipes && s->grp_op_test == true) {
dbgf(2, "Writer: ready to send the message: %d\n", s->np_notify + 1);
if (np_wr_send_receive(s) == false) {
H5_FAILED();
AT();
goto error2;
}
}
return true;
error:
/* Writer needs to send an error message to the reader to stop the test*/
if (s->use_named_pipes && s->grp_op_test == true)
np_send_error(s, true);
error2:
return false;
}
/*-------------------------------------------------------------------------
* Function: create_group
*
* Purpose: Create a group
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* unsigned int which
* The number of iterations for group creation
* This is used to generate the group name.
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the main() function.
*-------------------------------------------------------------------------
*/
static bool
create_group(state_t *s, unsigned int which)
{
char name[sizeof("/group-9999999999")];
hid_t g = H5I_INVALID_HID;
H5G_info_t group_info;
if (which >= s->nsteps) {
HDprintf("Number of created groups is out of bounds\n");
TEST_ERROR;
}
esnprintf(name, sizeof(name), "/group-%u", which);
if ((g = H5Gcreate2(s->file, name, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
HDprintf("H5Gcreate2 failed\n");
TEST_ERROR;
}
if (H5Gget_info(g, &group_info) < 0) {
HDprintf("H5Gget_info failed\n");
TEST_ERROR;
}
if (s->old_style_grp) {
if (group_info.storage_type != H5G_STORAGE_TYPE_SYMBOL_TABLE) {
HDprintf("Old-styled group test: but the group is not in old-style. \n");
TEST_ERROR;
}
dbgf(2, "Writer: group is created with the old-style.\n");
}
else {
if (group_info.storage_type == H5G_STORAGE_TYPE_SYMBOL_TABLE) {
HDprintf("The created group should NOT be in old-style . \n");
TEST_ERROR;
}
dbgf(2, "Writer: group is created with the new-style.\n");
}
if (H5Gclose(g) < 0) {
HDprintf("H5Gclose failed\n");
TEST_ERROR;
}
/* Writer sends a message to reader,
* then wait for the reader to verify and send an acknowledgement message back.*/
if (s->use_named_pipes && s->grp_op_test == true) {
dbgf(2, "Writer: ready to send the message: %d\n", s->np_notify + 1);
if (np_wr_send_receive(s) == false) {
H5_FAILED();
AT();
goto error2;
}
}
return true;
error:
/* Writer needs to send an error message to the reader to stop the test*/
if (s->use_named_pipes && s->grp_op_test == true)
np_send_error(s, true);
error2:
H5E_BEGIN_TRY
{
H5Gclose(g);
}
H5E_END_TRY;
return false;
}
/*-------------------------------------------------------------------------
* Function: delete_one_link
*
* Purpose: Delete a link(either hard/soft) in group operation tests.
* according to the group test pattern.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t obj_id
* The HDF5 object ID that the deleted link is attached to.
*
* const char *name
* The name of the link to be deleted.
*
* short link_storage
* <=0: link storage is ignored.
* 1: link storage should be compact after link deletion..
* >1: link storage should be dense after link deletion.
*
* unsigned int which
* The number of iterations for group creation
*
*
* Return: Success: true
* Failure: false
*
* Note: This is used by delete_groups() and delete_links() functions.
*-------------------------------------------------------------------------
*/
static bool
delete_one_link(state_t *s, hid_t obj_id, const char *name, short link_storage, unsigned int which)
{
H5G_info_t group_info;
if (which >= s->nsteps) {
HDprintf("Number of created groups is out of bounds\n");
TEST_ERROR;
}
if (H5Ldelete(obj_id, name, H5P_DEFAULT) < 0) {
HDprintf("H5Ldelete failed\n");
TEST_ERROR;
}
if (link_storage > 0) {
if (s->old_style_grp) {
HDprintf("Old style group doesn't support the indexed storage.\n");
TEST_ERROR;
}
if (H5Gget_info(obj_id, &group_info) < 0) {
HDprintf("H5Gget_info failed\n");
TEST_ERROR;
}
if (link_storage == 1) {
if (group_info.storage_type != H5G_STORAGE_TYPE_COMPACT) {
HDprintf("The group link storage should be compact. \n");
TEST_ERROR;
}
}
else {
if (group_info.storage_type != H5G_STORAGE_TYPE_DENSE) {
HDprintf("The group link storage should be dense. \n");
TEST_ERROR;
}
}
}
/* Writer sends a message to reader:
* then wait for the reader to verify and send an acknowledgement message back.*/
if (s->use_named_pipes && s->grp_op_test == true) {
dbgf(2, "writer: ready to send the message: %d\n", s->np_notify + 1);
if (np_wr_send_receive(s) == false) {
H5_FAILED();
AT();
goto error2;
}
}
return true;
error:
/* Writer needs to send an error message to the reader to stop the test*/
if (s->use_named_pipes && s->grp_op_test == true)
np_send_error(s, true);
error2:
return false;
}
/*-------------------------------------------------------------------------
* Function: delete_group
*
* Purpose: Delete a group and carry out group operations(add,delete etc.)
* according to the group operation test pattern.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* unsigned int which
* The number of iterations for group creation
* This is used to generate the group name
*
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the group_operations() function.
*-------------------------------------------------------------------------
*/
static bool
delete_group(state_t *s, unsigned int which)
{
char name[sizeof("/group-9999999999")];
bool ret_value = create_group(s, which);
if (ret_value == true) {
esnprintf(name, sizeof(name), "/group-%u", which);
ret_value = delete_one_link(s, s->file, name, 0, which);
}
return ret_value;
}
/*-------------------------------------------------------------------------
* Function: move_one_group
*
* Purpose: A helper function used by the move_group operation.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t obj_id
* ID of the object this group is attached to
*
* const char *name
* The original group name
*
* const char *newname
* The new group name
*
* unsigned int which
* The number of iterations for group creation
*
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the move_group() function.
*-------------------------------------------------------------------------
*/
static bool
move_one_group(state_t *s, hid_t obj_id, const char *name, const char *newname, unsigned int which)
{
if (which >= s->nsteps) {
HDprintf("Number of created groups is out of bounds\n");
TEST_ERROR;
}
if (H5Lmove(obj_id, name, obj_id, newname, H5P_DEFAULT, H5P_DEFAULT) < 0) {
HDprintf("H5Ldelete failed\n");
TEST_ERROR;
}
/* Writer sends a message to reader:
* then wait for the reader to verify and send an acknowledgement message back.*/
if (s->use_named_pipes && s->grp_op_test == true) {
dbgf(2, "writer: ready to send the message: %d\n", s->np_notify + 1);
if (np_wr_send_receive(s) == false) {
H5_FAILED();
AT();
goto error2;
}
}
return true;
error:
/* Writer needs to send an error message to the reader to stop the test*/
if (s->use_named_pipes && s->grp_op_test == true)
np_send_error(s, true);
error2:
return false;
}
/*-------------------------------------------------------------------------
* Function: move_group
*
* Purpose: Move a group to another group.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* unsigned int which
* The number of iterations for group creation
* used to generate the group name.
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the group_operations() function.
*-------------------------------------------------------------------------
*/
static bool
move_group(state_t *s, unsigned int which)
{
char name[sizeof("/group-9999999999")];
char new_name[sizeof("/new-group-9999999999")];
bool ret_value = create_group(s, which);
if (ret_value == true) {
esnprintf(name, sizeof(name), "/group-%u", which);
esnprintf(new_name, sizeof(new_name), "/new-group-%u", which);
ret_value = move_one_group(s, s->file, name, new_name, which);
}
return ret_value;
}
/*-------------------------------------------------------------------------
* Function: insert_one_link
*
* Purpose: A helper function used to attach a link to a group.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t obj_id
* ID of the object this link is attached to
*
* const char *name
* The name of the target object used by creating links
*
* const char *newname
* The name of the linked objects
*
* bool is_hard
* true if inserting a hard link
* false if inserting a soft link
*
* short link_storage
* <=0: link storage is ignored.
* 1: link storage should be compact.
* >1: link storage should be dense.
* unsigned int which
* The number of iterations for group creation
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the insert_links and link storage transit functions.
* For link storage, we test at both the writer and the reader.
*-------------------------------------------------------------------------
*/
static bool
insert_one_link(state_t *s, hid_t obj_id, const char *name, const char *newname, bool is_hard,
short link_storage, unsigned int which)
{
H5G_info_t group_info;
if (which >= s->nsteps) {
HDprintf("Number of created groups is out of bounds\n");
TEST_ERROR;
}
/* For storage transit and insert_links cases, we
* create links in different style, just add a little
* variation of the tests.*/
if (is_hard) {
if (link_storage > 0) {
if (H5Lcreate_hard(s->file, name, obj_id, newname, H5P_DEFAULT, H5P_DEFAULT) < 0) {
HDprintf("H5Lcreate_hard failed\n");
TEST_ERROR;
}
}
else {
if (H5Lcreate_hard(obj_id, name, obj_id, newname, H5P_DEFAULT, H5P_DEFAULT) < 0) {
HDprintf("H5Lcreate_hard failed\n");
TEST_ERROR;
}
}
}
else {
if (link_storage > 0) {
if (H5Lcreate_soft("/", obj_id, newname, H5P_DEFAULT, H5P_DEFAULT) < 0) {
HDprintf("H5Lcreate_soft failed\n");
TEST_ERROR;
}
}
else {
if (H5Lcreate_soft(name, obj_id, newname, H5P_DEFAULT, H5P_DEFAULT) < 0) {
HDprintf("H5Lcreate_soft failed.\n");
TEST_ERROR;
}
}
}
if (link_storage > 0) {
if (s->old_style_grp) {
HDprintf("Old style group doesn't support dense or compact storage.\n");
TEST_ERROR;
}
if (H5Gget_info(obj_id, &group_info) < 0) {
HDprintf("H5Gget_info failed\n");
TEST_ERROR;
}
if (link_storage == 1) {
if (group_info.storage_type != H5G_STORAGE_TYPE_COMPACT) {
HDprintf("The group link storage should be compact. \n");
TEST_ERROR;
}
}
else {
if (group_info.storage_type != H5G_STORAGE_TYPE_DENSE) {
HDprintf("The group link storage should be dense. \n");
TEST_ERROR;
}
}
}
/* Writer sends a message to reader,
* then wait for the reader to verify and send an acknowledgement message back.*/
if (s->use_named_pipes && s->grp_op_test == true) {
dbgf(2, "writer: ready to send the message: %d\n", s->np_notify + 1);
if (np_wr_send_receive(s) == false) {
H5_FAILED();
AT();
goto error2;
}
}
return true;
error:
/* Writer needs to send an error message to the reader to stop the test*/
if (s->use_named_pipes && s->grp_op_test == true)
np_send_error(s, true);
error2:
return false;
}
/*-------------------------------------------------------------------------
* Function: insert_links
*
* Purpose: create links with a group.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* unsigned int which
* The number of iterations
* used to generate the group name.
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the group_operations() function.
*-------------------------------------------------------------------------
*/
static bool
insert_links(state_t *s, unsigned int which)
{
char name[sizeof("/group-9999999999")];
char hd_name[sizeof("/hd-group-9999999999")];
char st_name[sizeof("/st-group-9999999999")];
bool ret_value = create_group(s, which);
if (ret_value == true) {
esnprintf(name, sizeof(name), "/group-%u", which);
esnprintf(hd_name, sizeof(hd_name), "/hd-group-%u", which);
esnprintf(st_name, sizeof(st_name), "/st-group-%u", which);
ret_value = insert_one_link(s, s->file, name, hd_name, true, 0, which);
if (ret_value == true)
ret_value = insert_one_link(s, s->file, name, st_name, false, 0, which);
}
return ret_value;
}
/*-------------------------------------------------------------------------
* Function: delete_links
*
* Purpose: create links with a group and then delete them successfully.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* unsigned int which
* The number of iterations
* used to generate the group name.
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the group_operations() function.
*-------------------------------------------------------------------------
*/
static bool
delete_links(state_t *s, unsigned int which)
{
char name[sizeof("/group-9999999999")];
char hd_name[sizeof("/hd-group-9999999999")];
char st_name[sizeof("/st-group-9999999999")];
bool ret_value = insert_links(s, which);
if (ret_value == true) {
esnprintf(name, sizeof(name), "/group-%u", which);
esnprintf(hd_name, sizeof(hd_name), "/hd-group-%u", which);
esnprintf(st_name, sizeof(st_name), "/st-group-%u", which);
ret_value = delete_one_link(s, s->file, hd_name, 0, which);
if (ret_value == true)
ret_value = delete_one_link(s, s->file, st_name, 0, which);
}
return ret_value;
}
/*-------------------------------------------------------------------------
* Function: transit_storage_compact_to_dense
*
* Purpose: Add links so that the link storage transits from
* compact to dense.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* unsigned int which
* The number of iterations used to generate the group name.
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the group_operations() function.
*-------------------------------------------------------------------------
*/
static bool
transit_storage_compact_to_dense(state_t *s, unsigned int which)
{
char name[sizeof("/group-9999999999")];
char hd_name[sizeof("/hd-group-9999999999")];
char st_name[sizeof("/st-group-9999999999")];
hid_t g = create_group_id(s, which, false);
if (g < 0) {
HDprintf("create_group_id failed\n");
TEST_ERROR;
}
/* First insert a hard link, compact storage. */
esnprintf(name, sizeof(name), "/group-%u", which);
esnprintf(hd_name, sizeof(hd_name), "hd-group-%u", which);
if (insert_one_link(s, g, name, hd_name, true, 1, which) == false) {
HDprintf("insert_one_link for compact storage failed\n");
TEST_ERROR;
}
/* Then insert a soft link, the storage becomes dense. */
esnprintf(st_name, sizeof(st_name), "st-group-%u", which);
if (insert_one_link(s, g, name, st_name, false, 2, which) == false) {
HDprintf("insert_one_link for dense storage failed\n");
TEST_ERROR;
}
if (close_group_id(s, g) == false) {
HDprintf("insert_one_link for dense storage failed\n");
TEST_ERROR;
}
return true;
error:
H5E_BEGIN_TRY
{
H5Gclose(g);
}
H5E_END_TRY;
return false;
}
/*-------------------------------------------------------------------------
* Function: transit_storage_dense_to_compact
*
* Purpose: Add or delete links so that the link storage transits from
* compact to dense then to compact.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* unsigned int which
* The number of iterations used to generate the group name.
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the group_operations() function.
*-------------------------------------------------------------------------
*/
static bool
transit_storage_dense_to_compact(state_t *s, unsigned int which)
{
char name[sizeof("/group-9999999999")];
char hd_name[sizeof("/hd-group-9999999999")];
char st_name[sizeof("st-group-9999999999")];
char st2_name[sizeof("st2-group-9999999999")];
hid_t g = create_group_id(s, which, true);
if (g < 0) {
HDprintf("create_group_id failed\n");
TEST_ERROR;
}
/* Insert a link, storage is compact. */
esnprintf(name, sizeof(name), "/group-%u", which);
esnprintf(hd_name, sizeof(hd_name), "hd-group-%u", which);
if (insert_one_link(s, g, name, hd_name, true, 1, which) == false) {
HDprintf("insert_one_link for compact storage failed\n");
TEST_ERROR;
}
/* Insert a link, storage is still compact. */
esnprintf(st_name, sizeof(st_name), "st-group-%u", which);
if (insert_one_link(s, g, name, st_name, false, 1, which) == false) {
HDprintf("insert_one_link for compact storage failed\n");
TEST_ERROR;
}
/* Insert a link, storage becomes dense. */
esnprintf(st2_name, sizeof(st2_name), "st2-group-%u", which);
if (insert_one_link(s, g, name, st2_name, false, 2, which) == false) {
HDprintf("insert_one_link for dense storage failed\n");
TEST_ERROR;
}
/* Delete a link, storage is still dense */
if (delete_one_link(s, g, st_name, 2, which) == false) {
HDprintf("delete_one_link for dense storage failed\n");
TEST_ERROR;
}
/* Delete another link, storage becomes compact */
if (delete_one_link(s, g, st2_name, 1, which) == false) {
HDprintf("delete_one_link for compact storage failed\n");
TEST_ERROR;
}
if (close_group_id(s, g) == false) {
HDprintf("insert_one_link for dense storage failed\n");
TEST_ERROR;
}
return true;
error:
H5E_BEGIN_TRY
{
H5Gclose(g);
}
H5E_END_TRY;
return false;
}
/*-------------------------------------------------------------------------
* Function: group_operations
*
* Purpose: Carry out group and attribute operations(add,delete etc.)
* according to the group operation and attribute test patterns.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* unsigned int which
* The number of iterations for group creation
*
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the main() function. The check of attribute
* operations is inside the write_group() function.
*-------------------------------------------------------------------------
*/
static bool
group_operations(state_t *s, unsigned int which)
{
bool ret_value = false;
char test_pattern = s->grp_op_pattern;
switch (test_pattern) {
case 'c':
ret_value = create_group(s, which);
break;
case 'd':
ret_value = delete_group(s, which);
break;
case 'm':
ret_value = move_group(s, which);
break;
case 'i':
ret_value = insert_links(s, which);
break;
case 'D':
ret_value = delete_links(s, which);
break;
case 't':
ret_value = transit_storage_compact_to_dense(s, which);
break;
case 'T':
ret_value = transit_storage_dense_to_compact(s, which);
break;
case ' ':
default:
ret_value = write_group(s, which);
break;
}
return ret_value;
}
/*-------------------------------------------------------------------------
* Function: vrfy_create_group
*
* Purpose: Verify if a group can be created successfully.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* unsigned int which
* The number of iterations for group creation
* used to generate the group name.
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the verify_group_operations() function.
*-------------------------------------------------------------------------
*/
static bool
vrfy_create_group(state_t *s, unsigned int which)
{
char name[sizeof("/group-9999999999")];
hid_t g = H5I_INVALID_HID;
H5G_info_t group_info;
dbgf(2, "reader: ready to send the message: \n");
/* The reader receives a message from the writer.Then sleep
* for a few ticks or stop the test if the received message
* is an error message.
*/
if (s->use_named_pipes && true == s->grp_op_test) {
if (false == np_rd_receive(s)) {
H5_FAILED();
AT();
goto error2;
}
decisleep(s->tick_len * s->update_interval);
dbgf(1, "reader: finish reading the message: %d\n", s->np_notify);
}
if (which >= s->nsteps) {
HDprintf("Number of created groups is out of bounds\n");
TEST_ERROR;
}
esnprintf(name, sizeof(name), "/group-%u", which);
if ((g = H5Gopen(s->file, name, H5P_DEFAULT)) < 0) {
HDprintf("H5Gopen failed\n");
TEST_ERROR;
}
if (H5Gget_info(g, &group_info) < 0) {
HDprintf("H5Gget_info failed\n");
TEST_ERROR;
}
dbgf(2, "Storage info is %d\n", group_info.storage_type);
if (s->old_style_grp) {
if (group_info.storage_type != H5G_STORAGE_TYPE_SYMBOL_TABLE) {
HDprintf("Reader - Old-styled group: but the group is not in old-style. \n");
TEST_ERROR;
}
dbgf(2, "Reader: verify that the group is created with the old-style.\n");
}
else {
if (group_info.storage_type == H5G_STORAGE_TYPE_SYMBOL_TABLE) {
HDprintf("Reader - The created group should NOT be in old-style . \n");
TEST_ERROR;
}
dbgf(2, "Reader: verify that the group is created with the new-style.\n");
}
if (H5Gclose(g) < 0) {
HDprintf("H5Gclose failed\n");
TEST_ERROR;
}
/* Reader sends an OK message back to the writer */
if (s->use_named_pipes && s->grp_op_test == true) {
if (np_rd_send(s) == false)
TEST_ERROR;
dbgf(1, "Reader: finish sending back the message: %d\n", s->np_notify);
}
return true;
error:
H5E_BEGIN_TRY
{
H5Gclose(g);
}
H5E_END_TRY;
/* The reader sends an error message to the writer to stop the test.*/
if (s->use_named_pipes && s->grp_op_test == true)
np_send_error(s, false);
error2:
return false;
}
/*-------------------------------------------------------------------------
* Function: vrfy_create_group_id
*
* Purpose: Verify if a group is created successfully and return the group
* ID.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* unsigned int which
* The number of iterations for group creation
* used to generate the group name.
*
* bool dense_to_compact
* true if this function is used to test the transition from dense to
* compact, false if the test is from compact to dense.
*
* Return: Success: the group ID
* Failure: -1
*
* Note: This function is used by the link storage transit functions.
*-------------------------------------------------------------------------
*/
static hid_t
vrfy_create_group_id(state_t *s, unsigned int which, bool dense_to_compact)
{
char name[sizeof("/group-9999999999")];
hid_t g = H5I_INVALID_HID;
hid_t gcpl = H5I_INVALID_HID;
H5G_info_t group_info;
unsigned max_compact = 0;
unsigned min_dense = 0;
dbgf(2, "reader: ready to receive a message: \n");
/* The reader receives a message from the writer.Then sleep
* for a few ticks or stop the test if the received message
* is an error message.
*/
if (s->use_named_pipes && true == s->grp_op_test) {
if (false == np_rd_receive(s)) {
H5_FAILED();
AT();
goto error2;
}
decisleep(s->tick_len * s->update_interval);
dbgf(1, "reader: finish reading the message: %d\n", s->np_notify);
}
if (which >= s->nsteps) {
HDprintf("Number of the created groups is out of bounds\n");
TEST_ERROR;
}
esnprintf(name, sizeof(name), "/group-%u", which);
if ((g = H5Gopen(s->file, name, H5P_DEFAULT)) < 0) {
HDprintf("H5Gopen failed\n");
TEST_ERROR;
}
if ((gcpl = H5Gget_create_plist(g)) < 0) {
HDprintf("H5Gget_create_plist failed\n");
TEST_ERROR;
}
if (H5Pget_link_phase_change(gcpl, &max_compact, &min_dense) < 0) {
HDprintf("H5Pget_link_phase_change failed\n");
TEST_ERROR;
}
if (dense_to_compact) {
if (max_compact != 2) {
HDprintf("For storage check from dense to compact:\n");
HDprintf(" The max_compact should be 2.\n");
HDprintf(" But the actual value is %d.\n", max_compact);
TEST_ERROR;
}
else if (min_dense != 2) {
HDprintf("For storage check from dense to compact:\n");
HDprintf(" The min_dense should be 2.\n");
HDprintf(" But the actual value is %d.\n", min_dense);
TEST_ERROR;
}
}
else {
if (max_compact != 1) {
HDprintf("For storage check from dense to compact:\n");
HDprintf(" The max_compact should be 1.\n");
HDprintf(" But the actual value is %d.\n", max_compact);
TEST_ERROR;
}
else if (min_dense != 1) {
HDprintf("For storage check from dense to compact:\n");
HDprintf(" The min_dense should be 1.\n");
HDprintf(" But the actual value is %d.\n", min_dense);
TEST_ERROR;
}
}
if (H5Pclose(gcpl) < 0) {
HDprintf("H5Pclose failed\n");
TEST_ERROR;
}
if (H5Gget_info(g, &group_info) < 0) {
HDprintf("H5Gget_info failed\n");
TEST_ERROR;
}
/* When the group is created, the storage type is always compact. */
if (group_info.storage_type != H5G_STORAGE_TYPE_COMPACT) {
HDprintf("Old-styled group test: but the group is not in old-style. \n");
TEST_ERROR;
}
dbgf(2, "Storage info is %d\n", group_info.storage_type);
/* Reader sends an OK message back to the reader */
if (s->use_named_pipes && s->grp_op_test == true) {
if (np_rd_send(s) == false)
TEST_ERROR;
dbgf(1, "Reader: finish sending back the message: %d\n", s->np_notify);
}
return g;
error:
H5E_BEGIN_TRY
{
H5Gclose(g);
H5Pclose(gcpl);
}
H5E_END_TRY;
/* The reader sends an error message to the writer to stop the test.*/
if (s->use_named_pipes && s->grp_op_test == true)
np_send_error(s, false);
error2:
return -1;
}
/*-------------------------------------------------------------------------
* Function: vrfy_close_group_id
*
* Purpose: Verify if a group is closed successfully.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t g
* The ID of the group to be closed.
*
* Return: Success: true
* Failure: false
*
* Note: This is used by the link storage transit functions.
*-------------------------------------------------------------------------
*/
static bool
vrfy_close_group_id(state_t *s, hid_t g)
{
/* The reader receives a message from the writer.Then sleep
* for a few ticks or stop the test if the received message
* is an error message.
*/
if (s->use_named_pipes && true == s->grp_op_test) {
if (false == np_rd_receive(s)) {
H5_FAILED();
AT();
goto error2;
}
decisleep(s->tick_len * s->update_interval);
dbgf(1, "reader: finish reading the message: %d\n", s->np_notify);
}
if (H5Gclose(g) < 0) {
HDprintf("H5Gclose failed\n");
TEST_ERROR;
}
/* Reader sends an OK message back to the reader */
if (s->use_named_pipes && s->grp_op_test == true) {
if (np_rd_send(s) == false)
TEST_ERROR;
dbgf(1, "Reader: finish sending back the message: %d\n", s->np_notify);
}
return true;
error:
/* The reader sends an error message to the writer to stop the test.*/
if (s->use_named_pipes && s->grp_op_test == true)
np_send_error(s, false);
error2:
return false;
}
/*-------------------------------------------------------------------------
* Function: vrfy_one_link_exist
*
* Purpose: Verify if a link exists or not. The link storage is
* also checked.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t obj_id
* The ID of the object the link is attached to
*
* bool expect_exist
* A flag that indicates if this link is expected to exist
*
* short link_storage
* <=0: link storage check is ignored.
* 1: link storage is expected to be compact.
* >1: link storage is expected to be dense.
*
* Return: Success: true
* Failure: false
*
* Note: Helper function to check if links are inserted or deleted.
* The link storage is also checked.
*-------------------------------------------------------------------------
*/
static bool
vrfy_one_link_exist(state_t *s, hid_t obj_id, const char *name, bool expect_exist, short link_storage)
{
int link_exists = 0;
H5G_info_t group_info;
dbgf(2, "reader: ready to send the message: \n");
/* The reader receives a message from the writer.Then sleep
* for a few ticks or stop the test if the received message
* is an error message.
*/
if (s->use_named_pipes && true == s->grp_op_test) {
if (false == np_rd_receive(s)) {
H5_FAILED();
AT();
goto error2;
}
decisleep(s->tick_len * s->update_interval);
dbgf(1, "reader: finish reading the message: %d\n", s->np_notify);
}
link_exists = H5Lexists(obj_id, name, H5P_DEFAULT);
if (link_exists < 0) {
HDprintf("H5Lexists error\n");
TEST_ERROR;
}
else if (link_exists == 1) {
if (expect_exist == false) {
HDprintf("This link should be moved or deleted but it still exists.\n");
TEST_ERROR;
}
}
else if (link_exists == 0) {
if (expect_exist == true) {
HDprintf("This link should exist but it is moved or deleted.\n");
TEST_ERROR;
}
}
if (link_storage > 0) {
if (s->old_style_grp) {
HDprintf("Old style group doesn't support the indexed storage.\n");
TEST_ERROR;
}
if (H5Gget_info(obj_id, &group_info) < 0) {
HDprintf("H5Gget_info failed\n");
TEST_ERROR;
}
if (link_storage == 1) {
if (group_info.storage_type != H5G_STORAGE_TYPE_COMPACT) {
HDprintf("The group link storage should be compact. \n");
TEST_ERROR;
}
}
else {
if (group_info.storage_type != H5G_STORAGE_TYPE_DENSE) {
HDprintf("The group link storage should be dense. \n");
TEST_ERROR;
}
}
}
/* Reader sends an OK message back to the reader */
if (s->use_named_pipes && s->grp_op_test == true) {
if (np_rd_send(s) == false) {
TEST_ERROR;
}
dbgf(1, "Reader: finish sending back the message: %d\n", s->np_notify);
}
return true;
error:
/* The reader sends an error message to the writer to stop the test.*/
if (s->use_named_pipes && s->grp_op_test == true)
np_send_error(s, false);
error2:
return false;
}
/*-------------------------------------------------------------------------
* Function: vrfy_delete_group
*
* Purpose: Verify if a group can be deleted successfully.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* unsigned int which
* The number of iterations for group creation
* used to generate the group name.
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the verify_group_operations() function.
*-------------------------------------------------------------------------
*/
static bool
vrfy_delete_group(state_t *s, unsigned int which)
{
bool ret_value = false;
char name[sizeof("/group-9999999999")];
ret_value = vrfy_create_group(s, which);
if (ret_value == true) {
esnprintf(name, sizeof(name), "/group-%u", which);
ret_value = vrfy_one_link_exist(s, s->file, name, false, 0);
}
return ret_value;
}
/*-------------------------------------------------------------------------
* Function: vrfy_move_one_group
*
* Purpose: A helper function to verify the move_group operation successfully.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* hid_t obj_id
* ID of the object this group is attached to
*
* const char *name
* The original group name
*
* const char *newname
* The new group name
*
* unsigned int which
* The number of iterations for group creation
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the verify_move_group() function.
*-------------------------------------------------------------------------
*/
static bool
vrfy_move_one_group(state_t *s, hid_t obj_id, const char *name, const char *newname, unsigned int which)
{
hid_t g = H5I_INVALID_HID;
H5G_info_t group_info;
int link_exists = 0;
dbgf(2, "reader: ready to send the message: \n");
/* The reader receives a message from the writer.Then sleep
* for a few ticks or stop the test if the received message
* is an error message.
*/
if (s->use_named_pipes && true == s->grp_op_test) {
if (false == np_rd_receive(s)) {
H5_FAILED();
AT();
goto error2;
}
decisleep(s->tick_len * s->update_interval);
dbgf(1, "reader: finish reading the message: %d\n", s->np_notify);
}
if (which >= s->nsteps) {
HDprintf("Number of created groups is out of bounds\n");
TEST_ERROR;
}
link_exists = H5Lexists(obj_id, name, H5P_DEFAULT);
if (link_exists < 0) {
HDprintf("H5Lexists error\n");
TEST_ERROR;
}
else if (link_exists == 1) {
HDprintf("This link should be moved but it still exists.\n");
TEST_ERROR;
}
if ((g = H5Gopen(obj_id, newname, H5P_DEFAULT)) < 0) {
HDprintf("H5Gopen failed\n");
TEST_ERROR;
}
if (H5Gget_info(g, &group_info) < 0) {
HDprintf("H5Gget_info failed\n");
TEST_ERROR;
}
dbgf(2, "Storage info is %d\n", group_info.storage_type);
if (s->old_style_grp) {
if (group_info.storage_type != H5G_STORAGE_TYPE_SYMBOL_TABLE) {
HDprintf("Reader - Old-styled group: but the group is not in old-style. \n");
TEST_ERROR;
}
dbgf(2, "Reader: verify that the group is created with the old-style.\n");
}
else {
if (group_info.storage_type == H5G_STORAGE_TYPE_SYMBOL_TABLE) {
HDprintf("Reader - The created group should NOT be in old-style . \n");
TEST_ERROR;
}
dbgf(2, "Reader: verify that the group is created with the new-style.\n");
}
if (H5Gclose(g) < 0) {
HDprintf("H5Gclose failed\n");
TEST_ERROR;
}
/* Reader sends an OK message back to the reader */
if (s->use_named_pipes && s->grp_op_test == true) {
if (np_rd_send(s) == false) {
TEST_ERROR;
}
dbgf(1, "Reader: finish sending back the message: %d\n", s->np_notify);
}
return true;
error:
H5E_BEGIN_TRY
{
H5Gclose(g);
}
H5E_END_TRY;
/* The reader sends an error message to the writer to stop the test.*/
if (s->use_named_pipes && s->grp_op_test == true)
np_send_error(s, false);
error2:
return false;
}
/*-------------------------------------------------------------------------
* Function: vrfy_move_group
*
* Purpose: Verify if a group can be moved successfully.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* unsigned int which
* The number of iterations for group creation
* used to generate the group name.
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the verify_group_operations() function.
*-------------------------------------------------------------------------
*/
static bool
vrfy_move_group(state_t *s, unsigned int which)
{
char name[sizeof("/group-9999999999")];
char new_name[sizeof("/new-group-9999999999")];
bool ret_value = vrfy_create_group(s, which);
if (ret_value == true) {
esnprintf(name, sizeof(name), "/group-%u", which);
esnprintf(new_name, sizeof(new_name), "/new-group-%u", which);
ret_value = vrfy_move_one_group(s, s->file, name, new_name, which);
}
return ret_value;
}
/*-------------------------------------------------------------------------
* Function: vrfy_insert_links
*
* Purpose: Verify if the links are inserted successfully.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* unsigned int which
* The number of iterations for group creation
* used to generate the group name.
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the verify_group_operations() function.
*-------------------------------------------------------------------------
*/
static bool
vrfy_insert_links(state_t *s, unsigned int which)
{
bool ret_value = false;
char hd_name[sizeof("/hd-group-9999999999")];
char st_name[sizeof("/st-group-9999999999")];
ret_value = vrfy_create_group(s, which);
if (ret_value == true) {
esnprintf(hd_name, sizeof(hd_name), "/hd-group-%u", which);
esnprintf(st_name, sizeof(st_name), "/st-group-%u", which);
ret_value = vrfy_one_link_exist(s, s->file, hd_name, true, 0);
if (ret_value == true)
ret_value = vrfy_one_link_exist(s, s->file, st_name, true, 0);
}
return ret_value;
}
/*-------------------------------------------------------------------------
* Function: vrfy_delete_links
*
* Purpose: Verify if the links created with a group are deleted successfully.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* unsigned int which
* The number of iterations for group creation
* used to generate the group name.
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the verify_group_operations() function.
*-------------------------------------------------------------------------
*/
static bool
vrfy_delete_links(state_t *s, unsigned int which)
{
bool ret_value = false;
char hd_name[sizeof("/hd-group-9999999999")];
char st_name[sizeof("/st-group-9999999999")];
/* First verify if the links are inserted correctly */
ret_value = vrfy_insert_links(s, which);
/* Then if these links are deleted correctly. */
if (ret_value == true) {
esnprintf(hd_name, sizeof(hd_name), "/hd-group-%u", which);
esnprintf(st_name, sizeof(st_name), "/st-group-%u", which);
ret_value = vrfy_one_link_exist(s, s->file, hd_name, false, 0);
if (ret_value == true)
ret_value = vrfy_one_link_exist(s, s->file, st_name, false, 0);
}
return ret_value;
}
/*-------------------------------------------------------------------------
* Function: vrfy_transit_storage_compact_to_dense
*
* Purpose: Verify if the link storage successfully transits from
* compact to dense.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* unsigned int which
* The number of iterations for group creation
* used to generate the group name.
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the verify_group_operations() function.
*-------------------------------------------------------------------------
*/
static bool
vrfy_transit_storage_compact_to_dense(state_t *s, unsigned int which)
{
hid_t g = H5I_INVALID_HID;
char hd_name[sizeof("hd-group-9999999999")];
char st_name[sizeof("st-group-9999999999")];
g = vrfy_create_group_id(s, which, false);
if (g < 0) {
HDprintf("verify create_group_id failed\n");
TEST_ERROR;
}
esnprintf(hd_name, sizeof(hd_name), "hd-group-%u", which);
if (vrfy_one_link_exist(s, g, hd_name, true, 1) == false) {
HDprintf("verify the compact storage failed for 'link compact to dense' test\n");
TEST_ERROR;
}
esnprintf(st_name, sizeof(st_name), "st-group-%u", which);
if (vrfy_one_link_exist(s, g, st_name, true, 2) == false) {
HDprintf("verify the dense link storage failed for 'link compact to dense' test\n");
TEST_ERROR;
}
if (vrfy_close_group_id(s, g) == false) {
HDprintf("verify the group close for 'link compact to dense' test\n");
TEST_ERROR;
}
return true;
error:
H5E_BEGIN_TRY
{
H5Gclose(g);
}
H5E_END_TRY;
return false;
}
/*-------------------------------------------------------------------------
* Function: vrfy_transit_storage_dense_to_compact
*
* Purpose: Verify if the link storage successfully transits from
* compact to dense then to compact.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* unsigned int which
* The number of iterations for group creation
* used to generate the group name.
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the verify_group_operations() function.
*-------------------------------------------------------------------------
*/
static bool
vrfy_transit_storage_dense_to_compact(state_t *s, unsigned int which)
{
hid_t g = H5I_INVALID_HID;
char hd_name[sizeof("hd-group-9999999999")];
char st_name[sizeof("st-group-9999999999")];
char st2_name[sizeof("st2-group-9999999999")];
g = vrfy_create_group_id(s, which, true);
if (g < 0) {
HDprintf("verify create_group_id failed\n");
TEST_ERROR;
}
/* Add a link, verify it is still the compact storage */
esnprintf(hd_name, sizeof(hd_name), "hd-group-%u", which);
if (vrfy_one_link_exist(s, g, hd_name, true, 1) == false) {
HDprintf("verify the compact storage failed for 'link compact to dense' test\n");
TEST_ERROR;
}
/* Add another link, verify it is still the compact storage */
esnprintf(st_name, sizeof(st_name), "st-group-%u", which);
if (vrfy_one_link_exist(s, g, st_name, true, 1) == false) {
HDprintf("verify the compact link storage failed for 'link compact to dense' test\n");
TEST_ERROR;
}
/* Add the third link, verify it becomes the dense storage */
esnprintf(st2_name, sizeof(st2_name), "st2-group-%u", which);
if (vrfy_one_link_exist(s, g, st2_name, true, 2) == false) {
HDprintf("verify the dense link storage failed for 'link compact to dense' test\n");
TEST_ERROR;
}
/* Remove a link, verify the link doesn't exist and still dense storage */
if (vrfy_one_link_exist(s, g, st_name, false, 2) == false) {
HDprintf("verify the dense link storage failed for 'link compact to dense' test\n");
TEST_ERROR;
}
/* Remove a link, verify the link doesn't exist and it becomes compact storage */
if (vrfy_one_link_exist(s, g, st2_name, false, 1) == false) {
HDprintf("verify the compact link storage failed for 'link compact to dense' test\n");
TEST_ERROR;
}
if (vrfy_close_group_id(s, g) == false) {
HDprintf("verify the group close for 'link compact to dense' test\n");
TEST_ERROR;
}
return true;
error:
H5E_BEGIN_TRY
{
H5Gclose(g);
}
H5E_END_TRY;
return false;
}
/*-------------------------------------------------------------------------
* Function: verify_group_operations
*
* Purpose: verify the success of group creation and
* carry out the test for attribute operations(add,delete etc.)
* according to the attribute test pattern.
*
* Parameters: state_t *s
* The struct that stores information of HDF5 file, named pipe
* and some VFD SWMR configuration parameters
*
* unsigned int which
* The number of iterations for group creation
*
*
* Return: Success: true
* Failure: false
*
* Note: This is called by the main() function.
*-------------------------------------------------------------------------
*/
static bool
verify_group_operations(state_t *s, unsigned int which)
{
bool ret_value = false;
char test_pattern = s->grp_op_pattern;
switch (test_pattern) {
case 'c':
ret_value = vrfy_create_group(s, which);
break;
case 'd':
ret_value = vrfy_delete_group(s, which);
break;
case 'm':
ret_value = vrfy_move_group(s, which);
break;
case 'i':
ret_value = vrfy_insert_links(s, which);
break;
case 'D':
ret_value = vrfy_delete_links(s, which);
break;
case 't':
ret_value = vrfy_transit_storage_compact_to_dense(s, which);
break;
case 'T':
ret_value = vrfy_transit_storage_dense_to_compact(s, which);
break;
case ' ':
default:
ret_value = verify_group(s, which);
break;
}
return ret_value;
}
int
main(int argc, char **argv)
{
hid_t fapl = H5I_INVALID_HID, fcpl = H5I_INVALID_HID;
unsigned step;
bool writer = false;
state_t s;
const char * personality;
H5F_vfd_swmr_config_t config;
const char * fifo_writer_to_reader = "./fifo_group_writer_to_reader";
const char * fifo_reader_to_writer = "./fifo_group_reader_to_writer";
int fd_writer_to_reader = -1, fd_reader_to_writer = -1;
int notify = 0, verify = 0;
bool wg_ret = false;
bool vg_ret = false;
if (!state_init(&s, argc, argv)) {
HDprintf("state_init failed\n");
TEST_ERROR;
}
personality = HDstrstr(s.progname, "vfd_swmr_group_");
if (personality != NULL && HDstrcmp(personality, "vfd_swmr_group_writer") == 0)
writer = true;
else if (personality != NULL && HDstrcmp(personality, "vfd_swmr_group_reader") == 0)
writer = false;
else {
HDprintf("unknown personality, expected vfd_swmr_group_{reader,writer}\n");
TEST_ERROR;
}
/* config, tick_len, max_lag, writer, flush_raw_data, md_pages_reserved, md_file_path */
init_vfd_swmr_config(&config, 4, 7, writer, FALSE, 128, "./group-shadow");
/* If old-style option is chosen, use the earliest file format(H5F_LIBVER_EARLIEST)
* as the second parameter of H5Pset_libver_bound() that is called by
* vfd_swmr_create_fapl. Otherwise, the latest file format(H5F_LIBVER_LATEST)
* should be used as the second parameter of H5Pset_libver_bound().
* Also pass the use_vfd_swmr, only_meta_page, page_buf_size, config to vfd_swmr_create_fapl().*/
if ((fapl = vfd_swmr_create_fapl(!s.old_style_grp, 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)
s.file = H5Fcreate(s.filename, H5F_ACC_TRUNC, fcpl, fapl);
else
s.file = H5Fopen(s.filename, H5F_ACC_RDONLY, fapl);
if (s.file < 0) {
HDprintf("H5Fcreate/open failed\n");
TEST_ERROR;
}
/* 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 (s.use_named_pipes && writer) {
/* Writer creates two named pipes(FIFO) */
if (HDmkfifo(fifo_writer_to_reader, 0600) < 0) {
HDprintf("HDmkfifo failed\n");
TEST_ERROR;
}
if (HDmkfifo(fifo_reader_to_writer, 0600) < 0) {
HDprintf("HDmkfifo failed\n");
TEST_ERROR;
}
}
/* Both the writer and reader open the pipes */
if (s.use_named_pipes && (fd_writer_to_reader = HDopen(fifo_writer_to_reader, O_RDWR)) < 0) {
HDprintf("HDopen failed\n");
TEST_ERROR;
}
if (s.use_named_pipes && (fd_reader_to_writer = HDopen(fifo_reader_to_writer, O_RDWR)) < 0) {
HDprintf("HDopen failed\n");
TEST_ERROR;
}
/* Pass the named pipe information to the struct of state_t s, for attribute tests.*/
if (s.use_named_pipes) {
s.np_fd_w_to_r = fd_writer_to_reader;
s.np_fd_r_to_w = fd_reader_to_writer;
s.np_notify = notify;
s.np_verify = verify;
s.tick_len = config.tick_len;
s.max_lag = config.max_lag;
}
/* For attribute test, force the named pipe to communicate in every step.
* This will avoid the fake verification error from the reader when using the named pipe.
* If the named pipe is not forced to communicate in every step, the reader may go ahead
* to verify the group and the attribute operations before the writer has a chance to
* carry out the corresponding operations. */
if (s.attr_test && s.use_named_pipes)
s.csteps = 1;
/* For group operation test, force the named pipe to communicate in every step. */
if (s.grp_op_test && s.use_named_pipes)
s.csteps = 1;
if (writer) {
for (step = 0; step < s.nsteps; step++) {
dbgf(2, "writer: step %d\n", step);
wg_ret = group_operations(&s, step);
if (wg_ret == false) {
/* At communication interval, notifies the reader about the failure and quit */
if (s.use_named_pipes && s.attr_test != true && s.grp_op_test != true && step % s.csteps == 0)
np_send_error(&s, true);
HDprintf("write_group failed at step %d\n", step);
TEST_ERROR;
}
else {
/* At communication interval, notifies the reader and waits for its response */
if (s.use_named_pipes && s.attr_test != true && s.grp_op_test != true &&
step % s.csteps == 0) {
if (np_wr_send_receive(&s) == false) {
HDprintf("writer: write group - verification failed.\n");
TEST_ERROR;
}
}
}
}
}
else {
for (step = 0; step < s.nsteps; step++) {
dbgf(1, "reader: step %d\n", step);
/* At communication interval, waits for the writer to finish creation before starting verification
*/
if (s.use_named_pipes && s.attr_test != true && s.grp_op_test != true && step % s.csteps == 0) {
if (false == np_rd_receive(&s)) {
TEST_ERROR;
}
}
/* For the default test, wait for a few ticks for the update to happen */
if (s.use_named_pipes && s.attr_test == false)
decisleep(config.tick_len * s.update_interval);
vg_ret = verify_group_operations(&s, step);
if (vg_ret == false) {
HDprintf("verify_group_operations failed\n");
/* At communication interval, tell the writer about the failure and exit */
if (s.use_named_pipes && s.attr_test != true && s.grp_op_test != true && step % s.csteps == 0)
np_send_error(&s, false);
TEST_ERROR;
}
else {
/* Send back the same nofity value for acknowledgement to tell the writer
* move to the next step. */
if (s.use_named_pipes && s.attr_test != true && s.grp_op_test != true &&
step % s.csteps == 0) {
if (np_rd_send(&s) == false) {
TEST_ERROR;
}
}
}
}
}
if (H5Pclose(fapl) < 0) {
HDprintf("H5Pclose failed\n");
TEST_ERROR;
}
if (H5Pclose(fcpl) < 0) {
HDprintf("H5Pclose failed\n");
TEST_ERROR;
}
if (H5Sclose(s.one_by_one_sid) < 0) {
HDprintf("H5Sclose failed\n");
TEST_ERROR;
}
if (H5Fclose(s.file) < 0) {
HDprintf("H5Fclose failed\n");
TEST_ERROR;
}
/* Both the writer and reader close the named pipes */
if (s.use_named_pipes && HDclose(fd_writer_to_reader) < 0) {
HDprintf("HDclose failed\n");
TEST_ERROR;
}
if (s.use_named_pipes && HDclose(fd_reader_to_writer) < 0) {
HDprintf("HDclose failed\n");
TEST_ERROR;
}
/* Reader finishes last and deletes the named pipes */
if (s.use_named_pipes && !writer) {
if (HDremove(fifo_writer_to_reader) != 0) {
HDprintf("HDremove failed\n");
TEST_ERROR;
}
if (HDremove(fifo_reader_to_writer) != 0) {
HDprintf("HDremove failed\n");
TEST_ERROR;
}
}
return EXIT_SUCCESS;
error:
H5E_BEGIN_TRY
{
H5Pclose(fapl);
H5Pclose(fcpl);
H5Sclose(s.one_by_one_sid);
H5Fclose(s.file);
}
H5E_END_TRY;
if (s.use_named_pipes && fd_writer_to_reader >= 0)
HDclose(fd_writer_to_reader);
if (s.use_named_pipes && fd_reader_to_writer >= 0)
HDclose(fd_reader_to_writer);
if (s.use_named_pipes && !writer) {
HDremove(fifo_writer_to_reader);
HDremove(fifo_reader_to_writer);
}
return EXIT_FAILURE;
}
#else /* H5_HAVE_WIN32_API */
int
main(void)
{
HDfprintf(stderr, "Non-POSIX platform. Skipping.\n");
return EXIT_SUCCESS;
} /* end main() */
#endif /* H5_HAVE_WIN32_API */
|