Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: convert testsuite to be function based #7221

Merged
merged 16 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions test/mpi/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@


/Makefile_mpitests.mtest
/**/Makefile_mpitests.mk
/all_mpitests.c
/run_mpitests
/run_mpitests.stamp
/aclocal.m4
/attr/attr2type
/attr/attrdeleteget
Expand Down
1 change: 1 addition & 0 deletions test/mpi/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

# mix in the "make testing" rule and other boilerplate
include $(top_srcdir)/Makefile_single.mtest
include $(top_srcdir)/Makefile_mpitests.mtest

ACLOCAL_AMFLAGS = -I confdb

Expand Down
9 changes: 8 additions & 1 deletion test/mpi/Makefile_common.mtest
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@
# AM_CPPFLAGS are used for C++ code as well
AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include

run_mpitests_obj = $(top_builddir)/util/librun_mpitests.la
$(top_builddir)/util/librun_mpitests.la: $(top_srcdir)/util/run_mpitests.c
(cd $(top_builddir)/util && $(MAKE) librun_mpitests.la)

$(top_builddir)/run_mpitests.stamp: $(top_srcdir)/util/run_mpitests.c
(cd $(top_builddir) && $(MAKE) run_mpitests && touch run_mpitests.stamp)

# Add libdtpools support
AM_CPPFLAGS += -I$(top_srcdir)/dtpools/include
LDADD = $(top_builddir)/dtpools/src/libdtpools.la
Expand All @@ -25,7 +32,7 @@ TESTDIRS ?= @default_testdirs@
TESTLIST ?= @default_testlist@
SUMMARY_BASENAME ?= summary

testing:
testing: $(top_builddir)/run_mpitests.stamp
$(top_srcdir)/runtests -srcdir=$(srcdir) -tests=$(TESTLIST) -testdirs=$(TESTDIRS) \
-mpiexec="${MPIEXEC}" $(RUNTESTS_OPTS) -xmlfile=$(SUMMARY_BASENAME).xml \
-tapfile=$(SUMMARY_BASENAME).tap -junitfile=$(SUMMARY_BASENAME).junit.xml
Expand Down
1 change: 1 addition & 0 deletions test/mpi/attr/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
##

include $(top_srcdir)/Makefile_single.mtest
include Makefile_mpitests.mk

## for all programs that are just built from the single corresponding source
## file, we don't need per-target _SOURCES rules, automake will infer them
Expand Down
46 changes: 22 additions & 24 deletions test/mpi/attr/attr2type.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,34 @@
* See COPYRIGHT in top-level directory
*/

#include <mpi.h>
#include <stdio.h>
#include <stdlib.h>
#include "mpitest.h"

#ifdef MULTI_TESTS
#define run attr_attr2type
int run(const char *arg);
#endif

static int foo_keyval = MPI_KEYVAL_INVALID;

int foo_initialize(void);
void foo_finalize(void);
static int foo_initialize(void);
static void foo_finalize(void);

int foo_copy_attr_function(MPI_Datatype type, int type_keyval,
void *extra_state, void *attribute_val_in,
void *attribute_val_out, int *flag);
int foo_delete_attr_function(MPI_Datatype type, int type_keyval,
void *attribute_val, void *extra_state);
static int foo_copy_attr_function(MPI_Datatype type, int type_keyval,
void *extra_state, void *attribute_val_in,
void *attribute_val_out, int *flag);
static int foo_delete_attr_function(MPI_Datatype type, int type_keyval,
void *attribute_val, void *extra_state);
static const char *my_func = 0;
static int verbose = 0;
static int delete_called = 0;
static int copy_called = 0;

int main(int argc, char *argv[])
int run(const char *arg)
{
MPI_Datatype type, duptype;
int rank;
int errs = 0;

MTest_Init(&argc, &argv);

MPI_Comm_rank(MPI_COMM_WORLD, &rank);

foo_initialize();
Expand Down Expand Up @@ -61,15 +61,13 @@ int main(int argc, char *argv[])
fflush(stdout);
}

MTest_Finalize(errs);

return MTestReturnValue(errs);
return errs;
}

