netcdf-c/nctest/driver.c

162 lines
4.8 KiB
C
Raw Normal View History

2010-06-03 21:24:43 +08:00
/*********************************************************************
2018-12-07 06:47:47 +08:00
* Copyright 1993-2018, UCAR/Unidata
2010-06-03 21:24:43 +08:00
* See COPYRIGHT file for copying and redistribution conditions.
*
* Test driver for netCDF implementation. This program performs tests
* against the netCDF specification for all user-level functions in an
* implementation of the netCDF library. Must be invoked from a
* directory in which the invoker has write permission.
*
* Glenn Davis, Russ Rew, Ed Hartnett
2010-06-03 21:24:43 +08:00
*********************************************************************/
#include <config.h>
2010-11-30 06:23:16 +08:00
#include <stdlib.h>
2010-06-03 21:24:43 +08:00
#include <netcdf.h>
#include <stdio.h>
#include <string.h>
2010-11-30 06:23:16 +08:00
#include "testcdf.h" /* defines in-memory test netcdf structure */
2010-06-03 21:24:43 +08:00
#include "tests.h"
#define MAX_NUM_FORMATS 5
Support MSYS2/Mingw platform re: The current netcdf-c release has some problems with the mingw platform on windows. Mostly they are path issues. Changes to support mingw+msys2: ------------------------------- * Enable option of looking into the windows registry to find the mingw root path. In aid of proper path handling. * Add mingw+msys as a specific platform in configure.ac and move testing of the platform to the front so it is available early. * Handle mingw X libncpoco (dynamic loader) properly even though mingw does not yet support it. * Handle mingw X plugins properly even though mingw does not yet support it. * Alias pwd='pwd -W' to better handle paths in shell scripts. * Plus a number of other minor compile irritations. * Disallow the use of multiple nc_open's on the same file for windows (and mingw) because windows does not seem to handle these properly. Not sure why we did not catch this earlier. * Add mountpoint info to dpathmgr.c to help support mingw. * Cleanup dpathmgr conversions. Known problems: --------------- * I have not been able to get shared libraries to work, so plugins/filters must be disabled. * There is some kind of problem with libcurl that I have not solved, so all uses of libcurl (currently DAP+Byterange) must be disabled. Misc. other fixes: ------------------ * Cleanup the relationship between ENABLE_PLUGINS and various other flags in CMakeLists.txt and configure.ac. * Re-arrange the TESTDIRS order in Makefile.am. * Add pseudo-breakpoint to nclog.[ch] for debugging. * Improve the documentation of the path manager code in ncpathmgr.h * Add better support for relative paths in dpathmgr.c * Default the mode args to NCfopen to include "b" (binary) for windows. * Add optional debugging output in various places. * Make sure that everything builds with plugins disabled. * Fix numerous (s)printf inconsistencies betweenb the format spec and the arguments.
2021-12-24 13:18:56 +08:00
#undef DEBUG
#ifdef DEBUG
#define CATCH(x) {(x); if(nerrs > 0) breakpoint();}
static void breakpoint(void) {return;}
#else
#define CATCH(x) (x)
#endif
int current_format = 0;
/* Determine how many formats are available, and what they are. */
void
determine_test_formats(int *num_formats, int *format)
{
int ind = 0;
int num;
/* We always have classic and 64-bit offset */
num = 2;
format[ind++] = NC_FORMAT_CLASSIC;
format[ind++] = NC_FORMAT_64BIT_OFFSET;
/* Do we have netCDF-4 and netCDF-4 classic? */
#ifdef USE_HDF5
num += 2;
format[ind++] = NC_FORMAT_NETCDF4_CLASSIC;
format[ind++] = NC_FORMAT_NETCDF4;
#endif /* USE_HDF5 */
/* Do we have CDF5? */
#ifdef NETCDF_ENABLE_CDF5
num++;
format[ind++] = NC_FORMAT_CDF5;
#endif /* NETCDF_ENABLE_CDF5 */
*num_formats = num;
}
2010-06-03 21:24:43 +08:00
int
main(int argc, char **argv)
{
/*EXTERNL int ncopts; */ /* netCDF error options */
char *format_name[MAX_NUM_FORMATS] = {"classic", "64bit_offset", "netcdf4_classic",
"netcdf4", "CDF5"};
char testfile[NC_MAX_NAME];
int format[MAX_NUM_FORMATS];
int num_formats;
int i, nerrs = 0;
ncopts &= ~NC_FATAL; /* make errors nonfatal */
ncopts &= ~NC_VERBOSE; /* turn off error messages */
/* How many formats are we testing? */
determine_test_formats(&num_formats, format);
printf("Testing V2 API with %d different netCDF formats.\n", num_formats);
for (i = 0; i < num_formats; i++)
{
current_format = format[i];
/* Skip netCDF-4 - only netCDF-4 classic will work. */
if (format[i] == NC_FORMAT_NETCDF4)
continue;
2018-12-07 06:47:47 +08:00
/* Come up with a test file name. */
snprintf(testfile, sizeof(testfile), "nctest_%s.nc", format_name[i]);
2018-12-07 06:47:47 +08:00
printf("Testing %s with file %s.\n", format_name[i], testfile);
/* Set the default format. */
nc_set_default_format(format[i], NULL);
/* Run all the tests for this format. */
Support MSYS2/Mingw platform re: The current netcdf-c release has some problems with the mingw platform on windows. Mostly they are path issues. Changes to support mingw+msys2: ------------------------------- * Enable option of looking into the windows registry to find the mingw root path. In aid of proper path handling. * Add mingw+msys as a specific platform in configure.ac and move testing of the platform to the front so it is available early. * Handle mingw X libncpoco (dynamic loader) properly even though mingw does not yet support it. * Handle mingw X plugins properly even though mingw does not yet support it. * Alias pwd='pwd -W' to better handle paths in shell scripts. * Plus a number of other minor compile irritations. * Disallow the use of multiple nc_open's on the same file for windows (and mingw) because windows does not seem to handle these properly. Not sure why we did not catch this earlier. * Add mountpoint info to dpathmgr.c to help support mingw. * Cleanup dpathmgr conversions. Known problems: --------------- * I have not been able to get shared libraries to work, so plugins/filters must be disabled. * There is some kind of problem with libcurl that I have not solved, so all uses of libcurl (currently DAP+Byterange) must be disabled. Misc. other fixes: ------------------ * Cleanup the relationship between ENABLE_PLUGINS and various other flags in CMakeLists.txt and configure.ac. * Re-arrange the TESTDIRS order in Makefile.am. * Add pseudo-breakpoint to nclog.[ch] for debugging. * Improve the documentation of the path manager code in ncpathmgr.h * Add better support for relative paths in dpathmgr.c * Default the mode args to NCfopen to include "b" (binary) for windows. * Add optional debugging output in various places. * Make sure that everything builds with plugins disabled. * Fix numerous (s)printf inconsistencies betweenb the format spec and the arguments.
2021-12-24 13:18:56 +08:00
CATCH(nerrs += test_nccreate(testfile));
CATCH(nerrs += test_ncopen(testfile));
CATCH(nerrs += test_ncredef(testfile));
CATCH(nerrs += test_ncendef(testfile));
CATCH(nerrs += test_ncclose(testfile));
CATCH(nerrs += test_ncinquire(testfile));
CATCH(nerrs += test_ncsync(testfile));
CATCH(nerrs += test_ncabort(testfile));
CATCH(nerrs += test_ncdimdef(testfile));
CATCH(nerrs += test_ncdimid(testfile));
CATCH(nerrs += test_ncdiminq(testfile));
CATCH(nerrs += test_ncdimrename(testfile));
CATCH(nerrs += test_ncvardef(testfile));
CATCH(nerrs += test_ncvarid(testfile));
CATCH(nerrs += test_ncvarinq(testfile));
CATCH(nerrs += test_ncvarputg(testfile));
CATCH(nerrs += test_ncvarput1(testfile));
CATCH(nerrs += test_ncvarget1(testfile));
CATCH(nerrs += test_ncvarput(testfile));
CATCH(nerrs += test_ncvarget(testfile));
CATCH(nerrs += test_ncvarputg(testfile));
CATCH(nerrs += test_ncvargetg(testfile));
CATCH(nerrs += test_ncrecinq(testfile));
CATCH(nerrs += test_ncrecput(testfile));
CATCH(nerrs += test_ncrecget(testfile));
CATCH(nerrs += test_ncvarrename(testfile));
CATCH(nerrs += test_ncattput(testfile));
CATCH(nerrs += test_ncattinq(testfile));
CATCH(nerrs += test_ncattget(testfile));
CATCH(nerrs += test_ncattcopy(testfile, "test2.nc"));
CATCH(nerrs += test_ncattname(testfile));
CATCH(nerrs += test_ncattrename(testfile));
CATCH(nerrs += test_ncattdel(testfile));
CATCH(nerrs += test_nctypelen());
/* Clean up in-memory struct. */
{
int i;
for (i = 0; i < test.ndims; i++)
free(test.dims[i].name);
for (i = 0; i < test.nvars; i++)
{
free(test.vars[i].name);
free(test.vars[i].dims);
}
for (i = 0; i < test.natts; i++)
free(test.atts[i].name);
}
}
2018-12-07 06:47:47 +08:00
fprintf(stderr, "\nTotal number of failures: %d\n", nerrs);
2010-06-03 21:24:43 +08:00
if (nerrs)
{
fprintf(stderr, "nctest FAILURE!!!\n");
return 2;
}
else
fprintf(stderr, "nctest SUCCESS!!!\n");
2010-06-03 21:24:43 +08:00
return 0;
2010-06-03 21:24:43 +08:00
}