Skip to content

Commit

Permalink
working on memory warning in test_rearr.c
Browse files Browse the repository at this point in the history
  • Loading branch information
edhartnett committed Mar 25, 2019
1 parent c2c8d29 commit 3422b55
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tests/cunit/pio_tests.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
fprintf(stderr, "MPI error, line %d, file %s: %s\n", __LINE__, __FILE__, err_buffer); \
MPI_Finalize(); \
ret = NC_EMPI; \
goto ecit; \
goto exit; \
} while (0)

/** Handle non-MPI errors by finalizing the MPI library and exiting
Expand Down
68 changes: 59 additions & 9 deletions tests/cunit/test_rearr.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,18 +479,18 @@ int test_expand_region()
}

/* Test define_iodesc_datatypes() function. */
int test_define_iodesc_datatypes()
int test_define_iodesc_datatypes(int my_rank)
{
#define NUM_REARRANGERS 2
int rearranger[NUM_REARRANGERS] = {PIO_REARR_BOX, PIO_REARR_SUBSET};
io_desc_t iodesc;
int mpierr;
int ret;
int ret = PIO_NOERR;

/* Run the functon. */
for (int r = 0; r < NUM_REARRANGERS; r++)
{
iosystem_desc_t ios;
io_desc_t iodesc;

/* Set up test for IO task with BOX rearranger to create one type. */
ios.ioproc = 1; /* this is IO proc. */
Expand All @@ -500,15 +500,21 @@ int test_define_iodesc_datatypes()
iodesc.nrecvs = 1; /* Number of types created. */
iodesc.mpitype = MPI_INT;
iodesc.stype = NULL; /* Array of MPI types will be created here. */
iodesc.rcount = NULL;
iodesc.rfrom = NULL;
iodesc.rindex = NULL;
iodesc.scount = NULL;
iodesc.sindex = NULL;
iodesc.rtype = NULL;

/* Allocate space for arrays in iodesc that will be filled in
* define_iodesc_datatypes(). */
if (!(iodesc.rcount = malloc(iodesc.nrecvs * sizeof(int))))
return PIO_ENOMEM;
BAIL(PIO_ENOMEM);
if (!(iodesc.rfrom = malloc(iodesc.nrecvs * sizeof(int))))
return PIO_ENOMEM;
BAIL(PIO_ENOMEM);
if (!(iodesc.rindex = malloc(1 * sizeof(PIO_Offset))))
return PIO_ENOMEM;
BAIL(PIO_ENOMEM);
iodesc.rindex[0] = 0;
iodesc.rcount[0] = 1;

Expand Down Expand Up @@ -541,16 +547,60 @@ int test_define_iodesc_datatypes()
MPIERR(mpierr);

/* Free resources. */
if (iodesc.rtype)
{
free(iodesc.rtype);
iodesc.rtype = NULL;
}
if (iodesc.sindex)
{
free(iodesc.sindex);
iodesc.sindex = NULL;
}
if (iodesc.scount)
{
free(iodesc.scount);
iodesc.scount = NULL;
}
if (iodesc.stype)
{
free(iodesc.stype);
iodesc.stype = NULL;
}
if (iodesc.rcount)
{
free(iodesc.rcount);
iodesc.rcount = NULL;
}
if (iodesc.rfrom)
{
free(iodesc.rfrom);
iodesc.rfrom = NULL;
}
if (iodesc.rindex)
{
free(iodesc.rindex);
iodesc.rindex = NULL;
}
}

exit:
if (iodesc.rtype)
free(iodesc.rtype);
if (iodesc.sindex)
free(iodesc.sindex);
if (iodesc.scount)
free(iodesc.scount);
if (iodesc.stype)
free(iodesc.stype);
if (iodesc.rcount)
free(iodesc.rcount);
if (iodesc.rfrom)
free(iodesc.rfrom);
if (iodesc.rindex)
free(iodesc.rindex);
}

return 0;
return ret;
}

/* Test the compute_counts() function with the box rearranger. */
Expand Down Expand Up @@ -1188,7 +1238,7 @@ int run_no_iosys_tests(int my_rank, MPI_Comm test_comm)
if ((ret = test_create_mpi_datatypes()))
return ret;

if ((ret = test_define_iodesc_datatypes()))
if ((ret = test_define_iodesc_datatypes(my_rank)))
return ret;

if ((ret = test_compare_offsets()))
Expand Down

0 comments on commit 3422b55

Please sign in to comment.