summaryrefslogtreecommitdiffstats
path: root/test/cache_common.c
blob: aeb9a255be5de84935bf5098edcc034dbcb5cb4a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * 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 files COPYING and Copyright.html.  COPYING can be found at the root   *
 * of the source code distribution tree; Copyright.html can be found at the  *
 * root level of an installed copy of the electronic HDF5 document set and   *
 * is linked from the top-level documents page.  It can also be found at     *
 * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html.  If you do not have     *
 * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/* Programmer:  John Mainzer
 *              10/27/05
 *
 *		This file contains common code for tests of the cache 
 *		implemented in H5C.c
 */
#include "h5test.h"
#include "H5Iprivate.h"
#include "H5ACprivate.h"
#include "cache_common.h"


/* global variable declarations: */

hbool_t write_permitted = TRUE;
hbool_t pass = TRUE; /* set to false on error */
hbool_t skip_long_tests = TRUE;
hbool_t run_full_test = TRUE;
const char *failure_mssg = NULL;

test_entry_t pico_entries[NUM_PICO_ENTRIES];
test_entry_t nano_entries[NUM_NANO_ENTRIES];
test_entry_t micro_entries[NUM_MICRO_ENTRIES];
test_entry_t tiny_entries[NUM_TINY_ENTRIES];
test_entry_t small_entries[NUM_SMALL_ENTRIES];
test_entry_t medium_entries[NUM_MEDIUM_ENTRIES];
test_entry_t large_entries[NUM_LARGE_ENTRIES];
test_entry_t huge_entries[NUM_HUGE_ENTRIES];
test_entry_t monster_entries[NUM_MONSTER_ENTRIES];

test_entry_t * entries[NUMBER_OF_ENTRY_TYPES] =
{
    pico_entries,
    nano_entries,
    micro_entries,
    tiny_entries,
    small_entries,
    medium_entries,
    large_entries,
    huge_entries,
    monster_entries
};

const int32_t max_indices[NUMBER_OF_ENTRY_TYPES] =
{
    NUM_PICO_ENTRIES - 1,
    NUM_NANO_ENTRIES - 1,
    NUM_MICRO_ENTRIES - 1,
    NUM_TINY_ENTRIES - 1,
    NUM_SMALL_ENTRIES - 1,
    NUM_MEDIUM_ENTRIES - 1,
    NUM_LARGE_ENTRIES - 1,
    NUM_HUGE_ENTRIES - 1,
    NUM_MONSTER_ENTRIES - 1
};

const size_t entry_sizes[NUMBER_OF_ENTRY_TYPES] =
{
    PICO_ENTRY_SIZE,
    NANO_ENTRY_SIZE,
    MICRO_ENTRY_SIZE,
    TINY_ENTRY_SIZE,
    SMALL_ENTRY_SIZE,
    MEDIUM_ENTRY_SIZE,
    LARGE_ENTRY_SIZE,
    HUGE_ENTRY_SIZE,
    MONSTER_ENTRY_SIZE
};

const haddr_t base_addrs[NUMBER_OF_ENTRY_TYPES] =
{
    PICO_BASE_ADDR,
    NANO_BASE_ADDR,
    MICRO_BASE_ADDR,
    TINY_BASE_ADDR,
    SMALL_BASE_ADDR,
    MEDIUM_BASE_ADDR,
    LARGE_BASE_ADDR,
    HUGE_BASE_ADDR,
    MONSTER_BASE_ADDR
};

const haddr_t alt_base_addrs[NUMBER_OF_ENTRY_TYPES] =
{
    PICO_ALT_BASE_ADDR,
    NANO_ALT_BASE_ADDR,
    MICRO_ALT_BASE_ADDR,
    TINY_ALT_BASE_ADDR,
    SMALL_ALT_BASE_ADDR,
    MEDIUM_ALT_BASE_ADDR,
    LARGE_ALT_BASE_ADDR,
    HUGE_ALT_BASE_ADDR,
    MONSTER_ALT_BASE_ADDR
};

const char * entry_type_names[NUMBER_OF_ENTRY_TYPES] =
{
    "pico entries -- 1 B",
    "nano entries -- 4 B",
    "micro entries -- 16 B",
    "tiny entries -- 64 B",
    "small entries -- 256 B",
    "medium entries -- 1 KB",
    "large entries -- 4 KB",
    "huge entries -- 16 KB",
    "monster entries -- 64 KB"
};


/* callback table declaration */

const H5C_class_t types[NUMBER_OF_ENTRY_TYPES] =
{
  {
    PICO_ENTRY_TYPE,
    (H5C_load_func_t)pico_load,
    (H5C_flush_func_t)pico_flush,
    (H5C_dest_func_t)pico_dest,
    (H5C_clear_func_t)pico_clear,
    (H5C_size_func_t)pico_size
  },
  {
    NANO_ENTRY_TYPE,
    (H5C_load_func_t)nano_load,
    (H5C_flush_func_t)nano_flush,
    (H5C_dest_func_t)nano_dest,
    (H5C_clear_func_t)nano_clear,
    (H5C_size_func_t)nano_size
  },
  {
    MICRO_ENTRY_TYPE,
    (H5C_load_func_t)micro_load,
    (H5C_flush_func_t)micro_flush,
    (H5C_dest_func_t)micro_dest,
    (H5C_clear_func_t)micro_clear,
    (H5C_size_func_t)micro_size
  },
  {
    TINY_ENTRY_TYPE,
    (H5C_load_func_t)tiny_load,
    (H5C_flush_func_t)tiny_flush,
    (H5C_dest_func_t)tiny_dest,
    (H5C_clear_func_t)tiny_clear,
    (H5C_size_func_t)tiny_size
  },
  {
    SMALL_ENTRY_TYPE,
    (H5C_load_func_t)small_load,
    (H5C_flush_func_t)small_flush,
    (H5C_dest_func_t)small_dest,
    (H5C_clear_func_t)small_clear,
    (H5C_size_func_t)small_size
  },
  {
    MEDIUM_ENTRY_TYPE,
    (H5C_load_func_t)medium_load,
    (H5C_flush_func_t)medium_flush,
    (H5C_dest_func_t)medium_dest,
    (H5C_clear_func_t)medium_clear,
    (H5C_size_func_t)medium_size
  },
  {
    LARGE_ENTRY_TYPE,
    (H5C_load_func_t)large_load,
    (H5C_flush_func_t)large_flush,
    (H5C_dest_func_t)large_dest,
    (H5C_clear_func_t)large_clear,
    (H5C_size_func_t)large_size
  },
  {
    HUGE_ENTRY_TYPE,
    (H5C_load_func_t)huge_load,
    (H5C_flush_func_t)huge_flush,
    (H5C_dest_func_t)huge_dest,
    (H5C_clear_func_t)huge_clear,
    (H5C_size_func_t)huge_size
  },
  {
    MONSTER_ENTRY_TYPE,
    (H5C_load_func_t)monster_load,
    (H5C_flush_func_t)monster_flush,
    (H5C_dest_func_t)monster_dest,
    (H5C_clear_func_t)monster_clear,
    (H5C_size_func_t)monster_size
  }
};

static herr_t clear(H5F_t * f, void * thing, hbool_t dest);
static herr_t destroy(H5F_t UNUSED * f, void * thing);
static herr_t flush(H5F_t *f, hid_t UNUSED dxpl_id, hbool_t dest,
                    haddr_t addr, void *thing);
static void * load(H5F_t UNUSED *f, hid_t UNUSED dxpl_id, haddr_t addr,
                   const void UNUSED *udata1, void UNUSED *udata2);
static herr_t size(H5F_t UNUSED * f, void * thing, size_t * size_ptr);



/* address translation funtions: */

/*-------------------------------------------------------------------------
 * Function:	addr_to_type_and_index
 *
 * Purpose:	Given an address, compute the type and index of the
 *		associated entry.
 *
 * Return:	void
 *
 * Programmer:	John Mainzer
 *              6/10/04
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
void
addr_to_type_and_index(haddr_t addr,
                       int32_t * type_ptr,
                       int32_t * index_ptr)
{
    int i;
    int32_t type;
    int32_t idx;

    HDassert( type_ptr );
    HDassert( index_ptr );

    /* we only have a small number of entry types, so just do a
     * linear search.  If NUMBER_OF_ENTRY_TYPES grows, we may want
     * to do a binary search instead.
     */
    i = 1;
    if ( addr >= PICO_ALT_BASE_ADDR ) {

        while ( ( i < NUMBER_OF_ENTRY_TYPES ) &&
                ( addr >= alt_base_addrs[i] ) )
        {
            i++;
        }

    } else {

        while ( ( i < NUMBER_OF_ENTRY_TYPES ) &&
                ( addr >= base_addrs[i] ) )
        {
            i++;
        }
    }

    type = i - 1;

    HDassert( ( type >= 0 ) && ( type < NUMBER_OF_ENTRY_TYPES ) );

    if ( addr >= PICO_ALT_BASE_ADDR ) {

        idx = (addr - alt_base_addrs[type]) / entry_sizes[type];
        HDassert( !((entries[type])[idx].at_main_addr) );
        HDassert( addr == (entries[type])[idx].alt_addr );

    } else {

        idx = (addr - base_addrs[type]) / entry_sizes[type];
        HDassert( (entries[type])[idx].at_main_addr );
        HDassert( addr == (entries[type])[idx].main_addr );
    }

    HDassert( ( idx >= 0 ) && ( idx <= max_indices[type] ) );

    HDassert( addr == (entries[type])[idx].addr );

    *type_ptr = type;
    *index_ptr = idx;

    return;

} /* addr_to_type_and_index() */


#if 0 /* This function has never been used, but we may want it
       * some time.  Lets keep it for now.
       */
/*-------------------------------------------------------------------------
 * Function:	type_and_index_to_addr
 *
 * Purpose:	Given a type and index of an entry, compute the associated
 *		addr and return that value.
 *
 * Return:	computed addr
 *
 * Programmer:	John Mainzer
 *              6/10/04
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
haddr_t
type_and_index_to_addr(int32_t type,
                       int32_t idx)
{
    haddr_t addr;

    HDassert( ( type >= 0 ) && ( type < NUMBER_OF_ENTRY_TYPES ) );
    HDassert( ( idx >= 0 ) && ( idx <= max_indices[type] ) );

    addr = base_addrs[type] + (((haddr_t)idx) * entry_sizes[type]);

    HDassert( addr == (entries[type])[idx].addr );

    if ( (entries[type])[idx].at_main_addr ) {

        HDassert( addr == (entries[type])[idx].main_addr );

    } else {

        HDassert( addr == (entries[type])[idx].alt_addr );
    }

    return(addr);

} /* type_and_index_to_addr() */

#endif


/* Call back functions: */

/*-------------------------------------------------------------------------
 *
 * Function:    check_if_write_permitted
 *
 * Purpose:     Determine if a write is permitted under the current
 *              circumstances, and set *write_permitted_ptr accordingly.
 *              As a general rule it is, but when we are running in parallel
 *              mode with collective I/O, we must ensure that a read cannot
 *              cause a write.
 *
 *              In the event of failure, the value of *write_permitted_ptr
 *              is undefined.
 *
 * Return:      Non-negative on success/Negative on failure.
 *
 * Programmer:  John Mainzer, 5/15/04
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */

herr_t
check_write_permitted(const H5F_t UNUSED * f,
                      hid_t UNUSED dxpl_id,
                      hbool_t * write_permitted_ptr)
{

    HDassert( write_permitted_ptr );
    *write_permitted_ptr = write_permitted;

    return(SUCCEED);

} /* check_write_permitted() */


/*-------------------------------------------------------------------------
 * Function:	clear & friends
 *
 * Purpose:	clear the entry.  The helper functions verify that the
 *		correct version of clear is being called, and then call
 *		clear proper.
 *
 * Return:	SUCCEED
 *
 * Programmer:	John Mainzer
 *              6/10/04
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */

herr_t
clear(H5F_t * f,
      void *  thing,
      hbool_t dest)
{
    test_entry_t * entry_ptr;
    test_entry_t * base_addr;

    HDassert( thing );

    entry_ptr = (test_entry_t *)thing;
    base_addr = entries[entry_ptr->type];

    HDassert( entry_ptr->index >= 0 );
    HDassert( entry_ptr->index <= max_indices[entry_ptr->type] );
    HDassert( entry_ptr == &(base_addr[entry_ptr->index]) );
    HDassert( entry_ptr == entry_ptr->self );
    HDassert( entry_ptr->header.addr == entry_ptr->addr );
    HDassert( entry_ptr->header.size == entry_ptr->size );
    HDassert( entry_ptr->size == entry_sizes[entry_ptr->type] );

    entry_ptr->header.is_dirty = FALSE;
    entry_ptr->is_dirty = FALSE;

    entry_ptr->cleared = TRUE;

    if ( dest ) {

        destroy(f, thing);

    }

    return(SUCCEED);

} /* clear() */

herr_t
pico_clear(H5F_t * f, void *  thing, hbool_t dest)
{
    HDassert ( ((test_entry_t *)thing)->type == PICO_ENTRY_TYPE );
    return(clear(f, thing, dest));
}

herr_t
nano_clear(H5F_t * f, void *  thing, hbool_t dest)
{
    HDassert ( ((test_entry_t *)thing)->type == NANO_ENTRY_TYPE );
    return(clear(f, thing, dest));
}

herr_t
micro_clear(H5F_t * f, void *  thing, hbool_t dest)
{
    HDassert ( ((test_entry_t *)thing)->type == MICRO_ENTRY_TYPE );
    return(clear(f, thing, dest));
}

herr_t
tiny_clear(H5F_t * f, void *  thing, hbool_t dest)
{
    HDassert ( ((test_entry_t *)thing)->type == TINY_ENTRY_TYPE );
    return(clear(f, thing, dest));
}

herr_t
small_clear(H5F_t * f, void *  thing, hbool_t dest)
{
    HDassert ( ((test_entry_t *)thing)->type == SMALL_ENTRY_TYPE );
    return(clear(f, thing, dest));
}

herr_t
medium_clear(H5F_t * f, void *  thing, hbool_t dest)
{
    HDassert ( ((test_entry_t *)thing)->type == MEDIUM_ENTRY_TYPE );
    return(clear(f, thing, dest));
}

herr_t
large_clear(H5F_t * f, void *  thing, hbool_t dest)
{
    HDassert ( ((test_entry_t *)thing)->type == LARGE_ENTRY_TYPE );
    return(clear(f, thing, dest));
}

herr_t
huge_clear(H5F_t * f, void *  thing, hbool_t dest)
{
    HDassert ( ((test_entry_t *)thing)->type == HUGE_ENTRY_TYPE );
    return(clear(f, thing, dest));
}

herr_t
monster_clear(H5F_t * f, void *  thing, hbool_t dest)
{
    HDassert ( ((test_entry_t *)thing)->type == MONSTER_ENTRY_TYPE );
    return(clear(f, thing, dest));
}


/*-------------------------------------------------------------------------
 * Function:	dest & friends
 *
 * Purpose:	Destroy the entry.  The helper functions verify that the
 *		correct version of dest is being called, and then call
 *		dest proper.
 *
 * Return:	SUCCEED
 *
 * Programmer:	John Mainzer
 *              6/10/04
 *
 * Modifications:
 *
 * 		JRM -- 4/4/06
 * 		Added code to decrement the pinning_ref_count s of entries
 * 		pinned by the target entry, and to unpin those entries
 * 		if the reference count drops to zero.
 *
 *-------------------------------------------------------------------------
 */

herr_t
destroy(H5F_t UNUSED * f,
        void *         thing)
{
    int i;
    test_entry_t * entry_ptr;
    test_entry_t * base_addr;
    test_entry_t * pinned_entry_ptr;
    test_entry_t * pinned_base_addr;

    HDassert( thing );

    entry_ptr = (test_entry_t *)thing;
    base_addr = entries[entry_ptr->type];

    HDassert( entry_ptr->index >= 0 );
    HDassert( entry_ptr->index <= max_indices[entry_ptr->type] );
    HDassert( entry_ptr == &(base_addr[entry_ptr->index]) );
    HDassert( entry_ptr == entry_ptr->self );
    HDassert( entry_ptr->cache_ptr != NULL );
    HDassert( entry_ptr->cache_ptr->magic == H5C__H5C_T_MAGIC );
    HDassert( entry_ptr->header.addr == entry_ptr->addr );
    HDassert( entry_ptr->header.size == entry_ptr->size );
    HDassert( entry_ptr->size == entry_sizes[entry_ptr->type] );

    HDassert( !(entry_ptr->is_dirty) );
    HDassert( !(entry_ptr->header.is_dirty) );

    if ( entry_ptr->num_pins > 0 ) {

	for ( i = 0; i < entry_ptr->num_pins; i++ )
        {
	    pinned_base_addr = entries[entry_ptr->pin_type[i]];
	    pinned_entry_ptr = &(pinned_base_addr[entry_ptr->pin_idx[i]]);

	    HDassert( 0 <= pinned_entry_ptr->type ); 
            HDassert( pinned_entry_ptr->type < NUMBER_OF_ENTRY_TYPES );
	    HDassert( pinned_entry_ptr->type == entry_ptr->pin_type[i] );
	    HDassert( pinned_entry_ptr->index >= 0 );
	    HDassert( pinned_entry_ptr->index <= 
		      max_indices[pinned_entry_ptr->type] );
	    HDassert( pinned_entry_ptr->index == entry_ptr->pin_idx[i] );
	    HDassert( pinned_entry_ptr == pinned_entry_ptr->self );
	    HDassert( pinned_entry_ptr->header.is_pinned );
	    HDassert( pinned_entry_ptr->is_pinned );
	    HDassert( pinned_entry_ptr->pinning_ref_count > 0 );

	    pinned_entry_ptr->pinning_ref_count--;

	    if ( pinned_entry_ptr->pinning_ref_count <= 0 ) {

		unpin_entry(pinned_entry_ptr->cache_ptr, 
			    pinned_entry_ptr->type,
			    pinned_entry_ptr->index);
	    }

	    entry_ptr->pin_type[i] = -1;
	    entry_ptr->pin_idx[i] = -1;
	}
	entry_ptr->num_pins = 0;
    }

    entry_ptr->destroyed = TRUE;
    entry_ptr->cache_ptr = NULL;

    return(SUCCEED);

} /* dest() */

herr_t
pico_dest(H5F_t * f, void * thing)
{
    HDassert ( ((test_entry_t *)thing)->type == PICO_ENTRY_TYPE );
    return(destroy(f, thing));
}

herr_t
nano_dest(H5F_t * f, void * thing)
{
    HDassert ( ((test_entry_t *)thing)->type == NANO_ENTRY_TYPE );
    return(destroy(f, thing));
}

herr_t
micro_dest(H5F_t * f, void * thing)
{
    HDassert ( ((test_entry_t *)thing)->type == MICRO_ENTRY_TYPE );
    return(destroy(f, thing));
}

herr_t
tiny_dest(H5F_t * f, void * thing)
{
    HDassert ( ((test_entry_t *)thing)->type == TINY_ENTRY_TYPE );
    return(destroy(f, thing));
}

herr_t
small_dest(H5F_t * f, void * thing)
{
    HDassert ( ((test_entry_t *)thing)->type == SMALL_ENTRY_TYPE );
    return(destroy(f, thing));
}

herr_t
medium_dest(H5F_t * f, void * thing)
{
    HDassert ( ((test_entry_t *)thing)->type == MEDIUM_ENTRY_TYPE );
    return(destroy(f, thing));
}

herr_t
large_dest(H5F_t * f, void * thing)
{
    HDassert ( ((test_entry_t *)thing)->type == LARGE_ENTRY_TYPE );
    return(destroy(f, thing));
}

herr_t
huge_dest(H5F_t * f, void *  thing)
{
    HDassert ( ((test_entry_t *)thing)->type == HUGE_ENTRY_TYPE );
    return(destroy(f, thing));
}

herr_t
monster_dest(H5F_t * f, void *  thing)
{
    HDassert ( ((test_entry_t *)thing)->type == MONSTER_ENTRY_TYPE );
    return(destroy(f, thing));
}


/*-------------------------------------------------------------------------
 * Function:	flush & friends
 *
 * Purpose:	flush the entry and mark it as clean.  The helper functions
 *              verify that the correct version of flush is being called,
 *		and then call flush proper.
 *
 * Return:	SUCCEED
 *
 * Programmer:	John Mainzer
 *              6/10/04
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */

herr_t
flush(H5F_t *f,
      hid_t UNUSED dxpl_id,
      hbool_t dest,
      haddr_t addr,
      void *thing)
{
    test_entry_t * entry_ptr;
    test_entry_t * base_addr;

    HDassert( thing );

    entry_ptr = (test_entry_t *)thing;
    base_addr = entries[entry_ptr->type];

    HDassert( entry_ptr->index >= 0 );
    HDassert( entry_ptr->index <= max_indices[entry_ptr->type] );
    HDassert( entry_ptr == &(base_addr[entry_ptr->index]) );
    HDassert( entry_ptr == entry_ptr->self );
    HDassert( entry_ptr->header.addr == entry_ptr->addr );
    HDassert( entry_ptr->addr == addr );
    HDassert( entry_ptr->header.size == entry_ptr->size );
    HDassert( entry_ptr->size == entry_sizes[entry_ptr->type] );
    HDassert( entry_ptr->header.is_dirty == entry_ptr->is_dirty );

    entry_ptr->flushed = TRUE;

    if ( ( ! write_permitted ) && ( entry_ptr->is_dirty ) ) {

        pass = FALSE;
        failure_mssg = "called flush when write_permitted is FALSE.";
    }

    if ( entry_ptr->is_dirty ) {

        (entry_ptr->writes)++;
        entry_ptr->is_dirty = FALSE;
        entry_ptr->header.is_dirty = FALSE;
    }

    if ( dest ) {

        destroy(f, thing);

    }

    return(SUCCEED);

} /* flush() */

herr_t
pico_flush(H5F_t *f, hid_t dxpl_id, hbool_t dest, haddr_t addr, void *thing)
{
    HDassert ( ((test_entry_t *)thing)->type == PICO_ENTRY_TYPE );
    return(flush(f, dxpl_id, dest, addr, thing));
}

herr_t
nano_flush(H5F_t *f, hid_t dxpl_id, hbool_t dest, haddr_t addr, void *thing)
{
    HDassert ( ((test_entry_t *)thing)->type == NANO_ENTRY_TYPE );
    return(flush(f, dxpl_id, dest, addr, thing));
}

herr_t
micro_flush(H5F_t *f, hid_t dxpl_id, hbool_t dest, haddr_t addr, void *thing)
{
    HDassert ( ((test_entry_t *)thing)->type == MICRO_ENTRY_TYPE );
    return(flush(f, dxpl_id, dest, addr, thing));
}

herr_t
tiny_flush(H5F_t *f, hid_t dxpl_id, hbool_t dest, haddr_t addr, void *thing)
{
    HDassert ( ((test_entry_t *)thing)->type == TINY_ENTRY_TYPE );
    return(flush(f, dxpl_id, dest, addr, thing));
}

herr_t
small_flush(H5F_t *f, hid_t dxpl_id, hbool_t dest, haddr_t addr, void *thing)
{
    HDassert ( ((test_entry_t *)thing)->type == SMALL_ENTRY_TYPE );
    return(flush(f, dxpl_id, dest, addr, thing));
}

herr_t
medium_flush(H5F_t *f, hid_t dxpl_id, hbool_t dest, haddr_t addr, void *thing)
{
    HDassert ( ((test_entry_t *)thing)->type == MEDIUM_ENTRY_TYPE );
    return(flush(f, dxpl_id, dest, addr, thing));
}

herr_t
large_flush(H5F_t *f, hid_t dxpl_id, hbool_t dest, haddr_t addr, void *thing)
{
    HDassert ( ((test_entry_t *)thing)->type == LARGE_ENTRY_TYPE );
    return(flush(f, dxpl_id, dest, addr, thing));
}

herr_t
huge_flush(H5F_t *f, hid_t dxpl_id, hbool_t dest, haddr_t addr, void *thing)
{
    HDassert ( ((test_entry_t *)thing)->type == HUGE_ENTRY_TYPE );
    return(flush(f, dxpl_id, dest, addr, thing));
}

herr_t
monster_flush(H5F_t *f, hid_t dxpl_id, hbool_t dest, haddr_t addr, void *thing)
{
    HDassert ( ((test_entry_t *)thing)->type == MONSTER_ENTRY_TYPE );
    return(flush(f, dxpl_id, dest, addr, thing));
}


/*-------------------------------------------------------------------------
 * Function:	load & friends
 *
 * Purpose:	"load" the requested entry and mark it as clean.  The
 *		helper functions verify that the correct version of load
 *		 is being called, and then call load proper.
 *
 * Return:	SUCCEED
 *
 * Programmer:	John Mainzer
 *              6/10/04
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */

void *
load(H5F_t UNUSED *f,
     hid_t UNUSED dxpl_id,
     haddr_t addr,
     const void UNUSED *udata1,
     void UNUSED *udata2)
{
    int32_t type;
    int32_t idx;
    test_entry_t * entry_ptr;
    test_entry_t * base_addr;

    addr_to_type_and_index(addr, &type, &idx);

    base_addr = entries[type];
    entry_ptr = &(base_addr[idx]);

    HDassert( entry_ptr->type == type );
    HDassert( entry_ptr->type >= 0 );
    HDassert( entry_ptr->type < NUMBER_OF_ENTRY_TYPES );
    HDassert( entry_ptr->index == idx );
    HDassert( entry_ptr->index >= 0 );
    HDassert( entry_ptr->index <= max_indices[type] );
    HDassert( entry_ptr == entry_ptr->self );
    HDassert( entry_ptr->addr == addr );
    HDassert( entry_ptr->size == entry_sizes[type] );

    entry_ptr->loaded = TRUE;

    entry_ptr->header.is_dirty = FALSE;
    entry_ptr->is_dirty = FALSE;

    (entry_ptr->reads)++;

    return(entry_ptr);

} /* load() */

void *
pico_load(H5F_t *f, hid_t dxpl_id, haddr_t addr,
          const void *udata1, void *udata2)
{
    return(load(f, dxpl_id, addr, udata1, udata2));
}

void *
nano_load(H5F_t *f, hid_t dxpl_id, haddr_t addr,
          const void *udata1, void *udata2)
{
    return(load(f, dxpl_id, addr, udata1, udata2));
}

