Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'v3_8_x'
[simgrid.git] / teshsuite / smpi / mpich-test / pt2pt / test.c
1 /* Procedures for recording and printing test results */
2
3 #include <stdio.h>
4 #include <string.h>
5 #include "test.h"
6
7 #if defined(USE_STDARG)
8 #include <stdarg.h>
9 #endif
10
11 static int tests_passed = 0;
12 static int tests_failed = 0;
13 static char failed_tests[255][81];
14 static char suite_name[255];
15 FILE *fileout = NULL;
16
17 void Test_Init(const char *suite, int rank)
18 {
19     char filename[512];
20
21     sprintf(filename, "%s-%d.out", suite, rank);
22     strncpy(suite_name, suite, 255);
23     fileout = fopen(filename, "w");
24     if (!fileout) {
25         fprintf( stderr, "Could not open %s on node %d\n", filename, rank );
26         MPI_Abort( MPI_COMM_WORLD, 1 );
27     }
28
29     //MPI_Errhandler_create( Test_Errors_warn, &TEST_ERRORS_WARN );
30 }
31
32 void Test_Message(const char *mess)
33 {
34     fprintf(fileout, "[%s]: %s\n", suite_name, mess);
35     fflush(fileout);
36 }
37
38 void Test_Failed(const char *test)
39 {
40     fprintf(fileout, "[%s]: *** Test '%s' Failed! ***\n", suite_name, test);
41     strncpy(failed_tests[tests_failed], test, 81);
42     fflush(fileout);
43     tests_failed++;
44 }
45
46 void Test_Passed(const char *test)
47 {
48 #ifdef VERBOSE
49     fprintf(fileout, "[%s]: Test '%s' Passed.\n", suite_name, test);
50     fflush(fileout);
51 #endif
52     tests_passed++;
53 }
54
55 int Summarize_Test_Results()
56 {
57 #ifdef VERBOSE
58     fprintf(fileout, "For test suite '%s':\n", suite_name);
59 #else
60     if (tests_failed > 0)
61 #endif
62     {
63         fprintf(fileout, "Of %d attempted tests, %d passed, %d failed.\n", 
64                 tests_passed + tests_failed, tests_passed, tests_failed);
65     }
66     if (tests_failed > 0) {
67         int i;
68
69         fprintf(fileout, "*** Tests Failed:\n");
70         for (i = 0; i < tests_failed; i++)
71             fprintf(fileout, "*** %s\n", failed_tests[i]);
72     }
73     return tests_failed;
74 }
75
76 void Test_Finalize( void )
77 {
78     //if (TEST_ERRORS_WARN != MPI_ERRHANDLER_NULL) 
79         //MPI_Errhandler_free( &TEST_ERRORS_WARN );
80     if (fileout) {
81         fflush(fileout);
82         //fclose(fileout);
83     }
84 }
85
86 #include "mpi.h"
87 /* Wait for every process to pass through this point.  This test is used
88    to make sure that all processes complete, and that a test "passes" because
89    it executed, not because it some process failed.  
90  */
91 void Test_Waitforall( void )
92 {
93     int m, one, myrank, n;
94
95     MPI_Comm_rank( MPI_COMM_WORLD, &myrank );
96     MPI_Comm_size( MPI_COMM_WORLD, &n );
97     one = 1;
98     MPI_Allreduce( &one, &m, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
99
100     if (m != n) {
101         printf( "[%d] Expected %d processes to wait at end, got %d\n", myrank, 
102                 n, m );
103     }
104     if (myrank == 0) 
105         printf( " No Errors\n" );
106 }
107
108 /*
109    Handler prints warning messsage and returns.  Internal.  Not
110    a part of the standard.
111  */
112 MPI_Errhandler TEST_ERRORS_WARN ;
113
114 #ifdef USE_STDARG
115 void Test_Errors_warn(  MPI_Comm *comm, int *code, ... )
116 {  
117   char buf[MPI_MAX_ERROR_STRING];
118   int  myid; 
119   char *string;
120 #ifdef MPIR_DEBUG
121   char *file;
122   int  *line;
123 #endif
124   static int in_handler = 0;
125   va_list Argp;
126
127 #ifdef USE_OLDSTYLE_STDARG
128   va_start( Argp );
129 #else
130   va_start( Argp, code );
131 #endif
132   string = va_arg(Argp,char *);
133 #ifdef MPIR_DEBUG
134   /* These are only needed for debugging output */
135   file   = va_arg(Argp,char *);
136   line   = va_arg(Argp,int *);
137 #endif
138   va_end( Argp );
139 #else
140 void Test_Errors_warn( MPI_Comm *comm, int *code, char *string, char *file, 
141                        int *line )
142 {
143   char buf[MPI_MAX_ERROR_STRING];
144   int  myid, result_len; 
145   static int in_handler = 0;
146 #endif
147
148   if (in_handler) return;
149   in_handler = 1;
150
151   MPI_Comm_rank( MPI_COMM_WORLD, &myid );
152   //MPI_Error_string( *code, buf, &result_len );
153 #ifdef MPIR_DEBUG
154   /* Generate this information ONLY when debugging MPIR */
155   fprintf( stderr, "%d -  File: %s   Line: %d\n", myid, 
156                    file, *line );
157 #endif
158   fprintf( stderr, "%d - %s : %s\n", myid, 
159           string ? string : "<NO ERROR MESSAGE>", buf );
160   fflush( stderr );
161   in_handler = 0;
162 }