Beispiel #1
0
static svn_error_t *
test_spillbuf__basic(apr_pool_t *pool, apr_size_t len, svn_spillbuf_t *buf)
{
  int i;
  const char *readptr;
  apr_size_t readlen;

  /* It starts empty.  */
  SVN_TEST_ASSERT(svn_spillbuf__get_size(buf) == 0);

  /* Place enough data into the buffer to cause a spill to disk.  */
  for (i = 20; i--; )
    SVN_ERR(svn_spillbuf__write(buf, basic_data, len, pool));

  /* And now has content.  */
  SVN_TEST_ASSERT(svn_spillbuf__get_size(buf) > 0);

  /* Verify that we can read 20 copies of basic_data from the buffer.  */
  for (i = 20; i--; )
    CHECK_READ(buf, (i + 1) * len, basic_data, pool);

  /* And after precisely 20 reads, it should be empty.  */
  SVN_ERR(svn_spillbuf__read(&readptr, &readlen, buf, pool));
  SVN_TEST_ASSERT(readptr == NULL);
  SVN_TEST_ASSERT(svn_spillbuf__get_size(buf) == 0);

  return SVN_NO_ERROR;
}
Beispiel #2
0
static svn_error_t *
test_spillbuf__file_attrs(apr_pool_t *pool, svn_boolean_t spill_all,
                          svn_spillbuf_t *buf)
{
  apr_finfo_t finfo;

  SVN_ERR(svn_spillbuf__write(buf, "abcdef", 6, pool));
  SVN_ERR(svn_spillbuf__write(buf, "ghijkl", 6, pool));
  SVN_ERR(svn_spillbuf__write(buf, "mnopqr", 6, pool));

  /* Check that the spillbuf size is what we expect it to be */
  SVN_TEST_ASSERT(svn_spillbuf__get_size(buf) == 18);

  /* Check file existence */
  SVN_TEST_ASSERT(svn_spillbuf__get_filename(buf) != NULL);
  SVN_TEST_ASSERT(svn_spillbuf__get_file(buf) != NULL);

  /* The size of the file must match expectations */
  SVN_ERR(svn_io_file_info_get(&finfo, APR_FINFO_SIZE,
                               svn_spillbuf__get_file(buf), pool));
  if (spill_all)
    SVN_TEST_ASSERT(finfo.size == svn_spillbuf__get_size(buf));
  else
    SVN_TEST_ASSERT(finfo.size == (svn_spillbuf__get_size(buf)
                                   - svn_spillbuf__get_memory_size(buf)));
  return SVN_NO_ERROR;
}
Beispiel #3
0
static svn_error_t *
test_spillbuf__interleaving(apr_pool_t *pool, svn_spillbuf_t* buf)
{
  SVN_ERR(svn_spillbuf__write(buf, "abcdef", 6, pool));
  SVN_ERR(svn_spillbuf__write(buf, "ghijkl", 6, pool));
  /* now: two blocks: 8 and 4 bytes  */

  CHECK_READ(buf, 12, "abcdefgh", pool);
  /* now: one block: 4 bytes  */

  SVN_ERR(svn_spillbuf__write(buf, "mnopqr", 6, pool));
  /* now: two blocks: 8 and 2 bytes  */

  CHECK_READ(buf, 10, "ijklmnop", pool);
  /* now: one block: 2 bytes  */

  SVN_ERR(svn_spillbuf__write(buf, "stuvwx", 6, pool));
  SVN_ERR(svn_spillbuf__write(buf, "ABCDEF", 6, pool));
  SVN_ERR(svn_spillbuf__write(buf, "GHIJKL", 6, pool));
  /* now: two blocks: 8 and 6 bytes, and 6 bytes spilled to a file  */

  CHECK_READ(buf, 20, "qrstuvwx", pool);
  CHECK_READ(buf, 12, "ABCDEF", pool);
  CHECK_READ(buf, 6, "GHIJKL", pool);

  SVN_TEST_ASSERT(svn_spillbuf__get_size(buf) == 0);

  return SVN_NO_ERROR;
}
Beispiel #4
0
static svn_error_t *
test_spillbuf_eof(apr_pool_t *pool)
{
  svn_spillbuf_t *buf = svn_spillbuf__create(4 /* blocksize */,
                                             10 /* maxsize */,
                                             pool);

  SVN_ERR(svn_spillbuf__write(buf, "abcdef", 6, pool));
  SVN_ERR(svn_spillbuf__write(buf, "ghijkl", 6, pool));
  /* now: two blocks: 4 and 2 bytes, and 6 bytes in spill file.  */

  CHECK_READ(buf, 12, "abcd", pool);
  CHECK_READ(buf, 8, "ef", pool);
  CHECK_READ(buf, 6, "ghij", pool);
  CHECK_READ(buf, 2, "kl", pool);
  /* The spill file should have been emptied and forgotten.  */

  /* Assuming the spill file has been forgotten, this should result in
     precisely the same behavior. Specifically: the initial write should
     create two blocks, and the second write should be spilled. If there
     *was* a spill file, then this written data would go into the file.  */
  SVN_ERR(svn_spillbuf__write(buf, "abcdef", 6, pool));
  SVN_ERR(svn_spillbuf__write(buf, "ghijkl", 6, pool));
  CHECK_READ(buf, 12, "abcd", pool);
  CHECK_READ(buf, 8, "ef", pool);
  CHECK_READ(buf, 6, "ghij", pool);
  CHECK_READ(buf, 2, "kl", pool);
  /* The spill file should have been emptied and forgotten.  */

  /* Now, let's do a sequence where we arrange to hit EOF precisely on
     a block-sized read. Note: the second write must be more than 4 bytes,
     or it will not cause a spill. We use 8 to get the right boundary.  */
  SVN_ERR(svn_spillbuf__write(buf, "abcdef", 6, pool));
  SVN_ERR(svn_spillbuf__write(buf, "ghijklmn", 8, pool));
  CHECK_READ(buf, 14, "abcd", pool);
  CHECK_READ(buf, 10, "ef", pool);
  CHECK_READ(buf, 8, "ghij", pool);
  CHECK_READ(buf, 4, "klmn", pool);
  /* We discard the spill file when we know it has no data, rather than
     upon hitting EOF (upon a read attempt). Thus, the spill file should
     be gone.  */

  /* Verify the forgotten spill file.  */
  SVN_ERR(svn_spillbuf__write(buf, "abcdef", 6, pool));
  SVN_ERR(svn_spillbuf__write(buf, "ghijkl", 6, pool));
  CHECK_READ(buf, 12, "abcd", pool);
  CHECK_READ(buf, 8, "ef", pool);
  CHECK_READ(buf, 6, "ghij", pool);
  /* Two unread bytes remaining in the spill file.  */
  SVN_TEST_ASSERT(svn_spillbuf__get_size(buf) == 2);

  return SVN_NO_ERROR;
}
Beispiel #5
0
static svn_error_t *
check_read(svn_spillbuf_t *buf,
           svn_filesize_t starting_size,
           const char *expected,
           apr_pool_t *scratch_pool)
{
  apr_size_t expected_len = strlen(expected);
  const char *readptr;
  apr_size_t readlen;

  SVN_TEST_ASSERT(svn_spillbuf__get_size(buf) == starting_size);
  SVN_ERR(svn_spillbuf__read(&readptr, &readlen, buf, scratch_pool));
  SVN_TEST_ASSERT(readptr != NULL
                  && readlen == expected_len
                  && memcmp(readptr, expected, expected_len) == 0);
  return SVN_NO_ERROR;
}
Beispiel #6
0
static svn_error_t *
test_spillbuf__file(apr_pool_t *pool, apr_size_t altsize, svn_spillbuf_t *buf)
{
  int i;
  const char *readptr;
  apr_size_t readlen;
  apr_size_t cur_index;

  /* Place enough data into the buffer to cause a spill to disk. Note that
     we are writing data that is *smaller* than the blocksize.  */
  for (i = 7; i--; )
    SVN_ERR(svn_spillbuf__write(buf, basic_data, sizeof(basic_data), pool));

  /* The first two reads will be in-memory blocks (the third write causes
     the spill to disk). The spillbuf will pack the content into BLOCKSIZE
     blocks. The second/last memory block will (thus) be a bit smaller.  */
  SVN_ERR(svn_spillbuf__read(&readptr, &readlen, buf, pool));
  SVN_TEST_ASSERT(readptr != NULL);
  SVN_TEST_ASSERT(readlen == altsize);
  SVN_ERR(svn_spillbuf__read(&readptr, &readlen, buf, pool));
  SVN_TEST_ASSERT(readptr != NULL);
  /* The second write put sizeof(basic_data) into the buffer. A small
     portion was stored at the end of the memblock holding the first write.
     Thus, the size of this read will be the written data, minus that
     slice written to the first block.  */
  SVN_TEST_ASSERT(readlen
                  == sizeof(basic_data) - (altsize - sizeof(basic_data)));

  /* Current index into basic_data[] that we compare against.  */
  cur_index = 0;

  while (TRUE)
    {
      /* This will read more bytes (from the spill file into a temporary
         in-memory block) than the blocks of data that we wrote. This makes
         it trickier to verify that the right data is being returned.  */
      SVN_ERR(svn_spillbuf__read(&readptr, &readlen, buf, pool));
      if (readptr == NULL)
        break;

      while (TRUE)
        {
          apr_size_t amt;

          /* Compute the slice of basic_data that we will compare against,
             given the readlen and cur_index.  */
          if (cur_index + readlen >= sizeof(basic_data))
            amt = sizeof(basic_data) - cur_index;
          else
            amt = readlen;
          SVN_TEST_ASSERT(memcmp(readptr, &basic_data[cur_index], amt) == 0);
          if ((cur_index += amt) == sizeof(basic_data))
            cur_index = 0;
          if ((readlen -= amt) == 0)
            break;
          readptr += amt;
        }
    }

  SVN_TEST_ASSERT(svn_spillbuf__get_size(buf) == 0);

  return SVN_NO_ERROR;
}