summaryrefslogtreecommitdiffstats
path: root/Source/cmDependsJavaParserHelper.cxx
blob: 0c5d310e3027bbd9ad0b6b3d0f47ca5366455e03 (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
/* Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
   file Copyright.txt or https://cmake.org/licensing for details.  */
#include "cmDependsJavaParserHelper.h"

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <utility>

#include <cm/memory>
#include <cm/string_view>

#include "cmsys/FStream.hxx"

#include "cmDependsJavaLexer.h"
#include "cmSystemTools.h"

int cmDependsJava_yyparse(yyscan_t yyscanner);

cmDependsJavaParserHelper::cmDependsJavaParserHelper()
{
  this->CurrentDepth = 0;

  this->UnionsAvailable = 0;
  this->LastClassId = 0;

  CurrentClass tl;
  tl.Name = "*";
  this->ClassStack.push_back(std::move(tl));
}

cmDependsJavaParserHelper::~cmDependsJavaParserHelper()
{
  this->CleanupParser();
}

void cmDependsJavaParserHelper::CurrentClass::AddFileNamesForPrinting(
  std::vector<std::string>* files, const char* prefix, const char* sep) const
{
  std::string rname;
  if (prefix) {
    rname += prefix;
    rname += sep;
  }
  rname += this->Name;
  files->push_back(rname);
  for (CurrentClass const& nc : this->NestedClasses) {
    nc.AddFileNamesForPrinting(files, rname.c_str(), sep);
  }
}

void cmDependsJavaParserHelper::DeallocateParserType(char** pt)
{
  if (!pt) {
    return;
  }
  if (!*pt) {
    return;
  }
  *pt = nullptr;
  this->UnionsAvailable--;
}

void cmDependsJavaParserHelper::AddClassFound(const char* sclass)
{
  if (!sclass) {
    return;
  }
  for (std::string const& cf : this->ClassesFound) {
    if (cf == sclass) {
      return;
    }
  }
  this->ClassesFound.emplace_back(sclass);
}

void cmDependsJavaParserHelper::AddPackagesImport(const char* sclass)
{
  for (std::string const& pi : this->PackagesImport) {
    if (pi == sclass) {
      return;
    }
  }
  this->PackagesImport.emplace_back(sclass);
}

void cmDependsJavaParserHelper::SafePrintMissing(const char* str, int line,
                                                 int cnt)
{
  if (str) {
    std::cout << line << " String " << cnt << " exists: ";
    unsigned int cc;
    for (cc = 0; cc < strlen(str); cc++) {
      unsigned char ch = str[cc];
      if (ch >= 32 && ch <= 126) {
        std::cout << static_cast<char>(ch);
      } else {
        std::cout << "<" << static_cast<int>(ch) << ">";
        break;
      }
    }
    std::cout << "- " << strlen(str) << std::endl;
  }
}
void cmDependsJavaParserHelper::Print(const char* place, const char* str) const
{
  if (this->Verbose) {
    std::cout << "[" << place << "=" << str << "]" << std::endl;
  }
}

void cmDependsJavaParserHelper::CombineUnions(char** out, const char* in1,
                                              char** in2, const char* sep)
{
  size_t len = 1;
  if (in1) {
    len += strlen(in1);
  }
  if (*in2) {
    len += strlen(*in2);
  }
  if (sep) {
    len += strlen(sep);
  }
  *out = new char[len];
  *out[0] = 0;
  if (in1) {
    strcat(*out, in1);
  }
  if (sep) {
    strcat(*out, sep);
  }
  if (*in2) {
    strcat(*out, *in2);
  }
  if (*in2) {
    this->DeallocateParserType(in2);
  }
  this->UnionsAvailable++;
}

void cmDependsJavaParserHelper::CheckEmpty(
  int line, int cnt, cmDependsJavaParserHelper::ParserType* pt)
{
  int cc;
  int kk = -cnt + 1;
  for (cc = 1; cc <= cnt; cc++) {
    cmDependsJavaParserHelper::ParserType* cpt = pt + kk;
    this->SafePrintMissing(cpt->str, line, cc);
    kk++;
  }
}

void cmDependsJavaParserHelper::PrepareElement(
  cmDependsJavaParserHelper::ParserType* me)
{
  // Inititalize self
  me->str = nullptr;
}

void cmDependsJavaParserHelper::AllocateParserType(
  cmDependsJavaParserHelper::ParserType* pt, const char* str, int len)
{
  pt->str = nullptr;
  if (len == 0) {
    len = static_cast<int>(strlen(str));
  }
  if (len == 0) {
    return;
  }
  this->UnionsAvailable++;
  auto up = cm::make_unique<char[]>(len + 1);
  pt->str = up.get();
  strncpy(pt->str, str, len);
  pt->str[len] = 0;
  this->Allocates.push_back(std::move(up));
}

void cmDependsJavaParserHelper::StartClass(const char* cls)
{
  CurrentClass cl;
  cl.Name = cls;
  this->ClassStack.push_back(std::move(cl));

  this->CurrentDepth++;
}

void cmDependsJavaParserHelper::EndClass()
{
  if (this->ClassStack.empty()) {
    std::cerr << "Error when parsing. Current class is null" << std::endl;
    abort();
  }
  if (this->ClassStack.size() <= 1) {
    std::cerr << "Error when parsing. Parent class is null" << std::endl;
    abort();
  }
  CurrentClass& current = this->ClassStack.back();
  CurrentClass& parent = this->ClassStack[this->ClassStack.size() - 2];
  this->CurrentDepth--;
  parent.NestedClasses.push_back(current);
  this->ClassStack.pop_back();
}

void cmDependsJavaParserHelper::PrintClasses()
{
  if (this->ClassStack.empty()) {
    std::cerr << "Error when parsing. No classes on class stack" << std::endl;
    abort();
  }
  for (std::string const& f : this->GetFilesProduced()) {
    std::cout << "  " << f << ".class" << std::endl;
  }
}

std::vector<std::string> cmDependsJavaParserHelper::GetFilesProduced()
{
  std::vector<std::string> files;
  CurrentClass const& toplevel = this->ClassStack.front();
  for (CurrentClass const& nc : toplevel.NestedClasses) {
    nc.AddFileNamesForPrinting(&files, nullptr, "$");
  }
  return files;
}

int cmDependsJavaParserHelper::ParseString(const char* str, int verb)
{
  if (!str) {
    return 0;
  }
  this->Verbose = verb;
  this->InputBuffer = str;
  this->InputBufferPos = 0;
  this->CurrentLine = 0;

  yyscan_t yyscanner;
  cmDependsJava_yylex_init(&yyscanner);
  cmDependsJava_yyset_extra(this, yyscanner);
  int res = cmDependsJava_yyparse(yyscanner);
  cmDependsJava_yylex_destroy(yyscanner);
  if (res != 0) {
    std::cout << "JP_Parse returned: " << res << std::endl;
    return 0;
  }

  if (verb) {
    if (!this->CurrentPackage.empty()) {
      std::cout << "Current package is: " << this->CurrentPackage << std::endl;
    }
    std::cout << "Imports packages:";
    if (!this->PackagesImport.empty()) {
      std::vector<std::string>::iterator it;
      for (it = this->PackagesImport.begin(); it != this->PackagesImport.end();
           ++it) {
        std::cout << " " << *it;
      }
    }
    std::cout << std::endl;
    std::cout << "Depends on:";
    if (!this->ClassesFound.empty()) {
      for (std::string const& cf : this->ClassesFound) {
        std::cout << " " << cf;
      }
    }
    std::cout << std::endl;
    std::cout << "Generated files:" << std::endl;
    this->PrintClasses();
    if (this->UnionsAvailable != 0) {
      std::cout << "There are still " << this->UnionsAvailable
                << " unions available" << std::endl;
    }
  }
  this->CleanupParser();
  return 1;
}

void cmDependsJavaParserHelper::CleanupParser()
{
  this->Allocates.clear();
}

int cmDependsJavaParserHelper::LexInput(char* buf, int maxlen)
{
  if (maxlen < 1) {
    return 0;
  }
  if (this->InputBufferPos < this->InputBuffer.size()) {
    buf[0] = this->InputBuffer[this->InputBufferPos++];
    if (buf[0] == '\n') {
      this->CurrentLine++;
    }
    return 1;
  }
  buf[0] = '\n';
  return 0;
}
void cmDependsJavaParserHelper::Error(const char* str)
{
  unsigned long pos = static_cast<unsigned long>(this->InputBufferPos);
  fprintf(stderr, "JPError: %s (%lu / Line: %d)\n", str, pos,
          this->CurrentLine);
  std::cerr << "String: ["
            << cm::string_view{ this->InputBuffer }.substr(
                 this->InputBufferPos, 30)
            << "]" << std::endl;
}

void cmDependsJavaParserHelper::UpdateCombine(const char* str1,
                                              const char* str2)
{
  if (this->CurrentCombine.empty() && str1 != nullptr) {
    this->CurrentCombine = str1;
  }
  this->CurrentCombine += ".";
  this->CurrentCombine += str2;
}

int cmDependsJavaParserHelper::ParseFile(const char* file)
{
  if (!cmSystemTools::FileExists(file)) {
    return 0;
  }
  cmsys::ifstream ifs(file);
  if (!ifs) {
    return 0;
  }

  std::string fullfile;
  std::string line;
  while (cmSystemTools::GetLineFromStream(ifs, line)) {
    fullfile += line + "\n";
  }
  return this->ParseString(fullfile.c_str(), 0);
}
85'>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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * 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.                                                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/***********************************************************
*
* Test program:	 cache_page_buffer
*
* Tests the Page Buffer Feature.
*
*************************************************************/

#include "h5test.h"

#include "H5CXprivate.h"        /* API Contexts                         */
#include "H5Iprivate.h"
#include "H5PBprivate.h"
#include "H5VLprivate.h"        /* Virtual Object Layer                     */

/*
 * This file needs to access private information from the H5F package.
 */
#define H5MF_FRIEND		/*suppress error about including H5MFpkg	  */
#include "H5MFpkg.h"

#define H5F_FRIEND		/*suppress error about including H5Fpkg	  */
#define H5F_TESTING
#include "H5Fpkg.h"


#define FILENAME_LEN            1024

/* test routines */
#ifdef H5_HAVE_PARALLEL
static unsigned verify_page_buffering_disabled(hid_t orig_fapl, 
    const char *env_h5_drvr);
#else
#define NUM_DSETS               5
#define NX                      100
#define NY                      50

static unsigned test_args(hid_t fapl, const char *env_h5_drvr);
static unsigned test_raw_data_handling(hid_t orig_fapl, const char *env_h5_drvr);
static unsigned test_lru_processing(hid_t orig_fapl, const char *env_h5_drvr);
static unsigned test_min_threshold(hid_t orig_fapl, const char *env_h5_drvr);
static unsigned test_stats_collection(hid_t orig_fapl, const char *env_h5_drvr);

/* helper routines */
static unsigned create_file(char *filename, hid_t fcpl, hid_t fapl);
static unsigned open_file(char *filename, hid_t fapl, hsize_t page_size, size_t page_buffer_size);
#endif /* H5_HAVE_PARALLEL */

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

#ifndef H5_HAVE_PARALLEL

/*-------------------------------------------------------------------------
 * Function:    create_file()
 *
 * Purpose:     The purpose of this function appears to be a smoke check
 *              intended to exercise the page buffer.
 *
 *              Specifically, the function creates a file, and then goes 
 *              through a loop in which it creates four data sets, write 
 *              data to one of them, verifies the data written, and then 
 *              deletes the three that it didn't write to.
 *
 *              Any data mis-matches or failures reported by the HDF5
 *              library result in test failure.
 *
 * Return:      0 if test is sucessful
 *              1 if test fails
 *
 * Programmer:  unknown
 *              ?? / ?? / ??
 *
 *-------------------------------------------------------------------------
 */
static unsigned
create_file(char *filename, hid_t fcpl, hid_t fapl)
{
    hid_t       file_id = -1;
    hid_t       dset_id = -1;
    hid_t       grp_id = -1;
    hid_t       filespace = -1;
    hsize_t     dimsf[2] = {NX, NY};       /* dataset dimensions */
    int         *data = NULL;                     /* pointer to data buffer to write */
    hid_t       dcpl = -1;
    int         i;
    int         num_elements;
    int         j;
    char        dset_name[32];

    if((file_id = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl)) < 0)
        FAIL_STACK_ERROR;

    if((grp_id = H5Gcreate2(file_id, "GROUP", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0)
        FAIL_STACK_ERROR;

    num_elements  = NX * NY;
    if((data = (int *)HDcalloc((size_t)num_elements, sizeof(int))) == NULL)
        TEST_ERROR
    for (i=0; i < (int)num_elements; i++)
        data[i] = i;

    if((filespace = H5Screate_simple(2, dimsf, NULL)) < 0)
        FAIL_STACK_ERROR;

    if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
       FAIL_STACK_ERROR;
    if(H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_EARLY) < 0)
        FAIL_STACK_ERROR;

    for(i=0 ; i<NUM_DSETS; i++) {

        HDsprintf(dset_name, "D1dset%d", i);
        if((dset_id = H5Dcreate2(grp_id, dset_name, H5T_NATIVE_INT, filespace,
                                 H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
            FAIL_STACK_ERROR;
        if(H5Dclose(dset_id) < 0)
            FAIL_STACK_ERROR;

        HDsprintf(dset_name, "D2dset%d", i);
        if((dset_id = H5Dcreate2(grp_id, dset_name, H5T_NATIVE_INT, filespace,
                                 H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
            FAIL_STACK_ERROR;
        if(H5Dclose(dset_id) < 0)
            FAIL_STACK_ERROR;

        HDsprintf(dset_name, "D3dset%d", i);
        if((dset_id = H5Dcreate2(grp_id, dset_name, H5T_NATIVE_INT, filespace,
                                 H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
            FAIL_STACK_ERROR;
        if(H5Dclose(dset_id) < 0)
            FAIL_STACK_ERROR;

        HDsprintf(dset_name, "dset%d", i);
        if((dset_id = H5Dcreate2(grp_id, dset_name, H5T_NATIVE_INT, filespace,
                                 H5P_DEFAULT, dcpl, H5P_DEFAULT)) < 0)
            FAIL_STACK_ERROR;

        if(H5Dwrite(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data) < 0)
            FAIL_STACK_ERROR;
        if(H5Dclose(dset_id) < 0)
            FAIL_STACK_ERROR;

        HDmemset(data, 0, (size_t)num_elements * sizeof(int));
        if((dset_id = H5Dopen2(grp_id, dset_name, H5P_DEFAULT)) < 0)
            FAIL_STACK_ERROR;        
        if(H5Dread(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data) < 0)
            FAIL_STACK_ERROR;
        if(H5Dclose(dset_id) < 0)
            FAIL_STACK_ERROR;

        for (j=0; j < num_elements; j++) {
            if(data[j] != j) {
                HDfprintf(stderr, "Read different values than written\n");
                FAIL_STACK_ERROR;
            }
        }

        HDsprintf(dset_name, "D1dset%d", i);
        if(H5Ldelete(grp_id, dset_name, H5P_DEFAULT) < 0)
            FAIL_STACK_ERROR;
        HDsprintf(dset_name, "D2dset%d", i);
        if(H5Ldelete(grp_id, dset_name, H5P_DEFAULT) < 0)
            FAIL_STACK_ERROR;
        HDsprintf(dset_name, "D3dset%d", i);
        if(H5Ldelete(grp_id, dset_name, H5P_DEFAULT) < 0)
            FAIL_STACK_ERROR;
    }

    if(H5Gclose(grp_id) < 0)
        FAIL_STACK_ERROR;
    if(H5Fclose(file_id) < 0)
        FAIL_STACK_ERROR;
    if(H5Pclose(dcpl) < 0)
        FAIL_STACK_ERROR;
    if(H5Sclose(filespace) < 0)
        FAIL_STACK_ERROR;

    HDfree(data);
    return 0;

error:
    H5E_BEGIN_TRY {
        H5Pclose(dcpl);
        H5Sclose(filespace);
        H5Gclose(grp_id);
        H5Fclose(file_id);
        if(data)
            HDfree(data);
    } H5E_END_TRY;
    return(1);
} /* create_file */


/*-------------------------------------------------------------------------
 * Function:    open_file()
 *
 * Purpose:     The purpose of this function appears to be a smoke check
 *              intended to exercise the page buffer.
 *
 *              Specifically, the function opens a file (created by 
 *              create_file()?), and verify the contents of its datasets.
 *
 *              Any data mis-matches or failures reported by the HDF5
 *              library result in test failure.
 *
 * Return:      0 if test is sucessful
 *              1 if test fails
 *
 * Programmer:  unknown
 *              ?? / ?? / ??
 *
 *-------------------------------------------------------------------------
 */
static unsigned
open_file(char *filename, hid_t fapl, hsize_t page_size, 
    size_t page_buffer_size)
{
    hid_t       file_id = -1;
    hid_t       dset_id = -1;
    hid_t       grp_id = -1;
    int         *data = NULL;                    /* pointer to data buffer to write */
    int         i;
    int         j;
    int         num_elements;
    char        dset_name[32];
    H5F_t       *f = NULL;

    if((file_id = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0)
        FAIL_STACK_ERROR;

    /* Get a pointer to the internal file object */
    if(NULL == (f = (H5F_t *)H5VL_object(file_id)))
        FAIL_STACK_ERROR;

    if(f->shared->page_buf == NULL)
        FAIL_STACK_ERROR;
    if(f->shared->page_buf->page_size != page_size)
        FAIL_STACK_ERROR;
    if(f->shared->page_buf->max_size != page_buffer_size)
        FAIL_STACK_ERROR;

    if((grp_id = H5Gopen2(file_id, "GROUP", H5P_DEFAULT)) < 0)
        FAIL_STACK_ERROR;

    num_elements  = NX * NY;
    if((data = (int *)HDcalloc((size_t)num_elements, sizeof(int))) == NULL)
        TEST_ERROR

    for(i=0 ; i<NUM_DSETS; i++) {

        HDsprintf(dset_name, "dset%d", i);
        if((dset_id = H5Dopen2(grp_id, dset_name, H5P_DEFAULT)) < 0)
            FAIL_STACK_ERROR;

        if(H5Dread(dset_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data) < 0)
            FAIL_STACK_ERROR;

        if(H5Dclose(dset_id) < 0)
            FAIL_STACK_ERROR;

        for (j=0; j < num_elements; j++) {
            if(data[j] != j) {
                HDfprintf(stderr, "Read different values than written\n");
                FAIL_STACK_ERROR;
            }
        }
    }

    if(H5Gclose(grp_id) < 0)
        FAIL_STACK_ERROR;
    if(H5Fclose(file_id) < 0)
        FAIL_STACK_ERROR;
    HDfree(data);

    return 0;

error:
    H5E_BEGIN_TRY {
        H5Gclose(grp_id);
        H5Fclose(file_id);
        if(data)
            HDfree(data);
    } H5E_END_TRY;
    return 1;
}
#endif /* H5_HAVE_PARALLEL */

/*
 *
 *  set_multi_split():
 *      Internal routine to set up page-aligned address space for multi/split driver
 *      when testing paged aggregation.
 *
 */
static unsigned
set_multi_split(const char *env_h5_drvr, hid_t fapl, hsize_t pagesize)
{
    hbool_t split = FALSE;
    hbool_t multi = FALSE;
    H5FD_mem_t memb_map[H5FD_MEM_NTYPES];
    hid_t memb_fapl_arr[H5FD_MEM_NTYPES];
    char *memb_name[H5FD_MEM_NTYPES];
    haddr_t memb_addr[H5FD_MEM_NTYPES];
    hbool_t relax;
    H5FD_mem_t  mt;

    /* Check for split or multi driver */
    if(!HDstrcmp(env_h5_drvr, "split"))
        split = TRUE;
    else if(!HDstrcmp(env_h5_drvr, "multi"))
        multi = TRUE;

    if(split || multi) {

        HDmemset(memb_name, 0, sizeof memb_name);

        /* Get current split settings */
        if(H5Pget_fapl_multi(fapl, memb_map, memb_fapl_arr, memb_name, memb_addr, &relax) < 0)
            TEST_ERROR

        if(split) {
            /* Set memb_addr aligned */
            memb_addr[H5FD_MEM_SUPER] = ((memb_addr[H5FD_MEM_SUPER] + pagesize - 1) / pagesize) * pagesize;
            memb_addr[H5FD_MEM_DRAW] = ((memb_addr[H5FD_MEM_DRAW] + pagesize - 1) / pagesize) * pagesize;
        } else {
            /* Set memb_addr aligned */
            for(mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; mt++)
                memb_addr[mt] = ((memb_addr[mt] + pagesize - 1) / pagesize) * pagesize;
        } /* end else */

        /* Set multi driver with new FAPLs */
        if(H5Pset_fapl_multi(fapl, memb_map, memb_fapl_arr, (const char * const *)memb_name, memb_addr, relax) < 0)
            TEST_ERROR

        /* Free memb_name */
        for(mt = H5FD_MEM_DEFAULT; mt < H5FD_MEM_NTYPES; mt++)
            free(memb_name[mt]);

    } /* end if */

    return 0;

error:
    return 1;

} /* set_multi_split() */

#ifndef H5_HAVE_PARALLEL

/*-------------------------------------------------------------------------
 * Function:    test_args()
 *
 * Purpose:     This test appears to be a quick smoke check directed at:
 *
 *              1) verifying that API errors are caught.
 *
 *              2) verifying that the page buffer behaves more or less 
 *                 as advertized.
 *
 *              Any data mis-matches or unexpected failures or successes
 *              reported by the HDF5 library result in test failure.
 *
 * Return:      0 if test is sucessful
 *              1 if test fails
 *
 * Programmer:  unknown
 *              ?? / ?? / ??
 *
 *-------------------------------------------------------------------------
 */

static unsigned
test_args(hid_t orig_fapl, const char *env_h5_drvr)
{
    char filename[FILENAME_LEN]; /* Filename to use */
    hid_t file_id = -1;          /* File ID */
    hid_t fcpl = -1;
    hid_t fapl = -1;
    herr_t ret;

    TESTING("Settings for Page Buffering");

    h5_fixname(FILENAME[0], orig_fapl, filename, sizeof(filename));

    if((fapl = H5Pcopy(orig_fapl)) < 0) TEST_ERROR

    if((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0)
        TEST_ERROR;


    /* Test setting a page buffer without Paged Aggregation enabled - 
     * should fail 
     */
    if(H5Pset_page_buffer_size(fapl, 512, 0, 0) < 0)
        TEST_ERROR;

    H5E_BEGIN_TRY {
        file_id = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl);
    } H5E_END_TRY;

    if(file_id >= 0)
        TEST_ERROR;


    /* Test setting a page buffer with a size smaller than a single 
     * page size - should fail 
     */
    if(H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_PAGE, 0, (hsize_t)1) < 0)
        TEST_ERROR;

    if(H5Pset_file_space_page_size(fcpl, 512) < 0)
        TEST_ERROR;

    if(H5Pset_page_buffer_size(fapl, 511, 0, 0) < 0)
        TEST_ERROR;

    H5E_BEGIN_TRY {
        file_id = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl);
    } H5E_END_TRY;

    if(file_id >= 0)
        TEST_ERROR;


    /* Test setting a page buffer with sum of min meta and raw 
     * data percentage > 100 - should fail 
     */
    H5E_BEGIN_TRY {
        ret = H5Pset_page_buffer_size(fapl, 512, 50, 51);
    } H5E_END_TRY;

    if(ret >= 0)
        TEST_ERROR;

    if(set_multi_split(env_h5_drvr, fapl, 512)  != 0)
        TEST_ERROR;

    /* Test setting a page buffer with a size equal to a single page size */
    if(H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_PAGE, 0, (hsize_t)1) < 0)
        TEST_ERROR;

    if(H5Pset_file_space_page_size(fcpl, 512) < 0)
        TEST_ERROR;

    if(H5Pset_page_buffer_size(fapl, 512, 0, 0) < 0)
        TEST_ERROR;

    if(create_file(filename, fcpl, fapl) != 0)
        TEST_ERROR;

    if(open_file(filename, fapl, 512, 512) != 0)
        TEST_ERROR;


    /* Test setting a page buffer with a size slightly larger than a 
     * single page size 
     */
    if(H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_PAGE, 0, (hsize_t)1) < 0)
        TEST_ERROR;

    if(H5Pset_file_space_page_size(fcpl, 512) < 0)
        TEST_ERROR;

    if(H5Pset_page_buffer_size(fapl, 513, 0, 0) < 0)
        TEST_ERROR;

    if(create_file(filename, fcpl, fapl) != 0)
        TEST_ERROR;

    if(open_file(filename, fapl, 512, 512) != 0)
        TEST_ERROR;

    if(set_multi_split(env_h5_drvr, fapl, 4194304)  != 0)
        TEST_ERROR;


    /* Test setting a large page buffer size and page size */
    if(H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_PAGE, 0, (hsize_t)1) < 0)
        TEST_ERROR;

    if(H5Pset_file_space_page_size(fcpl, 4194304) < 0)
        TEST_ERROR;

    if(H5Pset_page_buffer_size(fapl, 16777216, 0, 0) < 0)
        TEST_ERROR;

    if(create_file(filename, fcpl, fapl) != 0)
        TEST_ERROR;

    if(open_file(filename, fapl, 4194304, 16777216) != 0)
        TEST_ERROR;

    if(set_multi_split(env_h5_drvr, fapl, 1)  != 0)
        TEST_ERROR;


    /* Test setting a 512 byte page buffer size and page size */
    if(H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_PAGE, 0, (hsize_t)1) < 0)
        TEST_ERROR;

    if(H5Pset_file_space_page_size(fcpl, 512) < 0)
        TEST_ERROR;
    if(H5Pset_page_buffer_size(fapl, 512, 0, 0) < 0)
        TEST_ERROR;
    if(create_file(filename, fcpl, fapl) != 0)
        TEST_ERROR;
    if(open_file(filename, fapl, 512, 512) != 0)
        TEST_ERROR;


    if(H5Pclose(fcpl) < 0)
        FAIL_STACK_ERROR;
    if(H5Pclose(fapl) < 0)
        FAIL_STACK_ERROR;

    PASSED();
    return 0;

error:
    H5E_BEGIN_TRY {
        H5Pclose(fapl);
        H5Pclose(fcpl);
    } H5E_END_TRY;
    return 1;
} /* test_args */


/*-------------------------------------------------------------------------
 * Function:    test_raw_data_handling()
 *
 * Purpose:     The purpose of this function appears to be a smoke check
 *              of raw data reads and writes via the page buffer.
 *
 *              Any data mis-matches or failures reported by the HDF5
 *              library result in test failure.
 *
 * Return:      0 if test is sucessful
 *              1 if test fails
 *
 * Programmer:  unknown
 *              ?? / ?? / ??
 *              
 * Changes:     Added base_page_cnt field as supporting code.  This allows
 *              the test to adjust to the number of page buffer pages
 *              accessed during file open / create.
 *
 *              The test for the value of base_page_cnt just after file 
 *              open exists detect changes in library behavior.  Assuming
 *              any such change is not indicative of other issues, these 
 *              tests can be modified to reflect the change.
 *
 *                                                    JRM -- 2/23/17
 *
 *-------------------------------------------------------------------------
 */

/* Changes due to file space page size has a minimum size of 512 */
static unsigned
test_raw_data_handling(hid_t orig_fapl, const char *env_h5_drvr)
{
    char filename[FILENAME_LEN]; /* Filename to use */
    hid_t file_id = -1;          /* File ID */
    hid_t fcpl = -1;
    hid_t fapl = -1;
    size_t base_page_cnt;
    size_t page_count = 0;
    int i, num_elements = 2000;
    haddr_t addr = HADDR_UNDEF;
    int *data = NULL;
    H5F_t *f = NULL;

    TESTING("Raw Data Handling");

    h5_fixname(FILENAME[0], orig_fapl, filename, sizeof(filename));

    if((fapl = H5Pcopy(orig_fapl)) < 0)
        TEST_ERROR

    if(set_multi_split(env_h5_drvr, fapl, sizeof(int)*200)  != 0)
        TEST_ERROR;

    if((data = (int *)HDcalloc((size_t)num_elements, sizeof(int))) == NULL)
        TEST_ERROR;

    if((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0)
        TEST_ERROR;
    if(H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_PAGE, 0, (hsize_t)1) < 0)
        TEST_ERROR;
    if(H5Pset_file_space_page_size(fcpl, sizeof(int)*200) < 0)
        TEST_ERROR;
    if(H5Pset_page_buffer_size(fapl, sizeof(int)*2000, 0, 0) < 0)
        TEST_ERROR;

    if((file_id = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl)) < 0)
        FAIL_STACK_ERROR;

    /* Get a pointer to the internal file object */
    if(NULL == (f = (H5F_t *)H5VL_object(file_id)))
        FAIL_STACK_ERROR;

    /* opening the file inserts one or more pages into the page buffer.
     * Get the number of pages inserted, and verify that it is the 
     * the expected value.
     */
    base_page_cnt = H5SL_count(f->shared->page_buf->slist_ptr);
    if(base_page_cnt != 1)
        TEST_ERROR;

    /* allocate space for a 2000 elements */
    if(HADDR_UNDEF == (addr = H5MF_alloc(f, H5FD_MEM_DRAW, sizeof(int)*(size_t)num_elements)))
        FAIL_STACK_ERROR;

    /* initialize all the elements to have a value of -1 */
    for(i=0 ; i<num_elements ; i++)
        data[i] = -1;
    if(H5F_block_write(f, H5FD_MEM_DRAW, addr, sizeof(int)*(size_t)num_elements, data) < 0)
        FAIL_STACK_ERROR;

    /* update the first 50 elements to have values 0-49 - this will be
       a page buffer update with 1 page resulting in the page
       buffer. */
    /* Changes: 100 */
    for(i=0 ; i<100 ; i++)
        data[i] = i;

    if(H5F_block_write(f, H5FD_MEM_DRAW, addr, sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    page_count ++;

    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count + base_page_cnt)
        FAIL_STACK_ERROR;

    /* update elements 300 - 450, with values 300 -  - this will
       bring two more pages into the page buffer. */
    for(i=0 ; i<150 ; i++)
        data[i] = i+300;
    if(H5F_block_write(f, H5FD_MEM_DRAW, addr+(sizeof(int)*300), sizeof(int)*150, data) < 0)
        FAIL_STACK_ERROR;
    page_count += 2;
    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count + base_page_cnt)
        FAIL_STACK_ERROR;

    /* update elements 100 - 300, this will go to disk but also update
       existing pages in the page buffer. */
    for(i=0 ; i<200 ; i++)
        data[i] = i+100;
    if(H5F_block_write(f, H5FD_MEM_DRAW, addr+(sizeof(int)*100), sizeof(int)*200, data) < 0)
        FAIL_STACK_ERROR;
    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count + base_page_cnt)
        FAIL_STACK_ERROR;

    /* Update elements 225-300 - this will update an existing page in the PB */
    /* Changes: 450 - 600; 150 */
    for(i=0 ; i<150 ; i++)
        data[i] = i+450;
    if(H5F_block_write(f, H5FD_MEM_DRAW, addr+(sizeof(int)*450), sizeof(int)*150, data) < 0)
        FAIL_STACK_ERROR;
    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count + base_page_cnt)
        FAIL_STACK_ERROR;

    /* Do a full page write to block 600-800 - should bypass the PB */
    for(i=0 ; i<200 ; i++)
        data[i] = i+600;
    if(H5F_block_write(f, H5FD_MEM_DRAW, addr+(sizeof(int)*600), sizeof(int)*200, data) < 0)
        FAIL_STACK_ERROR;
    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count + base_page_cnt)
        FAIL_STACK_ERROR;

    /* read elements 800 - 1200, this should not affect the PB, and should read -1s */
    if(H5F_block_read(f, H5FD_MEM_DRAW, addr+(sizeof(int)*800), sizeof(int)*400, data) < 0)
        FAIL_STACK_ERROR;
    for (i=0; i < 400; i++) {
        if(data[i] != -1) {
            HDfprintf(stderr, "Read different values than written\n");
            FAIL_STACK_ERROR;
        }
    }
    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count + base_page_cnt)
        FAIL_STACK_ERROR;

    /* read elements 1200 - 1201, this should read -1 and bring in an 
     * entire page of addr 1200 
     */
    if(H5F_block_read(f, H5FD_MEM_DRAW, addr+(sizeof(int)*1200), sizeof(int)*1, data) < 0)
        FAIL_STACK_ERROR;
    for (i=0; i < 1; i++) {
        if(data[i] != -1) {
            HDfprintf(stderr, "Read different values than written\n");
            TEST_ERROR;
        }
    }
    page_count ++;
    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count + base_page_cnt)
        TEST_ERROR;

    /* read elements 175 - 225, this should use the PB existing pages */
    /* Changes: 350 - 450 */
    /* read elements 175 - 225, this should use the PB existing pages */
    if(H5F_block_read(f, H5FD_MEM_DRAW, addr+(sizeof(int)*350), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;
    for (i=0; i < 100; i++) {
        if(data[i] != i+350) {
            HDfprintf(stderr, "Read different values than written\n");
            TEST_ERROR;
        }
    }
    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count + base_page_cnt)
        TEST_ERROR;

    /* read elements 0 - 800 using the VFD.. this should result in -1s
       except for the writes that went through the PB (100-300 & 600-800) */
    if(H5FD_read(f->shared->lf, H5FD_MEM_DRAW, addr, sizeof(int)*800, data) < 0)
        FAIL_STACK_ERROR;
    i = 0;
    while (i < 800) {
        if((i>=100 && i<300) || (i>=600)) {
            if(data[i] != i) {
                HDfprintf(stderr, "Read different values than written\n");
                TEST_ERROR;
            }
        }
        else {
            if(data[i] != -1) {
                HDfprintf(stderr, "Read different values than written\n");
                TEST_ERROR;
            }
        }
        i++;
    }

    /* read elements 0 - 800 using the PB.. this should result in all
     * what we have written so far and should get the updates from the PB 
     */
    if(H5F_block_read(f, H5FD_MEM_DRAW, addr, sizeof(int)*800, data) < 0)
        FAIL_STACK_ERROR;
    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count + base_page_cnt)
        TEST_ERROR;
    for (i=0; i < 800; i++) {
        if(data[i] != i) {
            HDfprintf(stderr, "Read different values than written\n");
            TEST_ERROR;
        }
    }

    /* update elements 400 - 1400 to value 0, this will go to disk but
     * also evict existing pages from the PB (page 400 & 1200 that are
     * existing). 
     */
    for(i=0 ; i<1000 ; i++)
        data[i] = 0;
    if(H5F_block_write(f, H5FD_MEM_DRAW, addr+(sizeof(int)*400), sizeof(int)*1000, data) < 0)
        FAIL_STACK_ERROR;
    page_count -= 2;
    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count + base_page_cnt)
        TEST_ERROR;

    /* read elements 0 - 1000.. this should go to disk then update the
     * buffer result 200-400 with existing pages
     */
    if(H5F_block_read(f, H5FD_MEM_DRAW, addr, sizeof(int)*1000, data) < 0)
        FAIL_STACK_ERROR;
    i=0;
    while (i < 1000) {
        if(i<400) {
            if(data[i] != i) {
                HDfprintf(stderr, "Read different values than written\n");
                TEST_ERROR;
            }
        }
        else {
            if(data[i] != 0) {
                HDfprintf(stderr, "Read different values than written\n");
                TEST_ERROR;
            }
        }
        i++;
    }
    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count + base_page_cnt)
        TEST_ERROR;

    if(H5Fclose(file_id) < 0)
        FAIL_STACK_ERROR;
    if(H5Pclose(fcpl) < 0)
        FAIL_STACK_ERROR;
    if(H5Pclose(fapl) < 0)
        FAIL_STACK_ERROR;
    HDfree(data);

    PASSED();
    return 0;

