summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/.distdep96
-rw-r--r--test/chunk.c64
-rw-r--r--test/dtypes.c339
3 files changed, 403 insertions, 96 deletions
diff --git a/test/.distdep b/test/.distdep
index 020d41a..48594df 100644
--- a/test/.distdep
+++ b/test/.distdep
@@ -178,33 +178,6 @@ th5s.o: \
../src/H5Tpublic.h \
../src/H5Zprivate.h \
../src/H5Zpublic.h
-dtypes.o: \
- dtypes.c \
- ../src/hdf5.h \
- ../src/H5public.h \
- ../src/H5config.h \
- ../src/H5Ipublic.h \
- ../src/H5Apublic.h \
- ../src/H5ACpublic.h \
- ../src/H5Bpublic.h \
- ../src/H5Dpublic.h \
- ../src/H5Epublic.h \
- ../src/H5Fpublic.h \
- ../src/H5Gpublic.h \
- ../src/H5HGpublic.h \
- ../src/H5HLpublic.h \
- ../src/H5MFpublic.h \
- ../src/H5MMpublic.h \
- ../src/H5Opublic.h \
- ../src/H5Ppublic.h \
- ../src/H5Zpublic.h \
- ../src/H5Spublic.h \
- ../src/H5Tpublic.h \
- ../src/H5Tpkg.h \
- ../src/H5HGprivate.h \
- ../src/H5Fprivate.h \
- ../src/H5private.h \
- ../src/H5Tprivate.h
hyperslab.o: \
hyperslab.c \
../src/H5private.h \
@@ -410,8 +383,24 @@ links.o: \
../src/H5Zpublic.h \
../src/H5Spublic.h \
../src/H5Tpublic.h
-chunk.o: \
- chunk.c \
+bittests.o: \
+ bittests.c \
+ ../src/H5Tpkg.h \
+ ../src/H5HGprivate.h \
+ ../src/H5HGpublic.h \
+ ../src/H5public.h \
+ ../src/H5config.h \
+ ../src/H5Fprivate.h \
+ ../src/H5Fpublic.h \
+ ../src/H5Ipublic.h \
+ ../src/H5private.h \
+ ../src/H5Dpublic.h \
+ ../src/H5Tprivate.h \
+ ../src/H5Tpublic.h \
+ ../src/H5Gprivate.h \
+ ../src/H5Gpublic.h
+mtime.o: \
+ mtime.c \
../src/hdf5.h \
../src/H5public.h \
../src/H5config.h \
@@ -431,25 +420,33 @@ chunk.o: \
../src/H5Ppublic.h \
../src/H5Zpublic.h \
../src/H5Spublic.h \
- ../src/H5Tpublic.h
-bittests.o: \
- bittests.c \
- ../src/H5Tpkg.h \
- ../src/H5HGprivate.h \
- ../src/H5HGpublic.h \
+ ../src/H5Tpublic.h \
+ ../src/H5private.h
+big.o: \
+ big.c \
+ ../src/hdf5.h \
../src/H5public.h \
../src/H5config.h \
- ../src/H5Fprivate.h \
- ../src/H5Fpublic.h \
../src/H5Ipublic.h \
- ../src/H5private.h \
+ ../src/H5Apublic.h \
+ ../src/H5ACpublic.h \
+ ../src/H5Bpublic.h \
../src/H5Dpublic.h \
- ../src/H5Tprivate.h \
+ ../src/H5Epublic.h \
+ ../src/H5Fpublic.h \
+ ../src/H5Gpublic.h \
+ ../src/H5HGpublic.h \
+ ../src/H5HLpublic.h \
+ ../src/H5MFpublic.h \
+ ../src/H5MMpublic.h \
+ ../src/H5Opublic.h \
+ ../src/H5Ppublic.h \
+ ../src/H5Zpublic.h \
+ ../src/H5Spublic.h \
../src/H5Tpublic.h \
- ../src/H5Gprivate.h \
- ../src/H5Gpublic.h
-mtime.o: \
- mtime.c \
+ ../src/H5private.h
+dtypes.o: \
+ dtypes.c \
../src/hdf5.h \
../src/H5public.h \
../src/H5config.h \
@@ -470,9 +467,13 @@ mtime.o: \
../src/H5Zpublic.h \
../src/H5Spublic.h \
../src/H5Tpublic.h \
- ../src/H5private.h
-big.o: \
- big.c \
+ ../src/H5Tpkg.h \
+ ../src/H5HGprivate.h \
+ ../src/H5Fprivate.h \
+ ../src/H5private.h \
+ ../src/H5Tprivate.h
+chunk.o: \
+ chunk.c \
../src/hdf5.h \
../src/H5public.h \
../src/H5config.h \
@@ -492,5 +493,4 @@ big.o: \
../src/H5Ppublic.h \
../src/H5Zpublic.h \
../src/H5Spublic.h \
- ../src/H5Tpublic.h \
- ../src/H5private.h
+ ../src/H5Tpublic.h
diff --git a/test/chunk.c b/test/chunk.c
index 73cb07c..60a8850 100644
--- a/test/chunk.c
+++ b/test/chunk.c
@@ -7,13 +7,8 @@
*
* Purpose: Checks the effect of various I/O request sizes and raw data
* cache sizes. Performance depends on the amount of data read
- * from disk, and we use a trick to get that number: a
- * compress/uncompress pair that counts the amount of data read.
- * Since the data itself is not important, the compression just
- * removes a byte and uncompression adds some byte of arbitrary
- * value. The change in size is necessary or the library will
- * not store the data as compressed and thus not call the
- * uncompression method.
+ * from disk and we use a filter to get that number.
+
*/
#include <assert.h>
#include <hdf5.h>
@@ -34,7 +29,7 @@
#define LINESPOINTS "lines"
#define CH_SIZE 100 /*squared in terms of bytes */
#define DS_SIZE 20 /*squared in terms of chunks */
-#define ZMETHNO H5Z_USERDEF_MIN
+#define FILTER_COUNTER 305
#define READ 0
#define WRITE 1
#define MIN(X,Y) ((X)<(Y)?(X):(Y))
@@ -62,9 +57,9 @@ static hid_t fapl_g = -1;
/*-------------------------------------------------------------------------
- * Function: count_c
+ * Function: counter
*
- * Purpose: A bogus compression method that just removes the last byte.
+ * Purpose: Count number of bytes but don't do anything.
*
* Return: Success: src_nbytes-1
*
@@ -78,41 +73,12 @@ static hid_t fapl_g = -1;
*-------------------------------------------------------------------------
*/
static size_t
-count_c (unsigned int __unused__ flags, size_t __unused__ cd_size,
- const void __unused__ *client_data, size_t src_nbytes,
- const void *src, size_t __unused__ dst_nbytes, void *dst/*out*/)
-{
- memcpy (dst, src, src_nbytes-1);
- nio_g += src_nbytes;
- return src_nbytes-1;
-}
-
-
-/*-------------------------------------------------------------------------
- * Function: count_u
- *
- * Purpose: A bogus unompress method that just adds a zero to the end.
- *
- * Return: Success: src_nbytes+1
- *
- * Failure: never fails
- *
- * Programmer: Robb Matzke
- * Thursday, May 14, 1998
- *
- * Modifications:
- *
- *-------------------------------------------------------------------------
- */
-static size_t
-count_u (unsigned int __unused__ flags, size_t __unused__ cd_size,
- const void __unused__ *client_data, size_t src_nbytes,
- const void *src, size_t __unused__ dst_nbytes, void *dst/*out*/)
+counter (unsigned __unused__ flags, size_t __unused__ cd_nelmts,
+ const unsigned __unused__ *cd_values, size_t nbytes,
+ size_t __unused__ *buf_size, void __unused__ **buf)
{
- memcpy (dst, src, src_nbytes);
- ((char*)dst)[src_nbytes] = 0;
- nio_g += src_nbytes+1;
- return src_nbytes+1;
+ nio_g += nbytes;
+ return nbytes;
}
@@ -151,8 +117,8 @@ create_dataset (void)
dcpl = H5Pcreate (H5P_DATASET_CREATE);
size[0] = size[1] = CH_SIZE;
H5Pset_chunk (dcpl, 2, size);
- H5Zregister (ZMETHNO, "counter", count_c, count_u);
- H5Pset_compression (dcpl, ZMETHNO, 0, 0, NULL);
+ H5Zregister (FILTER_COUNTER, "counter", counter);
+ H5Pset_filter (dcpl, FILTER_COUNTER, 0, 0, NULL);
/* The dataset */
dset = H5Dcreate (file, "dset", H5T_NATIVE_CHAR, space, dcpl);
@@ -214,7 +180,8 @@ test_rowmaj (int op, hsize_t cache_size, hsize_t io_size)
hs_offset[1] = j;
hs_size[1] = MIN (io_size, CH_SIZE*DS_SIZE-j);
mem_space = H5Screate_simple (2, hs_size, hs_size);
- H5Sselect_hyperslab (file_space, H5S_SELECT_SET, hs_offset, NULL, hs_size, NULL);
+ H5Sselect_hyperslab (file_space, H5S_SELECT_SET, hs_offset,
+ NULL, hs_size, NULL);
if (READ==op) {
H5Dread (dset, H5T_NATIVE_CHAR, mem_space, file_space,
@@ -274,7 +241,8 @@ test_diag (int op, hsize_t cache_size, hsize_t io_size, hsize_t offset)
hs_offset[0] = hs_offset[1] = i;
hs_size[0] = hs_size[1] = MIN (io_size, CH_SIZE*DS_SIZE-i);
mem_space = H5Screate_simple (2, hs_size, hs_size);
- H5Sselect_hyperslab (file_space, H5S_SELECT_SET, hs_offset, NULL, hs_size, NULL);
+ H5Sselect_hyperslab (file_space, H5S_SELECT_SET, hs_offset, NULL,
+ hs_size, NULL);
if (READ==op) {
H5Dread (dset, H5T_NATIVE_CHAR, mem_space, file_space,
H5P_DEFAULT, buf);
diff --git a/test/dtypes.c b/test/dtypes.c
index f06c8bb..320d440 100644
--- a/test/dtypes.c
+++ b/test/dtypes.c
@@ -681,6 +681,343 @@ test_named (void)
/*-------------------------------------------------------------------------
+ * Function: mkstr
+ *
+ * Purpose: Create a new string data type
+ *
+ * Return: Success: New type
+ *
+ * Failure: -1
+ *
+ * Programmer: Robb Matzke
+ * Monday, August 10, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static hid_t
+mkstr(size_t len, H5T_str_t strpad)
+{
+ hid_t t;
+
+ if ((t=H5Tcopy(H5T_C_S1))<0) return -1;
+ if (H5Tset_size(t, len)<0) return -1;
+ if (H5Tset_strpad(t, strpad)<0) return -1;
+ return t;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_conv_str_1
+ *
+ * Purpose: Test string conversions
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Robb Matzke
+ * Monday, August 10, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+test_conv_str_1(void)
+{
+ char *buf=NULL;
+ hid_t src_type, dst_type;
+
+ printf("%-70s", "Testing string conversions");
+ fflush(stdout);
+
+ /*
+ * Convert a null-terminated string to a shorter and longer null
+ * terminated string.
+ */
+ src_type = mkstr(10, H5T_STR_NULLTERM);
+ dst_type = mkstr(5, H5T_STR_NULLTERM);
+ buf = calloc(2, 10);
+ memcpy(buf, "abcdefghi\0abcdefghi\0", 20);
+ if (H5Tconvert(src_type, dst_type, 2, buf, NULL)<0) goto error;
+ if (memcmp(buf, "abcd\0abcd\0abcdefghi\0", 20)) {
+ puts("*FAILED*");
+ puts(" Truncated C-string test failed");
+ goto error;
+ }
+ if (H5Tconvert(dst_type, src_type, 2, buf, NULL)<0) goto error;
+ if (memcmp(buf, "abcd\0\0\0\0\0\0abcd\0\0\0\0\0\0", 20)) {
+ puts("*FAILED*");
+ puts(" Extended C-string test failed");
+ goto error;
+ }
+ free(buf);
+ H5Tclose(src_type);
+ H5Tclose(dst_type);
+
+ /*
+ * Convert a null padded string to a shorter and then longer string.
+ */
+ src_type = mkstr(10, H5T_STR_NULLPAD);
+ dst_type = mkstr(5, H5T_STR_NULLPAD);
+ buf = calloc(2, 10);
+ memcpy(buf, "abcdefghijabcdefghij", 20);
+ if (H5Tconvert(src_type, dst_type, 2, buf, NULL)<0) goto error;
+ if (memcmp(buf, "abcdeabcdeabcdefghij", 20)) {
+ puts("*FAILED*");
+ puts(" Truncated C buffer test failed");
+ goto error;
+ }
+ if (H5Tconvert(dst_type, src_type, 2, buf, NULL)<0) goto error;
+ if (memcmp(buf, "abcde\0\0\0\0\0abcde\0\0\0\0\0", 20)) {
+ puts("*FAILED*");
+ puts(" Extended C buffer test failed");
+ goto error;
+ }
+ free(buf);
+ H5Tclose(src_type);
+ H5Tclose(dst_type);
+
+ /*
+ * Convert a space-padded string to a shorter and then longer string.
+ */
+ src_type = mkstr(10, H5T_STR_SPACEPAD);
+ dst_type = mkstr(5, H5T_STR_SPACEPAD);
+ buf = calloc(2, 10);
+ memcpy(buf, "abcdefghijabcdefghij", 20);
+ if (H5Tconvert(src_type, dst_type, 2, buf, NULL)<0) goto error;
+ if (memcmp(buf, "abcdeabcdeabcdefghij", 20)) {
+ puts("*FAILED*");
+ puts(" Truncated Fortran-string test failed");
+ goto error;
+ }
+ if (H5Tconvert(dst_type, src_type, 2, buf, NULL)<0) goto error;
+ if (memcmp(buf, "abcde abcde ", 20)) {
+ puts("*FAILED*");
+ puts(" Extended Fortran-string test failed");
+ goto error;
+ }
+ free(buf);
+ H5Tclose(src_type);
+ H5Tclose(dst_type);
+
+ /*
+ * What happens if a null-terminated string is not null terminated? If
+ * the conversion is to an identical string then nothing happens but if
+ * the destination is a different size or type of string then the right
+ * thing should happen.
+ */
+ src_type = mkstr(10, H5T_STR_NULLTERM);
+ dst_type = mkstr(10, H5T_STR_NULLTERM);
+ buf = calloc(2, 10);
+ memcpy(buf, "abcdefghijabcdefghij", 20);
+ if (H5Tconvert(src_type, dst_type, 2, buf, NULL)<0) goto error;
+ if (memcmp(buf, "abcdefghijabcdefghij", 20)) {
+ puts("*FAILED*");
+ puts(" Non-terminated string test 1");
+ goto error;
+ }
+ H5Tclose(dst_type);
+ dst_type = mkstr(5, H5T_STR_NULLTERM);
+ memcpy(buf, "abcdefghijabcdefghij", 20);
+ if (H5Tconvert(src_type, dst_type, 2, buf, NULL)<0) goto error;
+ if (memcmp(buf, "abcd\0abcd\0abcdefghij", 20)) {
+ puts("*FAILED*");
+ puts(" Non-terminated string test 2");
+ goto error;
+ }
+ memcpy(buf, "abcdeabcdexxxxxxxxxx", 20);
+ if (H5Tconvert(dst_type, src_type, 2, buf, NULL)<0) goto error;
+ if (memcmp(buf, "abcde\0\0\0\0\0abcde\0\0\0\0\0", 20)) {
+ puts("*FAILED*");
+ puts(" Non-terminated string test 2");
+ goto error;
+ }
+ free(buf);
+ H5Tclose(src_type);
+ H5Tclose(dst_type);
+
+ /*
+ * Test C string to Fortran and vice versa.
+ */
+ src_type = mkstr(10, H5T_STR_NULLTERM);
+ dst_type = mkstr(10, H5T_STR_SPACEPAD);
+ buf = calloc(2, 10);
+ memcpy(buf, "abcdefghi\0abcdefghi\0", 20);
+ if (H5Tconvert(src_type, dst_type, 2, buf, NULL)<0) goto error;
+ if (memcmp(buf, "abcdefghi abcdefghi ", 20)) {
+ puts("*FAILED*");
+ puts(" C string to Fortran test 1");
+ goto error;
+ }
+ if (H5Tconvert(dst_type, src_type, 2, buf, NULL)<0) goto error;
+ if (memcmp(buf, "abcdefghi\0abcdefghi\0", 20)) {
+ puts("*FAILED*");
+ puts(" Fortran to C string test 1");
+ goto error;
+ }
+ H5Tclose(dst_type);
+ dst_type = mkstr(5, H5T_STR_SPACEPAD);
+ memcpy(buf, "abcdefgh\0\0abcdefgh\0\0", 20);
+ if (H5Tconvert(src_type, dst_type, 2, buf, NULL)<0) goto error;
+ if (memcmp(buf, "abcdeabcdeabcdefgh\0\0", 20)) {
+ puts("*FAILED*");
+ puts(" C string to Fortran test 2");
+ goto error;
+ }
+ if (H5Tconvert(dst_type, src_type, 2, buf, NULL)<0) goto error;
+ if (memcmp(buf, "abcde\0\0\0\0\0abcde\0\0\0\0\0", 20)) {
+ puts("*FAILED*");
+ puts(" Fortran to C string test 2");
+ goto error;
+ }
+ H5Tclose(src_type);
+ H5Tclose(dst_type);
+ src_type = mkstr(5, H5T_STR_NULLTERM);
+ dst_type = mkstr(10, H5T_STR_SPACEPAD);
+ memcpy(buf, "abcd\0abcd\0xxxxxxxxxx", 20);
+ if (H5Tconvert(src_type, dst_type, 2, buf, NULL)<0) goto error;
+ if (memcmp(buf, "abcd abcd ", 20)) {
+ puts("*FAILED*");
+ puts(" C string to Fortran test 3");
+ goto error;
+ }
+ if (H5Tconvert(dst_type, src_type, 2, buf, NULL)<0) goto error;
+ if (memcmp(buf, "abcd\0abcd\0abcd ", 20)) {
+ puts("*FAILED*");
+ puts(" Fortran to C string test 3");
+ goto error;
+ }
+ free(buf);
+ H5Tclose(src_type);
+ H5Tclose(dst_type);
+
+ /*
+ * Test C buffer to Fortran and vice versa.
+ */
+ src_type = mkstr(10, H5T_STR_NULLPAD);
+ dst_type = mkstr(10, H5T_STR_SPACEPAD);
+ buf = calloc(2, 10);
+ memcpy(buf, "abcdefghijabcdefghij", 20);
+ if (H5Tconvert(src_type, dst_type, 2, buf, NULL)<0) goto error;
+ if (memcmp(buf, "abcdefghijabcdefghij", 20)) {
+ puts("*FAILED*");
+ puts(" C buffer to Fortran test 1");
+ goto error;
+ }
+ if (H5Tconvert(dst_type, src_type, 2, buf, NULL)<0) goto error;
+ if (memcmp(buf, "abcdefghijabcdefghij", 20)) {
+ puts("*FAILED*");
+ puts(" Fortran to C buffer test 1");
+ goto error;
+ }
+ H5Tclose(dst_type);
+ dst_type = mkstr(5, H5T_STR_SPACEPAD);
+ memcpy(buf, "abcdefgh\0\0abcdefgh\0\0", 20);
+ if (H5Tconvert(src_type, dst_type, 2, buf, NULL)<0) goto error;
+ if (memcmp(buf, "abcdeabcdeabcdefgh\0\0", 20)) {
+ puts("*FAILED*");
+ puts(" C buffer to Fortran test 2");
+ goto error;
+ }
+ if (H5Tconvert(dst_type, src_type, 2, buf, NULL)<0) goto error;
+ if (memcmp(buf, "abcde\0\0\0\0\0abcde\0\0\0\0\0", 20)) {
+ puts("*FAILED*");
+ puts(" Fortran to C buffer test 2");
+ goto error;
+ }
+ H5Tclose(src_type);
+ H5Tclose(dst_type);
+ src_type = mkstr(5, H5T_STR_NULLPAD);
+ dst_type = mkstr(10, H5T_STR_SPACEPAD);
+ memcpy(buf, "abcd\0abcd\0xxxxxxxxxx", 20);
+ if (H5Tconvert(src_type, dst_type, 2, buf, NULL)<0) goto error;
+ if (memcmp(buf, "abcd abcd ", 20)) {
+ puts("*FAILED*");
+ puts(" C buffer to Fortran test 3");
+ goto error;
+ }
+ if (H5Tconvert(dst_type, src_type, 2, buf, NULL)<0) goto error;
+ if (memcmp(buf, "abcd\0abcd\0abcd ", 20)) {
+ puts("*FAILED*");
+ puts(" Fortran to C buffer test 3");
+ goto error;
+ }
+ free(buf);
+ H5Tclose(src_type);
+ H5Tclose(dst_type);
+
+ puts(" PASSED");
+ return 0;
+
+ error:
+ return -1;
+}
+
+
+/*-------------------------------------------------------------------------
+ * Function: test_conv_str_2
+ *
+ * Purpose: Tests C-to-Fortran and Fortran-to-C string conversion speed.
+ *
+ * Return: Success: 0
+ *
+ * Failure: -1
+ *
+ * Programmer: Robb Matzke
+ * Monday, August 10, 1998
+ *
+ * Modifications:
+ *
+ *-------------------------------------------------------------------------
+ */
+static herr_t
+test_conv_str_2(void)
+{
+ char *buf=NULL, s[80];
+ hid_t c_type, f_type;
+ const size_t nelmts = 200000, ntests=5;
+ size_t i, j, nchars;
+ herr_t ret_value = -1;
+
+ /*
+ * Initialize types and buffer.
+ */
+ c_type = mkstr(8, H5T_STR_NULLPAD);
+ f_type = mkstr(8, H5T_STR_SPACEPAD);
+ buf = calloc(nelmts, 8);
+ for (i=0; i<nelmts; i++) {
+ nchars = rand() % 8;
+ for (j=0; j<nchars; j++) {
+ buf[i*8+j] = 'a' + rand()%26;
+ }
+ while (j<nchars) buf[i*8+j++] = '\0';
+ }
+
+ /* Do the conversions */
+ for (i=0; i<ntests; i++) {
+ sprintf(s, "Testing random string conversion speed (test %d/%d)",
+ (int)(i+1), (int)ntests);
+ printf("%-70s", s);
+ fflush(stdout);
+
+ if (H5Tconvert(c_type, f_type, nelmts, buf, NULL)<0) goto error;
+ if (H5Tconvert(f_type, c_type, nelmts, buf, NULL)<0) goto error;
+ puts(" PASSED");
+ }
+ ret_value = 0;
+
+ error:
+ if (buf) free(buf);
+ return ret_value;
+}
+
+
+
+
+/*-------------------------------------------------------------------------
* Function: test_conv_int
*
* Purpose: Test atomic number conversions.
@@ -1310,6 +1647,8 @@ main(void)
nerrors += test_compound()<0 ? 1 : 0;
nerrors += test_transient ()<0 ? 1 : 0;
nerrors += test_named ()<0 ? 1 : 0;
+ nerrors += test_conv_str_1()<0 ? 1 : 0;
+ nerrors += test_conv_str_2()<0 ? 1 : 0;
nerrors += test_conv_int ()<0 ? 1 : 0;
/* Does floating point overflow generate a SIGFPE? */