Repository: Unidata/netcdf-c
Pull request #2284 (2022-04-09 20:33:28)

fixing some of the problems with nc_test when --enable-pnetcdf is used
In this PR I tried to pull in a subset of what is in #2020, but without creating a test shell file for each MPI-enabled test, and also continuing to run the MPI-enabled tests (as intended) without mpiexec for non-MPI builds.

Thanks to @tjahns for providing the code to:
* use TEMP_LARGE for pnetcdf tests.
* call MPI_Finalize in test tst_nofill.c
* using @MPIEXEC@ and a .in file for the test, so that the builder can use a different launcher than mpiexec.

This should be merged (and tests rerun) after #2280, which turns on --enable-pnetcdf testing.

Part of #2283 


Patch:
diff --git a/configure.ac b/configure.ac
index ee1d46342..e548b35e0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1973,6 +1973,7 @@ AC_CONFIG_FILES(ncdap_test/findtestserver.c:ncdap_test/findtestserver.c.in)
 AC_CONFIG_FILES(dap4_test/findtestserver4.c:ncdap_test/findtestserver.c.in)
 AC_CONFIG_FILES(dap4_test/pingurl4.c:ncdap_test/pingurl.c)
 AC_CONFIG_FILES([h5_test/run_par_tests.sh], [chmod ugo+x h5_test/run_par_tests.sh])
+AC_CONFIG_FILES([nc_test/run_pnetcdf_tests.sh], [chmod ugo+x nc_test/run_pnetcdf_tests.sh])
 AC_CONFIG_FILES([nc_test4/run_par_test.sh], [chmod ugo+x nc_test4/run_par_test.sh])
 AC_CONFIG_FILES([nc_perf/run_par_bm_test.sh], [chmod ugo+x nc_perf/run_par_bm_test.sh])
 AC_CONFIG_FILES([nc_perf/run_gfs_test.sh], [chmod ugo+x nc_perf/run_gfs_test.sh])


