2003-04-01 01:59:04 +08:00
|
|
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
2007-02-07 22:56:24 +08:00
|
|
|
* Copyright by The HDF Group. *
|
2003-04-01 01:59:04 +08:00
|
|
|
* Copyright by the Board of Trustees of the University of Illinois. *
|
|
|
|
* All rights reserved. *
|
|
|
|
* *
|
|
|
|
* This file is part of HDF5. The full HDF5 copyright notice, including *
|
|
|
|
* terms governing use, modification, and redistribution, is contained in *
|
2017-04-18 03:32:16 +08:00
|
|
|
* the COPYING file, which can be found at the root of the source code *
|
|
|
|
* distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
|
|
|
|
* If you do not have access to either file, you may request a copy from *
|
|
|
|
* help@hdfgroup.org. *
|
2003-04-01 01:59:04 +08:00
|
|
|
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
|
|
|
|
2000-05-19 03:13:33 +08:00
|
|
|
/********************************************************************
|
|
|
|
*
|
|
|
|
* Testing thread safety. Deliberate per-thread errors to test error stack
|
|
|
|
* -----------------------------------------------------------------------
|
|
|
|
*
|
|
|
|
* Create 16 multiple threads to create datasets with the same name. The
|
|
|
|
* library should respond with 15 equivalent error stack printouts (one for
|
|
|
|
* each bad thread). The final hdf5 file should be a valid file with one
|
|
|
|
* entry.
|
|
|
|
*
|
|
|
|
* Temporary files generated:
|
2001-09-05 01:37:10 +08:00
|
|
|
*
|
|
|
|
* ttsafe_error.h5
|
2000-05-19 03:13:33 +08:00
|
|
|
*
|
|
|
|
* Created: Apr 28 2000
|
|
|
|
* Programmer: Chee Wai LEE
|
|
|
|
*
|
|
|
|
********************************************************************/
|
|
|
|
#include "ttsafe.h"
|
|
|
|
|
2003-06-26 10:10:33 +08:00
|
|
|
#ifdef H5_HAVE_THREADSAFE
|
2000-05-19 03:13:33 +08:00
|
|
|
|
2006-08-28 05:09:31 +08:00
|
|
|
#define NUM_THREAD 16
|
2001-09-05 01:37:10 +08:00
|
|
|
#define FILENAME "ttsafe_error.h5"
|
2000-05-20 07:00:03 +08:00
|
|
|
|
2000-05-19 03:13:33 +08:00
|
|
|
/* Having a common dataset name is an error */
|
2018-05-14 15:44:02 +08:00
|
|
|
#define DATASETNAME "commonname"
|
2018-10-10 23:10:15 +08:00
|
|
|
#define EXPECTED_ERROR_DEPTH 9
|
2018-05-14 15:44:02 +08:00
|
|
|
#define WRITE_NUMBER 37
|
2000-05-19 03:13:33 +08:00
|
|
|
|
2018-05-14 15:44:02 +08:00
|
|
|
/* Typedefs */
|
2000-05-19 03:13:33 +08:00
|
|
|
typedef struct err_num_struct {
|
2003-08-09 03:06:29 +08:00
|
|
|
hid_t maj_num;
|
|
|
|
hid_t min_num;
|
2000-05-19 03:13:33 +08:00
|
|
|
} err_num_t;
|
|
|
|
|
2018-05-14 15:44:02 +08:00
|
|
|
/* Global variables */
|
|
|
|
hid_t error_file_g = H5I_INVALID_HID;
|
|
|
|
int error_flag_g = 0;
|
|
|
|
int error_count_g = 0;
|
|
|
|
err_num_t expected_g[EXPECTED_ERROR_DEPTH];
|
|
|
|
H5TS_mutex_simple_t error_mutex_g;
|
|
|
|
|
|
|
|
/* Prototypes */
|
|
|
|
static herr_t error_callback(hid_t , void *);
|
|
|
|
static herr_t walk_error_callback(unsigned, const H5E_error2_t *, void *);
|
|
|
|
static void *tts_error_thread(void *);
|
2000-05-20 07:00:03 +08:00
|
|
|
|
2000-05-19 03:13:33 +08:00
|
|
|
|
2018-05-14 15:44:02 +08:00
|
|
|
void
|
|
|
|
tts_error(void)
|
2000-05-20 07:00:03 +08:00
|
|
|
{
|
2018-05-14 15:44:02 +08:00
|
|
|
hid_t dataset = H5I_INVALID_HID;
|
|
|
|
H5TS_thread_t threads[NUM_THREAD];
|
|
|
|
H5TS_attr_t attribute;
|
|
|
|
int value, i;
|
|
|
|
herr_t status;
|
2003-08-09 03:06:29 +08:00
|
|
|
|
|
|
|
/* Must initialize these at runtime */
|
2018-05-14 15:44:02 +08:00
|
|
|
expected_g[0].maj_num = H5E_DATASET;
|
|
|
|
expected_g[0].min_num = H5E_CANTINIT;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2018-10-10 23:10:15 +08:00
|
|
|
expected_g[1].maj_num = H5E_VOL;
|
2018-05-14 15:44:02 +08:00
|
|
|
expected_g[1].min_num = H5E_CANTINIT;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2018-10-10 23:10:15 +08:00
|
|
|
expected_g[2].maj_num = H5E_DATASET;
|
2018-05-14 15:44:02 +08:00
|
|
|
expected_g[2].min_num = H5E_CANTINIT;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2018-10-10 23:10:15 +08:00
|
|
|
expected_g[3].maj_num = H5E_DATASET;
|
|
|
|
expected_g[3].min_num = H5E_CANTINIT;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2018-10-10 23:10:15 +08:00
|
|
|
expected_g[4].maj_num = H5E_LINK;
|
|
|
|
expected_g[4].min_num = H5E_CANTINIT;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2018-10-10 23:10:15 +08:00
|
|
|
expected_g[5].maj_num = H5E_LINK;
|
|
|
|
expected_g[5].min_num = H5E_CANTINSERT;
|
2007-04-12 01:18:45 +08:00
|
|
|
|
2018-10-10 23:10:15 +08:00
|
|
|
expected_g[6].maj_num = H5E_SYM;
|
|
|
|
expected_g[6].min_num = H5E_NOTFOUND;
|
|
|
|
|
|
|
|
expected_g[7].maj_num = H5E_SYM;
|
|
|
|
expected_g[7].min_num = H5E_CALLBACK;
|
|
|
|
|
|
|
|
expected_g[8].maj_num = H5E_LINK;
|
|
|
|
expected_g[8].min_num = H5E_EXISTS;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2003-08-09 03:06:29 +08:00
|
|
|
/* set up mutex for global count of errors */
|
2018-05-14 15:44:02 +08:00
|
|
|
H5TS_mutex_init(&error_mutex_g);
|
2003-08-09 03:06:29 +08:00
|
|
|
|
|
|
|
/* make thread scheduling global */
|
2010-09-11 00:15:34 +08:00
|
|
|
H5TS_attr_init(&attribute);
|
|
|
|
|
2003-08-09 03:06:29 +08:00
|
|
|
#ifdef H5_HAVE_SYSTEM_SCOPE_THREADS
|
2018-05-14 15:44:02 +08:00
|
|
|
/* set thread scope to system */
|
2010-09-11 00:15:34 +08:00
|
|
|
H5TS_attr_setscope(&attribute, H5TS_SCOPE_SYSTEM);
|
2003-08-09 03:06:29 +08:00
|
|
|
#endif /* H5_HAVE_SYSTEM_SCOPE_THREADS */
|
2003-07-26 10:55:47 +08:00
|
|
|
|
2018-05-14 15:44:02 +08:00
|
|
|
/* Create a hdf5 file using H5F_ACC_TRUNC access, default file
|
2003-08-09 03:06:29 +08:00
|
|
|
* creation plist and default file access plist
|
|
|
|
*/
|
2018-05-14 15:44:02 +08:00
|
|
|
error_file_g = H5Fcreate(FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
|
|
|
|
CHECK(error_file_g, H5I_INVALID_HID, "H5Fcreate");
|
2000-05-20 07:00:03 +08:00
|
|
|
|
2018-05-14 15:44:02 +08:00
|
|
|
for (i = 0; i < NUM_THREAD; i++)
|
2010-09-11 00:15:34 +08:00
|
|
|
threads[i] = H5TS_create_thread(tts_error_thread, &attribute, NULL);
|
2000-05-20 07:00:03 +08:00
|
|
|
|
2018-05-14 15:44:02 +08:00
|
|
|
for (i = 0; i < NUM_THREAD; i++)
|
2010-09-11 00:15:34 +08:00
|
|
|
H5TS_wait_for_thread(threads[i]);
|
2000-05-20 07:00:03 +08:00
|
|
|
|
2018-05-14 15:44:02 +08:00
|
|
|
if (error_flag_g) {
|
|
|
|
TestErrPrintf("At least one thread reported a value that was different from the exected value\n");
|
|
|
|
HDprintf("(Update this test if the error stack changed!)\n");
|
|
|
|
}
|
2003-08-09 03:06:29 +08:00
|
|
|
|
2018-05-14 15:44:02 +08:00
|
|
|
if (error_count_g != NUM_THREAD - 1)
|
|
|
|
TestErrPrintf("Error: %d threads failed instead of %d\n", error_count_g, NUM_THREAD-1);
|
2003-08-09 03:06:29 +08:00
|
|
|
|
2018-05-14 15:44:02 +08:00
|
|
|
dataset = H5Dopen2(error_file_g, DATASETNAME, H5P_DEFAULT);
|
|
|
|
CHECK(dataset, H5I_INVALID_HID, "H5Dopen2");
|
2005-08-20 04:01:41 +08:00
|
|
|
|
2018-05-14 15:44:02 +08:00
|
|
|
status = H5Dread(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &value);
|
|
|
|
CHECK(status, FAIL, "H5Dread");
|
2003-08-09 03:06:29 +08:00
|
|
|
|
2004-01-10 09:41:13 +08:00
|
|
|
if (value != WRITE_NUMBER)
|
|
|
|
TestErrPrintf("Error: Successful thread wrote value %d instead of %d\n", value, WRITE_NUMBER);
|
2003-08-09 03:06:29 +08:00
|
|
|
|
2018-05-14 15:44:02 +08:00
|
|
|
status = H5Dclose(dataset);
|
|
|
|
CHECK(status, FAIL, "H5Dclose");
|
|
|
|
status = H5Fclose(error_file_g);
|
|
|
|
CHECK(status, FAIL, "H5Fclose");
|
2003-08-09 03:06:29 +08:00
|
|
|
|
2010-09-11 00:15:34 +08:00
|
|
|
H5TS_attr_destroy(&attribute);
|
2018-05-14 15:44:02 +08:00
|
|
|
} /* end tts_error() */
|
2000-05-19 03:13:33 +08:00
|
|
|
|
2018-05-14 15:44:02 +08:00
|
|
|
static void *
|
|
|
|
tts_error_thread(void H5_ATTR_UNUSED *arg)
|
2000-05-20 07:00:03 +08:00
|
|
|
{
|
2018-05-14 15:44:02 +08:00
|
|
|
hid_t dataspace = H5I_INVALID_HID;
|
|
|
|
hid_t datatype = H5I_INVALID_HID;
|
|
|
|
hid_t dataset = H5I_INVALID_HID;
|
2003-08-09 03:06:29 +08:00
|
|
|
hsize_t dimsf[1]; /* dataset dimensions */
|
2010-09-28 03:02:48 +08:00
|
|
|
H5E_auto2_t old_error_cb;
|
2003-08-09 03:06:29 +08:00
|
|
|
void *old_error_client_data;
|
|
|
|
int value;
|
2018-05-14 15:44:02 +08:00
|
|
|
herr_t status;
|
2003-08-09 03:06:29 +08:00
|
|
|
|
|
|
|
/* preserve previous error stack handler */
|
2018-05-14 15:44:02 +08:00
|
|
|
status = H5Eget_auto2(H5E_DEFAULT, &old_error_cb, &old_error_client_data);
|
|
|
|
CHECK(status, FAIL, "H5Eget_auto2");
|
2003-08-09 03:06:29 +08:00
|
|
|
|
|
|
|
/* set each thread's error stack handler */
|
2018-05-14 15:44:02 +08:00
|
|
|
status = H5Eset_auto2(H5E_DEFAULT, error_callback, NULL);
|
|
|
|
CHECK(status, FAIL, "H5Eset_auto2");
|
2003-08-09 03:06:29 +08:00
|
|
|
|
|
|
|
/* define dataspace for dataset */
|
|
|
|
dimsf[0] = 1;
|
[svn-r14199] Description:
Add H5Dcreate to API versioned routines, replacing internal usage with
H5Dcreate2
Fix thread-safe error stack initialization for API versioned error
stack printing routines.
Tested on:
FreeBSD/32 6.2 (duty) in debug mode
FreeBSD/64 6.2 (liberty) w/C++ & FORTRAN, in debug mode
Linux/32 2.6 (kagiso) w/PGI compilers, w/C++ & FORTRAN, w/threadsafe,
in debug mode
Linux/64-amd64 2.6 (smirom) w/default API=1.6.x, w/C++ & FORTRAN,
in production mode
Linux/64-ia64 2.6 (cobalt) w/Intel compilers, w/C++ & FORTRAN,
in production mode
Solaris/32 2.10 (linew) w/deprecated symbols disabled, w/C++ & FORTRAN,
w/szip filter, in production mode
Mac OS X/32 10.4.10 (amazon) in debug mode
2007-10-12 00:24:11 +08:00
|
|
|
dataspace = H5Screate_simple(1, dimsf, NULL);
|
2018-05-14 15:44:02 +08:00
|
|
|
CHECK(dataspace, H5I_INVALID_HID, "H5Screate_simple");
|
2003-08-09 03:06:29 +08:00
|
|
|
|
|
|
|
/* define datatype for the data using native little endian integers */
|
|
|
|
datatype = H5Tcopy(H5T_NATIVE_INT);
|
2018-05-14 15:44:02 +08:00
|
|
|
CHECK(datatype, H5I_INVALID_HID, "H5Tcopy");
|
|
|
|
status = H5Tset_order(datatype, H5T_ORDER_LE);
|
|
|
|
CHECK(status, FAIL, "H5Tset_order");
|
2004-12-29 22:26:20 +08:00
|
|
|
|
2003-08-09 03:06:29 +08:00
|
|
|
/* create a new dataset within the file */
|
2018-05-14 15:44:02 +08:00
|
|
|
dataset = H5Dcreate2(error_file_g, DATASETNAME, datatype, dataspace, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
|
|
|
|
/* Most of these will fail, so don't check the error here */
|
|
|
|
if (dataset >= 0) {
|
2003-08-09 03:06:29 +08:00
|
|
|
value = WRITE_NUMBER;
|
2018-05-14 15:44:02 +08:00
|
|
|
status = H5Dwrite(dataset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, &value);
|
|
|
|
CHECK(status, FAIL, "H5Dwrite");
|
|
|
|
status = H5Dclose(dataset);
|
|
|
|
CHECK(status, FAIL, "H5Dclose");
|
|
|
|
}
|
2003-08-09 03:06:29 +08:00
|
|
|
|
2018-05-14 15:44:02 +08:00
|
|
|
status = H5Tclose(datatype);
|
|
|
|
CHECK(status, FAIL, "H5Tclose");
|
|
|
|
status = H5Sclose(dataspace);
|
|
|
|
CHECK(status, FAIL, "H5Sclose");
|
2003-08-09 03:06:29 +08:00
|
|
|
|
|
|
|
/* turn our error stack handler off */
|
2018-05-14 15:44:02 +08:00
|
|
|
status = H5Eset_auto2(H5E_DEFAULT, old_error_cb, old_error_client_data);
|
|
|
|
CHECK(status, FAIL, "H5Eset_auto2");
|
2003-08-09 03:06:29 +08:00
|
|
|
|
|
|
|
return NULL;
|
2018-05-14 15:44:02 +08:00
|
|
|
} /* end tts_error_thread() */
|
2000-05-19 03:13:33 +08:00
|
|
|
|
2018-05-14 15:44:02 +08:00
|
|
|
static herr_t
|
|
|
|
error_callback(hid_t H5_ATTR_UNUSED estack_id, void *client_data)
|
2003-09-30 00:24:56 +08:00
|
|
|
{
|
2018-05-14 15:44:02 +08:00
|
|
|
H5TS_mutex_lock_simple(&error_mutex_g);
|
|
|
|
error_count_g++;
|
|
|
|
H5TS_mutex_unlock_simple(&error_mutex_g);
|
2007-04-13 05:41:23 +08:00
|
|
|
return H5Ewalk2(H5E_DEFAULT, H5E_WALK_DOWNWARD, walk_error_callback, client_data);
|
2003-09-30 00:24:56 +08:00
|
|
|
}
|
|
|
|
|
2018-05-14 15:44:02 +08:00
|
|
|
static herr_t
|
|
|
|
walk_error_callback(unsigned n, const H5E_error2_t *err_desc, void H5_ATTR_UNUSED *client_data)
|
2000-05-20 07:00:03 +08:00
|
|
|
{
|
2018-05-14 15:44:02 +08:00
|
|
|
hid_t maj_num = H5I_INVALID_HID;
|
|
|
|
hid_t min_num = H5I_INVALID_HID;
|
2003-08-09 03:06:29 +08:00
|
|
|
|
|
|
|
if (err_desc) {
|
2003-09-30 00:24:56 +08:00
|
|
|
maj_num = err_desc->maj_num;
|
|
|
|
min_num = err_desc->min_num;
|
2005-08-14 04:53:35 +08:00
|
|
|
|
2018-05-14 15:44:02 +08:00
|
|
|
if (n <= EXPECTED_ERROR_DEPTH && maj_num == expected_g[n].maj_num && min_num == expected_g[n].min_num)
|
2003-08-09 03:06:29 +08:00
|
|
|
return SUCCEED;
|
|
|
|
}
|
|
|
|
|
2018-05-14 15:44:02 +08:00
|
|
|
error_flag_g = -1;
|
2003-08-09 03:06:29 +08:00
|
|
|
return SUCCEED;
|
2000-05-20 07:00:03 +08:00
|
|
|
}
|
|
|
|
|
2018-05-14 15:44:02 +08:00
|
|
|
void
|
|
|
|
cleanup_error(void)
|
2000-05-20 07:00:03 +08:00
|
|
|
{
|
2003-08-09 03:06:29 +08:00
|
|
|
HDunlink(FILENAME);
|
2000-05-19 03:13:33 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /*H5_HAVE_THREADSAFE*/
|
2015-08-27 01:05:57 +08:00
|
|
|
|