int foo_copy_attr_function(MPI_Datatype type,
int type_keyval,
void *extra_state,
void *attribute_val_in, void *attribute_val_out, int *flag)
static int foo_copy_attr_function(MPI_Datatype type,
int type_keyval,
void *extra_state,
void *attribute_val_in, void *attribute_val_out, int *flag)
{
if (verbose)
printf("copy fn. called\n");
Expand All @@ -80,8 +78,8 @@ int foo_copy_attr_function(MPI_Datatype type,
return MPI_SUCCESS;
}

int foo_delete_attr_function(MPI_Datatype type,
int type_keyval, void *attribute_val, void *extra_state)
static int foo_delete_attr_function(MPI_Datatype type,
int type_keyval, void *attribute_val, void *extra_state)
{
if (verbose)
printf("delete fn. called in %s\n", my_func);
Expand All @@ -90,7 +88,7 @@ int foo_delete_attr_function(MPI_Datatype type,
return MPI_SUCCESS;
}

int foo_initialize(void)
static int foo_initialize(void)
{
/* create keyval for use later */
MPI_Type_create_keyval(foo_copy_attr_function, foo_delete_attr_function, &foo_keyval, NULL);
Expand All @@ -100,7 +98,7 @@ int foo_initialize(void)
return 0;
}

void foo_finalize(void)
static void foo_finalize(void)
{
/* remove keyval */
MPI_Type_free_keyval(&foo_keyval);
Expand Down
24 changes: 13 additions & 11 deletions test/mpi/attr/attrdeleteget.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,33 @@
* See COPYRIGHT in top-level directory
*/

#include <stdio.h>
#include "mpi.h"
#include "mpitest.h"

int key = MPI_KEYVAL_INVALID;
char a[100];
#ifdef MULTI_TESTS
#define run attr_attrdeleteget
int run(const char *arg);
#endif

static int key = MPI_KEYVAL_INVALID;
static char a[100];

int delete_fn(MPI_Comm, int, void *, void *);
static int delete_fn(MPI_Comm, int, void *, void *);

int main(int argc, char **argv)
int run(const char *arg)
{
MPI_Comm scomm;
int errs = 0;

MTest_Init(&argc, &argv);
MPI_Comm scomm;
MPI_Comm_split(MPI_COMM_WORLD, 1, 0, &scomm);
MPI_Comm_create_keyval(MPI_NULL_COPY_FN, delete_fn, &key, &errs);
MPI_Comm_set_attr(scomm, key, a);
MPI_Comm_free(&scomm);
MPI_Comm_free_keyval(&key);
MTest_Finalize(errs);
return MTestReturnValue(errs);

return errs;
}

int delete_fn(MPI_Comm comm, int keyval, void *attr_val, void *extra_state)
static int delete_fn(MPI_Comm comm, int keyval, void *attr_val, void *extra_state)
{
/* The standard is not explicit that the 'comm' argument of
* delete_fn must be valid, so this test is only in effect when
Expand Down
56 changes: 25 additions & 31 deletions test/mpi/attr/attrend.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,64 +9,58 @@
MPI_Finalize. This is useful for tools that want to perform the MPI
equivalent of an "at_exit" action.
*/
#include <stdio.h>
#include "mpi.h"
/* NOTE: we modified the test to check the delete attributes behavior at
* MPI_Comm_free. The behavior at MPI_Finalize for builtin-comms are covered
* in attrend2.
*/
#include "mpitest.h"

int exit_key = MPI_KEYVAL_INVALID;
int wasCalled = 0;
int foundError = 0;
/* #define DEBUG */
int delete_fn(MPI_Comm, int, void *, void *);
#ifdef DEBUG
#define FFLUSH fflush(stdout);
#else
#define FFLUSH
#ifdef MULTI_TESTS
#define run attr_attrend
int run(const char *arg);
#endif

int main(int argc, char **argv)
{
int errs = 0, wrank;
static int wasCalled = 0;
static int foundError = 0;
static int delete_fn(MPI_Comm, int, void *, void *);

MPI_Init(&argc, &argv);
int run(const char *arg)
{
int errs = 0;
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);

MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
MPI_Comm comm_self;
MPI_Comm_dup(MPI_COMM_SELF, &comm_self);

/* create the keyval for the exit handler */
int exit_key = MPI_KEYVAL_INVALID;
MPI_Keyval_create(MPI_NULL_COPY_FN, delete_fn, &exit_key, (void *) 0);

/* Attach to comm_self */
MPI_Attr_put(MPI_COMM_SELF, exit_key, (void *) 0);
MPI_Attr_put(comm_self, exit_key, (void *) 0);
/* We can free the key now */
MPI_Keyval_free(&exit_key);

/* Now, exit MPI */
MPI_Finalize();
MPI_Comm_free(&comm_self);

/* Check that the exit handler was called, and without error */
if (wrank == 0) {
if (rank == 0) {
/* In case more than one process exits MPI_Finalize */
if (wasCalled != 1) {
errs++;
printf("Attribute delete function on MPI_COMM_SELF was not called\n");
printf("Attribute delete function on comm_self was not called\n");
}
if (foundError != 0) {
errs++;
printf("Found %d errors while executing delete function in MPI_COMM_SELF\n",
foundError);
}
if (errs == 0) {
printf(" No Errors\n");
} else {
printf(" Found %d errors\n", errs);
printf("Found %d errors while executing delete function in comm_self\n", foundError);
}
fflush(stdout);
}

return MTestReturnValue(errs);
return errs;
}

int delete_fn(MPI_Comm comm, int keyval, void *attribute_val, void *extra_state)
static int delete_fn(MPI_Comm comm, int keyval, void *attribute_val, void *extra_state)
{
int flag;
wasCalled++;
Expand Down
33 changes: 16 additions & 17 deletions test/mpi/attr/attrerr.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,21 @@
failure.

*/
#include <stdio.h>
#include "mpi.h"
#include "mpitest.h"

int test_communicators(void);
void abort_msg(const char *, int);
int copybomb_fn(MPI_Comm, int, void *, void *, void *, int *);
int deletebomb_fn(MPI_Comm, int, void *, void *);
#ifdef MULTI_TESTS
#define run attr_attrerr
int run(const char *arg);
#endif

static int test_communicators(void);
static void abort_msg(const char *, int);
static int copybomb_fn(MPI_Comm, int, void *, void *, void *, int *);
static int deletebomb_fn(MPI_Comm, int, void *, void *);

int main(int argc, char **argv)
int run(const char *arg)
{
int errs;
MTest_Init(&argc, &argv);
errs = test_communicators();
MTest_Finalize(errs);
return MTestReturnValue(errs);
return test_communicators();
}

/*
Expand All @@ -37,8 +36,8 @@ int main(int argc, char **argv)
* Proposals to specify particular values (e.g., user's value) failed.
*/
/* Return an error as the value */
int copybomb_fn(MPI_Comm oldcomm, int keyval, void *extra_state,
void *attribute_val_in, void *attribute_val_out, int *flag)
static int copybomb_fn(MPI_Comm oldcomm, int keyval, void *extra_state,
void *attribute_val_in, void *attribute_val_out, int *flag)
{
/* Note that if (sizeof(int) < sizeof(void *), just setting the int
* part of attribute_val_out may leave some dirty bits
Expand All @@ -50,20 +49,20 @@ int copybomb_fn(MPI_Comm oldcomm, int keyval, void *extra_state,
/* Set delete flag to 1 to allow the attribute to be deleted */
static int delete_flag = 0;

int deletebomb_fn(MPI_Comm comm, int keyval, void *attribute_val, void *extra_state)
static int deletebomb_fn(MPI_Comm comm, int keyval, void *attribute_val, void *extra_state)
{
if (delete_flag)
return MPI_SUCCESS;
return MPI_ERR_OTHER;
}

void abort_msg(const char *str, int code)
static void abort_msg(const char *str, int code)
{
fprintf(stderr, "%s, err = %d\n", str, code);
MPI_Abort(MPI_COMM_WORLD, code);
}

int test_communicators(void)
static int test_communicators(void)
{
MPI_Comm dup_comm_world, d2;
int world_rank, world_size, key_1;
Expand Down
Loading