summaryrefslogtreecommitdiffstats
path: root/test/API/H5_api_test_util.c
diff options
context:
space:
mode:
Diffstat (limited to 'test/API/H5_api_test_util.c')
-rw-r--r--test/API/H5_api_test_util.c876
1 files changed, 426 insertions, 450 deletions
diff --git a/test/API/H5_api_test_util.c b/test/API/H5_api_test_util.c
index 7fec2b6..c37a9ed 100644
--- a/test/API/H5_api_test_util.c
+++ b/test/API/H5_api_test_util.c
@@ -34,11 +34,18 @@
#define COMPACT_DATATYPE_MAX_SIZE 1024
/* The maximum level of recursion that the generate_random_datatype()
- * function should go down to, before being forced to choose a base type
- * in order to not cause a stack overflow.
+ * function should go down to, before being forced to choose a base type.
*/
#define TYPE_GEN_RECURSION_MAX_DEPTH 3
+/* The number of predefined standard integer types in HDF5
+ */
+#define NUM_PREDEFINED_INT_TYPES 16
+
+/* The number of predefined floating point types in HDF5
+ */
+#define NUM_PREDEFINED_FLOAT_TYPES 4
+
/* The maximum number of members allowed in an HDF5 compound type, as
* generated by the generate_random_datatype() function, for ease of
* development.
@@ -69,553 +76,522 @@
#define COMPACT_SPACE_MAX_DIM_SIZE 4
#define COMPACT_SPACE_MAX_DIMS 3
+typedef hid_t (*generate_datatype_func)(H5T_class_t parent_class, hbool_t is_compact);
+
+static hid_t generate_random_datatype_integer(H5T_class_t parent_class, hbool_t is_compact);
+static hid_t generate_random_datatype_float(H5T_class_t parent_class, hbool_t is_compact);
+static hid_t generate_random_datatype_string(H5T_class_t parent_class, hbool_t is_compact);
+static hid_t generate_random_datatype_compound(H5T_class_t parent_class, hbool_t is_compact);
+static hid_t generate_random_datatype_reference(H5T_class_t parent_class, hbool_t is_compact);
+static hid_t generate_random_datatype_enum(H5T_class_t parent_class, hbool_t is_compact);
+static hid_t generate_random_datatype_array(H5T_class_t parent_class, hbool_t is_compact);
+
/*
* Helper function to generate a random HDF5 datatype in order to thoroughly
* test support for datatypes. The parent_class parameter is to support
* recursive generation of datatypes. In most cases, this function should be
* called with H5T_NO_CLASS for the parent_class parameter.
*/
-/*
- * XXX: limit size of datatype generated
- */
hid_t
generate_random_datatype(H5T_class_t parent_class, hbool_t is_compact)
{
- static int depth = 0;
- hsize_t *array_dims = NULL;
- size_t i;
- hid_t compound_members[COMPOUND_TYPE_MAX_MEMBERS];
- hid_t datatype = H5I_INVALID_HID;
+ generate_datatype_func gen_func;
+ static int depth = 0;
+ size_t type_size;
+ hid_t datatype = H5I_INVALID_HID;
+ hid_t ret_value = H5I_INVALID_HID;
depth++;
- for (i = 0; i < COMPOUND_TYPE_MAX_MEMBERS; i++)
- compound_members[i] = H5I_INVALID_HID;
-
+roll_datatype:
switch (rand() % H5T_NCLASSES) {
-case_integer:
- case H5T_INTEGER: {
- switch (rand() % 16) {
- case 0:
- if ((datatype = H5Tcopy(H5T_STD_I8BE)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't copy predefined integer type\n");
- goto done;
- }
-
- break;
-
- case 1:
- if ((datatype = H5Tcopy(H5T_STD_I8LE)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't copy predefined integer type\n");
- goto done;
- }
-
- break;
-
- case 2:
- if ((datatype = H5Tcopy(H5T_STD_I16BE)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't copy predefined integer type\n");
- goto done;
- }
-
- break;
-
- case 3:
- if ((datatype = H5Tcopy(H5T_STD_I16LE)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't copy predefined integer type\n");
- goto done;
- }
-
- break;
-
- case 4:
- if ((datatype = H5Tcopy(H5T_STD_I32BE)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't copy predefined integer type\n");
- goto done;
- }
-
- break;
-
- case 5:
- if ((datatype = H5Tcopy(H5T_STD_I32LE)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't copy predefined integer type\n");
- goto done;
- }
-
- break;
-
- case 6:
- if ((datatype = H5Tcopy(H5T_STD_I64BE)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't copy predefined integer type\n");
- goto done;
- }
-
- break;
-
- case 7:
- if ((datatype = H5Tcopy(H5T_STD_I64LE)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't copy predefined integer type\n");
- goto done;
- }
-
- break;
-
- case 8:
- if ((datatype = H5Tcopy(H5T_STD_U8BE)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't copy predefined integer type\n");
- goto done;
- }
-
- break;
-
- case 9:
- if ((datatype = H5Tcopy(H5T_STD_U8LE)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't copy predefined integer type\n");
- goto done;
- }
-
- break;
-
- case 10:
- if ((datatype = H5Tcopy(H5T_STD_U16BE)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't copy predefined integer type\n");
- goto done;
- }
-
- break;
-
- case 11:
- if ((datatype = H5Tcopy(H5T_STD_U16LE)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't copy predefined integer type\n");
- goto done;
- }
-
- break;
-
- case 12:
- if ((datatype = H5Tcopy(H5T_STD_U32BE)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't copy predefined integer type\n");
- goto done;
- }
-
- break;
-
- case 13:
- if ((datatype = H5Tcopy(H5T_STD_U32LE)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't copy predefined integer type\n");
- goto done;
- }
-
- break;
-
- case 14:
- if ((datatype = H5Tcopy(H5T_STD_U64BE)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't copy predefined integer type\n");
- goto done;
- }
-
- break;
-
- case 15:
- if ((datatype = H5Tcopy(H5T_STD_U64LE)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't copy predefined integer type\n");
- goto done;
- }
-
- break;
-
- default:
- H5_FAILED();
- HDprintf(" invalid value for predefined integer type; should not happen\n");
- goto done;
- }
+ case H5T_INTEGER:
+ gen_func = generate_random_datatype_integer;
+ break;
+ case H5T_FLOAT:
+ gen_func = generate_random_datatype_float;
+ break;
+ case H5T_TIME:
+ /* Time datatype is unsupported, try again */
+ goto roll_datatype;
+ break;
+ case H5T_STRING:
+ gen_func = generate_random_datatype_string;
+ break;
+ case H5T_BITFIELD:
+ /* Bitfield datatype is unsupported, try again */
+ goto roll_datatype;
+ break;
+ case H5T_OPAQUE:
+ /* Opaque datatype is unsupported, try again */
+ goto roll_datatype;
+ break;
+ case H5T_COMPOUND:
+ /* Currently only allows arrays of integer, float or string. Pick another type if we
+ * are creating an array of something other than these. Also don't allow recursion
+ * to go too deep. Pick another type that doesn't recursively call this function. */
+ if ((H5T_ARRAY == parent_class) || ((depth + 1) > TYPE_GEN_RECURSION_MAX_DEPTH))
+ goto roll_datatype;
- break;
- }
+ gen_func = generate_random_datatype_compound;
+ break;
+ case H5T_REFERENCE:
+ /* Temporarily disable generation of reference datatypes */
+ goto roll_datatype;
-case_float:
- case H5T_FLOAT: {
- switch (rand() % 4) {
- case 0:
- if ((datatype = H5Tcopy(H5T_IEEE_F32BE)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't copy predefined floating-point type\n");
- goto done;
- }
+ /* Currently only allows arrays of integer, float or string. Pick another type if we
+ * are creating an array of something other than these. */
+ if (H5T_ARRAY == parent_class)
+ goto roll_datatype;
- break;
+ gen_func = generate_random_datatype_reference;
+ break;
+ case H5T_ENUM:
+ /* Currently doesn't currently support ARRAY of ENUM, so try another type
+ * if this happens. */
+ if (H5T_ARRAY == parent_class)
+ goto roll_datatype;
- case 1:
- if ((datatype = H5Tcopy(H5T_IEEE_F32LE)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't copy predefined floating-point type\n");
- goto done;
- }
+ gen_func = generate_random_datatype_enum;
+ break;
+ case H5T_VLEN:
+ /* Variable-length datatypes are unsupported, try again */
+ goto roll_datatype;
+ break;
+ case H5T_ARRAY:
+ /* Currently doesn't currently support ARRAY of ARRAY, so try another type
+ * if this happens. Also check for too much recursion. */
+ if ((H5T_ARRAY == parent_class) || ((depth + 1) > TYPE_GEN_RECURSION_MAX_DEPTH))
+ goto roll_datatype;
- break;
+ gen_func = generate_random_datatype_array;
+ break;
+ default:
+ HDprintf(" invalid datatype class\n");
+ goto done;
+ break;
+ }
- case 2:
- if ((datatype = H5Tcopy(H5T_IEEE_F64BE)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't copy predefined floating-point type\n");
- goto done;
- }
+ if ((datatype = (gen_func)(parent_class, is_compact)) < 0) {
+ HDprintf(" couldn't generate datatype\n");
+ goto done;
+ }
- break;
+ /*
+ * Check to make sure that the generated datatype does
+ * not exceed the maximum datatype size and doesn't exceed
+ * the maximum compact datatype size if a compact datatype
+ * was requested.
+ */
+ if (depth == 1) {
+ if (0 == (type_size = H5Tget_size(datatype))) {
+ HDprintf(" failed to retrieve datatype's size\n");
+ H5Tclose(datatype);
+ datatype = H5I_INVALID_HID;
+ goto done;
+ }
- case 3:
- if ((datatype = H5Tcopy(H5T_IEEE_F64LE)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't copy predefined floating-point type\n");
- goto done;
- }
+ if ((type_size > GENERATED_DATATYPE_MAX_SIZE) ||
+ (is_compact && (type_size > COMPACT_DATATYPE_MAX_SIZE))) {
+ /*
+ * Generate a new datatype.
+ */
+ H5Tclose(datatype);
+ datatype = H5I_INVALID_HID;
+ goto roll_datatype;
+ }
+ }
- break;
+ ret_value = datatype;
- default:
- H5_FAILED();
- HDprintf(" invalid value for floating point type; should not happen\n");
- goto done;
- }
+done:
+ depth--;
- break;
+ return ret_value;
+}
+
+static hid_t
+generate_random_datatype_integer(H5T_class_t H5_ATTR_UNUSED parent_class, hbool_t H5_ATTR_UNUSED is_compact)
+{
+ hid_t type_to_copy = H5I_INVALID_HID;
+ hid_t datatype = H5I_INVALID_HID;
+ hid_t ret_value = H5I_INVALID_HID;
+
+ switch (rand() % NUM_PREDEFINED_INT_TYPES) {
+ case 0:
+ type_to_copy = H5T_STD_I8BE;
+ break;
+ case 1:
+ type_to_copy = H5T_STD_I8LE;
+ break;
+ case 2:
+ type_to_copy = H5T_STD_I16BE;
+ break;
+ case 3:
+ type_to_copy = H5T_STD_I16LE;
+ break;
+ case 4:
+ type_to_copy = H5T_STD_I32BE;
+ break;
+ case 5:
+ type_to_copy = H5T_STD_I32LE;
+ break;
+ case 6:
+ type_to_copy = H5T_STD_I64BE;
+ break;
+ case 7:
+ type_to_copy = H5T_STD_I64LE;
+ break;
+ case 8:
+ type_to_copy = H5T_STD_U8BE;
+ break;
+ case 9:
+ type_to_copy = H5T_STD_U8LE;
+ break;
+ case 10:
+ type_to_copy = H5T_STD_U16BE;
+ break;
+ case 11:
+ type_to_copy = H5T_STD_U16LE;
+ break;
+ case 12:
+ type_to_copy = H5T_STD_U32BE;
+ break;
+ case 13:
+ type_to_copy = H5T_STD_U32LE;
+ break;
+ case 14:
+ type_to_copy = H5T_STD_U64BE;
+ break;
+ case 15:
+ type_to_copy = H5T_STD_U64LE;
+ break;
+ default:
+ HDprintf(" invalid value for predefined integer type; should not happen\n");
+ goto done;
}
-case_time:
- case H5T_TIME: {
- /* Time datatype is unsupported, try again */
- goto reroll;
- break;
+ if ((datatype = H5Tcopy(type_to_copy)) < 0) {
+ HDprintf(" couldn't copy predefined integer type\n");
+ goto done;
}
-case_string:
- case H5T_STRING: {
- /* Note: currently only H5T_CSET_ASCII is supported for the character set and
- * only H5T_STR_NULLTERM is supported for string padding for variable-length
- * strings and only H5T_STR_NULLPAD is supported for string padding for
- * fixed-length strings, but these may change in the future.
- */
- if (0 == (rand() % 2)) {
- if ((datatype = H5Tcreate(H5T_STRING, (size_t)(rand() % STRING_TYPE_MAX_SIZE) + 1)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't create fixed-length string datatype\n");
- goto done;
- }
+ ret_value = datatype;
- if (H5Tset_strpad(datatype, H5T_STR_NULLPAD) < 0) {
- H5_FAILED();
- HDprintf(" couldn't set H5T_STR_NULLPAD for fixed-length string type\n");
- goto done;
- }
- }
- else {
- /*
- * Currently, all VL datatypes are disabled.
- */
- goto reroll;
-
-#if 0
- if ((datatype = H5Tcreate(H5T_STRING, H5T_VARIABLE)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't create variable-length string datatype\n");
- goto done;
- }
-
- if (H5Tset_strpad(datatype, H5T_STR_NULLTERM) < 0) {
- H5_FAILED();
- HDprintf(" couldn't set H5T_STR_NULLTERM for variable-length string type\n");
- goto done;
- }
-#endif
- }
+done:
+ if ((ret_value == H5I_INVALID_HID) && (datatype >= 0)) {
+ if (H5Tclose(datatype) < 0)
+ HDprintf(" couldn't close datatype\n");
+ }
- if (H5Tset_cset(datatype, H5T_CSET_ASCII) < 0) {
- H5_FAILED();
- HDprintf(" couldn't set string datatype character set\n");
- goto done;
- }
+ return ret_value;
+}
- break;
- }
+static hid_t
+generate_random_datatype_float(H5T_class_t H5_ATTR_UNUSED parent_class, hbool_t H5_ATTR_UNUSED is_compact)
+{
+ hid_t type_to_copy = H5I_INVALID_HID;
+ hid_t datatype = H5I_INVALID_HID;
+ hid_t ret_value = H5I_INVALID_HID;
+
+ switch (rand() % NUM_PREDEFINED_FLOAT_TYPES) {
+ case 0:
+ type_to_copy = H5T_IEEE_F32BE;
+ break;
+ case 1:
+ type_to_copy = H5T_IEEE_F32LE;
+ break;
+ case 2:
+ type_to_copy = H5T_IEEE_F64BE;
+ break;
+ case 3:
+ type_to_copy = H5T_IEEE_F64LE;
+ break;
-case_bitfield:
- case H5T_BITFIELD: {
- /* Bitfield datatype is unsupported, try again */
- goto reroll;
- break;
+ default:
+ HDprintf(" invalid value for floating point type; should not happen\n");
+ goto done;
}
-case_opaque:
- case H5T_OPAQUE: {
- /* Opaque datatype is unsupported, try again */
- goto reroll;
- break;
+ if ((datatype = H5Tcopy(type_to_copy)) < 0) {
+ HDprintf(" couldn't copy predefined floating-point type\n");
+ goto done;
}
-case_compound:
- case H5T_COMPOUND: {
- size_t num_members;
- size_t next_offset = 0;
- size_t compound_size = 0;
+ ret_value = datatype;
- /* Currently only allows arrays of integer, float or string. Pick another type if we
- * are creating an array of something other than these. Also don't allow recursion
- * to go too deep. Pick another type that doesn't recursively call this function. */
- if (H5T_ARRAY == parent_class || depth > TYPE_GEN_RECURSION_MAX_DEPTH)
- goto reroll;
+done:
+ if ((ret_value == H5I_INVALID_HID) && (datatype >= 0)) {
+ if (H5Tclose(datatype) < 0)
+ HDprintf(" couldn't close datatype\n");
+ }
- if ((datatype = H5Tcreate(H5T_COMPOUND, 1)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't create compound datatype\n");
- goto done;
- }
+ return ret_value;
+}
- num_members = (size_t)(rand() % COMPOUND_TYPE_MAX_MEMBERS + 1);
+static hid_t
+generate_random_datatype_string(H5T_class_t H5_ATTR_UNUSED parent_class, hbool_t H5_ATTR_UNUSED is_compact)
+{
+ hid_t datatype = H5I_INVALID_HID;
+ hid_t ret_value = H5I_INVALID_HID;
- for (i = 0; i < num_members; i++) {
- size_t member_size;
- char member_name[256];
+ /* Note: currently only H5T_CSET_ASCII is supported for the character set and
+ * only H5T_STR_NULLTERM is supported for string padding for variable-length
+ * strings and only H5T_STR_NULLPAD is supported for string padding for
+ * fixed-length strings, but these may change in the future.
+ */
+#if 0 /* Currently, all VL types are disabled */
+ if (0 == (rand() % 2)) {
+#endif
+ if ((datatype = H5Tcreate(H5T_STRING, (size_t)(rand() % STRING_TYPE_MAX_SIZE) + 1)) < 0) {
+ HDprintf(" couldn't create fixed-length string datatype\n");
+ goto done;
+ }
- HDsnprintf(member_name, 256, "compound_member%zu", i);
+ if (H5Tset_strpad(datatype, H5T_STR_NULLPAD) < 0) {
+ HDprintf(" couldn't set H5T_STR_NULLPAD for fixed-length string type\n");
+ goto done;
+ }
+#if 0 /* Currently, all VL types are disabled */
+ }
+ else {
- if ((compound_members[i] = generate_random_datatype(H5T_NO_CLASS, is_compact)) < 0) {
+ if ((datatype = H5Tcreate(H5T_STRING, H5T_VARIABLE)) < 0) {
H5_FAILED();
- HDprintf(" couldn't create compound datatype member %zu\n", i);
+ HDprintf(" couldn't create variable-length string datatype\n");
goto done;
}
- if (!(member_size = H5Tget_size(compound_members[i]))) {
+ if (H5Tset_strpad(datatype, H5T_STR_NULLTERM) < 0) {
H5_FAILED();
- HDprintf(" couldn't get compound member %zu size\n", i);
+ HDprintf(" couldn't set H5T_STR_NULLTERM for variable-length string type\n");
goto done;
}
+ }
+#endif
- compound_size += member_size;
+ if (H5Tset_cset(datatype, H5T_CSET_ASCII) < 0) {
+ HDprintf(" couldn't set string datatype character set\n");
+ goto done;
+ }
- if (H5Tset_size(datatype, compound_size) < 0) {
- H5_FAILED();
- HDprintf(" couldn't set size for compound datatype\n");
- goto done;
- }
+ ret_value = datatype;
- if (H5Tinsert(datatype, member_name, next_offset, compound_members[i]) < 0) {
- H5_FAILED();
- HDprintf(" couldn't insert compound datatype member %zu\n", i);
- goto done;
- }
+done:
+ if ((ret_value == H5I_INVALID_HID) && (datatype >= 0)) {
+ if (H5Tclose(datatype) < 0)
+ HDprintf(" couldn't close datatype\n");
+ }
- next_offset += member_size;
- }
+ return ret_value;
+}
- break;
+static hid_t
+generate_random_datatype_compound(H5T_class_t H5_ATTR_UNUSED parent_class, hbool_t is_compact)
+{
+ size_t num_members = 0;
+ size_t next_offset = 0;
+ size_t compound_size = 0;
+ hid_t compound_members[COMPOUND_TYPE_MAX_MEMBERS];
+ hid_t datatype = H5I_INVALID_HID;
+ hid_t ret_value = H5I_INVALID_HID;
+
+ for (size_t i = 0; i < COMPOUND_TYPE_MAX_MEMBERS; i++)
+ compound_members[i] = H5I_INVALID_HID;
+
+ if ((datatype = H5Tcreate(H5T_COMPOUND, 1)) < 0) {
+ HDprintf(" couldn't create compound datatype\n");
+ goto done;
}
-case_reference:
- case H5T_REFERENCE: {
- /* Temporarily disable generation of reference datatypes */
- goto reroll;
+ num_members = (size_t)(rand() % COMPOUND_TYPE_MAX_MEMBERS + 1);
- /* Currently only allows arrays of integer, float or string. Pick another type if we
- * are creating an array of something other than these. */
- if (H5T_ARRAY == parent_class)
- goto reroll;
+ for (size_t i = 0; i < num_members; i++) {
+ size_t member_size;
+ char member_name[256];
- if (0 == (rand() % 2)) {
- if ((datatype = H5Tcopy(H5T_STD_REF_OBJ)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't copy object reference datatype\n");
- goto done;
- }
+ HDsnprintf(member_name, 256, "compound_member%zu", i);
+
+ if ((compound_members[i] = generate_random_datatype(H5T_COMPOUND, is_compact)) < 0) {
+ HDprintf(" couldn't create compound datatype member %zu\n", i);
+ goto done;
}
- else {
- /* Region references are currently unsupported */
- goto reroll;
- if ((datatype = H5Tcopy(H5T_STD_REF_DSETREG)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't copy region reference datatype\n");
- goto done;
- }
+ if (!(member_size = H5Tget_size(compound_members[i]))) {
+ HDprintf(" couldn't get compound member %zu size\n", i);
+ goto done;
}
- break;
- }
+ compound_size += member_size;
-case_enum:
- case H5T_ENUM: {
- /* Currently doesn't currently support ARRAY of ENUM, so try another type
- * if this happens. */
- if (H5T_ARRAY == parent_class)
- goto reroll;
+ if (H5Tset_size(datatype, compound_size) < 0) {
+ HDprintf(" couldn't set size for compound datatype\n");
+ goto done;
+ }
- if ((datatype = H5Tenum_create(H5T_NATIVE_INT)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't create enum datatype\n");
+ if (H5Tinsert(datatype, member_name, next_offset, compound_members[i]) < 0) {
+ HDprintf(" couldn't insert compound datatype member %zu\n", i);
goto done;
}
- for (i = 0; i < (size_t)(rand() % ENUM_TYPE_MAX_MEMBERS + 1); i++) {
- char name[ENUM_TYPE_MAX_MEMBER_NAME_LENGTH];
- int value = rand();
+ next_offset += member_size;
+ }
- HDsnprintf(name, ENUM_TYPE_MAX_MEMBER_NAME_LENGTH, "enum_val%zu", i);
+ ret_value = datatype;
- if (H5Tenum_insert(datatype, name, &value) < 0) {
- H5_FAILED();
- HDprintf(" couldn't insert member into enum datatype\n");
- goto done;
- }
+done:
+ for (size_t i = 0; i < COMPOUND_TYPE_MAX_MEMBERS; i++) {
+ if (compound_members[i] > 0 && H5Tclose(compound_members[i]) < 0) {
+ HDprintf(" couldn't close compound member %zu\n", i);
}
+ }
- break;
+ if ((ret_value == H5I_INVALID_HID) && (datatype >= 0)) {
+ if (H5Tclose(datatype) < 0)
+ HDprintf(" couldn't close datatype\n");
}
-case_vlen:
- case H5T_VLEN: {
- /* Variable-length datatypes are unsupported, try again */
- goto reroll;
- break;
+ return ret_value;
+}
+
+static hid_t
+generate_random_datatype_reference(H5T_class_t H5_ATTR_UNUSED parent_class, hbool_t H5_ATTR_UNUSED is_compact)
+{
+ hid_t datatype = H5I_INVALID_HID;
+ hid_t ret_value = H5I_INVALID_HID;
+
+#if 0 /* Region references are currently unsupported */
+ if (0 == (rand() % 2)) {
+#endif
+ if ((datatype = H5Tcopy(H5T_STD_REF_OBJ)) < 0) {
+ HDprintf(" couldn't copy object reference datatype\n");
+ goto done;
}
+#if 0 /* Region references are currently unsupported */
+ }
+ else {
+ if ((datatype = H5Tcopy(H5T_STD_REF_DSETREG)) < 0) {
+ H5_FAILED();
+ HDprintf(" couldn't copy region reference datatype\n");
+ goto done;
+ }
+ }
+#endif
-case_array:
- case H5T_ARRAY: {
- unsigned ndims;
- hid_t base_datatype = H5I_INVALID_HID;
+ ret_value = datatype;
- /* Currently doesn't currently support ARRAY of ARRAY, so try another type
- * if this happens. Also check for too much recursion. */
- if (H5T_ARRAY == parent_class || depth > TYPE_GEN_RECURSION_MAX_DEPTH)
- goto reroll;
+done:
+ if ((ret_value == H5I_INVALID_HID) && (datatype >= 0)) {
+ if (H5Tclose(datatype) < 0)
+ HDprintf(" couldn't close datatype\n");
+ }
- ndims = (unsigned)(rand() % ARRAY_TYPE_MAX_DIMS + 1);
+ return ret_value;
+}
- if (NULL == (array_dims = (hsize_t *)HDmalloc(ndims * sizeof(*array_dims))))
- goto done;
+static hid_t
+generate_random_datatype_enum(H5T_class_t H5_ATTR_UNUSED parent_class, hbool_t H5_ATTR_UNUSED is_compact)
+{
+ size_t num_members = 0;
+ hid_t datatype = H5I_INVALID_HID;
+ int *enum_member_vals = NULL;
+ hid_t ret_value = H5I_INVALID_HID;
- for (i = 0; i < ndims; i++)
- array_dims[i] = (hsize_t)(rand() % MAX_DIM_SIZE + 1);
+ if ((datatype = H5Tenum_create(H5T_NATIVE_INT)) < 0) {
+ HDprintf(" couldn't create enum datatype\n");
+ goto done;
+ }
- if ((base_datatype = generate_random_datatype(H5T_ARRAY, is_compact)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't create array base datatype\n");
- goto done;
- }
+ num_members = (size_t)(rand() % ENUM_TYPE_MAX_MEMBERS + 1);
- if ((datatype = H5Tarray_create2(base_datatype, ndims, array_dims)) < 0) {
- H5_FAILED();
- HDprintf(" couldn't create array datatype\n");
+ if (NULL == (enum_member_vals = HDmalloc(num_members * sizeof(int)))) {
+ HDprintf(" couldn't allocate space for enum members\n");
+ goto done;
+ }
+
+ for (size_t i = 0; i < num_members; i++) {
+ hbool_t unique;
+ char name[ENUM_TYPE_MAX_MEMBER_NAME_LENGTH];
+ int enum_val;
+
+ HDsnprintf(name, ENUM_TYPE_MAX_MEMBER_NAME_LENGTH, "enum_val%zu", i);
+
+ do {
+ enum_val = rand();
+
+ /* Check for uniqueness of enum member */
+ unique = TRUE;
+ for (size_t j = 0; j < i; j++)
+ if (enum_val == enum_member_vals[j])
+ unique = FALSE;
+ } while (!unique);
+
+ enum_member_vals[i] = enum_val;
+
+ if (H5Tenum_insert(datatype, name, &enum_val) < 0) {
+ HDprintf(" couldn't insert member into enum datatype\n");
goto done;
}
-
- break;
}
- default:
- H5_FAILED();
- HDprintf(" invalid datatype class\n");
- break;
- } /* end if */
+ ret_value = datatype;
done:
- if (depth > 0)
- depth--;
+ HDfree(enum_member_vals);
- if (datatype < 0) {
- for (i = 0; i < COMPOUND_TYPE_MAX_MEMBERS; i++) {
- if (compound_members[i] > 0 && H5Tclose(compound_members[i]) < 0) {
- H5_FAILED();
- HDprintf(" couldn't close compound member %zu\n", i);
- }
- }
+ if ((ret_value == H5I_INVALID_HID) && (datatype >= 0)) {
+ if (H5Tclose(datatype) < 0)
+ HDprintf(" couldn't close datatype\n");
}
- if (array_dims) {
- HDfree(array_dims);
- array_dims = NULL;
+ return ret_value;
+}
+
+static hid_t
+generate_random_datatype_array(H5T_class_t H5_ATTR_UNUSED parent_class, hbool_t is_compact)
+{
+ unsigned ndims = 0;
+ hsize_t *array_dims = NULL;
+ hid_t base_datatype = H5I_INVALID_HID;
+ hid_t datatype = H5I_INVALID_HID;
+ hid_t ret_value = H5I_INVALID_HID;
+
+ ndims = (unsigned)(rand() % ARRAY_TYPE_MAX_DIMS + 1);
+
+ if (NULL == (array_dims = HDmalloc(ndims * sizeof(*array_dims)))) {
+ HDprintf(" couldn't allocate space for array datatype dims\n");
+ goto done;
}
- if (is_compact && (depth == 0)) {
- size_t type_size;
+ for (size_t i = 0; i < ndims; i++)
+ array_dims[i] = (hsize_t)(rand() % MAX_DIM_SIZE + 1);
- /*
- * Check to make sure that the generated datatype does
- * not exceed the maximum compact datatype size if a
- * compact datatype was requested.
- */
- if (0 == (type_size = H5Tget_size(datatype))) {
- H5_FAILED();
- HDprintf(" failed to retrieve datatype's size\n");
- H5Tclose(datatype);
- datatype = H5I_INVALID_HID;
- }
- else {
- if (type_size > COMPACT_DATATYPE_MAX_SIZE) {
- /*
- * Generate a new datatype.
- */
- H5Tclose(datatype);
- datatype = H5I_INVALID_HID;
- goto reroll;
- }
- }
+ if ((base_datatype = generate_random_datatype(H5T_ARRAY, is_compact)) < 0) {
+ HDprintf(" couldn't create array base datatype\n");
+ goto done;
}
- return datatype;
+ if ((datatype = H5Tarray_create2(base_datatype, ndims, array_dims)) < 0) {
+ HDprintf(" couldn't create array datatype\n");
+ goto done;
+ }
-reroll:
- if (depth > 0)
- depth--;
+ ret_value = datatype;
- /*
- * The datatype generation resulted in a datatype that is currently invalid
- * for these tests, try again.
- */
- switch (rand() % H5T_NCLASSES) {
- case H5T_INTEGER:
- goto case_integer;
- case H5T_FLOAT:
- goto case_float;
- case H5T_TIME:
- goto case_time;
- case H5T_STRING:
- goto case_string;
- case H5T_BITFIELD:
- goto case_bitfield;
- case H5T_OPAQUE:
- goto case_opaque;
- case H5T_COMPOUND:
- goto case_compound;
- case H5T_REFERENCE:
- goto case_reference;
- case H5T_ENUM:
- goto case_enum;
- case H5T_VLEN:
- goto case_vlen;
- case H5T_ARRAY:
- goto case_array;
- default:
- H5_FAILED();
- HDprintf(" invalid value for goto\n");
- break;
+done:
+ HDfree(array_dims);
+
+ if (base_datatype >= 0) {
+ if (H5Tclose(base_datatype) < 0)
+ HDprintf(" couldn't close array base datatype\n");
}
- return H5I_INVALID_HID;
+ if ((ret_value == H5I_INVALID_HID) && (datatype >= 0)) {
+ if (H5Tclose(datatype) < 0)
+ HDprintf(" couldn't close datatype\n");
+ }
+
+ return ret_value;
}
/*