Merge branch 'master' into ejh_all_tests

This commit is contained in:
Ed Hartnett 2018-05-30 17:39:19 -06:00 committed by GitHub
commit 112a200cc9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 142 additions and 21 deletions

6
cf
View File

@ -1,6 +1,6 @@
#!/bin/bash
#NB=1
DB=1
#DB=1
#X=-x
#FAST=1
@ -124,8 +124,8 @@ FLAGS="$FLAGS --disable-parallel4"
fi
if test "x${DB}" = x1 ; then
#FLAGS="$FLAGS --disable-shared --enable-static"
FLAGS="$FLAGS --enable-static"
FLAGS="$FLAGS --disable-shared --enable-static"
#FLAGS="$FLAGS --enable-static"
else
FLAGS="$FLAGS --enable-shared"
fi

View File

@ -2590,6 +2590,11 @@ nc4_open_file(const char *path, int mode, void* parameters, NC *nc)
#ifdef HDF5_HAS_COLL_METADATA_OPS
H5Pset_all_coll_metadata_ops(fapl_id, 1 );
#endif
/* Does the mode specify that this file is read-only? */
if ((mode & NC_WRITE) == 0)
nc4_info->no_write = NC_TRUE;
if(nc4_info->mem.inmemory) {
/* validate */
if(nc4_info->mem.memio.size == 0 || nc4_info->mem.memio.memory == NULL)
@ -2600,10 +2605,6 @@ nc4_open_file(const char *path, int mode, void* parameters, NC *nc)
} else if ((nc4_info->hdfid = H5Fopen(path, flags, fapl_id)) < 0)
BAIL(NC_EHDFERR);
/* Does the mode specify that this file is read-only? */
if ((mode & NC_WRITE) == 0)
nc4_info->no_write = NC_TRUE;
/* Now read in all the metadata. Some types and dimscale
* information may be difficult to resolve here, if, for example, a
* dataset of user-defined type is encountered before the

View File

@ -34,7 +34,7 @@
#define HDrealloc(M,Z) realloc(M,Z)
#endif /* HDrealloc */
extern int NC4_image_init(NC_HDF5_FILE_INFO_T* h5);
extern hid_t NC4_image_init(NC_HDF5_FILE_INFO_T* h5);
int
NC4_open_image_file(NC_HDF5_FILE_INFO_T* h5)

View File

