Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
first commit to add the mpich-test suite to smpi tesh suite. Obviously all tests...
[simgrid.git] / teshsuite / smpi / mpich-test / topol / 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(suite, rank)
15 char *suite;
16 int rank;
17 {
18     char filename[512];
19
20     sprintf(filename, "%s-%d.out", suite, rank);
21     strncpy(suite_name, suite, 255);
22     fileout = fopen(filename, "w");
23     if (!fileout) {
24         fprintf( stderr, "Could not open %s on node %d\n", filename, rank );
25         MPI_Abort( MPI_COMM_WORLD, 1 );
26     }
27 }
28
29 void Test_Message(mess)
30 char *mess;
31 {
32     fprintf(fileout, "[%s]: %s\n", suite_name, mess);
33     fflush(fileout);
34 }
35
36 void Test_Failed(test)
37 char *test;
38 {
39     fprintf(fileout, "[%s]: *** Test '%s' Failed! ***\n", suite_name, test);
40     strncpy(failed_tests[tests_failed], test, 81);
41     fflush(fileout);
42     tests_failed++;
43 }
44
45 void Test_Passed(test)
46 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()
77 {
78     fflush(fileout);
79     fclose(fileout);
80 }
81
82 #include "mpi.h"
83 /* Wait for every process to pass through this point.  This test is used
84    to make sure that all processes complete, and that a test "passes" because
85    it executed, not because it some process failed.  
86  */
87 void Test_Waitforall( )
88 {
89 int m, one, myrank, n;
90
91 MPI_Comm_rank( MPI_COMM_WORLD, &myrank );
92 MPI_Comm_size( MPI_COMM_WORLD, &n );
93 one = 1;
94 MPI_Allreduce( &one, &m, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
95
96 if (m != n) {
97     printf( "[%d] Expected %d processes to wait at end, got %d\n", myrank, 
98             n, m );
99     }
100 if (myrank == 0) 
101     printf( " No Errors\n" );
102 }