Blame test/mpi/errors/io/fileerrret.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/*
Packit 0848f5
 *
Packit 0848f5
 *  (C) 2006 by Argonne National Laboratory.
Packit 0848f5
 *      See COPYRIGHT in top-level directory.
Packit 0848f5
 */
Packit 0848f5
#include "mpi.h"
Packit 0848f5
#include "mpitestconf.h"
Packit 0848f5
#include <stdio.h>
Packit 0848f5
Packit 0848f5
#ifdef HAVE_STRING_H
Packit 0848f5
#include <string.h>
Packit 0848f5
#endif
Packit 0848f5
#include "mpitest.h"
Packit 0848f5
Packit 0848f5
static int ncalls = 0;
Packit 0848f5
void efn(MPI_File * fh, int *code, ...);
Packit 0848f5
void efn(MPI_File * fh, int *code, ...)
Packit 0848f5
{
Packit 0848f5
    ncalls++;
Packit 0848f5
    *code = MPI_SUCCESS;
Packit 0848f5
}
Packit 0848f5
Packit 0848f5
int main(int argc, char *argv[])
Packit 0848f5
{
Packit 0848f5
    MPI_File fh;
Packit 0848f5
    MPI_Errhandler eh;
Packit 0848f5
    char filename[10];
Packit 0848f5
    int errs = 0, rc;
Packit 0848f5
Packit 0848f5
    MTest_Init(&argc, &argv);
Packit 0848f5
Packit 0848f5
    /* Test that the default error handler is errors return for files */
Packit 0848f5
    strncpy(filename, "t1", sizeof(filename));
Packit 0848f5
Packit 0848f5
    rc = MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_RDWR, MPI_INFO_NULL, &fh;;
Packit 0848f5
    if (!rc) {
Packit 0848f5
        errs++;
Packit 0848f5
        printf("Did not get error from open for writing without CREATE\n");
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    /* Test that we can change the default error handler by changing
Packit 0848f5
     * the error handler on MPI_FILE_NULL. */
Packit 0848f5
    MPI_File_create_errhandler(efn, &eh;;
Packit 0848f5
    MPI_File_set_errhandler(MPI_FILE_NULL, eh);
Packit 0848f5
    MPI_Errhandler_free(&eh;;
Packit 0848f5
Packit 0848f5
    rc = MPI_File_open(MPI_COMM_WORLD, filename, MPI_MODE_RDWR, MPI_INFO_NULL, &fh;;
Packit 0848f5
    if (rc) {
Packit 0848f5
        errs++;
Packit 0848f5
        printf("Returned error from open (should have called error handler instead)\n");
Packit 0848f5
    }
Packit 0848f5
    if (ncalls != 1) {
Packit 0848f5
        errs++;
Packit 0848f5
        printf
Packit 0848f5
            ("Did not invoke error handler when opening a non-existent file for writing and reading (without MODE_CREATE)\n");
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    /* Find out how many errors we saw */
Packit 0848f5
    MTest_Finalize(errs);
Packit 0848f5
    MPI_Finalize();
Packit 0848f5
Packit 0848f5
    return 0;
Packit 0848f5
}