diff options
Diffstat (limited to 'hl/test')
-rw-r--r-- | hl/test/CMakeLists.txt | 87 | ||||
-rw-r--r-- | hl/test/Makefile.am | 2 | ||||
-rw-r--r-- | hl/test/Makefile.in | 5 | ||||
-rw-r--r-- | hl/test/test_ds.c | 162 |
4 files changed, 243 insertions, 13 deletions
diff --git a/hl/test/CMakeLists.txt b/hl/test/CMakeLists.txt new file mode 100644 index 0000000..91d7c80 --- /dev/null +++ b/hl/test/CMakeLists.txt @@ -0,0 +1,87 @@ +cmake_minimum_required (VERSION 2.8) +# -------------------------------------------------------------------- +# Notes: When creating unit test executables they should be prefixed +# with "hl_". This allows for easier filtering of the test suite when +# using ctest. An example would be +# ctest -R hl_ +# which would only run the High Level based unit tests. +# -------------------------------------------------------------------- + +PROJECT (HDF5_HL_TEST) + +#----------------------------------------------------------------------------- +# Generate the H5srcdir_str.h file containing user settings needed by compilation +#----------------------------------------------------------------------------- +SET (srcdir ${CMAKE_CURRENT_SOURCE_DIR}) +CONFIGURE_FILE (${HDF5_HL_TEST_SOURCE_DIR}/H5srcdir_str.h.in H5srcdir_str.h @ONLY) + +INCLUDE_DIRECTORIES (${CMAKE_CURRENT_BINARY_DIR}) +INCLUDE_DIRECTORIES (${HDF5_TEST_SOURCE_DIR}) + +# -------------------------------------------------------------------- +# Macro used to add a unit test +# -------------------------------------------------------------------- +MACRO (HL_ADD_TEST hl_name files) + ADD_EXECUTABLE (hl_${hl_name} ${hl_name}.c) + H5_NAMING (hl_${hl_name}) + IF (WIN32) + IF (MSVC) + IF (NOT BUILD_SHARED_LIBS) + SET_TARGET_PROPERTIES (hl_${hl_name} + PROPERTIES + LINK_FLAGS "/NODEFAULTLIB:MSVCRT" + ) + ENDIF (NOT BUILD_SHARED_LIBS) + ENDIF (MSVC) + ENDIF (WIN32) + TARGET_LINK_LIBRARIES (hl_${hl_name} + ${HDF5_HL_LIB_TARGET} + ${HDF5_LIB_TARGET} + ${HDF5_TEST_LIB_TARGET} + ) + + ADD_TEST (NAME hl_${hl_name} COMMAND $<TARGET_FILE:hl_${hl_name}>) + + #-- Copy the necessary files. + FOREACH (h5_file ${files}) + SET (dest "${HDF5_HL_TEST_BINARY_DIR}/${h5_file}") + #MESSAGE (STATUS " Copying HL Test File ${h5_file} to ${dest}") + ADD_CUSTOM_COMMAND ( + TARGET hl_${hl_name} + PRE_BUILD + COMMAND ${CMAKE_COMMAND} + ARGS -E copy_if_different ${HDF5_HL_TEST_SOURCE_DIR}/${h5_file} ${dest} + ) + + ENDFOREACH (h5_file ${HL_REFERENCE_TEST_FILES}) +ENDMACRO (HL_ADD_TEST) + +HL_ADD_TEST (test_ds "dsdata.txt;dslat.txt;dslon.txt;test_ds_be.h5;test_ds_le.h5") +HL_ADD_TEST (test_image "image8.txt;sepia.pal;earth.pal;image24pixel.txt;image24plane.txt;usa.wri") +HL_ADD_TEST (test_lite "dtype_file.txt") +HL_ADD_TEST (test_packet "") +HL_ADD_TEST (test_table "test_table_be.hdf5;test_table_cray.hdf5;test_table_le.hdf5") + +# -------------------------------------------------------------------- +# This executable is used to generate test files for the test_ds test. +# It should only be run during development when new test files are needed +# -------------------------------------------------------------------- +IF (NOT BUILD_SHARED_LIBS) + ADD_EXECUTABLE (hl_gen_test_ds gen_test_ds.c) + H5_NAMING (hl_gen_test_ds) + IF (WIN32) + IF (MSVC) + IF (NOT BUILD_SHARED_LIBS) + SET_TARGET_PROPERTIES (hl_gen_test_ds + PROPERTIES + LINK_FLAGS "/NODEFAULTLIB:MSVCRT" + ) + ENDIF (NOT BUILD_SHARED_LIBS) + ENDIF (MSVC) + ENDIF (WIN32) + TARGET_LINK_LIBRARIES (hl_gen_test_ds + ${HDF5_HL_LIB_TARGET} + ${HDF5_LIB_TARGET} + ${HDF5_TEST_LIB_TARGET} + ) +ENDIF (NOT BUILD_SHARED_LIBS) diff --git a/hl/test/Makefile.am b/hl/test/Makefile.am index fc6e969..86e3318 100644 --- a/hl/test/Makefile.am +++ b/hl/test/Makefile.am @@ -46,6 +46,6 @@ endif # Temporary files. These files are the ones created by running `make test'. CHECK_CLEANFILES+=combine_tables[1-2].h5 test_ds[1-9].h5 test_image[1-3].h5 \ test_lite[1-2].h5 test_table.h5 test_packet_table.h5 \ - test_packet_compress.h5 + test_packet_compress.h5 test_detach.h5 include $(top_srcdir)/config/conclude.am diff --git a/hl/test/Makefile.in b/hl/test/Makefile.in index 3d37e3e..a68831e 100644 --- a/hl/test/Makefile.in +++ b/hl/test/Makefile.in @@ -215,12 +215,12 @@ INSTALL_SCRIPT = @INSTALL_SCRIPT@ INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ INSTRUMENT = @INSTRUMENT@ INSTRUMENT_LIBRARY = @INSTRUMENT_LIBRARY@ +LARGEFILE = @LARGEFILE@ LD = @LD@ LDFLAGS = @LDFLAGS@ LIBOBJS = @LIBOBJS@ LIBS = @LIBS@ LIBTOOL = @LIBTOOL@ -LINUX_LFS = @LINUX_LFS@ LIPO = @LIPO@ LL_PATH = @LL_PATH@ LN_S = @LN_S@ @@ -383,7 +383,8 @@ TRACE = perl $(top_srcdir)/bin/trace # Temporary files. These files are the ones created by running `make test'. CHECK_CLEANFILES = *.chkexe *.chklog *.clog combine_tables[1-2].h5 \ test_ds[1-9].h5 test_image[1-3].h5 test_lite[1-2].h5 \ - test_table.h5 test_packet_table.h5 test_packet_compress.h5 + test_table.h5 test_packet_table.h5 test_packet_compress.h5 \ + test_detach.h5 # The tests depend on the hdf5, hdf5 test, and hdf5_hl libraries LDADD = $(LIBH5_HL) $(LIBH5TEST) $(LIBHDF5) diff --git a/hl/test/test_ds.c b/hl/test/test_ds.c index d1705ec..53870f5 100644 --- a/hl/test/test_ds.c +++ b/hl/test/test_ds.c @@ -71,6 +71,7 @@ static int test_long_scalenames(const char *fileext); static int test_samelong_scalenames(const char *fileext); static int test_float_scalenames(const char *fileext); static int test_foreign_scaleattached(const char *fileforeign); +static int test_detachscales(void); static int test_simple(void); static int test_errors(void); @@ -136,6 +137,9 @@ static int read_data( const char* fname, int ndims, hsize_t *dims, float **buf ) #define FILE6 "test_ds8.h5" #define FILE7 "test_ds9.h5" +#define DIMENSION_LIST "DIMENSION_LIST" +#define REFERENCE_LIST "REFERENCE_LIST" + /*------------------------------------------------------------------------- * the main program *------------------------------------------------------------------------- @@ -169,6 +173,7 @@ int main(void) nerrors += test_samelong_scalenames("2") < 0 ? 1 : 0; nerrors += test_foreign_scaleattached(FOREIGN_FILE1) < 0 ? 1 : 0; nerrors += test_foreign_scaleattached(FOREIGN_FILE2) < 0 ? 1 : 0; + nerrors += test_detachscales() < 0 ? 1 : 0; /* the following tests have not been rewritten to match those above */ nerrors += test_simple() < 0 ?1:0; @@ -238,8 +243,7 @@ herr_t create_char_dataset(hid_t fid, const char *dsidx, int fulldims) int rank = 3; int rankds = 1; hsize_t dims[3] = {DIM1_SIZE,DIM2_SIZE,DIM3_SIZE}; - char buf[DIM_DATA*3] = {1,2,3,4,5,6,7,8,9,10,11,12, - 1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11,12}; + char buf[DIM1_SIZE*DIM2_SIZE*DIM3_SIZE]; hsize_t s1_dim[1] = {DIM1_SIZE}; hsize_t s2_dim[1] = {DIM2_SIZE}; hsize_t s3_dim[1] = {DIM3_SIZE}; @@ -292,8 +296,7 @@ herr_t create_short_dataset(hid_t fid, const char *dsidx, int fulldims) int rank = 3; int rankds = 1; hsize_t dims[3] = {DIM1_SIZE,DIM2_SIZE,DIM3_SIZE}; - short buf[DIM_DATA*3] = {1,2,3,4,5,6,7,8,9,10,11,12, - 1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11,12}; + short buf[DIM1_SIZE*DIM2_SIZE*DIM3_SIZE]; hsize_t s1_dim[1] = {DIM1_SIZE}; hsize_t s2_dim[1] = {DIM2_SIZE}; hsize_t s3_dim[1] = {DIM3_SIZE}; @@ -347,7 +350,7 @@ herr_t create_int_dataset(hid_t fid, const char *dsidx, int fulldims) int rank = RANK; int rankds = 1; hsize_t dims[RANK] = {DIM1_SIZE,DIM2_SIZE}; - int buf[DIM_DATA] = {1,2,3,4,5,6,7,8,9,10,11,12}; + int buf[DIM1_SIZE*DIM2_SIZE]; hsize_t s1_dim[1] = {DIM1_SIZE}; hsize_t s2_dim[1] = {DIM2_SIZE}; int s1_wbuf[DIM1_SIZE] = {10,20,30}; @@ -389,10 +392,7 @@ herr_t create_long_dataset(hid_t fid, const char *dsname, const char *dsidx, int int rank = 4; int rankds = 1; hsize_t dims[4] = {DIM1_SIZE,DIM2_SIZE,DIM3_SIZE,DIM4_SIZE}; - long buf[DIM_DATA*3*2] = {1,2,3,4,5,6,7,8,9,10,11,12, - 1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11,12, - 1,2,3,4,5,6,7,8,9,10,11,12,1,2,3,4,5,6,7,8,9,10,11,12, - 1,2,3,4,5,6,7,8,9,10,11,12}; + long buf[DIM1_SIZE*DIM2_SIZE*DIM3_SIZE*DIM4_SIZE]; hsize_t s1_dim[1] = {DIM1_SIZE}; hsize_t s2_dim[1] = {DIM2_SIZE}; hsize_t s3_dim[1] = {DIM3_SIZE}; @@ -458,7 +458,7 @@ herr_t create_float_dataset(hid_t fid, const char *dsidx, int fulldims) int rank = RANK; int rankds = 1; hsize_t dims[RANK] = {DIM1_SIZE,DIM2_SIZE}; - float buf[DIM_DATA] = {1,2,3,4,5,6,7,8,9,10,11,12}; + float buf[DIM1_SIZE*DIM2_SIZE]; hsize_t s1_dim[1] = {DIM1_SIZE}; hsize_t s2_dim[1] = {DIM2_SIZE}; float s1_wbuf[DIM1_SIZE] = {10,20,30}; @@ -1144,6 +1144,148 @@ herr_t test_cmp_scalename(hid_t fid, hid_t did, const char *name, const char *sc return ret_value; } +static int test_detachscales(void) +{ + hid_t fid = -1; + hid_t did = -1; + hid_t dsid = -1; + int rank1 = 1; + int rank3 = 3; + hsize_t dims[] = {1,2,3}; /*some bogus numbers, not important for the test*/ + int *buf = NULL; + char dname[10]; + int i; + + /* This tests creates two three dimensional datasets; then it creates + four integer datasets that are used as dim. scales; we will attach + and detach them to check that at the end there is no attributes + REFERENCE_LIST on a dimension scale and DIMENSION_LIST on a dataset */ + + TESTING2("test_detachscales"); + + if((fid = H5Fcreate("test_detach.h5", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) + goto out; + + /* make datasets; they are three dimensional*/ + for (i=0; i < 2; i++) { + sprintf(dname,"D%d", i); + if(H5LTmake_dataset_int(fid, dname, rank3, dims, buf) < 0) + goto out; + } + /* create datasets and make them dim. scales */ + + for (i=0; i < 4; i++) { + sprintf(dname, "DS%d", i); + if(H5LTmake_dataset_int(fid, dname, rank1, dims, buf) < 0) + goto out; + } + /* attach scales to the first dataset; first dimension will have + two scales attached */ + if((did = H5Dopen2(fid, "D0", H5P_DEFAULT)) >= 0) { + for (i=0; i<4; i++) { + sprintf(dname, "DS%d", i); + if((dsid = H5Dopen2(fid, dname, H5P_DEFAULT)) < 0) + goto out; + if(H5DSattach_scale(did, dsid, (unsigned int) i%3) < 0) + goto out; + if(H5Dclose(dsid) < 0) + goto out; + } + if(H5Dclose(did) < 0) + goto out; + } + else + goto out; + + /* attach scales to the second dataset */ + if((did = H5Dopen2(fid, "D1", H5P_DEFAULT)) >= 0) { + for (i=0; i<3; i++) { + sprintf(dname, "DS%d", i); + if((dsid = H5Dopen2(fid, dname, H5P_DEFAULT)) < 0) + goto out; + if(H5DSattach_scale(did, dsid, (unsigned int) i) < 0) + goto out; + if(H5Dclose(dsid) < 0) + goto out; + } + if(H5Dclose(did) < 0) + goto out; + } + else + goto out; + + /* detach DS0 from first dimension of D0 and D1; then check + that DS0 doesn't have attribute REFERENCE _LIST */ + + if((dsid = H5Dopen2(fid, "DS0", H5P_DEFAULT)) < 0) + goto out; + + for (i=0; i<2; i++) { + sprintf(dname, "D%d", i); + if((did = H5Dopen2(fid, dname, H5P_DEFAULT)) < 0) + goto out; + if(H5DSdetach_scale(did, dsid, (unsigned int)0) < 0) + goto out; + if(H5Dclose(did) < 0) + goto out; + } + /* Check that attribute "REFERENCE_LIST" doesn't exist anymore */ + if(H5Aexists(dsid, REFERENCE_LIST)!= 0) + goto out; + if(H5Dclose(dsid) < 0) + goto out; + /* Check that DS3 is the only dim. scale attached to the first + dimension of D0 */ + if((did = H5Dopen2(fid, "D0", H5P_DEFAULT)) < 0) + goto out; + if((dsid = H5Dopen2(fid, "DS3", H5P_DEFAULT)) < 0) + goto out; + if(H5DSis_attached(did, dsid, (unsigned int) 0) <= 0) + goto out; + if(H5Dclose(did) < 0) + goto out; + if(H5Dclose(dsid) < 0) + goto out; + + /* Detach the rest of the scales DS3, DS1, DS2 from D0 and make + sure that attribute "DIMENSION_LIST" doesn't exist anymore */ + if((did = H5Dopen2(fid, "D0", H5P_DEFAULT)) >= 0) { + for (i=1; i<4; i++) { + sprintf(dname, "DS%d", i); + if((dsid = H5Dopen2(fid, dname, H5P_DEFAULT)) < 0) + goto out; + if(H5DSdetach_scale(did, dsid, (unsigned int) i%3) < 0) + goto out; + if(H5Dclose(dsid) < 0) + goto out; + } + /* Check that attribute "DIMENSION_LIST" doesn't exist anymore */ + if(H5Aexists(did, DIMENSION_LIST)!= 0) + goto out; + if(H5Dclose(did) < 0) + goto out; + } + else + goto out; + + + PASSED(); + + H5Fclose(fid); + return SUCCEED; + +out: + H5E_BEGIN_TRY { + H5Dclose(did); + H5Dclose(dsid); + H5Fclose(fid); + } H5E_END_TRY; + + H5_FAILED(); + + return FAIL; +} + static int test_char_attachscales(const char *fileext) { hid_t fid = -1; |