Commit 53ae0615 authored by Thomas Jahns's avatar Thomas Jahns 🤸
Browse files

Add test for chunk-wise creation of file.

parent 8d7980ad
......@@ -323,6 +323,7 @@ tests/cksum.c -text
tests/cksum.h -text
tests/cksum_read.c -text
tests/cksum_write.c -text
tests/cksum_write_chunk.c -text
tests/ensure_array_size.c -text
tests/ensure_array_size.h -text
tests/pio_cksum_asynch.in -text
......@@ -334,6 +335,7 @@ tests/pio_write.c -text
tests/pio_write_run.in -text
tests/stream_cksum.c -text
tests/stream_cksum.h -text
tests/test_chunk_cksum.in -text
tests/test_cksum_extra.in -text
tests/test_cksum_grib.in -text
tests/test_cksum_ieg.in -text
......
......@@ -27299,7 +27299,7 @@ cat >>confdefs.h <<_ACEOF
_ACEOF
 
 
ac_config_files="$ac_config_files tests/test_cksum_grib tests/test_cksum_nc tests/test_cksum_nc2 tests/test_cksum_nc4 tests/test_cksum_extra tests/test_cksum_service tests/test_cksum_ieg tests/pio_write_run tests/pio_cksum_mpinonb tests/pio_cksum_fpguard tests/pio_cksum_asynch tests/pio_cksum_writer tests/pio_cksum_cdf util/serialrun"
ac_config_files="$ac_config_files tests/test_cksum_grib tests/test_cksum_nc tests/test_cksum_nc2 tests/test_cksum_nc4 tests/test_cksum_extra tests/test_cksum_service tests/test_cksum_ieg tests/test_chunk_cksum tests/pio_write_run tests/pio_cksum_mpinonb tests/pio_cksum_fpguard tests/pio_cksum_asynch tests/pio_cksum_writer tests/pio_cksum_cdf util/serialrun"
 
 
ac_config_files="$ac_config_files Makefile src/Makefile interfaces/Makefile app/Makefile tests/Makefile examples/Makefile cdi.settings examples/pio/Makefile src/pkgconfig/cdi.pc"
......@@ -28640,6 +28640,7 @@ do
"tests/test_cksum_extra") CONFIG_FILES="$CONFIG_FILES tests/test_cksum_extra" ;;
"tests/test_cksum_service") CONFIG_FILES="$CONFIG_FILES tests/test_cksum_service" ;;
"tests/test_cksum_ieg") CONFIG_FILES="$CONFIG_FILES tests/test_cksum_ieg" ;;
"tests/test_chunk_cksum") CONFIG_FILES="$CONFIG_FILES tests/test_chunk_cksum" ;;
"tests/pio_write_run") CONFIG_FILES="$CONFIG_FILES tests/pio_write_run" ;;
"tests/pio_cksum_mpinonb") CONFIG_FILES="$CONFIG_FILES tests/pio_cksum_mpinonb" ;;
"tests/pio_cksum_fpguard") CONFIG_FILES="$CONFIG_FILES tests/pio_cksum_fpguard" ;;
......@@ -30469,6 +30470,7 @@ _LT_EOF
"tests/test_cksum_extra":F) chmod a+x "$ac_file" ;;
"tests/test_cksum_service":F) chmod a+x "$ac_file" ;;
"tests/test_cksum_ieg":F) chmod a+x "$ac_file" ;;
"tests/test_chunk_cksum":F) chmod a+x "$ac_file" ;;
"tests/pio_write_run":F) chmod a+x "$ac_file" ;;
"tests/pio_cksum_mpinonb":F) chmod a+x "$ac_file" ;;
"tests/pio_cksum_fpguard":F) chmod a+x "$ac_file" ;;
......
......@@ -290,6 +290,7 @@ AC_CONFIG_FILES([tests/test_cksum_grib \
tests/test_cksum_extra \
tests/test_cksum_service \
tests/test_cksum_ieg \
tests/test_chunk_cksum \
tests/pio_write_run \
tests/pio_cksum_mpinonb \
tests/pio_cksum_fpguard \
......
......@@ -2,14 +2,16 @@
#
TESTS = test_grib.sh test_cksum_grib test_cksum_nc test_cksum_extra \
test_cksum_service test_cksum_nc2 test_cksum_nc4 test_cksum_ieg \
test_chunk_cksum \
pio_write_run pio_cksum_mpinonb pio_cksum_fpguard \
pio_cksum_asynch pio_cksum_writer pio_cksum_cdf \
test_resource_copy
check_PROGRAMS = test_grib cksum_write cksum_read pio_write \
test_resource_copy
test_resource_copy cksum_write_chunk
#
test_grib_SOURCES = test_grib.c
cksum_write_SOURCES = cksum_write.c cksum.c cksum.h
cksum_write_chunk_SOURCES = cksum_write_chunkb main.c cksum.c cksum.h
cksum_read_SOURCES = cksum_read.c \
var_cksum.c var_cksum.h \
stream_cksum.c stream_cksum.h \
......
......@@ -52,21 +52,21 @@ build_triplet = @build@
host_triplet = @host@
TESTS = test_grib.sh test_cksum_grib test_cksum_nc test_cksum_extra \
test_cksum_service test_cksum_nc2 test_cksum_nc4 \
test_cksum_ieg pio_write_run pio_cksum_mpinonb \
pio_cksum_fpguard pio_cksum_asynch pio_cksum_writer \
pio_cksum_cdf test_resource_copy$(EXEEXT)
test_cksum_ieg test_chunk_cksum pio_write_run \
pio_cksum_mpinonb pio_cksum_fpguard pio_cksum_asynch \
pio_cksum_writer pio_cksum_cdf test_resource_copy$(EXEEXT)
check_PROGRAMS = test_grib$(EXEEXT) cksum_write$(EXEEXT) \
cksum_read$(EXEEXT) pio_write$(EXEEXT) \
test_resource_copy$(EXEEXT)
test_resource_copy$(EXEEXT) cksum_write_chunk$(EXEEXT)
subdir = tests
DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in \
$(srcdir)/pio_cksum_asynch.in $(srcdir)/pio_cksum_cdf.in \
$(srcdir)/pio_cksum_fpguard.in $(srcdir)/pio_cksum_mpinonb.in \
$(srcdir)/pio_cksum_writer.in $(srcdir)/pio_write_run.in \
$(srcdir)/test_cksum_extra.in $(srcdir)/test_cksum_grib.in \
$(srcdir)/test_cksum_ieg.in $(srcdir)/test_cksum_nc.in \
$(srcdir)/test_cksum_nc2.in $(srcdir)/test_cksum_nc4.in \
$(srcdir)/test_cksum_service.in
$(srcdir)/test_chunk_cksum.in $(srcdir)/test_cksum_extra.in \
$(srcdir)/test_cksum_grib.in $(srcdir)/test_cksum_ieg.in \
$(srcdir)/test_cksum_nc.in $(srcdir)/test_cksum_nc2.in \
$(srcdir)/test_cksum_nc4.in $(srcdir)/test_cksum_service.in
ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
am__aclocal_m4_deps = \
$(top_srcdir)/m4/acx_assert_lang_is_fortran_variant.m4 \
......@@ -86,9 +86,9 @@ mkinstalldirs = $(SHELL) $(top_srcdir)/config/mkinstalldirs
CONFIG_HEADER = $(top_builddir)/src/config.h
CONFIG_CLEAN_FILES = test_cksum_grib test_cksum_nc test_cksum_nc2 \
test_cksum_nc4 test_cksum_extra test_cksum_service \
test_cksum_ieg pio_write_run pio_cksum_mpinonb \
pio_cksum_fpguard pio_cksum_asynch pio_cksum_writer \
pio_cksum_cdf
test_cksum_ieg test_chunk_cksum pio_write_run \
pio_cksum_mpinonb pio_cksum_fpguard pio_cksum_asynch \
pio_cksum_writer pio_cksum_cdf
CONFIG_CLEAN_VPATH_FILES =
am_cksum_read_OBJECTS = cksum_read.$(OBJEXT) var_cksum.$(OBJEXT) \
stream_cksum.$(OBJEXT) cksum.$(OBJEXT) \
......@@ -100,6 +100,11 @@ am_cksum_write_OBJECTS = cksum_write.$(OBJEXT) cksum.$(OBJEXT)
cksum_write_OBJECTS = $(am_cksum_write_OBJECTS)
cksum_write_LDADD = $(LDADD)
cksum_write_DEPENDENCIES = ../src/libcdi.la
am_cksum_write_chunk_OBJECTS = cksum_write_chunk.$(OBJEXT) \
cksum.$(OBJEXT)
cksum_write_chunk_OBJECTS = $(am_cksum_write_chunk_OBJECTS)
cksum_write_chunk_LDADD = $(LDADD)
cksum_write_chunk_DEPENDENCIES = ../src/libcdi.la
am_pio_write_OBJECTS = pio_write.$(OBJEXT) cksum.$(OBJEXT)
pio_write_OBJECTS = $(am_pio_write_OBJECTS)
pio_write_LDADD = $(LDADD)
......@@ -126,11 +131,11 @@ LINK = $(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) \
--mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) \
$(LDFLAGS) -o $@
SOURCES = $(cksum_read_SOURCES) $(cksum_write_SOURCES) \
$(pio_write_SOURCES) $(test_grib_SOURCES) \
$(test_resource_copy_SOURCES)
$(cksum_write_chunk_SOURCES) $(pio_write_SOURCES) \
$(test_grib_SOURCES) $(test_resource_copy_SOURCES)
DIST_SOURCES = $(cksum_read_SOURCES) $(cksum_write_SOURCES) \
$(pio_write_SOURCES) $(test_grib_SOURCES) \
$(test_resource_copy_SOURCES)
$(cksum_write_chunk_SOURCES) $(pio_write_SOURCES) \
$(test_grib_SOURCES) $(test_resource_copy_SOURCES)
am__can_run_installinfo = \
case $$AM_UPDATE_INFO_DIR in \
n|no|NO) false;; \
......@@ -329,6 +334,7 @@ top_srcdir = @top_srcdir@
#
test_grib_SOURCES = test_grib.c
cksum_write_SOURCES = cksum_write.c cksum.c cksum.h
cksum_write_chunk_SOURCES = cksum_write_chunk.c cksum.c cksum.h
cksum_read_SOURCES = cksum_read.c \
var_cksum.c var_cksum.h \
stream_cksum.c stream_cksum.h \
......@@ -393,6 +399,8 @@ test_cksum_service: $(top_builddir)/config.status $(srcdir)/test_cksum_service.i
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
test_cksum_ieg: $(top_builddir)/config.status $(srcdir)/test_cksum_ieg.in
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
test_chunk_cksum: $(top_builddir)/config.status $(srcdir)/test_chunk_cksum.in
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
pio_write_run: $(top_builddir)/config.status $(srcdir)/pio_write_run.in
cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@
pio_cksum_mpinonb: $(top_builddir)/config.status $(srcdir)/pio_cksum_mpinonb.in
......@@ -420,6 +428,9 @@ cksum_read$(EXEEXT): $(cksum_read_OBJECTS) $(cksum_read_DEPENDENCIES) $(EXTRA_ck
cksum_write$(EXEEXT): $(cksum_write_OBJECTS) $(cksum_write_DEPENDENCIES) $(EXTRA_cksum_write_DEPENDENCIES)
@rm -f cksum_write$(EXEEXT)
$(LINK) $(cksum_write_OBJECTS) $(cksum_write_LDADD) $(LIBS)
cksum_write_chunk$(EXEEXT): $(cksum_write_chunk_OBJECTS) $(cksum_write_chunk_DEPENDENCIES) $(EXTRA_cksum_write_chunk_DEPENDENCIES)
@rm -f cksum_write_chunk$(EXEEXT)
$(LINK) $(cksum_write_chunk_OBJECTS) $(cksum_write_chunk_LDADD) $(LIBS)
pio_write$(EXEEXT): $(pio_write_OBJECTS) $(pio_write_DEPENDENCIES) $(EXTRA_pio_write_DEPENDENCIES)
@rm -f pio_write$(EXEEXT)
$(LINK) $(pio_write_OBJECTS) $(pio_write_LDADD) $(LIBS)
......@@ -439,6 +450,7 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cksum.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cksum_read.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cksum_write.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/cksum_write_chunk.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ensure_array_size.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pio_write.Po@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/stream_cksum.Po@am__quote@
......
......@@ -11,6 +11,7 @@
#include "cksum.h"
static int
parse_intarg(const char msg[])
{
......@@ -37,6 +38,13 @@ sign_flat(double v)
return v;
}
static void
allocError(const char *msg)
{
perror(msg);
exit(EXIT_FAILURE);
}
static char *
fname_create(const char *prefix, const char *suffix)
{
......@@ -44,16 +52,35 @@ fname_create(const char *prefix, const char *suffix)
char *fname;
if (!(fname =malloc((prefix_len = strlen(prefix)) + 1
+ (suffix_len = strlen(suffix)) + 1)))
{
perror("cannot create string");
exit(EXIT_FAILURE);
}
allocError("cannot create string");
strcpy(fname, prefix);
fname[prefix_len] = '.';
strcpy(fname + prefix_len + 1, suffix);
return fname;
}
#ifdef TEST_CHUNK_WRITE
static void
get_chunk(double *chunkBuf, double *var, int varShape[3],
int chunk[3][2])
{
size_t ofs = 0;
unsigned start_k = (unsigned)chunk[2][0], start_j = (unsigned)chunk[1][0],
start_i = (unsigned)chunk[0][0];
unsigned size_k = (unsigned)chunk[2][1] - (unsigned)chunk[2][0] + 1,
size_j = (unsigned)chunk[1][1] - (unsigned)chunk[1][0] + 1,
size_i = (unsigned)chunk[0][1] - (unsigned)chunk[0][0] + 1;
size_t stride_k = (size_t)varShape[0] * (size_t)varShape[1],
stride_j = (size_t)varShape[0];
for (unsigned k = 0; k < size_k ; ++k)
for (unsigned j = 0; j < size_j; ++j)
for (unsigned i = 0; i < size_i; ++i)
chunkBuf[ofs++] = var[(k + start_k) * stride_k
+ (j + start_j) * stride_j + (i + start_i)];
}
#endif
#ifndef TEST_CHUNK_WRITE
static const struct {
char suffix[4];
int type, defaultDT, defaultGrid;
......@@ -66,7 +93,7 @@ static const struct {
{ "svc", FILETYPE_SRV, DATATYPE_FLT64, GRID_GENERIC, },
{ "ieg", FILETYPE_IEG, DATATYPE_FLT64, GRID_LONLAT },
};
#endif
enum {
nvars = 2,
};
......@@ -86,13 +113,24 @@ main(int argc, char *argv[])
double *lons, *lats, *var[nvars], *levs, mscale, mrscale;
size_t varSize[nvars];
char *varName[nvars] = { "varname1", "varname2" };
#ifndef TEST_CHUNK_WRITE
const char *suffix = "grb", *prefix = "example";
int grid = GRID_LONLAT;
int filetype = FILETYPE_GRB, datatype = DATATYPE_PACK24;
#else
const char *suffix = "nc", *prefix = "example";
int grid = GRID_LONLAT;
int filetype = FILETYPE_NC, datatype = DATATYPE_FLT64;
#endif
{
int opt;
while ((opt = getopt(argc, argv, "f:m:n:o:t:")) != -1)
while ((opt = getopt(argc, argv,
#ifndef TEST_CHUNK_WRITE
"f:"
#endif
"m:n:o:t:")) != -1)
switch (opt) {
#ifndef TEST_CHUNK_WRITE
case 'f':
{
int found = 0;
......@@ -114,8 +152,17 @@ main(int argc, char *argv[])
}
}
break;
#endif
case 'm':
nlon = parse_intarg("error parsing number of longitudes");
#ifdef TEST_CHUNK_WRITE
if (nlon < 2)
{
fputs("number of longitudes must be larger 1 for "
"chunk write test\n", stderr);
exit(EXIT_FAILURE);
}
#endif
break;
case 'n':
nlat = parse_intarg("error parsing number of latitudes");
......@@ -177,7 +224,6 @@ main(int argc, char *argv[])
vlistDefVarDatatype(vlistID, varID[i], datatype);
// create memory for variables
var[i] = malloc(varSize[i] * sizeof (var[i][0]));
}
{
......@@ -266,8 +312,38 @@ main(int argc, char *argv[])
memcrc_r(&checksum_state[1], (const unsigned char *)var[1], varSize[1] * sizeof (var[1][0]));
// Write var1 and var2
#ifdef TEST_CHUNK_WRITE
{
size_t maxChunkSize = (nlon + 1)/2 * nlat * nlev;
double *chunkBuf = malloc(maxChunkSize * sizeof (double));
int varShape[2][3] = { { nlon, nlat, 1 }, { nlon, nlat, nlev } },
chunk[3][2] = { { 0, nlon/2 - 1 }, { 0, nlat - 1 }, { 0, 0 } };
if (!chunkBuf)
allocError("cannot create chunk buffer");
chunk[0][0] = 0; chunk[0][1] = nlon/2 - 1;
chunk[2][1] = 0;
get_chunk(chunkBuf, var[0], varShape[0], chunk);
streamWriteVarChunk(streamID, varID[0], (const int (*)[2])chunk,
chunkBuf, nmiss);
chunk[2][1] = nlev - 1;
get_chunk(chunkBuf, var[1], varShape[1], chunk);
streamWriteVarChunk(streamID, varID[1], (const int (*)[2])chunk,
chunkBuf, nmiss);
chunk[0][0] = chunk[0][1] + 1; chunk[0][1] = nlon - 1;
chunk[2][1] = 0;
get_chunk(chunkBuf, var[0], varShape[0], chunk);
streamWriteVarChunk(streamID, varID[0], (const int (*)[2])chunk,
chunkBuf, nmiss);
chunk[2][1] = nlev - 1;
get_chunk(chunkBuf, var[1], varShape[1], chunk);
streamWriteVarChunk(streamID, varID[1], (const int (*)[2])chunk,
chunkBuf, nmiss);
free(chunkBuf);
}
#else
streamWriteVar(streamID, varID[0], var[0], nmiss);
streamWriteVar(streamID, varID[1], var[1], nmiss);
#endif
}
// write checksums to table file
{
......@@ -301,12 +377,16 @@ main(int argc, char *argv[])
streamClose(streamID);
// Destroy the objects
for (i = 0; i < nvars; ++i)
free(var[i]);
vlistDestroy(vlistID);
taxisDestroy(taxisID);
zaxisDestroy(zaxisID[0]);
zaxisDestroy(zaxisID[1]);
gridDestroy(gridID);
free(levs);
free(lats);
free(lons);
return 0;
}
......
#define TEST_CHUNK_WRITE 1
#include "cksum_write.c"
#! /bin/sh
set -e
format=nc
if [ @ENABLE_NETCDF@ = yes ]; then
exec >test_chunk_cksum_$format.log 2>&1
./cksum_write_chunk -m 17
./cksum_read example.$format
\rm example.cksum example.$format
\rm test_chunk_cksum_$format.log
else
# skip tests for unsupported formats
exit 77
fi
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment