Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add mpich3 test suite, to replace older one.
[simgrid.git] / teshsuite / smpi / mpich-test / env / testerr.c
1 #include <stdio.h>
2 #include "mpi.h"
3 /* Test error handling.  This is MPICH specific */
4 void Test_Send( void );
5 void Test_Recv( void );
6 void Test_Datatype( void );
7 void Test_Errors_warn( MPI_Comm *comm, int *code, ... );
8 void Test_Failed( const char * msg );
9 void Test_Passed(const char * msg );
10
11 void Test_Errors_warn( MPI_Comm *comm, int *code, ... )
12 {  
13   char buf[MPI_MAX_ERROR_STRING+1];
14   int  result_len; 
15   static int in_handler = 0;
16
17   if (in_handler) return;
18   in_handler = 1;
19   /* Convert code to message and print */
20   MPI_Error_string( *code, buf, &result_len );
21   printf( "%s\n", buf );
22   in_handler = 0;
23 }  
24
25 static int errcount = 0;
26 void Test_Failed( const char * msg )
27 {
28     printf( "FAILED: %s\n", msg );
29     errcount++;
30 }
31 void Test_Passed(const char * msg )
32 {
33     printf( "Passed: %s\n", msg );
34 }
35
36 int main( int argc, char *argv[] )
37 {
38     MPI_Errhandler TEST_ERRORS_WARN;
39
40     MPI_Init( &argc, &argv );
41
42     MPI_Errhandler_create( Test_Errors_warn, &TEST_ERRORS_WARN );
43     MPI_Errhandler_set(MPI_COMM_WORLD, TEST_ERRORS_WARN);
44
45     Test_Send();
46
47     Test_Recv();
48
49     Test_Datatype();
50
51     MPI_Finalize();
52
53     return 0;
54 }
55
56 void Test_Send( void )
57 {
58     int buffer[100];
59     int dest;
60     MPI_Datatype bogus_type = MPI_DATATYPE_NULL;
61     int myrank, size;
62     int large_tag, flag, small_tag;
63     int *tag_ubp;
64
65     MPI_Comm_rank( MPI_COMM_WORLD, &myrank );
66     MPI_Comm_size( MPI_COMM_WORLD, &size );
67     dest = size - 1;
68
69     if (MPI_Send(buffer, 20, MPI_INT, dest,
70                  1, MPI_COMM_NULL) == MPI_SUCCESS){
71         Test_Failed("NULL Communicator Test");
72     }
73     else
74         Test_Passed("NULL Communicator Test");
75
76     if (MPI_Send(buffer, -1, MPI_INT, dest,
77                  1, MPI_COMM_WORLD) == MPI_SUCCESS){
78         Test_Failed("Invalid Count Test");
79     }
80     else
81         Test_Passed("Invalid Count Test");
82
83     if (MPI_Send(buffer, 20, bogus_type, dest,
84                  1, MPI_COMM_WORLD) == MPI_SUCCESS){
85         Test_Failed("Invalid Type Test");
86     }
87     else
88         Test_Passed("Invalid Type Test");
89
90     small_tag = -1;
91     if (small_tag == MPI_ANY_TAG) small_tag = -2;
92     if (MPI_Send(buffer, 20, MPI_INT, dest, 
93                  small_tag, MPI_COMM_WORLD) == MPI_SUCCESS) {
94         Test_Failed("Invalid Tag Test");
95     }
96     else
97         Test_Passed("Invalid Tag Test");
98
99     /* Form a tag that is too large */
100     MPI_Attr_get( MPI_COMM_WORLD, MPI_TAG_UB, (void **)&tag_ubp, &flag );
101     if (!flag) Test_Failed("Could not get tag ub!" );
102     large_tag = *tag_ubp + 1;
103     if (large_tag > *tag_ubp) {
104         if (MPI_Send(buffer, 20, MPI_INT, dest, 
105                      -1, MPI_COMM_WORLD) == MPI_SUCCESS) {
106             Test_Failed("Invalid Tag Test");
107             }
108         else
109             Test_Passed("Invalid Tag Test");
110         }
111
112     if (MPI_Send(buffer, 20, MPI_INT, 300,
113                  1, MPI_COMM_WORLD) == MPI_SUCCESS) {
114         Test_Failed("Invalid Destination Test");
115     }
116     else
117         Test_Passed("Invalid Destination Test");
118
119     if (MPI_Send((void *)0, 10, MPI_INT, dest,
120                  1, MPI_COMM_WORLD) == MPI_SUCCESS){
121         Test_Failed("Invalid Buffer Test (send)");
122     }
123     else
124         Test_Passed("Invalid Buffer Test (send)");
125 }
126
127 void Test_Recv( void )
128 {
129 }
130
131 void Test_Datatype( void )
132 {
133 }
134     
135 #ifdef FOO
136 void
137 ReceiverTest3()
138 {
139     int buffer[20];
140     MPI_Datatype bogus_type = MPI_DATATYPE_NULL;
141     MPI_Status status;
142     int myrank;
143     int *tag_ubp;
144     int large_tag, flag, small_tag;
145
146     MPI_Comm_rank( MPI_COMM_WORLD, &myrank );
147
148     if (myrank == 0) {
149         fprintf( stderr, 
150 "There should be eight error messages about invalid communicator\n\
151 count argument, datatype argument, tag, rank, buffer send and buffer recv\n" );
152         }
153
154     /* A receive test might not fail until it is triggered... */
155     if (MPI_Recv((void *)0, 10, MPI_INT, src,
156                  15, MPI_COMM_WORLD, &status) == MPI_SUCCESS){
157         Test_Failed("Invalid Buffer Test (recv)");
158     }
159     else
160         Test_Passed("Invalid Buffer Test (recv)");
161
162     /* Just to keep things happy, see if there is a message to receive */
163     { int flag, ibuf[10];
164
165     MPI_Iprobe( src, 15, MPI_COMM_WORLD, &flag, &status );
166     if (flag) 
167         MPI_Recv( ibuf, 10, MPI_INT, src, 15, MPI_COMM_WORLD, &status );
168     }
169     return;
170 #endif