Skip to content

Commit

Permalink
Merge pull request ESMCI#1366 from NCAR/ejh_more_codacy
Browse files Browse the repository at this point in the history
more codacy plus combining test_perf1 and test_perf2
  • Loading branch information
edhartnett authored Mar 21, 2019
2 parents 544f6c7 + 79a0e58 commit 38e16a2
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 422 deletions.
3 changes: 1 addition & 2 deletions tests/cunit/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test_darray_multivar3 test_darray_1d test_darray_3d \
test_decomp_uneven test_decomps test_rearr test_darray_async_simple \
test_darray_async test_darray_async_many test_darray_2sync \
test_async_multicomp test_async_multi2 test_async_manyproc \
test_darray_fill test_decomp_frame test_perf1 test_perf2
test_darray_fill test_decomp_frame test_perf2

# Tests will run from a bash script.
TESTS = run_tests.sh
Expand Down Expand Up @@ -59,7 +59,6 @@ test_async_multi2_SOURCES = test_async_multi2.c test_common.c pio_tests.h
test_async_manyproc_SOURCES = test_async_manyproc.c test_common.c pio_tests.h
test_darray_fill_SOURCES = test_darray_fill.c test_common.c pio_tests.h
test_decomp_frame_SOURCES = test_decomp_frame.c test_common.c pio_tests.h
test_perf1_SOURCES = test_perf1.c test_common.c pio_tests.h
test_perf2_SOURCES = test_perf2.c test_common.c pio_tests.h

# Distribute the test script.
Expand Down
8 changes: 8 additions & 0 deletions tests/cunit/pio_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@
return e; \
} while (0)

/** Handle non-MPI errors by finalizing the MPI library and goto
* exit. */
#define BAIL(e) do { \
fprintf(stderr, "%d Error %d in %s, line %d\n", my_rank, e, __FILE__, __LINE__); \
MPI_Finalize(); \
goto exit; \
} while (0)