void *
micro_load(H5F_t *f, hid_t dxpl_id, haddr_t addr,
           const void *udata1, void *udata2)
{
    return(load(f, dxpl_id, addr, udata1, udata2));
}

void *
tiny_load(H5F_t *f, hid_t dxpl_id, haddr_t addr,
          const void *udata1, void *udata2)
{
    return(load(f, dxpl_id, addr, udata1, udata2));
}

void *
small_load(H5F_t *f, hid_t dxpl_id, haddr_t addr,
           const void *udata1, void *udata2)
{
    return(load(f, dxpl_id, addr, udata1, udata2));
}

void *
medium_load(H5F_t *f, hid_t dxpl_id, haddr_t addr,
            const void *udata1, void *udata2)
{
    return(load(f, dxpl_id, addr, udata1, udata2));
}

void *
large_load(H5F_t *f, hid_t dxpl_id, haddr_t addr,
           const void *udata1, void *udata2)
{
    return(load(f, dxpl_id, addr, udata1, udata2));
}

void *
huge_load(H5F_t *f, hid_t dxpl_id, haddr_t addr,
          const void *udata1, void *udata2)
{
    return(load(f, dxpl_id, addr, udata1, udata2));
}

void *
monster_load(H5F_t *f, hid_t dxpl_id, haddr_t addr,
             const void *udata1, void *udata2)
{
    return(load(f, dxpl_id, addr, udata1, udata2));
}


/*-------------------------------------------------------------------------
 * Function:	size & friends
 *
 * Purpose:	Get the size of the specified entry.  The helper functions
 *		verify that the correct version of size is being called,
 *		and then call size proper.
 *
 * Return:	SUCCEED
 *
 * Programmer:	John Mainzer
 *              6/10/04
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */

herr_t
size(H5F_t UNUSED *  f,
     void *   thing,
     size_t * size_ptr)
{
    test_entry_t * entry_ptr;
    test_entry_t * base_addr;

    HDassert( size_ptr );
    HDassert( thing );

    entry_ptr = (test_entry_t *)thing;
    base_addr = entries[entry_ptr->type];

    HDassert( entry_ptr->index >= 0 );
    HDassert( entry_ptr->index <= max_indices[entry_ptr->type] );
    HDassert( entry_ptr == &(base_addr[entry_ptr->index]) );
    HDassert( entry_ptr == entry_ptr->self );
    HDassert( entry_ptr->header.addr == entry_ptr->addr );
    HDassert( entry_ptr->size == entry_sizes[entry_ptr->type] );

    *size_ptr = entry_ptr->size;

    return(SUCCEED);

} /* size() */

herr_t
pico_size(H5F_t * f, void * thing, size_t * size_ptr)
{
    HDassert ( ((test_entry_t *)thing)->type == PICO_ENTRY_TYPE );
    return(size(f, thing, size_ptr));
}

herr_t
nano_size(H5F_t * f, void * thing, size_t * size_ptr)
{
    HDassert ( ((test_entry_t *)thing)->type == NANO_ENTRY_TYPE );
    return(size(f, thing, size_ptr));
}

herr_t
micro_size(H5F_t * f, void * thing, size_t * size_ptr)
{
    HDassert ( ((test_entry_t *)thing)->type == MICRO_ENTRY_TYPE );
    return(size(f, thing, size_ptr));
}

herr_t
tiny_size(H5F_t * f, void * thing, size_t * size_ptr)
{
    HDassert ( ((test_entry_t *)thing)->type == TINY_ENTRY_TYPE );
    return(size(f, thing, size_ptr));
}

herr_t
small_size(H5F_t * f, void * thing, size_t * size_ptr)
{
    HDassert ( ((test_entry_t *)thing)->type == SMALL_ENTRY_TYPE );
    return(size(f, thing, size_ptr));
}

herr_t
medium_size(H5F_t * f, void * thing, size_t * size_ptr)
{
    HDassert ( ((test_entry_t *)thing)->type == MEDIUM_ENTRY_TYPE );
    return(size(f, thing, size_ptr));
}

herr_t
large_size(H5F_t * f, void * thing, size_t * size_ptr)
{
    HDassert ( ((test_entry_t *)thing)->type == LARGE_ENTRY_TYPE );
    return(size(f, thing, size_ptr));
}

herr_t
huge_size(H5F_t * f, void * thing, size_t * size_ptr)
{
    HDassert ( ((test_entry_t *)thing)->type == HUGE_ENTRY_TYPE );
    return(size(f, thing, size_ptr));
}

herr_t
monster_size(H5F_t * f, void * thing, size_t * size_ptr)
{
    HDassert ( ((test_entry_t *)thing)->type == MONSTER_ENTRY_TYPE );
    return(size(f, thing, size_ptr));
}


/**************************************************************************/
/**************************************************************************/
/************************** test utility functions: ***********************/
/**************************************************************************/
/**************************************************************************/

/*-------------------------------------------------------------------------
 * Function:	create_pinned_entry_dependency
 *
 * Purpose:	Do noting if pass is FALSE on entry.
 *
 *              Otherwise, set up a pinned entry dependency so we can 
 *              test the pinned entry modifications to the flush routine.
 *
 *		Given the types and indicies of the pinned and pinning
 *		entries, add the pinned entry to the list of pinned
 *		entries in the pinning entry, increment the 
 *		pinning reference count of the pinned entry, and
 *		if that count was zero initially, pin the entry.
 *
 * Return:	void
 *
 * Programmer:	John Mainzer
 *              6/10/04
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */

void
create_pinned_entry_dependency(H5C_t * cache_ptr,
		               int pinning_type,
                               int pinning_idx,
	                       int pinned_type,
	                       int pinned_idx)
{
    test_entry_t * pinning_base_addr;
    test_entry_t * pinning_entry_ptr;
    test_entry_t * pinned_base_addr;
    test_entry_t * pinned_entry_ptr;

    if ( pass ) {

        HDassert( ( 0 <= pinning_type ) && 
 	          ( pinning_type < NUMBER_OF_ENTRY_TYPES ) );
        HDassert( ( 0 <= pinning_idx ) && 
	          ( pinning_idx <= max_indices[pinning_type] ) );
        HDassert( ( 0 <= pinned_type ) && 
	          ( pinned_type < NUMBER_OF_ENTRY_TYPES ) );
        HDassert( ( 0 <= pinned_idx ) && 
	          ( pinned_idx <= max_indices[pinned_type] ) );

        pinning_base_addr = entries[pinning_type];
        pinning_entry_ptr = &(pinning_base_addr[pinning_idx]);

        pinned_base_addr = entries[pinned_type];
        pinned_entry_ptr = &(pinned_base_addr[pinned_idx]);

        HDassert( pinning_entry_ptr->index == pinning_idx );
        HDassert( pinning_entry_ptr->type == pinning_type );
        HDassert( pinning_entry_ptr == pinning_entry_ptr->self );
	HDassert( pinning_entry_ptr->num_pins < MAX_PINS );

        HDassert( pinning_entry_ptr->index == pinning_idx );
        HDassert( pinning_entry_ptr->type == pinning_type );
        HDassert( pinning_entry_ptr == pinning_entry_ptr->self );
	HDassert( ! ( pinning_entry_ptr->is_protected ) );

	pinning_entry_ptr->pin_type[pinning_entry_ptr->num_pins] = pinned_type;
	pinning_entry_ptr->pin_idx[pinning_entry_ptr->num_pins] = pinned_idx;
	(pinning_entry_ptr->num_pins)++;

        if ( pinned_entry_ptr->pinning_ref_count == 0 ) {

	    protect_entry(cache_ptr, pinned_type, pinned_idx);
	    unprotect_entry(cache_ptr, pinned_type, pinned_idx, FALSE, 
		            H5C__PIN_ENTRY_FLAG);
	}

	(pinned_entry_ptr->pinning_ref_count)++;
    }

    return;

} /* create_pinned_entry_dependency() */


/*-------------------------------------------------------------------------
 * Function:	entry_in_cache
 *
 * Purpose:	Given a pointer to a cache, an entry type, and an index,
 *		determine if the entry is currently in the cache.
 *
 * Return:	TRUE if the entry is in the cache, and FALSE otherwise.
 *
 * Programmer:	John Mainzer
 *              6/10/04
 *
 * Modifications:
 *
 *		JRM - 10/12/04
 *		Removed references to local_H5C_t, as we now get direct
 *		access to the definition of H5C_t via H5Cpkg.h.
 *
 *-------------------------------------------------------------------------
 */

hbool_t
entry_in_cache(H5C_t * cache_ptr,
               int32_t type,
               int32_t idx)
{
    hbool_t in_cache = FALSE; /* will set to TRUE if necessary */
    test_entry_t * base_addr;
    test_entry_t * entry_ptr;
    H5C_cache_entry_t * test_ptr = NULL;

    HDassert( cache_ptr );
    HDassert( ( 0 <= type ) && ( type < NUMBER_OF_ENTRY_TYPES ) );
    HDassert( ( 0 <= idx ) && ( idx <= max_indices[type] ) );

    base_addr = entries[type];
    entry_ptr = &(base_addr[idx]);

    HDassert( entry_ptr->index == idx );
    HDassert( entry_ptr->type == type );
    HDassert( entry_ptr == entry_ptr->self );

    H5C__SEARCH_INDEX(cache_ptr, entry_ptr->addr, test_ptr)

    if ( test_ptr != NULL ) {

        in_cache = TRUE;
        HDassert( test_ptr == (H5C_cache_entry_t *)entry_ptr );
        HDassert( entry_ptr->addr == entry_ptr->header.addr );
    }

    return(in_cache);

} /* entry_in_cache() */


/*-------------------------------------------------------------------------
 * Function:	reset_entries
 *
 * Purpose:	reset the contents of the entries arrays to know values.
 *
 * Return:	void
 *
 * Programmer:	John Mainzer
 *              6/10/04
 *
 * Modifications:
 *
 * 		JRM -- 3/31/06
 * 		Added initialization for new pinned entry test related
 * 		fields.
 *
 *-------------------------------------------------------------------------
 */

void
reset_entries(void)

{
    int i;
    int j;
    int k;
    int32_t max_index;
    haddr_t addr = 0;
    haddr_t alt_addr = PICO_ALT_BASE_ADDR;
    size_t entry_size;
    test_entry_t * base_addr;

    for ( i = 0; i < NUMBER_OF_ENTRY_TYPES; i++ )
    {
        entry_size = entry_sizes[i];
        max_index = max_indices[i];
        base_addr = entries[i];

        HDassert( base_addr );

        for ( j = 0; j <= max_index; j++ )
        {
            /* one can argue that we should fill the header with garbage.
             * If this is desired, we can simply comment out the header
             * initialization - the headers will be full of garbage soon
             * enough.
             */

            base_addr[j].header.addr = (haddr_t)0;
            base_addr[j].header.size = (size_t)0;
            base_addr[j].header.type = NULL;
            base_addr[j].header.is_dirty = FALSE;
            base_addr[j].header.is_protected = FALSE;
            base_addr[j].header.next = NULL;
            base_addr[j].header.prev = NULL;
            base_addr[j].header.aux_next = NULL;
            base_addr[j].header.aux_prev = NULL;

            base_addr[j].self = &(base_addr[j]);
            base_addr[j].cache_ptr = NULL;
            base_addr[j].addr = addr;
            base_addr[j].at_main_addr = TRUE;
            base_addr[j].main_addr = addr;
            base_addr[j].alt_addr = alt_addr;
            base_addr[j].size = entry_size;
            base_addr[j].type = i;
            base_addr[j].index = j;
            base_addr[j].reads = 0;
            base_addr[j].writes = 0;
            base_addr[j].is_dirty = FALSE;
            base_addr[j].is_protected = FALSE;

            base_addr[j].is_pinned = FALSE;
	    base_addr[j].pinning_ref_count = 0;
	    base_addr[j].num_pins = 0;
	    for ( k = 0; k < MAX_PINS; k++ )
            {
	        base_addr[j].pin_type[k] = -1;
		base_addr[j].pin_idx[k] = -1;
	    }

            base_addr[j].loaded = FALSE;
            base_addr[j].cleared = FALSE;
            base_addr[j].flushed = FALSE;
            base_addr[j].destroyed = FALSE;

            addr += (haddr_t)entry_size;
            alt_addr += (haddr_t)entry_size;
        }
    }

    return;

} /* reset_entries() */


/*-------------------------------------------------------------------------
 * Function:	verify_clean
 *
 * Purpose:	Verify that all cache entries are marked as clean.  If any
 *		are not, set pass to FALSE.
 *
 *		Do nothing if pass is FALSE on entry.
 *
 * Return:	void
 *
 * Programmer:	John Mainzer
 *              6/10/04
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */

void
verify_clean(void)

{
    int i;
    int j;
    int dirty_count = 0;
    int32_t max_index;
    test_entry_t * base_addr;

    if ( pass ) {

        for ( i = 0; i < NUMBER_OF_ENTRY_TYPES; i++ )
        {
            max_index = max_indices[i];
            base_addr = entries[i];

            HDassert( base_addr );

            for ( j = 0; j <= max_index; j++ )
            {
                if ( ( base_addr[j].header.is_dirty ) || ( base_addr[j].is_dirty ) ) {

                    dirty_count++;
                }
            }
        }

        if ( dirty_count > 0 ) {

            pass = FALSE;
            failure_mssg = "verify_clean() found dirty entry(s).";
        }
    }

    return;

} /* verify_clean() */


/*-------------------------------------------------------------------------
 * Function:	verify_unprotected
 *
 * Purpose:	Verify that no cache entries are marked as protected.  If
 *		any are, set pass to FALSE.
 *
 *		Do nothing if pass is FALSE on entry.
 *
 * Return:	void
 *
 * Programmer:	John Mainzer
 *              6/10/04
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */

void
verify_unprotected(void)

{
    int i;
    int j;
    int protected_count = 0;
    int32_t max_index;
    test_entry_t * base_addr;

    if ( pass ) {

        for ( i = 0; i < NUMBER_OF_ENTRY_TYPES; i++ )
        {
            max_index = max_indices[i];
            base_addr = entries[i];

            HDassert( base_addr );

            for ( j = 0; j <= max_index; j++ )
            {
                HDassert( base_addr[j].header.is_protected ==
                          base_addr[j].is_protected );

                if ( ( base_addr[j].header.is_protected ) ||
                     ( base_addr[j].is_protected ) ) {

                    protected_count++;
                }
            }
        }

        if ( protected_count > 0 ) {

            pass = FALSE;
            failure_mssg = "verify_unprotected() found protected entry(s).";
        }
    }

    return;

} /* verify_unprotected() */


/*-------------------------------------------------------------------------
 * Function:	setup_cache()
 *
 * Purpose:	Allocate a cache of the desired size and configure it for
 *		use in the test bed.  Return a pointer to the new cache
 *		structure.
 *
 * Return:	Pointer to new cache, or NULL on failure.
 *
 * Programmer:	John Mainzer
 *              6/11/04
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */

H5C_t *
setup_cache(size_t max_cache_size,
            size_t min_clean_size)
{
    H5C_t * cache_ptr = NULL;

    cache_ptr = H5C_create(max_cache_size,
                           min_clean_size,
                           (NUMBER_OF_ENTRY_TYPES - 1),
			   (const char **)entry_type_names,
                           check_write_permitted,
                           TRUE,
                           NULL,
                           NULL);

    if ( cache_ptr == NULL ) {

        pass = FALSE;
        failure_mssg = "H5C_create() returned NULL.";

    } else {

        H5C_set_skip_flags(cache_ptr, TRUE, TRUE);
    }

    return(cache_ptr);

} /* setup_cache() */


/*-------------------------------------------------------------------------
 * Function:	takedown_cache()
 *
 * Purpose:	Flush the specified cache and disable it.  If requested,
 *		dump stats first.  If pass is FALSE, do nothing.
 *
 * Return:	void
 *
 * Programmer:	John Mainzer
 *              6/11/04
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */

void
takedown_cache(H5C_t * cache_ptr,
               hbool_t dump_stats,
               hbool_t dump_detailed_stats)
{
    HDassert(cache_ptr);

    if ( pass ) {

        if ( dump_stats ) {

            H5C_stats(cache_ptr, "test cache", dump_detailed_stats);
        }

        H5C_dest(NULL, -1, -1, cache_ptr);
    }

    return;

} /* takedown_cache() */


/*-------------------------------------------------------------------------
 * Function:	flush_cache()
 *
 * Purpose:	Flush the specified cache, destroying all entries if
                requested.  If requested, dump stats first.
 *
 * Return:	void
 *
 * Programmer:	John Mainzer
 *              6/23/04
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */

void
flush_cache(H5C_t * cache_ptr,
            hbool_t destroy_entries,
            hbool_t dump_stats,
            hbool_t dump_detailed_stats)
{
    herr_t result = 0;

    HDassert(cache_ptr);

    verify_unprotected();

    if ( pass ) {

        if ( destroy_entries ) {

            result = H5C_flush_cache(NULL, -1, -1, cache_ptr,
                                     H5C__FLUSH_INVALIDATE_FLAG);

        } else {

            result = H5C_flush_cache(NULL, -1, -1, cache_ptr,
                                     H5C__NO_FLAGS_SET);
        }
    }

    if ( dump_stats ) {

        H5C_stats(cache_ptr, "test cache", dump_detailed_stats);
    }

    if ( result < 0 ) {

        pass = FALSE;
        failure_mssg = "error in H5C_flush_cache().";
    }

    return;

} /* flush_cache() */


/*-------------------------------------------------------------------------
 * Function:	insert_entry()
 *
 * Purpose:	Insert the entry indicated by the type and index.  Mark
 *		it clean or dirty as indicated.
 *
 *		Note that I don't see much practical use for inserting
 *		a clean entry, but the interface permits it so we should
 *		test it.
 *
 *		Do nothing if pass is false.
 *
 * Return:	void
 *
 * Programmer:	John Mainzer
 *              6/16/04
 *
 * Modifications:
 *
 *		JRM -- 1/13/05
 *		Updated function for the flags parameter in
 *		H5C_insert_entry(), and to allow access to this parameter.
 *
 *		JRM -- 6/17/05
 *		The interface no longer permits clean inserts.
 *		Accordingly, the dirty parameter is no longer meaningfull.
 *
 *		JRM -- 4/5/06
 *		Added code to initialize the new cache_ptr field of the
 *		test_entry_t structure.
 *
 *-------------------------------------------------------------------------
 */

void
insert_entry(H5C_t * cache_ptr,
             int32_t type,
             int32_t idx,
             hbool_t UNUSED dirty,
             unsigned int flags)
{
    herr_t result;
    test_entry_t * base_addr;
    test_entry_t * entry_ptr;

    if ( pass ) {

        HDassert( cache_ptr );
        HDassert( ( 0 <= type ) && ( type < NUMBER_OF_ENTRY_TYPES ) );
        HDassert( ( 0 <= idx ) && ( idx <= max_indices[type] ) );

        base_addr = entries[type];
        entry_ptr = &(base_addr[idx]);

        HDassert( entry_ptr->index == idx );
        HDassert( entry_ptr->type == type );
        HDassert( entry_ptr == entry_ptr->self );
        HDassert( !(entry_ptr->is_protected) );

	entry_ptr->is_dirty = TRUE;

        result = H5C_insert_entry(NULL, -1, -1, cache_ptr, &(types[type]),
                                  entry_ptr->addr, (void *)entry_ptr, flags);

        if ( ( result < 0 ) ||
             ( entry_ptr->header.is_protected ) ||
             ( entry_ptr->header.type != &(types[type]) ) ||
             ( entry_ptr->size != entry_ptr->header.size ) ||
             ( entry_ptr->addr != entry_ptr->header.addr ) ) {

            pass = FALSE;
            failure_mssg = "error in H5C_insert().";

#if 0
            /* This is useful debugging code.  Lets keep it around. */

            HDfprintf(stdout, "result = %d\n", (int)result);
            HDfprintf(stdout, "entry_ptr->header.is_protected = %d\n",
                      (int)(entry_ptr->header.is_protected));
            HDfprintf(stdout, 
		      "entry_ptr->header.type != &(types[type]) = %d\n",
                      (int)(entry_ptr->header.type != &(types[type])));
            HDfprintf(stdout,
                      "entry_ptr->size != entry_ptr->header.size = %d\n",
                      (int)(entry_ptr->size != entry_ptr->header.size));
            HDfprintf(stdout,
                      "entry_ptr->addr != entry_ptr->header.addr = %d\n",
                       (int)(entry_ptr->addr != entry_ptr->header.addr));
#endif
        }
	HDassert( entry_ptr->cache_ptr == NULL );

        entry_ptr->cache_ptr = cache_ptr;

        HDassert( entry_ptr->header.is_dirty );
        HDassert( ((entry_ptr->header).type)->id == type );
    }

    return;

} /* insert_entry() */


/*-------------------------------------------------------------------------
 * Function:	mark_pinned_entry_dirty()
 *
 * Purpose:	Mark the specified entry as dirty.  
 *
 *		Do nothing if pass is FALSE on entry.
 *
 * Return:	void
 *
 * Programmer:	John Mainzer
 *              3/28/06
 *
 * Modifications:
 *
 *		None.
 *
 *-------------------------------------------------------------------------
 */

void
mark_pinned_entry_dirty(H5C_t * cache_ptr,
                        int32_t type,
                        int32_t idx,
			hbool_t size_changed,
			size_t  new_size)
{
    /* const char * fcn_name = "mark_pinned_entry_dirty()"; */
    herr_t result;
    test_entry_t * base_addr;
    test_entry_t * entry_ptr;

    if ( pass ) {

        HDassert( cache_ptr );
        HDassert( ( 0 <= type ) && ( type < NUMBER_OF_ENTRY_TYPES ) );
        HDassert( ( 0 <= idx ) && ( idx <= max_indices[type] ) );

        base_addr = entries[type];
        entry_ptr = &(base_addr[idx]);

        HDassert( entry_ptr->index == idx );
        HDassert( entry_ptr->type == type );
        HDassert( entry_ptr == entry_ptr->self );
	HDassert( entry_ptr->cache_ptr == cache_ptr );
        HDassert( ! (entry_ptr->header.is_protected) );
        HDassert( entry_ptr->header.is_pinned );
	HDassert( entry_ptr->is_pinned );

	entry_ptr->is_dirty = TRUE;

        result = H5C_mark_pinned_entry_dirty(cache_ptr, 
			                     (void *)entry_ptr,
					     size_changed,
					     new_size);

        if ( ( result < 0 ) ||
             ( ! (entry_ptr->header.is_dirty) ) ||
             ( ! (entry_ptr->header.is_pinned) ) ||
             ( entry_ptr->header.type != &(types[type]) ) ||
             ( entry_ptr->size != entry_ptr->header.size ) ||
             ( entry_ptr->addr != entry_ptr->header.addr ) ) {

            pass = FALSE;
            failure_mssg = "error in H5C_mark_pinned_entry_dirty().";

        }

        HDassert( ((entry_ptr->header).type)->id == type );

    }

    return;

} /* mark_pinned_entry_dirty() */


/*-------------------------------------------------------------------------
 * Function:	mark_pinned_or_protected_entry_dirty()
 *
 * Purpose:	Mark the specified entry as dirty.  
 *
 *		Do nothing if pass is FALSE on entry.
 *
 * Return:	void
 *
 * Programmer:	John Mainzer
 *              5/17/06
 *
 * Modifications:
 *
 *		None.
 *
 *-------------------------------------------------------------------------
 */

void
mark_pinned_or_protected_entry_dirty(H5C_t * cache_ptr,
                                     int32_t type,
                                     int32_t idx)
{
    const char * fcn_name = "mark_pinned_or_protected_entry_dirty()";
    herr_t result;
    test_entry_t * base_addr;
    test_entry_t * entry_ptr;

    if ( pass ) {

        HDassert( cache_ptr );
        HDassert( ( 0 <= type ) && ( type < NUMBER_OF_ENTRY_TYPES ) );
        HDassert( ( 0 <= idx ) && ( idx <= max_indices[type] ) );

        base_addr = entries[type];
        entry_ptr = &(base_addr[idx]);

        HDassert( entry_ptr->index == idx );
        HDassert( entry_ptr->type == type );
        HDassert( entry_ptr == entry_ptr->self );
	HDassert( entry_ptr->cache_ptr == cache_ptr );
        HDassert( entry_ptr->header.is_protected || 
		  entry_ptr->header.is_pinned );

	entry_ptr->is_dirty = TRUE;

        result = H5C_mark_pinned_or_protected_entry_dirty(cache_ptr, 
			                                  (void *)entry_ptr);

        if ( ( result < 0 ) 
	     ||
	     ( ( ! (entry_ptr->header.is_protected) ) 
	       &&
	       ( ! (entry_ptr->header.is_pinned) ) 
	     ) 
	     ||
             ( ( entry_ptr->header.is_protected ) 
	       && 
	       ( ! ( entry_ptr->header.dirtied ) ) 
	     )
	     ||
             ( ( ! ( entry_ptr->header.is_protected ) )
	       && 
	       ( ! ( entry_ptr->header.is_dirty ) ) 
	     )
	     ||
             ( entry_ptr->header.type != &(types[type]) ) 
	     ||
             ( entry_ptr->size != entry_ptr->header.size ) 
	     ||
             ( entry_ptr->addr != entry_ptr->header.addr ) ) {

            pass = FALSE;
            failure_mssg = 
                "error in H5C_mark_pinned_or_protected_entry_dirty().";

        }

        HDassert( ((entry_ptr->header).type)->id == type );

    }

    return;

} /* mark_pinned_or_protected_entry_dirty() */


/*-------------------------------------------------------------------------
 * Function:	rename_entry()
 *
 * Purpose:	Rename the entry indicated by the type and index to its
 *		main or alternate address as indicated.  If the entry is
 *		already at the desired entry, do nothing.
 *
 * Return:	void
 *
 * Programmer:	John Mainzer
 *              6/21/04
 *
 * Modifications:
 *
 *		JRM -- 6/17/05
 *		Updated code to reflect the fact that renames automatically
 *		dirty entries.
 *
 *-------------------------------------------------------------------------
 */

