Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid into...
[simgrid.git] / teshsuite / smpi / mpich-test / env / test.c
1 /* Procedures for recording and printing test results */
2
3 #include <stdio.h>
4 #include <string.h>
5 #include "test.h"
6 #include "mpi.h"
7
8 #if defined(USE_STDARG)
9 #include <stdarg.h>
10 #endif
11
12 static int tests_passed = 0;
13 static int tests_failed = 0;
14 static char failed_tests[255][81];
15 static char suite_name[255];
16 FILE *fileout = NULL;
17
18 void Test_Init(suite, rank)
19 char *suite;
20 int rank;
21 {
22     char filename[512];
23
24     sprintf(filename, "%s-%d.out", suite, rank);
25     strncpy(suite_name, suite, 255);
26     fileout = fopen(filename, "w");
27     if (!fileout) {
28         fprintf( stderr, "Could not open %s on node %d\n", filename, rank );
29         MPI_Abort( MPI_COMM_WORLD, 1 );
30     }
31 }
32
33 #ifdef USE_STDARG
34 void Test_Printf(char *format, ...)
35 {
36     va_list arglist;
37
38     va_start(arglist, format);
39     (void)vfprintf(fileout, format, arglist);
40     va_end(arglist);
41 }
42 #else
43 void Test_Printf(va_alist)
44 va_dcl
45 {
46     char *format;
47     va_list arglist;
48
49     va_start(arglist);
50     format = va_arg(arglist, char *);
51     (void)vfprintf(fileout, format, arglist);
52     fflush(fileout);
53     va_end(arglist);
54 }
55 #endif
56
57 void Test_Message(mess)
58 const char *mess;
59 {
60     fprintf(fileout, "[%s]: %s\n", suite_name, mess);
61     fflush(fileout);
62 }
63
64 void Test_Failed(test)
65 const char *test;
66 {
67     fprintf(fileout, "[%s]: *** Test '%s' Failed! ***\n", suite_name, test);
68     strncpy(failed_tests[tests_failed], test, 81);
69     fflush(fileout);
70     tests_failed++;
71 }
72
73 void Test_Passed(test)
74 const char *test;
75 {
76 #ifdef VERBOSE
77     fprintf(fileout, "[%s]: Test '%s' Passed.\n", suite_name, test);
78     fflush(fileout);
79 #endif
80     tests_passed++;
81 }
82
83 int Summarize_Test_Results()
84 {
85 #ifdef VERBOSE
86     fprintf(fileout, "For test suite '%s':\n", suite_name);
87 #else
88     if (tests_failed > 0)
89 #endif
90     {
91         fprintf(fileout, "Of %d attempted tests, %d passed, %d failed.\n", 
92                 tests_passed + tests_failed, tests_passed, tests_failed);
93     }
94     if (tests_failed > 0) {
95         int i;
96
97         fprintf(fileout, "*** Tests Failed:\n");
98         for (i = 0; i < tests_failed; i++)
99             fprintf(fileout, "*** %s\n", failed_tests[i]);
100     }
101     return tests_failed;
102 }
103
104 void Test_Finalize()
105 {
106     fflush(fileout);
107     fclose(fileout);
108 }
109
110 #include "mpi.h"
111 /* Wait for every process to pass through this point.  This test is used
112    to make sure that all processes complete, and that a test "passes" because
113    it executed, not because it some process failed.  
114  */
115 void Test_Waitforall( )
116 {
117 int m, one, myrank, n;
118
119 MPI_Comm_rank( MPI_COMM_WORLD, &myrank );
120 MPI_Comm_size( MPI_COMM_WORLD, &n );
121 one = 1;
122 MPI_Allreduce( &one, &m, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
123
124 if (m != n) {
125     printf( "[%d] Expected %d processes to wait at end, got %d\n", myrank, 
126             n, m );
127     }
128 if (myrank == 0) 
129     printf( " No Errors\n" );
130 }