summaryrefslogtreecommitdiffstats
path: root/test/accum.c
blob: d298aec43c82af0aaccd079b90feb1a5b103cae0 (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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * 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 COPYING file, which can be found at the root of the source code       *
 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
 * If you do not have access to either file, you may request a copy from     *
 * help@hdfgroup.org.                                                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/* Programmer:  Mike McGreevy
 *              October 7, 2010
 */
#include "h5test.h"

#define H5F_PACKAGE
#include "H5Fpkg.h"
#include "H5FDprivate.h"
#include "H5Iprivate.h"

/* Filename */
#define FILENAME "accum.h5"

/* "big" I/O test values */
#define BIG_BUF_SIZE (6 * 1024 * 1024)

/* Random I/O test values */
#define RANDOM_BUF_SIZE (1 * 1024 * 1024)
#define MAX_RANDOM_SEGMENTS (5 * 1024)
#define RAND_SEG_LEN    (1024)
#define RANDOM_BASE_OFF (1024 * 1024)

/* Make file global to all tests */
H5F_t * f = NULL;

/* Function Prototypes */
unsigned test_write_read(const H5F_io_info_t *fio_info);
unsigned test_write_read_nonacc_front(const H5F_io_info_t *fio_info);
unsigned test_write_read_nonacc_end(const H5F_io_info_t *fio_info);
unsigned test_accum_overlap(const H5F_io_info_t *fio_info);
unsigned test_accum_overlap_clean(const H5F_io_info_t *fio_info);
unsigned test_accum_overlap_size(const H5F_io_info_t *fio_info);
unsigned test_accum_non_overlap_size(const H5F_io_info_t *fio_info);
unsigned test_accum_adjust(const H5F_io_info_t *fio_info);
unsigned test_read_after(const H5F_io_info_t *fio_info);
unsigned test_free(const H5F_io_info_t *fio_info);
unsigned test_big(const H5F_io_info_t *fio_info);
unsigned test_random_write(const H5F_io_info_t *fio_info);

/* Helper Function Prototypes */
void accum_printf(void);

/* Private Test H5Faccum Function Wrappers */
#define accum_write(a,s,b) H5F_block_write(f, H5FD_MEM_DEFAULT, (haddr_t)(a), (size_t)(s), H5P_DATASET_XFER_DEFAULT, (b))
#define accum_read(a,s,b)  H5F_block_read(f, H5FD_MEM_DEFAULT, (haddr_t)(a), (size_t)(s), H5P_DATASET_XFER_DEFAULT, (b))
#define accum_free(fio_info,a,s)  H5F__accum_free(fio_info, H5FD_MEM_DEFAULT, (haddr_t)(a), (hsize_t)(s))
#define accum_flush(fio_info)   H5F__accum_flush(fio_info)
#define accum_reset(fio_info)   H5F__accum_reset(fio_info, TRUE)

/* ================= */
/* Main Test Routine */
/* ================= */


/*-------------------------------------------------------------------------
 * Function:    main
 * 
 * Purpose:     Test the metadata accumulator code
 * 
 * Return:      Success: SUCCEED
 *              Failure: FAIL
 * 
 * Programmer:  Mike McGreevy
 *              October 7, 2010
 *
 *-------------------------------------------------------------------------
 */
int
main(void)
{
    H5F_io_info_t fio_info;             /* I/O info for operation */
    unsigned nerrors = 0;        /* track errors */
    hid_t fid = -1;

    /* Test Setup */
    puts("Testing the metadata accumulator");

    /* Create a test file */
    if((fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR

    /* Get H5F_t * to internal file structure */
    if(NULL == (f = (H5F_t *)H5I_object(fid))) FAIL_STACK_ERROR

    /* We'll be writing lots of garbage data, so extend the
        file a ways. 10MB should do. */
    if(H5FD_set_eoa(f->shared->lf, H5FD_MEM_DEFAULT, (haddr_t)(1024*1024*10)) < 0) FAIL_STACK_ERROR

    /* Set up I/O info for operation */
    fio_info.f = f;
    if(NULL == (fio_info.dxpl = (H5P_genplist_t *)H5I_object(H5P_DATASET_XFER_DEFAULT))) FAIL_STACK_ERROR

    /* Reset metadata accumulator for the file */
    if(accum_reset(&fio_info) < 0) FAIL_STACK_ERROR

    /* Test Functions */
    nerrors += test_write_read(&fio_info);
    nerrors += test_write_read_nonacc_front(&fio_info);
    nerrors += test_write_read_nonacc_end(&fio_info);
    nerrors += test_accum_overlap(&fio_info);
    nerrors += test_accum_overlap_clean(&fio_info);
    nerrors += test_accum_overlap_size(&fio_info);
    nerrors += test_accum_non_overlap_size(&fio_info);
    nerrors += test_accum_adjust(&fio_info);
    nerrors += test_read_after(&fio_info);
    nerrors += test_free(&fio_info);
    nerrors += test_big(&fio_info);
    nerrors += test_random_write(&fio_info);

    /* End of test code, close and delete file */
    if(H5Fclose(fid) < 0) TEST_ERROR
    HDremove(FILENAME);

    if(nerrors)
        goto error;
    puts("All metadata accumulator tests passed.");

    return 0;

error: 
    puts("*** TESTS FAILED ***");
    return 1;
} /* end main() */

/* ============================= */
/* Individual Unit Test Routines */
/* ============================= */


/*-------------------------------------------------------------------------
 * Function:    test_write_read
 * 
 * Purpose:     Simple test to write to then read from metadata accumulator.
 * 
 * Return:      Success: SUCCEED
 *              Failure: FAIL
 * 
 * Programmer:  Mike McGreevy
 *              October 7, 2010
 *
 *-------------------------------------------------------------------------
 */
unsigned
test_write_read(const H5F_io_info_t *fio_info)
{
    int i = 0;
    int *write_buf, *read_buf;

    TESTING("simple write/read to/from metadata accumulator");

    /* Allocate buffers */
    write_buf = (int *)HDmalloc(1024 * sizeof(int));
    HDassert(write_buf);
    read_buf = (int *)HDcalloc(1024, sizeof(int));
    HDassert(read_buf);

    /* Fill buffer with data, zero out read buffer */
    for(i = 0; i < 1024; i++)
        write_buf[i] = i + 1;

    /* Do a simple write/read/verify of data */
    /* Write 1KB at Address 0 */
    if(accum_write(0, 1024, write_buf) < 0) FAIL_STACK_ERROR;
    if(accum_read(0, 1024, read_buf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(write_buf, read_buf, 1024) != 0) TEST_ERROR;

    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;

    PASSED();

    /* Release memory */
    HDfree(write_buf);
    HDfree(read_buf);

    return 0;

error:
    /* Release memory */
    HDfree(write_buf);
    HDfree(read_buf);

    return 1;
} /* test_write_read */ 


/*-------------------------------------------------------------------------
 * Function:    test_write_read_nonacc_front
 * 
 * Purpose:     Simple test to write to then read from before metadata accumulator.
 * 
 * Return:      Success: SUCCEED
 *              Failure: FAIL
 * 
 * Programmer:  Allen Byrne
 *              October 8, 2010
 *
 *-------------------------------------------------------------------------
 */
unsigned
test_write_read_nonacc_front(const H5F_io_info_t *fio_info)
{
    int i = 0;
    int *write_buf, *read_buf;

    TESTING("simple write/read to/from before metadata accumulator");

    /* Allocate buffers */
    write_buf = (int *)HDmalloc(2048 * sizeof(int));
    HDassert(write_buf);
    read_buf = (int *)HDcalloc(2048, sizeof(int));
    HDassert(read_buf);

    /* Fill buffer with data, zero out read buffer */
    for(i = 0; i < 2048; i++)
        write_buf[i] = i + 1;

    /* Do a simple write/read/verify of data */
    /* Write 1KB at Address 0 */
    if(accum_write(0, 1024, write_buf) < 0) FAIL_STACK_ERROR;
    if(accum_flush(fio_info) < 0) FAIL_STACK_ERROR;
    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;
    if(accum_write(1024, 1024, write_buf) < 0) FAIL_STACK_ERROR;
    if(accum_read(0, 1024, read_buf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(write_buf, read_buf, 1024) != 0) TEST_ERROR;

    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;

    PASSED();

    /* Release memory */
    HDfree(write_buf);
    HDfree(read_buf);

    return 0;

error:
    /* Release memory */
    HDfree(write_buf);
    HDfree(read_buf);

    return 1;
} /* test_write_read */ 


/*-------------------------------------------------------------------------
 * Function:    test_write_read_nonacc_end
 * 
 * Purpose:     Simple test to write to then read from after metadata accumulator.
 * 
 * Return:      Success: SUCCEED
 *              Failure: FAIL
 * 
 * Programmer:  Allen Byrne
 *              October 8, 2010
 *
 *-------------------------------------------------------------------------
 */
unsigned
test_write_read_nonacc_end(const H5F_io_info_t *fio_info)
{
    int i = 0;
    int *write_buf, *read_buf;

    TESTING("simple write/read to/from after metadata accumulator");

    /* Allocate buffers */
    write_buf = (int *)HDmalloc(2048 * sizeof(int));
    HDassert(write_buf);
    read_buf = (int *)HDcalloc(2048, sizeof(int));
    HDassert(read_buf);

    /* Fill buffer with data, zero out read buffer */
    for(i = 0; i < 2048; i++)
        write_buf[i] = i + 1;

    /* Do a simple write/read/verify of data */
    /* Write 1KB at Address 0 */
    if(accum_write(1024, 1024, write_buf) < 0) FAIL_STACK_ERROR;
    if(accum_flush(fio_info) < 0) FAIL_STACK_ERROR;
    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;
    if(accum_write(0, 1024, write_buf) < 0) FAIL_STACK_ERROR;
    if(accum_read(1024, 1024, read_buf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(write_buf, read_buf, 1024) != 0) TEST_ERROR;

    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;

    PASSED();

    /* Release memory */
    HDfree(write_buf);
    HDfree(read_buf);

    return 0;

error:
    /* Release memory */
    HDfree(write_buf);
    HDfree(read_buf);

    return 1;
} /* test_write_read */ 


/*-------------------------------------------------------------------------
 * Function:    test_free
 *
 * Purpose:     Simple test to free metadata accumulator.
 * 
 * Return:      Success: SUCCEED
 *              Failure: FAIL
 * 
 * Programmer:  Raymond Lu
 *              October 8, 2010
 *
 *-------------------------------------------------------------------------
 */
unsigned
test_free(const H5F_io_info_t *fio_info)
{
    int i = 0;
    int32_t *wbuf = NULL;
    int32_t *rbuf = NULL;
    int32_t *expect = NULL;

    TESTING("simple freeing metadata accumulator");

    /* Write and free the whole accumulator. */ 
    wbuf = (int32_t *)HDmalloc(256 * sizeof(int32_t));
    HDassert(wbuf);
    rbuf = (int32_t *)HDmalloc(256 * sizeof(int32_t));
    HDassert(rbuf);
    expect = (int32_t *)HDmalloc(256 * sizeof(int32_t));
    HDassert(expect);

    /* Fill buffer with data */
    for(i = 0; i < 256; i++)
        wbuf[i] = (int32_t)(i + 1);

    if(accum_write(0, 256 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;

    if(accum_free(fio_info, 0, 256 * sizeof(int32_t)) < 0) FAIL_STACK_ERROR;

    /* Free an empty accumulator */
    if(accum_free(fio_info, 0, 256 * 1024 * sizeof(int32_t)) < 0) FAIL_STACK_ERROR;

    /* Write second quarter of the accumulator */
    if(accum_write(64 * sizeof(int32_t), 64 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;

    /* Free the second quarter of the accumulator, the requested area 
     * is bigger than the data region on the right side. */
    if(accum_free(fio_info, 64 * sizeof(int32_t), 65 * sizeof(int32_t)) < 0) FAIL_STACK_ERROR;


    /* Write half of the accumulator. */ 
    if(accum_write(0, 128 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;

    /* Free the first block of 4B */
    if(accum_free(fio_info, 0, sizeof(int32_t)) < 0) FAIL_STACK_ERROR;

    /* Check that the accumulator still contains the correct data */
    if(accum_read(1 * sizeof(int32_t), 127 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf + 1, rbuf, 127 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Free the block of 4B at 127*4B */
    if(accum_free(fio_info, 127 * sizeof(int32_t), sizeof(int32_t)) < 0) FAIL_STACK_ERROR;

    /* Check that the accumulator still contains the correct data */
    if(accum_read(1 * sizeof(int32_t), 126 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf + 1, rbuf, 126 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Free the block of 4B at 2*4B */
    if(accum_free(fio_info, 2 * sizeof(int32_t), sizeof(int32_t)) < 0) FAIL_STACK_ERROR;

    /* Check that the accumulator still contains the correct data */
    if(accum_read(1 * sizeof(int32_t), 1 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf + 1, rbuf, 1 * sizeof(int32_t)) != 0) TEST_ERROR;
    if(accum_read(3 * sizeof(int32_t), 124 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf + 3, rbuf, 124 * sizeof(int32_t)) != 0) TEST_ERROR;


    /* Test freeing section that overlaps the start of the accumulator and is
     * entirely before dirty section */
    if(accum_write(64 * sizeof(int32_t), 128 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    HDmemcpy(expect + 64, wbuf, 128 * sizeof(int32_t));
    if(accum_flush(fio_info) < 0) FAIL_STACK_ERROR;
    if(accum_write(68 * sizeof(int32_t), 4 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    HDmemcpy(expect + 68, wbuf, 4 * sizeof(int32_t));
    if(accum_free(fio_info, 62 * sizeof(int32_t), 4 * sizeof(int32_t)) < 0) FAIL_STACK_ERROR;

    /* Check that the accumulator still contains the correct data */
    if(accum_read(66 * sizeof(int32_t), 126 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(expect + 66, rbuf, 126 * sizeof(int32_t)) != 0) TEST_ERROR;


    /* Test freeing section that overlaps the start of the accumulator and
     * completely contains dirty section */
    if(accum_write(64 * sizeof(int32_t), 128 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    HDmemcpy(expect + 64, wbuf, 128 * sizeof(int32_t));
    if(accum_flush(fio_info) < 0) FAIL_STACK_ERROR;
    if(accum_write(68 * sizeof(int32_t), 4 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    HDmemcpy(expect + 68, wbuf, 4 * sizeof(int32_t));
    if(accum_free(fio_info, 62 * sizeof(int32_t), 16 * sizeof(int32_t)) < 0) FAIL_STACK_ERROR;

    /* Check that the accumulator still contains the correct data */
    if(accum_read(78 * sizeof(int32_t), 114 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(expect + 78, rbuf, 114 * sizeof(int32_t)) != 0) TEST_ERROR;


    /* Test freeing section completely contained in accumulator and is entirely
     * before dirty section */
    if(accum_write(64 * sizeof(int32_t), 128 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    HDmemcpy(expect + 64, wbuf, 128 * sizeof(int32_t));
    if(accum_flush(fio_info) < 0) FAIL_STACK_ERROR;
    if(accum_write(72 * sizeof(int32_t), 4 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    HDmemcpy(expect + 72, wbuf, 4 * sizeof(int32_t));
    if(accum_free(fio_info, 66 * sizeof(int32_t), 4 * sizeof(int32_t)) < 0) FAIL_STACK_ERROR;

    /* Check that the accumulator still contains the correct data */
    if(accum_read(70 * sizeof(int32_t), 122 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(expect + 70, rbuf, 122 * sizeof(int32_t)) != 0) TEST_ERROR;


    /* Test freeing section completely contained in accumulator, starts before
     * dirty section, and ends in dirty section */
    if(accum_write(64 * sizeof(int32_t), 128 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    HDmemcpy(expect + 64, wbuf, 128 * sizeof(int32_t));
    if(accum_flush(fio_info) < 0) FAIL_STACK_ERROR;
    if(accum_write(72 * sizeof(int32_t), 4 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    HDmemcpy(expect + 72, wbuf, 4 * sizeof(int32_t));
    if(accum_free(fio_info, 70 * sizeof(int32_t), 4 * sizeof(int32_t)) < 0) FAIL_STACK_ERROR;

    /* Check that the accumulator still contains the correct data */
    if(accum_read(74 * sizeof(int32_t), 118 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(expect + 74, rbuf, 118 * sizeof(int32_t)) != 0) TEST_ERROR;


    /* Test freeing section completely contained in accumulator and completely
     * contains dirty section */
    if(accum_write(64 * sizeof(int32_t), 128 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    HDmemcpy(expect + 64, wbuf, 128 * sizeof(int32_t));
    if(accum_flush(fio_info) < 0) FAIL_STACK_ERROR;
    if(accum_write(72 * sizeof(int32_t), 4 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    HDmemcpy(expect + 72, wbuf, 4 * sizeof(int32_t));
    if(accum_free(fio_info, 70 * sizeof(int32_t), 8 * sizeof(int32_t)) < 0) FAIL_STACK_ERROR;

    /* Check that the accumulator still contains the correct data */
    if(accum_read(78 * sizeof(int32_t), 114 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(expect + 78, rbuf, 114 * sizeof(int32_t)) != 0) TEST_ERROR;


    /* Test freeing section completely contained in accumulator, starts at start
     * of dirty section, and ends in dirty section */
    if(accum_write(64 * sizeof(int32_t), 128 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    HDmemcpy(expect + 64, wbuf, 128 * sizeof(int32_t));
    if(accum_flush(fio_info) < 0) FAIL_STACK_ERROR;
    if(accum_write(72 * sizeof(int32_t), 8 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    HDmemcpy(expect + 72, wbuf, 8 * sizeof(int32_t));
    if(accum_free(fio_info, 72 * sizeof(int32_t), 4 * sizeof(int32_t)) < 0) FAIL_STACK_ERROR;

    /* Check that the accumulator still contains the correct data */
    if(accum_read(76 * sizeof(int32_t), 116 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(expect + 76, rbuf, 116 * sizeof(int32_t)) != 0) TEST_ERROR;

    HDfree(wbuf);
    wbuf = NULL;
    HDfree(rbuf);
    rbuf = NULL;
    HDfree(expect);
    expect = NULL;

    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;

    PASSED();

    return 0;

error:
    if(wbuf)
        HDfree(wbuf);
    if(rbuf)
        HDfree(rbuf);
    if(expect)
        HDfree(expect);

    return 1;
} /* test_free */ 


/*-------------------------------------------------------------------------
 * Function:    test_accum_overlap
 * 
 * Purpose:     This test will write a series of pieces of data
 *              to the accumulator with the goal of overlapping
 *              the writes in various different ways.
 * 
 * Return:      Success: SUCCEED
 *              Failure: FAIL
 * 
 * Programmer:  Mike McGreevy
 *              October 7, 2010
 *
 *-------------------------------------------------------------------------
 */
unsigned
test_accum_overlap(const H5F_io_info_t *fio_info)
{
    int i = 0;
    int32_t *wbuf, *rbuf;

    TESTING("overlapping write to metadata accumulator");

    /* Allocate buffers */
    wbuf = (int32_t *)HDmalloc(4096 * sizeof(int32_t));
    HDassert(wbuf);
    rbuf = (int32_t *)HDcalloc(4096, sizeof(int32_t));
    HDassert(rbuf);

    /* Case 1: No metadata in accumulator */
    /* Write 10 1's at address 40 */
    /* @0:|          1111111111| */
    /* Put some data in the accumulator initially */
    for(i = 0; i < 10; i++)
        wbuf[i] = 1;
    if(accum_write(40, 10 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(40, 10 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 10 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Case 2: End of new piece aligns with start of accumulated data */
    /* Write 5 2's at address 20 */
    /* @0:|     222221111111111| */
    for(i = 0; i < 5; i++)
        wbuf[i] = 2;
    if(accum_write(20, 5 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(20, 5 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 5 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Case 3: Start of new piece aligns with start of accumulated data */
    /* Write 3 3's at address 20 */
    /* @0:|     333221111111111| */
    for(i = 0; i < 3; i++)
        wbuf[i] = 3;
    if(accum_write(20, 3 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(20, 3 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 3 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Case 4: New piece overlaps start of accumulated data */
    /* Write 5 4's at address 8 */
    /* @0:|  444443221111111111| */
    for(i = 0; i < 5; i++)
        wbuf[i] = 4;
    if(accum_write(8, 5 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(8, 5 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 5 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Case 5: New piece completely within accumulated data */
    /* Write 4 5's at address 48 */
    /* @0:|  444443221155551111| */
    for(i = 0; i < 4; i++)
        wbuf[i] = 5;
    if(accum_write(48, 4 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(48, 4 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 4 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Case 6: End of new piece aligns with end of accumulated data */
    /* Write 3 6's at address 68 */
    /* @0:|  444443221155551666| */
    for(i = 0; i < 3; i++)
        wbuf[i] = 6;
    if(accum_write(68, 3 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(68, 3 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 3 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Case 7: New piece overlaps end of accumulated data */
    /* Write 5 7's at address 76 */
    /* @0:|  4444432211555516677777| */
    for(i = 0; i < 5; i++)
        wbuf[i] = 7;
    if(accum_write(76, 5 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(76, 5 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 5 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Case 8: Start of new piece aligns with end of accumulated data */
    /* Write 3 8's at address 96 */
    /* @0:|  4444432211555516677777888| */
    for(i = 0; i < 3; i++)
        wbuf[i] = 8;
    if(accum_write(96, 3 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(96, 3 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 3 * sizeof(int32_t)) != 0) TEST_ERROR;
 
    /* Set up expected data buffer and verify contents of
        accumulator as constructed by cases 1-8, above */    
    for(i = 0; i < 5; i++)
        wbuf[i] = 4;
    for(i = 5; i < 6; i++)
        wbuf[i] = 3;
    for(i = 6; i < 8; i++)
        wbuf[i] = 2;
    for(i = 8; i < 10; i++)
        wbuf[i] = 1;
    for(i = 10; i < 14; i++)
        wbuf[i] = 5;
    for(i = 14; i < 15; i++)
        wbuf[i] = 1;
    for(i = 15; i < 17; i++)
        wbuf[i] = 6;
    for(i = 17; i < 22; i++)
        wbuf[i] = 7;
    for(i = 22; i < 25; i++)
        wbuf[i] = 8;
    if(accum_read(8, 25 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 25 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Case 9: New piece completely before accumulated data */
    /* Write 1 9 at address 0 */
    /* @0:|9 4444432211555516677777888| */
    for(i = 0; i < 1; i++)
        wbuf[i] = 9;
    if(accum_write(0, 1 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(0, 1 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 1 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Case 10: New piece completely after accumulated data */
    /* Write 4 3's at address 116 */
    /* @0:|9 4444432211555516677777888  3333| */
    for(i = 0; i < 4; i++)
        wbuf[i] = 3;
    if(accum_write(116, 4 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(116, 4 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 4 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Case 11: New piece completely overlaps accumulated data */
    /* Write 6 4's at address 112 */
    /* @0:|9 4444432211555516677777888 444444| */
    for(i = 0; i < 6; i++)
        wbuf[i] = 4;
    if(accum_write(112, 6 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(112, 6 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 6 * sizeof(int32_t)) != 0) TEST_ERROR;

    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;

    PASSED();

    /* Release memory */
    HDfree(wbuf);
    HDfree(rbuf);

    return 0;

error:
    /* Release memory */
    HDfree(wbuf);
    HDfree(rbuf);

    return 1;
} /* test_accum_overlap */


/*-------------------------------------------------------------------------
 * Function:    test_accum_overlap_clean
 *
 * Purpose:     This test will write a series of pieces of data
 *              to the accumulator with the goal of overlapping
 *              the writes in various different ways, with clean
 *              areas in the accumulator.
 *
 * Return:      Success: SUCCEED
 *              Failure: FAIL
 *
 * Programmer:  Neil Fortner
 *              October 8, 2010
 *
 *-------------------------------------------------------------------------
 */
unsigned
test_accum_overlap_clean(const H5F_io_info_t *fio_info)
{
    int i = 0;
    int32_t *wbuf, *rbuf;

    TESTING("overlapping write to partially clean metadata accumulator");

    /* Allocate buffers */
    wbuf = (int32_t *)HDmalloc(4096 * sizeof(int32_t));
    HDassert(wbuf);
    rbuf = (int32_t *)HDcalloc(4096, sizeof(int32_t));
    HDassert(rbuf);

    /* Case 1: No metadata in accumulator */
    /* Write 10 1's at address 40 */
    /* @0:|          1111111111| */
    /* Put some data in the accumulator initially */
    for(i = 0; i < 10; i++)
        wbuf[i] = 1;
    if(accum_write(40, 10 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(40, 10 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 10 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Case 2: End of new piece aligns with start of clean accumulated data */
    /* Write 5 2's at address 20 */
    /* @0:|     222221111111111| */
    if(accum_flush(fio_info) < 0) FAIL_STACK_ERROR;
    for(i = 0; i < 5; i++)
        wbuf[i] = 2;
    if(accum_write(20, 5 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(20, 5 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 5 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Case 3: Start of new piece aligns with start of accumulated data,
     * completely encloses dirty section of accumulator */
    /* Write 6 3's at address 20 */
    /* @0:|  333333111111111| */
    for(i = 0; i < 6; i++)
        wbuf[i] = 3;
    if(accum_write(20, 6 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(20, 6 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 6 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Case 4: New piece completely within accumulated data, overlaps
     * end of dirty section of accumulator */
    /* Write 2 4's at address 40 */
    /* @0:|  333334411111111| */
    for(i = 0; i < 2; i++)
        wbuf[i] = 4;
    if(accum_write(40, 2 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(40, 2 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 2 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Case 5: New piece completely within accumulated data, completely
     * after dirty section of accumulator */
    /* Write 2 5's at address 52 */
    /* @0:|  333334415511111| */
    for(i = 0; i < 2; i++)
        wbuf[i] = 5;
    if(accum_write(52, 2 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(52, 2 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 2 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Case 6: New piece completely within clean accumulated data */
    /* Write 3 6's at address 44 */
    /* @0:|  333334666511111| */
    if(accum_flush(fio_info) < 0) FAIL_STACK_ERROR;
    for(i = 0; i < 3; i++)
        wbuf[i] = 6;
    if(accum_write(44, 3 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(44, 3 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 3 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Case 7: New piece overlaps start of clean accumulated data */
    /* Write 2 7's at address 16 */
    /* @0:|  7733334666511111| */
    if(accum_flush(fio_info) < 0) FAIL_STACK_ERROR;
    for(i = 0; i < 2; i++)
        wbuf[i] = 7;
    if(accum_write(16, 2 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(16, 2 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 2 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Case 8: New piece overlaps start of accumulated data, completely
     * encloses dirty section of accumulator */
    /* Write 4 8's at address 12 */
    /* @0:|  88883334666511111| */
    for(i = 0; i < 4; i++)
        wbuf[i] = 8;
    if(accum_write(12, 4 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(12, 4 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 4 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Case 9: Start of new piece aligns with end of clean accumulated data */
    /* Write 3 9's at address 80 */
    /* @0:|  88883334666511111999| */
    if(accum_flush(fio_info) < 0) FAIL_STACK_ERROR;
    for(i = 0; i < 3; i++)
        wbuf[i] = 9;
    if(accum_write(80, 3 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(80, 3 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 3 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Case 10: New piece overlaps end of clean accumulated data */
    /* Write 3 2's at address 88 */
    /* @0:|  888833346665111119922| */
    if(accum_flush(fio_info) < 0) FAIL_STACK_ERROR;
    for(i = 0; i < 2; i++)
        wbuf[i] = 2;
    if(accum_write(88, 2 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(88, 2 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 2 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Case 11: New piece overlaps end of accumulated data, completely encloses
     * dirty section of accumulator */
    /* Write 4 7's at address 84 */
    /* @0:|  8888333466651111197777| */
    for(i = 0; i < 4; i++)
        wbuf[i] = 7;
    if(accum_write(84, 4 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(84, 4 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 4 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Set up expected data buffer and verify contents of
        accumulator as constructed by cases 1-11, above */
    for(i = 0; i < 4; i++)
        wbuf[i] = 8;
    for(i = 4; i < 7; i++)
        wbuf[i] = 3;
    for(i = 7; i < 8; i++)
        wbuf[i] = 4;
    for(i = 8; i < 11; i++)
        wbuf[i] = 6;
    for(i = 11; i < 12; i++)
        wbuf[i] = 5;
    for(i = 12; i < 17; i++)
        wbuf[i] = 1;
    for(i = 17; i < 18; i++)
        wbuf[i] = 9;
    for(i = 18; i < 22; i++)
        wbuf[i] = 7;
    if(accum_read(12, 22 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 22 * sizeof(int32_t)) != 0) TEST_ERROR;

    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;

    PASSED();

    /* Release memory */
    HDfree(wbuf);
    HDfree(rbuf);

    return 0;

error:
    /* Release memory */
    HDfree(wbuf);
    HDfree(rbuf);

    return 1;
} /* test_accum_overlap_clean */


/*-------------------------------------------------------------------------
 * Function:    test_accum_non_overlap_size
 * 
 * Purpose:     This test will write a series of pieces of data
 *              to the accumulator with the goal of not overlapping
 *              the writes with a data size larger then the accum size.
 * 
 * Return:      Success: SUCCEED
 *              Failure: FAIL
 * 
 * Programmer:  Allen Byrne
 *              October 8, 2010
 *
 *-------------------------------------------------------------------------
 */
unsigned
test_accum_non_overlap_size(const H5F_io_info_t *fio_info)
{
    int i = 0;
    int32_t *wbuf, *rbuf;

    TESTING("non-overlapping write to accumulator larger then accum_size");

    /* Allocate buffers */
    wbuf = (int *)HDmalloc(4096 * sizeof(int32_t));
    HDassert(wbuf);
    rbuf = (int *)HDcalloc(4096, sizeof(int32_t));
    HDassert(rbuf);

    /* Case 1: No metadata in accumulator */
    /* Write 10 1's at address 140 */
    /* @0:|     1111111111| */
    /* Put some data in the accumulator initially */
    for(i = 0; i < 10; i++)
        wbuf[i] = 1;
    if(accum_write(140, 10 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(140, 10 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 10 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Case 9: New piece completely before accumulated data */
    /* Write 20 9 at address 0 */
    /* @0:|9   1111111111| */
    for(i = 0; i < 20; i++)
        wbuf[i] = 9;
    if(accum_write(0, 20 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(0, 20 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 20 * sizeof(int32_t)) != 0) TEST_ERROR;

    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;

    PASSED();

    /* Release memory */
    HDfree(wbuf);
    HDfree(rbuf);

    return 0;

error:
    /* Release memory */
    HDfree(wbuf);
    HDfree(rbuf);

    return 1;
} /* test_accum_non_overlap_size */

/*-------------------------------------------------------------------------
 * Function:    test_accum_overlap_size
 *
 * Purpose:     This test will write a series of pieces of data
 *              to the accumulator with the goal of overlapping
 *              the writes with a data size completely overlapping 
 *              the accumulator at both ends.
 *
 * Return:      Success: SUCCEED
 *              Failure: FAIL
 *
 * Programmer:  Allen Byrne
 *              October 8, 2010
 *
 *-------------------------------------------------------------------------
 */
unsigned
test_accum_overlap_size(const H5F_io_info_t *fio_info)
{
    int i = 0;
    int32_t *wbuf, *rbuf;

    TESTING("overlapping write to accumulator larger then accum_size");

    /* Allocate buffers */
    wbuf = (int32_t *)HDmalloc(4096 * sizeof(int32_t));
    HDassert(wbuf);
    rbuf = (int32_t *)HDcalloc(4096, sizeof(int32_t));
    HDassert(rbuf);

    /* Case 1: No metadata in accumulator */
    /* Write 10 1's at address 64 */
    /* @0:|     1111111111| */
    /* Put some data in the accumulator initially */
    for(i = 0; i < 10; i++)
        wbuf[i] = 1;
    if(accum_write(64, 10 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(64, 10 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 10 * sizeof(int32_t)) != 0) TEST_ERROR;

    /* Case 9: New piece completely before accumulated data */
    /* Write 72 9 at address 60  */
    /* @0:|9   1111111111| */
    for(i = 0; i < 72; i++)
        wbuf[i] = 9;
    if(accum_write(60, 72 * sizeof(int32_t), wbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(60, 72 * sizeof(int32_t), rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 72 * sizeof(int32_t)) != 0) TEST_ERROR;

    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;

    PASSED();

    /* Release memory */
    HDfree(wbuf);
    HDfree(rbuf);

    return 0;

error:
    /* Release memory */
    HDfree(wbuf);
    HDfree(rbuf);

    return 1;
} /* test_accum_overlap_size */


/*-------------------------------------------------------------------------
 * Function:    test_accum_adjust
 * 
 * Purpose:     This test examines the various ways the accumulator might
 *              adjust itself as a result of data appending or prepending
 *              to it.
 *
 *              This test program covers all the code in H5F_accum_adjust, 
 *              but NOT all possible paths through said code. It only covers
 *              six potential paths through the function. (Again, though, each
 *              piece of code within an if/else statement in H5F_accum_adjust is
 *              covered by one of the paths in this test function). Since there 
 *              are a ridiculous number of total possible paths through this 
 *              function due to its large number of embedded if/else statements,
 *              that's certainly a lot of different test cases to write by hand. 
 *              (Though if someone comes across this code and has some free 
 *              time, go for it).
 * 
 * Return:      Success: SUCCEED
 *              Failure: FAIL
 * 
 * Programmer:  Mike McGreevy
 *              October 11, 2010
 *
 *-------------------------------------------------------------------------
 */
unsigned
test_accum_adjust(const H5F_io_info_t *fio_info)
{
    int i = 0;
    int s = 1048576;    /* size of buffer */
    int32_t *wbuf, *rbuf;

    TESTING("accumulator adjustments after append/prepend of data");

    /* Allocate buffers */
    wbuf = (int32_t *)HDmalloc((size_t)s * sizeof(int32_t));
    HDassert(wbuf);
    rbuf = (int32_t *)HDcalloc((size_t)s, sizeof(int32_t));
    HDassert(rbuf);

    /* Fill up write buffer */
    for(i = 0; i < s; i++)
        wbuf[i] = i + 1;

    /* ================================================================ */
    /* CASE 1: Prepending small block to large, fully dirty accumulator */
    /* ================================================================ */

    /* Write data to the accumulator to fill it just under 1MB (max size),
     * but not quite full. This will force the accumulator to, on subsequent
     * writes, a) have to adjust since it's nearly full, and b) prevent
     * an increase in size because it's already at it's maximum size */
    if(accum_write((1024 * 1024), (1024 * 1024) - 1, wbuf) < 0) FAIL_STACK_ERROR;

    /* Write a small (1KB) block that prepends to the front of the accumulator. */ 
    /* ==> Accumulator will need more buffer space */
    /* ==> Accumulator will try to resize, but see that it's getting too big */
    /* ==> Size of new block is less than half maximum size of accumulator */
    /* ==> New block is being prepended to accumulator */
    /* ==> Accumulator is dirty, it will be flushed. */
    /* ==> Dirty region overlaps region to eliminate from accumulator */
    if(accum_write((1024 * 1024) - 1024, 1024, wbuf) < 0) FAIL_STACK_ERROR;

    /* Read back and verify first write */
    if(accum_read((1024 * 1024), (1024 * 1024) - 1, rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, (1024 * 1024) - 1) != 0) TEST_ERROR;

    /* Read back and verify second write */
    if(accum_read((1024 * 1024) - 1024, 1024, rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 1024) != 0) TEST_ERROR;
    
    /* Reset accumulator for next case */
    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;

    /* ================================================================ */
    /* Case 2: Prepending large block to large, fully dirty accumulator */
    /* ================================================================ */

    /* Write data to the accumulator to fill it just under 1MB (max size),
     * but not quite full. This will force the accumulator to, on subsequent
     * writes, a) have to adjust since it's nearly full, and b) prevent
     * an increase in size because it's already at it's maximum size */
    if(accum_write((1024 * 1024), (1024 * 1024) - 1, wbuf) < 0) FAIL_STACK_ERROR;

    /* Write a large (just under 1MB) block to the front of the accumulator. */
    /* ==> Accumulator will need more buffer space */
    /* ==> Accumulator will try to resize, but see that it's getting too big */
    /* ==> Size of new block is larger than half maximum size of accumulator */
    /* ==> New block is being prepended to accumulator */
    /* ==> Accumulator is dirty, it will be flushed. */
    /* ==> Dirty region overlaps region to eliminate from accumulator */
    if(accum_write(5, (1024 * 1024) - 5, wbuf) < 0) FAIL_STACK_ERROR;

    /* Read back and verify both pieces of data */
    if(accum_read(1048576, 1048575, rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 1048576) != 0) TEST_ERROR;

    if(accum_read(5, 1048571, rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 1048571) != 0) TEST_ERROR;

    /* Reset accumulator for next case */
    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;

    /* ========================================================= */
    /* Case 3: Appending small block to large, clean accumulator */
    /* ========================================================= */

    /* Write data to the accumulator to fill it just under 1MB (max size),
     * but not quite full. This will force the accumulator to, on subsequent
     * writes, a) have to adjust since it's nearly full, and b) prevent
     * an increase in size because it's already at it's maximum size */
    if(accum_write(0, (1024 * 1024) - 1, wbuf) < 0) FAIL_STACK_ERROR;

    /* Flush the accumulator -- we want to test the case when
        accumulator contains clean data */
    if(accum_flush(fio_info) < 0) FAIL_STACK_ERROR

    /* Write a small (1KB) block to the end of the accumulator */
    /* ==> Accumulator will need more buffer space */
    /* ==> Accumulator will try to resize, but see that it's getting too big */
    /* ==> Size of new block is larger than half maximum size of accumulator */
    /* ==> New block being appended to accumulator */
    /* ==> Accumulator is NOT dirty */
    /* ==> Since we're appending, need to adjust location of accumulator */
    if(accum_write((1024 * 1024) - 1, 1024, wbuf) < 0) FAIL_STACK_ERROR;

    /* Write a piece of metadata outside current accumulator to force write
        to disk */
    if(accum_write(0, 1, wbuf) < 0) FAIL_STACK_ERROR;

    /* Read in the piece we wrote to disk above, and then verify that 
        the data is as expected */
    if(accum_read((1024 * 1024) - 1, 1024, rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 1024) != 0) TEST_ERROR;

    /* Reset accumulator for next case */
    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;

    /* ==================================================================== */
    /* Case 4: Appending small block to large, partially dirty accumulator, */
    /*         with existing dirty region NOT aligning with the new block   */
    /* ==================================================================== */

    /* Write data to the accumulator to fill it just under 1MB (max size),
     * but not quite full. This will force the accumulator to, on subsequent
     * writes, a) have to adjust since it's nearly full, and b) prevent
     * an increase in size because it's already at it's maximum size */
    if(accum_write(0, (1024 * 1024) - 5, wbuf) < 0) FAIL_STACK_ERROR;

    /* Flush the accumulator to clean it */
    if(accum_flush(fio_info) < 0) FAIL_STACK_ERROR

    /* write to part of the accumulator so just the start of it is dirty */
    if(accum_write(0, 5, wbuf) < 0) FAIL_STACK_ERROR;

    /* Write a small (~340KB) piece of data to the other end of the accumulator */
    /* ==> Accumulator will need more buffer space */
    /* ==> Accumulator will try to resize, but see that it's getting too big */
    /* ==> Size of new block is less than than half maximum size of accumulator */
    /* ==> New block being appended to accumulator */
    /* ==> We can slide the dirty region down, to accomodate the request */
    /* ==> Max Buffer Size - (dirty offset + adjust size) >= 2 * size) */ 
    /* ==> Need to adjust location of accumulator while appending */
    /* ==> Accumulator will need to be reallocated */
    if(accum_write(1048571, 349523, wbuf) < 0) FAIL_STACK_ERROR;

    /* Write a piece of metadata outside current accumulator to force write
        to disk */
    if(accum_write(1398900, 1, wbuf) < 0) FAIL_STACK_ERROR;

    /* Read in the piece we wrote to disk above, and then verify that 
        the data is as expected */
    if(accum_read(1048571, 349523, rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 349523) != 0) TEST_ERROR;

    /* Reset accumulator for next case */
    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;

    /* ==================================================================== */
    /* Case 5: Appending small block to large, partially dirty accumulator, */
    /*         with existing dirty region aligning with new block           */
    /* ==================================================================== */

    /* Write data to the accumulator to fill it just under max size (but not full) */
    if(accum_write(0, (1024 * 1024) - 5, wbuf) < 0) FAIL_STACK_ERROR;

    /* Flush the accumulator to clean it */
    if(accum_flush(fio_info) < 0) FAIL_STACK_ERROR

    /* write to part of the accumulator so it's dirty, but not entirely dirty */
    /* (just the begging few bytes will be clean) */
    if(accum_write(10, (1024 * 1024) - 15, wbuf) < 0) FAIL_STACK_ERROR;

    /* Write a small piece of data to the dirty end of the accumulator */
    /* ==> Accumulator will need more buffer space */
    /* ==> Accumulator will try to resize, but see that it's getting too big */
    /* ==> Size of new block is less than than half maximum size of accumulator */
    /* ==> New block being appended to accumulator */
    /* ==> We can slide the dirty region down, to accomodate the request */
    /* ==> Max Buffer Size - (dirty offset + adjust size) < 2 * size) */ 
    /* ==> Need to adjust location of accumulator while appending */
    if(accum_write((1024 * 1024) - 5, 10, wbuf) < 0) FAIL_STACK_ERROR;

    /* Write a piece of metadata outside current accumulator to force write
        to disk */
    if(accum_write(0, 1, wbuf) < 0) FAIL_STACK_ERROR;

    /* Read in the piece we wrote to disk above, and then verify that 
        the data is as expected */
    if(accum_read((1024 * 1024) - 5, 10, rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 10) != 0) TEST_ERROR;

    /* Reset accumulator for next case */
    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;

    /* ================================================================= */
    /* Case 6: Appending small block to large, fully dirty accumulator   */
    /* ================================================================= */

    /* Write data to the accumulator to fill it just under 1MB (max size),
     * but not quite full. This will force the accumulator to, on subsequent
     * writes, a) have to adjust since it's nearly full, and b) prevent
     * an increase in size because it's already at it's maximum size */
    if(accum_write(0, (1024 * 1024) - 5, wbuf) < 0) FAIL_STACK_ERROR;

    /* Write a small (~340KB) piece of data to the end of the accumulator */
    /* ==> Accumulator will need more buffer space */
    /* ==> Accumulator will try to resize, but see that it's getting too big */
    /* ==> Size of new block is less than than half maximum size of accumulator */
    /* ==> New block being appended to accumulator */
    /* ==> We cannot slide dirty region down, it's all dirty */
    /* ==> Dirty region overlaps region to eliminate from accumulator */
    /* ==> Need to adjust location of accumulator while appending */
    if(accum_write(1048571, 349523, wbuf) < 0) FAIL_STACK_ERROR;

    /* Write a piece of metadata outside current accumulator to force write
        to disk */
    if(accum_write(1398900, 1, wbuf) < 0) FAIL_STACK_ERROR;

    /* Read in the piece we wrote to disk above, and then verify that 
        the data is as expected */
    if(accum_read(1048571, 349523, rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 349523) != 0) TEST_ERROR;

    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;

    PASSED();

    /* Release memory */
    HDfree(wbuf);
    HDfree(rbuf);

    return 0;

error:
    /* Release memory */
    HDfree(wbuf);
    HDfree(rbuf);

    return 1;
} /* test_accum_adjust */


/*-------------------------------------------------------------------------
 * Function:    test_read_after
 * 
 * Purpose:     This test will verify the case when metadata is read partly 
 *              from the accumulator and partly from disk.  The test will 
 *              write a block of data at address 512, force the data to be
 *              written to disk, write new data partially overlapping the 
 *              original block from below, then read data at address 512.  
 *              The data read should be partly new and partly original. 
 * 
 * Return:      Success: SUCCEED
 *              Failure: FAIL
 * 
 * Programmer:  Larry Knox
 *              October 8, 2010
 *
 *-------------------------------------------------------------------------
 */
unsigned 
test_read_after(const H5F_io_info_t *fio_info)
{
    int i = 0;
    int s = 128;    /* size of buffer */
    int32_t *wbuf, *rbuf;

    TESTING("reading data from both accumulator and disk");

    /* Allocate buffers */
    wbuf = (int32_t *)HDmalloc((size_t)s * sizeof(int32_t));
    HDassert(wbuf);
    rbuf = (int32_t *)HDcalloc((size_t)s, sizeof(int32_t));
    HDassert(rbuf);

    /* Fill up write buffer with 1s */
    for(i = 0; i < s; i++)
        wbuf[i] = 1;

    /* Write data to the accumulator to fill it. */
    if(accum_write(512, 512, wbuf) < 0) FAIL_STACK_ERROR;

    /* Write a piece of metadata outside current accumulator to force write
        to disk */
    if(accum_write(0, 1, wbuf) < 0) FAIL_STACK_ERROR;

    /* Fill up write buffer with 2s */
    for(i = 0; i < s; i++)
        wbuf[i] = 2;

    /* Write a block of 2s of the original size that will overlap the lower half
        of the original block */
    if(accum_write(256, 512, wbuf) < 0) FAIL_STACK_ERROR;

    /* Read 128 bytes at the original address, and then  */ 
    if(accum_read(512, 512, rbuf) < 0) FAIL_STACK_ERROR;

    /* Set the second half of wbuf back to 1s */ 
    for(i = 64; i < s; i++)
        wbuf[i] = 1;

    /* Read in the piece we wrote to disk above, and then verify that 
        the data is as expected */
    if(accum_read(512, 512, rbuf) < 0) FAIL_STACK_ERROR;
    if(HDmemcmp(wbuf, rbuf, 128) != 0) TEST_ERROR;

    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;

    PASSED();

    /* Release memory */
    HDfree(wbuf);
    HDfree(rbuf);

    return 0;

error:
    /* Release memory */
    HDfree(wbuf);
    HDfree(rbuf);

    return 1;
} /* end test_read_after */


/*-------------------------------------------------------------------------
 * Function:    test_big
 * 
 * Purpose:     This test exercises writing large pieces of metadata to the
 *		file.
 * 
 * Return:      Success: SUCCEED
 *              Failure: FAIL
 * 
 * Programmer:  Quincey Koziol
 *              October 12, 2010
 *
 *-------------------------------------------------------------------------
 */
unsigned 
test_big(const H5F_io_info_t *fio_info)
{
    uint8_t *wbuf, *wbuf2, *rbuf, *zbuf;        /* Buffers for reading & writing, etc */
    unsigned u;                         /* Local index variable */

    /* Allocate space for the write & read buffers */
    wbuf = (uint8_t *)HDmalloc(BIG_BUF_SIZE);
    HDassert(wbuf);
    wbuf2 = (uint8_t *)HDmalloc(BIG_BUF_SIZE);
    HDassert(wbuf2);
    rbuf = (uint8_t *)HDcalloc(BIG_BUF_SIZE + 1536, 1);
    HDassert(rbuf);
    zbuf = (uint8_t *)HDcalloc(BIG_BUF_SIZE + 1536, 1);
    HDassert(zbuf);

    /* Initialize write buffers */
    for(u = 0; u < BIG_BUF_SIZE; u++) {
        wbuf[u] = (uint8_t)u;
        wbuf2[u] = (uint8_t)(u + 1);
    } /* end for */

    TESTING("large metadata I/O operations");

    /* Write large data segment to file */
    if(accum_write(0, BIG_BUF_SIZE, wbuf) < 0) FAIL_STACK_ERROR;

    /* Read entire segment back from file */
    if(accum_read(0, BIG_BUF_SIZE, rbuf) < 0) FAIL_STACK_ERROR;

    /* Verify data read */
    if(HDmemcmp(wbuf, rbuf, BIG_BUF_SIZE) != 0) TEST_ERROR;


    /* Reset data in file back to zeros & reset the read buffer */
    if(accum_write(0, BIG_BUF_SIZE, zbuf) < 0) FAIL_STACK_ERROR;
    HDmemset(rbuf, 0, BIG_BUF_SIZE);
    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;


    /* Write small section to middle of accumulator */
    if(accum_write(1024, 1024, wbuf) < 0) FAIL_STACK_ERROR;

    /* Read entire segment back from file */
    /* (Read covers entire dirty region) */
    if(accum_read(0, BIG_BUF_SIZE, rbuf) < 0) FAIL_STACK_ERROR;

    /* Verify data read */
    if(HDmemcmp(zbuf, rbuf, 1024) != 0) TEST_ERROR;
    if(HDmemcmp(wbuf, rbuf + 1024, 1024) != 0) TEST_ERROR;
    if(HDmemcmp(zbuf, rbuf + 2048, (BIG_BUF_SIZE - 2048)) != 0) TEST_ERROR;


    /* Reset data in file back to zeros & reset the read buffer */
    if(accum_write(1024, 1024, zbuf) < 0) FAIL_STACK_ERROR;
    HDmemset(rbuf, 0, BIG_BUF_SIZE);
    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;


    /* Write small section to overlap with end of "big" region */
    if(accum_write(BIG_BUF_SIZE - 512, 1024, wbuf) < 0) FAIL_STACK_ERROR;

    /* Read entire segment back from file */
    /* (Read covers bottom half of dirty region) */
    if(accum_read(0, BIG_BUF_SIZE, rbuf) < 0) FAIL_STACK_ERROR;

    /* Verify data read */
    if(HDmemcmp(zbuf, rbuf, (BIG_BUF_SIZE - 512)) != 0) TEST_ERROR;
    if(HDmemcmp(wbuf, rbuf + (BIG_BUF_SIZE - 512), 512) != 0) TEST_ERROR;


    /* Reset data in file back to zeros & reset the read buffer */
    if(accum_write(BIG_BUF_SIZE - 512, 1024, zbuf) < 0) FAIL_STACK_ERROR;
    HDmemset(rbuf, 0, BIG_BUF_SIZE);
    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;


    /* Write small section to overlap with beginning of "big" region */
    if(accum_write(0, 1024, wbuf) < 0) FAIL_STACK_ERROR;

    /* Read entire segment back from file */
    /* (Read covers bottom half of dirty region) */
    if(accum_read(512, BIG_BUF_SIZE, rbuf) < 0) FAIL_STACK_ERROR;

    /* Verify data read */
    if(HDmemcmp(wbuf + 512, rbuf, 512) != 0) TEST_ERROR;
    if(HDmemcmp(zbuf, rbuf + 512, (BIG_BUF_SIZE - 512)) != 0) TEST_ERROR;


    /* Reset data in file back to zeros & reset the read buffer */
    if(accum_write(0, 1024, zbuf) < 0) FAIL_STACK_ERROR;
    HDmemset(rbuf, 0, BIG_BUF_SIZE);
    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;


    /* Write small section to middle of accumulator */
    /* (With write buffer #1) */
    if(accum_write(1024, 1024, wbuf) < 0) FAIL_STACK_ERROR;

    /* Write entire segment to from file */
    /* (With write buffer #2) */
    /* (Write covers entire dirty region) */
    if(accum_write(0, BIG_BUF_SIZE, wbuf2) < 0) FAIL_STACK_ERROR;

    /* Read entire segment back from file */
    if(accum_read(0, BIG_BUF_SIZE, rbuf) < 0) FAIL_STACK_ERROR;

    /* Verify data read */
    if(HDmemcmp(wbuf2, rbuf, BIG_BUF_SIZE) != 0) TEST_ERROR;


    /* Reset data in file back to zeros & reset the read buffer */
    if(accum_write(0, BIG_BUF_SIZE, zbuf) < 0) FAIL_STACK_ERROR;
    HDmemset(rbuf, 0, BIG_BUF_SIZE);
    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;


    /* Write small section to overlap with end of "big" region */
    /* (With write buffer #1) */
    if(accum_write(BIG_BUF_SIZE - 512, 1024, wbuf) < 0) FAIL_STACK_ERROR;

    /* Write entire segment to from file */
    /* (With write buffer #2) */
    /* (Read covers bottom half of dirty region) */
    if(accum_write(0, BIG_BUF_SIZE, wbuf2) < 0) FAIL_STACK_ERROR;

    /* Read both segments back from file */
    if(accum_read(0, BIG_BUF_SIZE + 512, rbuf) < 0) FAIL_STACK_ERROR;

    /* Verify data read */
    if(HDmemcmp(wbuf2, rbuf, BIG_BUF_SIZE) != 0) TEST_ERROR;
    if(HDmemcmp(wbuf + 512, rbuf + BIG_BUF_SIZE, 512) != 0) TEST_ERROR;


    /* Reset data in file back to zeros & reset the read buffer */
    if(accum_write(0, BIG_BUF_SIZE + 512, zbuf) < 0) FAIL_STACK_ERROR;
    HDmemset(rbuf, 0, BIG_BUF_SIZE + 512);
    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;


    /* Write small section to be past "big" region */
    /* (With write buffer #1) */
    if(accum_write(BIG_BUF_SIZE + 512, 1024, wbuf) < 0) FAIL_STACK_ERROR;

    /* Read section before "big" region */
    /* (To enlarge accumulator, to it will intersect with big write) */
    if(accum_read(BIG_BUF_SIZE - 512, 1024, rbuf) < 0) FAIL_STACK_ERROR;

    /* Write entire segment to from file */
    /* (With write buffer #2) */
    /* (Doesn't overlap with small section) */
    if(accum_write(0, BIG_BUF_SIZE, wbuf2) < 0) FAIL_STACK_ERROR;

    /* Read both segments & gap back from file */
    if(accum_read(0, BIG_BUF_SIZE + 1024, rbuf) < 0) FAIL_STACK_ERROR;

    /* Verify data read */
    if(HDmemcmp(wbuf2, rbuf, BIG_BUF_SIZE) != 0) TEST_ERROR;
    if(HDmemcmp(zbuf, rbuf + BIG_BUF_SIZE, 512) != 0) TEST_ERROR;
    if(HDmemcmp(wbuf, rbuf + BIG_BUF_SIZE + 512, 512) != 0) TEST_ERROR;


    /* Reset data in file back to zeros & reset the read buffer */
    if(accum_write(0, BIG_BUF_SIZE + 1536, zbuf) < 0) FAIL_STACK_ERROR;
    HDmemset(rbuf, 0, BIG_BUF_SIZE + 1024);
    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;


    /* Write small section to be past "big" region */
    /* (With write buffer #1) */
    if(accum_write(BIG_BUF_SIZE + 512, 1024, wbuf) < 0) FAIL_STACK_ERROR;

    /* Read section before "big" region */
    /* (To enlarge accumulator, so it will intersect with big write) */
    if(accum_read(BIG_BUF_SIZE - 512, 1024, rbuf) < 0) FAIL_STACK_ERROR;
    if(accum_read(BIG_BUF_SIZE + 1536, 1024, rbuf) < 0) FAIL_STACK_ERROR;

    /* Write entire segment to from file */
    /* (With write buffer #2) */
    /* (Overwriting dirty region, but not invalidating entire accumulator) */
    if(accum_write(1536, BIG_BUF_SIZE, wbuf2) < 0) FAIL_STACK_ERROR;

    /* Read both segments & gap back from file */
    if(accum_read(0, BIG_BUF_SIZE + 1536, rbuf) < 0) FAIL_STACK_ERROR;

    /* Verify data read */
    if(HDmemcmp(zbuf, rbuf, 1536) != 0) TEST_ERROR;
    if(HDmemcmp(wbuf2, rbuf + 1536, BIG_BUF_SIZE) != 0) TEST_ERROR;


    /* Reset data in file back to zeros & reset the read buffer */
    if(accum_write(1536, BIG_BUF_SIZE, zbuf) < 0) FAIL_STACK_ERROR;
    HDmemset(rbuf, 0, BIG_BUF_SIZE + 1536);
    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;


    /* Write small section before "big" region */
    /* (With write buffer #1) */
    if(accum_write(1024, 1024, wbuf) < 0) FAIL_STACK_ERROR;

    /* Read section before "big" region */
    /* (To enlarge accumulator, so it will intersect with big write) */
    if(accum_read(0, 1024, rbuf) < 0) FAIL_STACK_ERROR;

    /* Write entire segment to from file */
    /* (With write buffer #2) */
    /* (Overwriting dirty region, but not invalidating entire accumulator) */
    if(accum_write(512, BIG_BUF_SIZE, wbuf2) < 0) FAIL_STACK_ERROR;

    /* Read both segments & gap back from file */
    if(accum_read(0, BIG_BUF_SIZE + 512, rbuf) < 0) FAIL_STACK_ERROR;

    /* Verify data read */
    if(HDmemcmp(zbuf, rbuf, 512) != 0) TEST_ERROR;
    if(HDmemcmp(wbuf2, rbuf + 512, BIG_BUF_SIZE) != 0) TEST_ERROR;


    /* Reset data in file back to zeros & reset the read buffer */
    if(accum_write(512, BIG_BUF_SIZE, zbuf) < 0) FAIL_STACK_ERROR;
    HDmemset(rbuf, 0, BIG_BUF_SIZE + 512);
    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;


    /* Write small section before "big" region */
    /* (With write buffer #1) */
    if(accum_write(0, 1024, wbuf) < 0) FAIL_STACK_ERROR;

    /* Read section before "big" region */
    /* (To enlarge accumulator, so it will intersect with big write) */
    if(accum_read(1024, 1024, rbuf) < 0) FAIL_STACK_ERROR;

    /* Write entire segment to from file */
    /* (With write buffer #2) */
    /* (Avoiding dirty region, and not invalidating entire accumulator) */
    if(accum_write(1536, BIG_BUF_SIZE, wbuf2) < 0) FAIL_STACK_ERROR;

    /* Read both segments & gap back from file */
    if(accum_read(0, BIG_BUF_SIZE + 1536, rbuf) < 0) FAIL_STACK_ERROR;

    /* Verify data read */
    if(HDmemcmp(wbuf, rbuf, 1024) != 0) TEST_ERROR;
    if(HDmemcmp(zbuf, rbuf + 1024, 512) != 0) TEST_ERROR;
    if(HDmemcmp(wbuf2, rbuf + 1536, BIG_BUF_SIZE) != 0) TEST_ERROR;


    /* Reset data in file back to zeros & reset the read buffer */
    if(accum_write(0, BIG_BUF_SIZE + 1536, zbuf) < 0) FAIL_STACK_ERROR;
    HDmemset(rbuf, 0, BIG_BUF_SIZE + 1536);
    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;


    /* Write small section before "big" region */
    /* (With write buffer #1) */
    if(accum_write(0, 1024, wbuf) < 0) FAIL_STACK_ERROR;

    /* Read section before "big" region */
    /* (To enlarge accumulator, so it will intersect with big write) */
    if(accum_read(1024, 1024, rbuf) < 0) FAIL_STACK_ERROR;

    /* Write entire segment to from file */
    /* (With write buffer #2) */
    /* (Partially overwriting dirty region, and not invalidating entire accumulator) */
    if(accum_write(512, BIG_BUF_SIZE, wbuf2) < 0) FAIL_STACK_ERROR;

    /* Read both segments back from file */
    if(accum_read(0, BIG_BUF_SIZE + 512, rbuf) < 0) FAIL_STACK_ERROR;

    /* Verify data read */
    if(HDmemcmp(wbuf, rbuf, 512) != 0) TEST_ERROR;
    if(HDmemcmp(wbuf2, rbuf + 512, BIG_BUF_SIZE) != 0) TEST_ERROR;


    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;

    PASSED();

    /* Release memory */
    HDfree(wbuf);
    HDfree(wbuf2);
    HDfree(rbuf);
    HDfree(zbuf);

    return 0;

error:
    HDfree(wbuf);
    HDfree(wbuf2);
    HDfree(rbuf);
    HDfree(zbuf);

    return 1;
} /* end test_big() */


/*-------------------------------------------------------------------------
 * Function:    test_random_write
 * 
 * Purpose:     This test writes random pieces of data to the file and
 *		then reads it all back.
 * 
 * Return:      Success: SUCCEED
 *              Failure: FAIL
 * 
 * Programmer:  Quincey Koziol
 *              October 11, 2010
 *
 *-------------------------------------------------------------------------
 */
unsigned 
test_random_write(const H5F_io_info_t *fio_info)
{
    uint8_t *wbuf, *rbuf;       /* Buffers for reading & writing */
    unsigned seed = 0;          /* Random # seed */
    size_t *off;                /* Offset of buffer segments to write */
    size_t *len;                /* Size of buffer segments to write */
    size_t cur_off;             /* Current offset */
    size_t nsegments;           /* Number of segments to write */
    size_t swap;                /* Position to swap with */
    unsigned u;                 /* Local index variable */

    /* Allocate space for the write & read buffers */
    wbuf = (uint8_t *)malloc(RANDOM_BUF_SIZE);
    HDassert(wbuf);
    rbuf = (uint8_t *)calloc(RANDOM_BUF_SIZE, 1);
    HDassert(rbuf);

    /* Initialize write buffer */
    for(u = 0; u < RANDOM_BUF_SIZE; u++)
        wbuf[u] = (uint8_t)u;

    TESTING("random writes to accumulator");

    /* Choose random # seed */
    seed = (unsigned)HDtime(NULL);
#ifdef QAK
/* seed = (unsigned)1155438845; */
HDfprintf(stderr, "Random # seed was: %u\n", seed);
#endif /* QAK */
    HDsrandom(seed);

    /* Allocate space for the segment length buffer */
    off = (size_t *)malloc(MAX_RANDOM_SEGMENTS * sizeof(size_t));
    HDassert(off);
    len = (size_t *)malloc(MAX_RANDOM_SEGMENTS * sizeof(size_t));
    HDassert(len);

    /* Randomly choose lengths of segments */
    cur_off = 0;
    for(u = 0; u < MAX_RANDOM_SEGMENTS; ) {
        size_t length = 0;      /* Length of current segment */

        /* Choose random length of segment, allowing for variance */
        do {
            length += (size_t)(HDrandom() % RAND_SEG_LEN) + 1;
        } while((HDrandom() & 256) >= 128); /* end while */

        /* Check for going off end of buffer */
        if((cur_off + length) > RANDOM_BUF_SIZE)
            length = RANDOM_BUF_SIZE - cur_off;

        /* Set offset & length of segment */
        off[u] = cur_off;
        len[u] = length;

        /* Advance array offset */
        u++;

        /* Advance current offset */
        cur_off += length;

        /* If we've used up entire buffer before hitting limit of segments, get out */
        if(cur_off >= RANDOM_BUF_SIZE)
            break;
    } /* end for */
    nsegments = u;

    /* Increase length of last segment, if it doesn't reach end of buffer */
    if(nsegments < MAX_RANDOM_SEGMENTS)
        len[nsegments - 1] = RANDOM_BUF_SIZE - off[nsegments - 1];

    /* Shuffle order of segments, to randomize positions to write */
    for(u = 0; u < nsegments; u++) {
        size_t tmp;        /* Temporary holder for offset & length values */

        /* Choose value within next few elements to to swap with */
        swap = ((size_t)HDrandom() % 8) + u;
        if(swap >= nsegments)
            swap = nsegments - 1;

        /* Swap values */
        tmp = off[u]; off[u] = off[swap]; off[swap] = tmp;
        tmp = len[u]; len[u] = len[swap]; len[swap] = tmp;
    } /* end for */

    /* Write data segments to file */
    for(u = 0; u < nsegments; u++) {
        if(accum_write(RANDOM_BASE_OFF + off[u], len[u], wbuf + off[u]) < 0) FAIL_STACK_ERROR;

        /* Verify individual reads */
        if(accum_read(RANDOM_BASE_OFF + off[u], len[u], rbuf) < 0) FAIL_STACK_ERROR;
        if(HDmemcmp(wbuf + off[u], rbuf, len[u]) != 0) TEST_ERROR;
    } /* end for */

    /* Read entire region back from file */
    if(accum_read(RANDOM_BASE_OFF, RANDOM_BUF_SIZE, rbuf) < 0) FAIL_STACK_ERROR;

    /* Verify data read back in */
    if(HDmemcmp(wbuf, rbuf, RANDOM_BUF_SIZE) != 0) TEST_ERROR;

    if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;

    PASSED();

    /* Release memory */
    HDfree(wbuf);
    HDfree(rbuf);
    HDfree(off);
    HDfree(len);

    return 0;

error:
    /* Release memory */
    HDfree(wbuf);
    HDfree(rbuf);
    HDfree(off);
    HDfree(len);

    HDfprintf(stderr, "Random # seed was: %u\n", seed);
    return 1;
} /* end test_random_write() */


/*-------------------------------------------------------------------------
 * Function:    accum_printf
 * 
 * Purpose:     Debug function to print some stats about the accumulator
 * 
 * Return:      Success: SUCCEED
 *              Failure: FAIL
 * 
 * Programmer:  Mike McGreevy
 *              October 7, 2010
 *
 *-------------------------------------------------------------------------
 */
void
accum_printf(void)
{
    H5F_meta_accum_t * accum = &f->shared->accum;

    printf("\n");
    printf("Current contents of accumulator:\n");
    if (accum->alloc_size == 0) {
        printf("=====================================================\n");
        printf(" No accumulator allocated.\n");
        printf("=====================================================\n");
    } else {
        printf("=====================================================\n");
        printf(" accumulator allocated size == %zu\n", accum->alloc_size);
        printf(" accumulated data size      == %zu\n", accum->size);
        HDfprintf(stdout, " accumulator dirty?         == %t\n", accum->dirty);
        printf("=====================================================\n");
        HDfprintf(stdout, " start of accumulated data, loc = %a\n", accum->loc);
        if(accum->dirty) {
            HDfprintf(stdout, " start of dirty region, loc = %a\n", (haddr_t)(accum->loc + accum->dirty_off));
            HDfprintf(stdout, " end of dirty region,   loc = %a\n", (haddr_t)(accum->loc + accum->dirty_off + accum->dirty_len));
        } /* end if */
        HDfprintf(stdout, " end of accumulated data,   loc = %a\n", (haddr_t)(accum->loc + accum->size));
        HDfprintf(stdout, " end of accumulator allocation,   loc = %a\n", (haddr_t)(accum->loc + accum->alloc_size));
        printf("=====================================================\n");
    }
    printf("\n\n");
} /* accum_printf() */