Skip to content

Commit

Permalink
add some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed Feb 13, 2019
1 parent bffeeb9 commit e41d24f
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 22 deletions.
2 changes: 1 addition & 1 deletion src/clib/pio_darray_int.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down
57 changes: 49 additions & 8 deletions tests/cunit/test_darray.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
{
Expand All @@ -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])))
Expand All @@ -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);
Expand All @@ -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
{
Expand All @@ -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)))
Expand All @@ -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)
Expand All @@ -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++)
Expand All @@ -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)
Expand All @@ -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 */
Expand Down
19 changes: 6 additions & 13 deletions tests/cunit/test_darray_multivar3.c
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down

0 comments on commit e41d24f

Please sign in to comment.