diff --git a/CMakeLists.txt b/CMakeLists.txt index a149e0fe4d..29f1c04dc5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1623,6 +1623,7 @@ ENDIF(USE_HDF5) IF(USE_HDF4) add_subdirectory(libhdf4) + add_subdirectory(hdf4_test) ENDIF(USE_HDF4) IF(ENABLE_DAP2) diff --git a/Makefile.am b/Makefile.am index f8c1e3eb89..ea4f6193b8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -64,13 +64,14 @@ endif # Build HDF4 if desired. if USE_HDF4 +HDF4_TEST_DIR = hdf4_test LIBHDF4 = libhdf4 endif # Define Test directories if BUILD_TESTSETS -TESTDIRS = $(V2_TEST) nc_test $(NC_TEST4) $(NCDAP2TESTDIR) \ -$(NCDAP4TESTDIR) +TESTDIRS = $(V2_TEST) nc_test $(NC_TEST4) $(HDF4_TEST_DIR) \ +$(NCDAP2TESTDIR) $(NCDAP4TESTDIR) endif # This is the list of subdirs for which Makefiles will be constructed diff --git a/configure.ac b/configure.ac index 726c0bda41..a981fb0294 100644 --- a/configure.ac +++ b/configure.ac @@ -72,8 +72,8 @@ AC_CONFIG_LINKS([nc_test4/ref_hdf5_compat1.nc:nc_test4/ref_hdf5_compat1.nc]) AC_CONFIG_LINKS([nc_test4/ref_hdf5_compat2.nc:nc_test4/ref_hdf5_compat2.nc]) AC_CONFIG_LINKS([nc_test4/ref_hdf5_compat3.nc:nc_test4/ref_hdf5_compat3.nc]) -AC_CONFIG_LINKS([nc_test4/ref_chunked.hdf4:nc_test4/ref_chunked.hdf4]) -AC_CONFIG_LINKS([nc_test4/ref_contiguous.hdf4:nc_test4/ref_contiguous.hdf4]) +AC_CONFIG_LINKS([hdf4_test/ref_chunked.hdf4:hdf4_test/ref_chunked.hdf4]) +AC_CONFIG_LINKS([hdf4_test/ref_contiguous.hdf4:hdf4_test/ref_contiguous.hdf4]) AM_INIT_AUTOMAKE([foreign dist-zip subdir-objects]) @@ -1430,6 +1430,7 @@ AC_CONFIG_FILES([Makefile include/netcdf_meta.h include/Makefile h5_test/Makefile + hdf4_test/Makefile libsrc/Makefile libsrc4/Makefile libsrcp/Makefile diff --git a/hdf4_test/CMakeLists.txt b/hdf4_test/CMakeLists.txt new file mode 100644 index 0000000000..1d95d9b123 --- /dev/null +++ b/hdf4_test/CMakeLists.txt @@ -0,0 +1,16 @@ +# Copy some test files from current source dir to out-of-tree build dir. +FILE(GLOB COPY_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.sh ${CMAKE_CURRENT_SOURCE_DIR}/*.hdf4) +FILE(COPY ${COPY_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) +IF(MSVC) + FILE(COPY ${COPY_FILES} DESTINATION ${RUNTIME_OUTPUT_DIRECTORY}/) +ENDIF() + +IF(USE_HDF4_FILE_TESTS AND NOT MSVC) + build_bin_test_no_prefix(tst_interops2) + build_bin_test_no_prefix(tst_interops3) + add_bin_test(hdf4_test tst_chunk_hdf4) + add_bin_test(hdf4_test tst_h4_lendian) + add_sh_test(hdf4_test run_get_hdf4_files) + add_sh_test(hdf4_test run_formatx_hdf4) +ENDIF() + diff --git a/hdf4_test/Makefile.am b/hdf4_test/Makefile.am new file mode 100644 index 0000000000..5bb7e82898 --- /dev/null +++ b/hdf4_test/Makefile.am @@ -0,0 +1,37 @@ +# This is part of the netCDF package. +# Copyright 2018 University Corporation for Atmospheric Research/Unidata +# See COPYRIGHT file for conditions of use. +# +# This directory has tests for the HDF4 code. This directory will be +# skipped if HDF4 is not enabled. +# +# Ed Hartnett + +# Put together AM_CPPFLAGS and AM_LDFLAGS. +include $(top_srcdir)/lib_flags.am + +# Link to our assembled library. +AM_LDFLAGS += ${top_builddir}/liblib/libnetcdf.la + +# These are the C tests for HDF4. +check_PROGRAMS = tst_chunk_hdf4 tst_h4_lendian +TESTS = tst_chunk_hdf4 tst_h4_lendian + +# This test script depends on ncdump and tst_interops2.c. +if BUILD_UTILITIES +check_PROGRAMS += tst_interops2 +TESTS += run_formatx_hdf4.sh +endif # BUILD_UTILITIES + +# This test script fetches HDF4 files from an FTP server and uses +# program tst_interops3.c to read them. +if USE_HDF4_FILE_TESTS +check_PROGRAMS += tst_interops3 +TESTS += run_get_hdf4_files.sh +endif # USE_HDF4_FILE_TESTS + +EXTRA_DIST = CMakeLists.txt ref_contiguous.hdf4 ref_chunked.hdf4 \ +run_get_hdf4_files.sh run_formatx_hdf4.sh + +CLEANFILES = *.h4 *.hdf + diff --git a/nc_test4/ref_chunked.hdf4 b/hdf4_test/ref_chunked.hdf4 similarity index 100% rename from nc_test4/ref_chunked.hdf4 rename to hdf4_test/ref_chunked.hdf4 diff --git a/nc_test4/ref_contiguous.hdf4 b/hdf4_test/ref_contiguous.hdf4 similarity index 100% rename from nc_test4/ref_contiguous.hdf4 rename to hdf4_test/ref_contiguous.hdf4 diff --git a/hdf4_test/run_formatx_hdf4.sh b/hdf4_test/run_formatx_hdf4.sh new file mode 100755 index 0000000000..8fc19928e7 --- /dev/null +++ b/hdf4_test/run_formatx_hdf4.sh @@ -0,0 +1,51 @@ +#!/bin/sh + +# This shell script runs tst_interops2 to create a HDF4 file, and read +# it with netCDF. Then the script runs ncdump on the HDF4 file. + +# Ed Hartnett + +if test "x$srcdir" = x ; then srcdir=`pwd`; fi +. ../test_common.sh + +FILE=tst_interops2.h4 + +ECODE=0 + +echo "" +echo "*** Testing extended file format output." +set -e + +echo "Creating HDF4 file" +${execdir}/tst_interops2 + +echo "Test extended format output for a HDF4 file" +rm -f tmp_tst_formatx_hdf4 +${NCDUMP} -K $FILE >tmp_tst_formatx_hdf4 +if ! fgrep 'HDF4 mode=00001000' host); + size_t hostlen = (triple->host ? strlen(triple->host) : 0); const char* flagname; if(strncmp("CURL.",triple->key,5) != 0) continue; /* not a curl flag */ /* do hostport prefix comparison */ if(hostport != NULL) { - int t = strncmp(hostport,triple->host,hostlen); + int t = 0; + if(triple->host != NULL) + t = strncmp(hostport,triple->host,hostlen); if(t != 0) continue; } flagname = triple->key+5; /* 5 == strlen("CURL."); */ diff --git a/libdispatch/drc.c b/libdispatch/drc.c index c1b8b0cfe4..e2de99debe 100644 --- a/libdispatch/drc.c +++ b/libdispatch/drc.c @@ -315,6 +315,8 @@ rccompile(const char* path) } ncbytesnull(tmp); triple->host = ncbytesextract(tmp); + if(strlen(triple->host)==0) + {free(triple->host); triple->host = NULL;} } /* split off key and value */ key=line; @@ -331,7 +333,8 @@ rccompile(const char* path) rctrim(triple->value); #ifdef D4DEBUG fprintf(stderr,"rc: host=%s key=%s value=%s\n", - triple->host,triple->key,triple->valu); + (triple->host != NULL ? triple->host : ""), + triple->key,triple->valu); #endif nclistpush(rc,triple); triple = NULL; @@ -371,7 +374,9 @@ rclocate(const char* key, const char* hostport) (because we have checked all other cases)*/ if(hplen == 0) {found=1;break;} /* do hostport match */ - t = strcmp(hostport,triple->host); + t = 0; + if(triple->host != NULL) + t = strcmp(hostport,triple->host); if(t == 0) {found=1; break;} } return (found?triple:NULL); diff --git a/nc_test4/CMakeLists.txt b/nc_test4/CMakeLists.txt index 7247d0d718..7502d16bc2 100644 --- a/nc_test4/CMakeLists.txt +++ b/nc_test4/CMakeLists.txt @@ -72,7 +72,7 @@ IF(BUILD_BENCHMARKS) ENDIF() # Copy some test files from current source dir to out-of-tree build dir. -FILE(GLOB COPY_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.nc ${CMAKE_CURRENT_SOURCE_DIR}/ref_bzip2.c ${CMAKE_CURRENT_SOURCE_DIR}/*.sh ${CMAKE_CURRENT_SOURCE_DIR}/*.hdf4 ${CMAKE_CURRENT_SOURCE_DIR}/*.h5 ${CMAKE_CURRENT_SOURCE_DIR}/*.cdl) +FILE(GLOB COPY_FILES ${CMAKE_CURRENT_SOURCE_DIR}/*.nc ${CMAKE_CURRENT_SOURCE_DIR}/ref_bzip2.c ${CMAKE_CURRENT_SOURCE_DIR}/*.sh ${CMAKE_CURRENT_SOURCE_DIR}/*.h5 ${CMAKE_CURRENT_SOURCE_DIR}/*.cdl) FILE(COPY ${COPY_FILES} DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/) IF(MSVC) FILE(COPY ${COPY_FILES} DESTINATION ${RUNTIME_OUTPUT_DIRECTORY}/) @@ -83,20 +83,6 @@ FOREACH(CTEST ${NC4_TESTS}) add_bin_test(nc_test4 ${CTEST}) ENDFOREACH() -# This must go after the 'foreach' stanza -# immediately above this comment. -IF(USE_HDF4_FILE_TESTS AND NOT MSVC) - add_bin_test_no_prefix(tst_interops2) - build_bin_test_no_prefix(tst_interops3) - add_sh_test(nc_test4 run_get_hdf4_files) - add_sh_test(nc_test4 tst_formatx_hdf4) - build_bin_test(tst_chunk_hdf4) - add_sh_test(nc_test4 run_chunk_hdf4) - add_bin_test(nc_test4 tst_h4_lendian) - add_sh_test(nc_test4 tst_hdf4_read_var) - SET_TESTS_PROPERTIES(nc_test4_tst_hdf4_read_var PROPERTIES DEPENDS tst_interops2) -ENDIF() - IF(TEST_PARALLEL4) build_bin_test(tst_mpi_parallel) build_bin_test(tst_parallel) diff --git a/nc_test4/Makefile.am b/nc_test4/Makefile.am index 6423d780ec..417a0c6309 100644 --- a/nc_test4/Makefile.am +++ b/nc_test4/Makefile.am @@ -95,26 +95,6 @@ benchmarks: check ./run_bm_ar4.sh endif # BUILD_BENCHMARKS -# These are the tests for HDF4. -if USE_HDF4 -check_PROGRAMS += tst_interops2 tst_chunk_hdf4 tst_h4_lendian - -if BUILD_UTILITIES -# This test script depends on ncdump. -TESTS += tst_interops2 tst_formatx_hdf4.sh -tst_formatx_hdf4.log: tst_interops2.log -endif # BUILD_UTILITIES - -TESTS += run_chunk_hdf4.sh tst_h4_lendian -if USE_HDF4_FILE_TESTS -check_PROGRAMS += tst_interops3 -TESTS += run_get_hdf4_files.sh tst_hdf4_read_var.sh - -tst_hdf4_read_var.log: tst_interops2.log - -endif # USE_HDF4_FILE_TESTS -endif # USE_HDF4 - # Szip Tests (requires ncdump) if USE_SZIP if BUILD_UTILITIES @@ -143,17 +123,15 @@ EXTRA_DIST = run_par_test.sh run_bm.sh run_bm_test1.sh \ run_bm_test2.sh run_bm_radar_2D.sh run_bm_radar_2D_compression1.sh \ run_par_bm_test.sh run_bm_elena.sh run_par_bm_radar_2D.sh \ run_bm_radar_2D_endianness1.sh run_tst_chunks.sh ref_chunks1.cdl \ -ref_chunks2.cdl run_get_hdf4_files.sh run_bm_ar4.sh \ -ref_tst_compounds.nc ref_tst_xplatform2_1.nc ref_tst_xplatform2_2.nc \ -ref_tst_dims.nc ref_tst_interops4.nc run_get_knmi_files.sh \ -CMakeLists.txt run_grp_rename.sh tst_formatx_hdf4.sh \ -run_chunk_hdf4.sh tst_h5_endians.c tst_h4_lendian.c \ -tst_atts_string_rewrite.c tst_put_vars_two_unlim_dim.c \ -tst_empty_vlen_unlim.c run_empty_vlen_test.sh ref_hdf5_compat1.nc \ -ref_hdf5_compat2.nc ref_hdf5_compat3.nc tst_misc.sh tdset.h5 \ -tst_hdf4_read_var.sh ref_contiguous.hdf4 ref_chunked.hdf4 tst_szip.sh \ -ref_szip.h5 ref_szip.cdl tst_filter.sh bzip2.cdl filtered.cdl \ -unfiltered.cdl ref_bzip2.c findplugin.in +ref_chunks2.cdl run_bm_ar4.sh ref_tst_compounds.nc \ +ref_tst_xplatform2_1.nc ref_tst_xplatform2_2.nc ref_tst_dims.nc \ +ref_tst_interops4.nc run_get_knmi_files.sh CMakeLists.txt \ +run_grp_rename.sh tst_h5_endians.c tst_atts_string_rewrite.c \ +tst_put_vars_two_unlim_dim.c tst_empty_vlen_unlim.c \ +run_empty_vlen_test.sh ref_hdf5_compat1.nc ref_hdf5_compat2.nc \ +ref_hdf5_compat3.nc tst_misc.sh tdset.h5 tst_szip.sh ref_szip.h5 \ +ref_szip.cdl tst_filter.sh bzip2.cdl filtered.cdl unfiltered.cdl \ +ref_bzip2.c findplugin.in CLEANFILES = tst_mpi_parallel.bin cdm_sea_soundings.nc bm_chunking.nc \ bm_radar.nc bm_radar1.nc radar_3d_compression_test.txt \ @@ -171,12 +149,4 @@ szip_dump.cdl DISTCLEANFILES = findplugin.sh -if USE_HDF4_FILE_TESTS -DISTCLEANFILES += AMSR_E_L2_Rain_V10_200905312326_A.hdf \ -AMSR_E_L3_DailyLand_V06_20020619.hdf \ -MYD29.A2009152.0000.005.2009153124331.hdf \ -MYD29.A2002185.0000.005.2007160150627.hdf \ -MOD29.A2000055.0005.005.2006267200024.hdf -endif # HDF4_FILE_TESTS - SUBDIRS=hdf5plugins diff --git a/nc_test4/run_chunk_hdf4.sh b/nc_test4/run_chunk_hdf4.sh deleted file mode 100755 index 5debe5fcfd..0000000000 --- a/nc_test4/run_chunk_hdf4.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/sh -# Run test_chunk_hdf4 passing ${srcdir} - - - -if test "x$srcdir" = x ; then srcdir=`pwd`; fi -. ../test_common.sh - -set -e - -echo "" -echo "*** Testing hdf4 chunking..." - -if test "x${srcdir}" = "x" ; then -srcdir="." -fi - -if ./tst_chunk_hdf4 ; then - echo "***SUCCESS!! tst_chunk_hdf4" -else - RES=$? - echo "***FAIL: tst_chunk_hdf4" - exit $RES -fi - -exit 0 diff --git a/nc_test4/tst_formatx_hdf4.sh b/nc_test4/tst_formatx_hdf4.sh deleted file mode 100755 index f008fe3e1d..0000000000 --- a/nc_test4/tst_formatx_hdf4.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/bin/sh -# This shell script tests the output several previous tests. -# Ed Hartnett - -if test "x$srcdir" = x ; then srcdir=`pwd`; fi -. ../test_common.sh - -FILE=tst_interops2.h4 - -ECODE=0 - -echo "" -echo "*** Testing extended file format output." -set -e - -echo "Creating HDF4 file" -${execdir}/tst_interops2 - -echo "Test extended format output for a HDF4 file" -rm -f tmp_tst_formatx_hdf4 -${NCDUMP} -K $FILE >tmp_tst_formatx_hdf4 -if ! fgrep 'HDF4 mode=00001000'