Merge branch 'master' into ejh_fill_test

This commit is contained in:
Ed Hartnett 2018-04-19 15:41:38 -06:00 committed by GitHub
commit f36ae96ee4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 172 additions and 15 deletions

View File

@ -156,10 +156,10 @@ dumpdata1(nc_type nctype, size_t index, char* data)
fprintf(stdout,"'%c' %hhd",data[index],data[index]);
break;
case NC_BYTE:
fprintf(stdout,"%hdB",((signed char*)data)[index]);
fprintf(stdout,"%hhdB",((signed char*)data)[index]);
break;
case NC_UBYTE:
fprintf(stdout,"%huB",((unsigned char*)data)[index]);
fprintf(stdout,"%hhuB",((unsigned char*)data)[index]);
break;
case NC_SHORT:
fprintf(stdout,"%hdS",((short*)data)[index]);

View File

@ -525,7 +525,7 @@ parseSequence(NCD4parser* parser, NCD4node* container, ezxml_t xml, NCD4node** n
vlentype->basetype = var->basetype;
/* Use name <fqnname>_t */
strncpy(name,fqnname,sizeof(name));
strlcat(name,"_t",sizeof(name));
strncat(name,"_t", sizeof(name) - strlen(name) - 1);
SETNAME(vlentype,name);
/* Set the basetype */
var->basetype = vlentype;
@ -540,7 +540,7 @@ parseSequence(NCD4parser* parser, NCD4node* container, ezxml_t xml, NCD4node** n
classify(group,structtype);
/* Use name <fqnname>_base */
strncpy(name,fqnname,sizeof(name));
strlcat(name,"_base",sizeof(name));
strncat(name,"_base", sizeof(name) - strlen(name) - 1);
SETNAME(structtype,name);
/* Parse Fields into type */
if((ret = parseFields(parser,structtype,xml))) goto done;
@ -549,7 +549,7 @@ parseSequence(NCD4parser* parser, NCD4node* container, ezxml_t xml, NCD4node** n
classify(group,vlentype);
/* Use name <xname>_t */
strncpy(name,fqnname,sizeof(name));
strlcat(name,"_t",sizeof(name));
strncat(name,"_t", sizeof(name) - strlen(name) - 1);
SETNAME(vlentype,name);
vlentype->basetype = structtype;
/* Set the basetype */

View File

@ -328,6 +328,101 @@ NCD4_entityescape(const char* s)
return escaped;
}
int
NCD4_readfile(const char* filename, NCbytes* content)
{
int ret = NC_NOERR;
FILE* stream = NULL;
char part[1024];
stream = fopen(filename,"r");
if(stream == NULL) {ret=errno; goto done;}
for(;;) {
size_t count = fread(part, 1, sizeof(part), stream);
if(count <= 0) break;
ncbytesappendn(content,part,count);
if(ferror(stream)) {ret = NC_EIO; goto done;}
if(feof(stream)) break;
}
ncbytesnull(content);
done:
if(stream) fclose(stream);
return ret;
}
/**
Wrap mktmp and return the generated name
*/
int
NCD4_mktmp(const char* base, char** tmpnamep)
{
int fd;
char tmp[NC_MAX_PATH];
#ifdef HAVE_MKSTEMP
mode_t mask;
#endif
strncpy(tmp,base,sizeof(tmp));
#ifdef HAVE_MKSTEMP
strncat(tmp,"XXXXXX", sizeof(tmp) - strlen(tmp) - 1);
/* Note Potential problem: old versions of this function
leave the file in mode 0666 instead of 0600 */
mask=umask(0077);
fd = mkstemp(tmp);
(void)umask(mask);
#else /* !HAVE_MKSTEMP */
/* Need to simulate by using some kind of pseudo-random number */
{
int rno = rand();
char spid[7];
if(rno < 0) rno = -rno;
snprintf(spid,sizeof(spid),"%06d",rno);
strncat(tmp,spid,sizeof(tmp));
#if defined(_WIN32) || defined(_WIN64)
fd=open(tmp,O_RDWR|O_BINARY|O_CREAT, _S_IREAD|_S_IWRITE);
# else
fd=open(tmp,O_RDWR|O_CREAT|O_EXCL, S_IRWXU);
# endif
}
#endif /* !HAVE_MKSTEMP */
if(fd < 0) {
nclog(NCLOGERR, "Could not create temp file: %s",tmp);
return THROW(NC_EPERM);
} else
close(fd);
if(tmpnamep) *tmpnamep = strdup(tmp);
return THROW(NC_NOERR);
}
void
NCD4_hostport(NCURI* uri, char* space, size_t len)
{
if(space != NULL && len > 0) {
space[0] = '\0'; /* so we can use strncat */
if(uri->host != NULL) {
strncat(space,uri->host,len);
if(uri->port != NULL) {
strncat(space,":",len);
strncat(space,uri->port,len);
}
}
}
}
void
NCD4_userpwd(NCURI* uri, char* space, size_t len)
{
if(space != NULL && len > 0) {
space[0] = '\0'; /* so we can use strncat */
if(uri->user != NULL && uri->password != NULL) {
strncat(space,uri->user,len);
strncat(space,":",len);
strncat(space,uri->password,len);
}
}
}
#ifdef BLOB
void
NCD4_saveblob(NCD4meta* meta, void* mem)

View File

@ -12,7 +12,7 @@ See \ref copyright file for copying and redistribution conditions.
#include <stdio.h>
#include <stdarg.h>
#include "netcdf.h"
#include "math.h"
#include <math.h>
/** \defgroup v2_api The Version 2 API

View File

@ -158,6 +158,7 @@ NC_begins(NC3_INFO* ncp,
size_t ii, j;
int sizeof_off_t;
off_t index = 0;
off_t old_ncp_begin_var;
NC_var **vpp;
NC_var *last = NULL;
NC_var *first_var = NULL; /* first "non-record" var */
@ -179,6 +180,8 @@ NC_begins(NC3_INFO* ncp,
if(ncp->vars.nelems == 0)
return NC_NOERR;
old_ncp_begin_var = ncp->begin_var;
/* only (re)calculate begin_var if there is not sufficient space in header
or start of non-record variables is not aligned as requested by valign */
if (ncp->begin_var < ncp->xsz + h_minfree ||
@ -217,6 +220,7 @@ fprintf(stderr, " VAR %d %s: %ld\n", ii, (*vpp)->name->cp, (long)index);
#endif
if( sizeof_off_t == 4 && (index > X_OFF_MAX || index < 0) )
{
ncp->begin_var = old_ncp_begin_var;
return NC_EVARSIZE;
}
(*vpp)->begin = index;
@ -287,6 +291,7 @@ fprintf(stderr, " REC %d %s: %ld\n", ii, (*vpp)->name->cp, (long)index);
#endif
if( sizeof_off_t == 4 && (index > X_OFF_MAX || index < 0) )
{
ncp->begin_var = old_ncp_begin_var;
return NC_EVARSIZE;
}
(*vpp)->begin = index;
@ -309,6 +314,7 @@ fprintf(stderr, " REC %d %s: %ld\n", ii, (*vpp)->name->cp, (long)index);
#if SIZEOF_OFF_T == SIZEOF_SIZE_T && SIZEOF_SIZE_T == 4
if( ncp->recsize > X_UINT_MAX - (*vpp)->len )
{
ncp->begin_var = old_ncp_begin_var;
return NC_EVARSIZE;
}
#endif

View File

@ -997,7 +997,11 @@ nc4_create_file(const char *path, int cmode, MPI_Comm comm, MPI_Info info,
#endif /* USE_PARALLEL4 */
#ifdef HDF5_HAS_LIBVER_BOUNDS
#if H5_VERSION_GE(1,10,2)
if (H5Pset_libver_bounds(fapl_id, H5F_LIBVER_EARLIEST, H5F_LIBVER_V18) < 0)
#else
if (H5Pset_libver_bounds(fapl_id, H5F_LIBVER_EARLIEST, H5F_LIBVER_LATEST) < 0)
#endif
BAIL(NC_EHDFERR);
#endif

View File

@ -30,7 +30,7 @@ TARGET_LINK_LIBRARIES(nc_test
)
# Some extra stand-alone tests
SET(TESTS t_nc tst_small tst_misc tst_norm tst_names tst_nofill tst_nofill2 tst_nofill3 tst_meta tst_inq_type tst_utf8_validate tst_utf8_phrases tst_global_fillval tst_max_var_dims tst_formats tst_def_var_fill)
SET(TESTS t_nc tst_small tst_misc tst_norm tst_names tst_nofill tst_nofill2 tst_nofill3 tst_meta tst_inq_type tst_utf8_validate tst_utf8_phrases tst_global_fillval tst_max_var_dims tst_formats tst_def_var_fill tst_err_enddef)
IF(NOT HAVE_BASH)
SET(TESTS ${TESTS} tst_atts3)

View File

@ -19,7 +19,7 @@ TEST_EXTENSIONS = .sh
TESTPROGRAMS = t_nc tst_small nc_test tst_misc tst_norm tst_names \
tst_nofill tst_nofill2 tst_nofill3 tst_atts3 tst_meta tst_inq_type \
tst_utf8_validate tst_utf8_phrases tst_global_fillval \
tst_max_var_dims tst_formats tst_def_var_fill
tst_max_var_dims tst_formats tst_def_var_fill tst_err_enddef
if USE_NETCDF4
TESTPROGRAMS += tst_atts tst_put_vars tst_elatefill

52
nc_test/tst_err_enddef.c Normal file
View File

@ -0,0 +1,52 @@
#include <stdio.h>
#include <netcdf.h>
#define CHECK_ERR { \
if (err != NC_NOERR) { \
nerrs++; \
printf("Error at line %d in %s: (%s)\n", \
__LINE__,__FILE__,nc_strerror(err)); \
} \
}
#define EXP_ERR(exp) { \
if (err != exp) { \
nerrs++; \
printf("Error at line %d in %s: expecting %s but got %s\n", \
__LINE__,__FILE__,nc_strerror(exp), nc_strerror(err)); \
} \
}
int main(int argc, char** argv)
{
char *filename="tst_err_enddef.nc";
int err, nerrs=0, ncid, cmode, varid, dimid[3];
if (argc == 2) filename = argv[1];
printf("*** TESTING error code returned from nc__enddef and nc_close ");
cmode = NC_CLOBBER;
err = nc_create(filename, cmode, &ncid); CHECK_ERR
err = nc_set_fill(ncid, NC_NOFILL, NULL); CHECK_ERR
err = nc_def_dim(ncid, "X", 5, &dimid[0]); CHECK_ERR
err = nc_def_dim(ncid, "YY", 32000, &dimid[1]); CHECK_ERR
err = nc_def_dim(ncid, "XX", 32000, &dimid[2]); CHECK_ERR
err = nc_def_var(ncid, "var", NC_INT, 1, dimid, &varid); CHECK_ERR
err = nc_def_var(ncid, "var_big", NC_FLOAT, 2, dimid+1, &varid); CHECK_ERR
/* make the file header size larger than 2 GiB */
err = nc__enddef(ncid, 2147483648LL, 1, 1, 1);
EXP_ERR(NC_EVARSIZE)
/* the above error keeps the program in define mode, thus close will
* call enddef again, but this time no error is expected
*/
err = nc_close(ncid); CHECK_ERR
if (nerrs) printf(".... failed with %d errors\n",nerrs);
else printf(".... pass\n");
return (nerrs > 0);
}

View File

@ -10,7 +10,7 @@
#include <nc_tests.h>
#include "err_macros.h"
#include "netcdf.h"
#include "math.h"
#include <math.h>
#define FILE_NAME "tst_converts2.nc"
#define VAR_NAME "Monkey"

View File

@ -1,18 +1,19 @@
#!/bin/sh
if test "x$srcdir" = x ; then srcdir=`pwd`; fi
if test "x$srcdir" = x ; then srcdir=`pwd`; fi
. ../test_common.sh
set -e
set -x
echo ""
EXIT=0
NCF=${srcdir}/ncdump/nc4_fileinfo.nc
HDF=${srcdir}/ncdump/hdf5_fileinfo.hdf
NF=${srcdir}/ncdump/ref_tst_compounds4.nc
NCF=${top_srcdir}/ncdump/nc4_fileinfo.nc
HDF=${top_srcdir}/ncdump/hdf5_fileinfo.hdf
NF=${top_srcdir}/ncdump/ref_tst_compounds4.nc
# Do a false negative test
# Do a false negative test
rm -f ./tmp_tst_fileinfo
if $NCDUMP -s $NF | fgrep '_IsNetcdf4 = 0' > ./tmp_tst_fileinfo ; then
echo "Pass: False negative for file: $NF"
@ -42,4 +43,3 @@ rm -f $NCF
rm -f $HDF
exit $EXIT