Test patch:
diff --git a/nc_test/Makefile.am b/nc_test/Makefile.am
index 8ed1ec41f..68eaff87d 100644
--- a/nc_test/Makefile.am
+++ b/nc_test/Makefile.am
@@ -22,24 +22,26 @@ AM_CPPFLAGS += -I$(top_builddir)/liblib -I$(top_builddir)/include -I$(top_srcdir
 
 TEST_EXTENSIONS = .sh
 
-check_PROGRAMS =
-
 # These are the tests which are always run.
-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			\
+TESTPROGRAMS = tst_names 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		\
 tst_default_format
 
+# These are always built, but for parallel builds are run from a test
+# script, because they are parallel-enabled tests.
+check_PROGRAMS = t_nc tst_atts3 tst_nofill nc_test tst_small
+
+# These tests are only run if pnetcdf is enabled.
 if USE_PNETCDF
-check_PROGRAMS += tst_parallel2 tst_pnetcdf tst_addvar
-TESTPROGRAMS += tst_formatx_pnetcdf tst_default_format_pnetcdf
+check_PROGRAMS += tst_parallel2 tst_pnetcdf tst_addvar	\
+tst_formatx_pnetcdf tst_default_format_pnetcdf
 endif
 
 if TEST_PARALLEL4
 if USE_PNETCDF
 if ENABLE_CDF5
-TESTPROGRAMS += tst_cdf5format
+check_PROGRAMS += tst_cdf5format
 endif
 endif
 endif
@@ -94,21 +96,23 @@ run_mmap.log: run_diskless.log
 endif
 endif
 
+# If pnetcdf is enabled, these tests are run by a test
+# script. Otherwise, the are run by automake in the usual way.
 if USE_PNETCDF
-TESTS += run_pnetcdf_test.sh
+TESTS += run_pnetcdf_tests.sh
+else
+TESTS += t_nc tst_atts3 tst_nofill nc_test tst_small
 endif
 
 # The .c files that are generated with m4 are already distributed, but
 # 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                   \
-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_nc4a.cdl ref_tst_http_nc4b.cdl ref_tst_http_nc4c.cdl       \
-CMakeLists.txt
+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			\
+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_nc4a.cdl ref_tst_http_nc4b.cdl	\
+ref_tst_http_nc4c.cdl CMakeLists.txt run_pnetcdf_tests.sh.in
 
 # These files are created by the tests.
 CLEANFILES = nc_test_*.nc tst_*.nc t_nc.nc large_files.nc		\
diff --git a/nc_test/run_pnetcdf_test.sh b/nc_test/run_pnetcdf_test.sh
deleted file mode 100755
index 4b3961698..000000000
--- a/nc_test/run_pnetcdf_test.sh
+++ /dev/null
@@ -1,14 +0,0 @@
-#!/bin/sh
-
-# This script runs some PnetCDF I/O tests
-
-set -e
-echo
-echo "Testing file created with PnetCDF is modifiable with netCDF..."
-./tst_pnetcdf
-
-echo "Testing file created with PnetCDF works when adding variables..."
-./tst_addvar tst_pnetcdf.nc
-
-# We assume a min of at least 2 processors is available
-mpiexec -n 2 ./tst_parallel2
diff --git a/nc_test/run_pnetcdf_tests.sh.in b/nc_test/run_pnetcdf_tests.sh.in
new file mode 100755
index 000000000..b76a6cf0d
--- /dev/null
+++ b/nc_test/run_pnetcdf_tests.sh.in
@@ -0,0 +1,26 @@
+#!/bin/sh
+
+# This script runs some PnetCDF I/O tests
+
+set -e
+echo
+echo "Testing file created with PnetCDF is modifiable with netCDF..."
+./tst_pnetcdf
+
+echo "Testing file created with PnetCDF works when adding variables..."
+./tst_addvar tst_pnetcdf.nc
+
+# We assume a min of at least 2 processors is available
+@MPIEXEC@ -n 2 ./tst_parallel2
+
+# These tests work in either serial or parallel builds.
+@MPIEXEC@ -n 1 ./t_nc
+@MPIEXEC@ -n 1 ./tst_atts3
+@MPIEXEC@ -n 1 ./tst_nofill
+@MPIEXEC@ -n 1 ./nc_test
+@MPIEXEC@ -n 1 ./tst_default_format_pnetcdf
+@MPIEXEC@ -n 1 ./tst_small
+@MPIEXEC@ -n 1 ./tst_formatx_pnetcdf
+@MPIEXEC@ -n 1 ./tst_cdf5format
+
+
diff --git a/nc_test/tst_nofill.c b/nc_test/tst_nofill.c
index 770821bd3..b6cb12d6f 100644
--- a/nc_test/tst_nofill.c
+++ b/nc_test/tst_nofill.c
@@ -486,8 +486,9 @@ main(int argc, char **argv)
        if (nc_close(ncid2)) ERR;
        SUMMARIZE_ERR;
    }
-   FINAL_RESULTS;
+
 #ifdef USE_PNETCDF
    MPI_Finalize();
 #endif
+   FINAL_RESULTS;
 }
diff --git a/nc_test/tst_pnetcdf.c b/nc_test/tst_pnetcdf.c
index de79f1989..2ae175c70 100644
--- a/nc_test/tst_pnetcdf.c
+++ b/nc_test/tst_pnetcdf.c
@@ -44,7 +44,8 @@ int main(int argc, char* argv[])
     size_t start[2], count[2];
     MPI_Comm comm=MPI_COMM_SELF;
     MPI_Info info=MPI_INFO_NULL;
-
+    char file_name[NC_MAX_NAME + 1];
+    
     printf("\n*** Testing bug fix with changing PnetCDF variable offsets...");
 
     MPI_Init(&argc,&argv);
@@ -63,7 +64,9 @@ int main(int argc, char* argv[])
 #endif
 
     cmode = NC_CLOBBER;
-    st = nc_create_par(FILENAME, cmode, comm, info, &ncid);
+    sprintf(file_name, "%s/%s", TEMP_LARGE, FILENAME);
+    st = nc_create_par(file_name, cmode, comm, info, &ncid);
+
 #ifdef USE_PNETCDF
     CHK_ERR(st)
 #else
@@ -109,7 +112,7 @@ int main(int argc, char* argv[])
     if (info != MPI_INFO_NULL) MPI_Info_free(&info);
 
     /* re-open the file with netCDF (parallel) and enter define mode */
-    st = nc_open_par(FILENAME, NC_WRITE, comm, info, &ncid); CHK_ERR(st)
+    st = nc_open_par(file_name, NC_WRITE, comm, info, &ncid); CHK_ERR(st)
 
     st = nc_redef(ncid); CHK_ERR(st)