error:
    H5E_BEGIN_TRY {
        H5Pclose(fapl);
        H5Pclose(fcpl);
        H5Fclose(file_id);
        if(data)
            HDfree(data);
    } H5E_END_TRY;
    return 1;
} /* test_raw_data_handling */


/*-------------------------------------------------------------------------
 * Function:    test_lru_processing()
 *
 * Purpose:     Basic set of tests verifying expected page buffer LRU
 *              management.
 *
 *              Any data mis-matches or failures reported by the HDF5
 *              library result in test failure.
 *
 * Return:      0 if test is sucessful
 *              1 if test fails
 *
 * Programmer:  unknown
 *              ?? / ?? / ??
 *              
 * Changes:     Added base_page_cnt field as supporting code.  This allows
 *              the test to adjust to the number of page buffer pages
 *              accessed during file open / create.
 *
 *              The test for the value of base_page_cnt just after file 
 *              open exists detect changes in library behavior.  Assuming
 *              any such change is not indicative of other issues, these 
 *              tests can be modified to reflect the change.
 *
 *                                                    JRM -- 2/23/17
 *
 *
 *-------------------------------------------------------------------------
 */

static unsigned
test_lru_processing(hid_t orig_fapl, const char *env_h5_drvr)
{
    char filename[FILENAME_LEN]; /* Filename to use */
    hid_t file_id = -1;          /* File ID */
    hid_t fcpl = -1;
    hid_t fapl = -1;
    size_t base_page_cnt;
    size_t page_count = 0;
    int i;
    int num_elements = 2000;
    haddr_t addr = HADDR_UNDEF;
    haddr_t search_addr = HADDR_UNDEF;
    int *data = NULL;
    H5F_t *f = NULL;

    TESTING("LRU Processing");

    h5_fixname(FILENAME[0], orig_fapl, filename, sizeof(filename));

    if((fapl = H5Pcopy(orig_fapl)) < 0)
        FAIL_STACK_ERROR

    if(set_multi_split(env_h5_drvr, fapl, sizeof(int)*200)  != 0)
        TEST_ERROR;

    if((data = (int *)HDcalloc((size_t)num_elements, sizeof(int))) == NULL)
        TEST_ERROR;

    if((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0)
        FAIL_STACK_ERROR;

    if(H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_PAGE, 0, (hsize_t)1) < 0)
        FAIL_STACK_ERROR;

    if(H5Pset_file_space_page_size(fcpl, sizeof(int)*200) < 0)
        FAIL_STACK_ERROR;

    /* keep 2 pages at max in the page buffer */
    if(H5Pset_page_buffer_size(fapl, sizeof(int)*400, 20, 0) < 0)
        FAIL_STACK_ERROR;

    if((file_id = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl)) < 0)
        FAIL_STACK_ERROR;

    /* Get a pointer to the internal file object */
    if(NULL == (f = (H5F_t *)H5VL_object(file_id)))
        FAIL_STACK_ERROR;

    /* opening the file inserts one or more pages into the page buffer.
     * Get the number of pages inserted, and verify that it is the 
     * the expected value.
     */
    base_page_cnt = H5SL_count(f->shared->page_buf->slist_ptr);
    if(base_page_cnt != 1)
        TEST_ERROR;

    /* allocate space for a 2000 elements */
    if(HADDR_UNDEF == (addr = H5MF_alloc(f, H5FD_MEM_DRAW, sizeof(int)*(size_t)num_elements)))
        FAIL_STACK_ERROR;

    /* initialize all the elements to have a value of -1 */
    for(i=0 ; i<num_elements ; i++)
        data[i] = -1;

    if(H5F_block_write(f, H5FD_MEM_DRAW, addr, sizeof(int)*(size_t)num_elements, data) < 0)
        FAIL_STACK_ERROR;

    /* update the first 100 elements to have values 0-99 - this will be
     * a page buffer update with 1 page resulting in the page
     * buffer. 
     */
    for(i=0 ; i<100 ; i++)
        data[i] = i;

    if(H5F_block_write(f, H5FD_MEM_DRAW, addr, sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    page_count ++;

    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count + base_page_cnt)
        TEST_ERROR;

    /* update elements 300 - 450, with values 300 - 449 - this will
     * bring two pages into the page buffer and evict 0. 
     */
    for(i=0 ; i<150 ; i++)
        data[i] = i+300;

    if(H5F_block_write(f, H5FD_MEM_DRAW, addr+(sizeof(int)*300), sizeof(int)*150, data) < 0)
        FAIL_STACK_ERROR;

    page_count = 2;

    /* at this point, the page buffer entry created at file open should
     * have been evicted -- thus no further need to consider base_page_cnt.
     */
    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count)
        FAIL_STACK_ERROR;

    /* The two pages should be the ones with address 100 and 200; 0
       should have been evicted */
    /* Changes: 200, 400 */
    search_addr = addr;
    if(NULL != H5SL_search(f->shared->page_buf->slist_ptr, &(search_addr)))
        FAIL_STACK_ERROR;
    search_addr = addr + sizeof(int)*200;
    if(NULL == H5SL_search(f->shared->page_buf->slist_ptr, &(search_addr)))
        FAIL_STACK_ERROR;
    search_addr = addr + sizeof(int)*400;
    if(NULL == H5SL_search(f->shared->page_buf->slist_ptr, &(search_addr)))
        FAIL_STACK_ERROR;

    /* update elements 150-151, this will update existing pages in the
       page buffer and move it to the top of the LRU. */
    /* Changes: 300 - 301 */
    for(i=0 ; i<1 ; i++)
        data[i] = i+300;
    if(H5F_block_write(f, H5FD_MEM_DRAW, addr+(sizeof(int)*300), sizeof(int)*1, data) < 0)
        FAIL_STACK_ERROR;
    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count)
        FAIL_STACK_ERROR;

    /* read elements 600 - 601, this should read -1 and bring in an
       entire page of addr 600, and evict page 200 */
    /* Changes: 1200 - 1201; 1200, 400 */
    if(H5F_block_read(f, H5FD_MEM_DRAW, addr+(sizeof(int)*1200), sizeof(int)*1, data) < 0)
        FAIL_STACK_ERROR;
    for (i=0; i < 1; i++) {
        if(data[i] != -1) {
            HDfprintf(stderr, "Read different values than written\n");
            TEST_ERROR;
        } /* end if */
    } /* end for */
    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count)
        FAIL_STACK_ERROR;

    /* Changes: 400 */
    search_addr = addr + sizeof(int)*400;
    if(NULL != H5SL_search(f->shared->page_buf->slist_ptr, &(search_addr)))
        FAIL_STACK_ERROR;

    /* Changes: 200 */
    search_addr = addr + sizeof(int)*200;
    if(NULL == H5SL_search(f->shared->page_buf->slist_ptr, &(search_addr)))
        FAIL_STACK_ERROR;

    /* Changes: 1200 */
    search_addr = addr + sizeof(int)*1200;
    if(NULL == H5SL_search(f->shared->page_buf->slist_ptr, &(search_addr)))
        FAIL_STACK_ERROR;
    /* read elements 175 - 225, this should move 100 to the top, evict 600 and bring in 200 */
    /* Changes: 350 - 450; 200, 1200, 400 */
    if(H5F_block_read(f, H5FD_MEM_DRAW, addr+(sizeof(int)*350), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;
    for (i=0; i < 100; i++) {
        if(data[i] != i+350) {
            HDfprintf(stderr, "Read different values than written\n");
            TEST_ERROR;
        } /* end if */
    } /* end for */
    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count)
        FAIL_STACK_ERROR;

    /* Changes: 1200 */
    search_addr = addr + sizeof(int)*1200;
    if(NULL != H5SL_search(f->shared->page_buf->slist_ptr, &(search_addr)))
        FAIL_STACK_ERROR;

    /* Changes: 200 */
    search_addr = addr + sizeof(int)*200;
    if(NULL == H5SL_search(f->shared->page_buf->slist_ptr, &(search_addr)))
        FAIL_STACK_ERROR;

    /* Changes: 400 */
    search_addr = addr + sizeof(int)*400;
    if(NULL == H5SL_search(f->shared->page_buf->slist_ptr, &(search_addr)))
        FAIL_STACK_ERROR;

    /* update elements 200 - 700 to value 0, this will go to disk but
       also discarding existing pages from the PB (page 200). */
    /* Changes: 400 - 1400; 400 */
    for(i=0 ; i<1000 ; i++)
        data[i] = 0;
    if(H5F_block_write(f, H5FD_MEM_DRAW, addr+(sizeof(int)*400), sizeof(int)*1000, data) < 0)
        FAIL_STACK_ERROR;
    page_count -= 1;
    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count)
        FAIL_STACK_ERROR;

    /* Changes: 200 */
    search_addr = addr + sizeof(int)*200;
    if(NULL == H5SL_search(f->shared->page_buf->slist_ptr, &(search_addr)))
        FAIL_STACK_ERROR;

    /* Changes: 400 */
    search_addr = addr + sizeof(int)*400;
    if(NULL != H5SL_search(f->shared->page_buf->slist_ptr, &(search_addr)))
        FAIL_STACK_ERROR;

    if(H5Fclose(file_id) < 0)
        FAIL_STACK_ERROR;
    if(H5Pclose(fcpl) < 0)
        FAIL_STACK_ERROR;
    if(H5Pclose(fapl) < 0)
        FAIL_STACK_ERROR;
    HDfree(data);

    PASSED();
    return 0;