void
rename_entry(H5C_t * cache_ptr,
             int32_t type,
             int32_t idx,
             hbool_t main_addr)
{
    herr_t         result;
    hbool_t	   done = TRUE; /* will set to FALSE if we have work to do */
    haddr_t        old_addr = HADDR_UNDEF;
    haddr_t        new_addr = HADDR_UNDEF;
    test_entry_t * base_addr;
    test_entry_t * entry_ptr;

    HDassert( cache_ptr );
    HDassert( ( 0 <= type ) && ( type < NUMBER_OF_ENTRY_TYPES ) );
    HDassert( ( 0 <= idx ) && ( idx <= max_indices[type] ) );

    base_addr = entries[type];
    entry_ptr = &(base_addr[idx]);

    HDassert( entry_ptr->index == idx );
    HDassert( entry_ptr->type == type );
    HDassert( entry_ptr == entry_ptr->self );
    HDassert( entry_ptr->cache_ptr == cache_ptr );
    HDassert( !(entry_ptr->is_protected) );
    HDassert( !(entry_ptr->header.is_protected) );


    if ( entry_ptr->at_main_addr && !main_addr ) {

        /* rename to alt addr */

        HDassert( entry_ptr->addr == entry_ptr->main_addr );

        done = FALSE;
        old_addr = entry_ptr->addr;
        new_addr = entry_ptr->alt_addr;

    } else if ( !(entry_ptr->at_main_addr) && main_addr ) {

        /* rename to main addr */

        HDassert( entry_ptr->addr == entry_ptr->alt_addr );

        done = FALSE;
        old_addr = entry_ptr->addr;
        new_addr = entry_ptr->main_addr;
    }

    if ( ! done ) {

        entry_ptr->is_dirty = TRUE;

        result = H5C_rename_entry(cache_ptr, &(types[type]),
                                  old_addr, new_addr);
    }

    if ( ! done ) {

        if ( ( result < 0 ) || ( entry_ptr->header.addr != new_addr ) ) {

            pass = FALSE;
            failure_mssg = "error in H5C_rename_entry().";

        } else {

            entry_ptr->addr = new_addr;
            entry_ptr->at_main_addr = main_addr;
        }
    }

    HDassert( ((entry_ptr->header).type)->id == type );

    HDassert( entry_ptr->header.is_dirty );
    HDassert( entry_ptr->is_dirty );

    return;

} /* rename_entry() */


/*-------------------------------------------------------------------------
 * Function:	protect_entry()
 *
 * Purpose:	Protect the entry indicated by the type and index.
 *
 *		Do nothing if pass is FALSE on entry.
 *
 * Return:	void
 *
 * Programmer:	John Mainzer
 *              6/11/04
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */

void
protect_entry(H5C_t * cache_ptr,
              int32_t type,
              int32_t idx)
{
    /* const char * fcn_name = "protect_entry()"; */
    test_entry_t * base_addr;
    test_entry_t * entry_ptr;
    H5C_cache_entry_t * cache_entry_ptr;

    if ( pass ) {

        HDassert( cache_ptr );
        HDassert( ( 0 <= type ) && ( type < NUMBER_OF_ENTRY_TYPES ) );
        HDassert( ( 0 <= idx ) && ( idx <= max_indices[type] ) );

        base_addr = entries[type];
        entry_ptr = &(base_addr[idx]);

        HDassert( entry_ptr->index == idx );
        HDassert( entry_ptr->type == type );
        HDassert( entry_ptr == entry_ptr->self );
        HDassert( !(entry_ptr->is_protected) );

        cache_entry_ptr = H5C_protect(NULL, -1, -1, cache_ptr, &(types[type]),
                                      entry_ptr->addr, NULL, NULL);

        if ( ( cache_entry_ptr != (void *)entry_ptr ) ||
             ( !(entry_ptr->header.is_protected) ) ||
             ( entry_ptr->header.type != &(types[type]) ) ||
             ( entry_ptr->size != entry_ptr->header.size ) ||
             ( entry_ptr->addr != entry_ptr->header.addr ) ) {

#if 0
            /* I've written the following debugging code several times
             * now.  Lets keep it around so I don't have to write it
             * again.
             *                              - JRM
             */
            HDfprintf(stdout, "( cache_entry_ptr != (void *)entry_ptr ) = %d\n",
                      (int)( cache_entry_ptr != (void *)entry_ptr ));
            HDfprintf(stdout, "cache_entry_ptr = 0x%lx, entry_ptr = 0x%lx\n",
                      (long)cache_entry_ptr, (long)entry_ptr);
            HDfprintf(stdout, "entry_ptr->header.is_protected = %d\n",
                      (int)(entry_ptr->header.is_protected));
            HDfprintf(stdout,
                      "( entry_ptr->header.type != &(types[type]) ) = %d\n",
                      (int)( entry_ptr->header.type != &(types[type]) ));
            HDfprintf(stdout,
                      "entry_ptr->size = %d, entry_ptr->header.size = %d\n",
                      (int)(entry_ptr->size), (int)(entry_ptr->header.size));
            HDfprintf(stdout,
                      "entry_ptr->addr = %d, entry_ptr->header.addr = %d\n",
                      (int)(entry_ptr->addr), (int)(entry_ptr->header.addr));
#endif
            pass = FALSE;
            failure_mssg = "error in H5C_protect().";

        } else {
	
	    HDassert( ( entry_ptr->cache_ptr == NULL ) || 
		      ( entry_ptr->cache_ptr == cache_ptr ) );

	    entry_ptr->cache_ptr = cache_ptr;
            entry_ptr->is_protected = TRUE;

        }

        HDassert( ((entry_ptr->header).type)->id == type );
    }

    return;

} /* protect_entry() */


/*-------------------------------------------------------------------------
 * Function:	unpin_entry()
 *
 * Purpose:	Unpin the entry indicated by the type and index.
 *
 *		Do nothing if pass is FALSE on entry.
 *
 * Return:	void
 *
 * Programmer:	John Mainzer
 *              3/28/06
 *
 * Modifications:
 *
 *		None.
 *
 *-------------------------------------------------------------------------
 */

void
unpin_entry(H5C_t * cache_ptr,
            int32_t type,
            int32_t idx)
{
    /* const char * fcn_name = "unpin_entry()"; */
    herr_t result;
    test_entry_t * base_addr;
    test_entry_t * entry_ptr;

    if ( pass ) {

        HDassert( cache_ptr );
        HDassert( ( 0 <= type ) && ( type < NUMBER_OF_ENTRY_TYPES ) );
        HDassert( ( 0 <= idx ) && ( idx <= max_indices[type] ) );

        base_addr = entries[type];
        entry_ptr = &(base_addr[idx]);

        HDassert( entry_ptr->index == idx );
        HDassert( entry_ptr->type == type );
        HDassert( entry_ptr == entry_ptr->self );
	HDassert( entry_ptr->cache_ptr == cache_ptr );
        HDassert( ! (entry_ptr->header.is_protected) );
        HDassert( entry_ptr->header.is_pinned );
	HDassert( entry_ptr->is_pinned );

        result = H5C_unpin_entry(cache_ptr, (void *)entry_ptr);

        if ( ( result < 0 ) ||
             ( entry_ptr->header.is_pinned ) ||
             ( entry_ptr->header.type != &(types[type]) ) ||
             ( entry_ptr->size != entry_ptr->header.size ) ||
             ( entry_ptr->addr != entry_ptr->header.addr ) ) {

            pass = FALSE;
            failure_mssg = "error in H5C_unpin().";

        }

	entry_ptr->is_pinned = FALSE;

        HDassert( ((entry_ptr->header).type)->id == type );

    }

    return;

} /* unpin_entry() */


/*-------------------------------------------------------------------------
 * Function:	unprotect_entry()
 *
 * Purpose:	Unprotect the entry indicated by the type and index.
 *
 *		Do nothing if pass is FALSE on entry.
 *
 * Return:	void
 *
 * Programmer:	John Mainzer
 *              6/12/04
 *
 * Modifications:
 *
 *		JRM -- 1/7/05
 *		Updated for the replacement of the deleted parameter in
 *		H5C_unprotect() with the new flags parameter.
 *
 *		JRM - 6/17/05
 *		Modified function to use the new dirtied parameter of
 *		H5C_unprotect().
 *
 *		JRM -- 9/8/05
 *		Update for new entry size parameter in H5C_unprotect().
 *		We don't use them here for now.
 *
 *		JRM -- 3/31/06
 *		Update for pinned entries.
 *
 *-------------------------------------------------------------------------
 */

void
unprotect_entry(H5C_t * cache_ptr,
                int32_t type,
                int32_t idx,
                int dirty,
                unsigned int flags)
{
    /* const char * fcn_name = "unprotect_entry()"; */
    herr_t result;
    hbool_t pin_flag_set;
    hbool_t unpin_flag_set;
    test_entry_t * base_addr;
    test_entry_t * entry_ptr;

    if ( pass ) {

        HDassert( cache_ptr );
        HDassert( ( 0 <= type ) && ( type < NUMBER_OF_ENTRY_TYPES ) );
        HDassert( ( 0 <= idx ) && ( idx <= max_indices[type] ) );

        base_addr = entries[type];
        entry_ptr = &(base_addr[idx]);

        HDassert( entry_ptr->index == idx );
        HDassert( entry_ptr->type == type );
        HDassert( entry_ptr == entry_ptr->self );
	HDassert( entry_ptr->cache_ptr == cache_ptr );
        HDassert( entry_ptr->header.is_protected );
        HDassert( entry_ptr->is_protected );

	pin_flag_set = ((flags & H5C__PIN_ENTRY_FLAG) != 0 );
	unpin_flag_set = ((flags & H5C__UNPIN_ENTRY_FLAG) != 0 );

	HDassert ( ! ( pin_flag_set && unpin_flag_set ) );
	HDassert ( ( ! pin_flag_set ) || ( ! (entry_ptr->is_pinned) ) );
	HDassert ( ( ! unpin_flag_set ) || ( entry_ptr->is_pinned ) );

        if ( ( dirty == TRUE ) || ( dirty == FALSE ) ) {

            flags |= (dirty ? H5C__DIRTIED_FLAG : H5C__NO_FLAGS_SET);
            entry_ptr->is_dirty = (entry_ptr->is_dirty || dirty);
        }

        result = H5C_unprotect(NULL, -1, -1, cache_ptr, &(types[type]),
                               entry_ptr->addr, (void *)entry_ptr,
                               flags, 0);

        if ( ( result < 0 ) ||
             ( entry_ptr->header.is_protected ) ||
             ( entry_ptr->header.type != &(types[type]) ) ||
             ( entry_ptr->size != entry_ptr->header.size ) ||
             ( entry_ptr->addr != entry_ptr->header.addr ) ) {

            pass = FALSE;
            failure_mssg = "error in H5C_unprotect().";

        }
        else
        {
            entry_ptr->is_protected = FALSE;

	    if ( pin_flag_set ) {

	        HDassert ( entry_ptr->header.is_pinned );
		entry_ptr->is_pinned = TRUE;

	    } else if ( unpin_flag_set ) {

	        HDassert ( ! ( entry_ptr->header.is_pinned ) );
		entry_ptr->is_pinned = FALSE;

            }
        }

        HDassert( ((entry_ptr->header).type)->id == type );

        if ( ( flags & H5C__DIRTIED_FLAG ) != 0
                && ( (flags & H5C__DELETED_FLAG) == 0 ) ) {

            HDassert( entry_ptr->header.is_dirty );
            HDassert( entry_ptr->is_dirty );
        }
    }

    return;

} /* unprotect_entry() */


/*-------------------------------------------------------------------------
 * Function:	row_major_scan_forward()
 *
 * Purpose:	Do a sequence of inserts, protects, unprotects, renames,
 *		destroys while scanning through the set of entries.  If
 *		pass is false on entry, do nothing.
 *
 * Return:	void
 *
 * Programmer:	John Mainzer
 *              6/12/04
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */

