From 062140b8d470b74162893a8a1f182ed5b410afde Mon Sep 17 00:00:00 2001 From: Matthew Larson Date: Fri, 15 Nov 2024 11:43:37 -0600 Subject: [PATCH] Fix FAPL ref count in MT VL tests --- test/threads/unit/mt_vl_test.c | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/test/threads/unit/mt_vl_test.c b/test/threads/unit/mt_vl_test.c index 4402782bf98..ed51096878f 100644 --- a/test/threads/unit/mt_vl_test.c +++ b/test/threads/unit/mt_vl_test.c @@ -726,15 +726,30 @@ void mt_test_vol_wrap_ctx(void) { fapl_id = H5Pcreate(H5P_FILE_ACCESS); CHECK(fapl_id, H5I_INVALID_HID, "H5Pcreate"); + /* To avoid dealing with concurrent registration in this test, we register the VOL + * a single time and pass a shared FAPL to the helper threads. + * To comply with the API, the ref count of the FAPL must be incremented + * for each new thread it will be passed to. */ + for (int i = 0; i < max_num_threads; i++) { + ret = H5Iinc_ref(fapl_id); + VERIFY(ret, i + 2, "H5Iinc_ref"); + } + ret = H5Pset_vol(fapl_id, passthru_id, (const void*) &passthru_info); CHECK(ret, FAIL, "H5Pset_vol"); + /* File will be used by each helper thread */ file_id = H5Fcreate(MT_TEST_VOL_WRAP_CTX_FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id); CHECK(file_id, H5I_INVALID_HID, "H5Fcreate"); mt_test_run_helper_in_parallel(max_num_threads, mt_test_vol_wrap_ctx_helper, (void*) fapl_id); /* Clean up */ + for (int i = 0; i < max_num_threads; i++) { + ret = H5Idec_ref(fapl_id); + VERIFY(ret, max_num_threads - i, "H5Idec_ref"); + } + ret = H5Fclose(file_id); CHECK(ret, FAIL, "H5Fclose"); @@ -753,7 +768,7 @@ void *mt_test_vol_wrap_ctx_helper(void H5_ATTR_UNUSED *arg) { hid_t fapl_id = H5I_INVALID_HID; hid_t file_id = H5I_INVALID_HID; - hid_t passthru_id = H5I_INVALID_HID; + hid_t vol_id = H5I_INVALID_HID; herr_t ret = SUCCEED; @@ -769,16 +784,16 @@ void *mt_test_vol_wrap_ctx_helper(void H5_ATTR_UNUSED *arg) { CHECK(vol_object->data, NULL, "H5I_object_verify"); /* Retrieve ID of VOL connector */ - ret = H5Pget_vol_id(fapl_id, &passthru_id); + ret = H5Pget_vol_id(fapl_id, &vol_id); CHECK(ret, FAIL, "H5Pget_vol_id"); /* Retrieve & subsequently free VOL wrap context */ - ret = H5VLget_wrap_ctx((void*) (vol_object->data), passthru_id, &wrap_ctx); + ret = H5VLget_wrap_ctx((void*) (vol_object->data), vol_id, &wrap_ctx); CHECK(ret, FAIL, "H5VLget_wrap_ctx"); CHECK(wrap_ctx, NULL, "H5VLget_wrap_ctx"); - ret = H5VLfree_wrap_ctx(wrap_ctx, passthru_id); + ret = H5VLfree_wrap_ctx(wrap_ctx, vol_id); CHECK(ret, FAIL, "H5VLfree_wrap_ctx");