Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add mpich3 test suite, to replace older one.
[simgrid.git] / teshsuite / smpi / mpich-test / coll / 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 static int tests_passed = 0;
9 static int tests_failed = 0;
10 static char failed_tests[255][81];
11 static char suite_name[255];
12 FILE *fileout = NULL;
13
14 void Test_Init( const char *suite, int rank)
15 {
16     char filename[512];
17
18     sprintf(filename, "%s-%d.out", suite, rank);
19     strncpy(suite_name, suite, 255);
20     fileout = fopen(filename, "w");
21     if (!fileout) {
22         fprintf( stderr, "Could not open %s on node %d\n", filename, rank );
23         MPI_Abort( MPI_COMM_WORLD, 1 );
24     }
25 }
26
27 void Test_Message( const char *mess)
28 {
29     fprintf(fileout, "[%s]: %s\n", suite_name, mess);
30     if(fileout)fflush(fileout);
31 }
32
33 void Test_Failed(const char *test)
34 {
35     fprintf(fileout, "[%s]: *** Test '%s' Failed! ***\n", suite_name, test);
36     strncpy(failed_tests[tests_failed], test, 81);
37     if(fileout)fflush(fileout);
38     tests_failed++;
39 }
40
41 void Test_Passed(const char *test)
42 {
43 #ifdef VERBOSE
44     fprintf(fileout, "[%s]: Test '%s' Passed.\n", suite_name, test);
45     if(fileout)fflush(fileout);
46 #endif
47     tests_passed++;
48 }
49
50 int Summarize_Test_Results(void)
51 {
52 #ifdef VERBOSE
53     fprintf(fileout, "For test suite '%s':\n", suite_name);
54 #else
55     if (tests_failed > 0)
56 #endif
57     {
58         fprintf(fileout, "Of %d attempted tests, %d passed, %d failed.\n", 
59                 tests_passed + tests_failed, tests_passed, tests_failed);
60     }
61     if (tests_failed > 0) {
62         int i;
63
64         fprintf(fileout, "*** Tests Failed:\n");
65         for (i = 0; i < tests_failed; i++)
66             fprintf(fileout, "*** %s\n", failed_tests[i]);
67     }
68     return tests_failed;
69 }
70
71 void Test_Finalize(void)
72 {
73     if(fileout)fflush(fileout);
74     //fclose(fileout);
75 }
76
77 #include "mpi.h"
78 /* Wait for every process to pass through this point.  This test is used
79    to make sure that all processes complete, and that a test "passes" because
80    it executed, not because some process failed.  
81  */
82 void Test_Waitforall(void)
83 {
84     int m, one, myrank, n;
85
86     MPI_Comm_rank( MPI_COMM_WORLD, &myrank );
87     MPI_Comm_size( MPI_COMM_WORLD, &n );
88     one = 1;
89     MPI_Allreduce( &one, &m, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
90
91     if (m != n) {
92         printf( "[%d] Expected %d processes to wait at end, got %d\n", myrank, 
93             n, m );
94     }
95     if (myrank == 0) 
96         printf( " No Errors\n" );
97 }