*-------------------------------------------------------------------------
H5F_io_info_t fio_info; /* I/O info for operation */
unsigned nerrors = 0; /* track errors */
puts("Testing the metadata accumulator");
HDputs("Testing the metadata accumulator");
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
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
puts("All metadata accumulator tests passed.");
HDputs("All metadata accumulator tests passed.");
puts("*** TESTS FAILED ***");
HDputs("*** TESTS FAILED ***");
/* ============================= */
/* Individual Unit Test Routines */
/* ============================= */
/*-------------------------------------------------------------------------
* Function: test_write_read
test_write_read(const H5F_io_info_t *fio_info)
int *write_buf, *read_buf;
TESTING("simple write/read to/from metadata accumulator");
write_buf = (int *)HDmalloc(1024 * sizeof(int));
read_buf = (int *)HDcalloc(1024, sizeof(int));
read_buf = (int *)HDcalloc((size_t)1024, sizeof(int));
/* Fill buffer with data, zero out read buffer */
for(i = 0; i < 1024; i++)
/* 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(HDmemcmp(write_buf, read_buf, (size_t)1024) != 0) TEST_ERROR;
if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;
test_write_read_nonacc_front(const H5F_io_info_t *fio_info)
int *write_buf, *read_buf;
TESTING("simple write/read to/from before metadata accumulator");
write_buf = (int *)HDmalloc(2048 * sizeof(int));
read_buf = (int *)HDcalloc(2048, sizeof(int));
read_buf = (int *)HDcalloc((size_t)2048, sizeof(int));
/* Fill buffer with data, zero out read buffer */
for(i = 0; i < 2048; i++)
/* 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(HDmemcmp(write_buf, read_buf, (size_t)1024) != 0) TEST_ERROR;
if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;
test_write_read_nonacc_end(const H5F_io_info_t *fio_info)
int *write_buf, *read_buf;
TESTING("simple write/read to/from after metadata accumulator");
write_buf = (int *)HDmalloc(2048 * sizeof(int));
read_buf = (int *)HDcalloc(2048, sizeof(int));
read_buf = (int *)HDcalloc((size_t)2048, sizeof(int));
/* Fill buffer with data, zero out read buffer */
for(i = 0; i < 2048; i++)
/* 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(HDmemcmp(write_buf, read_buf, (size_t)1024) != 0) TEST_ERROR;
if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;
test_accum_overlap(const H5F_io_info_t *fio_info)
TESTING("overlapping write to metadata accumulator");
wbuf = (int32_t *)HDmalloc(4096 * sizeof(int32_t));
rbuf = (int32_t *)HDcalloc(4096, sizeof(int32_t));
rbuf = (int32_t *)HDcalloc((size_t)4096, sizeof(int32_t));
/* Case 1: No metadata in accumulator */
/* Write 10 1's at address 40 */
/* Put some data in the accumulator initially */
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;
test_accum_overlap_clean(const H5F_io_info_t *fio_info)
TESTING("overlapping write to partially clean metadata accumulator");
wbuf = (int32_t *)HDmalloc(4096 * sizeof(int32_t));
rbuf = (int32_t *)HDcalloc(4096, sizeof(int32_t));
rbuf = (int32_t *)HDcalloc((size_t)4096, sizeof(int32_t));
/* Case 1: No metadata in accumulator */
/* Write 10 1's at address 40 */
/* Put some data in the accumulator initially */
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;
test_accum_non_overlap_size(const H5F_io_info_t *fio_info)
TESTING("non-overlapping write to accumulator larger then accum_size");
wbuf = (int *)HDmalloc(4096 * sizeof(int32_t));
rbuf = (int *)HDcalloc(4096, sizeof(int32_t));
rbuf = (int *)HDcalloc((size_t)4096, sizeof(int32_t));
/* Case 1: No metadata in accumulator */
/* Write 10 1's at address 140 */
/* Put some data in the accumulator initially */
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;
test_accum_overlap_size(const H5F_io_info_t *fio_info)
TESTING("overlapping write to accumulator larger then accum_size");
wbuf = (int32_t *)HDmalloc(4096 * sizeof(int32_t));
rbuf = (int32_t *)HDcalloc(4096, sizeof(int32_t));
rbuf = (int32_t *)HDcalloc((size_t)4096, sizeof(int32_t));
/* Case 1: No metadata in accumulator */
/* Write 10 1's at address 64 */
/* Put some data in the accumulator initially */
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;
/* ==> 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;
if(HDmemcmp(wbuf, rbuf, (size_t)((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;
if(HDmemcmp(wbuf, rbuf, (size_t)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
/* ==> 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(HDmemcmp(wbuf, rbuf, (size_t)1048576) != 0) TEST_ERROR;
if(accum_read(5, 1048571, rbuf) < 0) FAIL_STACK_ERROR;
if(HDmemcmp(wbuf, rbuf, 1048571) != 0) TEST_ERROR;
if(HDmemcmp(wbuf, rbuf, (size_t)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
/* ==> 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
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;
if(HDmemcmp(wbuf, rbuf, (size_t)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),
/* ==> 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
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(HDmemcmp(wbuf, rbuf, (size_t)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) */
/* ==> 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
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;
if(HDmemcmp(wbuf, rbuf, (size_t)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
/* ==> 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
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(HDmemcmp(wbuf, rbuf, (size_t)349523) != 0) TEST_ERROR;
if(accum_reset(fio_info) < 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 */
/* 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(HDmemcmp(wbuf, rbuf, (size_t)128) != 0) TEST_ERROR;
if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;
*-------------------------------------------------------------------------
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);
wbuf = (uint8_t *)HDmalloc((size_t)BIG_BUF_SIZE);
wbuf2 = (uint8_t *)HDmalloc(BIG_BUF_SIZE);
wbuf2 = (uint8_t *)HDmalloc((size_t)BIG_BUF_SIZE);
rbuf = (uint8_t *)HDcalloc(BIG_BUF_SIZE + 1536, 1);
rbuf = (uint8_t *)HDcalloc((size_t)(BIG_BUF_SIZE + 1536), (size_t)1);
zbuf = (uint8_t *)HDcalloc(BIG_BUF_SIZE + 1536, 1);
zbuf = (uint8_t *)HDcalloc((size_t)(BIG_BUF_SIZE + 1536), (size_t)1);
/* Initialize write buffers */
for(u = 0; u < BIG_BUF_SIZE; u++) {
wbuf2[u] = (uint8_t)(u + 1);
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;
if(HDmemcmp(wbuf, rbuf, BIG_BUF_SIZE) != 0) TEST_ERROR;
if(HDmemcmp(wbuf, rbuf, (size_t)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);
HDmemset(rbuf, 0, (size_t)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;
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;
if(HDmemcmp(zbuf, rbuf, (size_t)1024) != 0) TEST_ERROR;
if(HDmemcmp(wbuf, rbuf + 1024, (size_t)1024) != 0) TEST_ERROR;
if(HDmemcmp(zbuf, rbuf + 2048, (size_t)(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);
HDmemset(rbuf, 0, (size_t)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;
if(HDmemcmp(zbuf, rbuf, (BIG_BUF_SIZE - 512)) != 0) TEST_ERROR;
if(HDmemcmp(wbuf, rbuf + (BIG_BUF_SIZE - 512), 512) != 0) TEST_ERROR;
if(HDmemcmp(zbuf, rbuf, (size_t)(BIG_BUF_SIZE - 512)) != 0) TEST_ERROR;
if(HDmemcmp(wbuf, rbuf + (BIG_BUF_SIZE - 512), (size_t)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);
HDmemset(rbuf, 0, (size_t)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;
if(HDmemcmp(wbuf + 512, rbuf, 512) != 0) TEST_ERROR;
if(HDmemcmp(zbuf, rbuf + 512, (BIG_BUF_SIZE - 512)) != 0) TEST_ERROR;
if(HDmemcmp(wbuf + 512, rbuf, (size_t)512) != 0) TEST_ERROR;
if(HDmemcmp(zbuf, rbuf + 512, (size_t)(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);
HDmemset(rbuf, 0, (size_t)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;
if(HDmemcmp(wbuf2, rbuf, BIG_BUF_SIZE) != 0) TEST_ERROR;
if(HDmemcmp(wbuf2, rbuf, (size_t)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);
HDmemset(rbuf, 0, (size_t)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;
if(HDmemcmp(wbuf2, rbuf, BIG_BUF_SIZE) != 0) TEST_ERROR;
if(HDmemcmp(wbuf + 512, rbuf + BIG_BUF_SIZE, 512) != 0) TEST_ERROR;
if(HDmemcmp(wbuf2, rbuf, (size_t)BIG_BUF_SIZE) != 0) TEST_ERROR;
if(HDmemcmp(wbuf + 512, rbuf + BIG_BUF_SIZE, (size_t)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);
HDmemset(rbuf, 0, (size_t)(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;
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;
if(HDmemcmp(wbuf2, rbuf, (size_t)BIG_BUF_SIZE) != 0) TEST_ERROR;
if(HDmemcmp(zbuf, rbuf + BIG_BUF_SIZE, (size_t)512) != 0) TEST_ERROR;
if(HDmemcmp(wbuf, rbuf + BIG_BUF_SIZE + 512, (size_t)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);
HDmemset(rbuf, 0, (size_t)(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;
/* 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;
if(HDmemcmp(zbuf, rbuf, 1536) != 0) TEST_ERROR;
if(HDmemcmp(wbuf2, rbuf + 1536, BIG_BUF_SIZE) != 0) TEST_ERROR;
if(HDmemcmp(zbuf, rbuf, (size_t)1536) != 0) TEST_ERROR;
if(HDmemcmp(wbuf2, rbuf + 1536, (size_t)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);
HDmemset(rbuf, 0, (size_t)(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;
if(HDmemcmp(zbuf, rbuf, 512) != 0) TEST_ERROR;
if(HDmemcmp(wbuf2, rbuf + 512, BIG_BUF_SIZE) != 0) TEST_ERROR;
if(HDmemcmp(zbuf, rbuf, (size_t)512) != 0) TEST_ERROR;
if(HDmemcmp(wbuf2, rbuf + 512, (size_t)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);
HDmemset(rbuf, 0, (size_t)(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;
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;
if(HDmemcmp(wbuf, rbuf, (size_t)1024) != 0) TEST_ERROR;
if(HDmemcmp(zbuf, rbuf + 1024, (size_t)512) != 0) TEST_ERROR;
if(HDmemcmp(wbuf2, rbuf + 1536, (size_t)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);
HDmemset(rbuf, 0, (size_t)(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;
if(HDmemcmp(wbuf, rbuf, 512) != 0) TEST_ERROR;
if(HDmemcmp(wbuf2, rbuf + 512, BIG_BUF_SIZE) != 0) TEST_ERROR;
if(HDmemcmp(wbuf, rbuf, (size_t)512) != 0) TEST_ERROR;
if(HDmemcmp(wbuf2, rbuf + 512, (size_t)BIG_BUF_SIZE) != 0) TEST_ERROR;
if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;
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);
wbuf = (uint8_t *)HDmalloc((size_t)RANDOM_BUF_SIZE);
rbuf = (uint8_t *)calloc(RANDOM_BUF_SIZE, 1);
rbuf = (uint8_t *)HDcalloc((size_t)RANDOM_BUF_SIZE, (size_t)1);
/* Initialize write buffer */
for(u = 0; u < RANDOM_BUF_SIZE; u++)
TESTING("random writes to accumulator");
/* Choose random # seed */
seed = (unsigned)HDtime(NULL);
/* seed = (unsigned)1155438845; */
HDfprintf(stderr, "Random # seed was: %u\n", seed);
/* Allocate space for the segment length buffer */
off = (size_t *)malloc(MAX_RANDOM_SEGMENTS * sizeof(size_t));
off = (size_t *)HDmalloc(MAX_RANDOM_SEGMENTS * sizeof(size_t));
len = (size_t *)malloc(MAX_RANDOM_SEGMENTS * sizeof(size_t));
len = (size_t *)HDmalloc(MAX_RANDOM_SEGMENTS * sizeof(size_t));
/* Randomly choose lengths of segments */
for(u = 0; u < MAX_RANDOM_SEGMENTS; ) {
size_t length = 0; /* Length of current segment */
/* Choose random length of segment, allowing for variance */
length += (size_t)(HDrandom() % RAND_SEG_LEN) + 1;
/* 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;
/* 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(HDmemcmp(wbuf, rbuf, (size_t)RANDOM_BUF_SIZE) != 0) TEST_ERROR;
if(accum_reset(fio_info) < 0) FAIL_STACK_ERROR;
* Programmer: Mike McGreevy
*-------------------------------------------------------------------------
H5F_meta_accum_t * accum = &f->shared->accum;
printf("Current contents of accumulator:\n");
if (accum->alloc_size == 0) {
printf("=====================================================\n");
printf(" No accumulator allocated.\n");
printf("=====================================================\n");
printf("=====================================================\n");
printf(" accumulator allocated size == %zu\n", accum->alloc_size);
printf(" accumulated data size == %zu\n", accum->size);
HDprintf("Current contents of accumulator:\n");
if(accum->alloc_size == 0) {
HDprintf("=====================================================\n");
HDprintf(" No accumulator allocated.\n");
HDprintf("=====================================================\n");
HDprintf("=====================================================\n");
HDprintf(" accumulator allocated size == %zu\n", accum->alloc_size);
HDprintf(" accumulated data size == %zu\n", accum->size);
HDfprintf(stdout, " accumulator dirty? == %t\n", accum->dirty);
printf("=====================================================\n");
HDprintf("=====================================================\n");
HDfprintf(stdout, " start of accumulated data, loc = %a\n", accum->loc);
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));
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");
HDprintf("=====================================================\n");