From 316aa34bacba01f84748eeaf011a3e2f2d4aac7a Mon Sep 17 00:00:00 2001 From: David Young Date: Mon, 3 Aug 2020 15:00:25 -0500 Subject: Make tests pass on both of my branches, like they ought to: in the tests that call H5F__vfd_swmr_writer_md_test(), actually sleep for more than `max_lag` ticks so that the deferred-frees queue is actually flushed before we force new items onto the queue and count them. In H5F__vfd_swmr_writer_md_test(), check that the number of deferred shadow-space frees is *precisely* the number `nshadow_defrees`, since that seems to be what the tests that call this routine intend. --- src/H5Ftest.c | 2 +- test/vfd_swmr.c | 44 +++++++++++++++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/H5Ftest.c b/src/H5Ftest.c index ced4b2c..f249d45 100644 --- a/src/H5Ftest.c +++ b/src/H5Ftest.c @@ -581,7 +581,7 @@ H5F__vfd_swmr_writer_md_test(hid_t file_id, unsigned num_entries, HGOTO_ERROR(H5E_FILE, H5E_CANTALLOC, FAIL, "error updating the md file with the index") /* Verify the number of entries in the delayed list is as expected */ - if(count_shadow_defrees(&f->shared->shadow_defrees) < nshadow_defrees) + if(count_shadow_defrees(&f->shared->shadow_defrees) == nshadow_defrees) HGOTO_ERROR(H5E_FILE, H5E_BADVALUE, FAIL, "incorrect # of entries in the delayed list") /* Open the metadata file */ diff --git a/test/vfd_swmr.c b/test/vfd_swmr.c index 287f1ff..d49629f 100644 --- a/test/vfd_swmr.c +++ b/test/vfd_swmr.c @@ -824,6 +824,21 @@ error: return 1; } /* test_writer_create_open_flush() */ +/* Sleep for `tenths` tenths of a second. + * + * This routine may quietly perform a too-short sleep if an error occurs + * in nanosleep(2). + */ +static void +decisleep(uint32_t tenths) +{ + struct timespec delay = {.tv_sec = tenths / 10, + .tv_nsec = tenths * 100 * 1000 * 1000}; + + while (nanosleep(&delay, &delay) == -1 && errno == EINTR) + ; // do nothing +} + /*------------------------------------------------------------------------- * Function: test_writer_md() @@ -854,7 +869,7 @@ test_writer_md(void) hid_t fid = -1; /* File ID */ hid_t fapl = -1; /* File access property list */ hid_t fcpl = -1; /* File creation property list */ - unsigned num_entries = 0; /* Number of entries in the index */ + const unsigned num_entries = 10; /* index size */ unsigned i = 0; /* Local index variables */ uint8_t *buf = NULL; /* Data page from the page buffer */ hid_t dcpl = -1; /* Dataset creation property list */ @@ -895,7 +910,6 @@ test_writer_md(void) FAIL_STACK_ERROR; /* Allocate num_entries for the data buffer */ - num_entries = 10; if((buf = HDcalloc(num_entries, FS_PAGE_SIZE)) == NULL) FAIL_STACK_ERROR; @@ -930,7 +944,8 @@ test_writer_md(void) FAIL_STACK_ERROR /* Perform activities to ensure that max_lag ticks elapse */ - for(i = 0; i < 1000; i++) { + for(i = 0; i < my_config->max_lag + 1; i++) { + decisleep(my_config->tick_len); /* Create a chunked dataset */ sprintf(dname, "dset %d", i); @@ -962,7 +977,9 @@ test_writer_md(void) rwbuf[i] = (int)i; /* Perform activities to ensure that max_lag ticks elapse */ - for(i = 0; i < 1000; i++) { + for(i = 0; i < my_config->max_lag + 1; i++) { + decisleep(my_config->tick_len); + /* Open the dataset */ sprintf(dname, "dset %d", i); if((did = H5Dopen2(fid, dname, H5P_DEFAULT)) < 0) @@ -994,7 +1011,9 @@ test_writer_md(void) HDmemset(rwbuf, 0, sizeof(sizeof(int) * (50 * 20))); /* Perform activities to ensure that max_lag ticks elapse */ - for(i = 0; i < 1000; i++) { + for(i = 0; i < my_config->max_lag + 1; i++) { + decisleep(my_config->tick_len); + /* Open the dataset */ sprintf(dname, "dset %d", i); if((did = H5Dopen2(fid, dname, H5P_DEFAULT)) < 0) @@ -1476,7 +1495,8 @@ test_reader_md_concur(void) FAIL_STACK_ERROR /* Perform activities to ensure that ticks elapse */ - for(i = 0; i < 2000; i++) { + for(i = 0; i < config_writer->max_lag + 1; i++) { + decisleep(config_writer->tick_len); /* Create a chunked dataset */ sprintf(dname, "dset %d", i); @@ -1553,7 +1573,9 @@ test_reader_md_concur(void) rwbuf[i] = (int)i; /* Perform activities to ensure that max_lag ticks elapse */ - for(i = 0; i < 1000; i++) { + for(i = 0; i < config_writer->max_lag + 1; i++) { + decisleep(config_writer->tick_len); + /* Open the dataset */ sprintf(dname, "dset %d", i); if((did = H5Dopen2(fid_writer, dname, H5P_DEFAULT)) < 0) @@ -1606,7 +1628,9 @@ test_reader_md_concur(void) } /* Perform activities to ensure that max_lag ticks elapse */ - for(i = 0; i < 1000; i++) { + for(i = 0; i < config_writer->max_lag + 1; i++) { + decisleep(config_writer->tick_len); + /* Open the dataset */ sprintf(dname, "dset %d", i); if((did = H5Dopen2(fid_writer, dname, H5P_DEFAULT)) < 0) @@ -1658,7 +1682,9 @@ test_reader_md_concur(void) } /* Perform activities to ensure that ticks elapse */ - for(i = 0; i < 1000; i++) { + for(i = 0; i < config_writer->max_lag + 1; i++) { + decisleep(config_writer->tick_len); + /* Open the dataset */ sprintf(dname, "dset %d", i); if((did = H5Dopen2(fid_writer, dname, H5P_DEFAULT)) < 0) -- cgit v0.12