|
Packit |
0848f5 |
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
*
|
|
Packit |
0848f5 |
* (C) 2012 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 |
/*
|
|
Packit |
0848f5 |
* openerr - Test that errors on file open are handled correctly and that the
|
|
Packit |
0848f5 |
* returned error message is accessible
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
#define BUFLEN 10
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
int main(int argc, char *argv[])
|
|
Packit |
0848f5 |
{
|
|
Packit |
0848f5 |
MPI_File fh;
|
|
Packit |
0848f5 |
char emsg[MPI_MAX_ERROR_STRING];
|
|
Packit |
0848f5 |
int emsglen, err, ec, errs = 0;
|
|
Packit |
0848f5 |
int amode, rank;
|
|
Packit |
0848f5 |
char *name = 0;
|
|
Packit |
0848f5 |
MPI_Status st;
|
|
Packit |
0848f5 |
int outbuf[BUFLEN], inbuf[BUFLEN];
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
MTest_Init(&argc, &argv);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
name = "not-a-file-to-use";
|
|
Packit |
0848f5 |
/* Try to open a file that does/should not exist */
|
|
Packit |
0848f5 |
/* Note that no error message should be printed by MPI_File_open,
|
|
Packit |
0848f5 |
* even when there is an error */
|
|
Packit |
0848f5 |
err = MPI_File_open(MPI_COMM_WORLD, name, MPI_MODE_RDONLY, MPI_INFO_NULL, &fh;;
|
|
Packit |
0848f5 |
if (err == MPI_SUCCESS) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
printf("Did not return error when opening a file that does not exist\n");
|
|
Packit |
0848f5 |
MPI_File_close(&fh;;
|
|
Packit |
0848f5 |
MPI_File_delete(name, MPI_INFO_NULL);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else {
|
|
Packit |
0848f5 |
MPI_Error_class(err, &ec);
|
|
Packit |
0848f5 |
MPI_Error_string(err, emsg, &emsglen);
|
|
Packit |
0848f5 |
MTestPrintfMsg(2, "Error msg from open: %s\n", emsg);
|
|
Packit |
0848f5 |
if (ec != MPI_ERR_NO_SUCH_FILE && ec != MPI_ERR_IO) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
printf("Did not return class ERR_NO_SUCH_FILE or ERR_IO\n");
|
|
Packit |
0848f5 |
printf("Returned class %d, message %s\n", ec, emsg);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* Now, create a file, write data into it; close, then reopen as
|
|
Packit |
0848f5 |
* read only and try to write to it */
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
amode = MPI_MODE_CREATE | MPI_MODE_WRONLY;
|
|
Packit |
0848f5 |
name = "mpio-test-openerrs";
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
err = MPI_File_open(MPI_COMM_WORLD, name, amode, MPI_INFO_NULL, &fh;;
|
|
Packit |
0848f5 |
if (err) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
MTestPrintErrorMsg("Unable to open file for writing", err);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else {
|
|
Packit |
0848f5 |
MPI_Comm_rank(MPI_COMM_WORLD, &rank;;
|
|
Packit |
0848f5 |
memset(outbuf, 'A' + rank, BUFLEN);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
err = MPI_File_write_at(fh, rank * BUFLEN, outbuf, BUFLEN, MPI_BYTE, &st);
|
|
Packit |
0848f5 |
if (err) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
MTestPrintErrorMsg("Unable to write file", err);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
MPI_File_close(&fh;;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* Now, open for read only, and delete on close */
|
|
Packit |
0848f5 |
amode = MPI_MODE_RDONLY | MPI_MODE_DELETE_ON_CLOSE;
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
err = MPI_File_open(MPI_COMM_WORLD, name, amode, MPI_INFO_NULL, &fh;;
|
|
Packit |
0848f5 |
if (err) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
MTestPrintErrorMsg("Unable to reopen file for reading", err);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else {
|
|
Packit |
0848f5 |
/* Try to read it */
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* Clear buffer before reading into it */
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
memset(inbuf, 0, BUFLEN);
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
err = MPI_File_read_at(fh, rank * BUFLEN, inbuf, BUFLEN, MPI_BYTE, &st);
|
|
Packit |
0848f5 |
if (err) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
MTestPrintErrorMsg("Unable to read file", err);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* Try to write it (should fail) */
|
|
Packit |
0848f5 |
err = MPI_File_write_at(fh, rank * BUFLEN, outbuf, BUFLEN, MPI_BYTE, &st);
|
|
Packit |
0848f5 |
if (err == MPI_SUCCESS) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
printf("Write operation succeeded to read-only file\n");
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else {
|
|
Packit |
0848f5 |
/* Look at error class */
|
|
Packit |
0848f5 |
MPI_Error_class(err, &ec);
|
|
Packit |
0848f5 |
if (ec != MPI_ERR_READ_ONLY && ec != MPI_ERR_ACCESS) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
printf("Unexpected error class %d when writing to read-only file\n", ec);
|
|
Packit |
0848f5 |
MTestPrintErrorMsg("Error msg is: ", err);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
err = MPI_File_close(&fh;;
|
|
Packit |
0848f5 |
if (err) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
MTestPrintErrorMsg("Failed to close", err);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/* No MPI_Barrier is required here */
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
/*
|
|
Packit |
0848f5 |
* Test open without CREATE to see if DELETE_ON_CLOSE worked.
|
|
Packit |
0848f5 |
* This should fail if file was deleted correctly.
|
|
Packit |
0848f5 |
*/
|
|
Packit |
0848f5 |
|
|
Packit |
0848f5 |
amode = MPI_MODE_RDONLY;
|
|
Packit |
0848f5 |
err = MPI_File_open(MPI_COMM_WORLD, name, amode, MPI_INFO_NULL, &fh;;
|
|
Packit |
0848f5 |
if (err == MPI_SUCCESS) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
printf("File was not deleted!\n");
|
|
Packit |
0848f5 |
MPI_File_close(&fh;;
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
else {
|
|
Packit |
0848f5 |
MPI_Error_class(err, &ec);
|
|
Packit |
0848f5 |
if (ec != MPI_ERR_NO_SUCH_FILE && ec != MPI_ERR_IO) {
|
|
Packit |
0848f5 |
errs++;
|
|
Packit |
0848f5 |
printf("Did not return class ERR_NO_SUCH_FILE or ERR_IO\n");
|
|
Packit |
0848f5 |
printf("Returned class %d, message %s\n", ec, emsg);
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
Packit |
0848f5 |
}
|
|
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 |
}
|