/* * Function: cleanup * Purpose: Cleanup the output file. * Returns: Nothing * Programmer: Bill Wendling, 06. June 2002 * Modifications: */ static void cleanup(void) { if (!HDgetenv("HDF5_NOCLEANUP")) HDunlink(filename); HDfree(filename); }
/*------------------------------------------------------------------------- * Function: wait_for_signal * * Purpose: Waits for the specified signal. * * In terms of this test framework, a signal consists of a file * on disk. Since there are multiple processes that need to * communicate with each other, they do so by writing and * reading signal files on disk, the names and contents of * which are used to inform a process about when it can * proceed and what it should do next. * * This function continuously attempts to read the specified * signal file from disk, and only continues once it has * successfully done so (i.e., only after another process has * called the "send_signal" function to write the signal file). * This functon will then immediately remove the file (i.e., * to indicate that it has been received and can be reused), * and then exits, allowing the calling function to continue. * * Return: void * * Programmer: Mike McGreevy * August 18, 2010 * * Modifications: * *------------------------------------------------------------------------- */ herr_t wait_for_signal(const char * waitfor) { FILE *returnfile; time_t t0,t1; /* Start timer. If this function runs for too long (i.e., expected signal is never received), it will return failure */ time(&t0); /* Wait for return signal from some other process */ while ((returnfile = fopen(waitfor, "r")) == NULL) { /* make note of current time. */ time(&t1); /* If we've been waiting for a signal for too long, then it was likely never sent and we should fail rather than loop infinitely */ if (difftime(t1,t0) > SIGNAL_TIMEOUT) { HDfprintf(stdout, "Error communicating between processes. Make sure test script is running.\n"); TEST_ERROR; } /* end if */ } /* end while */ HDfclose(returnfile); HDunlink(waitfor); return SUCCEED; error: return FAIL; } /* wait_for_signal */
/*------------------------------------------------------------------------- * Function: is_sparse * * Purpose: Determines if the file system of the current working * directory supports holes. * * Return: Success: Non-zero if holes are supported; zero * otherwise. * * Failure: zero * * Programmer: Robb Matzke * Wednesday, July 15, 1998 * * Modifications: * *------------------------------------------------------------------------- */ static int is_sparse(void) { int fd; h5_stat_t sb; if ((fd=HDopen("x.h5", O_RDWR|O_TRUNC|O_CREAT, 0666))<0) return 0; if (HDlseek(fd, (off_t)(1024*1024), SEEK_SET)!=1024*1024) return 0; if (5!=HDwrite(fd, "hello", (size_t)5)) return 0; if (HDclose(fd)<0) return 0; if (HDstat("x.h5", &sb)<0) return 0; if (HDunlink("x.h5")<0) return 0; #ifdef H5_HAVE_STAT_ST_BLOCKS return ((unsigned long)sb.st_blocks*512 < (unsigned long)sb.st_size); #else return (0); #endif }
/*------------------------------------------------------------------------- * Function: supports_big * * Purpose: Determines if the file system of the current working * directory supports big files. * * Return: Success: Non-zero if big files are supported; zero * otherwise. * * Failure: zero * * Programmer: Raymond Lu * Wednesday, April 18, 2007 * * Modifications: * *------------------------------------------------------------------------- */ static int supports_big(void) { int fd; if ((fd=HDopen("y.h5", O_RDWR|O_TRUNC|O_CREAT, 0666))<0) return 0; /* Write a few bytes at 2GB */ if (HDlseek(fd, BIG_FILE, SEEK_SET)!=BIG_FILE) return 0; if (5!=HDwrite(fd, "hello", (size_t)5)) return 0; /* Write a few bytes at 4GB */ if (HDlseek(fd, 2*BIG_FILE, SEEK_SET) != 2*BIG_FILE) return 0; if (5!=HDwrite(fd, "hello", (size_t)5)) return 0; if (HDclose(fd)<0) return 0; if (HDunlink("y.h5")<0) return 0; return (1); }
/*------------------------------------------------------------------------- * Function: h5_reset * * Purpose: Reset the library by closing it. * * Return: void * * Programmer: Robb Matzke * Friday, November 20, 1998 * *------------------------------------------------------------------------- */ void h5_reset(void) { HDfflush(stdout); HDfflush(stderr); H5close(); /* Save current error stack reporting routine and redirect to our local one */ HDassert(err_func == NULL); H5Eget_auto2(H5E_DEFAULT, &err_func, NULL); H5Eset_auto2(H5E_DEFAULT, h5_errors, NULL); /* * I commented this chunk of code out because it's not clear what diagnostics * were being output and under what circumstances, and creating this file * is throwing off debugging some of the tests. I can't see any _direct_ * harm in keeping this section of code, but I can't see any _direct_ * benefit right now either. If we figure out under which circumstances * diagnostics are being output, we should enable this behavior based on * appropriate configure flags/macros. QAK - 2007/12/20 */ #ifdef OLD_WAY { char filename[1024]; /* * Cause the library to emit some diagnostics early so they don't * interfere with other formatted output. */ sprintf(filename, "/tmp/h5emit-%05d.h5", HDgetpid()); H5E_BEGIN_TRY { hid_t file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); hid_t grp = H5Gcreate2(file, "emit", H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Gclose(grp); H5Fclose(file); HDunlink(filename); } H5E_END_TRY; } #endif /* OLD_WAY */ }
/*------------------------------------------------------------------------- * Function: enough_room * * Purpose: Tries to create a bunch of sparse files to see if quotas will * get in the way. Some systems also have problems opening * enough files and we'll check that too. * * Return: Success: Non-zero * * Failure: zero * * Programmer: Robb Matzke * Thursday, August 6, 1998 * * Modifications: * *------------------------------------------------------------------------- */ static int enough_room(hid_t fapl) { int ret_value=0; int fd[68]; size_t i, size = (size_t)1 << 30; char filename[1024], name[1024]; /* Initialize file descriptors */ for (i=0; i<NELMTS(fd); i++) fd[i] = -1; /* Get file name template */ assert(H5FD_FAMILY==H5Pget_driver(fapl)); h5_fixname(FILENAME[0], fapl, filename, sizeof filename); /* Create files */ for (i=0; i<NELMTS(fd); i++) { HDsnprintf(name, sizeof name, filename, i); if ((fd[i]=HDopen(name, O_RDWR|O_CREAT|O_TRUNC, 0666))<0) { goto done; } if ((off_t)size != HDlseek(fd[i], (off_t)size, SEEK_SET)) { goto done; } if (1!=HDwrite(fd[i], "X", (size_t)1)) { goto done; } } ret_value = 1; done: for (i=0; i<NELMTS(fd) && fd[i]>=0; i++) { HDsnprintf(name, sizeof name, filename, i); if(HDclose(fd[i])<0) ret_value=0; HDunlink(name); } return ret_value; }
int main(void) { hid_t fil,spc,set; hid_t cs6, cmp, fix; hid_t cmp1, cmp2, cmp3; hid_t plist; hid_t array_dt; hsize_t dim[2]; hsize_t cdim[4]; char string5[5]; float fok[2] = {1234., 2341.}; float fnok[2] = {5678., 6785.}; float *fptr; char *data; char *mname; int result = 0; printf("%-70s", "Testing alignment in compound datatypes"); strcpy(string5, "Hi!"); HDunlink(fname); fil = H5Fcreate(fname, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); if (fil < 0) { puts("*FAILED*"); return 1; } H5E_BEGIN_TRY { H5Ldelete(fil, setname, H5P_DEFAULT); } H5E_END_TRY; cs6 = H5Tcopy(H5T_C_S1); H5Tset_size(cs6, sizeof(string5)); H5Tset_strpad(cs6, H5T_STR_NULLPAD); cmp = H5Tcreate(H5T_COMPOUND, sizeof(fok) + sizeof(string5) + sizeof(fnok)); H5Tinsert(cmp, "Awkward length", 0, cs6); cdim[0] = sizeof(fok) / sizeof(float); array_dt = H5Tarray_create2(H5T_NATIVE_FLOAT, 1, cdim); H5Tinsert(cmp, "Ok", sizeof(string5), array_dt); H5Tclose(array_dt); cdim[0] = sizeof(fnok) / sizeof(float); array_dt = H5Tarray_create2(H5T_NATIVE_FLOAT, 1, cdim); H5Tinsert(cmp, "Not Ok", sizeof(fok) + sizeof(string5), array_dt); H5Tclose(array_dt); fix=h5tools_get_native_type(cmp); cmp1 = H5Tcreate(H5T_COMPOUND, sizeof(fok)); cdim[0] = sizeof(fok) / sizeof(float); array_dt = H5Tarray_create2(H5T_NATIVE_FLOAT, 1, cdim); H5Tinsert(cmp1, "Ok", 0, array_dt); H5Tclose(array_dt); cmp2 = H5Tcreate(H5T_COMPOUND, sizeof(string5)); H5Tinsert(cmp2, "Awkward length", 0, cs6); cmp3 = H5Tcreate(H5T_COMPOUND, sizeof(fnok)); cdim[0] = sizeof(fnok) / sizeof(float); array_dt = H5Tarray_create2(H5T_NATIVE_FLOAT, 1, cdim); H5Tinsert(cmp3, "Not Ok", 0, array_dt); H5Tclose(array_dt); plist = H5Pcreate(H5P_DATASET_XFER); H5Pset_preserve(plist, 1); /* * Create a small dataset, and write data into it we write each field * in turn so that we are avoid alignment issues at this point */ dim[0] = 1; spc = H5Screate_simple(1, dim, NULL); set = H5Dcreate2(fil, setname, cmp, spc, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT); H5Dwrite(set, cmp1, spc, H5S_ALL, plist, fok); H5Dwrite(set, cmp2, spc, H5S_ALL, plist, string5); H5Dwrite(set, cmp3, spc, H5S_ALL, plist, fnok); H5Dclose(set); /* Now open the set, and read it back in */ data = malloc(H5Tget_size(fix)); if(!data) { perror("malloc() failed"); abort(); } set = H5Dopen2(fil, setname, H5P_DEFAULT); H5Dread(set, fix, spc, H5S_ALL, H5P_DEFAULT, data); fptr = (float *)(data + H5Tget_member_offset(fix, 1)); if(fok[0] != fptr[0] || fok[1] != fptr[1] || fnok[0] != fptr[2] || fnok[1] != fptr[3]) { result = 1; printf("%14s (%2d) %6s = %s\n", mname = H5Tget_member_name(fix, 0), (int)H5Tget_member_offset(fix,0), string5, (char *)(data + H5Tget_member_offset(fix, 0))); free(mname); fptr = (float *)(data + H5Tget_member_offset(fix, 1)); printf("Data comparison:\n" "%14s (%2d) %6f = %f\n" " %6f = %f\n", mname = H5Tget_member_name(fix, 1), (int)H5Tget_member_offset(fix,1), fok[0], fptr[0], fok[1], fptr[1]); free(mname); fptr = (float *)(data + H5Tget_member_offset(fix, 2)); printf("%14s (%2d) %6f = %f\n" " %6f = %6f\n", mname = H5Tget_member_name(fix, 2), (int)H5Tget_member_offset(fix,2), fnok[0], fptr[0], fnok[1], fptr[1]); free(mname); fptr = (float *)(data + H5Tget_member_offset(fix, 1)); printf("\n" "Short circuit\n" " %6f = %f\n" " %6f = %f\n" " %6f = %f\n" " %6f = %f\n", fok[0], fptr[0], fok[1], fptr[1], fnok[0], fptr[2], fnok[1], fptr[3]); puts("*FAILED*"); } else { puts(" PASSED"); } free(data); H5Sclose(spc); H5Tclose(cmp); H5Tclose(cmp1); H5Tclose(cmp2); H5Tclose(cmp3); H5Pclose(plist); H5Fclose(fil); HDunlink(fname); fflush(stdout); return result; }
void cleanup_dcreate(void) { HDunlink(FILENAME); }
static void do_write_test(unsigned long file_size, unsigned long min_buf_size, unsigned long max_buf_size) { uLongf src_len, total_len; struct timeval timer_start, timer_stop; double total_time; Bytef *src; for (src_len = min_buf_size; src_len <= max_buf_size; src_len <<= 1) { register unsigned long i, iters; iters = file_size / src_len; src = (Bytef *)HDcalloc(1, sizeof(Bytef) * src_len); if (!src) { cleanup(); error("out of memory"); } compression_time = 0.0; if (random_test) fill_with_random_data(src, src_len); HDfprintf(stdout, "Buffer size == "); if (src_len >= ONE_KB && (src_len % ONE_KB) == 0) { if (src_len >= ONE_MB && (src_len % ONE_MB) == 0) { HDfprintf(stdout, "%ldMB", src_len / ONE_MB); } else { HDfprintf(stdout, "%ldKB", src_len / ONE_KB); } } else { HDfprintf(stdout, "%ld", src_len); } HDfprintf(stdout, "\n"); /* do uncompressed data write */ HDgettimeofday(&timer_start, NULL); output = HDopen(filename, O_RDWR | O_CREAT, S_IRWXU); if (output == -1) error(HDstrerror(errno)); for (i = 0; i <= iters; ++i) { Bytef *s_ptr = src; uLong s_len = src_len; /* loop to make sure we write everything out that we want to write */ for (;;) { ssize_t rc = HDwrite(output, s_ptr, s_len); if (rc == -1) error(HDstrerror(errno)); if (rc == (ssize_t)s_len) break; s_len -= rc; s_ptr += rc; } } HDclose(output); HDgettimeofday(&timer_stop, NULL); total_time = ((double)timer_stop.tv_sec + ((double)timer_stop.tv_usec) / MICROSECOND) - ((double)timer_start.tv_sec + ((double)timer_start.tv_usec) / MICROSECOND); HDfprintf(stdout, "\tUncompressed Write Time: %.2fs\n", total_time); HDfprintf(stdout, "\tUncompressed Write Throughput: %.2fMB/s\n", MB_PER_SEC(file_size, total_time)); HDunlink(filename); /* do compressed data write */ output = HDopen(filename, O_RDWR | O_CREAT, S_IRWXU); if (output == -1) error(HDstrerror(errno)); report_once_flag = 1; HDgettimeofday(&timer_start, NULL); for (total_len = 0; total_len < file_size; total_len += src_len) write_file(src, src_len); HDclose(output); HDgettimeofday(&timer_stop, NULL); total_time = ((double)timer_stop.tv_sec + ((double)timer_stop.tv_usec) / MICROSECOND) - ((double)timer_start.tv_sec + ((double)timer_start.tv_usec) / MICROSECOND); HDfprintf(stdout, "\tCompressed Write Time: %.2fs\n", total_time); HDfprintf(stdout, "\tCompressed Write Throughput: %.2fMB/s\n", MB_PER_SEC(file_size, total_time)); HDfprintf(stdout, "\tCompression Time: %gs\n", compression_time); HDunlink(filename); HDfree(src); } }
void cleanup_error(void) { HDunlink(FILENAME); }