int _start_test(int argc, char *argv[]) { FCT_INIT(argc, argv); FCT_QTEST_BGN(test_with_my_own_func) { fct_chk(1); } FCT_QTEST_END(); FCT_FINAL(); return FCT_NUM_FAILED(); }
FCT_BGN() { int preserve = 0; // MPI setup: MPI_Init and atexit(MPI_Finalize) int world_size, world_rank; MPI_Init(&argc, &argv); atexit((void (*) ()) MPI_Finalize); MPI_Comm_size(MPI_COMM_WORLD, &world_size); MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); // Install the command line options defined above. fctcl_install(my_cl_options); // Retrieve and sanity check problem size options preserve = fctcl_is("--preserve"); const int ncomponents = (int) strtol( fctcl_val2("--ncomponents","2"), (char **) NULL, 10); if (ncomponents < 1) { fprintf(stderr, "\n--ncomponents=%d < 1\n", ncomponents); MPI_Abort(MPI_COMM_WORLD, 1); } // Obtain default HDF5 error handler H5E_auto2_t hdf5_handler; void *hdf5_client_data; H5Eget_auto2(H5E_DEFAULT, &hdf5_handler, &hdf5_client_data); // Obtain default ESIO error handler esio_error_handler_t * const esio_handler = esio_set_error_handler_off(); esio_set_error_handler(esio_handler); // Fixture-related details const char * const input_dir = getenv("ESIO_TEST_INPUT_DIR"); const char * const output_dir = getenv("ESIO_TEST_OUTPUT_DIR"); char * filetemplate = create_testfiletemplate(output_dir, __FILE__); (void) input_dir; // Possibly unused char * filename = NULL; esio_handle state = NULL; FCT_FIXTURE_SUITE_BGN(attribute_suite) { FCT_SETUP_BGN() { ESIO_MPICHKQ(MPI_Barrier(MPI_COMM_WORLD)); // Synchronize // Restore HDF5/ESIO default error handling H5Eset_auto2(H5E_DEFAULT, hdf5_handler, hdf5_client_data); esio_set_error_handler(esio_handler); // Rank 0 generates a unique filename and broadcasts it int filenamelen; if (world_rank == 0) { filename = create_testfilename(filetemplate); if (preserve) { printf("\nfilename: %s\n", filename); } filenamelen = strlen(filename); } ESIO_MPICHKR(MPI_Bcast(&filenamelen, 1, MPI_INT, 0, MPI_COMM_WORLD)); if (world_rank > 0) { filename = calloc(filenamelen + 1, sizeof(char)); } ESIO_MPICHKR(MPI_Bcast(filename, filenamelen, MPI_CHAR, 0, MPI_COMM_WORLD)); fct_req(filename); // Initialize ESIO state state = esio_handle_initialize(MPI_COMM_WORLD); fct_req(state); } FCT_SETUP_END(); FCT_TEARDOWN_BGN() { // Finalize ESIO state esio_handle_finalize(state); // Clean up the unique file and filename if (world_rank == 0) { if (!preserve) unlink(filename); } free(filename); } FCT_TEARDOWN_END(); // Test scalar-valued attributes, including overwrite details FCT_TEST_BGN(attribute) { TYPE value; // Open file fct_req(0 == esio_file_create(state, filename, 1)); // Write zero to disk and flush the buffers value = 0; fct_req(0 == AFFIX(esio_attribute_write)( state, "/", "attribute", &value)); fct_req(0 == esio_file_flush(state)); // Populate value with non-zero data // TODO Vary this based on the rank? value = 5678; // Overwrite zeros on disk with test data fct_req(0 == AFFIX(esio_attribute_write)( state, "/", "attribute", &value)); // Clear storage in memory value = 0; { // Ensure we can retrieve the size correctly int count; fct_req(0 == esio_attribute_sizev( state, "/", "attribute", &count)); fct_chk_eq_int(count, 1); } // Close the file fct_req(0 == esio_file_close(state)); // Reopen the file using normal HDF5 APIs on root processor // Ensure we can retrieve the data by other means if (world_rank == 0) { TYPE data; const hid_t file_id = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT); fct_req(0 <= AFFIX(H5LTget_attribute)(file_id, "/", "attribute", &data)); #ifdef __INTEL_COMPILER #pragma warning(push,disable:1572) #endif fct_chk(data == 5678); #ifdef __INTEL_COMPILER #pragma warning(pop) #endif fct_req(0 <= H5Fclose(file_id)); } // Re-read the file in a distributed manner and verify contents fct_req(0 == esio_file_open(state, filename, 0)); fct_req(0 == AFFIX(esio_attribute_read)( state, "/", "attribute", &value)); #ifdef __INTEL_COMPILER #pragma warning(push,disable:1572) #endif fct_chk(value == 5678); #ifdef __INTEL_COMPILER #pragma warning(pop) #endif // Check that non-existent attribute yields quiet ESIO_NOTFOUND fct_chk(ESIO_NOTFOUND == esio_attribute_sizev( state, "/", "nonexistent", NULL)); fct_req(0 == esio_file_close(state)); } FCT_TEST_END(); // Test vector-like attributes FCT_TEST_BGN(attribute) { TYPE *value; // Allocate storage value = calloc(ncomponents, sizeof(TYPE)); fct_req(value); // Open file fct_req(0 == esio_file_create(state, filename, 1)); // Populate test data for (int i = 0; i < ncomponents; ++i) { value[i] = (TYPE) i + 5678; } // Write attribute to file fct_req(0 == AFFIX(esio_attribute_writev)( state, "/", "attribute", value, ncomponents)); { // Ensure we can retrieve the size correctly int count; fct_req(0 == esio_attribute_sizev( state, "/", "attribute", &count)); fct_chk_eq_int(count, ncomponents); } // Close the file fct_req(0 == esio_file_close(state)); // Free the temporary free(value); // Reopen the file using normal HDF5 APIs on root processor // Examine the contents to ensure it matches if (world_rank == 0) { value = calloc(ncomponents, sizeof(TYPE)); fct_req(value); const hid_t file_id = H5Fopen(filename, H5F_ACC_RDONLY, H5P_DEFAULT); fct_req(0 <= AFFIX(H5LTget_attribute)(file_id, "/", "attribute", value)); for (int i = 0; i < ncomponents; ++i) { #ifdef __INTEL_COMPILER #pragma warning(push,disable:1572) #endif fct_chk(i + 5678 == value[i]); #ifdef __INTEL_COMPILER #pragma warning(pop) #endif } fct_req(0 <= H5Fclose(file_id)); free(value); } // Re-read the file in a distributed manner and verify contents value = calloc(ncomponents, sizeof(TYPE)); fct_req(value); fct_req(0 == esio_file_open(state, filename, 0)); fct_req(0 == AFFIX(esio_attribute_readv)( state, "/", "attribute", value, ncomponents)); for (int i = 0; i < ncomponents; ++i) { #ifdef __INTEL_COMPILER #pragma warning(push,disable:1572) #endif fct_chk(i + 5678 == value[i]); #ifdef __INTEL_COMPILER #pragma warning(pop) #endif } free(value); fct_req(0 == esio_file_close(state)); } FCT_TEST_END(); } FCT_FIXTURE_SUITE_END(); free(filetemplate); }
FCT_BGN() { int preserve = 0; // MPI setup: MPI_Init and atexit(MPI_Finalize) int world_size, world_rank; MPI_Init(&argc, &argv); atexit((void (*) ()) MPI_Finalize); MPI_Comm_size(MPI_COMM_WORLD, &world_size); MPI_Comm_rank(MPI_COMM_WORLD, &world_rank); // Install the command line options defined above. fctcl_install(my_cl_options); // Retrieve options preserve = fctcl_is("--preserve"); // Obtain default HDF5 error handler H5E_auto2_t hdf5_handler; void *hdf5_client_data; H5Eget_auto2(H5E_DEFAULT, &hdf5_handler, &hdf5_client_data); // Obtain default ESIO error handler esio_error_handler_t * const esio_handler = esio_set_error_handler_off(); esio_set_error_handler(esio_handler); // Fixture-related details const char * const input_dir = getenv("ESIO_TEST_INPUT_DIR"); const char * const output_dir = getenv("ESIO_TEST_OUTPUT_DIR"); char * filetemplate = create_testfiletemplate(output_dir, __FILE__); char * filename = NULL; esio_handle handle = NULL; FCT_FIXTURE_SUITE_BGN(esio_file) { FCT_SETUP_BGN() { ESIO_MPICHKQ(MPI_Barrier(MPI_COMM_WORLD)); // Synchronize // Restore HDF5/ESIO default error handling H5Eset_auto2(H5E_DEFAULT, hdf5_handler, hdf5_client_data); esio_set_error_handler(esio_handler); // Rank 0 generates a unique filename and broadcasts it int filenamelen; if (world_rank == 0) { filename = create_testfilename(filetemplate); if (preserve) { printf("\nfilename: %s\n", filename); } filenamelen = strlen(filename); } ESIO_MPICHKR(MPI_Bcast(&filenamelen, 1, MPI_INT, 0, MPI_COMM_WORLD)); if (world_rank > 0) { filename = calloc(filenamelen + 1, sizeof(char)); } ESIO_MPICHKR(MPI_Bcast(filename, filenamelen, MPI_CHAR, 0, MPI_COMM_WORLD)); fct_req(filename); // Initialize ESIO handle handle = esio_handle_initialize(MPI_COMM_WORLD); fct_req(handle); // Check that the handle correctly reports world_size int size; fct_req(ESIO_SUCCESS == esio_handle_comm_size(handle, &size)); fct_chk_eq_int(world_size, size); // Check that the handle correctly reports world_rank int rank; fct_req(ESIO_SUCCESS == esio_handle_comm_rank(handle, &rank)); fct_chk_eq_int(world_rank, rank); } FCT_SETUP_END(); FCT_TEARDOWN_BGN() { // Finalize ESIO handle esio_handle_finalize(handle); // Clean up the unique file and filename if (world_rank == 0) { if (!preserve) unlink(filename); } free(filename); } FCT_TEARDOWN_END(); FCT_TEST_BGN(success_code) { fct_chk_eq_int(0, ESIO_SUCCESS); // Success is zero fct_chk(!ESIO_SUCCESS); // Not success is true } FCT_TEST_END(); FCT_TEST_BGN(file_create_and_open) { // No open file so esio_file_path is empty fct_req(NULL == esio_file_path(handle)); // Create with overwrite should always work fct_req(0 == esio_file_create(handle, filename, 1 /* o/w */)); // Flush flush flush should always work fct_req(0 == esio_file_flush(handle)); fct_req(0 == esio_file_flush(handle)); fct_req(0 == esio_file_flush(handle)); // Check that esio_file_path points to a valid canonical location struct stat statbuf; char *file_path = esio_file_path(handle); fct_req(file_path != NULL); fct_chk_startswith_str(file_path, "/"); // Absolute? fct_req(0 == stat(file_path, &statbuf)); free(file_path); // Close the file fct_req(0 == esio_file_close(handle)); // Double closure should silently succeed fct_req(0 == esio_file_close(handle)); // No open file so esio_file_path is empty fct_req(NULL == esio_file_path(handle)); // Create without overwrite should fail H5Eset_auto2(H5E_DEFAULT, NULL, NULL); esio_set_error_handler_off(); fct_req(0 != esio_file_create(handle, filename, 0 /* no o/w */)); esio_set_error_handler(esio_handler); H5Eset_auto2(H5E_DEFAULT, hdf5_handler, hdf5_client_data); // Remove the file and create without overwrite should succeed ESIO_MPICHKQ(MPI_Barrier(MPI_COMM_WORLD)); // Synchronize if (world_rank == 0) { fct_req(0 == unlink(filename)); } ESIO_MPICHKQ(MPI_Barrier(MPI_COMM_WORLD)); // Synchronize fct_req(0 == esio_file_create(handle, filename, 0 /* no o/w */)); // Close the file fct_req(0 == esio_file_close(handle)); // Ensure we can open in read-only mode fct_req(0 == esio_file_open(handle, filename, 0 /* read-only */)); // Close the file fct_req(0 == esio_file_close(handle)); // Ensure we can open in read-write mode fct_req(0 == esio_file_open(handle, filename, 1 /* read-write */)); // Close the file fct_req(0 == esio_file_close(handle)); } FCT_TEST_END(); FCT_TEST_BGN(file_clone) { // Dynamically create the empty.h5 source filename per input_dir if (input_dir == NULL && world_rank == 0) { fprintf(stderr, "\nESIO_TEST_INPUT_DIR not in environment!\n"); } fct_req(NULL != input_dir /* check ESIO_TEST_INPUT_DIR set */); int srcfilelen = strlen(input_dir); fct_req(srcfilelen > 0); srcfilelen += strlen("/empty.h5"); srcfilelen += 1; char * srcfile = calloc(srcfilelen, 1); fct_req(NULL != srcfile); fct_req(NULL != strcat(srcfile, input_dir)); fct_req(NULL != strcat(srcfile, "/empty.h5")); // Clone with overwrite should always work fct_req(0 == esio_file_clone(handle, srcfile, filename, 1)); // Close the file fct_req(0 == esio_file_close(handle)); // Create without overwrite should fail H5Eset_auto2(H5E_DEFAULT, NULL, NULL); esio_set_error_handler_off(); fct_req(0 != esio_file_clone(handle, srcfile, filename, 0)); esio_set_error_handler(esio_handler); H5Eset_auto2(H5E_DEFAULT, hdf5_handler, hdf5_client_data); // Remove the file and create without overwrite should succeed ESIO_MPICHKQ(MPI_Barrier(MPI_COMM_WORLD)); // Synchronize if (world_rank == 0) { fct_req(0 == unlink(filename)); } ESIO_MPICHKQ(MPI_Barrier(MPI_COMM_WORLD)); // Synchronize fct_req(0 == esio_file_clone(handle, srcfile, filename, 0)); // Close the file fct_req(0 == esio_file_close(handle)); // Deallocate the srcfile name free(srcfile); } FCT_TEST_END(); // Much of this functionality is covered in restart_helpers.c // and restart_rename.{sh,c}. This covers only the public API's // most basic usage. FCT_TEST_BGN(file_close_restart) { struct stat statbuf; // Form template and expected file paths from temporary filename char *template = malloc(strlen(filename) + 2); fct_req(template);
FCT_BGN() { { VCookieStore *pvcs = 0; FCT_FIXTURE_SUITE_BGN(VCookies) { FCT_SETUP_BGN() { pvcs = new VCStoreInMemory(); } FCT_SETUP_END(); FCT_TEARDOWN_BGN() { delete pvcs; } FCT_TEARDOWN_END(); FCT_TEST_BGN(CreateVCookie) { VCookie vc(12345, 6789, 9876, true, *pvcs); fct_chk ( !vc.IsModified()); } FCT_TEST_END(); FCT_TEST_BGN(CreateVCookie2) { VCookie vc(12345, 6789, 9876, true, *pvcs); SetupVCookie (vc); fct_chk ( vc.IsModified()); } FCT_TEST_END(); FCT_TEST_BGN(TestRelationVars) { VCookie vc(12345, 6789, 9876, true, *pvcs); time_t t = time(0); vc.SetVar(1, "Var1a", t, 0, ALLOC_TYPE_FIRST); fct_chk (CheckVar (vc, 1, "Var1", t, 0, 'a')); vc.SetVar(1, "Var1a", t+1, 1,ALLOC_TYPE_FIRST); fct_chk (CheckVar (vc, 1, "Var1", t, 0, 'a')); vc.SetVar(1, "Var1b", t+2, 2, ALLOC_TYPE_LAST); fct_chk (CheckVar (vc, 1, "Var1", t+2, 2, 'b')); fct_chk (vc.GetVar(1,1) == 0); vc.ClearVar (1); fct_chk (vc.GetVarElementCount(1) == 0); fct_chk (vc.GetVar(1) == 0); vc.SetVar(1, "Var1c", t+3, 3, ALLOC_TYPE_FIRST); fct_chk (CheckVar (vc, 1, "Var1", t+3, 3, 'c')); vc.SetVar(1, "Var1d", t+4, 4, ALLOC_TYPE_LINEAR, 1); fct_chk (CheckVar (vc, 1, "Var1", t+4, 4, 'd')); vc.SetVar(1, "Var1e", t+5, 5, ALLOC_TYPE_LINEAR, 2); fct_chk (CheckVar (vc, 1, "Var1", t+4, 4, 'd', 2)); vc.SetVar(1, "Var1f", t+6, 6, ALLOC_TYPE_LINEAR, 3); fct_chk (CheckVar (vc, 1, "Var1", t+4, 4, 'd', 3)); vc.SetVar(1, "Var1g", t+7, 7, ALLOC_TYPE_LINEAR, 3); fct_chk (CheckVar (vc, 1, "Var1", t+5, 5, 'e', 3)); vc.SetVar(1, "Var1h", t+8, 8, ALLOC_TYPE_LINEAR, 2); fct_chk (CheckVar (vc, 1, "Var1", t+7, 7, 'g', 2)); } FCT_TEST_END(); FCT_TEST_BGN(LoadVCookie) { VCookie vc(12345, 6789, 9876, true, *pvcs); SetupVCookie (vc); pvcs->SaveVCookie(vc); VCookie vc2(12345, 6789, 9876, false, *pvcs); fct_chk ( !vc2.IsModified()); fct_chk (vc == vc2); } FCT_TEST_END(); FCT_TEST_BGN(DeleteOld) { for (unsigned i=0; i < 100; ++i) { VCookie vc(12345, 6789+i, 9876-i, true, *pvcs); vc.SetLastHitTimeGMT(100000*i+1+10000000*(i%2)); } fct_chk (pvcs->GetVCookieCount() == 100); fct_chk (pvcs->DeleteOldVCookies(100000*50) == 25); fct_chk (pvcs->GetVCookieCount() == 75); } FCT_TEST_END(); } FCT_FIXTURE_SUITE_END(); } }