void
row_major_scan_forward(H5C_t * cache_ptr,
                       int32_t lag,
                       hbool_t verbose,
                       hbool_t reset_stats,
                       hbool_t display_stats,
                       hbool_t display_detailed_stats,
                       hbool_t do_inserts,
                       hbool_t dirty_inserts,
                       hbool_t do_renames,
                       hbool_t rename_to_main_addr,
                       hbool_t do_destroys,
                       int dirty_destroys,
                       int dirty_unprotects)
{
    const char * fcn_name = "row_major_scan_forward";
    int32_t type;
    int32_t idx;

    if ( verbose )
        HDfprintf(stdout, "%s(): entering.\n", fcn_name);

    HDassert( lag > 5 );

    type = 0;

    if ( ( pass ) && ( reset_stats ) ) {

        H5C_stats__reset(cache_ptr);
    }

    while ( ( pass ) && ( type < NUMBER_OF_ENTRY_TYPES ) )
    {
        idx = -lag;

        while ( ( pass ) && ( idx <= (max_indices[type] + lag) ) )
        {
            if ( ( pass ) && ( do_inserts ) && ( (idx + lag) >= 0 ) &&
                 ( (idx + lag) <= max_indices[type] ) &&
                 ( ((idx + lag) % 2) == 0 ) &&
                 ( ! entry_in_cache(cache_ptr, type, (idx + lag)) ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(i, %d, %d) ", type, (idx + lag));

                insert_entry(cache_ptr, type, (idx + lag), dirty_inserts,
                             H5C__NO_FLAGS_SET);
            }


            if ( ( pass ) && ( (idx + lag - 1) >= 0 ) &&
                 ( (idx + lag - 1) <= max_indices[type] ) &&
                 ( ( (idx + lag - 1) % 3 ) == 0 ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(p, %d, %d) ", type, (idx + lag - 1));

                protect_entry(cache_ptr, type, (idx + lag - 1));
            }

            if ( ( pass ) && ( (idx + lag - 2) >= 0 ) &&
                 ( (idx + lag - 2) <= max_indices[type] ) &&
                 ( ( (idx + lag - 2) % 3 ) == 0 ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(u, %d, %d) ", type, (idx + lag - 2));

                unprotect_entry(cache_ptr, type, idx+lag-2, NO_CHANGE,
                                H5C__NO_FLAGS_SET);
            }


            if ( ( pass ) && ( do_renames ) && ( (idx + lag - 2) >= 0 ) &&
                 ( (idx + lag - 2) <= max_indices[type] ) &&
                 ( ( (idx + lag - 2) % 3 ) == 0 ) ) {

                rename_entry(cache_ptr, type, (idx + lag - 2),
                             rename_to_main_addr);
            }


            if ( ( pass ) && ( (idx + lag - 3) >= 0 ) &&
                 ( (idx + lag - 3) <= max_indices[type] ) &&
                 ( ( (idx + lag - 3) % 5 ) == 0 ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(p, %d, %d) ", type, (idx + lag - 3));

                protect_entry(cache_ptr, type, (idx + lag - 3));
            }

            if ( ( pass ) && ( (idx + lag - 5) >= 0 ) &&
                 ( (idx + lag - 5) <= max_indices[type] ) &&
                 ( ( (idx + lag - 5) % 5 ) == 0 ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(u, %d, %d) ", type, (idx + lag - 5));

                unprotect_entry(cache_ptr, type, idx+lag-5, NO_CHANGE,
                                H5C__NO_FLAGS_SET);
            }

            if ( ( pass ) && ( idx >= 0 ) && ( idx <= max_indices[type] ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(p, %d, %d) ", type, idx);

                protect_entry(cache_ptr, type, idx);
            }


            if ( ( pass ) && ( (idx - lag + 2) >= 0 ) &&
                 ( (idx - lag + 2) <= max_indices[type] ) &&
                 ( ( (idx - lag + 2) % 7 ) == 0 ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(u, %d, %d) ", type, (idx - lag + 2));

                unprotect_entry(cache_ptr, type, idx-lag+2, NO_CHANGE,
                                H5C__NO_FLAGS_SET);
            }

            if ( ( pass ) && ( (idx - lag + 1) >= 0 ) &&
                 ( (idx - lag + 1) <= max_indices[type] ) &&
                 ( ( (idx - lag + 1) % 7 ) == 0 ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(p, %d, %d) ", type, (idx - lag + 1));

                protect_entry(cache_ptr, type, (idx - lag + 1));
            }


            if ( do_destroys ) {

                if ( ( pass ) && ( (idx - lag) >= 0 ) &&
                     ( ( idx - lag) <= max_indices[type] ) ) {

                    switch ( (idx - lag) %4 ) {

                        case 0: /* we just did an insert */
                            unprotect_entry(cache_ptr, type, idx - lag,
                                            NO_CHANGE, H5C__NO_FLAGS_SET);
                            break;

                        case 1:
                            if ( (entries[type])[idx-lag].is_dirty ) {

                                unprotect_entry(cache_ptr, type, idx - lag,
                                                NO_CHANGE, H5C__NO_FLAGS_SET);
                            } else {

                                unprotect_entry(cache_ptr, type, idx - lag,
                                                dirty_unprotects,
                                                H5C__NO_FLAGS_SET);
                            }
                            break;

                        case 2: /* we just did an insrt */
                            unprotect_entry(cache_ptr, type, idx - lag,
                                            NO_CHANGE, H5C__DELETED_FLAG);
                            break;

                        case 3:
                            if ( (entries[type])[idx-lag].is_dirty ) {

                                unprotect_entry(cache_ptr, type, idx - lag,
                                                NO_CHANGE, H5C__DELETED_FLAG);
                            } else {

                                unprotect_entry(cache_ptr, type, idx - lag,
                                                dirty_destroys,
                                                H5C__DELETED_FLAG);
                            }
                            break;

                        default:
                            HDassert(0); /* this can't happen... */
                            break;
                    }
                }

            } else {

                if ( ( pass ) && ( (idx - lag) >= 0 ) &&
                     ( ( idx - lag) <= max_indices[type] ) ) {

                    if ( verbose )
                        HDfprintf(stdout, "(u, %d, %d) ", type, (idx - lag));

                    unprotect_entry(cache_ptr, type, idx - lag,
                                    dirty_unprotects, H5C__NO_FLAGS_SET);
                }
            }

            if ( verbose )
                HDfprintf(stdout, "\n");

            idx++;
        }
        type++;
    }

    if ( ( pass ) && ( display_stats ) ) {

        H5C_stats(cache_ptr, "test cache", display_detailed_stats);
    }

    return;

} /* row_major_scan_forward() */


/*-------------------------------------------------------------------------
 * Function:	hl_row_major_scan_forward()
 *
 * Purpose:	Do a high locality sequence of inserts, protects, and
 *		unprotects while scanning through the set of entries.
 *		If pass is false on entry, do nothing.
 *
 * Return:	void
 *
 * Programmer:	John Mainzer
 *              10/21/04
 *
 * Modifications:
 *
 *		JRM -- 1/21/05
 *		Added the max_index parameter to allow the caller to
 *		throttle the size of the inner loop, and thereby the
 *		execution time of the function.
 *
 *-------------------------------------------------------------------------
 */

void
hl_row_major_scan_forward(H5C_t * cache_ptr,
                          int32_t max_index,
                          hbool_t verbose,
                          hbool_t reset_stats,
                          hbool_t display_stats,
                          hbool_t display_detailed_stats,
                          hbool_t do_inserts,
                          hbool_t dirty_inserts)
{
    const char * fcn_name = "hl_row_major_scan_forward";
    int32_t type;
    int32_t idx;
    int32_t i;
    int32_t lag = 100;
    int32_t local_max_index;

    if ( verbose )
        HDfprintf(stdout, "%s(): entering.\n", fcn_name);

    HDassert( lag > 5 );
    HDassert( max_index >= 200 );
    HDassert( max_index <= MAX_ENTRIES );

    type = 0;

    if ( ( pass ) && ( reset_stats ) ) {

        H5C_stats__reset(cache_ptr);
    }

    while ( ( pass ) && ( type < NUMBER_OF_ENTRY_TYPES ) )
    {
        idx = -lag;

        local_max_index = MIN(max_index, max_indices[type]);

        while ( ( pass ) && ( idx <= (local_max_index + lag) ) )
        {
            if ( ( pass ) && ( do_inserts ) && ( (idx + lag) >= 0 ) &&
                 ( (idx + lag) <= max_indices[type] ) &&
                 ( ((idx + lag) % 2) == 0 ) &&
                 ( ! entry_in_cache(cache_ptr, type, (idx + lag)) ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(i, %d, %d) ", type, (idx + lag));

                insert_entry(cache_ptr, type, (idx + lag), dirty_inserts,
                             H5C__NO_FLAGS_SET);
            }

            i = idx;

            while ( ( pass ) && ( i >= idx - lag ) && ( i >= 0 ) )
            {
                if ( ( pass ) && ( i >= 0 ) && ( i <= local_max_index ) ) {

                    if ( verbose )
                        HDfprintf(stdout, "(p, %d, %d) ", type, i);

                    protect_entry(cache_ptr, type, i);

                    if ( verbose )
                        HDfprintf(stdout, "(u, %d, %d) ", type, i);

                    unprotect_entry(cache_ptr, type, i, NO_CHANGE,
                                    H5C__NO_FLAGS_SET);
                }
                i--;
            }

            if ( verbose )
                HDfprintf(stdout, "\n");

            idx++;
        }
        type++;
    }

    if ( ( pass ) && ( display_stats ) ) {

        H5C_stats(cache_ptr, "test cache", display_detailed_stats);
    }

    return;

} /* hl_row_major_scan_forward() */


/*-------------------------------------------------------------------------
 * Function:	row_major_scan_backward()
 *
 * Purpose:	Do a sequence of inserts, protects, unprotects, renames,
 *		destroys while scanning backwards through the set of
 *		entries.  If pass is false on entry, do nothing.
 *
 * Return:	void
 *
 * Programmer:	John Mainzer
 *              6/12/04
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */

void
row_major_scan_backward(H5C_t * cache_ptr,
                        int32_t lag,
                        hbool_t verbose,
                        hbool_t reset_stats,
                        hbool_t display_stats,
                        hbool_t display_detailed_stats,
                        hbool_t do_inserts,
                        hbool_t dirty_inserts,
                        hbool_t do_renames,
                        hbool_t rename_to_main_addr,
                        hbool_t do_destroys,
                        int dirty_destroys,
                        int dirty_unprotects)
{
    const char * fcn_name = "row_major_scan_backward";
    int32_t type;
    int32_t idx;

    if ( verbose )
        HDfprintf(stdout, "%s(): Entering.\n", fcn_name);

    HDassert( lag > 5 );

    type = NUMBER_OF_ENTRY_TYPES - 1;

    if ( ( pass ) && ( reset_stats ) ) {

        H5C_stats__reset(cache_ptr);
    }

    while ( ( pass ) && ( type >= 0 ) )
    {
        idx = max_indices[type] + lag;

        while ( ( pass ) && ( idx >= -lag ) )
        {
            if ( ( pass ) && ( do_inserts ) && ( (idx - lag) >= 0 ) &&
                 ( (idx - lag) <= max_indices[type] ) &&
                 ( ((idx - lag) % 2) == 1 ) &&
                 ( ! entry_in_cache(cache_ptr, type, (idx - lag)) ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(i, %d, %d) ", type, (idx - lag));

                insert_entry(cache_ptr, type, (idx - lag), dirty_inserts,
                             H5C__NO_FLAGS_SET);
            }


            if ( ( pass ) && ( (idx - lag + 1) >= 0 ) &&
                 ( (idx - lag + 1) <= max_indices[type] ) &&
                 ( ( (idx - lag + 1) % 3 ) == 0 ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(p, %d, %d) ", type, (idx - lag + 1));

                protect_entry(cache_ptr, type, (idx - lag + 1));
            }

            if ( ( pass ) && ( (idx - lag + 2) >= 0 ) &&
                 ( (idx - lag + 2) <= max_indices[type] ) &&
                 ( ( (idx - lag + 2) % 3 ) == 0 ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(u, %d, %d) ", type, (idx - lag + 2));

                unprotect_entry(cache_ptr, type, idx-lag+2, NO_CHANGE,
                                H5C__NO_FLAGS_SET);
            }


            if ( ( pass ) && ( do_renames ) && ( (idx - lag + 2) >= 0 ) &&
                 ( (idx - lag + 2) <= max_indices[type] ) &&
                 ( ( (idx - lag + 2) % 3 ) == 0 ) ) {

                rename_entry(cache_ptr, type, (idx - lag + 2),
                             rename_to_main_addr);
            }


            if ( ( pass ) && ( (idx - lag + 3) >= 0 ) &&
                 ( (idx - lag + 3) <= max_indices[type] ) &&
                 ( ( (idx - lag + 3) % 5 ) == 0 ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(p, %d, %d) ", type, (idx - lag + 3));

                protect_entry(cache_ptr, type, (idx - lag + 3));
            }

            if ( ( pass ) && ( (idx - lag + 5) >= 0 ) &&
                 ( (idx - lag + 5) <= max_indices[type] ) &&
                 ( ( (idx - lag + 5) % 5 ) == 0 ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(u, %d, %d) ", type, (idx - lag + 5));

                unprotect_entry(cache_ptr, type, idx-lag+5, NO_CHANGE,
                                H5C__NO_FLAGS_SET);
            }

            if ( ( pass ) && ( idx >= 0 ) && ( idx <= max_indices[type] ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(p, %d, %d) ", type, idx);

                protect_entry(cache_ptr, type, idx);
            }


            if ( ( pass ) && ( (idx + lag - 2) >= 0 ) &&
                 ( (idx + lag - 2) <= max_indices[type] ) &&
                 ( ( (idx + lag - 2) % 7 ) == 0 ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(u, %d, %d) ", type, (idx + lag - 2));

                unprotect_entry(cache_ptr, type, idx+lag-2, NO_CHANGE,
                                H5C__NO_FLAGS_SET);
            }

            if ( ( pass ) && ( (idx + lag - 1) >= 0 ) &&
                 ( (idx + lag - 1) <= max_indices[type] ) &&
                 ( ( (idx + lag - 1) % 7 ) == 0 ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(p, %d, %d) ", type, (idx + lag - 1));

                protect_entry(cache_ptr, type, (idx + lag - 1));
            }


            if ( do_destroys ) {

                if ( ( pass ) && ( (idx + lag) >= 0 ) &&
                     ( ( idx + lag) <= max_indices[type] ) ) {

                    switch ( (idx + lag) %4 ) {

                        case 0:
                            if ( (entries[type])[idx+lag].is_dirty ) {

                                unprotect_entry(cache_ptr, type, idx + lag,
                                                NO_CHANGE, H5C__NO_FLAGS_SET);
                            } else {

                                unprotect_entry(cache_ptr, type, idx + lag,
                                                dirty_unprotects,
                                                H5C__NO_FLAGS_SET);
                            }
                            break;

                        case 1: /* we just did an insert */
                            unprotect_entry(cache_ptr, type, idx + lag,
                                            NO_CHANGE, H5C__NO_FLAGS_SET);
                            break;

                        case 2:
                            if ( (entries[type])[idx + lag].is_dirty ) {

                                unprotect_entry(cache_ptr, type, idx + lag,
                                                NO_CHANGE, H5C__DELETED_FLAG);
                            } else {

                                unprotect_entry(cache_ptr, type, idx + lag,
                                                dirty_destroys,
                                                H5C__DELETED_FLAG);
                            }
                            break;

                        case 3: /* we just did an insrt */
                            unprotect_entry(cache_ptr, type, idx + lag,
                                            NO_CHANGE, H5C__DELETED_FLAG);
                            break;

                        default:
                            HDassert(0); /* this can't happen... */
                            break;
                    }
                }
            } else {

                if ( ( pass ) && ( (idx + lag) >= 0 ) &&
                     ( ( idx + lag) <= max_indices[type] ) ) {

                    if ( verbose )
                        HDfprintf(stdout, "(u, %d, %d) ", type, (idx - lag));

                    unprotect_entry(cache_ptr, type, idx + lag,
                                    dirty_unprotects, H5C__NO_FLAGS_SET);
                }
            }

            if ( verbose )
                HDfprintf(stdout, "\n");

            idx--;
        }
        type--;
    }

    if ( ( pass ) && ( display_stats ) ) {

        H5C_stats(cache_ptr, "test cache", display_detailed_stats);
    }

    return;

} /* row_major_scan_backward() */


/*-------------------------------------------------------------------------
 * Function:	hl_row_major_scan_backward()
 *
 * Purpose:	Do a high locality sequence of inserts, protects, and
 *		unprotects while scanning through the set of entries.
 *		If pass is false on entry, do nothing.
 *
 * Return:	void
 *
 * Programmer:	John Mainzer
 *              10/21/04
 *
 * Modifications:
 *
 *		JRM -- 1/21/05
 *		Added the max_index parameter to allow the caller to
 *		throttle the size of the inner loop, and thereby the
 *		execution time of the function.
 *
 *-------------------------------------------------------------------------
 */

void
hl_row_major_scan_backward(H5C_t * cache_ptr,
                           int32_t max_index,
                           hbool_t verbose,
                           hbool_t reset_stats,
                           hbool_t display_stats,
                           hbool_t display_detailed_stats,
                           hbool_t do_inserts,
                           hbool_t dirty_inserts)
{
    const char * fcn_name = "hl_row_major_scan_backward";
    int32_t type;
    int32_t idx;
    int32_t i;
    int32_t lag = 100;
    int32_t local_max_index;

    if ( verbose )
        HDfprintf(stdout, "%s(): entering.\n", fcn_name);

    HDassert( lag > 5 );
    HDassert( max_index >= 200 );
    HDassert( max_index <= MAX_ENTRIES );

    type = NUMBER_OF_ENTRY_TYPES - 1;

    if ( ( pass ) && ( reset_stats ) ) {

        H5C_stats__reset(cache_ptr);
    }

    while ( ( pass ) && ( type >= 0 ) )
    {
        idx = max_indices[type] + lag;

        local_max_index = MIN(max_index, max_indices[type]);

        while ( ( pass ) && ( idx >= -lag ) )
        {
            if ( ( pass ) && ( do_inserts ) && ( (idx + lag) >= 0 ) &&
                 ( (idx + lag) <= local_max_index ) &&
                 ( ((idx + lag) % 2) == 0 ) &&
                 ( ! entry_in_cache(cache_ptr, type, (idx + lag)) ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(i, %d, %d) ", type, (idx + lag));

                insert_entry(cache_ptr, type, (idx + lag), dirty_inserts,
                             H5C__NO_FLAGS_SET);
            }

            i = idx;

            while ( ( pass ) && ( i >= idx - lag ) && ( i >= 0 ) )
            {
                if ( ( pass ) && ( i >= 0 ) && ( i <= local_max_index ) ) {

                    if ( verbose )
                        HDfprintf(stdout, "(p, %d, %d) ", type, i);

                    protect_entry(cache_ptr, type, i);

                    if ( verbose )
                        HDfprintf(stdout, "(u, %d, %d) ", type, i);

                    unprotect_entry(cache_ptr, type, i, NO_CHANGE,
                                    H5C__NO_FLAGS_SET);
                }
                i--;
            }

            if ( verbose )
                HDfprintf(stdout, "\n");

            idx--;
        }
        type--;
    }

    if ( ( pass ) && ( display_stats ) ) {

        H5C_stats(cache_ptr, "test cache", display_detailed_stats);
    }

    return;

} /* hl_row_major_scan_backward() */


/*-------------------------------------------------------------------------
 * Function:	col_major_scan_forward()
 *
 * Purpose:	Do a sequence of inserts, protects, and unprotects
 *		while scanning through the set of entries.  If
 *		pass is false on entry, do nothing.
 *
 * Return:	void
 *
 * Programmer:	John Mainzer
 *              6/23/04
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */

void
col_major_scan_forward(H5C_t * cache_ptr,
                       int32_t lag,
                       hbool_t verbose,
                       hbool_t reset_stats,
                       hbool_t display_stats,
                       hbool_t display_detailed_stats,
                       hbool_t do_inserts,
                       hbool_t dirty_inserts,
                       int dirty_unprotects)
{
    const char * fcn_name = "col_major_scan_forward()";
    int32_t type;
    int32_t idx;

    if ( verbose )
        HDfprintf(stdout, "%s: entering.\n", fcn_name);

    HDassert( lag > 5 );

    type = 0;

    if ( ( pass ) && ( reset_stats ) ) {

        H5C_stats__reset(cache_ptr);
    }

    idx = -lag;

    while ( ( pass ) && ( (idx - lag) <= MAX_ENTRIES ) )
    {
        type = 0;

        while ( ( pass ) && ( type < NUMBER_OF_ENTRY_TYPES ) )
        {
            if ( ( pass ) && ( do_inserts ) && ( (idx + lag) >= 0 ) &&
                 ( (idx + lag) <= max_indices[type] ) &&
                 ( ((idx + lag) % 3) == 0 ) &&
                 ( ! entry_in_cache(cache_ptr, type, (idx + lag)) ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(i, %d, %d) ", type, (idx + lag));

                insert_entry(cache_ptr, type, (idx + lag), dirty_inserts,
                             H5C__NO_FLAGS_SET);
            }

            if ( ( pass ) && ( idx >= 0 ) && ( idx <= max_indices[type] ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(p, %d, %d) ", type, idx);

                protect_entry(cache_ptr, type, idx);
            }

            if ( ( pass ) && ( (idx - lag) >= 0 ) &&
                 ( (idx - lag) <= max_indices[type] ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(u, %d, %d) ", type, (idx - lag));

                unprotect_entry(cache_ptr, type, idx - lag,
                                dirty_unprotects, H5C__NO_FLAGS_SET);
            }

            if ( verbose )
                HDfprintf(stdout, "\n");

            type++;
        }

        idx++;
    }

    if ( ( pass ) && ( display_stats ) ) {

        H5C_stats(cache_ptr, "test cache", display_detailed_stats);
    }

    return;

} /* col_major_scan_forward() */


/*-------------------------------------------------------------------------
 * Function:	hl_col_major_scan_forward()
 *
 * Purpose:	Do a high locality sequence of inserts, protects, and
 *		unprotects while scanning through the set of entries.  If
 *		pass is false on entry, do nothing.
 *
 * Return:	void
 *
 * Programmer:	John Mainzer
 *              19/25/04
 *
 * Modifications:
 *
 *		JRM -- 1/21/05
 *		Added the max_index parameter to allow the caller to
 *		throttle the size of the inner loop, and thereby the
 *		execution time of the function.
 *
 *-------------------------------------------------------------------------
 */

void
hl_col_major_scan_forward(H5C_t * cache_ptr,
                          int32_t max_index,
                          hbool_t verbose,
                          hbool_t reset_stats,
                          hbool_t display_stats,
                          hbool_t display_detailed_stats,
                          hbool_t do_inserts,
                          hbool_t dirty_inserts,
                          int dirty_unprotects)
{
    const char * fcn_name = "hl_col_major_scan_forward()";
    int32_t type;
    int32_t idx;
    int32_t lag = 200;
    int32_t i;
    int32_t local_max_index;

    if ( verbose )
        HDfprintf(stdout, "%s: entering.\n", fcn_name);

    HDassert( lag > 5 );
    HDassert( max_index >= 500 );
    HDassert( max_index <= MAX_ENTRIES );

    type = 0;

    if ( ( pass ) && ( reset_stats ) ) {

        H5C_stats__reset(cache_ptr);
    }

    idx = 0;

    local_max_index = MIN(max_index, MAX_ENTRIES);

    while ( ( pass ) && ( idx <= local_max_index ) )
    {

        i = idx;

        while ( ( pass ) && ( i >= 0 ) && ( i >= (idx - lag) ) ) {

            type = 0;

            while ( ( pass ) && ( type < NUMBER_OF_ENTRY_TYPES ) )
            {
                if ( ( pass ) && ( do_inserts ) && ( i == idx ) &&
                     ( i <= local_max_index ) &&
                     ( (i % 3) == 0 ) &&
                     ( ! entry_in_cache(cache_ptr, type, i) ) ) {

                    if ( verbose )
                        HDfprintf(stdout, "(i, %d, %d) ", type, i);

                    insert_entry(cache_ptr, type, i, dirty_inserts,
                                 H5C__NO_FLAGS_SET);
                }

                if ( ( pass ) && ( i >= 0 ) && ( i <= local_max_index ) ) {

                    if ( verbose )
                        HDfprintf(stdout, "(p, %d, %d) ", type, i);

                    protect_entry(cache_ptr, type, i);
                }

                if ( ( pass ) && ( i >= 0 ) &&
                     ( i <= max_indices[type] ) ) {

                    if ( verbose )
                        HDfprintf(stdout, "(u, %d, %d) ", type, i);

                    unprotect_entry(cache_ptr, type, i,
                                    dirty_unprotects, H5C__NO_FLAGS_SET);
                }

                if ( verbose )
                    HDfprintf(stdout, "\n");

                type++;
            }

            i--;
        }

        idx++;
    }

    if ( ( pass ) && ( display_stats ) ) {

        H5C_stats(cache_ptr, "test cache", display_detailed_stats);
    }

    return;

} /* hl_col_major_scan_forward() */


/*-------------------------------------------------------------------------
 * Function:	col_major_scan_backward()
 *
 * Purpose:	Do a sequence of inserts, protects, and unprotects
 *		while scanning backwards through the set of
 *		entries.  If pass is false on entry, do nothing.
 *
 * Return:	void
 *
 * Programmer:	John Mainzer
 *              6/23/04
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */

void
col_major_scan_backward(H5C_t * cache_ptr,
                        int32_t lag,
                        hbool_t verbose,
                        hbool_t reset_stats,
                        hbool_t display_stats,
                        hbool_t display_detailed_stats,
                        hbool_t do_inserts,
                        hbool_t dirty_inserts,
                        int dirty_unprotects)
{
    const char * fcn_name = "col_major_scan_backward()";
    int mile_stone = 1;
    int32_t type;
    int32_t idx;

    if ( verbose )
        HDfprintf(stdout, "%s: entering.\n", fcn_name);

    HDassert( lag > 5 );

    if ( ( pass ) && ( reset_stats ) ) {

        H5C_stats__reset(cache_ptr);
    }

    idx = MAX_ENTRIES + lag;

    if ( verbose ) /* 1 */
        HDfprintf(stdout, "%s: point %d.\n", fcn_name, mile_stone++);


    while ( ( pass ) && ( (idx + lag) >= 0 ) )
    {
        type = NUMBER_OF_ENTRY_TYPES - 1;

        while ( ( pass ) && ( type >= 0 ) )
        {
            if ( ( pass ) && ( do_inserts) && ( (idx - lag) >= 0 ) &&
                 ( (idx - lag) <= max_indices[type] ) &&
                 ( ((idx - lag) % 3) == 0 ) &&
                 ( ! entry_in_cache(cache_ptr, type, (idx - lag)) ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(i, %d, %d) ", type, (idx - lag));

                insert_entry(cache_ptr, type, (idx - lag), dirty_inserts,
                             H5C__NO_FLAGS_SET);
            }

            if ( ( pass ) && ( idx >= 0 ) && ( idx <= max_indices[type] ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(p, %d, %d) ", type, idx);

                protect_entry(cache_ptr, type, idx);
            }

            if ( ( pass ) && ( (idx + lag) >= 0 ) &&
                 ( (idx + lag) <= max_indices[type] ) ) {

                if ( verbose )
                    HDfprintf(stdout, "(u, %d, %d) ", type, (idx + lag));

                unprotect_entry(cache_ptr, type, idx + lag,
                                dirty_unprotects, H5C__NO_FLAGS_SET);
            }

            if ( verbose )
                HDfprintf(stdout, "\n");

            type--;
        }

        idx--;
    }

    if ( verbose ) /* 2 */
        HDfprintf(stdout, "%s: point %d.\n", fcn_name, mile_stone++);

    if ( ( pass ) && ( display_stats ) ) {

        H5C_stats(cache_ptr, "test cache", display_detailed_stats);
    }

    if ( verbose )
        HDfprintf(stdout, "%s: exiting.\n", fcn_name);

    return;

} /* col_major_scan_backward() */


/*-------------------------------------------------------------------------
 * Function:	hl_col_major_scan_backward()
 *
 * Purpose:	Do a high locality sequence of inserts, protects, and
 *		unprotects while scanning backwards through the set of
 *		entries.  If pass is false on entry, do nothing.
 *
 * Return:	void
 *
 * Programmer:	John Mainzer
 *              10/25/04
 *
 * Modifications:
 *
 *		JRM -- 1/21/05
 *		Added the max_index parameter to allow the caller to
 *		throttle the size of the inner loop, and thereby the
 *		execution time of the function.
 *
 *-------------------------------------------------------------------------
 */

void
hl_col_major_scan_backward(H5C_t * cache_ptr,
                           int32_t max_index,
                           hbool_t verbose,
                           hbool_t reset_stats,
                           hbool_t display_stats,
                           hbool_t display_detailed_stats,
                           hbool_t do_inserts,
                           hbool_t dirty_inserts,
                           int dirty_unprotects)
{
    const char * fcn_name = "hl_col_major_scan_backward()";
    int32_t type;
    int32_t idx;
    int32_t lag = 50;
    int32_t i;
    int32_t local_max_index;

    if ( verbose )
        HDfprintf(stdout, "%s: entering.\n", fcn_name);

    HDassert( lag > 5 );
    HDassert( max_index >= 500 );
    HDassert( max_index <= MAX_ENTRIES );

    type = 0;

    local_max_index = MIN(max_index, MAX_ENTRIES);

    if ( ( pass ) && ( reset_stats ) ) {

        H5C_stats__reset(cache_ptr);
    }

    idx = local_max_index;

    while ( ( pass ) && ( idx >= 0 ) )
    {

        i = idx;

        while ( ( pass ) && ( i <= local_max_index ) && ( i <= (idx + lag) ) ) {

            type = 0;

            while ( ( pass ) && ( type < NUMBER_OF_ENTRY_TYPES ) )
            {
                if ( ( pass ) && ( do_inserts ) && ( i == idx ) &&
                     ( i <= local_max_index ) &&
                     ( ! entry_in_cache(cache_ptr, type, i) ) ) {

                    if ( verbose )
                        HDfprintf(stdout, "(i, %d, %d) ", type, i);

                    insert_entry(cache_ptr, type, i, dirty_inserts,
                                 H5C__NO_FLAGS_SET);
                }

                if ( ( pass ) && ( i >= 0 ) && ( i <= local_max_index ) ) {

                    if ( verbose )
                        HDfprintf(stdout, "(p, %d, %d) ", type, i);

                    protect_entry(cache_ptr, type, i);
                }

                if ( ( pass ) && ( i >= 0 ) &&
                     ( i <= local_max_index ) ) {

                    if ( verbose )
                        HDfprintf(stdout, "(u, %d, %d) ", type, i);

                    unprotect_entry(cache_ptr, type, i,
                                    dirty_unprotects, H5C__NO_FLAGS_SET);
                }

                if ( verbose )
                    HDfprintf(stdout, "\n");

                type++;
            }

            i++;
        }

        idx--;
    }

    if ( ( pass ) && ( display_stats ) ) {

        H5C_stats(cache_ptr, "test cache", display_detailed_stats);
    }

    return;

} /* hl_col_major_scan_backward() */

11544 11545 11546 11547 11548 11549 11550 11551 11552 11553 11554 11555 11556 11557 11558 11559 11560 11561 11562 11563 11564 11565 11566 11567 11568 11569 11570 11571 11572 11573 11574 11575 11576 11577 11578 11579 11580 11581 11582 11583 11584 11585 11586 11587 11588 11589 11590 11591 11592 11593 11594 11595 11596 11597 11598 11599 11600 11601 11602 11603 11604 11605 11606 11607 11608 11609 11610 11611 11612 11613 11614 11615 11616 11617 11618 11619 11620 11621 11622 11623 11624 11625 11626 11627 11628 11629 11630 11631 11632 11633 11634 11635 11636 11637 11638 11639 11640 11641 11642 11643 11644 11645 11646 11647 11648 11649 11650 11651 11652 11653 11654 11655 11656 11657 11658 11659 11660 11661 11662 11663 11664 11665 11666 11667 11668 11669 11670 11671 11672 11673 11674 11675 11676 11677 11678 11679 11680 11681 11682 11683 11684 11685 11686 11687 11688 11689 11690 11691 11692 11693 11694 11695 11696 11697 11698 11699 11700 11701 11702 11703 11704 11705 11706 11707 11708 11709 11710 11711 11712 11713 11714 11715 11716 11717 11718 11719 11720 11721 11722 11723 11724 11725 11726 11727 11728 11729 11730 11731 11732 11733 11734 11735 11736 11737 11738 11739 11740 11741 11742 11743 11744 11745 11746 11747 11748 11749 11750 11751 11752 11753 11754 11755 11756 11757 11758 11759 11760 11761 11762 11763 11764 11765 11766 11767 11768 11769 11770 11771 11772 11773 11774 11775 11776 11777 11778 11779 11780 11781 11782 11783 11784 11785 11786 11787 11788 11789 11790 11791 11792 11793 11794 11795 11796 11797 11798 11799 11800 11801 11802 11803 11804 11805 11806 11807 11808 11809 11810 11811 11812 11813 11814 11815 11816 11817 11818 11819 11820 11821 11822 11823 11824 11825 11826 11827 11828 11829 11830 11831 11832 11833 11834 11835 11836 11837 11838 11839 11840 11841 11842 11843 11844 11845 11846 11847 11848 11849 11850 11851 11852 11853 11854 11855 11856 11857 11858 11859 11860 11861 11862 11863 11864 11865 11866 11867 11868 11869 11870 11871 11872 11873 11874 11875 11876 11877 11878 11879 11880 11881 11882 11883 11884 11885 11886 11887 11888 11889 11890 11891 11892 11893 11894 11895 11896 11897 11898 11899 11900 11901 11902 11903 11904 11905 11906 11907 11908 11909 11910 11911 11912 11913 11914 11915 11916 11917 11918 11919 11920 11921 11922 11923 11924 11925 11926 11927 11928 11929 11930 11931 11932 11933 11934 11935 11936 11937 11938 11939 11940 11941 11942 11943 11944 11945 11946 11947 11948 11949 11950 11951 11952 11953 11954 11955 11956 11957 11958 11959 11960 11961 11962 11963 11964 11965 11966 11967 11968 11969 11970 11971 11972 11973 11974 11975 11976 11977 11978 11979 11980 11981 11982 11983 11984 11985 11986 11987 11988 11989 11990 11991 11992 11993 11994 11995 11996 11997 11998 11999 12000 12001 12002 12003 12004 12005 12006 12007 12008 12009 12010 12011 12012 12013 12014 12015 12016 12017 12018 12019 12020 12021 12022 12023 12024 12025 12026 12027 12028 12029 12030 12031 12032 12033 12034 12035 12036 12037 12038 12039 12040 12041 12042 12043 12044 12045 12046 12047 12048 12049 12050 12051 12052 12053 12054 12055 12056 12057 12058 12059 12060 12061 12062 12063 12064 12065 12066 12067 12068 12069 12070 12071 12072 12073 12074 12075 12076 12077 12078 12079 12080 12081 12082 12083 12084 12085 12086 12087 12088 12089 12090 12091 12092 12093 12094 12095 12096 12097 12098 12099 12100 12101 12102 12103 12104 12105 12106 12107 12108 12109 12110 12111 12112 12113 12114 12115 12116 12117 12118 12119 12120 12121 12122 12123 12124 12125 12126 12127 12128 12129 12130 12131 12132 12133 12134 12135 12136 12137 12138 12139 12140 12141 12142 12143 12144 12145 12146 12147 12148 12149 12150 12151 12152 12153 12154 12155 12156 12157 12158 12159 12160 12161 12162 12163 12164 12165 12166 12167 12168 12169 12170 12171 12172 12173 12174 12175 12176 12177 12178 12179 12180 12181 12182 12183 12184 12185 12186 12187 12188 12189 12190 12191 12192 12193 12194 12195 12196 12197 12198 12199 12200 12201 12202 12203 12204 12205 12206 12207 12208 12209 12210 12211 12212 12213 12214 12215 12216 12217 12218 12219 12220 12221 12222 12223 12224 12225 12226 12227 12228 12229 12230 12231 12232 12233 12234 12235 12236 12237 12238 12239 12240 12241 12242 12243 12244 12245 12246 12247 12248 12249 12250 12251 12252 12253 12254 12255 12256 12257 12258 12259 12260 12261 12262 12263 12264 12265 12266 12267 12268 12269 12270 12271 12272 12273 12274 12275 12276 12277 12278 12279 12280 12281 12282 12283 12284 12285 12286 12287 12288 12289 12290 12291 12292 12293 12294 12295 12296 12297 12298 12299 12300 12301 12302 12303 12304 12305 12306 12307 12308 12309 12310 12311 12312 12313 12314 12315 12316 12317 12318 12319 12320 12321 12322 12323 12324 12325 12326 12327 12328 12329 12330 12331 12332 12333 12334 12335 12336 12337 12338 12339 12340 12341 12342 12343 12344 12345 12346 12347 12348 12349 12350 12351 12352 12353 12354 12355 12356 12357 12358 12359 12360 12361 12362 12363 12364 12365 12366 12367 12368 12369 12370 12371 12372 12373 12374 12375 12376 12377 12378 12379 12380 12381 12382 12383 12384 12385 12386 12387 12388 12389 12390 12391 12392 12393 12394 12395 12396 12397 12398 12399 12400 12401 12402 12403 12404 12405 12406 12407 12408 12409 12410 12411 12412 12413 12414 12415 12416 12417 12418 12419 12420 12421 12422 12423 12424 12425 12426 12427 12428 12429 12430 12431 12432 12433 12434 12435 12436 12437 12438 12439 12440 12441 12442 12443 12444 12445 12446 12447 12448 12449 12450 12451 12452 12453 12454 12455 12456 12457 12458 12459 12460 12461 12462 12463 12464 12465 12466 12467 12468 12469 12470 12471 12472 12473 12474 12475 12476 12477 12478 12479 12480 12481 12482 12483 12484 12485 12486 12487 12488 12489 12490 12491 12492 12493 12494 12495 12496 12497 12498 12499 12500 12501 12502 12503 12504 12505 12506 12507 12508 12509 12510 12511 12512 12513 12514 12515 12516 12517 12518 12519 12520 12521 12522 12523 12524 12525 12526 12527 12528 12529 12530 12531 12532 12533 12534 12535 12536 12537 12538 12539 12540 12541 12542 12543 12544 12545 12546 12547 12548 12549 12550 12551 12552 12553 12554 12555 12556 12557 12558 12559 12560 12561 12562 12563 12564 12565 12566 12567 12568 12569 12570 12571 12572 12573 12574 12575 12576 12577 12578 12579 12580 12581 12582 12583 12584 12585 12586 12587 12588 12589 12590 12591 12592 12593 12594 12595 12596 12597 12598 12599 12600 12601 12602 12603 12604 12605 12606 12607 12608 12609 12610 12611 12612 12613 12614 12615 12616 12617 12618 12619 12620 12621 12622 12623 12624 12625 12626 12627 12628 12629 12630 12631 12632 12633 12634 12635 12636 12637 12638 12639 12640 12641 12642 12643 12644 12645 12646 12647 12648 12649 12650 12651 12652 12653 12654 12655 12656 12657 12658 12659 12660 12661 12662 12663 12664 12665 12666 12667 12668 12669 12670 12671 12672 12673 12674 12675 12676 12677 12678 12679 12680 12681 12682 12683 12684 12685 12686 12687 12688 12689 12690 12691 12692 12693 12694 12695 12696 12697 12698 12699 12700 12701 12702 12703 12704 12705 12706 12707 12708 12709 12710 12711 12712 12713 12714 12715 12716 12717 12718 12719 12720 12721 12722 12723 12724 12725 12726 12727 12728 12729 12730 12731 12732 12733 12734 12735 12736 12737 12738 12739 12740 12741 12742 12743 12744 12745 12746 12747 12748 12749 12750 12751 12752 12753 12754 12755 12756 12757 12758 12759 12760 12761 12762 12763 12764 12765 12766 12767 12768 12769 12770 12771 12772 12773 12774 12775 12776 12777 12778 12779 12780 12781 12782 12783 12784 12785 12786 12787 12788 12789 12790 12791 12792 12793 12794 12795 12796 12797 12798 12799 12800 12801 12802 12803 12804 12805 12806 12807 12808 12809 12810 12811 12812 12813 12814 12815 12816 12817 12818 12819 12820 12821 12822 12823 12824 12825 12826 12827 12828 12829 12830 12831 12832 12833 12834 12835 12836 12837 12838 12839 12840 12841 12842 12843 12844 12845 12846 12847 12848 12849 12850 12851 12852 12853 12854 12855 12856 12857 12858 12859 12860 12861 12862 12863 12864 12865 12866 12867 12868 12869 12870 12871 12872 12873 12874 12875 12876 12877 12878 12879 12880 12881 12882 12883 12884 12885 12886 12887 12888 12889 12890 12891 12892 12893 12894 12895 12896 12897 12898 12899 12900 12901 12902 12903 12904 12905 12906 12907 12908 12909 12910 12911 12912 12913 12914 12915 12916 12917 12918 12919 12920 12921 12922 12923 12924 12925 12926 12927 12928 12929 12930 12931 12932 12933 12934 12935 12936 12937 12938 12939 12940 12941 12942 12943 12944 12945 12946 12947 12948 12949 12950 12951 12952 12953 12954 12955 12956 12957 12958 12959 12960 12961 12962 12963 12964 12965 12966 12967 12968 12969 12970 12971 12972 12973 12974 12975 12976 12977 12978 12979 12980 12981 12982 12983 12984 12985 12986 12987 12988 12989 12990 12991 12992 12993 12994 12995 12996 12997 12998 12999 13000 13001 13002 13003 13004 13005 13006 13007 13008 13009 13010 13011 13012 13013 13014 13015 13016 13017 13018 13019 13020 13021 13022 13023 13024 13025 13026 13027 13028 13029 13030 13031 13032 13033 13034 13035 13036 13037 13038 13039 13040 13041 13042 13043 13044 13045 13046 13047 13048 13049 13050 13051 13052 13053 13054 13055 13056 13057 13058 13059 13060 13061 13062 13063 13064 13065 13066 13067 13068 13069 13070 13071 13072 13073 13074 13075 13076 13077 13078 13079 13080 13081 13082 13083 13084 13085 13086 13087 13088 13089 13090 13091 13092 13093 13094 13095 13096 13097 13098 13099 13100 13101 13102 13103 13104 13105 13106 13107 13108 13109 13110 13111 13112 13113 13114 13115 13116 13117 13118 13119 13120 13121 13122 13123 13124 13125 13126 13127 13128 13129 13130 13131 13132 13133 13134 13135 13136 13137 13138 13139 13140 13141 13142 13143 13144 13145 13146 13147 13148 13149 13150 13151 13152 13153 13154 13155 13156 13157 13158 13159 13160 13161 13162 13163 13164 13165 13166 13167 13168 13169 13170 13171 13172 13173 13174 13175 13176 13177 13178 13179 13180 13181 13182 13183 13184 13185 13186 13187 13188 13189 13190 13191 13192 13193 13194 13195 13196 13197 13198 13199 13200 13201 13202 13203 13204 13205 13206 13207 13208 13209 13210 13211 13212 13213 13214 13215 13216 13217 13218 13219 13220 13221 13222 13223 13224 13225 13226 13227 13228 13229 13230 13231 13232 13233 13234 13235 13236 13237 13238 13239 13240 13241 13242 13243 13244 13245 13246 13247 13248 13249 13250 13251 13252 13253 13254 13255 13256 13257 13258 13259 13260 13261 13262 13263 13264 13265 13266 13267 13268 13269 13270 13271 13272 13273 13274 13275 13276 13277 13278 13279 13280 13281 13282 13283 13284 13285 13286 13287 13288 13289 13290 13291 13292 13293 13294 13295 13296 13297 13298 13299 13300 13301 13302 13303 13304 13305 13306 13307 13308 13309 13310 13311 13312 13313 13314 13315 13316 13317 13318 13319 13320 13321 13322 13323 13324 13325 13326 13327 13328 13329 13330
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * 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 files COPYING and Copyright.html.  COPYING can be found at the root   *
 * of the source code distribution tree; Copyright.html can be found at the  *
 * root level of an installed copy of the electronic HDF5 document set and   *
 * is linked from the top-level documents page.  It can also be found at     *
 * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html.  If you do not have     *
 * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/* Programmer:  Quincey Koziol <koziol@ncsa.uiuc.edu>
 *              Friday, February 24, 2006
 */
#include "h5test.h"

/*
 * This file needs to access private datatypes from the H5HF package.
 * This file also needs to access the fractal heap testing code.
 */
#define H5HF_PACKAGE
#define H5HF_TESTING
#include "H5HFpkg.h"		/* Fractal heaps			*/

/* Other private headers that this test requires */
#include "H5Iprivate.h"
#include "H5MMprivate.h"	/* Memory management			*/
#include "H5Vprivate.h"		/* Vectors and arrays 			*/

/* Object size macros */
#define SMALL_OBJ_SIZE1         10
#define SMALL_OBJ_SIZE2         20

/* "Small" heap creation parameters */
#define SMALL_ADDRMAP     H5HF_ABSOLUTE           /* Heap address mapping */
#define SMALL_STAND_SIZE  (48 * 1024)             /* Standalone obj. min. size */
#define SMALL_MAN_WIDTH   4                       /* Managed obj. table width */
#define SMALL_MAN_START_BLOCK_SIZE 512            /* Managed obj. starting block size */
#define SMALL_MAN_MAX_DIRECT_SIZE (64 * 1024)     /* Managed obj. max. direct block size */
#define SMALL_MAN_MAX_INDEX 32                    /* Managed obj. # of bits for total heap size */
#define SMALL_MAN_START_ROOT_ROWS 1               /* Managed obj. starting # of root indirect block rows */

/* Define this macro to enable all insertion tests */
/* #define ALL_INSERT_TESTS */

/* Heap metadata macros */
#define HEAP_ID_LEN             6               /* # of bytes to use for heap ID */
#define HEAP_MAX_ROOT_ROWS(fh) H5HF_get_max_root_rows(fh)       /* Max. # of rows in root indirect block */
#define DTABLE_WIDTH(fh) H5HF_get_dtable_width_test(fh) /* Width of doubling table for heap */
#define DTABLE_MAX_DROWS(fh) H5HF_get_dtable_max_drows_test(fh) /* Max. # of direct block rows in any indirect block */
#define IBLOCK_MAX_DROWS(fh, pos) H5HF_get_iblock_max_drows_test(fh, pos) /* Max. # of direct block rows in a indirect block */
#define DBLOCK_SIZE(fh, r) H5HF_get_dblock_size_test(fh, r)     /* Size of a direct block in a given row */
#define DBLOCK_FREE(fh, r) H5HF_get_dblock_free_test(fh, r)     /* Free space in a direct block of a given row */

const char *FILENAME[] = {
    "fheap",
    NULL
};

/* Types of tests to perform */
typedef enum {
    FHEAP_TEST_NORMAL,          /* "Normal" test, with no testing parameters set */
    FHEAP_TEST_REOPEN,          /* Set the reopen_heap flag */
    FHEAP_TEST_NTESTS           /* The number of test types, must be last */
} fheap_test_type_t;

/* Order to delete objects */
typedef enum {
    HEAP_DEL_FORWARD,           /* Delete objects from 0 -> nobjs */
    HEAP_DEL_REVERSE,           /* Delete objects from nobjs -> 0 */
    HEAP_DEL_NDIRS              /* The number of different deletion orders, must be last */
} fheap_test_del_dir_t;

/* Order to delete objects */
typedef enum {
    HEAP_DEL_DRAIN_ALL,         /* Don't drain half of objects first */
    HEAP_DEL_DRAIN_HALF,        /* Don't drain half of objects first */
    HEAP_DEL_DRAIN_N            /* The number of different ways to drain, must be last */
} fheap_test_del_drain_t;

/* Testing parameters */
typedef struct fheap_test_param_t {
    fheap_test_type_t reopen_heap;      /* Whether to re-open the heap during the test */
    fheap_test_del_dir_t del_dir;       /* Whether to delete objects forward or reverse */
    fheap_test_del_drain_t drain_half;  /* Whether to drain half of the objects & refill, when deleting objects */
} fheap_test_param_t;

/* Heap state information */
typedef struct fheap_heap_state_t {
    hsize_t     heap_size;              /* Total size of heap (managed & standalone objects) */
    size_t      nobjs;                  /* # of objects within heap */
    hsize_t     man_size;               /* Size of managed object heap */
    hsize_t     man_alloc_size;         /* Size of managed object heap allocated */
    hsize_t     man_free_space;         /* Managed object free space within heap */
} fheap_heap_state_t;

/* Heap IDs to retain */
typedef struct fheap_heap_ids_t {
    size_t      num_ids;        /* # of heap IDs in array */
    size_t      alloc_ids;      /* # of heap IDs allocated in array */
    unsigned char *ids;         /* Array of object heap IDs */
    size_t *lens;               /* Array of object lengths */
    size_t *offs;               /* Array of object offsets (in global shared write buffer) */
} fheap_heap_ids_t;

/* Local variables */
unsigned char *shared_wobj_g;   /* Pointer to shared write buffer for objects */
unsigned char *shared_robj_g;   /* Pointer to shared read buffer for objects */
size_t shared_obj_size_g;       /* Size of shared objects */
unsigned char *shared_ids_g = NULL;     /* Array of shared object heap IDs */
size_t *shared_lens_g = NULL;   /* Array of shared object lengths */
size_t *shared_offs_g = NULL;   /* Array of shared object offsets */
size_t shared_alloc_ids_g = 0;  /* # of shared heap IDs allocated in array */

/* Local routines */
static int init_small_cparam(H5HF_create_t *cparam);
static int check_stats(const H5HF_t *fh, const fheap_heap_state_t *state);


/*-------------------------------------------------------------------------
 * Function:	init_small_cparam
 *
 * Purpose:	Initialize heap creation parameter structure with small
 *              settings
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, March 21, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
init_small_cparam(H5HF_create_t *cparam)
{
    /* Wipe out background */
    HDmemset(cparam, 0, sizeof(H5HF_create_t));

    /* General parameters */
    cparam->addrmap = SMALL_ADDRMAP;
    cparam->standalone_size = SMALL_STAND_SIZE;

    /* Managed object doubling-table parameters */
    cparam->managed.width = SMALL_MAN_WIDTH;
    cparam->managed.start_block_size = SMALL_MAN_START_BLOCK_SIZE;
    cparam->managed.max_direct_size = SMALL_MAN_MAX_DIRECT_SIZE;
    cparam->managed.max_index = SMALL_MAN_MAX_INDEX;
    cparam->managed.start_root_rows = SMALL_MAN_START_ROOT_ROWS;

    return(0);
} /* init_small_cparam() */


/*-------------------------------------------------------------------------
 * Function:	check_stats
 *
 * Purpose:	Verify stats for a heap
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, March  6, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
check_stats(const H5HF_t *fh, const fheap_heap_state_t *state)
{
    H5HF_stat_t heap_stats;             /* Statistics about the heap */

    /* Get statistics for heap and verify they are correct */
    if(H5HF_stat_info(fh, &heap_stats) < 0)
        FAIL_STACK_ERROR
    if(heap_stats.total_size != state->heap_size) {
        HDfprintf(stdout, "heap_stats.total_size = %Hu, state->heap_size = %Hu\n", heap_stats.total_size, state->heap_size);
        FAIL_STACK_ERROR
    } /* end if */
    if(heap_stats.nobjs != state->nobjs) {
        HDfprintf(stdout, "heap_stats.nobjs = %Hu, state->nobjs = %Hu\n", heap_stats.nobjs, state->nobjs);
        FAIL_STACK_ERROR
    } /* end if */
    if(heap_stats.man_size != state->man_size) {
        HDfprintf(stdout, "heap_stats.man_size = %Hu, state->man_size = %Hu\n", heap_stats.man_size, state->man_size);
        FAIL_STACK_ERROR
    } /* end if */
    if(heap_stats.man_alloc_size != state->man_alloc_size) {
        HDfprintf(stdout, "heap_stats.man_alloc_size = %Hu, state->man_alloc_size = %Hu\n", heap_stats.man_alloc_size, state->man_alloc_size);
        FAIL_STACK_ERROR
    } /* end if */
    if(heap_stats.man_free_space != state->man_free_space) {
        HDfprintf(stdout, "heap_stats.man_free_space = %Hu, state->man_free_space = %Hu\n", heap_stats.man_free_space, state->man_free_space);
        FAIL_STACK_ERROR
    } /* end if */

    /* All tests passed */
    return(0);

error:
    return(1);
} /* check_stats() */


/*-------------------------------------------------------------------------
 * Function:	add_obj
 *
 * Purpose:	Add an object to heap
 *
 * Note:        The following fields in the 'state' structure are set to
 *              the values expected _after_ any block created for the object:
 *                      heap_size
 *                      man_size
 *                      man_alloc_size
 *                      man_free_space
 *                      
 *              The following fields in the 'state' structure are set to
 *              the current state, before any block has been created:
 *                      nobjs
 *                      
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, April 10, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
add_obj(H5HF_t *fh, hid_t dxpl, unsigned obj_off, size_t obj_size,
    fheap_heap_state_t *state, fheap_heap_ids_t *keep_ids)
{
    unsigned char heap_id[HEAP_ID_LEN]; /* Heap ID for object inserted */
    unsigned char *obj;                 /* Buffer for object to insert */

    /* Sanity check */
    HDassert(fh);
    HDassert(state);

    /* Initialize object buffer */
    obj = &shared_wobj_g[obj_off];

    /* Insert object */
    HDmemset(heap_id, 0, sizeof(heap_id));
    if(H5HF_insert(fh, dxpl, obj_size, obj, heap_id) < 0)
        FAIL_STACK_ERROR

    /* Adjust state of heap */
    state->nobjs++;
    state->man_free_space -= obj_size;

    /* Check free space left in heap */
    if(check_stats(fh, state))
        FAIL_STACK_ERROR

    /* Read in object */
    if(H5HF_read(fh, dxpl, heap_id, shared_robj_g) < 0)
        FAIL_STACK_ERROR
    if(HDmemcmp(obj, shared_robj_g, obj_size))
        FAIL_STACK_ERROR

    /* If the heap IDs are to be retained, append them to the list */
    if(keep_ids) {
        /* Check for needing to increase size of heap ID array */
        if(keep_ids->num_ids + 1 > keep_ids->alloc_ids) {
            keep_ids->alloc_ids = MAX(1024, (keep_ids->alloc_ids * 2));
            if(NULL == (keep_ids->ids = H5MM_realloc(keep_ids->ids, HEAP_ID_LEN * keep_ids->alloc_ids)))
                FAIL_STACK_ERROR
            if(NULL == (keep_ids->lens = H5MM_realloc(keep_ids->lens, sizeof(size_t) * keep_ids->alloc_ids)))
                FAIL_STACK_ERROR
            if(NULL == (keep_ids->offs = H5MM_realloc(keep_ids->offs, sizeof(size_t) * keep_ids->alloc_ids)))
                FAIL_STACK_ERROR
        } /* end if */

        /* Append the object info onto the array */
        HDmemcpy(&keep_ids->ids[keep_ids->num_ids * HEAP_ID_LEN], obj, HEAP_ID_LEN);
        keep_ids->lens[keep_ids->num_ids] = obj_size;
        keep_ids->offs[keep_ids->num_ids] = obj_off;

        /* Increment the number of IDs kept */
        keep_ids->num_ids++;
    } /* end if */

    /* Operations succeeded */
    return(0);

error:
    return(1);
} /* add_obj() */


/*-------------------------------------------------------------------------
 * Function:	get_del_string
 *
 * Purpose:	Return string describing the kind of deletion to perform
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, June  6, 2006
 *
 *-------------------------------------------------------------------------
 */
static char *
get_del_string(fheap_test_param_t *tparam)
{
    char *str;

    /* Remove half of total objects from heap */
    if(tparam->del_dir == HEAP_DEL_FORWARD)
        if(tparam->drain_half == HEAP_DEL_DRAIN_ALL)
            str = HDstrdup("(all - forward)");
        else
            str = HDstrdup("(half, refill, all - forward)");
    else
        if(tparam->drain_half == HEAP_DEL_DRAIN_ALL)
            str = HDstrdup("(all - reverse)");
        else
            str = HDstrdup("(half, refill, all - reverse)");

    return(str);
} /* get_del_string() */


/*-------------------------------------------------------------------------
 * Function:	del_objs_half_refill
 *
 * Purpose:	Remove half of objects from heap and refill
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, June  6, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
del_objs_half_refill(H5F_t *f, hid_t dxpl, H5HF_t **fh, fheap_test_param_t *tparam,
    fheap_heap_state_t *state, fheap_heap_ids_t *keep_ids)
{
    unsigned char *wobj;        /* Buffer for object to insert */
    haddr_t fh_addr;            /* Address of fractal heap */
    size_t half_nobjs;          /* Half of total # of objects */
    size_t obj_idx;             /* Index of the object to remove */
    size_t u;                   /* Local index variable */

    /* Sanity check */
    HDassert(fh);
    HDassert(*fh);
    HDassert(state);
    HDassert(keep_ids);

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        if(H5HF_get_heap_addr(*fh, &fh_addr) < 0)
            FAIL_STACK_ERROR
        if(!H5F_addr_defined(fh_addr))
            FAIL_STACK_ERROR
    } /* end if */

    /* Remove half of total objects from heap */
    if(tparam->del_dir == HEAP_DEL_FORWARD)
        obj_idx = 0;
    else
        obj_idx = state->nobjs - 1;
    half_nobjs = state->nobjs / 2;
    for(u = 0; u < half_nobjs; u++) {
        /* Remove object from heap */
        if(H5HF_remove(*fh, dxpl, &keep_ids->ids[HEAP_ID_LEN * obj_idx]) < 0)
            FAIL_STACK_ERROR

        /* Check for closing & re-opening the heap */
        if(tparam->reopen_heap) {
            /* Close (empty) heap */
            if(H5HF_close(*fh, dxpl) < 0)
                TEST_ERROR

            /* Re-open heap */
            if(NULL == (*fh = H5HF_open(f, dxpl, fh_addr)))
                FAIL_STACK_ERROR
        } /* end if */

        /* Adjust index of object to delete next */
        if(tparam->del_dir == HEAP_DEL_FORWARD)
            obj_idx++;
        else
            obj_idx--;
    } /* end for */

    /* Re-insert half of total objects back into heap */
    if(tparam->del_dir == HEAP_DEL_FORWARD)
        obj_idx = 0;
    else
        obj_idx = state->nobjs - 1;
    for(u = 0; u < half_nobjs; u++) {
        /* Re-insert object */
        wobj = &shared_wobj_g[keep_ids->offs[obj_idx]];
        if(H5HF_insert(*fh, dxpl, keep_ids->lens[obj_idx], wobj, &keep_ids->ids[HEAP_ID_LEN * obj_idx]) < 0)
            FAIL_STACK_ERROR

        /* Check for closing & re-opening the heap */
        if(tparam->reopen_heap) {
            /* Close (empty) heap */
            if(H5HF_close(*fh, dxpl) < 0)
                TEST_ERROR

            /* Re-open heap */
            if(NULL == (*fh = H5HF_open(f, dxpl, fh_addr)))
                FAIL_STACK_ERROR
        } /* end if */

        /* Adjust index of object to delete next */
        if(tparam->del_dir == HEAP_DEL_FORWARD)
            obj_idx++;
        else
            obj_idx--;
    } /* end for */

    /* Operations succeeded */
    return(0);

error:
    return(1);
} /* del_objs_half_refill() */


/*-------------------------------------------------------------------------
 * Function:	del_objs
 *
 * Purpose:	Remove objects from heap
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, June  6, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
del_objs(H5F_t *f, hid_t dxpl, H5HF_t **fh, fheap_test_param_t *tparam,
    fheap_heap_state_t *state, fheap_heap_ids_t *keep_ids)
{
    haddr_t fh_addr;            /* Address of fractal heap */
    size_t obj_idx;             /* Index of the object to remove */
    size_t u;                   /* Local index variable */

    /* Sanity check */
    HDassert(fh);
    HDassert(*fh);
    HDassert(state);
    HDassert(keep_ids);

    /* Check for first deleting half of objects & then re-inserting them */
    if(tparam->drain_half == HEAP_DEL_DRAIN_HALF)
        if(del_objs_half_refill(f, dxpl, fh, tparam, state, keep_ids))
            FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        if(H5HF_get_heap_addr(*fh, &fh_addr) < 0)
            FAIL_STACK_ERROR
        if(!H5F_addr_defined(fh_addr))
            FAIL_STACK_ERROR
    } /* end if */

    /* Remove all objects from heap */
    if(tparam->del_dir == HEAP_DEL_FORWARD)
        obj_idx = 0;
    else
        obj_idx = state->nobjs - 1;
    for(u = 0; u < state->nobjs; u++) {
        /* Remove object from heap */
        if(H5HF_remove(*fh, dxpl, &keep_ids->ids[HEAP_ID_LEN * obj_idx]) < 0)
            FAIL_STACK_ERROR

        /* Check for closing & re-opening the heap */
        if(tparam->reopen_heap) {
            /* Close (empty) heap */
            if(H5HF_close(*fh, dxpl) < 0)
                TEST_ERROR

            /* Re-open heap */
            if(NULL == (*fh = H5HF_open(f, dxpl, fh_addr)))
                FAIL_STACK_ERROR
        } /* end if */

        /* Adjust index of object to delete next */
        if(tparam->del_dir == HEAP_DEL_FORWARD)
            obj_idx++;
        else
            obj_idx--;
    } /* end for */

    /* Check up on heap... */
    state->heap_size = 0;
    state->man_size = 0;
    state->man_alloc_size = 0;
    state->man_free_space = 0;
    state->nobjs = 0;
    if(check_stats(*fh, state))
        FAIL_STACK_ERROR

    /* Operations succeeded */
    return(0);

error:
    return(1);
} /* del_objs() */


/*-------------------------------------------------------------------------
 * Function:	fill_heap
 *
 * Purpose:	Insert (small) objects to fill up the free space in a heap block
 *
 * Note:        The following fields in the 'state' structure are set to
 *              the values expected _after_ the block has been created:
 *                      heap_size
 *                      man_size
 *                      man_alloc_size
 *                      man_free_space
 *                      
 *              The following fields in the 'state' structure are set to
 *              the current state, before the block has been created:
 *                      nobjs
 *                      
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, March  7, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
fill_heap(H5HF_t *fh, hid_t dxpl, unsigned block_row, size_t obj_size,
    fheap_heap_state_t *state, fheap_heap_ids_t *keep_ids)
{
    unsigned char *wobj;                /* Buffer for object to insert */
    unsigned char *curr_id_ptr;         /* Pointer into shared ID array */
    size_t *curr_len_ptr;               /* Pointer into shared length array */
    size_t *curr_off_ptr;               /* Pointer into shared offset array */
    size_t      num_ids = 0;            /* # of heap IDs in array */
    size_t      data_size;              /* Size of data portion of heap block */
    size_t      last_obj_len;           /* Size of last object inserted into heap */
    size_t      obj_off;                /* Offset of object in shared write buffer */
    unsigned    u;                      /* Local index variable */

    /* Sanity check */
    HDassert(fh);
    HDassert(state);
    HDassert(obj_size + 256 < shared_obj_size_g);

    /* Initialize starting information */
    data_size = DBLOCK_FREE(fh, block_row);
    wobj = shared_wobj_g;
    curr_id_ptr = shared_ids_g;
    curr_len_ptr = shared_lens_g;
    curr_off_ptr = shared_offs_g;
    obj_off = 0;

    /* Loop over inserting objects into the root direct block, until there's no more space */
    while(data_size >= obj_size) {
        /* Increment object count */
        num_ids++;

        /* Check for needing to increase size of heap ID array */
        if(num_ids > shared_alloc_ids_g) {
            shared_alloc_ids_g = MAX(1024, (shared_alloc_ids_g * 2));
            if(NULL == (shared_ids_g = H5MM_realloc(shared_ids_g, HEAP_ID_LEN * shared_alloc_ids_g)))
                FAIL_STACK_ERROR
            if(NULL == (shared_lens_g = H5MM_realloc(shared_lens_g, sizeof(size_t) * shared_alloc_ids_g)))
                FAIL_STACK_ERROR
            if(NULL == (shared_offs_g = H5MM_realloc(shared_offs_g, sizeof(size_t) * shared_alloc_ids_g)))
                FAIL_STACK_ERROR
            curr_id_ptr = &shared_ids_g[(num_ids - 1) * HEAP_ID_LEN];
            curr_len_ptr = &shared_lens_g[(num_ids - 1)];
            curr_off_ptr = &shared_offs_g[(num_ids - 1)];
        } /* end if */

        /* Insert object */
        if(H5HF_insert(fh, dxpl, obj_size, wobj, curr_id_ptr) < 0)
            FAIL_STACK_ERROR
        *curr_len_ptr = obj_size;
        *curr_off_ptr = obj_off;

        /* Adjust state of heap */
        state->nobjs++;
        state->man_free_space -= obj_size;

        /* Check stats for heap */
        if(check_stats(fh, state))
            FAIL_STACK_ERROR

        /* Adjust object & ID pointers */
        wobj++;
        obj_off++;
        if(obj_off > 255) {
            wobj = shared_wobj_g;
            obj_off = 0;
        } /* end if */
        curr_id_ptr += HEAP_ID_LEN;
        curr_len_ptr++;
        curr_off_ptr++;

        /* Decrement space left in block */
        data_size -= obj_size;
    } /* end while */

    /* Check for adding smaller last object to heap block */
    if(data_size > 0) {
        /* Set size of last object in block */
        last_obj_len = data_size;

        /* Increment object count */
        num_ids++;

        /* Check for needing to increase size of heap ID array */
        if(num_ids > shared_alloc_ids_g) {
            shared_alloc_ids_g = MAX(1024, (shared_alloc_ids_g * 2));
            if(NULL == (shared_ids_g = H5MM_realloc(shared_ids_g, HEAP_ID_LEN * shared_alloc_ids_g)))
                FAIL_STACK_ERROR
            if(NULL == (shared_lens_g = H5MM_realloc(shared_lens_g, sizeof(size_t) * shared_alloc_ids_g)))
                FAIL_STACK_ERROR
            if(NULL == (shared_offs_g = H5MM_realloc(shared_offs_g, sizeof(size_t) * shared_alloc_ids_g)))
                FAIL_STACK_ERROR
            curr_id_ptr = &shared_ids_g[(num_ids - 1) * HEAP_ID_LEN];
            curr_len_ptr = &shared_lens_g[(num_ids - 1)];
            curr_off_ptr = &shared_offs_g[(num_ids - 1)];
        } /* end if */

        /* Insert last object into the heap, using the remaining free space */
        if(H5HF_insert(fh, dxpl, last_obj_len, wobj, curr_id_ptr) < 0)
            FAIL_STACK_ERROR
        *curr_len_ptr = last_obj_len;
        *curr_off_ptr = obj_off;

        /* Adjust state of heap */
        state->nobjs++;
        state->man_free_space -= last_obj_len;

        /* Verify that the heap is full */
        if(check_stats(fh, state))
            FAIL_STACK_ERROR
    } /* end if */
    else
        last_obj_len = obj_size;     /* Normal sized last object */

    /* Verify reading the objects written out */

    /* Verify all the objects */
    wobj = shared_wobj_g;
    curr_id_ptr = shared_ids_g;
    curr_len_ptr = shared_lens_g;
    curr_off_ptr = shared_offs_g;
    for(u = 0; u < num_ids; u++) {
        /* Read in object */
        if(H5HF_read(fh, dxpl, curr_id_ptr, shared_robj_g) < 0)
            FAIL_STACK_ERROR

        /* Check that object is correct */
        wobj = &shared_wobj_g[*curr_off_ptr];
        if(HDmemcmp(wobj, shared_robj_g, *curr_len_ptr))
            FAIL_STACK_ERROR

        /* Adjust object & ID pointers */
        curr_id_ptr += HEAP_ID_LEN;
        curr_len_ptr++;
        curr_off_ptr++;
    } /* end for */

    /* If the heap IDs are to be retained, append them to the list */
    if(keep_ids) {
        /* Check for needing to increase size of heap ID array */
        if(keep_ids->num_ids + num_ids > keep_ids->alloc_ids) {
            keep_ids->alloc_ids = MAX(1024, (keep_ids->alloc_ids * 2));
            if(NULL == (keep_ids->ids = H5MM_realloc(keep_ids->ids, HEAP_ID_LEN * keep_ids->alloc_ids)))
                FAIL_STACK_ERROR
            if(NULL == (keep_ids->lens = H5MM_realloc(keep_ids->lens, sizeof(size_t) * keep_ids->alloc_ids)))
                FAIL_STACK_ERROR
            if(NULL == (keep_ids->offs = H5MM_realloc(keep_ids->offs, sizeof(size_t) * keep_ids->alloc_ids)))
                FAIL_STACK_ERROR
        } /* end if */

        /* Append the IDs onto the array */
        HDmemcpy(&keep_ids->ids[keep_ids->num_ids * HEAP_ID_LEN], shared_ids_g, (num_ids * HEAP_ID_LEN));
        HDmemcpy(&keep_ids->lens[keep_ids->num_ids], shared_lens_g, (num_ids * sizeof(size_t)));
        HDmemcpy(&keep_ids->offs[keep_ids->num_ids], shared_offs_g, (num_ids * sizeof(size_t)));

        /* Increment the number of IDs kept */
        keep_ids->num_ids += num_ids;
    } /* end if */

    /* Operations succeeded */
    return(0);

error:
    return(1);
} /* fill_heap() */


/*-------------------------------------------------------------------------
 * Function:	fill_root_row
 *
 * Purpose:	Fill up a row of direct blocks in the root indirect block
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, April 10, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
fill_root_row(H5HF_t *fh, hid_t dxpl, unsigned row, size_t obj_size,
    fheap_heap_state_t *state, fheap_heap_ids_t *keep_ids)
{
    hsize_t     first_free_space;       /* Size of free space in heap after the first block */
    hsize_t     all_free_space;         /* Size of free space in heap after all blocks */
    hsize_t     first_heap_size;        /* Total size of the heap after the first block */
    hsize_t     all_heap_size;          /* Total size of the heap after all blocks */
    size_t      block_size;             /* Block size for row */
    size_t      block_free;             /* Free space in empty block of this row */
    unsigned    width;                  /* Width of heap's doubling table */
    unsigned    expand_rows;            /* # of rows to expand heap by */
    unsigned    u;                      /* Local index variable */

    /* Sanity check */
    HDassert(fh);
    HDassert(state);

    /* Get some information for the heap */
    block_size = DBLOCK_SIZE(fh, row);
    block_free = DBLOCK_FREE(fh, row);
    width = DTABLE_WIDTH(fh);

    /* Compute the number of rows to expand heap by */
    if(row < 2)
        expand_rows = 1;
    else if(POWER_OF_TWO(row))
        expand_rows = row;
    else 
        expand_rows = 0;

    /* Compute first block & all blocks heap size & free space */
    if(state->heap_size == 0) {
        first_heap_size = block_size;
        first_free_space = block_free;
        all_heap_size = width * block_size;
        all_free_space = (width - 1) * block_free;
    } /* end if */
    else if(expand_rows == 0) {
        all_heap_size = state->heap_size;
        all_free_space = state->man_free_space;
        first_heap_size = all_heap_size;
        first_free_space = all_free_space;
        all_free_space -= block_free;      /* Account for shift from first free space */
    } /* end if */
    else {
        all_heap_size = state->heap_size;
        all_free_space = 0;
        for(u = 0; u < expand_rows; u++) {
            all_heap_size += width * DBLOCK_SIZE(fh, row + u);
            all_free_space += width * DBLOCK_FREE(fh, row + u);
        } /* end for */
        first_heap_size = all_heap_size;
        first_free_space = all_free_space;
        all_free_space -= block_free;      /* Account for shift from first free space */
    } /* end else */

    /* Loop over filling direct blocks, until root indirect row is full */
    state->heap_size = first_heap_size;
    state->man_size = first_heap_size;
    state->man_free_space = first_free_space;
    for(u = 0; u < width; u++) {
        /* Set heap's size & free space correctly */
        if(u == 1) {
            state->heap_size = all_heap_size;
            state->man_size = all_heap_size;
            state->man_free_space = all_free_space;
        } /* end if */

        /* Account for new block added */
        state->man_alloc_size += block_size;

        /* Fill a direct heap block up */
        if(fill_heap(fh, dxpl, row, obj_size, state, keep_ids))
            FAIL_STACK_ERROR
    } /* end for */

    /* Operations succeeded */
    return(0);

error:
    return(1);
} /* fill_root_row() */


/*-------------------------------------------------------------------------
 * Function:	fill_row
 *
 * Purpose:	Fill up a row of direct blocks in an non-root indirect block
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, April 10, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
fill_row(H5HF_t *fh, hid_t dxpl, unsigned row, size_t obj_size,
    fheap_heap_state_t *state, fheap_heap_ids_t *keep_ids)
{
    size_t      block_size;             /* Size of direct block in this row */
    unsigned    width;                  /* Width of heap's doubling table */
    unsigned    u;                      /* Local index variable */

    /* Sanity check */
    HDassert(fh);
    HDassert(state);

    /* Get some information for the heap */
    block_size = DBLOCK_SIZE(fh, row);
    width = DTABLE_WIDTH(fh);

    /* Loop over filling direct blocks, until indirect row is full */
    for(u = 0; u < width; u++) {
        /* Adjust stats for new block */
        state->man_alloc_size += block_size;

        /* Fill a direct heap block up */
        if(fill_heap(fh, dxpl, row, obj_size, state, keep_ids))
            FAIL_STACK_ERROR
    } /* end for */

    /* Operations succeeded */
    return(0);

error:
    return(1);
} /* fill_row() */


/*-------------------------------------------------------------------------
 * Function:	fill_root_direct
 *
 * Purpose:	Insert (small) objects to fill up the free space in all direct
 *              heap blocks in the root indirect block
 *              (Generally used to create & fill up direct blocks in a new
 *              indirect block)
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, April  3, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
fill_root_direct(H5HF_t *fh, hid_t dxpl, size_t obj_size,
    fheap_heap_state_t *state, fheap_heap_ids_t *keep_ids)
{
    unsigned    max_dblock_rows;        /* Max. # of direct block rows in indirect block */
    unsigned    row;                    /* Row being created */

    /* Get heap info */
    max_dblock_rows = DTABLE_MAX_DROWS(fh);
    HDassert(max_dblock_rows);

    /* Loop over rows */
    for(row = 0; row < max_dblock_rows; row++)
        if(fill_root_row(fh, dxpl, row, obj_size, state, keep_ids))
            FAIL_STACK_ERROR

    /* Operations succeeded */
    return(0);

error:
    return(1);
} /* fill_root_direct() */


/*-------------------------------------------------------------------------
 * Function:	fill_2nd_indirect
 *
 * Purpose:	Insert (small) objects to fill up the free space in all direct
 *              heap blocks in a second-level indirect block (which only has
 *              direct blocks)
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, April 10, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
fill_2nd_indirect(H5HF_t *fh, hid_t dxpl, unsigned pos, size_t obj_size,
    fheap_heap_state_t *state, fheap_heap_ids_t *keep_ids)
{
    unsigned    max_dblock_rows;        /* Max. # of direct block rows in indirect block */
    unsigned    row;                    /* Current row to create */

    /* Get some information for the heap */
    max_dblock_rows = IBLOCK_MAX_DROWS(fh, pos);
    HDassert(max_dblock_rows);

    /* Loop over rows */
    for(row = 0; row < max_dblock_rows; row++)
        if(fill_row(fh, dxpl, row, obj_size, state, keep_ids))
            FAIL_STACK_ERROR

    /* Operations succeeded */
    return(0);

error:
    return(1);
} /* fill_2nd_direct() */


/*-------------------------------------------------------------------------
 * Function:	fill_all_direct
 *
 * Purpose:	Insert (small) objects to fill up the free space in all direct
 *              heap blocks up to the maximum direct block size
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, April 10, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
fill_all_direct(H5HF_t *fh, hid_t dxpl, size_t obj_size,
    fheap_heap_state_t *state, fheap_heap_ids_t *keep_ids)
{
    unsigned    max_dblock_rows;        /* Max. # of direct block rows in indirect block */
    unsigned    row;                    /* Row being created */

    /* Get heap info */
    max_dblock_rows = DTABLE_MAX_DROWS(fh);
    HDassert(max_dblock_rows);

    /* Loop over rows */
    for(row = 0; row < max_dblock_rows; row++)
        if(fill_row(fh, dxpl, row, obj_size, state, keep_ids))
            FAIL_STACK_ERROR

    /* Operations succeeded */
    return(0);

error:
    return(1);
} /* fill_all_direct() */


/*-------------------------------------------------------------------------
 * Function:	fill_2nd_indirect_row
 *
 * Purpose:	Insert (small) objects to fill up the free space in all direct
 *              heap blocks in a row of second-level indirect block (which only
 *              have direct blocks)
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, April 10, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
fill_2nd_indirect_row(H5HF_t *fh, hid_t dxpl, unsigned pos, size_t obj_size,
    fheap_heap_state_t *state, fheap_heap_ids_t *keep_ids)
{
    unsigned    width;                  /* Width of heap's doubling table */
    unsigned    u;                      /* Local index variable */

    /* Get some information for the heap */
    width = DTABLE_WIDTH(fh);

    /* Loop over row of indirect blocks */
    for(u = 0; u < width; u++)
        if(fill_2nd_indirect(fh, dxpl, pos, obj_size, state, keep_ids))
            FAIL_STACK_ERROR

    /* Operations succeeded */
    return(0);

error:
    return(1);
} /* fill_2nd_direct_row() */


/*-------------------------------------------------------------------------
 * Function:	fill_all_2nd_indirect_rows
 *
 * Purpose:	Insert (small) objects to fill up the free space in all direct
 *              heap blocks in all rows of second-level indirect blocks (which only
 *              have direct blocks)
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, April 10, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
fill_all_2nd_indirect_rows(H5HF_t *fh, hid_t dxpl, size_t obj_size,
    fheap_heap_state_t *state, fheap_heap_ids_t *keep_ids)
{
    unsigned    width;                  /* Width of heap's doubling table */
    unsigned    u;                      /* Local index variable */

    /* Get some information for the heap */
    width = DTABLE_WIDTH(fh);

    /* Loop over rows of 2nd level deep indirect blocks */
    for(u = 0; u < (H5V_log2_of2(width) + 1); u++)
        if(fill_2nd_indirect_row(fh, dxpl, (u + 1), obj_size, state, keep_ids))
            FAIL_STACK_ERROR

    /* Operations succeeded */
    return(0);

error:
    return(1);
} /* fill_2nd_direct_row() */


/*-------------------------------------------------------------------------
 * Function:	fill_3rd_indirect
 *
 * Purpose:	Insert (small) objects to fill up the free space in all direct
 *              heap blocks in a third-level indirect block (which 
 *              has one more level of indirect blocks)
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, April 18, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
fill_3rd_indirect(H5HF_t *fh, hid_t dxpl, unsigned pos, size_t obj_size,
    fheap_heap_state_t *state, fheap_heap_ids_t *keep_ids)
{
    unsigned    u;                      /* Local index variable */

    /* Fill all direct block rows in third level indirect block */
    if(fill_all_direct(fh, dxpl, obj_size, state, keep_ids))
        FAIL_STACK_ERROR

    /* Fill rows of recursive indirect blocks in third level indirect block */
    for(u = 0; u < pos; u++)
        if(fill_2nd_indirect_row(fh, dxpl, (u + 1), obj_size, state, keep_ids))
            FAIL_STACK_ERROR

    /* Operations succeeded */
    return(0);

error:
    return(1);
} /* fill_3rd_indirect() */


/*-------------------------------------------------------------------------
 * Function:	fill_3rd_indirect_row
 *
 * Purpose:	Insert (small) objects to fill up the free space in all direct
 *              heap blocks in a row of third-level indirect block (which 
 *              have one more level of indirect blocks)
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, April 10, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
fill_3rd_indirect_row(H5HF_t *fh, hid_t dxpl, unsigned pos, size_t obj_size,
    fheap_heap_state_t *state, fheap_heap_ids_t *keep_ids)
{
    unsigned    width;                  /* Width of heap's doubling table */
    unsigned    u;              /* Local index variable */

    /* Get some information for the heap */
    width = DTABLE_WIDTH(fh);

    /* Loop over row of 3rd level indirect blocks */
    for(u = 0; u < width; u++)
        /* Fill third level indirect block */
        if(fill_3rd_indirect(fh, dxpl, pos, obj_size, state, keep_ids))
            FAIL_STACK_ERROR

    /* Operations succeeded */
    return(0);

error:
    return(1);
} /* fill_3rd_direct_row() */


/*-------------------------------------------------------------------------
 * Function:	fill_all_3rd_indirect_rows
 *
 * Purpose:	Insert (small) objects to fill up the free space in all direct
 *              heap blocks in all rows of third-level indirect blocks (which 
 *              have one more level of indirect blocks)
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, April 10, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
fill_all_3rd_indirect_rows(H5HF_t *fh, hid_t dxpl, size_t obj_size,
    fheap_heap_state_t *state, fheap_heap_ids_t *keep_ids)
{
    unsigned    width;                  /* Width of heap's doubling table */
    unsigned    u;                      /* Local index variable */

    /* Get some information for the heap */
    width = DTABLE_WIDTH(fh);

    /* Loop over rows of 3rd level deep indirect blocks */
    for(u = 0; u < (H5V_log2_of2(width) + 1); u++)
        /* Fill row of 3rd level indirect blocks */
        if(fill_3rd_indirect_row(fh, dxpl, (u + 1), obj_size, state, keep_ids))
            FAIL_STACK_ERROR

    /* Operations succeeded */
    return(0);

error:
    return(1);
} /* fill_all_3rd_direct_rows() */


/*-------------------------------------------------------------------------
 * Function:	fill_4th_indirect_row
 *
 * Purpose:	Insert (small) objects to fill up the free space in all direct
 *              heap blocks in a row of fourth-level indirect blocks (which 
 *              have two more levels of indirect blocks)
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, April 10, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
fill_4th_indirect_row(H5HF_t *fh, hid_t dxpl, unsigned pos, size_t obj_size,
    fheap_heap_state_t *state, fheap_heap_ids_t *keep_ids)
{
    unsigned    width;                  /* Width of heap's doubling table */
    unsigned    u, v;                   /* Local index variables */

    /* Get some information for the heap */
    width = DTABLE_WIDTH(fh);

    /* Loop over row of 4th level indirect blocks */
    for(u = 0; u < width; u++) {
        /* Fill all direct block rows in fourth level indirect block */
        if(fill_all_direct(fh, dxpl, obj_size, state, keep_ids))
            FAIL_STACK_ERROR

        /* Fill all rows of 2nd level deep indirect blocks in fourth level indirect block */
        if(fill_all_2nd_indirect_rows(fh, dxpl, obj_size, state, keep_ids))
            FAIL_STACK_ERROR

        /* Fill rows of third level indirect blocks in fourth level indirect block */
        for(v = 0; v < pos; v++)
            if(fill_3rd_indirect_row(fh, dxpl, (v + 1), obj_size, state, keep_ids))
                FAIL_STACK_ERROR
    } /* end for */

    /* Operations succeeded */
    return(0);

error:
    return(1);
} /* fill_4th_direct_row() */


/*-------------------------------------------------------------------------
 * Function:	fill_all_4th_indirect_rows
 *
 * Purpose:	Insert (small) objects to fill up the free space in all direct
 *              heap blocks in all rows of fourth-level indirect blocks (which 
 *              have two more levels of indirect blocks)
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, April 10, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
fill_all_4th_indirect_rows(H5HF_t *fh, hid_t dxpl, size_t obj_size,
    fheap_heap_state_t *state, fheap_heap_ids_t *keep_ids)
{
    unsigned    width;                  /* Width of heap's doubling table */
    unsigned    u;                      /* Local index variable */

    /* Get some information for the heap */
    width = DTABLE_WIDTH(fh);

    /* Loop over rows of 4th level deep indirect blocks */
    for(u = 0; u < (H5V_log2_of2(width) + 1); u++) {
        /* Fill row of 4th level indirect blocks */
        if(fill_4th_indirect_row(fh, dxpl, (u + 1), obj_size, state, keep_ids))
            FAIL_STACK_ERROR

        /* Account for root indirect block doubling # of rows again */
        /* (From 16 rows to the max. # of rows: 22) */
        /* (Note: this is tied to the particular doubling table/heap creation parameters) */
        if(u == 0) {
            unsigned max_root_rows;     /* Maximum # of rows in root indirect block */
            unsigned row;               /* Row in heap */

            /* Get some information for the heap */
            max_root_rows = HEAP_MAX_ROOT_ROWS(fh);

            /* Increase heap size & free space */
            for(row = 16; row < max_root_rows; row++) {
                state->heap_size += width * DBLOCK_SIZE(fh, row);
                state->man_size += width * DBLOCK_SIZE(fh, row);
                state->man_free_space += width * DBLOCK_FREE(fh, row);
            } /* end for */
        } /* end if */
    } /* end for */

    /* Operations succeeded */
    return(0);

error:
    return(1);
} /* fill_all_4th_direct_rows() */


/*-------------------------------------------------------------------------
 * Function:	test_create
 *
 * Purpose:	Create fractal heap
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Friday, February 24, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_create(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t UNUSED *tparam)
{
    hid_t	file = -1;              /* File ID */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_create_t test_cparam;          /* Creation parameters for heap */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /*
     * Test fractal heap creation (w/absolute address mapping)
     */
    TESTING("fractal heap creation (w/absolute address mapping)");
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));
    if(check_stats(fh, &state))
        FAIL_STACK_ERROR
    PASSED()

    /* Query the type of address mapping */
    TESTING("query heap creation parameters");
    HDmemset(&test_cparam, 0, sizeof(H5HF_create_t));
    if(H5HF_get_cparam_test(fh, &test_cparam) < 0)
        FAIL_STACK_ERROR
    if(HDmemcmp(cparam, &test_cparam, sizeof(H5HF_create_t)))
        FAIL_STACK_ERROR
    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, H5P_DATASET_XFER_DEFAULT) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, H5P_DATASET_XFER_DEFAULT);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_create() */


