Fix cmake X mmap

supercede PR: https://github.com/Unidata/netcdf-c/pull/1384

Since we have an mmap user, undeprecate it and make sure
it works. Other changes:

* fix test cases to work with make -j
* fix exposed ncgen error.
This commit is contained in:
Dennis Heimbigner 2019-04-19 20:32:26 -06:00
parent 48cc56ea38
commit c9d16d82d6
19 changed files with 352 additions and 158 deletions

View File

@ -12,7 +12,7 @@ services:
env:
matrix:
# Ubuntu
- DOCKIMG=unidata/nctests:serial USECMAKE=TRUE USEAC=TRUE DISTCHECK=TRUE USE_CC=gcc AC_COPTS='CFLAGS=-fsigned-char --disable-netcdf-4 --disable-dap-remote-tests --enable-cdf5' COPTS='-DENABLE_NETCDF_4=OFF -DCMAKE_C_FLAGS=-fsigned-char -DENABLE_DAP_REMOTE_TESTS=OFF -DENABLE_CDF5=TRUE' USECP=FALSE CURHOST=docker-gcc-x64-signed TESTFILTER=FALSE
- DOCKIMG=unidata/nctests:serial USECMAKE=TRUE USEAC=TRUE DISTCHECK=TRUE USE_CC=gcc AC_COPTS='CFLAGS=-fsigned-char --disable-netcdf-4 --disable-dap-remote-tests --enable-cdf5 --enable-byterange' COPTS='-DENABLE_NETCDF_4=OFF -DCMAKE_C_FLAGS=-fsigned-char -DENABLE_DAP_REMOTE_TESTS=OFF -DENABLE_CDF5=TRUE -DENABLE_BYTERANGE=TRUE' USECP=FALSE CURHOST=docker-gcc-x64-signed TESTFILTER=FALSE
- DOCKIMG=unidata/nctests:serial32 USECMAKE=TRUE USEAC=TRUE DISTCHECK=TRUE USE_CC=gcc AC_COPTS='CFLAGS=-fsigned-char --disable-netcdf-4 --disable-dap-remote-tests' COPTS='-DENABLE_NETCDF_4=OFF -DCMAKE_C_FLAGS=-fsigned-char -DENABLE_DAP_REMOTE_TESTS=OFF -DENABLE_CDF5=OFF' USECP=FALSE CURHOST=docker-gcc-x86-signed TESTFILTER=FALSE

View File