/** Global err buffer for MPI. When there is an MPI error, this buffer
* is used to store the error message that is associated with the MPI
* error. */
Expand Down
79 changes: 41 additions & 38 deletions tests/cunit/test_darray_async.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,24 @@ int check_darray_file(int iosysid, char *data_filename, int iotype, int my_rank,
{
int ncid;
int varid[NVAR] = {0, 1, 2, 3};
void *data_in;
void *data_in_norec;
void *data_in = NULL;
void *data_in_norec = NULL;
PIO_Offset type_size;
int ret;

/* Reopen the file. */
if ((ret = PIOc_openfile(iosysid, &ncid, &iotype, data_filename, NC_NOWRITE)))
ERR(ret);
BAIL(ret);

/* Get the size of the type. */
if ((ret = PIOc_inq_type(ncid, piotype, NULL, &type_size)))
ERR(ret);
BAIL(ret);

/* Allocate memory to read data. */
if (!(data_in = malloc(LAT_LEN * LON_LEN * type_size * NREC)))
ERR(PIO_ENOMEM);
BAIL(PIO_ENOMEM);
if (!(data_in_norec = malloc(LAT_LEN * LON_LEN * type_size)))
ERR(PIO_ENOMEM);
BAIL(PIO_ENOMEM);

/* We have two sets of variables, those with unlimted, and those
* without unlimited dimension. */
Expand All @@ -90,12 +90,12 @@ int check_darray_file(int iosysid, char *data_filename, int iotype, int my_rank,
/* Read the record data. The values we expect are: 10, 11, 20, 21, 30,
* 31, in each of three records. */
if ((ret = PIOc_get_var(ncid, rec_varid, data_in)))
ERR(ret);
BAIL(ret);

/* Read the non-record data. The values we expect are: 10, 11, 20, 21, 30,
* 31. */
if ((ret = PIOc_get_var(ncid, norec_varid, data_in_norec)))
ERR(ret);
BAIL(ret);

/* Check the results. */
for (int r = 0; r < LAT_LEN * LON_LEN * NREC; r++)
Expand All @@ -105,52 +105,52 @@ int check_darray_file(int iosysid, char *data_filename, int iotype, int my_rank,
{
case PIO_BYTE:
if (((signed char *)data_in)[r] != (tmp_r/2 + 1) * 10 + tmp_r % 2)
ERR(ret);
BAIL(ret);
break;
case PIO_CHAR:
if (((char *)data_in)[r] != (tmp_r/2 + 1) * 10 + tmp_r % 2)
ERR(ret);
BAIL(ret);
break;
case PIO_SHORT:
if (((short *)data_in)[r] != (tmp_r/2 + 1) * 10 + tmp_r % 2)
ERR(ret);
BAIL(ret);
break;
case PIO_INT:
if (((int *)data_in)[r] != (tmp_r/2 + 1) * 10 + tmp_r % 2)
ERR(ret);
BAIL(ret);
break;
case PIO_FLOAT:
if (((float *)data_in)[r] != (tmp_r/2 + 1) * 10.0 + tmp_r % 2)
ERR(ret);
BAIL(ret);
break;
case PIO_DOUBLE:
if (((double *)data_in)[r] != (tmp_r/2 + 1) * 10.0 + tmp_r % 2)
ERR(ret);
BAIL(ret);
break;
#ifdef _NETCDF4
case PIO_UBYTE:
if (((unsigned char *)data_in)[r] != (tmp_r/2 + 1) * 10 + tmp_r % 2)
ERR(ret);
BAIL(ret);
break;
case PIO_USHORT:
if (((unsigned short *)data_in)[r] != (tmp_r/2 + 1) * 10 + tmp_r % 2)
ERR(ret);
BAIL(ret);
break;
case PIO_UINT:
if (((unsigned int *)data_in)[r] != (tmp_r/2 + 1) * 10 + tmp_r % 2)
ERR(ret);
BAIL(ret);
break;
case PIO_INT64:
if (((long long *)data_in)[r] != (tmp_r/2 + 1) * 10 + tmp_r % 2)
ERR(ret);
BAIL(ret);
break;
case PIO_UINT64:
if (((unsigned long long *)data_in)[r] != (tmp_r/2 + 1) * 10 + tmp_r % 2)
ERR(ret);
BAIL(ret);
break;
#endif /* _NETCDF4 */
default:
ERR(ERR_WRONG);
BAIL(ERR_WRONG);
}
}

Expand All @@ -161,65 +161,68 @@ int check_darray_file(int iosysid, char *data_filename, int iotype, int my_rank,
{
case PIO_BYTE:
if (((signed char *)data_in_norec)[r] != (r/2 + 1) * 20.0 + r%2)
ERR(ret);
BAIL(ret);
break;
case PIO_CHAR:
if (((char *)data_in_norec)[r] != (r/2 + 1) * 20.0 + r%2)
ERR(ret);
BAIL(ret);
break;
case PIO_SHORT:
if (((short *)data_in_norec)[r] != (r/2 + 1) * 20.0 + r%2)
ERR(ret);
BAIL(ret);
break;
case PIO_INT:
if (((int *)data_in_norec)[r] != (r/2 + 1) * 20.0 + r%2)
ERR(ret);
BAIL(ret);
break;
case PIO_FLOAT:
if (((float *)data_in_norec)[r] != (r/2 + 1) * 20.0 + r%2)
ERR(ret);
BAIL(ret);
break;
case PIO_DOUBLE:
if (((double *)data_in_norec)[r] != (r/2 + 1) * 20.0 + r%2)
ERR(ret);
BAIL(ret);
break;
#ifdef _NETCDF4
case PIO_UBYTE:
if (((unsigned char *)data_in_norec)[r] != (r/2 + 1) * 20.0 + r%2)
ERR(ret);
BAIL(ret);
break;
case PIO_USHORT:
if (((unsigned short *)data_in_norec)[r] != (r/2 + 1) * 20.0 + r%2)
ERR(ret);
BAIL(ret);
break;
case PIO_UINT:
if (((unsigned int *)data_in_norec)[r] != (r/2 + 1) * 20.0 + r%2)
ERR(ret);
BAIL(ret);
break;
case PIO_INT64:
if (((long long *)data_in_norec)[r] != (r/2 + 1) * 20.0 + r%2)
ERR(ret);
BAIL(ret);
break;
case PIO_UINT64:
if (((unsigned long long *)data_in_norec)[r] != (r/2 + 1) * 20.0 + r%2)
ERR(ret);
BAIL(ret);
break;
#endif /* _NETCDF4 */
default:
ERR(ERR_WRONG);
BAIL(ERR_WRONG);
}
}
} /* next var set */

/* Free resources. */
free(data_in);
free(data_in_norec);

/* Close the file. */
if ((ret = PIOc_closefile(ncid)))
ERR(ret);
BAIL(ret);

return 0;
exit:
/* Free resources. */
if (data_in)
free(data_in);
if (data_in_norec)
free(data_in_norec);

return ret;
}

/* Run a simple test using darrays with async. */
Expand Down
Loading

0 comments on commit 38e16a2

Please sign in to comment.