From e41d24f73165dfb833f4beaee682f01905660e17 Mon Sep 17 00:00:00 2001 From: Jim Edwards Date: Wed, 13 Feb 2019 15:21:01 -0700 Subject: [PATCH] add some tests --- src/clib/pio_darray_int.c | 2 +- tests/cunit/test_darray.c | 57 +++++++++++++++++++++++++---- tests/cunit/test_darray_multivar3.c | 19 +++------- 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/src/clib/pio_darray_int.c b/src/clib/pio_darray_int.c index 583dfbf3e59..173845cf7c4 100644 --- a/src/clib/pio_darray_int.c +++ b/src/clib/pio_darray_int.c @@ -1213,7 +1213,7 @@ int pio_read_darray_nc(file_desc_t *file, io_desc_t *iodesc, int vid, void *iobu } } -#ifdef LOGGING +#ifdef PIO_ENABLE_LOGGING for (int i = 1; i < ndims; i++) LOG((3, "start[%d] %d count[%d] %d", i, start[i], i, count[i])); #endif /* LOGGING */ diff --git a/tests/cunit/test_darray.c b/tests/cunit/test_darray.c index 7001f395bb8..ec47a6b8717 100644 --- a/tests/cunit/test_darray.c +++ b/tests/cunit/test_darray.c @@ -76,9 +76,12 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank int ncid; /* The ncid of the netCDF file. */ int ncid2; /* The ncid of the re-opened netCDF file. */ int varid; /* The ID of the netCDF varable. */ - int varid2; /* The ID of a varable of different type. */ + int varid2; /* The ID of a netCDF varable of different type. */ int wrong_varid = TEST_VAL_42; /* A wrong ID. */ int ret; /* Return code. */ + int mpi_type; + int type_size; /* size of a variable of type pio_type */ + int other_type; /* another variable of the same size but different type */ PIO_Offset arraylen = 4; void *fillvalue; void *test_data; @@ -116,7 +119,7 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank /* Create the filename. */ sprintf(filename, "data_%s_iotype_%d_pio_type_%d_test_multi_%d_provide_fill_%d.nc", TEST_NAME, flavor[fmt], pio_type, test_multi, provide_fill); - + if(my_rank==0) printf("Test file %s\n", filename); /* Select the fill value and data. */ switch (pio_type) { @@ -143,6 +146,7 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank if ((ret = PIOc_createfile(iosysid, &ncid, &flavor[fmt], filename, PIO_CLOBBER))) ERR(ret); + if(my_rank==0) printf("Test file %s created\n", filename); /* Define netCDF dimensions and variable. */ for (int d = 0; d < NDIM; d++) if ((ret = PIOc_def_dim(ncid, dim_name[d], (PIO_Offset)dim_len[d], &dimids[d]))) @@ -152,23 +156,35 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank if ((ret = PIOc_def_var(ncid, VAR_NAME, pio_type, NDIM, dimids, &varid))) ERR(ret); - /* Define a variable with a different type. */ - int other_type = pio_type == PIO_INT ? PIO_FLOAT : PIO_INT; - if ((ret = PIOc_def_var(ncid, VAR_NAME2, other_type, NDIM, dimids, &varid2))) + /* Define a variable with a different type but same size. */ + if ((ret = find_mpi_type(pio_type, &mpi_type, &type_size))) + ERR(ret); + if (type_size == NETCDF_INT_FLOAT_SIZE) + other_type = pio_type == PIO_INT ? PIO_FLOAT : PIO_INT; +// else if(type_size == NETCDF_DOUBLE_INT64_SIZE) +// other_type = pio_type == PIO_INT64 ? PIO_DOUBLE : PIO_INT64; + else + other_type = 0; /* skip the test */ + printf("pio_type %d other_type %d\n",pio_type, other_type); + if (other_type && (ret = PIOc_def_var(ncid, VAR_NAME2, other_type, NDIM, dimids, &varid2))) ERR(ret); /* End define mode. */ if ((ret = PIOc_enddef(ncid))) ERR(ret); + if(my_rank==0) printf("Test file %s defined\n", filename); /* Set the value of the record dimension. */ if ((ret = PIOc_setframe(ncid, varid, 0))) ERR(ret); + if (other_type && (ret = PIOc_setframe(ncid, varid2, 0))) + ERR(ret); int frame = 0; int flushtodisk = test_multi - 1; if (!test_multi) { + if(my_rank==0) printf("expected fails\n"); /* These should not work. */ if (PIOc_write_darray(ncid + TEST_VAL_42, varid, ioid, arraylen, test_data, fillvalue) != PIO_EBADID) ERR(ERR_WRONG); @@ -178,12 +194,18 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank ERR(ERR_WRONG); if (PIOc_write_darray(ncid, TEST_VAL_42, ioid, arraylen, test_data, fillvalue) != PIO_ENOTVAR) ERR(ERR_WRONG); -// if (PIOc_write_darray(ncid, varid2, ioid, arraylen, test_data, fillvalue) != PIO_EINVAL) -// ERR(ERR_WRONG); + + if(my_rank==0) printf("expected pass\n"); + + /* This should work - library type conversion */ + if (other_type && (ret = PIOc_write_darray(ncid, varid2, ioid, arraylen, test_data, fillvalue))) + ERR(ret); /* Write the data. */ if ((ret = PIOc_write_darray(ncid, varid, ioid, arraylen, test_data, fillvalue))) ERR(ret); + + if(my_rank==0) printf("data write complete\n"); } else { @@ -209,6 +231,11 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank fillvalue, flushtodisk) != PIO_ENOTVAR) ERR(ERR_WRONG); + /* This should work - library type conversion */ + if (other_type && (ret = PIOc_write_darray_multi(ncid, &varid2, ioid, 1, arraylen, test_data, &frame, + fillvalue, flushtodisk))) + ERR(ret); + /* Write the data with the _multi function. */ if ((ret = PIOc_write_darray_multi(ncid, &varid, ioid, 1, arraylen, test_data, &frame, fillvalue, flushtodisk))) @@ -219,10 +246,20 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank if ((ret = PIOc_closefile(ncid))) ERR(ret); + printf("file closed\n"); + /* Reopen the file. */ if ((ret = PIOc_openfile(iosysid, &ncid2, &flavor[fmt], filename, PIO_NOWRITE))) ERR(ret); + PIO_Offset dimlen; + /* check the unlimited dim size - it should be 1 */ + if ((ret = PIOc_inq_dimlen(ncid2, dimids[0], &dimlen))) + ERR(ret); + if (dimlen != 1) + ERR(ERR_WRONG); + + printf("file reopened\n"); /* These should not work. */ if (PIOc_read_darray(ncid2 + TEST_VAL_42, varid, ioid, arraylen, test_data_in) != PIO_EBADID) @@ -235,9 +272,11 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank if ((ret = PIOc_setframe(ncid2, varid, 0))) ERR(ret); + printf("read darray\n"); /* Read the data. */ if ((ret = PIOc_read_darray(ncid2, varid, ioid, arraylen, test_data_in))) ERR(ret); + if(my_rank==0) printf("read darray complete\n"); /* Check the results. */ for (int f = 0; f < arraylen; f++) @@ -260,6 +299,8 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank ERR(ERR_WRONG); } } + if(my_rank==0) printf("data read\n"); + /* Try to write, but it won't work, because we opened file read-only. */ if (!test_multi) @@ -273,10 +314,10 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank fillvalue, flushtodisk) != PIO_EPERM) ERR(ERR_WRONG); } - /* Close the netCDF file. */ if ((ret = PIOc_closefile(ncid2))) ERR(ret); + if(my_rank==0) printf("file closed\n"); } /* next fillvalue test case */ } /* next test multi */ } /* next iotype */ diff --git a/tests/cunit/test_darray_multivar3.c b/tests/cunit/test_darray_multivar3.c index 032560ec1b2..fd3f0b6d019 100644 --- a/tests/cunit/test_darray_multivar3.c +++ b/tests/cunit/test_darray_multivar3.c @@ -148,19 +148,12 @@ int test_multivar_darray(int iosysid, int ioid, int num_flavors, int *flavor, fvp_int))) ERR(ret); - /* This should not work, since the type of the var is - * PIO_FLOAT, and the type of the decomposition is - * PIO_INT. */ -// if (PIOc_write_darray(ncid, varid[2], ioid, arraylen, test_data_float, -// fvp_float) != PIO_EINVAL) -// ERR(ERR_WRONG); - - /* This should also fail, because it mixes an int and a - * float. */ -// int frame[NUM_VAR] = {0, 0, 0}; -// if (PIOc_write_darray_multi(ncid, varid, ioid, NUM_VAR, arraylen * NUM_VAR, test_data_float, -// frame, NULL, 0) != PIO_EINVAL) -// ERR(ERR_WRONG); + /* This should work since an int and a + * float are the same size. */ + int frame[NUM_VAR] = {0, 0, 0}; + if (PIOc_write_darray_multi(ncid, varid, ioid, NUM_VAR, arraylen * NUM_VAR, test_data_float, + frame, NULL, 0) != PIO_EINVAL) + ERR(ret); /* Close the netCDF file. */