@ -96,23 +96,32 @@
#endif
#undef TRACE
#define CATCH
#ifdef TRACE
#define CATCH
#endif
#ifdef TRACE
#include <stdarg.h>
static void trace(const char* fcn, void* _udata, ...);
static void traceend(const char* fcn, void* _udata);
static void tracefail(const char* fcn);
/* In case we do not have variadic macros */
#define TRACE1(fcn,udata,x1) trace(fcn,udata,x1)
#define TRACE2(fcn,udata,x1,x2) trace(fcn,udata,x1,x2)
#define TRACE3(fcn,udata,x1,x2,x3) trace(fcn,udata,x1,x2,x3)
#define TRACEEND(fcn,udata) traceend(fcn,udata);
#define TRACEFAIL(fcn) tracefail(fcn)
#else /*!TRACE*/
#define TRACE1(fcn,udata,x1)
#define TRACE2(fcn,udata,x1,x2)
#define TRACE3(fcn,udata,x1,x2,x3)
#define TRACEEND(fcn,udata)
#endif
#ifdef CATCH
static void tracefail(const char* fcn);
#define TRACEFAIL(fcn) tracefail(fcn)
#else
#define TRACEFAIL(fcn)
#endif
@ -667,7 +676,7 @@ out:
*
*-------------------------------------------------------------------------
*/
int
hid_t
NC4_image_init(NC_HDF5_FILE_INFO_T* h5)
{
hid_t fapl = -1, file_id = -1; /* HDF5 identifiers */
@ -721,6 +730,7 @@ NC4_image_init(NC_HDF5_FILE_INFO_T* h5)
/* Set callbacks for file image ops ONLY if the file image is NOT copied */
if (flags & H5LT_FILE_IMAGE_DONT_COPY)
// if (0)
{
H5LT_file_image_ud_t *udata; /* Pointer to udata structure */
@ -847,11 +857,13 @@ static void traceend(const char* fcn, void* _udata)
fflush(stderr);
}
#endif /*TRACE*/
#ifdef CATCH
static void
tracefail(const char* fcn)
{
fprintf(stderr,"fail: %s",fcn);
fflush(stderr);
}
#endif /*TRACE*/
#endif /*CATCH*/

View File

@ -52,7 +52,7 @@ IF(LARGE_FILE_TESTS)
ENDIF()
SET(TESTFILES ${TESTFILES} tst_diskless tst_diskless3 tst_diskless4 tst_diskless5 tst_inmemory)
SET(TESTFILES ${TESTFILES} tst_diskless tst_diskless3 tst_diskless4 tst_diskless5 tst_inmemory tst_open_mem)
IF(USE_NETCDF4)
SET(TESTFILES ${TESTFILES} tst_diskless2)
ENDIF()

View File

@ -1,29 +1,40 @@
# Test c output
T=tst_diskless
T=tst_open_mem
#ARGS=t
#H58=8
H510=10
#ARGS=f03_1820.nc
#CMD=valgrind --leak-check=full
#CMD=export NETCDF_LOG_LEVEL=5 ;gdb --args
CMD=gdb --args
#CMD=env HDF5_DEBUG=trace
#PAR=1
ifdef H58
H5L=/usr/local
endif
ifdef H510
H5L=/opt
endif
CFLAGS=-Wall -Wno-unused-variable -Wno-unused-function -g -O0 -I.. -I../include
ifdef PAR
CC=mpicc
#CC=/usr/local/bin/mpicc
LDFLAGS=../liblib/.libs/libnetcdf.a -L/usr/local/lib -lhdf5_hl -lhdf5 -lz -ldl -lcurl -lpnetcdf -lmpich -lm
LDFLAGS=../liblib/.libs/libnetcdf.a -L${H5L}/lib -lhdf5_hl -lhdf5 -lz -ldl -lcurl -lpnetcdf -lmpich -lm
else
CC=gcc
#LDFLAGS=../liblib/.libs/libnetcdf.a -L/usr/local/lib -lhdf5_hl -lhdf5 -lz -lm -lcurl
LDFLAGS=../liblib/.libs/libnetcdf.a -L/usr/local/lib -lhdf5_hl -lhdf5 -lz -ldl -lm -lcurl
#LDFLAGS=../liblib/.libs/libnetcdf.a -L${H5L}/lib -lhdf5_hl -lhdf5 -lz -lm -lcurl
LDFLAGS=../liblib/.libs/libnetcdf.a -L${H5L}/lib -lhdf5_hl -lhdf5 -lz -ldl -lm -lcurl
endif
# cd .. ; ${MAKE} all
LLP=/usr/local/lib:${LD_LIBRARY_PATH}
LLP=${H5L}/lib:${LD_LIBRARY_PATH}
all:: cmp
export LD_LIBRARY_PATH=${LLP}; export CFLAGS; export LDFLAGS; \

View File

@ -53,7 +53,7 @@ endif
check_PROGRAMS = $(TESTPROGRAMS)
# Build Diskless test helpers
check_PROGRAMS += tst_diskless tst_diskless3 tst_diskless4 tst_diskless5 tst_inmemory
check_PROGRAMS += tst_diskless tst_diskless3 tst_diskless4 tst_diskless5 tst_inmemory tst_open_mem
if USE_NETCDF4
check_PROGRAMS += tst_diskless2
endif
@ -83,6 +83,7 @@ endif
EXTRA_DIST = test_get.m4 test_put.m4 run_diskless.sh run_diskless2.sh \
run_diskless5.sh run_mmap.sh run_pnetcdf_test.sh test_read.m4 \
test_write.m4 ref_tst_diskless2.cdl tst_diskless5.cdl run_inmemory.sh \
f03tst_open_mem.nc \
CMakeLists.txt
# These files are created by the tests.

BIN
nc_test/f03tst_open_mem.nc Normal file

Binary file not shown.

View File

@ -16,6 +16,9 @@ CREATE3=tst_inmemory3_create
FILE4=tst_inmemory4
CREATE4=tst_inmemory4_create
# For tst_open_mem
OMEMFILE=f03tst_open_mem.nc
echo ""
echo "*** Testing in-memory operations"
@ -25,6 +28,9 @@ HASNC4=`${top_builddir}/nc-config --has-nc4`
if ! ${execdir}/tst_inmemory; then
echo "FAIL: tst.inmemory"
fi
if ! ${execdir}/tst_open_mem ${srcdir}/${OMEMFILE}; then
echo "FAIL: tst_open_mem"
fi
echo "**** Test ncdump of the resulting inmemory data"
${NCDUMP} -n "${FILE3}" ${FILE3}.nc > ${FILE3}.cdl

90
nc_test/tst_open_mem.c Normal file
View File

@ -0,0 +1,90 @@
#include <config.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include "netcdf.h"
#include "netcdf_mem.h"
#include "ncbytes.h"
#include "nc_tests.h"
#include "err_macros.h"
#ifdef USE_NETCDF4
#include <hdf5.h>
extern int H5Eprint1(FILE * stream);
#endif
static int
readfile(const char* path, NC_memio* memio)
{
int status = NC_NOERR;
FILE* f = NULL;
size_t filesize = 0;
size_t count = 0;
char* memory = NULL;
char* p = NULL;
/* Open the file for reading */
#ifdef _MSC_VER
f = fopen(path,"rb");
#else
f = fopen(path,"r");
#endif
if(f == NULL)
{status = errno; goto done;}
/* get current filesize */
if(fseek(f,0,SEEK_END) < 0)
{status = errno; goto done;}
filesize = (size_t)ftell(f);
/* allocate memory */
memory = malloc((size_t)filesize);
if(memory == NULL)
{status = NC_ENOMEM; goto done;}
/* move pointer back to beginning of file */
rewind(f);
count = filesize;
p = memory;
while(count > 0) {
size_t actual;
actual = fread(p,1,count,f);
if(actual == 0 || ferror(f))
{status = NC_EIO; goto done;}
count -= actual;
p += actual;
}
if(memio) {
memio->size = (size_t)filesize;
memio->memory = memory;
}
done:
if(status != NC_NOERR && memory != NULL)
free(memory);
if(f != NULL) fclose(f);
return status;
}
int
main(int argc, char** argv)
{
int retval = NC_NOERR;
int ncid;
NC_memio mem;
char* path = "f03tst_open_mem.nc";
if(argc > 1)
path = argv[1];
if((retval=readfile(path,&mem)))
goto exit;
if((retval = nc_open_mem("mem", NC_INMEMORY|NC_NETCDF4, mem.size, mem.memory, &ncid)))
goto exit;
if((retval = nc_close(ncid)))
goto exit;
return 0;
exit:
fprintf(stderr,"retval=%d\n",retval);
return 1;
}