Skip to content

Commit

Permalink
fix the fillvalue in test
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards4b committed Feb 14, 2019
1 parent e41d24f commit 55887b8
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions tests/cunit/test_darray.c
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank
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 *fillvalue, *ofillvalue;
void *test_data;
void *test_data_in;
int fillvalue_int = NC_FILL_INT;
Expand Down Expand Up @@ -119,7 +119,6 @@ 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 @@ -146,7 +145,6 @@ 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 @@ -165,14 +163,23 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank
// 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);
switch (other_type)
{
case PIO_INT:
ofillvalue = provide_fill ? &fillvalue_int : NULL;
break;
case PIO_FLOAT:
ofillvalue = provide_fill ? &fillvalue_float : NULL;
break;
default:
break;
}
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)))
Expand All @@ -184,7 +191,6 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank
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 @@ -195,17 +201,15 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank
if (PIOc_write_darray(ncid, TEST_VAL_42, ioid, arraylen, test_data, fillvalue) != PIO_ENOTVAR)
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)))
if (other_type && (ret = PIOc_write_darray(ncid, varid2, ioid, arraylen, test_data, ofillvalue))){
printf("other_type %d ret %d fillvalue %x\n",other_type, ret, 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 Down Expand Up @@ -246,7 +250,6 @@ 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)))
Expand All @@ -259,7 +262,6 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank
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 @@ -272,11 +274,9 @@ 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 @@ -299,8 +299,6 @@ 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 @@ -317,7 +315,6 @@ int test_darray(int iosysid, int ioid, int num_flavors, int *flavor, int my_rank
/* 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

0 comments on commit 55887b8

Please sign in to comment.