error:
    H5E_BEGIN_TRY {
        H5Pclose(fapl);
        H5Pclose(fcpl);
        H5Fclose(file_id);
        if(data)
            HDfree(data);
    } H5E_END_TRY;
    return 1;
} /* test_lru_processing */


/*-------------------------------------------------------------------------
 * Function:    test_min_threshold()
 *
 * Purpose:     Tests verifying observation of minimum and maximum 
 *              raw and metadata page counts in the page buffer.
 *
 *              Any data mis-matches or failures reported by the HDF5
 *              library result in test failure.
 *
 * Return:      0 if test is sucessful
 *              1 if test fails
 *
 * Programmer:  unknown
 *              ?? / ?? / ??
 *              
 * Changes:     Added the base_raw_cnt and base_meta_cnt fields and
 *              supporting code.  This allows the test to adjust to the 
 *              number of page buffer pages accessed during file open / 
 *              create.
 *
 *              The tests for the values of base_raw_cnt and base_meta_cnt
 *              just after file open exist detect changes in library 
 *              behavior.  Assuming any such change is not indicative of 
 *              other issues, these tests can be modified to reflect the 
 *              change.
 *
 *                                                    JRM -- 2/23/17
 *
 *-------------------------------------------------------------------------
 */

static unsigned
test_min_threshold(hid_t orig_fapl, const char *env_h5_drvr)
{
    char filename[FILENAME_LEN]; /* Filename to use */
    hid_t file_id = -1;          /* File ID */
    hid_t fcpl = -1;
    hid_t fapl = -1;
    size_t base_raw_cnt = 0;
    size_t base_meta_cnt = 0;
    size_t page_count = 0;
    int i;
    int num_elements = 1000;
    H5PB_t *page_buf;
    haddr_t meta_addr = HADDR_UNDEF;
    haddr_t raw_addr = HADDR_UNDEF;
    int *data = NULL;
    H5F_t *f = NULL;

    TESTING("Minimum Metadata threshold Processing");
    HDprintf("\n");
    h5_fixname(FILENAME[0], orig_fapl, filename, sizeof(filename));

    if((fapl = H5Pcopy(orig_fapl)) < 0)
        TEST_ERROR

    if(set_multi_split(env_h5_drvr, fapl, sizeof(int)*200)  != 0)
        TEST_ERROR;

    if((data = (int *)HDcalloc((size_t)num_elements, sizeof(int))) == NULL)
        TEST_ERROR;

    if((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0)
        FAIL_STACK_ERROR;

    if(H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_PAGE, 0, (hsize_t)1) < 0)
        FAIL_STACK_ERROR;

    if(H5Pset_file_space_page_size(fcpl, sizeof(int)*200) < 0)
        FAIL_STACK_ERROR;

    HDprintf("\tMinimum metadata threshold = 100%%\n");

    /* keep 5 pages at max in the page buffer and 5 meta page minimum */
    if(H5Pset_page_buffer_size(fapl, sizeof(int)*1000, 100, 0) < 0)
        FAIL_STACK_ERROR;

    /* create the file */
    if((file_id = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl)) < 0)
        FAIL_STACK_ERROR;

    /* Get a pointer to the internal file object */
    if(NULL == (f = (H5F_t *)H5VL_object(file_id)))
        FAIL_STACK_ERROR;

    /* opening the file inserts one or more pages into the page buffer.
     * Get the raw and meta counts now, so we can adjust tests accordingly.
     */
    HDassert(f);
    HDassert(f->shared);
    HDassert(f->shared->page_buf);

    base_raw_cnt = f->shared->page_buf->raw_count;
    base_meta_cnt = f->shared->page_buf->meta_count;

    if(base_raw_cnt != 0)
        TEST_ERROR;

    if(base_meta_cnt != 1)
        TEST_ERROR;

    page_buf = f->shared->page_buf;

    if(page_buf->min_meta_count != 5)
        TEST_ERROR;

    if(page_buf->min_raw_count != 0)
        TEST_ERROR;

    if(HADDR_UNDEF == (meta_addr = H5MF_alloc(f, H5FD_MEM_SUPER, sizeof(int)*(size_t)num_elements)))
        FAIL_STACK_ERROR;

    if(HADDR_UNDEF == (raw_addr = H5MF_alloc(f, H5FD_MEM_DRAW, sizeof(int)*(size_t)num_elements)))
        FAIL_STACK_ERROR;

    /* write all raw data, this would end up in page buffer since there 
     * is no metadata yet
     *
     * Not necessarily -- opening the file may may load a metadata page.
     */
    for(i=0 ; i<100 ; i++)
        data[i] = i;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr, sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*200), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*400), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*600), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*800), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    page_count += 5;

    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count)
        FAIL_STACK_ERROR;

    if(page_buf->raw_count != 5 - base_meta_cnt)
        TEST_ERROR;

    /* write all meta data, this would end up in page buffer */
    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr, sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*200), sizeof(int)*50, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*400), sizeof(int)*50, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_read(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*600), sizeof(int)*50, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_read(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*800), sizeof(int)*50, data) < 0)
        FAIL_STACK_ERROR;

    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count)
        FAIL_STACK_ERROR;

    if(page_buf->meta_count != 5)
        TEST_ERROR;

    if(page_buf->raw_count != 0)
        TEST_ERROR;

    /* write and read more raw data and make sure that they don't end up in
     * page buffer since the minimum metadata is actually the entire
     * page buffer 
     */
    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*200), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*350), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_read(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*500), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_read(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*750), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_read(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*900), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count)
        FAIL_STACK_ERROR;

    if(page_buf->meta_count != 5)
        TEST_ERROR;

    if(page_buf->raw_count != 0)
        TEST_ERROR;

    if(H5Fclose(file_id) < 0)
        FAIL_STACK_ERROR;


    HDprintf("\tMinimum raw data threshold = 100%%\n");

    page_count = 0;

    /* keep 5 pages at max in the page buffer and 5 raw page minimum */
    /* Changes: 1000 */
    if(H5Pset_page_buffer_size(fapl, sizeof(int)*1000, 0, 100) < 0)
        TEST_ERROR;

    /* create the file */
    if((file_id = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl)) < 0)
        FAIL_STACK_ERROR;

    /* Get a pointer to the internal file object */
    if(NULL == (f = (H5F_t *)H5VL_object(file_id)))
        FAIL_STACK_ERROR;

    /* opening the file inserts one or more pages into the page buffer.
     * Get the raw and meta counts now, so we can adjust tests accordingly.
     */
    HDassert(f);
    HDassert(f->shared);
    HDassert(f->shared->page_buf);

    base_raw_cnt = f->shared->page_buf->raw_count;
    base_meta_cnt = f->shared->page_buf->meta_count;

    if(base_raw_cnt != 0)
        TEST_ERROR;

    if(base_meta_cnt != 1)
        TEST_ERROR;

    page_buf = f->shared->page_buf;

    if(page_buf->min_meta_count != 0)
        TEST_ERROR;
    if(page_buf->min_raw_count != 5)
        FAIL_STACK_ERROR;

    if(HADDR_UNDEF == (meta_addr = H5MF_alloc(f, H5FD_MEM_SUPER, sizeof(int)*(size_t)num_elements)))
        FAIL_STACK_ERROR;

    if(HADDR_UNDEF == (raw_addr = H5MF_alloc(f, H5FD_MEM_DRAW, sizeof(int)*(size_t)num_elements)))
        TEST_ERROR;

    /* write all meta data, this would end up in page buffer since there 
     * is no raw data yet
     */
    for(i=0 ; i<100 ; i++)
        data[i] = i;

    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr, sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*200), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*400), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*600), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*800), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    page_count += 5;

    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count)
        FAIL_STACK_ERROR;
    if(page_buf->meta_count != 5 - base_raw_cnt)
        TEST_ERROR;

    /* write/read all raw data, this would end up in page buffer */
    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr, sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*200), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*400), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_read(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*600), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_read(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*800), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count)
        FAIL_STACK_ERROR;

    if(page_buf->raw_count != 5)
        TEST_ERROR;

    if(page_buf->meta_count != 0)
        TEST_ERROR;

    /* write and read more meta data and make sure that they don't end up in
     * page buffer since the minimum metadata is actually the entire
     * page buffer 
     */
    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*100), sizeof(int)*50, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*350), sizeof(int)*50, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_read(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*500), sizeof(int)*50, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_read(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*750), sizeof(int)*50, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_read(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*900), sizeof(int)*50, data) < 0)
        FAIL_STACK_ERROR;

    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count)
        FAIL_STACK_ERROR;

    if(page_buf->raw_count != 5)
        TEST_ERROR;

    if(page_buf->meta_count != 0)
        TEST_ERROR;

    if(H5Fclose(file_id) < 0)
        FAIL_STACK_ERROR;


    HDprintf("\tMinimum metadata threshold = 40%%, Minimum rawdata threshold = 40%%\n");
    page_count = 0;
    /* keep 5 pages at max in the page buffer 2 meta pages, 2 raw pages  
     * minimum 
     */
    if(H5Pset_page_buffer_size(fapl, sizeof(int)*1000, 40, 40) < 0)
        TEST_ERROR;

    /* create the file */
    if((file_id = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl)) < 0)
        FAIL_STACK_ERROR;

    /* Get a pointer to the internal file object */
    if(NULL == (f = (H5F_t *)H5VL_object(file_id)))
        FAIL_STACK_ERROR;

    /* opening the file inserts one or more pages into the page buffer.
     *
     * However, with the current 1 metadata page inserted into the 
     * the page buffer, it is not necessary to track the base raw and 
     * metadata entry counts.
     */

    if(base_raw_cnt != 0)
        TEST_ERROR;

    if(base_meta_cnt != 1)
        TEST_ERROR;
    page_buf = f->shared->page_buf;

    if(page_buf->min_meta_count != 2)
        TEST_ERROR;

    if(page_buf->min_raw_count != 2)
        TEST_ERROR;

    if(HADDR_UNDEF == (meta_addr = H5MF_alloc(f, H5FD_MEM_SUPER, sizeof(int)*(size_t)num_elements)))
        FAIL_STACK_ERROR;

    if(HADDR_UNDEF == (raw_addr = H5MF_alloc(f, H5FD_MEM_DRAW, sizeof(int)*(size_t)num_elements)))
        FAIL_STACK_ERROR;

    /* initialize all the elements to have a value of -1 */
    for(i=0 ; i<num_elements ; i++)
        data[i] = -1;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr, sizeof(int)*(size_t)num_elements, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr, sizeof(int)*(size_t)num_elements, data) < 0)
        FAIL_STACK_ERROR;

    /* fill the page buffer with raw data */
    for(i=0 ; i<100 ; i++)
        data[i] = i;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr, sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*200), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*400), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*600), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*800), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    page_count += 5;

    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count)
        TEST_ERROR;

    if(f->shared->page_buf->raw_count != 5 - base_meta_cnt)
        TEST_ERROR;

    /* add 3 meta entries evicting 3 raw entries */
    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr, sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*200), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*400), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count)
        FAIL_STACK_ERROR;

    if(f->shared->page_buf->meta_count != 3)
        TEST_ERROR;

    if(f->shared->page_buf->raw_count != 2)
        TEST_ERROR;

    /* adding more meta entires should replace meta entries since raw data 
     * is at its minimum 
     */
    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*600), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*800), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(f->shared->page_buf->meta_count != 3)
        TEST_ERROR;

    if(f->shared->page_buf->raw_count != 2)
        TEST_ERROR;

    /* bring existing raw entires up the LRU */
    if(H5F_block_read(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*750), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    /* adding 2 raw entries (even with 1 call) should only evict 1 meta 
     * entry and another raw entry 
     */
    if(H5F_block_read(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*350), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(f->shared->page_buf->meta_count != 2)
        TEST_ERROR;

    if(f->shared->page_buf->raw_count != 3)
        TEST_ERROR;

    /* adding 2 meta entries should replace 2 entires at the bottom of the LRU */
    if(H5F_block_read(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*98), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_read(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*242), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(f->shared->page_buf->meta_count != 2)
        TEST_ERROR;

    if(f->shared->page_buf->raw_count != 3)
        TEST_ERROR;

    if(H5Fclose(file_id) < 0)
        FAIL_STACK_ERROR;

    HDprintf("\tMinimum metadata threshold = 20%%\n");
    page_count = 0;
    /* keep 5 pages at max in the page buffer and 1 meta page minimum */
    if(H5Pset_page_buffer_size(fapl, sizeof(int)*1000, 39, 0) < 0)
        TEST_ERROR;
    /* create the file */
    if((file_id = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl)) < 0)
        FAIL_STACK_ERROR;
    /* Get a pointer to the internal file object */
    if(NULL == (f = (H5F_t *)H5VL_object(file_id)))
        FAIL_STACK_ERROR;
    page_buf = f->shared->page_buf;

    if(page_buf->min_meta_count != 1)
        TEST_ERROR;
    if(page_buf->min_raw_count != 0)
        TEST_ERROR;

    if(HADDR_UNDEF == (meta_addr = H5MF_alloc(f, H5FD_MEM_SUPER, sizeof(int)*(size_t)num_elements)))
        FAIL_STACK_ERROR;

    if(HADDR_UNDEF == (raw_addr = H5MF_alloc(f, H5FD_MEM_DRAW, sizeof(int)*(size_t)num_elements)))
        FAIL_STACK_ERROR;

    /* initialize all the elements to have a value of -1 */
    for(i=0 ; i<num_elements ; i++)
        data[i] = -1;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr, sizeof(int)*(size_t)num_elements, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr, sizeof(int)*(size_t)num_elements, data) < 0)
        FAIL_STACK_ERROR;

    /* fill the page buffer with raw data */
    for(i=0 ; i<100 ; i++)
        data[i] = i;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr, sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*200), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*400), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*600), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*800), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    page_count += 5;

    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count)
        FAIL_STACK_ERROR;

    /* add 2 meta entries evicting 2 raw entries */
    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr, sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*200), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count)
        FAIL_STACK_ERROR;

    if(f->shared->page_buf->meta_count != 2)
        TEST_ERROR;

    if(f->shared->page_buf->raw_count != 3)
        TEST_ERROR;

    /* bring the rest of the raw entries up the LRU */
    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*500), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*700), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*900), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    /* write one more raw entry which replace one meta entry */
    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*100), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count)
        FAIL_STACK_ERROR;

    if(f->shared->page_buf->meta_count != 1)
        TEST_ERROR;

    if(f->shared->page_buf->raw_count != 4)
        TEST_ERROR;

    /* write one more raw entry which should replace another raw entry 
     * keeping min threshold of meta entries 
     */
    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*300), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count)
        FAIL_STACK_ERROR;

    if(f->shared->page_buf->meta_count != 1)
        TEST_ERROR;

    if(f->shared->page_buf->raw_count != 4)
        TEST_ERROR;

    /* write a metadata entry that should replace the metadata entry 
     * at the bottom of the LRU 
     */
    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*500), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5SL_count(f->shared->page_buf->slist_ptr) != page_count)
        FAIL_STACK_ERROR;

    if(f->shared->page_buf->meta_count != 1)
        TEST_ERROR;

    if(f->shared->page_buf->raw_count != 4)
        TEST_ERROR;

    if(H5Fclose(file_id) < 0)
        FAIL_STACK_ERROR;

    if(H5Pclose(fcpl) < 0)
        FAIL_STACK_ERROR;

    if(H5Pclose(fapl) < 0)
        FAIL_STACK_ERROR;

    HDfree(data);

    PASSED();

    return 0;