@ -765,69 +765,65 @@ IF(USE_HDF5 OR ENABLE_NETCDF_4)
ENDIF(USE_HDF5 OR ENABLE_NETCDF_4)
# See if we have libcurl
FIND_PACKAGE(CURL)
ADD_DEFINITIONS(-DCURL_STATICLIB=1)
INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS})
# Check to see if CURLOPT_USERNAME is defined.
# It is present starting version 7.19.1.
CHECK_C_SOURCE_COMPILES("
#include <curl/curl.h>
int main() {int x = CURLOPT_USERNAME;}" HAVE_CURLOPT_USERNAME)
# Check to see if CURLOPT_PASSWORD is defined.
# It is present starting version 7.19.1.
CHECK_C_SOURCE_COMPILES("
#include <curl/curl.h>
int main() {int x = CURLOPT_PASSWORD;}" HAVE_CURLOPT_PASSWORD)
# Check to see if CURLOPT_KEYPASSWD is defined.
# It is present starting version 7.16.4.
CHECK_C_SOURCE_COMPILES("
#include <curl/curl.h>
int main() {int x = CURLOPT_KEYPASSWD;}" HAVE_CURLOPT_KEYPASSWD)
# Check to see if CURLINFO_RESPONSE_CODE is defined.
# It showed up in curl 7.10.7.
CHECK_C_SOURCE_COMPILES("
#include <curl/curl.h>
int main() {int x = CURLINFO_RESPONSE_CODE;}" HAVE_CURLINFO_RESPONSE_CODE)
# Check to see if CURLINFO_HTTP_CONNECTCODE is defined.
# It showed up in curl 7.10.7.
CHECK_C_SOURCE_COMPILES("
#include <curl/curl.h>
int main() {int x = CURLINFO_HTTP_CONNECTCODE;}" HAVE_CURLINFO_HTTP_CONNECTCODE)
# Check to see if CURLOPT_BUFFERSIZE is defined.
# It is present starting version 7.59
CHECK_C_SOURCE_COMPILES("
#include <curl/curl.h>
int main() {int x = CURLOPT_BUFFERSIZE;}" HAVE_CURLOPT_BUFFERSIZE)
# Check to see if CURLOPT_TCP_KEEPALIVE is defined.
# It is present starting version 7.25
CHECK_C_SOURCE_COMPILES("
#include <curl/curl.h>
int main() {int x = CURLOPT_TCP_KEEPALIVE;}" HAVE_CURLOPT_KEEPALIVE)
# Option to Build DAP2+DAP4 Clients
OPTION(ENABLE_DAP "Enable DAP2 and DAP4 Client." ON)
IF(ENABLE_DAP)
SET(USE_DAP ON CACHE BOOL "")
SET(ENABLE_DAP2 ON CACHE BOOL "")
IF(ENABLE_NETCDF_4)
SET(ENABLE_DAP4 ON CACHE BOOL "")
ELSE(ENABLE_NETCDF_4)
SET(ENABLE_DAP4 OFF CACHE BOOL "")
ENDIF(ENABLE_NETCDF_4)
FIND_PACKAGE(CURL)
IF(NOT CURL_LIBRARY)
MESSAGE(FATAL_ERROR "DAP Support specified, CURL libraries are not found.")
ENDIF()
ADD_DEFINITIONS(-DCURL_STATICLIB=1)
INCLUDE_DIRECTORIES(${CURL_INCLUDE_DIRS})
# Check to see if CURLOPT_USERNAME is defined.
# It is present starting version 7.19.1.
CHECK_C_SOURCE_COMPILES("
#include <curl/curl.h>
int main() {int x = CURLOPT_USERNAME;}" HAVE_CURLOPT_USERNAME)
# Check to see if CURLOPT_PASSWORD is defined.
# It is present starting version 7.19.1.
CHECK_C_SOURCE_COMPILES("
#include <curl/curl.h>
int main() {int x = CURLOPT_PASSWORD;}" HAVE_CURLOPT_PASSWORD)
# Check to see if CURLOPT_KEYPASSWD is defined.
# It is present starting version 7.16.4.
CHECK_C_SOURCE_COMPILES("
#include <curl/curl.h>
int main() {int x = CURLOPT_KEYPASSWD;}" HAVE_CURLOPT_KEYPASSWD)
# Check to see if CURLINFO_RESPONSE_CODE is defined.
# It showed up in curl 7.10.7.
CHECK_C_SOURCE_COMPILES("
#include <curl/curl.h>
int main() {int x = CURLINFO_RESPONSE_CODE;}" HAVE_CURLINFO_RESPONSE_CODE)
# Check to see if CURLINFO_HTTP_CONNECTCODE is defined.
# It showed up in curl 7.10.7.
CHECK_C_SOURCE_COMPILES("
#include <curl/curl.h>
int main() {int x = CURLINFO_HTTP_CONNECTCODE;}" HAVE_CURLINFO_HTTP_CONNECTCODE)
# Check to see if CURLOPT_BUFFERSIZE is defined.
# It is present starting version 7.59
CHECK_C_SOURCE_COMPILES("
#include <curl/curl.h>
int main() {int x = CURLOPT_BUFFERSIZE;}" HAVE_CURLOPT_BUFFERSIZE)
# Check to see if CURLOPT_TCP_KEEPALIVE is defined.
# It is present starting version 7.25
CHECK_C_SOURCE_COMPILES("
#include <curl/curl.h>
int main() {int x = CURLOPT_TCP_KEEPALIVE;}" HAVE_CURLOPT_KEEPALIVE)
ELSE()
SET(ENABLE_DAP2 OFF)
SET(ENABLE_DAP4 OFF)
@ -835,13 +831,14 @@ ENDIF()
# Option to support byte-range reading of remote datasets
OPTION(ENABLE_BYTERANGE "Enable byte-range access to remote datasets.." OFF)
IF(ENABLE_BYTERANGE)
FIND_PACKAGE(CURL)
IF(NOT CURL_LIBRARY)
IF(NOT CURL_LIBRARY)
IF(ENABLE_BYTERANGE)
MESSAGE(FATAL_ERROR "Byte-range support specified, CURL libraries are not found.")
SET(ENABLE_BYTERANGE OFF BOOL)
ELSE()
SET(ENABLE_BYTERANGE ON BOOL)
ENDIF()
IF(ENABLE_DAP2 OR ENABLE_DAP4)
MESSAGE(FATAL_ERROR "DAP support specified, CURL libraries are not found.")
ENDIF()
ENDIF()
@ -1421,16 +1418,21 @@ CHECK_FUNCTION_EXISTS(mremap HAVE_MREMAP)
CHECK_FUNCTION_EXISTS(fileno HAVE_FILENO)
# Check to see if MAP_ANONYMOUS is defined.
IF(MSVC)
MESSAGE(WARNING "mmap not supported under visual studio: disabling MMAP support.")
SET(ENABLE_MMAP OFF)
ELSE()
CHECK_C_SOURCE_COMPILES("
#include <sys/mmap.h>
#include <sys/mman.h>
int main() {int x = MAP_ANONYMOUS;}" HAVE_MAPANON)
IF(NOT HAVE_MMMAP OR NOT HAVE_MREMAP OR NOT HAVE_MAPANON)
MESSAGE(WARNING "mmap or mremap or MAP_ANONYMOUS not found: disabling MMAP support.")
IF(NOT HAVE_MMAP OR NOT HAVE_MAPANON)
MESSAGE(WARNING "mmap or MAP_ANONYMOUS not found: disabling MMAP support.")
SET(ENABLE_MMAP OFF)
ENDIF()
ENDIF()
IF(ENABLE_MMAP)
# Aliases
SET(BUILD_MMAP ON)
SET(USE_MMAP ON)
ENDIF(ENABLE_MMAP)

View File

@ -36,7 +36,7 @@ build: off
build_script:
- cmd: mkdir build
- cmd: cd build
- cmd: cmake .. -G "%CMAKE_GENERATOR%" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%INSTALL_LOC% -DENABLE_BASH_SCRIPT_TESTING=OFF -DENABLE_FILTER_TESTING=OFF
- cmd: cmake .. -G "%CMAKE_GENERATOR%" -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX=%INSTALL_LOC% -DENABLE_BASH_SCRIPT_TESTING=OFF -DENABLE_FILTER_TESTING=OFF -DENABLE_BYTERANGE=ON
- cmd: if errorlevel 1 exit 1
- cmd: cmake --build . --config Release -- /maxcpucount:4

View File

@ -347,7 +347,7 @@ AC_ARG_ENABLE([dap],
test "x$enable_dap" = xno || enable_dap=yes
AC_MSG_RESULT($enable_dap)
# We need curl for DAP.
# We need curl for DAP and byterange
AC_CHECK_LIB([curl],[curl_easy_setopt],[found_curl=yes],[found_curl=no])
if test "x$enable_dap" = "xyes" ; then
AC_SEARCH_LIBS([curl_easy_setopt],[curl curl.dll], [],
@ -846,10 +846,15 @@ AC_ARG_ENABLE([mmap],
test "x$enable_mmap" = xyes || enable_mmap=no
AC_MSG_RESULT($enable_mmap)
# check for mmap and mremap availability before committing to use mmap
# check for mmap availability before committing to use mmap
have_mmap="$enable_mmap"
AC_CHECK_FUNCS([mmap],[],[have_mmap=no])
AC_CHECK_FUNCS([mremap],[],[have_mmap=no])
AC_CHECK_FUNCS([mmap],[havemmapfcn=yes],[havemmapfcn=no])
if test "x$havemmapfcn" = xno ; then
have_mmap=no
fi
# check for mremap availability; not strictly needed
AC_CHECK_FUNCS([mremap],[havemremapfcn=yes],[havemmapfcn=no])
# Check for MAP_ANONYMOUS
AC_COMPILE_IFELSE([AC_LANG_PROGRAM(

View File

@ -6,11 +6,11 @@ DB=1
#ANSI=1
#MEM=1
#NOTUIL=1
#FAST=1
FAST=1
#PROF=1
HDF5=1
DAP=1
#HDF5=1
#DAP=1
#SZIP=1
#HDF4=1
#PNETCDF=1
@ -91,18 +91,17 @@ LDFLAGS="$LDFLAGS -lsz -laec"
fi
export PKG_CONFIG_PATH=/usr/lib/pkgconfig
if test "x$DAP" = "x1" ; then
if curl-config --version >/dev/null ; then
TMP=`curl-config --cflags`
CPPFLAGS="$TMP $CPPFLAGS"
WH=`curl-config --prefix`
WH="${WH}/lib"
TMP=`curl-config --libs`
LDFLAGS="$TMP $LDFLAGS"
TMP=`curl-config --prefix`
LD_LIBRARY_PATH="$TMP/lib:$LD_LIBRARY_PATH"
LDFLAGS="$LDFLAGS -L$WH $TMP"
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$WH"
else
LDFLAGS="${LDFLAGS} -lcurl"
fi
fi
CXXFLAGS="$CPPFLAGS $CXXFLAGS"
@ -122,6 +121,7 @@ FLAGS="$FLAGS --enable-extreme-numbers"
FLAGS="$FLAGS --enable-logging"
#FLAGS="$FLAGS --disable-diskless"
FLAGS="$FLAGS --enable-mmap"
FLAGS="$FLAGS --enable-byterange"
#FLAGS="$FLAGS --with-udunits"
#FLAGS="$FLAGS --with-libcf"
#FLAGS="$FLAGS --enable-jna"

View File

@ -24,7 +24,7 @@ write it back out to disk when nc_close() is called.
of memory as if it were a netcdf file. At close, it is possible to ask
for the final contents of the memory chunk. Be warned that there is
some complexity to this as described below.
4. MMAP -- (deprecated) Tell the netcdf-c library to use the *mmap()* operating
4. MMAP -- Tell the netcdf-c library to use the *mmap()* operating
system functionality to access a file.
The first two capabilities are intertwined in the sense that the
@ -34,10 +34,7 @@ capability can be used independently of the *diskless*
capability.
The *mmap()* capability provides a capability similar to *diskless* but
using special capabilities of the underlying operating system. It turns out
that the mmap capability has seen no significant use, so its use is deprecated
and will be removed at some point in the future.
using special capabilities of the underlying operating system.
Note also that *diskless* and *inmemory* can be used for both
*netcdf-3* (classic) and *netcdf-4* (enhanced) data. The *mmap*
capability can only be used with *netcdf-3*.
@ -203,11 +200,9 @@ In this way, it is possible to avoid memory reallocation while still
allowing modifications to the file. You will still need to call
*nc_close_memio()* to obtain the size of the final, modified, file.
Enabling MMAP File Access (Deprecated) {#Enable_MMAP}
Enabling MMAP File Access {#Enable_MMAP}
--------------
The MMAP functionality is deprecated.
Some operating systems provide a capability called MMAP.
This allows disk files to automatically be mapped to chunks of memory.
It operates in a fashion somewhat similar to operating system virtual

View File

@ -420,6 +420,8 @@ static int
mmapio_pad_length(ncio* nciop, off_t length)
{
NCMMAPIO* mmapio;
int persist = 0;
if(nciop == NULL || nciop->pvt == NULL) return NC_EINVAL;
mmapio = (NCMMAPIO*)nciop->pvt;
@ -429,6 +431,9 @@ mmapio_pad_length(ncio* nciop, off_t length)
if(mmapio->locked > 0)
return NC_EDISKLESS;
if(mmapio->mapfd >= 0)
persist = 1;
if(length > mmapio->alloc) {
/* Realloc the allocated memory to a multiple of the pagesize*/
off_t newsize = length;
@ -450,12 +455,12 @@ mmapio_pad_length(ncio* nciop, off_t length)
newmem = (char*)mremap(mmapio->memory,mmapio->alloc,newsize,MREMAP_MAYMOVE);
if(newmem == NULL) return NC_ENOMEM;
#else
newmemory = (char*)mmap(NULL,newsize,
newmem = (char*)mmap(NULL,newsize,
persist?(PROT_READ|PROT_WRITE):(PROT_READ),
MAP_SHARED,
mmapio->mapfd,0);
if(newmem == NULL) return NC_ENOMEM;
memcpy(newmemory,mmapio->memory,mmapio->alloc);
memcpy(newmem,mmapio->memory,mmapio->alloc);
munmap(mmapio->memory,mmapio->alloc);
#endif

View File

@ -90,14 +90,17 @@ IF(BUILD_UTILITIES)
IF(LARGE_FILE_TESTS)
add_sh_test(nc_test run_diskless2)
ENDIF()
ENDIF(BUILD_UTILITIES)
IF(ENABLE_BYTERANGE)
build_bin_test_no_prefix(tst_byterange)
IF(BUILD_UTILITIES)
IF(ENABLE_BYTERANGE)
build_bin_test_no_prefix(tst_byterange)
add_sh_test(nc_test test_byterange)
ENDIF()
ENDIF()
IF(BUILD_MMAP)
add_sh_test(nc_test run_mmap)
ENDIF()
ENDIF(BUILD_UTILITIES)
# 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}/*.sh)
@ -114,5 +117,6 @@ ENDIF()
FILE(GLOB CUR_EXTRA_DIST RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.c ${CMAKE_CURRENT_SOURCE_DIR}/*.h ${CMAKE_CURRENT_SOURCE_DIR}/*.sh)
SET(CUR_EXTRA_DIST ${CUR_EXTRA_DIST} CMakeLists.txt Makefile.am)
SET(CUR_EXTRA_DIST ${CUR_EXTRA_DIST} test_get.m4 test_put.m4 test_read.m4 test_write.m4 ref_tst_diskless2.cdl tst_diskless5.cdl
ref_tst_diskless3_create.cdl ref_tst_diskless3_open.cdl
ref_tst_http_nc3.cdl ref_tst_http_nc4.cdl)
ADD_EXTRA_DIST("${CUR_EXTRA_DIST}")

View File

@ -6,6 +6,10 @@
# Ed Hartnett, Dennis Heimbigner, Ward Fisher
# Un comment to use a more verbose test driver
#SH_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver-verbose
#LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver-verbose
# Put together AM_CPPFLAGS and AM_LDFLAGS.
include $(top_srcdir)/lib_flags.am
AM_CPPFLAGS += -I$(top_srcdir)/libsrc
@ -82,6 +86,9 @@ endif
if ENABLE_BYTERANGE
TESTS += test_byterange.sh
endif
if BUILD_MMAP
TESTS += run_mmap.sh
endif
endif
if USE_PNETCDF
@ -92,14 +99,16 @@ endif
# we also include the original m4 files, plus test scripts data.
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 \
test_write.m4 ref_tst_diskless2.cdl tst_diskless5.cdl \
ref_tst_diskless3_create.cdl ref_tst_diskless3_open.cdl \
run_inmemory.sh run_mmap.sh \
f03tst_open_mem.nc \
test_byterange.sh ref_tst_http_nc3.cdl ref_tst_http_nc4.cdl \
test_byterange.sh ref_tst_http_nc3.cdl ref_tst_http_nc4.cdl \
CMakeLists.txt
# These files are created by the tests.
CLEANFILES = nc_test_*.nc tst_*.nc t_nc.nc large_files.nc \
quick_large_files.nc tst_diskless3_file.cdl tst_diskless3_memory.cdl \
quick_large_files.nc tst_diskless3_file.cdl \
tst_diskless4.cdl ref_tst_diskless4.cdl benchmark.nc \
tst_http_nc3.cdl tst_http_nc4.cdl

View File

@ -0,0 +1,32 @@
netcdf tst_mmap3 {
dimensions:
Time = UNLIMITED ; // (10 currently)
variables:
char Times(Time) ;
Times:a_97 = "a" ;
Times:a_98 = "b" ;
Times:a_99 = "c" ;
Times:a_100 = "d" ;
Times:a_101 = "e" ;
Times:a_102 = "f" ;
Times:a_103 = "g" ;
Times:a_104 = "h" ;
Times:a_105 = "i" ;
Times:a_106 = "j" ;
char var2(Time) ;
var2:a_97 = "a" ;
var2:a_98 = "b" ;
var2:a_99 = "c" ;
var2:a_100 = "d" ;
var2:a_101 = "e" ;
var2:a_102 = "f" ;
var2:a_103 = "g" ;
var2:a_104 = "h" ;
var2:a_105 = "i" ;
var2:a_106 = "j" ;
data:
Times = "abcdefghij" ;
var2 = "abcdefghij" ;
}

View File

@ -0,0 +1,37 @@
netcdf tst_mmap3 {
dimensions:
Time = UNLIMITED ; // (10 currently)
X = 30 ;
variables:
char Times(Time) ;
Times:a_97 = "a" ;
Times:a_98 = "b" ;
Times:a_99 = "c" ;
Times:a_100 = "d" ;
Times:a_101 = "e" ;
Times:a_102 = "f" ;
Times:a_103 = "g" ;
Times:a_104 = "h" ;
Times:a_105 = "i" ;
Times:a_106 = "j" ;
char var2(Time) ;
var2:a_97 = "a" ;
var2:a_98 = "b" ;
var2:a_99 = "c" ;
var2:a_100 = "d" ;
var2:a_101 = "e" ;
var2:a_102 = "f" ;
var2:a_103 = "g" ;
var2:a_104 = "h" ;
var2:a_105 = "i" ;
var2:a_106 = "j" ;
int var3(X) ;
data:
Times = "abcdefghij" ;
var2 = "abcdefghij" ;
var3 = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19,
20, 21, 22, 23, 24, 25, 26, 27, 28, 29 ;
}

View File

@ -82,6 +82,7 @@ if test -f $FILE2 ; then
else
echo "#### $FILE2 not created"
fi
exit
rm -f tmp1.cdl tmp2.cdl tmp1.nc tmp2.nc
if test "x$ok" = xyes ; then
@ -101,19 +102,19 @@ rm -f tst_diskless3_file.cdl tst_diskless3_memory.cdl
echo ""
echo "**** Create baseline cdl"
rm -f $FILE3
${execdir}/tst_diskless3 file
${execdir}/tst_diskless3 file file:$FILE3
${NCDUMP} $FILE3 >tst_diskless3_file.cdl
echo ""
echo "**** Create and modify file using diskless"
rm -f $FILE3
${execdir}/tst_diskless3 diskless persist
${execdir}/tst_diskless3 diskless persist file:$FILE3
${NCDUMP} $FILE3 >tst_diskless3_memory.cdl
# compare
diff tst_diskless3_file.cdl tst_diskless3_memory.cdl
# cleanup
rm -f $FILE3 tst_diskless3_file.cdl tst_diskless3_memory.cdl
rm -f $FILE1 $FILE2 $FILE3 tst_diskless3_file.cdl tst_diskless3_memory.cdl
exit 0

View File

@ -1,6 +1,5 @@
#!/bin/sh
if test "x$srcdir" = x ; then srcdir=`pwd`; fi
. ../test_common.sh
@ -11,9 +10,8 @@ CPU=`uname -p`
OS=`uname`
#Constants
FILE1=tst_diskless.nc
FILE2=tst_diskless2.nc
FILE3=tst_diskless3.nc
FILE1=tst_mmap1.nc
FILE3=tst_mmap3.nc
echo ""
echo "*** Testing create files with mmap"
@ -25,7 +23,7 @@ echo "PASS: create mmap netCDF classic file without persistence"
echo ""
echo "**** Test create mmap netCDF classic file with persistence"
rm -f $FILE1
${execdir}/tst_diskless mmap persist
${execdir}/tst_diskless mmap persist file:tst_mmap1.nc
if test -f $FILE1 ; then
echo "**** $FILE1 created"
# ${NCDUMP} $FILE1
@ -41,18 +39,26 @@ echo ""
echo "**** Testing open files with mmap"
# clear old files
rm -f tst_diskless3_file.cdl tst_diskless3_memory.cdl
rm -f tst_diskless3_mmap_create.cdl
rm -f tst_diskless3_mmap_open.cdl
echo ""
echo "**** Open and modify file using mmap"
echo "**** create and modify file using mmap"
rm -f $FILE3
${execdir}/tst_diskless3 diskless mmap
${NCDUMP} $FILE3 >tst_diskless3_memory.cdl
${execdir}/tst_diskless3 mmap persist create
${NCDUMP} $FILE3 >tst_diskless3_mmap_create.cdl
# compare
diff tst_diskless3_file.cdl tst_diskless3_memory.cdl
diff ${srcdir}/ref_tst_diskless3_create.cdl tst_diskless3_mmap_create.cdl
echo ""
echo "**** open and modify file using mmap"
${execdir}/tst_diskless3 mmap persist open
${NCDUMP} $FILE3 >tst_diskless3_mmap_open.cdl
# compare
diff ${srcdir}/ref_tst_diskless3_open.cdl tst_diskless3_mmap_open.cdl
# cleanup
rm -f $FILE3 tst_diskless3_file.cdl tst_diskless3_memory.cdl
rm -f $FILE1 $FILE3 tst_diskless3_mmap_create.cdl tst_diskless3_mmap_open.cdl
exit

View File

@ -98,6 +98,10 @@ main(int argc, char **argv)
else if(strcmp(argv[i],"persist")==0) persist=1;
else if(strcmp(argv[i],"mmap")==0) mmap=1;
else if(strcmp(argv[i],"diskless")==0) diskless=1;
else if(strncmp(argv[i],"file:",strlen("file:"))==0) {
filename = argv[i];
filename += strlen("file:");
}
/* ignore anything not recognized */
}

View File

@ -15,6 +15,9 @@ See \ref copyright file for more info.
#include <netcdf.h>
#define FILENAME "tst_diskless2.nc"
#define Clear ((unsigned char)0)
#define Cumulonimbus ((unsigned char)1)
#define Stratus ((unsigned char)2)
@ -98,7 +101,7 @@ main() {/* create tst_diskless2.nc */
int country_dims[RANK_country];
/* enter define mode */
stat = nc_create("tst_diskless2.nc", NC_DISKLESS|NC_WRITE|NC_CLOBBER|NC_NETCDF4, &ncid);
stat = nc_create(FILENAME, NC_DISKLESS|NC_WRITE|NC_CLOBBER|NC_NETCDF4|NC_PERSIST, &ncid);
check_err(stat,__LINE__,__FILE__);
root_grp = ncid;
stat = nc_def_grp(root_grp, "g", &g_grp);

View File

@ -7,42 +7,82 @@
$Id: tst_small.c,v 1.15 2008/10/20 01:48:08 ed Exp $
*/
#include <nc_tests.h>
#include "config.h"
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
#include <sys/types.h>
#include "netcdf.h"
#include "nc_tests.h"
#include "err_macros.h"
#include <netcdf.h>
/* Derived from tst_small.c */
#undef DBG
/* Test everything for classic using in-memory files */
/* Test extending an existing file */
#define NCFILENAME "tst_diskless3.nc"
#define NCFILENAME "tst_mmap3.nc"
#define ATT_NAME "Atom"
#define MAX_LEN 7
#define VAR_NAME2 "var2"
#define NUM_VARS 2
#define ONE_DIM 1
#define MAX_RECS 10
#define DIM1_NAME "Time"
#define DIM2_NAME "DataStrLen"
#define DIM3_NAME "X"
#define DIM3_LEN 30
#define VAR_NAME "Times"
#define VAR_NAME2 "var2"
#define VAR_NAME3 "var3"
#define STR_LEN 19
#define NUM_VALS 2
#define NDIMS 2
#define TITLE " OUTPUT FROM WRF V2.0.3.1 MODEL"
#define ATT_NAME2 "TITLE"
#define ATT_NAME3 "MISC"
#define NUM_VARS 2
static int status = NC_NOERR;
/* Control flags */
static int persist, usenetcdf4, mmap, diskless, file;
static int persist, usenetcdf4, mmap, diskless, file, openfile;
static char* filename = NCFILENAME;
static int diskmode = 0;
static int diskmode;
#ifdef DBG
char*
static int
ERR_report_local(int stat, const char* file, int line)
{
fflush(stdout);
fprintf(stderr, "Sorry! Unexpected result, %s, line: %d; status=(%d)%s\n",
file,line,stat,nc_strerror(stat));
fflush(stderr);
return 1;
}
#undef ERRSTAT
#define ERRSTAT(stat) {err+=ERR_report_local(stat,__FILE__,__LINE__);}
static int
catch(void)
{
fflush(stdout); /* Make sure our stdout is synced with stderr. */ \
err++; \
fprintf(stderr, "Sorry! Unexpected result, %s, line: %d\n", \
__FILE__, __LINE__); \
fflush(stderr); \
return 2; \
}
#undef ERR
#define ERR return catch()
#endif
static char*
smode(int mode)
{
static char ms[8192];
@ -57,6 +97,8 @@ smode(int mode)
strcat(ms,"|NC_WRITE");
if(mode & NC_NOCLOBBER)
strcat(ms,"|NC_NOCLOBBER");
else
strcat(ms,"|NC_CLOBBER");
if(mode & NC_INMEMORY)
strcat(ms,"|NC_INMEMORY");
if(mode & NC_PERSIST)
@ -66,8 +108,7 @@ smode(int mode)
return ms;
}
/* Test a diskless file with two record vars, which grow, and has
* attributes added. */
/* Test a file with two record vars, which grow, and has attributes added. */
static int
test_two_growing_with_att(const char *testfile)
{
@ -103,58 +144,67 @@ test_two_growing_with_att(const char *testfile)
/* verify */
if((status=nc_inq_dimlen(ncid, 0, &len_in))) ERRSTAT(status);
if (len_in != r + 1) ERR;
if (len_in != r + 1)
ERR;
index[0] = r;
for (v = 0; v < NUM_VARS; v++)
{
if((status=nc_get_var1_text(ncid, varid[v], index, &data_in))) ERRSTAT(status);
if (data_in != data[r]) ERR;
if (data_in != data[r])
ERR;
}
} /* Next record. */
if((status=nc_close(ncid))) ERRSTAT(status);
if((status=nc_close(ncid))) ERRSTAT(status);
return 0;
}
#if 0
/* Test a diskless file with one var and one att. */
/* Test a diskless file with one new var (dimensioned) */
static int
test_one_with_att(const char *testfile)
test_plus_one(const char *testfile)
{
int i;
int ncid, dimid, varid;
char data = 'h', data_in;
size_t count[1];
size_t start[1];
int idata[DIM3_LEN];
int ndims, nvars, natts, unlimdimid;
size_t start[NDIMS], count[NDIMS];
/* Create a file with one ulimited dimensions, and one var. */
if((status=nc_create(testfile, NC_CLOBBER, &ncid))) ERRSTAT(status);
if((status=nc_def_dim(ncid, DIM1_NAME, NC_UNLIMITED, &dimid))) ERRSTAT(status);
if((status=nc_def_var(ncid, VAR_NAME, NC_CHAR, 1, &dimid, &varid))) ERRSTAT(status);
if((status=nc_put_att_text(ncid, NC_GLOBAL, ATT_NAME, 1, &data))) ERRSTAT(status);
/* Open file */
if((status=nc_open(testfile, diskmode, &ncid))) ERRSTAT(status);
if((status=nc_redef(ncid))) ERRSTAT(status);
if((status=nc_def_dim(ncid, DIM3_NAME, DIM3_LEN, &dimid))) ERRSTAT(status);
if((status=nc_def_var(ncid, VAR_NAME3, NC_INT, 1, &dimid, &varid))) ERRSTAT(status);
if((status=nc_enddef(ncid))) ERRSTAT(status);
/* Write one record of var data, a single character. */
count[0] = 1;
/* Write one record of var data */
for(i=0;i<DIM3_LEN;i++)
idata[i] = i;
count[0] = DIM3_LEN;
start[0] = 0;
if((status=nc_put_vara_text(ncid, varid, start, count, &data))) ERRSTAT(status);
if((status=nc_put_vara_int(ncid, varid, start, count, idata))) ERRSTAT(status);
/* We're done! */
if((status=nc_close(ncid))) ERRSTAT(status);
/* Reopen the file and check it. */
if((status=nc_open(testfile, diskmode|NC_WRITE, &ncid))) ERRSTAT(status);
if((status=nc_open(testfile, diskmode & ~NC_WRITE, &ncid))) ERRSTAT(status);
if((status=nc_inq(ncid, &ndims, &nvars, &natts, &unlimdimid))) ERRSTAT(status);
if (ndims != 1 && nvars != 1 && natts != 0 && unlimdimid != 0) ERRSTAT(status);
if((status=nc_get_var_text(ncid, varid, &data_in))) ERRSTAT(status);
if (data_in != data) ERRSTAT(status);
if((status=nc_get_att_text(ncid, NC_GLOBAL, ATT_NAME, &data_in))) ERRSTAT(status);
if (data_in != data) ERRSTAT(status);
if (ndims != 2 && nvars != 3 && natts != 0 && unlimdimid != 0) ERRSTAT(status);
if((status=nc_inq_varid(ncid,VAR_NAME3,&varid))) ERRSTAT(status);
memset(idata,0,sizeof(idata));
if((status=nc_get_var_int(ncid, varid, idata))) ERRSTAT(status);
for(i=0;i<DIM3_LEN;i++) {
if(idata[i] != i)
ERR;
}
if((status=nc_close(ncid))) ERRSTAT(status);
return 0;
}
#endif
int
main(int argc, char **argv)
static void
parse(int argc, char** argv)
{
int i;
@ -165,12 +215,19 @@ main(int argc, char **argv)
diskless = 0;
file = 0;
diskmode = 0;
openfile = 0;
for(i=1;i<argc;i++) {
if(strcmp(argv[i],"diskless")==0) diskless=1;
else if(strcmp(argv[i],"mmap")==0) mmap=1;
else if(strcmp(argv[i],"file")==0) file=1;
else if(strcmp(argv[i],"persist")==0) persist=1;
else if(strcmp(argv[i],"open")==0) openfile=1;
else if(strcmp(argv[i],"create")==0) openfile=0;
else if(strncmp(argv[i],"file:",strlen("file:"))==0) {
filename = argv[i];
filename += strlen("file:");
}
/* ignore anything not recognized */
}
@ -179,27 +236,56 @@ main(int argc, char **argv)
exit(1);
}
if(!diskless && !mmap && !file) {
fprintf(stderr,"file or diskless or mmap must be specified\n");
exit(1);
}
}
static void
buildmode(void)
{
diskmode = 0;
if(diskless)
diskmode |= NC_DISKLESS;
if(mmap)
diskmode |= NC_MMAP;
if(persist)
diskmode |= NC_PERSIST;
if(openfile)
diskmode |= NC_NOCLOBBER|NC_WRITE;
}
printf("\n*** Testing create/modify file=%s mode=%s\n", NCFILENAME,
diskless?"diskless":"mmap");
int
main(int argc, char **argv)
{
parse(argc,argv);
if(!diskless && !mmap && !file) {
fprintf(stderr,"file or diskless or mmap must be specified\n");
exit(1);
}
buildmode();
printf("\n*** Testing %s: file=%s mode=%s\n",
(openfile?"open+modify":"create"),filename,smode(diskmode));
fflush(stdout);
/* case NC_FORMAT_CLASSIC: only test this format */
nc_set_default_format(NC_FORMAT_CLASSIC, NULL);
printf("*** testing diskless file with two growing record "
if(openfile) {
printf("*** testing diskless file with new variable...");
#ifdef DBG
openfile = 0;
buildmode();
test_two_growing_with_att(filename);
openfile = 1;
buildmode();
#endif
test_plus_one(filename);
} else {/* create */
printf("*** testing diskless file with two growing record "
"variables, with attributes added...");
test_two_growing_with_att(NCFILENAME);
test_two_growing_with_att(filename);
}
SUMMARIZE_ERR;
FINAL_RESULTS;

View File

@ -11,8 +11,8 @@
include $(top_srcdir)/lib_flags.am
# Un comment to use a more verbose test driver
SH_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver-verbose
LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver-verbose
#SH_LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver-verbose
#LOG_DRIVER = $(SHELL) $(top_srcdir)/test-driver-verbose
TEST_EXTENSIONS = .sh

View File

@ -187,7 +187,7 @@ typedef struct Typeinfo {
nc_type typecode;
unsigned long offset; /* fields in struct*/
unsigned long alignment;/* fields in struct*/
NCConstant* econst; /* for enum values*/
NCConstant* econst; /* for enum values*/
Dimset dimset; /* for NC_VAR/NC_FIELD/NC_ATT*/
size_t size; /* for opaque, compound, etc.*/
size_t cmpdalign; /* alignment needed for total size instances */

View File

@ -501,7 +501,12 @@ fixeconstref(Symbol* avsym, NCConstant* con)
varsym = NULL;
}
if(basetype->objectclass != NC_TYPE && basetype->subclass != NC_ENUM)
/* If this is a non-econst fillvalue, then ignore it */
if(con->nctype == NC_FILLVALUE && basetype->subclass != NC_ENUM)
return;
/* If this is an econst then validate against type */
if(con->nctype == NC_ECONST && basetype->subclass != NC_ENUM)
semerror(con->lineno,"Enumconstant associated with a non-econst type");
if(con->nctype == NC_FILLVALUE) {