void test_ids(void) { /* Set the random # seed */ HDsrandom((unsigned)HDtime(NULL)); if (basic_id_test() < 0) TestErrPrintf("Basic ID test failed\n"); if (id_predefined_test() < 0) TestErrPrintf("Predefined ID type test failed\n"); if (test_is_valid() < 0) TestErrPrintf("H5Iis_valid test failed\n"); if (test_get_type() < 0) TestErrPrintf("H5Iget_type test failed\n"); if (test_id_type_list() < 0) TestErrPrintf("ID type list test failed\n"); if (test_remove_clear_type() < 0) TestErrPrintf("ID remove during H5Iclear_type test failed\n"); }
/*------------------------------------------------------------------------- * Function: H5_now * * Purpose: Retrieves the current time, as seconds after the UNIX epoch. * * Return: # of seconds from the epoch (can't fail) * * Programmer: Quincey Koziol * Tuesday, November 28, 2006 * *------------------------------------------------------------------------- */ time_t H5_now(void) { time_t now; /* Current time */ #ifdef H5_HAVE_GETTIMEOFDAY { struct timeval now_tv; HDgettimeofday(&now_tv, NULL); now = now_tv.tv_sec; } #else /* H5_HAVE_GETTIMEOFDAY */ now = HDtime(NULL); #endif /* H5_HAVE_GETTIMEOFDAY */ return(now); } /* end H5_now() */
/**************************************************************** ** ** test_skiplist_init(): Test H5SL (skiplist) code. ** Initialize data for skip list testing ** ****************************************************************/ static void test_skiplist_init(void) { time_t curr_time; /* Current time, for seeding random number generator */ int new_val; /* New value to insert */ unsigned found; /* Flag to indicate value was inserted already */ size_t u,v; /* Local index variables */ /* Initialize random number seed */ curr_time = HDtime(NULL); HDsrandom((unsigned)curr_time); /* Create randomized set of numbers */ for(u=0; u<NUM_ELEMS; u++) { do { /* Reset flag */ found=0; /* Generate random numbers from -5000 to 5000 */ new_val=(int)(HDrandom()%10001)-5001; /* Check if the value is already in the array */ for(v=0; v<u; v++) if(rand_num[v]==new_val) found=1; } while(found); /* Set unique value in array */ rand_num[u]=new_val; } /* end for */ /* Copy random values to sorted array */ HDmemcpy(sort_rand_num,rand_num,sizeof(int)*NUM_ELEMS); /* Sort random numbers */ HDqsort(sort_rand_num, (size_t)NUM_ELEMS, sizeof(int), tst_sort); /* Copy random values to reverse sorted array */ HDmemcpy(rev_sort_rand_num, rand_num, sizeof(int) * NUM_ELEMS); /* Sort random numbers */ HDqsort(rev_sort_rand_num, (size_t)NUM_ELEMS, sizeof(int), tst_rev_sort); } /* end test_tst_init() */
/*------------------------------------------------------------------------- * Function: test_allocate_random * * Purpose: Tests allocating random sized blocks in pool * * Return: Success: 0 * * Failure: 1 * * Programmer: Quincey Koziol * Friday, May 6, 2005 * * Modifications: * *------------------------------------------------------------------------- */ static int test_allocate_random(void) { H5MP_pool_t *mp; /* Memory pool */ size_t u; /* Local index variable */ time_t curr_time; /* Current time, for seeding random number generator */ size_t *blk_size = NULL; /* Pointer to block sizes */ void **spc = NULL; /* Pointer to space allocated */ size_t swap_idx; /* Location to swap with when shuffling */ void *swap_ptr; /* Pointer to swap when shuffling */ /* * Test memory pool allocation */ TESTING("allocate many random sized blocks"); /* Initialize random number seed */ curr_time=HDtime(NULL); #ifdef QAK curr_time=1115412944; HDfprintf(stderr,"curr_time=%lu\n",(unsigned long)curr_time); #endif /* QAK */ HDsrandom((unsigned long)curr_time); /* Create a memory pool */ if(NULL == (mp = H5MP_create((size_t)MPOOL_PAGE_SIZE, MPOOL_FLAGS))) TEST_ERROR /* Allocate space for the block sizes */ if(NULL == (blk_size = HDmalloc(sizeof(size_t) * MPOOL_NUM_RANDOM))) TEST_ERROR /* Allocate space for the block pointers */ if(NULL == (spc = HDmalloc(sizeof(void *) * MPOOL_NUM_RANDOM))) TEST_ERROR /* Initialize the block sizes with random values */ for(u = 0; u < MPOOL_NUM_RANDOM; u++) blk_size[u] = (size_t)(HDrandom() % MPOOL_RANDOM_MAX_SIZE) + 1; /* Allocate space in pool */ for(u = 0; u < MPOOL_NUM_RANDOM; u++) if(NULL == (spc[u] = H5MP_malloc(mp, blk_size[u]))) TEST_ERROR /* Check that free space totals match */ if(H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR; /* Shuffle pointers to free */ for(u = 0; u < MPOOL_NUM_RANDOM; u++) { swap_idx = (size_t)(HDrandom() % (MPOOL_NUM_RANDOM - u)) + u; swap_ptr = spc[u]; spc[u] = spc[swap_idx]; spc[swap_idx] = swap_ptr; } /* end for */ /* Free blocks in pool */ for(u = 0; u < MPOOL_NUM_RANDOM; u++) H5MP_free(mp, spc[u]); /* Check that free space totals match */ if (H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR; /* Initialize the block sizes with random values */ for(u = 0; u < MPOOL_NUM_RANDOM; u++) blk_size[u] = (size_t)(HDrandom() % MPOOL_RANDOM_MAX_SIZE) + 1; /* Allocate space in pool (again) */ /* (Leave allocated to test closing pool with many blocks still allocated) */ for(u = 0; u < MPOOL_NUM_RANDOM; u++) if(NULL == (spc[u] = H5MP_malloc(mp, blk_size[u]))) TEST_ERROR /* Check that free space totals match */ if(H5MP_pool_is_free_size_correct(mp) <= 0) TEST_ERROR; /* Close the memory pool */ if (H5MP_close(mp) < 0) TEST_ERROR /* Free memory for block sizes & pointers */ HDfree(blk_size); HDfree(spc); PASSED(); return 0; error: if(blk_size) HDfree(blk_size); if(spc) HDfree(spc); H5E_BEGIN_TRY { } H5E_END_TRY; return 1; } /* test_allocate_random() */
/*------------------------------------------------------------------------- * Function: main * * Purpose: Tests indexed storage stuff. * * Return: Success: exit(0) * * Failure: exit(non-zero) * * Programmer: Robb Matzke * Wednesday, October 15, 1997 * * Modifications: * *------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { hid_t fapl=-1, file=-1, fcpl=-1; herr_t status; int nerrors = 0; unsigned size_of_test; unsigned u; /* Local index variable */ char filename[1024]; int skip_test = 0; int has_sparse_support = 0; /* Parse arguments or assume these tests (`small', `medium' ) */ if (1 == argc) { size_of_test = TEST_SMALL | TEST_MEDIUM | TEST_LARGE; } else { int i; for (i = 1, size_of_test = 0; i < argc; i++) { if (!strcmp(argv[i], "small")) { size_of_test |= TEST_SMALL; } else if (!strcmp(argv[i], "medium")) { size_of_test |= TEST_MEDIUM; } else if (!strcmp(argv[i], "large")) { size_of_test |= TEST_LARGE; } else { printf("unrecognized argument: %s\n", argv[i]); #if 0 exit(1); #endif } } } printf("Test sizes: "); if (size_of_test & TEST_SMALL) printf(" SMALL"); if (size_of_test & TEST_MEDIUM) printf(" MEDIUM"); if (size_of_test & TEST_LARGE) printf(" LARGE"); printf("\n"); /* Set the random # seed */ HDsrandom((unsigned)HDtime(NULL)); /* Check to see if the file system supports POSIX-style sparse files. * Windows NTFS does not, so we want to avoid tests which create * very large files. */ has_sparse_support = is_sparse(); /* Reset library */ h5_reset(); fapl = h5_fileaccess(); /* Use larger file addresses... */ fcpl = H5Pcreate(H5P_FILE_CREATE); H5Pset_sizes(fcpl, (size_t)8, (size_t)0); /* Create the test file */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if ((file=H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl)) < 0) { printf("Cannot create file %s; test aborted\n", filename); exit(1); } /* Initialize chunk dimensions */ for(u = 0; u < H5O_LAYOUT_NDIMS; u++) chunk_dims[u] = TEST_CHUNK_SIZE; /* * Creation test: Creates empty objects with various raw data sizes * and alignments. */ status = test_create(file, "create"); nerrors += status < 0 ? 1 : 0; if (size_of_test & TEST_SMALL) { status = test_extend(file, "extend", (size_t)10, (size_t)0, (size_t)0); nerrors += status < 0 ? 1 : 0; status = test_extend(file, "extend", (size_t)10, (size_t)10, (size_t)0); nerrors += status < 0 ? 1 : 0; status = test_extend(file, "extend", (size_t)10, (size_t)10, (size_t)10); nerrors += status < 0 ? 1 : 0; } if (size_of_test & TEST_MEDIUM) { status = test_extend(file, "extend", (size_t)10000, (size_t)0, (size_t)0); nerrors += status < 0 ? 1 : 0; status = test_extend(file, "extend", (size_t)2500, (size_t)10, (size_t)0); nerrors += status < 0 ? 1 : 0; status = test_extend(file, "extend", (size_t)10, (size_t)400, (size_t)10); nerrors += status < 0 ? 1 : 0; } skip_test = 0; if (size_of_test & TEST_SMALL) { status = test_sparse(file, "sparse", (size_t)100, (size_t)5, (size_t)0, (size_t)0, skip_test); nerrors += status < 0 ? 1 : 0; status = test_sparse(file, "sparse", (size_t)100, (size_t)3, (size_t)4, (size_t)0, skip_test); nerrors += status < 0 ? 1 : 0; status = test_sparse(file, "sparse", (size_t)100, (size_t)2, (size_t)3, (size_t)4, skip_test); nerrors += status < 0 ? 1 : 0; } if (size_of_test & TEST_MEDIUM) { status = test_sparse(file, "sparse", (size_t)1000, (size_t)30, (size_t)0, (size_t)0, skip_test); nerrors += status < 0 ? 1 : 0; status = test_sparse(file, "sparse", (size_t)2000, (size_t)7, (size_t)3, (size_t)0, skip_test); nerrors += status < 0 ? 1 : 0; status = test_sparse(file, "sparse", (size_t)2000, (size_t)4, (size_t)2, (size_t)3, skip_test); nerrors += status < 0 ? 1 : 0; } skip_test = !has_sparse_support; if (size_of_test & TEST_LARGE) { /* This test is skipped if there is no POSIX-style sparse file support * e.g.: Windows NTFS filesystems */ status = test_sparse(file, "sparse", (size_t)800, (size_t)50, (size_t)50, (size_t)50, skip_test); if(skip_test) printf(" The current VFD does not support sparse files on this platform.\n"); nerrors += status < 0 ? 1 : 0; } /* Close the test file and exit */ H5Pclose(fcpl); H5Fclose(file); /* Verify symbol table messages are cached */ nerrors += (h5_verify_cached_stabs(FILENAME, fapl) < 0 ? 1 : 0); if (nerrors) { printf("***** %d I-STORE TEST%s FAILED! *****\n", nerrors, 1 == nerrors ? "" : "S"); exit(1); } printf("All i-store tests passed.\n"); h5_cleanup(FILENAME, fapl); return 0; }
/*------------------------------------------------------------------------- * Function: main * * Purpose: H5O_mtime_decode() test. * * Return: Success: * * Failure: * * Programmer: Robb Matzke * Thursday, July 30, 1998 * * Modifications: * Added checks for old and new modification time messages * in pre-created datafiles (generated with gen_old_mtime.c and * gen_new_mtime.c). * Quincey Koziol * Friday, January 3, 2003 * *------------------------------------------------------------------------- */ int main(void) { hid_t fapl, file, space, dset; hsize_t size[1] = {2}; time_t now; struct tm *tm; H5O_info_t oi1, oi2; signed char buf1[32], buf2[32]; char filename[1024]; h5_reset(); fapl = h5_fileaccess(); TESTING("modification time messages"); /* Create the file, create a dataset, then close the file */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if((file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0) TEST_ERROR; if((space = H5Screate_simple(1, size, NULL)) < 0) TEST_ERROR; if((dset = H5Dcreate2(file, "dset", H5T_NATIVE_SCHAR, space, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR; now = HDtime(NULL); if(H5Dclose(dset) < 0) TEST_ERROR; if(H5Sclose(space) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; /* * Open the file and get the modification time. We'll test the * H5Oget_info() arguments too: being able to stat something without * knowing its name. */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if((file = H5Fopen(filename, H5F_ACC_RDONLY, fapl)) < 0) TEST_ERROR; if(H5Oget_info_by_name(file, "dset", &oi1, H5P_DEFAULT) < 0) TEST_ERROR; if((dset = H5Dopen2(file, "dset", H5P_DEFAULT)) < 0) TEST_ERROR; if(H5Oget_info(dset, &oi2) < 0) TEST_ERROR; if(H5Dclose(dset) < 0) TEST_ERROR; if(H5Fclose(file) < 0) TEST_ERROR; /* Compare addresses & times from the two ways of calling H5Oget_info() */ if(oi1.addr != oi2.addr || oi1.mtime != oi2.mtime) { H5_FAILED(); puts(" Calling H5Oget_info() with the dataset ID returned"); puts(" different values than calling it with a file and dataset"); puts(" name."); goto error; } /* Compare times -- they must be within 60 seconds of one another */ if(0 == oi1.mtime) { SKIPPED(); puts(" The modification time could not be decoded on this OS."); puts(" Modification times will be mantained in the file but"); puts(" cannot be queried on this system. See H5O_mtime_decode()."); return 0; } else if(HDfabs(HDdifftime(now, oi1.mtime)) > 60.0) { H5_FAILED(); tm = HDlocaltime(&(oi1.mtime)); HDstrftime((char*)buf1, sizeof buf1, "%Y-%m-%d %H:%M:%S", tm); tm = HDlocaltime(&now); HDstrftime((char*)buf2, sizeof buf2, "%Y-%m-%d %H:%M:%S", tm); printf(" got: %s\n ans: %s\n", buf1, buf2); goto error; } PASSED(); /* Check opening existing file with old-style modification time information * and make certain that the time is correct */ TESTING("accessing old modification time messages"); { char testfile[512]=""; char *srcdir = HDgetenv("srcdir"); if(srcdir && ((HDstrlen(srcdir) + strlen(TESTFILE1) + 1) < sizeof(testfile))){ HDstrcpy(testfile, srcdir); HDstrcat(testfile, "/"); } HDstrcat(testfile, TESTFILE1); file = H5Fopen(testfile, H5F_ACC_RDONLY, H5P_DEFAULT); if(file >= 0){ if(H5Oget_info_by_name(file, "/Dataset1", &oi1, H5P_DEFAULT) < 0) TEST_ERROR; if(oi1.mtime != MTIME1) { H5_FAILED(); /* If this fails, examine H5Omtime.c. Modification time is very * system dependant (e.g., on Windows DST must be hardcoded). */ puts(" Old modification time incorrect"); goto error; } if(H5Fclose(file) < 0) TEST_ERROR; } else { H5_FAILED(); printf("***cannot open the pre-created old modification test file (%s)\n", testfile); goto error; } /* end else */ } PASSED(); /* Check opening existing file with new-style modification time information * and make certain that the time is correct */ TESTING("accessing new modification time messages"); { char testfile[512]=""; char *srcdir = HDgetenv("srcdir"); if(srcdir && ((HDstrlen(srcdir) + strlen(TESTFILE2) + 1) < sizeof(testfile))){ HDstrcpy(testfile, srcdir); HDstrcat(testfile, "/"); } HDstrcat(testfile, TESTFILE2); file = H5Fopen(testfile, H5F_ACC_RDONLY, H5P_DEFAULT); if(file >= 0){ if(H5Oget_info_by_name(file, "/Dataset1", &oi2, H5P_DEFAULT) < 0) TEST_ERROR; if(oi2.mtime != MTIME2) { H5_FAILED(); puts(" Modification time incorrect."); goto error; } if(H5Fclose(file) < 0) TEST_ERROR; } else { H5_FAILED(); printf("***cannot open the pre-created old modification test file (%s)\n", testfile); goto error; } /* end else */ } PASSED(); /* All looks good */ puts("All modification time tests passed."); h5_cleanup(FILENAME, fapl); return 0; /* Something broke */ error: return 1; }
/*------------------------------------------------------------------------- * Function: main * * Purpose: Tests indexed storage stuff. * * Return: Success: exit(0) * * Failure: exit(non-zero) * * Programmer: Robb Matzke * Wednesday, October 15, 1997 * * Modifications: * *------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { hid_t fapl=-1, file=-1, fcpl=-1; herr_t status; int nerrors = 0; unsigned size_of_test; unsigned u; /* Local index variable */ char filename[1024]; /* Parse arguments or assume these tests (`small', `medium' ) */ if (1 == argc) { size_of_test = TEST_SMALL; } else { int i; for (i = 1, size_of_test = 0; i < argc; i++) { if (!strcmp(argv[i], "small")) { size_of_test |= TEST_SMALL; } else if (!strcmp(argv[i], "medium")) { size_of_test |= TEST_MEDIUM; } else if (!strcmp(argv[i], "large")) { size_of_test |= TEST_LARGE; } else { printf("unrecognized argument: %s\n", argv[i]); #if 0 exit(1); #endif } } } printf("Test sizes: "); if (size_of_test & TEST_SMALL) printf(" SMALL"); if (size_of_test & TEST_MEDIUM) printf(" MEDIUM"); if (size_of_test & TEST_LARGE) printf(" LARGE"); printf("\n"); /* Set the random # seed */ HDsrandom((unsigned long)HDtime(NULL)); /* Reset library */ h5_reset(); fapl = h5_fileaccess(); /* Use larger file addresses... */ fcpl = H5Pcreate(H5P_FILE_CREATE); H5Pset_sizes(fcpl, 8, 0); /* Create the test file */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if ((file=H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl))<0) { printf("Cannot create file %s; test aborted\n", filename); exit(1); } /* * For testing file families, fool the library into thinking it already * allocated a whole bunch of data. */ if (H5FD_FAMILY==H5Pget_driver(fapl)) { haddr_t addr; H5F_t *f; addr = 8 * ((uint64_t)1<<30); /*8 GB */ f=H5I_object(file); if (H5FDset_eoa(f->shared->lf, addr)<0) { printf("Cannot create large file family\n"); exit(1); } } /* Initialize chunk dimensions */ for (u = 0; u < H5O_LAYOUT_NDIMS; u++) chunk_dims[u]=TEST_CHUNK_SIZE; /* * Creation test: Creates empty objects with various raw data sizes * and alignments. */ status = test_create(file, "create"); nerrors += status < 0 ? 1 : 0; if (size_of_test & TEST_SMALL) { status = test_extend(file, "extend", 10, 0, 0); nerrors += status < 0 ? 1 : 0; status = test_extend(file, "extend", 10, 10, 0); nerrors += status < 0 ? 1 : 0; status = test_extend(file, "extend", 10, 10, 10); nerrors += status < 0 ? 1 : 0; } if (size_of_test & TEST_MEDIUM) { status = test_extend(file, "extend", 10000, 0, 0); nerrors += status < 0 ? 1 : 0; status = test_extend(file, "extend", 2500, 10, 0); nerrors += status < 0 ? 1 : 0; status = test_extend(file, "extend", 10, 400, 10); nerrors += status < 0 ? 1 : 0; } if (size_of_test & TEST_SMALL) { status = test_sparse(file, "sparse", 100, 5, 0, 0); nerrors += status < 0 ? 1 : 0; status = test_sparse(file, "sparse", 100, 3, 4, 0); nerrors += status < 0 ? 1 : 0; status = test_sparse(file, "sparse", 100, 2, 3, 4); nerrors += status < 0 ? 1 : 0; } if (size_of_test & TEST_MEDIUM) { status = test_sparse(file, "sparse", 1000, 30, 0, 0); nerrors += status < 0 ? 1 : 0; status = test_sparse(file, "sparse", 2000, 7, 3, 0); nerrors += status < 0 ? 1 : 0; status = test_sparse(file, "sparse", 2000, 4, 2, 3); nerrors += status < 0 ? 1 : 0; } if (size_of_test & TEST_LARGE) { status = test_sparse(file, "sparse", 800, 50, 50, 50); nerrors += status < 0 ? 1 : 0; } /* Close the test file and exit */ H5Pclose(fcpl); H5Fclose(file); if (nerrors) { printf("***** %d I-STORE TEST%s FAILED! *****\n", nerrors, 1 == nerrors ? "" : "S"); exit(1); } printf("All i-store tests passed.\n"); h5_cleanup(FILENAME, fapl); return 0; }
/*------------------------------------------------------------------------- * Function: print_header * * Purpose: Prints the header for the generated file. * * Return: void *------------------------------------------------------------------------- */ static void print_header(void) { time_t now = HDtime(NULL); struct tm *tm = HDlocaltime(&now); char real_name[30]; char host_name[256]; int i; const char *s; #ifdef H5_HAVE_GETPWUID struct passwd *pwd = NULL; #else int pwd = 1; #endif static const char *month_name[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; static const char *purpose = "\ This machine-generated source code contains\n\ information about the library build configuration\n"; /* * The real name is the first item from the passwd gecos field. */ #ifdef H5_HAVE_GETPWUID { size_t n; char *comma; if((pwd = HDgetpwuid(HDgetuid()))) { if((comma = HDstrchr(pwd->pw_gecos, ','))) { n = MIN(sizeof(real_name) - 1, (unsigned)(comma - pwd->pw_gecos)); HDstrncpy(real_name, pwd->pw_gecos, n); real_name[n] = '\0'; } /* end if */ else { HDstrncpy(real_name, pwd->pw_gecos, sizeof(real_name)); real_name[sizeof(real_name) - 1] = '\0'; } /* end else */ } /* end if */ else real_name[0] = '\0'; } #else real_name[0] = '\0'; #endif /* * The FQDM of this host or the empty string. */ #ifdef H5_HAVE_GETHOSTNAME if(HDgethostname(host_name, sizeof(host_name)) < 0) host_name[0] = '\0'; #else host_name[0] = '\0'; #endif /* * The file header: warning, copyright notice, build information. */ fprintf(rawoutstream, "/* Generated automatically by H5make_libsettings -- do not edit */\n\n\n"); HDfputs(FileHeader, rawoutstream); /*the copyright notice--see top of this file */ fprintf(rawoutstream, " *\n * Created:\t\t%s %2d, %4d\n", month_name[tm->tm_mon], tm->tm_mday, 1900 + tm->tm_year); if(pwd || real_name[0] || host_name[0]) { fprintf(rawoutstream, " *\t\t\t"); if(real_name[0]) fprintf(rawoutstream, "%s <", real_name); #ifdef H5_HAVE_GETPWUID if(pwd) HDfputs(pwd->pw_name, rawoutstream); #endif if(host_name[0]) fprintf(rawoutstream, "@%s", host_name); if(real_name[0]) fprintf(rawoutstream, ">"); HDfputc('\n', rawoutstream); } /* end if */ fprintf(rawoutstream, " *\n * Purpose:\t\t"); for(s = purpose; *s; s++) { HDfputc(*s, rawoutstream); if('\n' == *s && s[1]) fprintf(rawoutstream, " *\t\t\t"); } /* end for */ fprintf(rawoutstream, " *\n * Modifications:\n *\n"); fprintf(rawoutstream, " *\tDO NOT MAKE MODIFICATIONS TO THIS FILE!\n"); fprintf(rawoutstream, " *\tIt was generated by code in `H5make_libsettings.c'.\n"); fprintf(rawoutstream, " *\n *"); for(i = 0; i < 73; i++) HDfputc('-', rawoutstream); fprintf(rawoutstream, "\n */\n\n"); }
/*------------------------------------------------------------------------- * Function: main * * Purpose: Tests indexed storage stuff. * * Return: Success: exit(0) * * Failure: exit(non-zero) * * Programmer: Robb Matzke * Wednesday, October 15, 1997 * * Modifications: * *------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { hid_t fapl=-1, file=-1, fcpl=-1; herr_t status; int nerrors = 0; unsigned size_of_test; unsigned u; /* Local index variable */ char filename[1024]; /* Parse arguments or assume these tests (`small', `medium' ) */ if (1 == argc) { size_of_test = TEST_SMALL | TEST_MEDIUM | TEST_LARGE; } else { int i; for (i = 1, size_of_test = 0; i < argc; i++) { if (!strcmp(argv[i], "small")) { size_of_test |= TEST_SMALL; } else if (!strcmp(argv[i], "medium")) { size_of_test |= TEST_MEDIUM; } else if (!strcmp(argv[i], "large")) { size_of_test |= TEST_LARGE; } else { printf("unrecognized argument: %s\n", argv[i]); #if 0 exit(1); #endif } } } printf("Test sizes: "); if (size_of_test & TEST_SMALL) printf(" SMALL"); if (size_of_test & TEST_MEDIUM) printf(" MEDIUM"); if (size_of_test & TEST_LARGE) printf(" LARGE"); printf("\n"); /* Set the random # seed */ HDsrandom((unsigned)HDtime(NULL)); /* Reset library */ h5_reset(); fapl = h5_fileaccess(); /* Use larger file addresses... */ fcpl = H5Pcreate(H5P_FILE_CREATE); H5Pset_sizes(fcpl, (size_t)8, (size_t)0); /* Create the test file */ h5_fixname(FILENAME[0], fapl, filename, sizeof filename); if ((file=H5Fcreate(filename, H5F_ACC_TRUNC, fcpl, fapl)) < 0) { printf("Cannot create file %s; test aborted\n", filename); exit(1); } /* Initialize chunk dimensions */ for(u = 0; u < H5O_LAYOUT_NDIMS; u++) chunk_dims[u] = TEST_CHUNK_SIZE; /* * Creation test: Creates empty objects with various raw data sizes * and alignments. */ status = test_create(file, "create"); nerrors += status < 0 ? 1 : 0; if (size_of_test & TEST_SMALL) { status = test_extend(file, "extend", (size_t)10, (size_t)0, (size_t)0); nerrors += status < 0 ? 1 : 0; status = test_extend(file, "extend", (size_t)10, (size_t)10, (size_t)0); nerrors += status < 0 ? 1 : 0; status = test_extend(file, "extend", (size_t)10, (size_t)10, (size_t)10); nerrors += status < 0 ? 1 : 0; } if (size_of_test & TEST_MEDIUM) { status = test_extend(file, "extend", (size_t)10000, (size_t)0, (size_t)0); nerrors += status < 0 ? 1 : 0; status = test_extend(file, "extend", (size_t)2500, (size_t)10, (size_t)0); nerrors += status < 0 ? 1 : 0; status = test_extend(file, "extend", (size_t)10, (size_t)400, (size_t)10); nerrors += status < 0 ? 1 : 0; } if (size_of_test & TEST_SMALL) { status = test_sparse(file, "sparse", (size_t)100, (size_t)5, (size_t)0, (size_t)0); nerrors += status < 0 ? 1 : 0; status = test_sparse(file, "sparse", (size_t)100, (size_t)3, (size_t)4, (size_t)0); nerrors += status < 0 ? 1 : 0; status = test_sparse(file, "sparse", (size_t)100, (size_t)2, (size_t)3, (size_t)4); nerrors += status < 0 ? 1 : 0; } if (size_of_test & TEST_MEDIUM) { status = test_sparse(file, "sparse", (size_t)1000, (size_t)30, (size_t)0, (size_t)0); nerrors += status < 0 ? 1 : 0; status = test_sparse(file, "sparse", (size_t)2000, (size_t)7, (size_t)3, (size_t)0); nerrors += status < 0 ? 1 : 0; status = test_sparse(file, "sparse", (size_t)2000, (size_t)4, (size_t)2, (size_t)3); nerrors += status < 0 ? 1 : 0; } if (size_of_test & TEST_LARGE) { status = test_sparse(file, "sparse", (size_t)800, (size_t)50, (size_t)50, (size_t)50); nerrors += status < 0 ? 1 : 0; } /* Close the test file and exit */ H5Pclose(fcpl); H5Fclose(file); if (nerrors) { printf("***** %d I-STORE TEST%s FAILED! *****\n", nerrors, 1 == nerrors ? "" : "S"); exit(1); } printf("All i-store tests passed.\n"); h5_cleanup(FILENAME, fapl); return 0; }
/*------------------------------------------------------------------------- * Function: main * * Purpose: * * Return: Success: * * Failure: * * Programmer: Robb Matzke * Friday, April 10, 1998 * * Modifications: * Albert Cheng, 2002/03/28 * Added command option -fsize. * Albert Cheng, 2002/04/19 * Added command option -c. * * Raymond Lu, 2007/05/25 * Added similar tests for SEC2 and STDIO drivers. * *------------------------------------------------------------------------- */ int main (int ac, char **av) { unsigned long seed = 0; /* Random # seed */ hid_t fapl = -1; hid_t driver = -1; /* parameters setup */ while (--ac > 0){ av++; if (HDstrcmp("-fsize", *av)==0){ /* specify a different family file size */ ac--; av++; if (ac > 0) { family_size_def = (hsize_t)HDstrtoull(*av, NULL, 0); } else{ printf("***Missing fsize value***\n"); usage(); return 1; } } else if (HDstrcmp("-c", *av)==0){ /* turn off file system check before test */ cflag=0; } else if (HDstrcmp("-h", *av)==0){ usage(); return 0; }else{ usage(); return 1; } } /* check VFD to see if this is one we test */ if((fapl = h5_fileaccess()) < 0) goto error; if((driver = H5Pget_driver(fapl)) < 0) goto error; /* check sparse file support unless cflag is not set. */ if(cflag) sparse_support = is_sparse(); /* Choose random # seed */ seed = (unsigned long)HDtime(NULL); #ifdef QAK /* seed = (unsigned long)1155438845; */ HDfprintf(stderr, "Random # seed was: %lu\n", seed); #endif /* QAK */ HDsrandom(seed); /* run VFD-specific test */ if(H5FD_SEC2 == driver) { if(test_sec2(fapl) != 0) goto error; } else if(H5FD_STDIO == driver) { if(test_stdio(fapl) != 0) goto error; } else if(H5FD_FAMILY == driver) { if(test_family(fapl) != 0) goto error; } else HDputs("This VFD is not supported"); /* End with normal exit code */ /* fapls are cleaned up in the vfd test code */ return 0; error: HDputs("*** TEST FAILED ***"); if(fapl > 0) H5Pclose(fapl); return 1; }
/*------------------------------------------------------------------------- * Function: read_records * * Purpose: For a given dataset, checks to make sure that the stated * and actual sizes are the same. If they are not, then * we have an inconsistent dataset due to a SWMR error. * * Parameters: const char *filename * The SWMR test file's name. * * unsigned verbose * Whether verbose console output is desired. * * unsigned long nrecords * The total number of records to read. * * unsigned poll_time * The amount of time to sleep (s). * * unsigned reopen_count * * * Return: Success: 0 * Failure: -1 * *------------------------------------------------------------------------- */ static int read_records(const char *filename, unsigned verbose, unsigned long nrecords, unsigned poll_time, unsigned reopen_count) { hid_t fid; /* File ID */ hid_t aid; /* Attribute ID */ time_t start_time; /* Starting time */ hid_t mem_sid; /* Memory dataspace ID */ symbol_t record; /* The record to add to the dataset */ unsigned seed; /* Seed for random number generator */ unsigned iter_to_reopen = reopen_count; /* # of iterations until reopen */ unsigned long u; /* Local index variable */ hid_t fapl; HDassert(filename); HDassert(poll_time != 0); /* Create file access property list */ if((fapl = h5_fileaccess()) < 0) return -1; H5Pset_fclose_degree(fapl, H5F_CLOSE_SEMI); /* Emit informational message */ if(verbose) HDfprintf(stderr, "Opening file: %s\n", filename); /* Open the file */ if((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, fapl)) < 0) return -1; /* Seed the random number generator with the attribute in the file */ if((aid = H5Aopen(fid, "seed", H5P_DEFAULT)) < 0) return -1; if(H5Aread(aid, H5T_NATIVE_UINT, &seed) < 0) return -1; if(H5Aclose(aid) < 0) return -1; HDsrandom(seed); /* Reset the record */ /* (record's 'info' field might need to change for each record written, also) */ HDmemset(&record, 0, sizeof(record)); /* Create a dataspace for the record to read */ if((mem_sid = H5Screate(H5S_SCALAR)) < 0) return -1; /* Emit informational message */ if(verbose) HDfprintf(stderr, "Reading records\n"); /* Get the starting time */ start_time = HDtime(NULL); /* Read records */ for(u = 0; u < nrecords; u++) { symbol_info_t *symbol = NULL; /* Symbol (dataset) */ htri_t attr_exists; /* Whether the sequence number attribute exists */ unsigned long file_u; /* Attribute sequence number (writer's "u") */ /* Get a random dataset, according to the symbol distribution */ symbol = choose_dataset(); /* Fill in "nrecords" field. Note that this depends on the writer * using the same algorithm and "nrecords" */ symbol->nrecords = nrecords / 5; /* Wait until we can read the dataset */ do { /* Check if sequence attribute exists */ if((attr_exists = H5Aexists_by_name(fid, symbol->name, "seq", H5P_DEFAULT)) < 0) return -1; if(attr_exists) { /* Read sequence number attribute */ if((aid = H5Aopen_by_name(fid, symbol->name, "seq", H5P_DEFAULT, H5P_DEFAULT)) < 0) return -1; if(H5Aread(aid, H5T_NATIVE_ULONG, &file_u) < 0) return -1; if(H5Aclose(aid) < 0) return -1; /* Check if sequence number is at least u - if so, this should * guarantee that this record has been written */ if(file_u >= u) break; } /* end if */ /* Check for timeout */ if(HDtime(NULL) >= (time_t)(start_time + (time_t)TIMEOUT)) { HDfprintf(stderr, "Reader timed out\n"); return -1; } /* end if */ /* Pause */ HDsleep(poll_time); /* Retrieve and print the collection of metadata read retries */ if(print_metadata_retries_info(fid) < 0) HDfprintf(stderr, "Warning: could not obtain metadata retries info\n"); /* Reopen the file */ if(H5Fclose(fid) < 0) return -1; if((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, fapl)) < 0) return -1; iter_to_reopen = reopen_count; } while(1); /* Emit informational message */ if(verbose) HDfprintf(stderr, "Checking dataset %lu\n", u); /* Check dataset */ if(check_dataset(fid, verbose, symbol, &record, mem_sid) < 0) return -1; HDmemset(&record, 0, sizeof(record)); /* Check for reopen */ iter_to_reopen--; if(iter_to_reopen == 0) { /* Emit informational message */ if(verbose) HDfprintf(stderr, "Reopening file: %s\n", filename); /* Retrieve and print the collection of metadata read retries */ if(print_metadata_retries_info(fid) < 0) HDfprintf(stderr, "Warning: could not obtain metadata retries info\n"); /* Reopen the file */ if(H5Fclose(fid) < 0) return -1; if((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, fapl)) < 0) return -1; iter_to_reopen = reopen_count; } /* end if */ } /* end while */ /* Retrieve and print the collection of metadata read retries */ if(print_metadata_retries_info(fid) < 0) HDfprintf(stderr, "Warning: could not obtain metadata retries info\n"); /* Close file */ if(H5Fclose(fid) < 0) return -1; /* Close the memory dataspace */ if(H5Sclose(mem_sid) < 0) return -1; return 0; } /* end read_records() */
/**************************************************************** ** ** test_tst_init(): Test basic H5ST (ternary search tree) selection code. ** Initialize data for TST testing ** ****************************************************************/ static void test_tst_init(void) { time_t curr_time; /* Current time, for seeding random number generator */ char *tmp_word;/* Temporary pointer to word in word set */ size_t u,v,w; /* Local index variables */ /* Compute the number of words in the test set */ num_words=sizeof(words)/sizeof(words[0]); /* Determine the number of unique words in test set */ /* (Not particularly efficient, be careful if many words are added to set) */ num_uniq_words=0; for(u=0; u<num_words; u++) { /* Assume word is unique */ num_uniq_words++; for(v=0; v<u; v++) /* If word is already found in words looked at, decrement unique count */ if(!HDstrcmp(words[u],words[v])) { num_uniq_words--; break; } /* end if */ } /* end for */ /* Allocate space for the array of unique words */ uniq_words=HDmalloc(sizeof(char *)*num_uniq_words); /* Allocate space for the array of randomized order unique words also */ rand_uniq_words=HDmalloc(sizeof(char *)*num_uniq_words); /* Allocate space for the array of sorted order unique words also */ sort_uniq_words=HDmalloc(sizeof(char *)*num_uniq_words); /* Insert unique words from test set into unique word set */ w=0; for(u=0; u<num_words; u++) { /* Assume word is unique */ tmp_word=(char *)words[u]; for(v=0; v<u; v++) /* If word is already found in words looked at, decrement unique count */ if(!HDstrcmp(words[u],words[v])) { tmp_word=NULL; break; } /* end if */ /* Check if word was actually unique */ if(tmp_word!=NULL) uniq_words[w++]=tmp_word; } /* end for */ /* Create randomized set of unique words */ for(u=0; u<num_uniq_words; u++) rand_uniq_words[u]=uniq_words[u]; curr_time=HDtime(NULL); HDsrandom((unsigned long)curr_time); for(u=0; u<num_uniq_words; u++) { v=u+(HDrandom()%(num_uniq_words-u)); if(u!=v) { tmp_word=rand_uniq_words[u]; rand_uniq_words[u]=rand_uniq_words[v]; rand_uniq_words[v]=tmp_word; } /* end if */ } /* end for */ /* Create sorted set of unique words */ for(u=0; u<num_uniq_words; u++) sort_uniq_words[u]=uniq_words[u]; HDqsort(sort_uniq_words,num_uniq_words,sizeof(char *),tst_strcmp); } /* end test_tst_init() */