error:

    H5E_BEGIN_TRY {
        H5Pclose(fapl);
        H5Pclose(fcpl);
        H5Fclose(file_id);
        if(data)
            HDfree(data);
    } H5E_END_TRY;

    return 1;

} /* test_min_threshold */


/*-------------------------------------------------------------------------
 * Function:    test_stats_collection()
 *
 * Purpose:     Tests verifying correct collection of statistics
 *              by the page buffer.
 *
 *              Any data mis-matches or failures reported by the HDF5
 *              library result in test failure.
 *
 * Return:      0 if test is sucessful
 *              1 if test fails
 *
 * Programmer:  unknown
 *              ?? / ?? / ??
 *              
 * Changes:     Added the base_raw_cnt and base_meta_cnt fields and
 *              supporting code.  This allows the test to adjust to the 
 *              number of page buffer pages accessed during file open / 
 *              create.
 *
 *              The tests for the values of base_raw_cnt and base_meta_cnt
 *              just after file open exist detect changes in library 
 *              behavior.  Assuming any such change is not indicative of 
 *              other issues, these tests can be modified to reflect the 
 *              change.
 *
 *                                                    JRM -- 2/23/17
 *
 *-------------------------------------------------------------------------
 */
static unsigned
test_stats_collection(hid_t orig_fapl, const char *env_h5_drvr)
{
    char filename[FILENAME_LEN]; /* Filename to use */
    hid_t file_id = -1;          /* File ID */
    hid_t fcpl = -1;
    hid_t fapl = -1;
    int i;
    int num_elements = 1000;
    size_t base_raw_cnt = 0;
    size_t base_meta_cnt = 0;
    haddr_t meta_addr = HADDR_UNDEF;
    haddr_t raw_addr = HADDR_UNDEF;
    int *data = NULL;
    H5F_t *f = NULL;

    TESTING("Statistics Collection");

    h5_fixname(FILENAME[0], orig_fapl, filename, sizeof(filename));

    if((fapl = H5Pcopy(orig_fapl)) < 0)
        TEST_ERROR

    if(set_multi_split(env_h5_drvr, fapl, sizeof(int)*200)  != 0)
        TEST_ERROR;

    if((data = (int *)HDcalloc((size_t)num_elements, sizeof(int))) == NULL)
        TEST_ERROR

    if((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0)
        TEST_ERROR;

    if(H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_PAGE, 0, (hsize_t)1) < 0)
        TEST_ERROR;

    if(H5Pset_file_space_page_size(fcpl, sizeof(int)*200) < 0)
        TEST_ERROR;

    /* keep 5 pages at max in the page buffer */
    if(H5Pset_page_buffer_size(fapl, sizeof(int)*1000, 20, 0) < 0)
        TEST_ERROR;

    if((file_id = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl)) < 0)
        FAIL_STACK_ERROR;

    /* Get a pointer to the internal file object */
    if(NULL == (f = (H5F_t *)H5VL_object(file_id)))
        FAIL_STACK_ERROR;

    /* opening the file inserts one or more pages into the page buffer.
     * Get the raw and meta counts now, so we can adjust the expected 
     * statistics accordingly.
     */
    HDassert(f);
    HDassert(f->shared);
    HDassert(f->shared->page_buf);

    base_raw_cnt = f->shared->page_buf->raw_count;
    base_meta_cnt = f->shared->page_buf->meta_count;

    if(base_raw_cnt != 0)
        TEST_ERROR;

    if(base_meta_cnt != 1)
        TEST_ERROR;

    /* reset statistics before we begin the tests */
    if(H5Freset_page_buffering_stats(file_id) < 0)
        FAIL_STACK_ERROR;

    if(HADDR_UNDEF == (meta_addr = H5MF_alloc(f, H5FD_MEM_SUPER, sizeof(int)*(size_t)num_elements)))
        FAIL_STACK_ERROR;

    if(HADDR_UNDEF == (raw_addr = H5MF_alloc(f, H5FD_MEM_DRAW, sizeof(int)*(size_t)num_elements)))
        FAIL_STACK_ERROR;


    /* initialize all the elements to have a value of -1 */
    for(i=0 ; i<num_elements ; i++)
        data[i] = -1;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr, sizeof(int)*(size_t)num_elements, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr, sizeof(int)*(size_t)num_elements, data) < 0)
        FAIL_STACK_ERROR;

    for(i=0 ; i<200 ; i++)
        data[i] = i;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr, sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*200), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*400), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr, sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*200), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*600), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*800), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*600), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*500), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*700), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*900), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*400), sizeof(int)*200, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*100), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*300), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_write(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*800), sizeof(int)*182, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_read(f, H5FD_MEM_DRAW, raw_addr, sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_read(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*200), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_read(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*400), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_read(f, H5FD_MEM_SUPER, meta_addr, sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_read(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*200), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_read(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*600), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_read(f, H5FD_MEM_DRAW, raw_addr+(sizeof(int)*800), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_read(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*400), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_read(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*600), sizeof(int)*200, data) < 0)
        FAIL_STACK_ERROR;

    if(H5F_block_read(f, H5FD_MEM_SUPER, meta_addr+(sizeof(int)*800), sizeof(int)*100, data) < 0)
        FAIL_STACK_ERROR;

    if(f->shared->page_buf->accesses[0] != 8)
        TEST_ERROR;
    if(f->shared->page_buf->accesses[1] != 16)
        TEST_ERROR;

    if(f->shared->page_buf->bypasses[0] != 3)
        TEST_ERROR;
    if(f->shared->page_buf->bypasses[1] != 1)
        TEST_ERROR;

    if(f->shared->page_buf->hits[0] != 0)
        TEST_ERROR;
    if(f->shared->page_buf->hits[1] != 4)
        TEST_ERROR;

    if(f->shared->page_buf->misses[0] != 8)
        TEST_ERROR;
    if(f->shared->page_buf->misses[1] != 11)
        TEST_ERROR;

    if(f->shared->page_buf->evictions[0] != 5 + base_meta_cnt)
        TEST_ERROR;
    if(f->shared->page_buf->evictions[1] != 9 + base_raw_cnt)
        TEST_ERROR;

    {
        unsigned accesses[2];
        unsigned hits[2];
        unsigned misses[2];
        unsigned evictions[2];
        unsigned bypasses[2];

        if(H5Fget_page_buffering_stats(file_id, accesses, hits, misses, evictions, bypasses) < 0)
            FAIL_STACK_ERROR;

        if(accesses[0] != 8)
            TEST_ERROR;
        if(accesses[1] != 16)
            TEST_ERROR;
        if(bypasses[0] != 3)
            TEST_ERROR;
        if(bypasses[1] != 1)
            TEST_ERROR;
        if(hits[0] != 0)
            TEST_ERROR;
        if(hits[1] != 4)
            TEST_ERROR;
        if(misses[0] != 8)
            TEST_ERROR;
        if(misses[1] != 11)
            TEST_ERROR;
        if(evictions[0] != 5 + base_meta_cnt)
            TEST_ERROR;
        if(evictions[1] != 9 + base_raw_cnt)
            TEST_ERROR;

        if(H5Freset_page_buffering_stats(file_id) < 0)
            FAIL_STACK_ERROR;
        if(H5Fget_page_buffering_stats(file_id, accesses, hits, misses, evictions, bypasses) < 0)
            FAIL_STACK_ERROR;

        if(accesses[0] != 0)
            TEST_ERROR;
        if(accesses[1] != 0)
            TEST_ERROR;
        if(bypasses[0] != 0)
            TEST_ERROR;
        if(bypasses[1] != 0)
            TEST_ERROR;
        if(hits[0] != 0)
            TEST_ERROR;
        if(hits[1] != 0)
            TEST_ERROR;
        if(misses[0] != 0)
            TEST_ERROR;
        if(misses[1] != 0)
            TEST_ERROR;
        if(evictions[0] != 0)
            TEST_ERROR;
        if(evictions[1] != 0)
            TEST_ERROR;
    } /* end block */

    if(H5Fclose(file_id) < 0)
        FAIL_STACK_ERROR;
    if(H5Pclose(fcpl) < 0)
        FAIL_STACK_ERROR;
    if(H5Pclose(fapl) < 0)
        FAIL_STACK_ERROR;
    HDfree(data);


    PASSED();
    return 0;

error:
    H5E_BEGIN_TRY {
        H5Pclose(fapl);
        H5Pclose(fcpl);
        H5Fclose(file_id);
        if(data)
            HDfree(data);
    } H5E_END_TRY;

    return 1;
} /* test_stats_collection */
#endif /* #ifndef H5_HAVE_PARALLEL */


