summaryrefslogtreecommitdiffstats
path: root/test/swmr_common.c
diff options
context:
space:
mode:
authorAlbert Cheng <acheng@hdfgroup.org>2009-07-22 20:17:42 (GMT)
committerAlbert Cheng <acheng@hdfgroup.org>2009-07-22 20:17:42 (GMT)
commitbe4c660148eab2cebbadee134d6afda8df64e092 (patch)
tree54f71b26c53abac7b78ada28b8b2908013d354ee /test/swmr_common.c
parent0c8e622e1acfe4dbf0d8dd25a514a231c08d388d (diff)
downloadhdf5-be4c660148eab2cebbadee134d6afda8df64e092.zip
hdf5-be4c660148eab2cebbadee134d6afda8df64e092.tar.gz
hdf5-be4c660148eab2cebbadee134d6afda8df64e092.tar.bz2
[svn-r17224] Installed SWMR testings.
Tested: amani.
Diffstat (limited to 'test/swmr_common.c')
-rw-r--r--test/swmr_common.c93
1 files changed, 93 insertions, 0 deletions
diff --git a/test/swmr_common.c b/test/swmr_common.c
new file mode 100644
index 0000000..bb75c0d
--- /dev/null
+++ b/test/swmr_common.c
@@ -0,0 +1,93 @@
+#include "swmr_common.h"
+
+static unsigned symbol_mapping[NMAPPING] = {0, 0, 0, 0, 1, 1, 2, 3, 4};
+unsigned symbol_count[NLEVELS] = {100, 200, 400, 800, 1600};
+
+symbol_info_t *symbol_info[NLEVELS];
+
+symbol_info_t *
+choose_dataset(void)
+{
+ unsigned level; /* The level of the dataset */
+ unsigned offset; /* The "offset" of the dataset at that level */
+
+ /* Determine level of dataset */
+ level = symbol_mapping[random() % NMAPPING];
+
+ /* Determine the offset of the level */
+ offset = random() % symbol_count[level];
+
+ return(&symbol_info[level][offset]);
+} /* end choose_dataset() */
+
+hid_t
+create_symbol_datatype(void)
+{
+ hid_t sym_type_id; /* Datatype ID for symbol */
+ hid_t opaq_type_id; /* Datatype ID for opaque part of record */
+
+ /* Create opaque datatype to represent other information for this record */
+ if((opaq_type_id = H5Tcreate(H5T_OPAQUE, DTYPE_SIZE)) < 0)
+ return(-1);
+
+ /* Create compound datatype for symbol */
+ if((sym_type_id = H5Tcreate(H5T_COMPOUND, sizeof(symbol_t))) < 0)
+ return(-1);
+
+ /* Insert fields in symbol datatype */
+ if(H5Tinsert(sym_type_id, "rec_id", HOFFSET(symbol_t, rec_id), H5T_NATIVE_UINT64) < 0)
+ return(-1);
+ if(H5Tinsert(sym_type_id, "info", HOFFSET(symbol_t, info), opaq_type_id) < 0)
+ return(-1);
+
+ /* Close opaque datatype */
+ if(H5Tclose(opaq_type_id) < 0)
+ return(-1);
+
+ return(sym_type_id);
+} /* end create_symbol_datatype() */
+
+int
+generate_name(char *name_buf, unsigned level, unsigned count)
+{
+ sprintf(name_buf, "%u-%04u", level, count);
+
+ return(0);
+} /* end generate_name() */
+
+int
+generate_symbols(void)
+{
+ unsigned u, v; /* Local index variables */
+
+ for(u = 0; u < NLEVELS; u++) {
+ symbol_info[u] = malloc(symbol_count[u] * sizeof(symbol_info_t));
+ for(v = 0; v < symbol_count[u]; v++) {
+ char name_buf[64];
+
+ generate_name(name_buf, u, v);
+ symbol_info[u][v].name = malloc(strlen(name_buf) + 1);
+ strcpy(symbol_info[u][v].name, name_buf);
+ symbol_info[u][v].dsid = -1;
+ symbol_info[u][v].nrecords = 0;
+ } /* end for */
+ } /* end for */
+
+ return(0);
+} /* end generate_symbols() */
+
+int
+shutdown_symbols(void)
+{
+ unsigned u, v; /* Local index variables */
+
+ /* Clean up the symbols */
+ for(u = 0; u < NLEVELS; u++) {
+ for(v = 0; v < symbol_count[u]; v++)
+ free(symbol_info[u][v].name);
+ free(symbol_info[u]);
+ } /* end for */
+
+ return(0);
+} /* end shutdown_symbols() */
+