Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add tests for errhandlers
authorAugustin Degomme <adegomme@users.noreply.github.com>
Sun, 18 Aug 2019 18:40:32 +0000 (20:40 +0200)
committerAugustin Degomme <adegomme@users.noreply.github.com>
Sun, 18 Aug 2019 19:08:00 +0000 (21:08 +0200)
Most of them actually need mpi_add_error features, which are not really implemented yet

teshsuite/smpi/mpich3-test/errhan/CMakeLists.txt [new file with mode: 0644]
teshsuite/smpi/mpich3-test/errhan/adderr.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/errhan/commcall.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/errhan/dynamic_errcode_predefined_errclass.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/errhan/errfatal.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/errhan/errstring2.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/errhan/predef_eh.c [new file with mode: 0644]
teshsuite/smpi/mpich3-test/errhan/testlist [new file with mode: 0644]
tools/cmake/DefinePackages.cmake

diff --git a/teshsuite/smpi/mpich3-test/errhan/CMakeLists.txt b/teshsuite/smpi/mpich3-test/errhan/CMakeLists.txt
new file mode 100644 (file)
index 0000000..5d4ec3a
--- /dev/null
@@ -0,0 +1,28 @@
+if(enable_smpi AND enable_smpi_MPICH3_testsuite)
+  if(WIN32)
+    set(CMAKE_C_FLAGS "-include ${CMAKE_HOME_DIRECTORY}/include/smpi/smpi_main.h")
+  else()
+    set(CMAKE_C_COMPILER "${CMAKE_BINARY_DIR}/smpi_script/bin/smpicc")
+    set(CMAKE_Fortran_COMPILER "${CMAKE_BINARY_DIR}/smpi_script/bin/smpiff")
+  endif()
+
+  include_directories(BEFORE "${CMAKE_HOME_DIRECTORY}/include/smpi")
+  include_directories("${CMAKE_CURRENT_SOURCE_DIR}/../include/")
+
+  foreach(file adderr commcall errfatal predef_eh errstring2 dynamic_errcode_predefined_errclass)
+    add_executable(${file} EXCLUDE_FROM_ALL ${file}.c)
+    add_dependencies(tests ${file})
+    target_link_libraries(${file} simgrid mtest_c)
+  endforeach()
+endif()
+
+if (enable_smpi_MPICH3_testsuite AND HAVE_RAW_CONTEXTS)
+  ADD_TEST(test-smpi-mpich3-errhan-raw       ${CMAKE_COMMAND} -E chdir ${CMAKE_BINARY_DIR}/teshsuite/smpi/mpich3-test/errhan ${PERL_EXECUTABLE} ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/mpich3-test/runtests "-wrapper=${TESH_WRAPPER}" -mpiexec=${CMAKE_BINARY_DIR}/smpi_script/bin/smpirun -srcdir=${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/mpich3-test/errhan -tests=testlist -execarg=--cfg=contexts/factory:raw)
+  SET_TESTS_PROPERTIES(test-smpi-mpich3-errhan-raw PROPERTIES PASS_REGULAR_EXPRESSION "tests passed!")
+endif()
+
+foreach(file adderr commcall errfatal predef_eh errstring2 dynamic_errcode_predefined_errclass)
+  set(examples_src  ${examples_src} ${CMAKE_CURRENT_SOURCE_DIR}/${file}.c)
+endforeach()
+set(examples_src  ${examples_src}                                        PARENT_SCOPE)
+set(txt_files     ${txt_files}     ${CMAKE_CURRENT_SOURCE_DIR}/testlist  PARENT_SCOPE)
diff --git a/teshsuite/smpi/mpich3-test/errhan/adderr.c b/teshsuite/smpi/mpich3-test/errhan/adderr.c
new file mode 100644 (file)
index 0000000..8c3dcfc
--- /dev/null
@@ -0,0 +1,63 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2003 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+#include "mpi.h"
+#include <stdio.h>
+#include <stdlib.h>
+#include "mpitest.h"
+#include "mpitestconf.h"
+#ifdef HAVE_STRING_H
+#include <string.h>
+#endif
+
+/* Create NCLASSES new classes, each with 5 codes (160 total) */
+#define NCLASSES 32
+#define NCODES   5
+
+int main(int argc, char *argv[])
+{
+    int errs = 0;
+    char string[MPI_MAX_ERROR_STRING], outstring[MPI_MAX_ERROR_STRING];
+    int newclass[NCLASSES], newcode[NCLASSES][NCODES];
+    int i, j, slen, outclass;
+
+    MTest_Init(&argc, &argv);
+
+    /* Initialize the new codes */
+    for (i = 0; i < NCLASSES; i++) {
+        MPI_Add_error_class(&newclass[i]);
+        for (j = 0; j < NCODES; j++) {
+            MPI_Add_error_code(newclass[i], &newcode[i][j]);
+            sprintf(string, "code for class %d code %d\n", i, j);
+            MPI_Add_error_string(newcode[i][j], string);
+        }
+    }
+
+    /* check the values */
+    for (i = 0; i < NCLASSES; i++) {
+        MPI_Error_class(newclass[i], &outclass);
+        if (outclass != newclass[i]) {
+            errs++;
+            printf("Error class %d is not a valid error code %d %d\n", i, outclass, newclass[i]);
+        }
+        for (j = 0; j < NCODES; j++) {
+            MPI_Error_class(newcode[i][j], &outclass);
+            if (outclass != newclass[i]) {
+                errs++;
+                printf("Class of code for %d is not correct %d %d\n", j, outclass, newclass[i]);
+            }
+            MPI_Error_string(newcode[i][j], outstring, &slen);
+            sprintf(string, "code for class %d code %d\n", i, j);
+            if (strcmp(outstring, string)) {
+                errs++;
+                printf("Error string is :%s: but should be :%s:\n", outstring, string);
+            }
+        }
+    }
+
+    MTest_Finalize(errs);
+    return MTestReturnValue(errs);
+}
diff --git a/teshsuite/smpi/mpich3-test/errhan/commcall.c b/teshsuite/smpi/mpich3-test/errhan/commcall.c
new file mode 100644 (file)
index 0000000..28e88ed
--- /dev/null
@@ -0,0 +1,93 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2003 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+#include "mpi.h"
+#include <stdio.h>
+#include "mpitest.h"
+
+/*
+static char MTEST_Descrip[] = "Test comm_call_errhandler";
+*/
+
+static int calls = 0;
+static int errs = 0;
+static MPI_Comm mycomm;
+void eh(MPI_Comm * comm, int *err, ...);
+void eh(MPI_Comm * comm, int *err, ...)
+{
+    if (*err != MPI_ERR_OTHER) {
+        errs++;
+        printf("Unexpected error code\n");
+    }
+    if (*comm != mycomm) {
+        errs++;
+        printf("Unexpected communicator\n");
+    }
+    calls++;
+    return;
+}
+
+int main(int argc, char *argv[])
+{
+    MPI_Comm comm;
+    MPI_Errhandler newerr;
+    int i;
+    int reset_handler;
+
+    MTest_Init(&argc, &argv);
+
+    comm = MPI_COMM_WORLD;
+    mycomm = comm;
+
+    MPI_Comm_create_errhandler(eh, &newerr);
+
+    MPI_Comm_set_errhandler(comm, newerr);
+    MPI_Comm_call_errhandler(comm, MPI_ERR_OTHER);
+    MPI_Errhandler_free(&newerr);
+    if (calls != 1) {
+        errs++;
+        printf("Error handler not called\n");
+    }
+
+    /* Here we apply the test to many copies of a communicator */
+    for (reset_handler = 0; reset_handler <= 1; ++reset_handler) {
+        for (i = 0; i < 1000; i++) {
+            MPI_Comm comm2;
+            calls = 0;
+            MPI_Comm_dup(MPI_COMM_WORLD, &comm);
+            mycomm = comm;
+            MPI_Comm_create_errhandler(eh, &newerr);
+
+            MPI_Comm_set_errhandler(comm, newerr);
+            MPI_Comm_call_errhandler(comm, MPI_ERR_OTHER);
+            if (calls != 1) {
+                errs++;
+                printf("Error handler not called\n");
+            }
+            MPI_Comm_dup(comm, &comm2);
+            calls = 0;
+            mycomm = comm2;
+            /* comm2 must inherit the error handler from comm */
+            MPI_Comm_call_errhandler(comm2, MPI_ERR_OTHER);
+            if (calls != 1) {
+                errs++;
+                printf("Error handler not called\n");
+            }
+
+            if (reset_handler) {
+                /* extra checking of the reference count handling */
+                MPI_Comm_set_errhandler(comm, MPI_ERRORS_ARE_FATAL);
+            }
+            MPI_Errhandler_free(&newerr);
+
+            MPI_Comm_free(&comm);
+            MPI_Comm_free(&comm2);
+        }
+    }
+
+    MTest_Finalize(errs);
+    return MTestReturnValue(errs);
+}
diff --git a/teshsuite/smpi/mpich3-test/errhan/dynamic_errcode_predefined_errclass.c b/teshsuite/smpi/mpich3-test/errhan/dynamic_errcode_predefined_errclass.c
new file mode 100644 (file)
index 0000000..d697e6f
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ *  (C) 2006 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ *
+ *  Portions of this code were written by Intel Corporation.
+ *  Copyright (C) 2011-2012 Intel Corporation.  Intel provides this material
+ *  to Argonne National Laboratory subject to Software Grant and Corporate
+ *  Contributor License Agreement dated February 8, 2012.
+ */
+
+#include <stdio.h>
+#include <mpi.h>
+#include "mpitest.h"
+
+int main(int argc, char **argv)
+{
+    int errcode, errclass, errs = 0;
+
+    MTest_Init(&argc, &argv);
+
+    MPI_Add_error_code(MPI_ERR_ARG, &errcode);
+    MPI_Error_class(errcode, &errclass);
+
+    if (errclass != MPI_ERR_ARG) {
+        printf("ERROR: Got 0x%d, expected 0x%d\n", errclass, MPI_ERR_ARG);
+        errs++;
+    }
+
+    MTest_Finalize(errs);
+    return MTestReturnValue(errs);
+}
diff --git a/teshsuite/smpi/mpich3-test/errhan/errfatal.c b/teshsuite/smpi/mpich3-test/errhan/errfatal.c
new file mode 100644 (file)
index 0000000..0e9f55a
--- /dev/null
@@ -0,0 +1,46 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *  (C) 2004 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+#include <mpi.h>
+#include <stdio.h>
+
+/* FIXME: This behavior of this test is implementation specific. */
+
+static int verbose = 0;
+
+int main(int argc, char **argv)
+{
+    int MY_ERROR_CLASS;
+    int MY_ERROR_CODE;
+    char MY_ERROR_STRING[10];
+
+    sprintf(MY_ERROR_STRING, "MY ERROR");
+
+    MPI_Init(&argc, &argv);
+
+    if (verbose)
+        printf("Adding My Error Class\n");
+    MPI_Add_error_class(&MY_ERROR_CLASS);
+    if (verbose)
+        printf("Adding My Error Code\n");
+    MPI_Add_error_code(MY_ERROR_CLASS, &MY_ERROR_CODE);
+    if (verbose)
+        printf("Adding My Error String\n");
+    MPI_Add_error_string(MY_ERROR_CODE, MY_ERROR_STRING);
+
+    if (verbose)
+        printf("Calling Error Handler\n");
+    MPI_Comm_call_errhandler(MPI_COMM_WORLD, MY_ERROR_CODE);
+
+    /* We should not get here, because the default error handler
+     * is ERRORS_ARE_FATAL.  This makes sure that the correct error
+     * handler is called and that no failure occured (such as
+     * a SEGV) in Comm_call_errhandler on the default
+     * error handler. */
+    printf("After the Error Handler Has Been Called\n");
+
+    MPI_Finalize();
+    return 0;
+}
diff --git a/teshsuite/smpi/mpich3-test/errhan/errstring2.c b/teshsuite/smpi/mpich3-test/errhan/errstring2.c
new file mode 100644 (file)
index 0000000..e12aafe
--- /dev/null
@@ -0,0 +1,28 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *  (C) 2014 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+#include <stdio.h>
+#include <mpi.h>
+#include <string.h>
+#include "mpitest.h"
+
+int main(int argc, char *argv[])
+{
+    int errorclass;
+    char errorstring[MPI_MAX_ERROR_STRING] = { 64, 0 };
+    int slen;
+    int errs = 0;
+
+    MTest_Init(&argc, &argv);
+    MPI_Add_error_class(&errorclass);
+    MPI_Error_string(errorclass, errorstring, &slen);
+    if (strncmp(errorstring, "", 1)) {
+        fprintf(stderr, "errorclass:%d errorstring:'%s' len:%d\n", errorclass, errorstring, slen);
+        errs++;
+    }
+    MTest_Finalize(errs);
+    return MTestReturnValue(errs);
+}
diff --git a/teshsuite/smpi/mpich3-test/errhan/predef_eh.c b/teshsuite/smpi/mpich3-test/errhan/predef_eh.c
new file mode 100644 (file)
index 0000000..b7e6ccc
--- /dev/null
@@ -0,0 +1,35 @@
+/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
+/*
+ *
+ *  (C) 2012 by Argonne National Laboratory.
+ *      See COPYRIGHT in top-level directory.
+ */
+
+#include <stdio.h>
+#include <assert.h>
+#include <stdlib.h>
+#include "mpi.h"
+#include "mpitest.h"
+
+/* Ensure that setting a user-defined error handler on predefined
+ * communicators does not cause a problem at finalize time.  Regression
+ * test for ticket #1591 */
+void errf(MPI_Comm * comm, int *ec);
+void errf(MPI_Comm * comm, int *ec)
+{
+    /* do nothing */
+}
+
+int main(int argc, char **argv)
+{
+    MPI_Errhandler errh;
+    int wrank;
+    MTest_Init(&argc, &argv);
+    MPI_Comm_rank(MPI_COMM_WORLD, &wrank);
+    MPI_Comm_create_errhandler((MPI_Comm_errhandler_function *) errf, &errh);
+    MPI_Comm_set_errhandler(MPI_COMM_WORLD, errh);
+    MPI_Comm_set_errhandler(MPI_COMM_SELF, errh);
+    MPI_Errhandler_free(&errh);
+    MTest_Finalize(0);
+    return 0;
+}
diff --git a/teshsuite/smpi/mpich3-test/errhan/testlist b/teshsuite/smpi/mpich3-test/errhan/testlist
new file mode 100644 (file)
index 0000000..9cf33b8
--- /dev/null
@@ -0,0 +1,9 @@
+#needs MPI_Error_class
+#adderr 1
+commcall 2
+errfatal 1 resultTest=TestErrFatal
+predef_eh 1
+predef_eh 2
+#needs MPI_Error_class and such
+#errstring2 1
+#dynamic_errcode_predefined_errclass 1
index 297daab..2be9a38 100644 (file)
@@ -1011,6 +1011,7 @@ set(CMAKEFILES_TXT
   teshsuite/smpi/mpich3-test/coll/CMakeLists.txt
   teshsuite/smpi/mpich3-test/comm/CMakeLists.txt
   teshsuite/smpi/mpich3-test/datatype/CMakeLists.txt
   teshsuite/smpi/mpich3-test/coll/CMakeLists.txt
   teshsuite/smpi/mpich3-test/comm/CMakeLists.txt
   teshsuite/smpi/mpich3-test/datatype/CMakeLists.txt
+  teshsuite/smpi/mpich3-test/errhan/CMakeLists.txt
   teshsuite/smpi/mpich3-test/f77/attr/CMakeLists.txt
   teshsuite/smpi/mpich3-test/f77/coll/CMakeLists.txt
   teshsuite/smpi/mpich3-test/f77/info/CMakeLists.txt
   teshsuite/smpi/mpich3-test/f77/attr/CMakeLists.txt
   teshsuite/smpi/mpich3-test/f77/coll/CMakeLists.txt
   teshsuite/smpi/mpich3-test/f77/info/CMakeLists.txt