/*------------------------------------------------------------------------- * Function: main * * Purpose: Tests the plugin module (H5PL) * * Return: EXIT_SUCCESS/EXIT_FAILURE * *------------------------------------------------------------------------- */ int main(void) { char filename[FILENAME_BUF_SIZE]; hid_t fid = -1; hid_t old_ff_fapl_id = -1; hid_t new_ff_fapl_id = -1; unsigned new_format; int nerrors = 0; /*******************************************************************/ /* ENSURE THAT WRITING TO DATASETS AND CREATING GROUPS WORKS */ /*******************************************************************/ /* Test with old & new format groups */ for (new_format = FALSE; new_format <= TRUE; new_format++) { hid_t my_fapl_id; /* Testing setup */ h5_reset(); /* Get a VFD-dependent filename */ if ((old_ff_fapl_id = h5_fileaccess()) < 0) TEST_ERROR; /* Turn off the chunk cache, so all the chunks are immediately written to disk */ if (disable_chunk_cache(old_ff_fapl_id) < 0) TEST_ERROR; /* Fix up the filename for the VFD */ h5_fixname(FILENAME[0], old_ff_fapl_id, filename, sizeof(filename)); /* Set the FAPL for the type of format */ if (new_format) { HDputs("\nTesting with new file format:"); /* Copy the file access property list and set the latest file format on it */ if ((new_ff_fapl_id = H5Pcopy(old_ff_fapl_id)) < 0) TEST_ERROR; if (H5Pset_libver_bounds(new_ff_fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) TEST_ERROR; my_fapl_id = new_ff_fapl_id; } else { HDputs("Testing with old file format:"); my_fapl_id = old_ff_fapl_id; } /* Create the file for this test */ if ((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, my_fapl_id)) < 0) TEST_ERROR; /* Test creating datasets and writing to them using plugin filters */ nerrors += (test_dataset_write_with_filters(fid) < 0 ? 1 : 0); /* Test creating groups using dynamically-loaded plugin filters */ nerrors += (test_creating_groups_using_plugins(fid) < 0 ? 1 : 0); if (H5Fclose(fid) < 0) TEST_ERROR; /* Close FAPLs */ if (H5Pclose(old_ff_fapl_id) < 0) TEST_ERROR; if (new_format) { if (H5Pclose(new_ff_fapl_id) < 0) TEST_ERROR; } /* Restore the default error handler (set in h5_reset()) */ h5_restore_err(); /*******************************************************************/ /* ENSURE THAT READING FROM DATASETS AND OPENING GROUPS WORKS */ /*******************************************************************/ HDputs("\nTesting reading data with with dynamic plugin filters:"); /* Close the library so that all loaded plugin libraries are unloaded */ h5_reset(); if ((old_ff_fapl_id = h5_fileaccess()) < 0) TEST_ERROR; /* Set the FAPL for the type of format */ if (new_format) { /* Copy the file access property list and set the latest file format on it */ if ((new_ff_fapl_id = H5Pcopy(old_ff_fapl_id)) < 0) TEST_ERROR; if (H5Pset_libver_bounds(new_ff_fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) TEST_ERROR; my_fapl_id = new_ff_fapl_id; } else my_fapl_id = old_ff_fapl_id; /* Reopen the file for testing data reading */ if ((fid = H5Fopen(filename, H5F_ACC_RDONLY, my_fapl_id)) < 0) TEST_ERROR; /* Read the data with filters */ nerrors += (test_dataset_read_with_filters(fid) < 0 ? 1 : 0); /* Test creating groups using dynamically-loaded plugin filters */ nerrors += (test_opening_groups_using_plugins(fid) < 0 ? 1 : 0); /* Close FAPLs */ if (H5Pclose(old_ff_fapl_id) < 0) TEST_ERROR; if (new_format) { if (H5Pclose(new_ff_fapl_id) < 0) TEST_ERROR; } /* Restore the default error handler (set in h5_reset()) */ h5_restore_err(); /*******************************************************************/ /* ENSURE THAT DISABLING FILTER PLUGINS VIA THE FILTER FLAGS WORKS */ /*******************************************************************/ /* Close the library so that all loaded plugin libraries are unloaded */ h5_reset(); if ((old_ff_fapl_id = h5_fileaccess()) < 0) TEST_ERROR; /* Set the FAPL for the type of format */ if (new_format) { /* Copy the file access property list and set the latest file format on it */ if ((new_ff_fapl_id = H5Pcopy(old_ff_fapl_id)) < 0) TEST_ERROR; if (H5Pset_libver_bounds(new_ff_fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) TEST_ERROR; my_fapl_id = new_ff_fapl_id; } else my_fapl_id = old_ff_fapl_id; /* Reopen the file for testing data reading */ if ((fid = H5Fopen(filename, H5F_ACC_RDONLY, my_fapl_id)) < 0) TEST_ERROR; /* When filters are disabled, make sure we can't read data from a * dataset that requires a filter plugin. */ nerrors += (test_no_read_when_plugins_disabled(fid) < 0 ? 1 : 0); if (H5Fclose(fid) < 0) TEST_ERROR; /*********************/ /* CLEAN UP */ /*********************/ /* Close FAPLs */ if (new_format) { if (H5Pclose(new_ff_fapl_id) < 0) TEST_ERROR; } else { /* Restore the default error handler (set in h5_reset()) */ h5_restore_err(); if (H5Pclose(old_ff_fapl_id) < 0) TEST_ERROR; } /* Free up saved arrays */ free_2D_array(&orig_deflate_g); free_2D_array(&orig_dynlib1_g); free_2D_array(&orig_dynlib2_g); free_2D_array(&orig_dynlib4_g); } /* end for */ h5_cleanup(FILENAME, old_ff_fapl_id); /************************************/ /* TEST THE FILTER PLUGIN API CALLS */ /************************************/ /* Test the APIs for access to the filter plugin path table */ nerrors += (test_path_api_calls() < 0 ? 1 : 0); if (nerrors) TEST_ERROR; HDprintf("All plugin tests passed.\n"); HDexit(EXIT_SUCCESS); error: H5E_BEGIN_TRY { H5Fclose(fid); H5Pclose(old_ff_fapl_id); H5Pclose(new_ff_fapl_id); } H5E_END_TRY /* Free up saved arrays (NULLs okay) */ free_2D_array(&orig_deflate_g); free_2D_array(&orig_dynlib1_g); free_2D_array(&orig_dynlib2_g); free_2D_array(&orig_dynlib4_g); nerrors = MAX(1, nerrors); HDprintf("***** %d PLUGIN TEST%s FAILED! *****\n", nerrors, 1 == nerrors ? "" : "S"); HDexit(EXIT_FAILURE); } /* end main() */
static herr_t H5O_iterate_cb (hid_t g_id, const char *name, const H5O_info_t *info, void *cb_data) { cb_wrapper *wrapper = (cb_wrapper *)cb_data; jmethodID constructor, mid; jobject cb_info_t = NULL; jobject visit_callback = wrapper->visit_callback; jobject hdrinfobuf; jobject ihinfobuf1; jobject ihinfobuf2; jstring str; JNIEnv *cbenv = NULL; jclass cls; jvalue args[12]; void *op_data = (void *)wrapper->op_data; jint status = FAIL; if (JVMPTR->AttachCurrentThread(JVMPAR, (void **)&cbenv, NULL) < 0) { CHECK_JNI_EXCEPTION(CBENVONLY, JNI_TRUE); H5_JNI_FATAL_ERROR(CBENVONLY, "H5O_iterate_cb: failed to attach current thread to JVM"); } if (NULL == (cls = CBENVPTR->GetObjectClass(CBENVONLY, visit_callback))) CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); if (NULL == (mid = CBENVPTR->GetMethodID(CBENVONLY, cls, "callback", "(JLjava/lang/String;Lhdf/hdf5lib/structs/H5O_info_t;Lhdf/hdf5lib/callbacks/H5O_iterate_t;)I"))) CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); if (NULL == (str = CBENVPTR->NewStringUTF(CBENVONLY, name))) CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); args[0].i = (jint)info->hdr.version; args[1].i = (jint)info->hdr.nmesgs; args[2].i = (jint)info->hdr.nchunks; args[3].i = (jint)info->hdr.flags; args[4].j = (jlong)info->hdr.space.total; args[5].j = (jlong)info->hdr.space.meta; args[6].j = (jlong)info->hdr.space.mesg; args[7].j = (jlong)info->hdr.space.free; args[8].j = (jlong)info->hdr.mesg.present; args[9].j = (jlong)info->hdr.mesg.shared; /* Get a reference to the H5_hdr_info_t class */ if (NULL == (cls = CBENVPTR->FindClass(CBENVONLY, "hdf/hdf5lib/structs/H5O_hdr_info_t"))) CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); /* Get a reference to the constructor; the name is <init> */ if (NULL == (constructor = CBENVPTR->GetMethodID(CBENVONLY, cls, "<init>", "(IIIIJJJJJJ)V"))) CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); if (NULL == (hdrinfobuf = CBENVPTR->NewObjectA(CBENVONLY, cls, constructor, args))) { HDprintf("H5O_iterate_cb ERROR: hdf/hdf5lib/structs/H5O_hdr_info_t: Creation failed\n"); CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); } args[0].j = (jlong)info->meta_size.obj.index_size; args[1].j = (jlong)info->meta_size.obj.heap_size; /* Get a reference to the H5_ih_info_t class */ if (NULL == (cls = CBENVPTR->FindClass(CBENVONLY, "hdf/hdf5lib/structs/H5_ih_info_t"))) CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); /* Get a reference to the constructor; the name is <init> */ if (NULL == (constructor = CBENVPTR->GetMethodID(CBENVONLY, cls, "<init>", "(JJ)V"))) CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); if (NULL == (ihinfobuf1 = CBENVPTR->NewObjectA(CBENVONLY, cls, constructor, args))) { HDprintf("H5O_iterate_cb ERROR: hdf/hdf5lib/structs/H5_ih_info_t: Creation failed\n"); CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); } args[0].j = (jlong)info->meta_size.attr.index_size; args[1].j = (jlong)info->meta_size.attr.heap_size; if (NULL == (ihinfobuf2 = CBENVPTR->NewObjectA(CBENVONLY, cls, constructor, args))) { HDprintf("H5O_iterate_cb ERROR: hdf/hdf5lib/structs/H5_ih_info_t: Creation failed\n"); CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); } args[0].j = (jlong)info->fileno; args[1].j = (jlong)info->addr; args[2].i = info->type; args[3].i = (jint)info->rc; args[4].j = (jlong)info->num_attrs; args[5].j = info->atime; args[6].j = info->mtime; args[7].j = info->ctime; args[8].j = info->btime; args[9].l = hdrinfobuf; args[10].l = ihinfobuf1; args[11].l = ihinfobuf2; /* Get a reference to the H5O_info_t class */ if (NULL == (cls = CBENVPTR->FindClass(CBENVONLY, "hdf/hdf5lib/structs/H5O_info_t"))) CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); /* Get a reference to the constructor; the name is <init> */ if (NULL == (constructor = CBENVPTR->GetMethodID(CBENVONLY, cls, "<init>", "(JJIIJJJJJLhdf/hdf5lib/structs/H5O_hdr_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;Lhdf/hdf5lib/structs/H5_ih_info_t;)V"))) CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); if (NULL == (cb_info_t = CBENVPTR->NewObjectA(CBENVONLY, cls, constructor, args))) { HDprintf("H5O_iterate_cb ERROR: hdf/hdf5lib/structs/H5O_info_t: Creation failed\n"); CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); } status = CBENVPTR->CallIntMethod(CBENVONLY, visit_callback, mid, g_id, str, cb_info_t, op_data); CHECK_JNI_EXCEPTION(CBENVONLY, JNI_FALSE); done: if (cbenv) JVMPTR->DetachCurrentThread(JVMPAR); return (herr_t)status; } /* end H5O_iterate_cb */