/*-------------------------------------------------------------------------
 * Function:	test_reopen
 *
 * Purpose:	Create & reopen a fractal heap
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, April 18, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_reopen(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t UNUSED *tparam)
{
    hid_t	file = -1;              /* File ID */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_create_t test_cparam;          /* Creation parameters for heap */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /*
     * Test fractal heap creation (w/absolute address mapping)
     */

    TESTING("reopening existing fractal heap (w/absolute address mapping)");

    /* Create heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));
    if(check_stats(fh, &state))
        FAIL_STACK_ERROR

    /* Close the fractal heap */
    if(H5HF_close(fh, H5P_DATASET_XFER_DEFAULT) < 0)
        TEST_ERROR

    /* Re-open the heap */
    if(NULL == (fh = H5HF_open(f, H5P_DATASET_XFER_DEFAULT, fh_addr)))
        FAIL_STACK_ERROR

    /* Query the type of address mapping */
    HDmemset(&test_cparam, 0, sizeof(H5HF_create_t));
    if(H5HF_get_cparam_test(fh, &test_cparam) < 0)
        FAIL_STACK_ERROR
    if(HDmemcmp(cparam, &test_cparam, sizeof(H5HF_create_t)))
        FAIL_STACK_ERROR

    /* Close the fractal heap */
    if(H5HF_close(fh, H5P_DATASET_XFER_DEFAULT) < 0)
        TEST_ERROR
    PASSED()

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, H5P_DATASET_XFER_DEFAULT);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_reopen() */

