diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/bittests.c | 12 | ||||
-rw-r--r-- | test/hyperslab.c | 12 | ||||
-rw-r--r-- | test/ttsafe_cancel.c | 4 | ||||
-rw-r--r-- | test/ttsafe_dcreate.c | 226 | ||||
-rw-r--r-- | test/ttsafe_error.c | 3 |
5 files changed, 147 insertions, 110 deletions
diff --git a/test/bittests.c b/test/bittests.c index a5af191..e1f01f9 100644 --- a/test/bittests.c +++ b/test/bittests.c @@ -513,6 +513,14 @@ main (void) { int nerrors=0; + /* + * Open the library explicitly for thread-safe builds, so per-thread + * things are initialized correctly. + */ +#ifdef H5_HAVE_THREADSAFE + H5open(); +#endif /* H5_HAVE_THREADSAFE */ + nerrors += test_find ()<0?1:0; nerrors += test_set ()<0?1:0; nerrors += test_clear()<0?1:0; @@ -524,5 +532,9 @@ main (void) exit(1); } printf("All bit tests passed.\n"); + +#ifdef H5_HAVE_THREADSAFE + H5close(); +#endif /* H5_HAVE_THREADSAFE */ return 0; } diff --git a/test/hyperslab.c b/test/hyperslab.c index 2844ec6..aa43d96 100644 --- a/test/hyperslab.c +++ b/test/hyperslab.c @@ -1114,6 +1114,14 @@ main(int argc, char *argv[]) printf("\n"); /* + * Open the library explicitly for thread-safe builds, so per-thread + * things are initialized correctly. + */ +#ifdef H5_HAVE_THREADSAFE + H5open(); +#endif /* H5_HAVE_THREADSAFE */ + + /* *------------------------------ * TEST HYPERSLAB FILL OPERATION *------------------------------ @@ -1259,5 +1267,9 @@ main(int argc, char *argv[]) exit(1); } printf("All hyperslab tests passed.\n"); + +#ifdef H5_HAVE_THREADSAFE + H5close(); +#endif /* H5_HAVE_THREADSAFE */ return 0; } diff --git a/test/ttsafe_cancel.c b/test/ttsafe_cancel.c index 2d2ce3f..8e47d09 100644 --- a/test/ttsafe_cancel.c +++ b/test/ttsafe_cancel.c @@ -86,6 +86,9 @@ void tts_cancel(void) H5Dclose(dataset); H5Fclose(cancel_file); + + /* Destroy the thread attribute */ + pthread_attr_destroy(&attribute); } void *tts_cancel_thread(void *arg) @@ -201,7 +204,6 @@ void tts_cancel_barrier(void) void cleanup_cancel(void) { - H5close(); HDunlink(FILENAME); } diff --git a/test/ttsafe_dcreate.c b/test/ttsafe_dcreate.c index ae4fdbc..d85dbe7 100644 --- a/test/ttsafe_dcreate.c +++ b/test/ttsafe_dcreate.c @@ -44,140 +44,148 @@ typedef struct thread_info { } thread_info; /* + * Set individual dataset names (rather than generated the names + * automatically) + */ +const char *dsetname[NUM_THREAD]={ + "zero", + "one", + "two", + "three", + "four", + "five", + "six", + "seven", + "eight", + "nine", + "ten", + "eleven", + "twelve", + "thirteen", + "fourteen", + "fifteen" +}; + +thread_info thread_out[NUM_THREAD]; + +/* ********************************************************************** * Thread safe test - multiple dataset creation ********************************************************************** */ void tts_dcreate(void) { - /* Pthread definitions */ - pthread_t threads[NUM_THREAD]; - - /* HDF5 data definitions */ - hid_t file, dataset, datatype; - int datavalue, i; - thread_info *thread_out; - const char *dsetname[NUM_THREAD]; - pthread_attr_t attribute; - - /* set pthread attribute to perform global scheduling */ - pthread_attr_init(&attribute); - pthread_attr_setscope(&attribute, PTHREAD_SCOPE_SYSTEM); - - /* - * Set individual dataset names (rather than generated the names - * automatically) - */ - - for (i = 0; i < NUM_THREAD; i++) - dsetname[i] = malloc(sizeof(char) * DATASETNAME_LENGTH); - - dsetname[0] = "zero"; - dsetname[1] = "one"; - dsetname[2] = "two"; - dsetname[3] = "three"; - dsetname[4] = "four"; - dsetname[5] = "five"; - dsetname[6] = "six"; - dsetname[7] = "seven"; - dsetname[8] = "eight"; - dsetname[9] = "nine"; - dsetname[10] = "ten"; - dsetname[11] = "eleven"; - dsetname[12] = "twelve"; - dsetname[13] = "thirteen"; - dsetname[14] = "fourteen"; - dsetname[15] = "fifteen"; - - /* - * Create a hdf5 file using H5F_ACC_TRUNC access, default file - * creation plist and default file access plist - */ - file = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); - - /* simultaneously create a large number of datasets within the file */ - for (i = 0; i < NUM_THREAD; i++) { - thread_out = malloc(sizeof(thread_info)); - thread_out->id = i; - thread_out->file = file; - thread_out->dsetname = dsetname[i]; - pthread_create(&threads[i], NULL, tts_dcreate_creator, thread_out); - } - - for (i = 0;i < NUM_THREAD; i++) - pthread_join(threads[i], NULL); - - /* compare data to see if it is written correctly */ - - /* define datatype for the data using native little endian integers */ - datatype = H5Tcopy(H5T_NATIVE_INT); - - for (i = 0; i < NUM_THREAD; i++) { - if ((dataset = H5Dopen(file,dsetname[i])) < 0) { - fprintf(stderr, "Dataset name not found - test failed\n"); - H5Fclose(file); - num_errs++; - return; - } else { - H5Dread(dataset, datatype, H5S_ALL, H5S_ALL, H5P_DEFAULT, &datavalue); - - if (datavalue != i) { - fprintf(stderr, - "Wrong value read %d for dataset name %s - test failed\n", - datavalue, dsetname[i]); - H5Dclose(dataset); - H5Fclose(file); - num_errs++; - return; - } - - H5Dclose(dataset); - } - } - - /* close remaining resources */ - H5Fclose(file); + /* Pthread definitions */ + pthread_t threads[NUM_THREAD]; + + /* HDF5 data definitions */ + hid_t file, dataset; + int datavalue, i; + pthread_attr_t attribute; + int ret; + + /* set pthread attribute to perform global scheduling */ + ret=pthread_attr_init(&attribute); + assert(ret==0); + ret=pthread_attr_setscope(&attribute, PTHREAD_SCOPE_SYSTEM); +/* Don't check return value on FreeBSD, since PTHREAD_SCOPE_SYSTEM is not + * currently supported in v4.7 + */ +#ifndef __FreeBSD__ + assert(ret==0); +#endif /* __FreeBSD__ */ + + /* + * Create a hdf5 file using H5F_ACC_TRUNC access, default file + * creation plist and default file access plist + */ + file = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT); + assert(file>=0); + + /* simultaneously create a large number of datasets within the file */ + for (i = 0; i < NUM_THREAD; i++) { + thread_out[i].id = i; + thread_out[i].file = file; + thread_out[i].dsetname = dsetname[i]; + ret=pthread_create(&threads[i], NULL, tts_dcreate_creator, &thread_out[i]); + assert(ret==0); + } + + for (i = 0;i < NUM_THREAD; i++) { + ret=pthread_join(threads[i], NULL); + assert(ret==0); + } /* end for */ + + /* compare data to see if it is written correctly */ + + for (i = 0; i < NUM_THREAD; i++) { + if ((dataset = H5Dopen(file,dsetname[i])) < 0) { + fprintf(stderr, "Dataset name not found - test failed\n"); + H5Fclose(file); + num_errs++; + return; + } else { + ret=H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &datavalue); + assert(ret>=0); + + if (datavalue != i) { + fprintf(stderr, "Wrong value read %d for dataset name %s - test failed\n", + datavalue, dsetname[i]); + H5Dclose(dataset); + H5Fclose(file); + num_errs++; + return; + } + + ret=H5Dclose(dataset); + assert(ret>=0); + } + } + + /* close remaining resources */ + ret=H5Fclose(file); + assert(ret>=0); + + /* Destroy the thread attribute */ + ret=pthread_attr_destroy(&attribute); + assert(ret==0); } -void *tts_dcreate_creator(void *thread_data) +void *tts_dcreate_creator(void *_thread_data) { - hid_t dataspace, datatype, dataset; + hid_t dataspace, dataset; + herr_t ret; hsize_t dimsf[1]; /* dataset dimensions */ - struct thread_info { - int id; - hid_t file; - char *dsetname; - } thread_in; + struct thread_info thread_data; - thread_in.dsetname = malloc(sizeof(char) * DATASETNAME_LENGTH); - thread_in = *((struct thread_info *)thread_data); + memcpy(&thread_data,_thread_data,sizeof(struct thread_info)); /* define dataspace for dataset */ dimsf[0] = 1; dataspace = H5Screate_simple(1,dimsf,NULL); - - /* define datatype for the data using native little endian integers */ - datatype = H5Tcopy(H5T_NATIVE_INT); - H5Tset_order(datatype, H5T_ORDER_LE); + assert(dataspace>=0); /* create a new dataset within the file */ - dataset = H5Dcreate(thread_in.file, thread_in.dsetname, - datatype, dataspace, H5P_DEFAULT); + dataset = H5Dcreate(thread_data.file, thread_data.dsetname, + H5T_NATIVE_INT, dataspace, H5P_DEFAULT); + assert(dataset>=0); /* initialize data for dataset and write value to dataset */ - H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, - H5P_DEFAULT, &thread_in.id); + ret=H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, + H5P_DEFAULT, &thread_data.id); + assert(ret>=0); + + /* close dataset and dataspace resources */ + ret=H5Dclose(dataset); + assert(ret>=0); + ret=H5Sclose(dataspace); + assert(ret>=0); - /* close dataset, datatype and dataspace resources */ - H5Dclose(dataset); - H5Tclose(datatype); - H5Sclose(dataspace); return NULL; } void cleanup_dcreate(void) { - H5close(); HDunlink(FILENAME); } #endif /*H5_HAVE_THREADSAFE*/ diff --git a/test/ttsafe_error.c b/test/ttsafe_error.c index 54ffc4b..e911863 100644 --- a/test/ttsafe_error.c +++ b/test/ttsafe_error.c @@ -130,6 +130,9 @@ void tts_error(void) /* turn our error stack handler off */ H5Eset_auto(old_error_cb, old_error_client_data); + + /* Destroy the thread attribute */ + pthread_attr_destroy(&attribute); } static |