/*-------------------------------------------------------------------------
 * Function:    verify_page_buffering_disabled()
 *
 * Purpose:     This function should only be called in parallel 
 *              builds.
 *
 *              At present, page buffering should be disabled in parallel
 *              builds.  Verify this.
 *
 * Return:      0 if test is sucessful
 *              1 if test fails
 *
 * Programmer:  John Mainzer
 *              03/21/17
 *              
 * Changes:     None.
 *
 *-------------------------------------------------------------------------
 */

#ifdef H5_HAVE_PARALLEL
static unsigned
verify_page_buffering_disabled(hid_t orig_fapl, const char *env_h5_drvr)
{
    char filename[FILENAME_LEN]; /* Filename to use */
    hid_t file_id = -1;          /* File ID */
    hid_t fcpl = -1;
    hid_t fapl = -1;

    TESTING("Page Buffering Disabled");
    h5_fixname(FILENAME[0], orig_fapl, filename, sizeof(filename));


    /* first, try to create a file with page buffering enabled */

    if((fapl = H5Pcopy(orig_fapl)) < 0)
        TEST_ERROR

    if(set_multi_split(env_h5_drvr, fapl, 4096)  != 0)
        TEST_ERROR;

    if((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0)
        FAIL_STACK_ERROR;

    if(H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_PAGE, 0, (hsize_t)1) < 0)
        FAIL_STACK_ERROR;

    if(H5Pset_file_space_page_size(fcpl, 4096) < 0)
        FAIL_STACK_ERROR;

    if(H5Pset_page_buffer_size(fapl, 4096*8, 0, 0) < 0)
        FAIL_STACK_ERROR;

    /* try to create  the file -- should fail */
    H5E_BEGIN_TRY {
        file_id = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl);
    } H5E_END_TRY;

    if(file_id >= 0)
        TEST_ERROR;

    /* now, create a file, close it, and then try to open it with page 
     * buffering enabled.
     */
    if((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0)
        FAIL_STACK_ERROR;

    if(H5Pset_file_space_strategy(fcpl, H5F_FSPACE_STRATEGY_PAGE, 0, (hsize_t)1) < 0)
        FAIL_STACK_ERROR;

    if(H5Pset_file_space_page_size(fcpl, 4096) < 0)
        FAIL_STACK_ERROR;

    /* create the file */
    if((file_id = H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, H5P_DEFAULT)) < 0)
        FAIL_STACK_ERROR;

    /* close the file */
    if(H5Fclose(file_id) < 0)
        FAIL_STACK_ERROR;

    /* try to open the file using the fapl prepared above which enables 
     * page buffering.  Should fail.
     */
    H5E_BEGIN_TRY {
        file_id = H5Fopen(filename, H5F_ACC_RDWR, fapl);
    } H5E_END_TRY;

    if(file_id >= 0)
        TEST_ERROR;

    if(H5Pclose(fcpl) < 0)
        FAIL_STACK_ERROR;

    if(H5Pclose(fapl) < 0)
        FAIL_STACK_ERROR;

    PASSED();

    return 0;