#ifdef ALL_INSERT_TESTS

/*-------------------------------------------------------------------------
 * Function:	test_abs_insert_first
 *
 * Purpose:	Test inserting first object into absolute heap
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Friday, February 24, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_insert_first(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, dxpl, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));
    if(check_stats(fh, &state))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close (empty) heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /*
     * Test inserting first (small) object into absolute heap
     */
    TESTING("inserting first (small) object into absolute heap");
    state.heap_size = DBLOCK_SIZE(fh, 0);
    state.man_size = DBLOCK_SIZE(fh, 0);
    state.man_alloc_size = DBLOCK_SIZE(fh, 0);
    state.man_free_space = DBLOCK_FREE(fh, 0);
    if(add_obj(fh, dxpl, 10, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Check for correctly sized heap */
    if(check_stats(fh, &state))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_insert_first() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_insert_second
 *
 * Purpose:	Test inserting two objects into absolute heap
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, March  6, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_insert_second(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, dxpl, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting first (small) object into absolute heap
     */
    TESTING("inserting two (small) objects into absolute heap");
    state.heap_size = DBLOCK_SIZE(fh, 0);
    state.man_size = DBLOCK_SIZE(fh, 0);
    state.man_alloc_size = DBLOCK_SIZE(fh, 0);
    state.man_free_space = DBLOCK_FREE(fh, 0);
    if(add_obj(fh, dxpl, 10, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert second object */
    if(add_obj(fh, dxpl, 20, SMALL_OBJ_SIZE2, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_insert_second() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_insert_root_mult
 *
 * Purpose:	Test inserting mult. objects into absolute heap, up to the
 *              limit of a root direct block
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, March  6, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_insert_root_mult(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, dxpl, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) object into absolute heap
     */
    TESTING("inserting objects to fill absolute heap's root direct block");

    /* Fill the heap up */
    state.heap_size = DBLOCK_SIZE(fh, 0);
    state.man_size = DBLOCK_SIZE(fh, 0);
    state.man_alloc_size = DBLOCK_SIZE(fh, 0);
    state.man_free_space = DBLOCK_FREE(fh, 0);
    if(fill_heap(fh, dxpl, 0, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_insert_root_mult() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_insert_force_indirect
 *
 * Purpose:	Test inserting mult. objects into absolute heap, filling the
 *              root direct block and forcing the root block to be converted
 *              into an indirect block
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, March  6, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_insert_force_indirect(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test forcing creation of indirect root block & second direct block
     */
    TESTING("inserting objects to create root indirect block");

    /* Fill the heap up */
    state.heap_size = DBLOCK_SIZE(fh, 0);
    state.man_size = DBLOCK_SIZE(fh, 0);
    state.man_alloc_size = DBLOCK_SIZE(fh, 0);
    state.man_free_space = DBLOCK_FREE(fh, 0);
    if(fill_heap(fh, dxpl, 0, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert one more object, to force root indirect block creation */
    state.heap_size = cparam->managed.width * DBLOCK_SIZE(fh, 0);
    state.man_size = cparam->managed.width * DBLOCK_SIZE(fh, 0);
    state.man_alloc_size += DBLOCK_SIZE(fh, 0);
    state.man_free_space = (cparam->managed.width - 1) * DBLOCK_FREE(fh, 0);
    if(add_obj(fh, dxpl, 10, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_insert_force_indirect() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_insert_fill_second
 *
 * Purpose:	Test inserting mult. objects into absolute heap, filling the
 *              root direct block, forcing the root block to be converted
 *              into an indirect block and filling the secnod indirect block
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, March  7, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_insert_fill_second(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to fill second direct block
     */
    TESTING("inserting objects to fill second direct block");

    /* Fill the first direct block heap up */
    state.heap_size = DBLOCK_SIZE(fh, 0);
    state.man_size = DBLOCK_SIZE(fh, 0);
    state.man_alloc_size = DBLOCK_SIZE(fh, 0);
    state.man_free_space = DBLOCK_FREE(fh, 0);
    if(fill_heap(fh, dxpl, 0, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill the second direct block heap up (also creates initial root indirect block) */
    state.heap_size = cparam->managed.width * DBLOCK_SIZE(fh, 0);
    state.man_size = cparam->managed.width * DBLOCK_SIZE(fh, 0);
    state.man_alloc_size += DBLOCK_SIZE(fh, 0);
    state.man_free_space = (cparam->managed.width - 1) * DBLOCK_FREE(fh, 0);
    if(fill_heap(fh, dxpl, 0, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_insert_fill_second() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_insert_third_direct
 *
 * Purpose:	Test inserting mult. objects into absolute heap, filling the
 *              root direct block, forcing the root block to be converted
 *              into an indirect block, filling the secnod indirect block and
 *              creating a third direct block
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, March  7, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_insert_third_direct(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to create third direct block
     */
    TESTING("inserting objects to create third direct block");

    /* Fill the first direct block up */
    state.heap_size = DBLOCK_SIZE(fh, 0);
    state.man_size = DBLOCK_SIZE(fh, 0);
    state.man_alloc_size = DBLOCK_SIZE(fh, 0);
    state.man_free_space = DBLOCK_FREE(fh, 0);
    if(fill_heap(fh, dxpl, 0, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Fill the second direct block heap up (also creates initial root indirect block) */
    state.heap_size = cparam->managed.width * DBLOCK_SIZE(fh, 0);
    state.man_size = cparam->managed.width * DBLOCK_SIZE(fh, 0);
    state.man_alloc_size += DBLOCK_SIZE(fh, 0);
    state.man_free_space = (cparam->managed.width - 1) * DBLOCK_FREE(fh, 0);
    if(fill_heap(fh, dxpl, 0, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert one more object, to force creation of third direct block */
    state.man_alloc_size += DBLOCK_SIZE(fh, 0);
    if(add_obj(fh, dxpl, 10, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_insert_third_direct() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_fill_first_row
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill first row of root indirect
 *              block.
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, March 13, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_fill_first_row(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to fill first row in root indirect block
     */
    TESTING("inserting objects to fill first row of root indirect block");

    /* Fill first row of [root] indirect block */
    if(fill_root_row(fh, dxpl, 0, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_fill_first_row() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_start_second_row
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill first row of root indirect
 *              block, then add another object to start second row.
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, March 14, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_start_second_row(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to start second row in root indirect block
     */
    TESTING("inserting objects to start second row of root indirect block");

    /* Fill first root indirect row */
    if(fill_root_row(fh, dxpl, 0, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert one more object, to force expanding root indirect block to two rows */
    state.heap_size += cparam->managed.width * DBLOCK_SIZE(fh, 1);
    state.man_size += cparam->managed.width * DBLOCK_SIZE(fh, 1);
    state.man_alloc_size += DBLOCK_SIZE(fh, 1);
    state.man_free_space = cparam->managed.width * DBLOCK_FREE(fh, 1);
    if(add_obj(fh, dxpl, 10, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_start_second_row() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_fill_second_row
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill first row of root indirect
 *              block, then fill the second row also.
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, March 14, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_fill_second_row(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to start second row in root indirect block
     */
    TESTING("inserting objects to fill second row of root indirect block");

    /* Fill first root indirect row */
    if(fill_root_row(fh, dxpl, 0, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill second root indirect row */
    if(fill_root_row(fh, dxpl, 1, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_fill_second_row() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_start_third_row
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill first row of root indirect
 *              block, fill the second row also, then add another object to
 *              start the third row.
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, March 20, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_start_third_row(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to start third row in root indirect block
     */
    TESTING("inserting objects to start third row of root indirect block");

    /* Fill first root indirect row */
    if(fill_root_row(fh, dxpl, 0, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Fill second root indirect row */
    if(fill_root_row(fh, dxpl, 1, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert one more object, to force expanding root indirect block to four rows */
    /* (Goes to four rows because it's doubling) */
    state.heap_size += cparam->managed.width * DBLOCK_SIZE(fh, 2);
    state.heap_size += cparam->managed.width * DBLOCK_SIZE(fh, 3);
    state.man_size += cparam->managed.width * DBLOCK_SIZE(fh, 2);
    state.man_size += cparam->managed.width * DBLOCK_SIZE(fh, 3);
    state.man_alloc_size += DBLOCK_SIZE(fh, 2);
    state.man_free_space += cparam->managed.width * DBLOCK_FREE(fh, 2);
    state.man_free_space += cparam->managed.width * DBLOCK_FREE(fh, 3);
    if(add_obj(fh, dxpl, 10, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_start_third_row() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_fill_fourth_row
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill first four rows of root indirect
 *              block.
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, March 20, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_fill_fourth_row(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */
    unsigned    u;                      /* Local index variables */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to fill four rows in root indirect block
     */
    TESTING("inserting objects to fill four rows of root indirect block");

    /* Loop over rows */
    for(u = 0; u < 4; u++)
        if(fill_root_row(fh, dxpl, u, SMALL_OBJ_SIZE1, &state, NULL))
            FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_fill_fourth_row() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_fill_all_root_direct
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill all direct rows of root indirect
 *              block.
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, March 20, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_fill_all_root_direct(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to fill all direct  rows in root indirect block
     */
    TESTING("inserting objects to fill all direct rows of root indirect block");

    /* Fill all direct blocks in root indirect block */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_fill_all_root_direct() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_first_recursive_indirect
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill all direct rows of root indirect
 *              block and create first recursive indirect block.
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, March 20, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_first_recursive_indirect(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to force creation of first recursive indirect block
     */
    TESTING("inserting objects to create first recursive indirect block");

    /* Fill direct blocks up */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert one more object, to force creation of first recursive indirect block */
    state.man_alloc_size += DBLOCK_SIZE(fh, 0);
    if(add_obj(fh, dxpl, 10, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_first_recursive_indirect() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_second_direct_recursive_indirect
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill all direct rows of root indirect
 *              block, create first recursive indirect block and start second
 *              direct block in that indirect block.
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, March 21, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_second_direct_recursive_indirect(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to force creation of second direct
     *  block in first recursive indirect block
     */
    TESTING("inserting objects to create second direct block in first recursive indirect block");

    /* Fill direct blocks up */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Fill the first direct block in the recursive indirect block up */
    state.man_alloc_size += DBLOCK_SIZE(fh, 0);
    if(fill_heap(fh, dxpl, 0, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert one more object, to force creation of second direct block in
     * first recursive indirect block
     */
    state.man_alloc_size += DBLOCK_SIZE(fh, 0);
    if(add_obj(fh, dxpl, 10, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_second_direct_recursive_indirect() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_fill_first_recursive_indirect
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill all direct rows of root indirect
 *              block, create first recursive indirect block and filling all
 *              direct blocks in that indirect block.
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, March 21, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_fill_first_recursive_indirect(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to fill all direct
     *  blocks in first recursive indirect block
     */
    TESTING("inserting objects to fill all direct blocks in first recursive indirect block");

    /* Fill direct blocks up in root indirect block */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill first recursive indirect block */
    if(fill_2nd_indirect(fh, dxpl, 1, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_fill_first_recursive_indirect() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_second_recursive_indirect
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill all direct rows of root indirect
 *              block, create first recursive indirect block, filling all
 *              direct blocks in that indirect block and adding another
 *              object to force creation of second recursive indirect block.
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, March 21, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_second_recursive_indirect(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to fill all direct
     *  blocks in first recursive indirect block
     */
    TESTING("inserting objects to start second recursive indirect block");

    /* Fill direct blocks up in root indirect block */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Fill first recursive indirect block */
    if(fill_2nd_indirect(fh, dxpl, 1, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert one more object, to force creation of second 
     * recursive indirect block
     */
    state.man_alloc_size += DBLOCK_SIZE(fh, 0);
    if(add_obj(fh, dxpl, 10, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_second_recursive_indirect() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_fill_second_recursive_indirect
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill all direct rows of root indirect
 *              block, create first recursive indirect block, filling all
 *              direct blocks in that indirect block and then create second
 *              recursive indirect block and fill all direct blocks in that
 *              indirect block.
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, March 21, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_fill_second_recursive_indirect(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to fill all direct
     *  blocks in first recursive indirect block
     */
    TESTING("inserting objects to fill all direct blocks in second recursive indirect block");

    /* Fill direct blocks up in root indirect block */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Fill first recursive indirect block */
    if(fill_2nd_indirect(fh, dxpl, 1, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill 2nd recursive indirect block */
    if(fill_2nd_indirect(fh, dxpl, 1, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_fill_second_recursive_indirect() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_fill_recursive_indirect_row
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill all direct rows of root indirect
 *              block, create first recursive indirect block, filling all
 *              direct blocks in that indirect block and then create second
 *              recursive indirect block and fill all direct blocks in that
 *              indirect block.
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, March 21, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_fill_recursive_indirect_row(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to fill all direct
     *  blocks in first recursive indirect block
     */
    TESTING("inserting objects to fill all direct blocks in first row of recursive indirect block");

    /* Fill direct blocks in root indirect block up */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill row of recursive indirect blocks */
    if(fill_2nd_indirect_row(fh, dxpl, 1, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_fill_recursive_indirect_row() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_start_2nd_recursive_indirect
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill all direct rows of root indirect
 *              block, fill all direct blocks in the first row of indirect
 *              blocks and start on first block in second row of indirect blocks
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, March 27, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_start_2nd_recursive_indirect(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to fill all direct
     *  blocks in first recursive indirect block
     */
    TESTING("inserting objects to start second row of recursive indirect blocks");

    /* Fill direct blocks in root indirect block up */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Fill row of recursive indirect blocks */
    if(fill_2nd_indirect_row(fh, dxpl, 1, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert one more object, to force creation of second 
     * recursive indirect block
     */
    state.man_alloc_size += DBLOCK_SIZE(fh, 0);
    if(add_obj(fh, dxpl, 10, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_start_2nd_recursive_indirect() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_recursive_indirect_two_deep
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill all direct rows of root indirect
 *              block, fill all direct blocks in the row of indirect
 *              blocks that are 2 levels deep
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, March 27, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_recursive_indirect_two_deep(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to fill all direct
     *  blocks in first recursive indirect block
     */
    TESTING("inserting objects to fill recursive indirect blocks two levels deep");

    /* Fill direct blocks up in root indirect block */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill all rows of 2nd level indirect blocks */
    if(fill_all_2nd_indirect_rows(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_recursive_indirect_two_deep() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_start_3rd_recursive_indirect
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill all direct rows of root indirect
 *              block, fill all direct blocks in the row of indirect
 *              blocks that are 2 levels deep and start first direct block
 *              in 3rd level of indirect blocks
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, March 27, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_start_3rd_recursive_indirect(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to fill all direct
     *  blocks in first recursive indirect block
     */
    TESTING("inserting objects to start recursive indirect blocks three levels deep");

    /* Fill direct blocks up in root indirect block */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Fill all rows of 2nd level indirect blocks */
    if(fill_all_2nd_indirect_rows(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert one more object, to force creation of third level deep
     * recursive indirect block
     */
    state.man_alloc_size += DBLOCK_SIZE(fh, 0);
    if(add_obj(fh, dxpl, 10, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_start_3rd_recursive_indirect() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_fill_first_3rd_recursive_indirect
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill all direct rows of root indirect
 *              block, fill all direct blocks in the row of indirect
 *              blocks that are 2 levels deep and fill first indirect block
 *              in 3rd level of indirect blocks
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, March 27, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_fill_first_3rd_recursive_indirect(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to fill all direct
     *  blocks in first recursive indirect block
     */
    TESTING("inserting objects to fill first indirect block of recursive indirect blocks three levels deep");

    /* Fill direct blocks up in root indirect block */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Fill all rows of 2nd level indirect blocks */
    if(fill_all_2nd_indirect_rows(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Fill all direct block rows in third level indirect block */
    if(fill_all_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill row of recursive indirect blocks in third level indirect block */
    if(fill_2nd_indirect_row(fh, dxpl, 1, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_fill_first_3rd_recursive_indirect() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_fill_3rd_recursive_indirect_row
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill all direct rows of root indirect
 *              block, fill all direct blocks in the row of indirect
 *              blocks that are 2 levels deep and fill all indirect blocks
 *              first row of 3rd level of indirect blocks
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, March 27, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_fill_3rd_recursive_indirect_row(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to fill all direct
     *  blocks in first recursive indirect block
     */
    TESTING("inserting objects to fill row of indirect blocks in recursive indirect blocks three levels deep");

    /* Fill direct blocks up in root indirect block */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Fill all rows of 2nd level indirect blocks */
    if(fill_all_2nd_indirect_rows(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill 1st row of 3rd level indirect blocks */
    if(fill_3rd_indirect_row(fh, dxpl, 1, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_fill_3rd_recursive_indirect_row() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_fill_all_3rd_recursive_indirect
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill all direct rows of root indirect
 *              block, fill all direct blocks in the row of indirect
 *              blocks that are 2 levels deep and fill all indirect blocks
 *              that are three levels deep
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, March 27, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_fill_all_3rd_recursive_indirect(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to fill all direct
     *  blocks in first recursive indirect block
     */
    TESTING("inserting objects to fill row of indirect blocks in recursive indirect blocks three levels deep");

    /* Fill direct blocks up in root indirect block */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Fill all rows of 2nd level indirect blocks */
    if(fill_all_2nd_indirect_rows(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill all rows of 3rd level indirect blocks */
    if(fill_all_3rd_indirect_rows(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_fill_all_3rd_recursive_indirect() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_start_4th_recursive_indirect
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill all direct rows of root indirect
 *              block, fill all direct blocks in the row of indirect
 *              blocks that are 2 levels deep, fill all indirect blocks
 *              that are three levels deep and start first direct block that
 *              is four levels deep
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, March 27, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_start_4th_recursive_indirect(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to fill all direct
     *  blocks in first recursive indirect block
     */
    TESTING("inserting objects to start first direct block in recursive indirect blocks four levels deep");

    /* Fill direct blocks up in root indirect block */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Fill all rows of 2nd level indirect blocks */
    if(fill_all_2nd_indirect_rows(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Fill all rows of 3rd level indirect blocks */
    if(fill_all_3rd_indirect_rows(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert one more object, to force creation of four level deep
     * recursive indirect block
     */
    state.man_alloc_size += DBLOCK_SIZE(fh, 0);
    if(add_obj(fh, dxpl, 10, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_start_4th_recursive_indirect() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_fill_first_4th_recursive_indirect
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill all direct rows of root indirect
 *              block, fill all direct blocks in the row of indirect
 *              blocks that are 2 levels deep, fill all indirect blocks
 *              that are three levels deep and fill the first (3rd level)
 *              indirect block that is four levels deep
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, March 27, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_fill_first_4th_recursive_indirect(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to fill all direct
     *  blocks in first recursive indirect block
     */
    TESTING("inserting objects to fill first (3rd level) indirect block in recursive indirect block four levels deep");

    /* Fill direct blocks up in root indirect block */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Fill all rows of 2nd level indirect blocks */
    if(fill_all_2nd_indirect_rows(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Fill all rows of 3rd level indirect blocks */
    if(fill_all_3rd_indirect_rows(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Fill direct block rows in fourth level indirect block */
    if(fill_all_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Fill all rows of 2nd level deep indirect blocks in fourth level indirect block */
    if(fill_all_2nd_indirect_rows(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill first row of 3rd level deep indirect blocks in fourth level indirect block */
    if(fill_3rd_indirect_row(fh, dxpl, 1, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_fill_first_4th_recursive_indirect() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_fill_4th_recursive_indirect_row
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill all direct rows of root indirect
 *              block, fill all direct blocks in the row of indirect
 *              blocks that are 2 levels deep, fill all indirect blocks
 *              that are three levels deep and fill the first row of
 *              indirect block that is four levels deep
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, March 27, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_fill_4th_recursive_indirect_row(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to fill all direct
     *  blocks in first recursive indirect block
     */
    TESTING("inserting objects to fill first row of recursive indirect blocks four levels deep");

    /* Fill direct blocks up in root indirect block */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Fill all rows of 2nd level indirect blocks */
    if(fill_all_2nd_indirect_rows(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Fill all rows of 3rd level indirect blocks */
    if(fill_all_3rd_indirect_rows(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill 1st row of 4th level indirect blocks */
    if(fill_4th_indirect_row(fh, dxpl, 1, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_fill_4th_recursive_indirect_row() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_fill_all_4th_recursive_indirect
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill all direct rows of root indirect
 *              block, fill all direct blocks in the row of indirect
 *              blocks that are 2 levels deep, fill all indirect blocks
 *              that are three levels deep and fill all rows of
 *              indirect blocks that are four levels deep
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, March 27, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_fill_all_4th_recursive_indirect(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to fill all direct
     *  blocks in recursive indirect blocks four levels deep
     */
    TESTING("inserting objects to fill all rows of recursive indirect blocks four levels deep");

    /* Fill direct blocks up in root indirect block */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Fill all rows of 2nd level indirect blocks */
    if(fill_all_2nd_indirect_rows(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Fill all rows of 3rd level indirect blocks */
    if(fill_all_3rd_indirect_rows(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill all rows of 4th level indirect blocks */
    if(fill_all_4th_indirect_rows(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_fill_all_4th_recursive_indirect() */
#endif /* ALL_INSERT_TESTS */

#ifndef QAK

/*-------------------------------------------------------------------------
 * Function:	test_abs_start_5th_recursive_indirect
 *
 * Purpose:	Test inserting mult. objects into absolute heap, creating
 *              enough direct blocks to fill all direct rows of root indirect
 *              block, fill all direct blocks in the row of indirect
 *              blocks that are 2 levels deep, fill all indirect blocks
 *              that are three levels deep, fill all rows of indirect blocks
 *              that are four levels deep and start first direct block in 
 *              indirect blocks five levels deep
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, March 27, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_start_5th_recursive_indirect(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting mult. (small) objects to fill all direct
     *  blocks in recursive indirect blocks four levels deep and add one more
     *  block, to make a five level deep structure
     */
    TESTING("inserting objects to create first direct block in recursive indirect blocks five levels deep");

    /* Fill direct blocks up in root indirect block */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill all rows of 2nd level indirect blocks */
    if(fill_all_2nd_indirect_rows(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill all rows of 3rd level indirect blocks */
    if(fill_all_3rd_indirect_rows(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill all rows of 4th level indirect blocks */
    if(fill_all_4th_indirect_rows(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert one more object, to force creation of five level deep
     * recursive indirect block
     */
    state.man_alloc_size += DBLOCK_SIZE(fh, 0);
    if(add_obj(fh, dxpl, 10, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_start_5th_recursive_indirect() */
#endif /* QAK */

#ifndef QAK

/*-------------------------------------------------------------------------
 * Function:	test_abs_skip_start_block
 *
 * Purpose:	Test inserting object into absolute heap which is too large
 *              for starting block size, which forces root indirect block
 *              creation
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, March 27, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_skip_start_block(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    size_t      obj_size;               /* Size of object */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));
    if(check_stats(fh, &state))
        FAIL_STACK_ERROR

    /*
     * Test inserting object into absolute heap which doesn't fit into starting
     *  block size
     */
    TESTING("inserting object that is too large for starting block");

    obj_size = DBLOCK_SIZE(fh, 0) + 1;
    state.heap_size = cparam->managed.width * DBLOCK_SIZE(fh, 0);
    state.heap_size += cparam->managed.width * DBLOCK_SIZE(fh, 1);
    state.heap_size += cparam->managed.width * DBLOCK_SIZE(fh, 2);
    state.man_size = cparam->managed.width * DBLOCK_SIZE(fh, 0);
    state.man_size += cparam->managed.width * DBLOCK_SIZE(fh, 1);
    state.man_size += cparam->managed.width * DBLOCK_SIZE(fh, 2);
    state.man_alloc_size = DBLOCK_SIZE(fh, 2);
    state.man_free_space = cparam->managed.width * DBLOCK_FREE(fh, 0);
    state.man_free_space += cparam->managed.width * DBLOCK_FREE(fh, 1);
    state.man_free_space += cparam->managed.width * DBLOCK_FREE(fh, 2);
    if(add_obj(fh, dxpl, 10, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_skip_start_block() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_skip_start_block_add_back
 *
 * Purpose:	Test inserting object into absolute heap which is too large
 *              for starting block size, which forces root indirect block
 *              creation, then add object which fits in skipped direct block
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, March 28, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_skip_start_block_add_back(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    size_t      obj_size;               /* Size of object */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));
    if(check_stats(fh, &state))
        FAIL_STACK_ERROR

    /*
     * Test inserting object into absolute heap which doesn't fit into starting
     *  block size
     */
    TESTING("skipping starting block, then adding object back to first block");

    /* Insert object too large for starting block size */
    obj_size = DBLOCK_SIZE(fh, 0) + 1;
    state.heap_size = cparam->managed.width * DBLOCK_SIZE(fh, 0);
    state.heap_size += cparam->managed.width * DBLOCK_SIZE(fh, 1);
    state.heap_size += cparam->managed.width * DBLOCK_SIZE(fh, 2);
    state.man_size = cparam->managed.width * DBLOCK_SIZE(fh, 0);
    state.man_size += cparam->managed.width * DBLOCK_SIZE(fh, 1);
    state.man_size += cparam->managed.width * DBLOCK_SIZE(fh, 2);
    state.man_alloc_size = DBLOCK_SIZE(fh, 2);
    state.man_free_space = cparam->managed.width * DBLOCK_FREE(fh, 0);
    state.man_free_space += cparam->managed.width * DBLOCK_FREE(fh, 1);
    state.man_free_space += cparam->managed.width * DBLOCK_FREE(fh, 2);
    if(add_obj(fh, dxpl, 10, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert an object to fill up the heap block just created */
    obj_size = DBLOCK_FREE(fh, 2) - obj_size;
    if(add_obj(fh, dxpl, 10, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert second "real" object, which should go in earlier direct block */
    state.man_alloc_size += DBLOCK_SIZE(fh, 0);
    if(add_obj(fh, dxpl, 20, SMALL_OBJ_SIZE2, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_skip_start_block_add_back() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_skip_start_block_add_skipped
 *
 * Purpose:	Test inserting object into absolute heap which is too large
 *              for starting block size, which forces root indirect block
 *              creation, then add objects to fill skipped direct blocks
 *              and add another object to start on next "normal" block
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, March 28, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_skip_start_block_add_skipped(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    size_t      obj_size;               /* Size of object */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));
    if(check_stats(fh, &state))
        FAIL_STACK_ERROR

    /*
     * Test inserting object into absolute heap which doesn't fit into starting
     *  block size
     */
    TESTING("skipping starting block, then adding objects to backfill and extend");

    /* Insert object too large for starting block size */
    obj_size = DBLOCK_SIZE(fh, 0) + 1;
    state.heap_size = cparam->managed.width * DBLOCK_SIZE(fh, 0);
    state.heap_size += cparam->managed.width * DBLOCK_SIZE(fh, 1);
    state.heap_size += cparam->managed.width * DBLOCK_SIZE(fh, 2);
    state.man_size = cparam->managed.width * DBLOCK_SIZE(fh, 0);
    state.man_size += cparam->managed.width * DBLOCK_SIZE(fh, 1);
    state.man_size += cparam->managed.width * DBLOCK_SIZE(fh, 2);
    state.man_alloc_size = DBLOCK_SIZE(fh, 2);
    state.man_free_space = cparam->managed.width * DBLOCK_FREE(fh, 0);
    state.man_free_space += cparam->managed.width * DBLOCK_FREE(fh, 1);
    state.man_free_space += cparam->managed.width * DBLOCK_FREE(fh, 2);
    if(add_obj(fh, dxpl, 10, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert an object to fill up the heap block just created */
    obj_size = DBLOCK_FREE(fh, 2) - obj_size;
    if(add_obj(fh, dxpl, 10, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Add rows of blocks to "backfill" direct blocks that were skipped */
    if(fill_row(fh, dxpl, 0, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR
    if(fill_row(fh, dxpl, 1, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert another object, which should extend direct blocks, instead of backfill */
    state.man_alloc_size += DBLOCK_SIZE(fh, 2);
    if(add_obj(fh, dxpl, 20, SMALL_OBJ_SIZE2, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_skip_start_block_add_skipped() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_skip_2nd_block
 *
 * Purpose:	Test inserting object into absolute heap which is small
 *              enough for starting block size, then add object too large
 *              for any blocks in first row of direct blocks, to force
 *              early creation of indirect block (and range of skipped blocks)
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Saturday, April  1, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_skip_2nd_block(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    size_t      obj_size;               /* Size of object */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting first (small) object into absolute heap
     */
    TESTING("insert object to initial block, then add object too large for starting direct blocks");

    /* Insert small object, to create root direct block */
    state.heap_size = DBLOCK_SIZE(fh, 0);
    state.man_size = DBLOCK_SIZE(fh, 0);
    state.man_alloc_size = DBLOCK_SIZE(fh, 0);
    state.man_free_space = DBLOCK_FREE(fh, 0);
    if(add_obj(fh, dxpl, 10, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert large object, to force creation of indirect block and
     * range of skipped blocks that are too small to hold the second object
     */
    obj_size = DBLOCK_SIZE(fh, 0) + 1;
    state.heap_size += (cparam->managed.width - 1) * DBLOCK_SIZE(fh, 0);
    state.heap_size += cparam->managed.width * DBLOCK_SIZE(fh, 1);
    state.heap_size += cparam->managed.width * DBLOCK_SIZE(fh, 2);
    state.man_size += (cparam->managed.width - 1) * DBLOCK_SIZE(fh, 0);
    state.man_size += cparam->managed.width * DBLOCK_SIZE(fh, 1);
    state.man_size += cparam->managed.width * DBLOCK_SIZE(fh, 2);
    state.man_alloc_size += DBLOCK_SIZE(fh, 2);
    state.man_free_space += (cparam->managed.width - 1 )* DBLOCK_FREE(fh, 0);
    state.man_free_space += cparam->managed.width * DBLOCK_FREE(fh, 1);
    state.man_free_space += cparam->managed.width * DBLOCK_FREE(fh, 2);
    if(add_obj(fh, dxpl, 20, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_skip_2nd_block() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_skip_2nd_block_add_skipped
 *
 * Purpose:	Test inserting object into absolute heap which is small
 *              enough for starting block size, then add object too large
 *              for any blocks in first row of direct blocks, to force
 *              early creation of indirect block (and range of skipped blocks).
 *              Then add more objects to fill up remainder of initial direct
 *              block and all the skipped blocks, and one more object (to
 *              start next "normal" block).
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Saturday, April  1, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_skip_2nd_block_add_skipped(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    size_t      obj_size;               /* Size of object */
    fheap_heap_state_t state;           /* State of fractal heap */
    unsigned    v;                      /* Local index variables */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test inserting first (small) object into absolute heap
     */
    TESTING("insert object to initial block, then add object too large for starting direct blocks, then backfill and extend");

    /* Insert small object, to create root direct block */
    state.heap_size = DBLOCK_SIZE(fh, 0);
    state.man_size = DBLOCK_SIZE(fh, 0);
    state.man_alloc_size = DBLOCK_SIZE(fh, 0);
    state.man_free_space = DBLOCK_FREE(fh, 0);
    if(add_obj(fh, dxpl, 10, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert large object, to force creation of indirect block and
     * range of skipped blocks that are too small to hold the second object
     */
    obj_size = DBLOCK_SIZE(fh, 0) + 1;
    state.heap_size += (cparam->managed.width - 1) * DBLOCK_SIZE(fh, 0);
    state.heap_size += cparam->managed.width * DBLOCK_SIZE(fh, 1);
    state.heap_size += cparam->managed.width * DBLOCK_SIZE(fh, 2);
    state.man_size += (cparam->managed.width - 1) * DBLOCK_SIZE(fh, 0);
    state.man_size += cparam->managed.width * DBLOCK_SIZE(fh, 1);
    state.man_size += cparam->managed.width * DBLOCK_SIZE(fh, 2);
    state.man_alloc_size += DBLOCK_SIZE(fh, 2);
    state.man_free_space += (cparam->managed.width - 1 )* DBLOCK_FREE(fh, 0);
    state.man_free_space += cparam->managed.width * DBLOCK_FREE(fh, 1);
    state.man_free_space += cparam->managed.width * DBLOCK_FREE(fh, 2);
    if(add_obj(fh, dxpl, 20, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert an object to fill up the (smaller) heap block just created */
    obj_size = DBLOCK_FREE(fh, 0) - SMALL_OBJ_SIZE1;
    if(add_obj(fh, dxpl, 10, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill remainder of 2 * start size block */
    obj_size = DBLOCK_FREE(fh, 2) - (DBLOCK_SIZE(fh, 0) + 1);
    if(add_obj(fh, dxpl, 20, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert objects to fill remaining rows of the starting block size */

    /* Fill remainder of first row of direct heap blocks up */
    for(v = 0; v < (cparam->managed.width - 1); v++) {
        state.man_alloc_size += DBLOCK_SIZE(fh, 0);
        if(fill_heap(fh, dxpl, 0, SMALL_OBJ_SIZE1, &state, NULL))
            FAIL_STACK_ERROR
    } /* end for */

    /* Fill second row of direct blocks */
    if(fill_row(fh, dxpl, 1, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert one more object, to create new 2 * start size direct block */
    state.man_alloc_size += DBLOCK_SIZE(fh, 2);
    if(add_obj(fh, dxpl, 10, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_skip_2nd_block_add_skipped() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_fill_one_partial_skip_2nd_block_add_skipped
 *
 * Purpose:	Test filling initial direct block, then add object small enough
 *              for initial block size (to create root indirect block), then
 *              add object too large for any blocks in first three rows of
 *              direct blocks, to force extension of indirect block (and range
 *              of skipped blocks).
 *
 *              Then add more objects to fill up remainder of partial direct
 *              block and all the skipped blocks, and one more object (to
 *              start next "normal" block).
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, April  3, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_fill_one_partial_skip_2nd_block_add_skipped(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    size_t      obj_size;               /* Size of object */
    fheap_heap_state_t state;           /* State of fractal heap */
    unsigned    u;                      /* Local index variable */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test absolute heap
     */
    TESTING("skipping blocks with indirect root, then backfill and extend");

    /* Fill initial direct block */
    state.heap_size = DBLOCK_SIZE(fh, 0);
    state.man_size = DBLOCK_SIZE(fh, 0);
    state.man_alloc_size = DBLOCK_SIZE(fh, 0);
    state.man_free_space = DBLOCK_FREE(fh, 0);
    if(fill_heap(fh, dxpl, 0, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert small object, to create root indirect block */
    state.heap_size += (cparam->managed.width - 1) * DBLOCK_SIZE(fh, 0);
    state.man_size += (cparam->managed.width - 1) * DBLOCK_SIZE(fh, 0);
    state.man_alloc_size += DBLOCK_SIZE(fh, 0);
    state.man_free_space += (cparam->managed.width - 1) * DBLOCK_FREE(fh, 0);
    if(add_obj(fh, dxpl, 10, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert large object, to force creation of indirect block and
     * range of skipped blocks that are too small to hold the large object
     */
    obj_size = DBLOCK_SIZE(fh, 2) + 1;
    state.heap_size += cparam->managed.width * DBLOCK_SIZE(fh, 1);
    state.heap_size += cparam->managed.width * DBLOCK_SIZE(fh, 2);
    state.heap_size += cparam->managed.width * DBLOCK_SIZE(fh, 3);
    state.man_size += cparam->managed.width * DBLOCK_SIZE(fh, 1);
    state.man_size += cparam->managed.width * DBLOCK_SIZE(fh, 2);
    state.man_size += cparam->managed.width * DBLOCK_SIZE(fh, 3);
    state.man_alloc_size += DBLOCK_SIZE(fh, 3);
    state.man_free_space += cparam->managed.width * DBLOCK_FREE(fh, 1);
    state.man_free_space += cparam->managed.width * DBLOCK_FREE(fh, 2);
    state.man_free_space += cparam->managed.width * DBLOCK_FREE(fh, 3);
    if(add_obj(fh, dxpl, 10, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert an object to fill up the (smaller) heap block just created */
    obj_size = DBLOCK_FREE(fh, 0) - SMALL_OBJ_SIZE1;
    if(add_obj(fh, dxpl, 10, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert object to fill remainder of 4 * start size block */
    obj_size = DBLOCK_FREE(fh, 3) - (DBLOCK_SIZE(fh, 2) + 1);
    if(add_obj(fh, dxpl, 10, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert objects to fill remaining heaps in first row */
    for(u = 0; u < (cparam->managed.width - 2); u++) {
        /* Fill a direct heap block up */
        state.man_alloc_size += DBLOCK_SIZE(fh, 0);
        if(fill_heap(fh, dxpl, 0, SMALL_OBJ_SIZE1, &state, NULL))
            FAIL_STACK_ERROR
    } /* end for */

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert objects to fill remaining heaps in second row */
    if(fill_row(fh, dxpl, 1, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert objects to fill remaining heaps in third row */
    if(fill_row(fh, dxpl, 2, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert one more object, to create new 4 * start size direct block */
    state.man_alloc_size += DBLOCK_SIZE(fh, 3);
    if(add_obj(fh, dxpl, 10, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_fill_one_partial_skip_2nd_block_add_skipped() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_fill_row_skip_add_skipped
 *
 * Purpose:	Test filling first row of direct blocks, then
 *              add object too large for any blocks in first three rows of
 *              direct blocks, to force extension of indirect block (and range
 *              of skipped blocks).
 *
 *              Then add more objects to fill up remainder of partial direct
 *              block and all the skipped blocks, and one more object (to
 *              start next "normal" block).
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, May 15, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_fill_row_skip_add_skipped(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    size_t      obj_size;               /* Size of object */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test absolute heap
     */
    TESTING("filling first row, then skipping rows, then backfill and extend");

    /* Fill first row of direct blocks */
    if(fill_root_row(fh, dxpl, 0, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert large object, to force creation of indirect block and
     * range of skipped blocks that are too small to hold the large object
     */
    obj_size = DBLOCK_SIZE(fh, 2) + 1;
    state.heap_size += cparam->managed.width * DBLOCK_SIZE(fh, 1);
    state.heap_size += cparam->managed.width * DBLOCK_SIZE(fh, 2);
    state.heap_size += cparam->managed.width * DBLOCK_SIZE(fh, 3);
    state.man_size += cparam->managed.width * DBLOCK_SIZE(fh, 1);
    state.man_size += cparam->managed.width * DBLOCK_SIZE(fh, 2);
    state.man_size += cparam->managed.width * DBLOCK_SIZE(fh, 3);
    state.man_alloc_size += DBLOCK_SIZE(fh, 3);
    state.man_free_space += cparam->managed.width * DBLOCK_FREE(fh, 1);
    state.man_free_space += cparam->managed.width * DBLOCK_FREE(fh, 2);
    state.man_free_space += cparam->managed.width * DBLOCK_FREE(fh, 3);
    if(add_obj(fh, dxpl, 20, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert object to fill remainder of 4 * start size block */
    obj_size = DBLOCK_FREE(fh, 3) - obj_size;
    if(add_obj(fh, dxpl, 20, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert objects to fill remaining heaps in second row */
    if(fill_row(fh, dxpl, 1, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert objects to fill remaining heaps in third row */
    if(fill_row(fh, dxpl, 2, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert one more object, to create new 4 * start size direct block */
    state.man_alloc_size += DBLOCK_SIZE(fh, 3);
    if(add_obj(fh, dxpl, 10, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_fill_row_skip_add_skipped() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_fill_direct_skip_indirect_start_block_add_skipped
 *
 * Purpose:	Test filling all direct blocks in root indirect block, then
 *              add object too large for initial block in first row of direct
 *              blocks in indirect block, to force extension of non-root
 *              indirect block (and range of skipped blocks).
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, April  3, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_fill_direct_skip_indirect_start_block_add_skipped(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    size_t      obj_size;               /* Size of object */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test absolute heap
     */
    TESTING("filling direct blocks and skipping blocks in non-root indirect block, then backfill and extend");

    /* Fill direct blocks in root indirect block */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert large object, to force creation of indirect block and
     * range of skipped blocks that are too small to hold the large object
     */
    obj_size = DBLOCK_SIZE(fh, 2) + 1;
    state.man_alloc_size += DBLOCK_SIZE(fh, 3);
    if(add_obj(fh, dxpl, 20, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Add rows of blocks to "backfill" direct blocks that were skipped */
    if(fill_row(fh, dxpl, 0, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR
    if(fill_row(fh, dxpl, 1, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert an object to fill up the (biggest) heap block created */
    obj_size = DBLOCK_FREE(fh, 3) - obj_size;
    if(add_obj(fh, dxpl, 20, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill direct block heaps with 2 * initial block size in nested indirect block */
    if(fill_row(fh, dxpl, 2, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert one more object, to create new 4 * start size direct block */
    obj_size = SMALL_OBJ_SIZE1;
    state.man_alloc_size += DBLOCK_SIZE(fh, 3);
    if(add_obj(fh, dxpl, 10, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_fill_direct_skip_indirect_start_block_add_skipped() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_fill_direct_skip_2nd_indirect_start_block_add_skipped
 *
 * Purpose:	Test filling all direct blocks in root indirect block, then
 *              add object too large for all direct blocks in first row of 
 *              indirect blocks, to force skipping a row of indirect blocks
 *              (and range of skipped blocks), then backfill all direct blocks
 *              skipped and extend to next "normal" direct block.
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Monday, April  3, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_fill_direct_skip_2nd_indirect_start_block_add_skipped(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    unsigned    num_first_indirect_rows;        /* Number of rows (of direct blocks) in each of the first indirect blocks */
    unsigned    row;                    /* Current row in indirect block */
    size_t      obj_size;               /* Size of object */
    fheap_heap_state_t state;           /* State of fractal heap */
    unsigned    u;                      /* Local index variable */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /* Retrieve info about heap */
    num_first_indirect_rows = IBLOCK_MAX_DROWS(fh, 1);
#ifdef QAK
HDfprintf(stderr, "num_first_indirect_rows = %u\n", num_first_indirect_rows);
#endif /* QAK */

    /*
     * Test absolute heap
     */
    TESTING("filling direct blocks and skipping row of non-root indirect blocks, then backfill and extend");

    /* Fill direct blocks in root indirect block */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert large object, to force creation of indirect block and
     * range of skipped (indirect) blocks that are too small to hold the large
     * object
     */
    obj_size = DBLOCK_SIZE(fh, num_first_indirect_rows - 1) + 1;
#ifdef QAK
HDfprintf(stderr, "obj_size = %Zu\n", obj_size);
#endif /* QAK */
    state.man_alloc_size += DBLOCK_SIZE(fh, num_first_indirect_rows);
    if(add_obj(fh, dxpl, 20, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert object to fill space in (large) block created */
    obj_size = DBLOCK_FREE(fh, num_first_indirect_rows) - obj_size;
    if(add_obj(fh, dxpl, 20, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill all rows of direct blocks that are smaller than large object's block size */
    for(row = 0; row < num_first_indirect_rows; row++) {
        /* Fill rows of direct blocks in skipped indirect blocks */
        for(u = 0; u < cparam->managed.width; u++)
            if(fill_row(fh, dxpl, row, SMALL_OBJ_SIZE1, &state, NULL))
                FAIL_STACK_ERROR

        /* Fill row of direct blocks in largest (i.e. non-skipped) indirect block */
        if(fill_row(fh, dxpl, row, SMALL_OBJ_SIZE1, &state, NULL))
            FAIL_STACK_ERROR
    } /* end for */

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Add one more object, to create another "large" block */
    obj_size = SMALL_OBJ_SIZE1;
    state.man_alloc_size += DBLOCK_SIZE(fh, num_first_indirect_rows);
    if(add_obj(fh, dxpl, 10, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_fill_direct_skip_2nd_indirect_start_block_add_skipped() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_fill_2nd_direct_less_one_wrap_start_block_add_skipped
 *
 * Purpose:	Test filling all direct blocks in root indirect block and all
 *              direct blocks in 2nd level indirect blocks, except the last
 *              one, then insert object insert object that is too large to
 *              hold in row of 2nd level indirect blocks (forcing the use of
 *              the next row of 2nd level blocks), then backfill all skipped
 *              direct blocks & extend.
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, April 18, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_fill_2nd_direct_less_one_wrap_start_block_add_skipped(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    unsigned    num_first_indirect_rows;        /* Number of rows (of direct blocks) in each of the first indirect blocks */
    size_t      obj_size;               /* Size of object */
    fheap_heap_state_t state;           /* State of fractal heap */
    unsigned    u;                      /* Local index variables */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /* Retrieve info about heap */
    num_first_indirect_rows = IBLOCK_MAX_DROWS(fh, 1);
#ifdef QAK
HDfprintf(stderr, "num_first_indirect_rows = %u\n", num_first_indirect_rows);
#endif /* QAK */

    /*
     * Test absolute heap
     */
    TESTING("filling direct blocks, filling 2nd level indirect blocks, except last one, and insert object too large for 2nd level indirect blocks, then backfill and extend");

    /* Fill direct blocks in root indirect block */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill first row (except one) of 2nd level indirect blocks */
    for(u = 0; u < cparam->managed.width - 1; u++)
        /* Fill all rows of 2nd level indirect blocks in root block */
        if(fill_2nd_indirect(fh, dxpl, 1, SMALL_OBJ_SIZE1, &state, NULL))
            FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert large object, to force creation of indirect block and
     * range of skipped (indirect) blocks that are too small to hold the large
     * object
     */
    obj_size = DBLOCK_SIZE(fh, num_first_indirect_rows - 1) + 1;
#ifdef QAK
HDfprintf(stderr, "obj_size = %Zu\n", obj_size);
#endif /* QAK */
    state.man_alloc_size += DBLOCK_SIZE(fh, num_first_indirect_rows);
    if(add_obj(fh, dxpl, 20, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert object to fill space in (large) block created */
    obj_size = DBLOCK_FREE(fh, num_first_indirect_rows) - obj_size;
    if(add_obj(fh, dxpl, 20, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill rows skipped over in 2nd level indirect block's direct blocks
     * (and rows of next 2nd level indirect block's direct blocks)
     */
    for(u = 0; u < num_first_indirect_rows; u++) {
        /* Direct block rows in skipped 2nd level indirect block */
        if(fill_row(fh, dxpl, u, SMALL_OBJ_SIZE1, &state, NULL))
            FAIL_STACK_ERROR

        /* Direct block row in current 2nd level indirect block */
        if(fill_row(fh, dxpl, u, SMALL_OBJ_SIZE1, &state, NULL))
            FAIL_STACK_ERROR
    } /* end for */

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Add one more object, to create another "large" block */
    obj_size = SMALL_OBJ_SIZE1;
    state.man_alloc_size += DBLOCK_SIZE(fh, num_first_indirect_rows);
    if(add_obj(fh, dxpl, 10, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_fill_2nd_direct_less_one_wrap_start_block_add_skipped() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_fill_direct_skip_2nd_indirect_skip_2nd_block_add_skipped
 *
 * Purpose:	Test filling all direct blocks in root indirect block, then
 *              add object too large for all direct blocks in first row of 
 *              indirect blocks, to force skipping a row of indirect blocks
 *              (and range of skipped blocks), then add object that is too
 *              large for initial block size in skipped indirect blocks, then
 *              backfill all direct blocks and extend to next "normal" direct
 *              block (but insert first block of backfilling with object
 *              too large for initial block size in skipped indirect block
 *              row's direct blocks).
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, April 11, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_fill_direct_skip_2nd_indirect_skip_2nd_block_add_skipped(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    unsigned    num_first_indirect_rows;        /* Number of rows (of direct blocks) in each of the first indirect blocks */
    unsigned    row;                    /* Current row in indirect block */
    size_t      obj_size;               /* Size of object */
    fheap_heap_state_t state;           /* State of fractal heap */
    unsigned    u;                      /* Local index variable */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /* Retrieve info about heap */
    num_first_indirect_rows = IBLOCK_MAX_DROWS(fh, 1);
#ifdef QAK
HDfprintf(stderr, "num_first_indirect_rows = %u\n", num_first_indirect_rows);
#endif /* QAK */

    /*
     * Test absolute heap
     */
    TESTING("filling direct blocks and skipping row of non-root indirect blocks, then skip row of direct blocks, then backfill and extend");

    /* Fill direct blocks in root indirect block */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert large object, to force creation of indirect block and
     * range of skipped (indirect) blocks that are too small to hold the large
     * object
     */
    obj_size = DBLOCK_SIZE(fh, num_first_indirect_rows - 1) + 1;
#ifdef QAK
HDfprintf(stderr, "obj_size = %Zu\n", obj_size);
#endif /* QAK */
    state.man_alloc_size += DBLOCK_SIZE(fh, num_first_indirect_rows);
    if(add_obj(fh, dxpl, 20, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert object to fill space in (large) block created */
    obj_size = DBLOCK_FREE(fh, num_first_indirect_rows) - obj_size;
    if(add_obj(fh, dxpl, 20, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert object too large for initial block size in skipped indirect blocks */
    obj_size = DBLOCK_SIZE(fh, 3) + 1;
#ifdef QAK
HDfprintf(stderr, "obj_size = %Zu\n", obj_size);
#endif /* QAK */
    state.man_alloc_size += DBLOCK_SIZE(fh, 4);
    if(add_obj(fh, dxpl, 10, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert object to fill space in (medium) block just created */
    obj_size = DBLOCK_FREE(fh, 4) - obj_size;
#ifdef QAK
HDfprintf(stderr, "obj_size = %Zu\n", obj_size);
#endif /* QAK */
    if(add_obj(fh, dxpl, 20, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Finish off blocks in row of medium block size (just to make row filling easier below) */
    obj_size = DBLOCK_FREE(fh, 4);
    for(u = 1; u < cparam->managed.width; u++) {
        state.man_alloc_size += DBLOCK_SIZE(fh, 4);
        if(add_obj(fh, dxpl, 20, obj_size, &state, NULL))
            FAIL_STACK_ERROR
    } /* end for */

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill all rows of direct blocks that are smaller than large object's block size */
    for(row = 0; row < num_first_indirect_rows; row++) {
        /* Fill rows of direct blocks in skipped indirect blocks */
        for(u = 0; u < cparam->managed.width; u++)
            if(fill_row(fh, dxpl, row, SMALL_OBJ_SIZE1, &state, NULL))
                FAIL_STACK_ERROR

        /* Fill row of direct blocks in largest (i.e. non-skipped) indirect block */
        /* (Skip the row of blocks filled above) */
        if(row != 4)
            if(fill_row(fh, dxpl, row, SMALL_OBJ_SIZE1, &state, NULL))
                FAIL_STACK_ERROR
    } /* end while */

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Add one more object, to create another "large" block */
    obj_size = SMALL_OBJ_SIZE1;
    state.man_alloc_size += DBLOCK_SIZE(fh, num_first_indirect_rows);
    if(add_obj(fh, dxpl, 10, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_fill_direct_skip_2nd_indirect_skip_2nd_block_add_skipped() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_fill_direct_skip_indirect_two_rows_add_skipped
 *
 * Purpose:	Test filling all direct blocks in root indirect block, then
 *              add object too large for initial block in first two rows of
 *              indirect blocks, to force extension of non-root
 *              indirect block (and range of skipped blocks).
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Saturday, April 15, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_fill_direct_skip_indirect_two_rows_add_skipped(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    unsigned    num_first_indirect_rows;        /* Number of rows (of direct blocks) in each of the first indirect blocks */
    unsigned    max_dblock_rows;        /* Max. # of rows (of direct blocks) in the root indirect block */
    size_t      obj_size;               /* Size of object */
    fheap_heap_state_t state;           /* State of fractal heap */
    unsigned    u, v;                   /* Local index variables */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /* Retrieve info about heap */
    num_first_indirect_rows = IBLOCK_MAX_DROWS(fh, 1);
    max_dblock_rows = DTABLE_MAX_DROWS(fh);

    /*
     * Test absolute heap
     */
    TESTING("filling direct blocks and skipping two rows of root indirect block, then backfill and extend");

    /* Fill direct blocks in root indirect block */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert large object, to force creation of indirect block and
     * range of skipped blocks that are too small to hold the large object
     */
    obj_size = DBLOCK_SIZE(fh, max_dblock_rows - 2) + 1;
    state.man_alloc_size += DBLOCK_SIZE(fh, max_dblock_rows - 1);
    if(add_obj(fh, dxpl, 20, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert an object to fill up the (biggest) heap block created */
    obj_size = DBLOCK_FREE(fh, max_dblock_rows - 1) - obj_size;
    if(add_obj(fh, dxpl, 20, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill rows skipped over in indirect block's direct blocks */
    for(u = 0; u < num_first_indirect_rows; u++) {
        /* Direct block rows in first row of skipped 2nd level indirect blocks */
        for(v = 0; v < cparam->managed.width; v++)
            if(fill_row(fh, dxpl, u, SMALL_OBJ_SIZE1, &state, NULL))
                FAIL_STACK_ERROR

        /* Direct block rows in second row of skipped 2nd level indirect blocks */
        for(v = 0; v < cparam->managed.width; v++)
            if(fill_row(fh, dxpl, u, SMALL_OBJ_SIZE1, &state, NULL))
                FAIL_STACK_ERROR

        /* Direct block row in used 2nd level indirect block */
        if(fill_row(fh, dxpl, u, SMALL_OBJ_SIZE1, &state, NULL))
            FAIL_STACK_ERROR
    } /* end for */

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill rows in second row of skipped 2nd level indirect blocks (and used 2nd level block) */

    /* Direct block rows in skipped 2nd level indirect blocks */
    for(v = 0; v < cparam->managed.width; v++)
        if(fill_row(fh, dxpl, num_first_indirect_rows, SMALL_OBJ_SIZE1, &state, NULL))
            FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Direct block row in used 2nd level indirect block */
    if(fill_row(fh, dxpl, num_first_indirect_rows, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Add one more object, to create another "large" block */
    obj_size = SMALL_OBJ_SIZE1;
    state.man_alloc_size += DBLOCK_SIZE(fh, max_dblock_rows - 1);
    if(add_obj(fh, dxpl, 10, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);

error:
    H5E_BEGIN_TRY {
        if(fh)
            H5HF_close(fh, dxpl);
	H5Fclose(file);
    } H5E_END_TRY;
    return(1);
} /* test_abs_fill_direct_skip_indirect_two_rows_add_skipped() */


/*-------------------------------------------------------------------------
 * Function:	test_abs_fill_2nd_direct_skip_start_block_add_skipped
 *
 * Purpose:	Test filling all direct blocks in root indirect block and all
 *              direct blocks in 2nd level indirect blocks, the insert object
 *              that is too large to hold in first row of direct blocks of
 *              3rd level indirect block, then backfill & extend all skipped
 *              3rd level indirect block's direct blocks.
 *
 * Return:	Success:	0
 *
 *		Failure:	1
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, April 11, 2006
 *
 *-------------------------------------------------------------------------
 */
static int
test_abs_fill_2nd_direct_skip_start_block_add_skipped(hid_t fapl, H5HF_create_t *cparam, fheap_test_param_t *tparam)
{
    hid_t	file = -1;              /* File ID */
    hid_t       dxpl = H5P_DATASET_XFER_DEFAULT;     /* DXPL to use */
    char	filename[1024];         /* Filename to use */
    H5F_t	*f = NULL;              /* Internal file object pointer */
    H5HF_t      *fh = NULL;             /* Fractal heap wrapper */
    haddr_t     fh_addr;                /* Address of fractal heap */
    size_t      id_len;                 /* Size of fractal heap IDs */
    size_t      obj_size;               /* Size of object */
    fheap_heap_state_t state;           /* State of fractal heap */

    /* Set the filename to use for this test (dependent on fapl) */
    h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));

    /* Create the file to work on */
    if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
        TEST_ERROR

    /* Get a pointer to the internal file object */
    if(NULL == (f = H5I_object(file)))
        STACK_ERROR

    /* Create absolute heap */
    if(NULL == (fh = H5HF_create(f, H5P_DATASET_XFER_DEFAULT, cparam)))
        FAIL_STACK_ERROR
    if(H5HF_get_id_len(fh, &id_len) < 0)
        FAIL_STACK_ERROR
    if(id_len > HEAP_ID_LEN)
        FAIL_STACK_ERROR
    if(H5HF_get_heap_addr(fh, &fh_addr) < 0)
        FAIL_STACK_ERROR
    if(!H5F_addr_defined(fh_addr))
        FAIL_STACK_ERROR
    HDmemset(&state, 0, sizeof(fheap_heap_state_t));

    /*
     * Test absolute heap
     */
    TESTING("filling direct blocks, filling 2nd level indirect blocks, and skip first rows of direct blocks of 3rd level indirect block, then backfill and extend");

    /* Fill direct blocks in root indirect block */
    if(fill_root_direct(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill all rows of 2nd level indirect blocks */
    if(fill_all_2nd_indirect_rows(fh, dxpl, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert large object, to force creation of indirect block and
     * range of skipped (indirect) blocks that are too small to hold the large
     * object
     */
    obj_size = DBLOCK_SIZE(fh, 2) + 1;
    state.man_alloc_size += DBLOCK_SIZE(fh, 3);
    if(add_obj(fh, dxpl, 10, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Insert object to fill space in (large) block created */
    obj_size = DBLOCK_FREE(fh, 3) - obj_size;
    if(add_obj(fh, dxpl, 20, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Fill rows skipped over in 3rd level indirect block's direct blocks */
    if(fill_row(fh, dxpl, 0, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR
    if(fill_row(fh, dxpl, 1, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR
    if(fill_row(fh, dxpl, 2, SMALL_OBJ_SIZE1, &state, NULL))
        FAIL_STACK_ERROR

    /* Check for closing & re-opening the heap */
    if(tparam->reopen_heap) {
        /* Close heap */
        if(H5HF_close(fh, dxpl) < 0)
            TEST_ERROR

        /* Re-open heap */
        if(NULL == (fh = H5HF_open(f, dxpl, fh_addr)))
            FAIL_STACK_ERROR
    } /* end if */

    /* Add one more object, to create another "large" block */
    obj_size = SMALL_OBJ_SIZE1;
    state.man_alloc_size += DBLOCK_SIZE(fh, 3);
    if(add_obj(fh, dxpl, 10, obj_size, &state, NULL))
        FAIL_STACK_ERROR

    PASSED()

    /* Close the fractal heap */
    if(H5HF_close(fh, dxpl) < 0)
        TEST_ERROR

    /* Close the file */
    if(H5Fclose(file) < 0)
        TEST_ERROR

    /* All tests passed */
    return(0);