From e872dfe03b49db9a1d979b08c2699f4b45957e86 Mon Sep 17 00:00:00 2001 From: Ed Date: Wed, 14 Aug 2024 07:19:23 -0600 Subject: [PATCH] adding and building tst_zstd.c --- nc_test4/CMakeLists.txt | 5 +++ nc_test4/Makefile.am | 14 +++++--- nc_test4/tst_zstd.c | 78 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+), 4 deletions(-) create mode 100644 nc_test4/tst_zstd.c diff --git a/nc_test4/CMakeLists.txt b/nc_test4/CMakeLists.txt index 33a105f5b..4df3684b6 100644 --- a/nc_test4/CMakeLists.txt +++ b/nc_test4/CMakeLists.txt @@ -102,6 +102,11 @@ IF(HAVE_H5Z_SZIP) ENDIF() ENDIF() +IF(HAVE_ZSTD) + BUILD_BIN_TEST(tst_zstd) +# add_sh_test(nc_test4 run_zstd_test) +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}/*.h5 ${CMAKE_CURRENT_SOURCE_DIR}/*.cdl) diff --git a/nc_test4/Makefile.am b/nc_test4/Makefile.am index 6d1c0e2e4..584e739d5 100644 --- a/nc_test4/Makefile.am +++ b/nc_test4/Makefile.am @@ -11,10 +11,10 @@ include $(top_srcdir)/lib_flags.am # Un comment to use a more verbose test driver -#SH_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 -#TESTS_ENVIRONMENT = export SETX=1; +SH_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 +TESTS_ENVIRONMENT = export SETX=1; TEST_EXTENSIONS = .sh @@ -113,6 +113,12 @@ endif # NETCDF_ENABLE_PLUGINS endif # USE_HDF5 endif # NETCDF_BUILD_UTILITIES +# Zstandard tests. +if HAVE_ZSTD +check_PROGRAMS += tst_zstd +#TESTS += run_zstd_test.sh +endif # HAVE_ZSTD + # This are extra tests that will only be run if netcdf-4 is configured # with --enable-parallel-tests. if TEST_PARALLEL4 diff --git a/nc_test4/tst_zstd.c b/nc_test4/tst_zstd.c new file mode 100644 index 000000000..7ae201fbf --- /dev/null +++ b/nc_test4/tst_zstd.c @@ -0,0 +1,78 @@ +/* This is part of the netCDF package. + Copyright 2018 University Corporation for Atmospheric Research/Unidata + See COPYRIGHT file for conditions of use. + + Test netcdf-4 variables. + Ed Hartnett, 8/7/24 +*/ + +#include "nc_tests.h" +#include "err_macros.h" +#include "netcdf.h" + +#define FILE_NAME "tst_zstd.nc" +#define VAR_FLOAT_NAME "GALE_data" +#define VAR_DOUBLE_NAME "ERICA_data" +#define NDIM2 2 +#define DIM1_NAME "x" +#define DIM1_LEN 2 +#define DIM2_NAME "y" +#define DIM2_LEN 3 + +int +main(int argc, char **argv) +{ + int ncid, dimids[NDIM2]; + int float_varid, double_varid; + float float_in[DIM1_LEN][DIM2_LEN], float_out[DIM1_LEN][DIM2_LEN] = {{-.1f, 9999.99f, 100.001f},{-.1f, 9999.99f, 100.001f}}; + double double_in[DIM1_LEN][DIM2_LEN], double_out[DIM1_LEN][DIM2_LEN] = {{0.02, .1128, 1090.1},{0.02, .1128, 1090.1}}; + int i, j, ret; + + + printf("\n*** Testing netcdf-4 zstd compression.\n"); + + printf("*** testing netcdf-4 zstd with float..."); + { + int nvars_in, varids_in[2]; + + /* Create a netcdf file with one dim and two vars. */ + if (nc_create(FILE_NAME, NC_NETCDF4, &ncid)) ERR; + if (nc_def_dim(ncid, DIM1_NAME, DIM1_LEN, &dimids[0])) ERR; + if (nc_def_dim(ncid, DIM2_NAME, DIM2_LEN, &dimids[1])) ERR; + if (nc_def_var(ncid, VAR_FLOAT_NAME, NC_FLOAT, 2, dimids, &float_varid)) ERR; + if (nc_def_var(ncid, VAR_DOUBLE_NAME, NC_DOUBLE, 2, dimids, &double_varid)) ERR; + if ((ret = nc_def_var_zstandard(ncid, float_varid, 4))) + { + printf("error: %s\n", nc_strerror(ret)); + ERR; + } + if (nc_def_var_zstandard(ncid, double_varid, 4)) ERR; + if (nc_put_var_float(ncid, float_varid, (float *)float_out)) ERR; + if (nc_put_var_double(ncid, double_varid, (double *)double_out)) ERR; + if (nc_close(ncid)) ERR; + + /* Open the file and make sure nc_inq_varids yields correct + * result. */ + if (nc_open(FILE_NAME, NC_NOWRITE, &ncid)) ERR; + if (nc_inq_varids(ncid, &nvars_in, varids_in)) ERR; + if (nvars_in != 2 || varids_in[0] != 0 || varids_in[1] != 1) ERR; + if (nc_get_var_float(ncid, float_varid, (float *)float_in)) ERR; + if (nc_get_var_double(ncid, double_varid, (double *)double_in)) ERR; + for (i = 0; i < DIM1_LEN; i++) + { + for (j = 0; j < DIM2_LEN; j++) + { + if (float_in[i][j] != float_out[i][j]) ERR; + if (double_in[i][j] != double_out[i][j]) ERR; + } + } + + + if (nc_close(ncid)) ERR; + } + + SUMMARIZE_ERR; + SUMMARIZE_ERR; + + FINAL_RESULTS; +}