error:

    H5E_BEGIN_TRY {
        H5Pclose(fapl);
        H5Pclose(fcpl);
        H5Fclose(file_id);
    } H5E_END_TRY;

    return 1;

} /* verify_page_buffering_disabled() */
#endif /* H5_HAVE_PARALLEL */


/*-------------------------------------------------------------------------
 * Function:    main()
 *
 * Purpose:     Main function for the page buffer tests.
 *
 * Return:      0 if test is sucessful
 *              1 if test fails
 *
 * Programmer:  unknown
 *              ?? / ?? / ??
 *
 *-------------------------------------------------------------------------
 */
int
main(void)
{
    hid_t       fapl = -1;              /* File access property list for data files */
    unsigned    nerrors = 0;            /* Cumulative error count */
    const char  *env_h5_drvr = NULL;    /* File Driver value from environment */
    hbool_t     api_ctx_pushed = FALSE;             /* Whether API context pushed */

    h5_reset();

    /* Get the VFD to use */
    env_h5_drvr = HDgetenv("HDF5_DRIVER");
    if(env_h5_drvr == NULL)
        env_h5_drvr = "nomatch";

    /* Temporary skip testing with multi/split drivers:
     * Page buffering depends on paged aggregation which is
     * currently disabled for multi/split drivers.
     */
    if((0 == HDstrcmp(env_h5_drvr, "multi")) || 
       (0 == HDstrcmp(env_h5_drvr, "split"))) {

        SKIPPED()
        HDputs("Skip page buffering test because paged aggregation is disabled for multi/split drivers");
        HDexit(EXIT_SUCCESS);
    } /* end if */

    if((fapl = h5_fileaccess()) < 0) {
        nerrors++;
        PUTS_ERROR("Can't get VFD-dependent fapl")
    } /* end if */

    /* Push API context */
    if(H5CX_push() < 0) FAIL_STACK_ERROR
    api_ctx_pushed = TRUE;

#ifdef H5_HAVE_PARALLEL 

    HDputs("Page Buffering is disabled for parallel.");
    nerrors += verify_page_buffering_disabled(fapl, env_h5_drvr);

#else /* H5_HAVE_PARALLEL */

    nerrors += test_args(fapl, env_h5_drvr);
    nerrors += test_raw_data_handling(fapl, env_h5_drvr);
    nerrors += test_lru_processing(fapl, env_h5_drvr);
    nerrors += test_min_threshold(fapl, env_h5_drvr);
    nerrors += test_stats_collection(fapl, env_h5_drvr);

#endif /* H5_HAVE_PARALLEL */

    h5_clean_files(FILENAME, fapl);

    if(nerrors)
        goto error;

    /* Pop API context */
    if(api_ctx_pushed && H5CX_pop() < 0) FAIL_STACK_ERROR
    api_ctx_pushed = FALSE;

    HDputs("All Page Buffering tests passed.");

    HDexit(EXIT_SUCCESS);

error:
    HDprintf("***** %d Page Buffering TEST%s FAILED! *****\n",
        nerrors, nerrors > 1 ? "S" : "");

    H5E_BEGIN_TRY {
        H5Pclose(fapl);
    } H5E_END_TRY;

    if(api_ctx_pushed) H5CX_pop();

    HDexit(EXIT_FAILURE);
} /* main() */