Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add mpich3 test suite, to replace older one.
[simgrid.git] / teshsuite / smpi / mpich-test / context / 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 const 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 const char *mess;
31 {
32     fprintf(fileout, "[%s]: %s\n", suite_name, mess);
33     fflush(fileout);
34 }
35
36 void Test_Failed(test)
37 const 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 const char *test;
47 {
48     fprintf(fileout, "[%s]: Test '%s' Passed.\n", suite_name, test);
49     fflush(fileout);
50     tests_passed++;
51 }
52
53 int Summarize_Test_Results()
54 {
55     fprintf(fileout, "For test suite '%s':\n", suite_name);
56     fprintf(fileout, "Of %d attempted tests, %d passed, %d failed.\n", 
57             tests_passed + tests_failed, tests_passed, tests_failed);
58     if (tests_failed > 0) {
59         int i;
60
61         fprintf(fileout, "*** Tests Failed:\n");
62         for (i = 0; i < tests_failed; i++)
63             fprintf(fileout, "*** %s\n", failed_tests[i]);
64     }
65     return tests_failed;
66 }
67
68 void Test_Finalize()
69 {
70     fflush(fileout);
71     fclose(fileout);
72 }
73
74 #include "mpi.h"
75 /* Wait for every process to pass through this point.  This test is used
76    to make sure that all processes complete, and that a test "passes" because
77    it executed, not because it some process failed.  
78  */
79 void Test_Waitforall( )
80 {
81 int m, one, myrank, n;
82
83 MPI_Comm_rank( MPI_COMM_WORLD, &myrank );
84 MPI_Comm_size( MPI_COMM_WORLD, &n );
85 one = 1;
86 MPI_Allreduce( &one, &m, 1, MPI_INT, MPI_SUM, MPI_COMM_WORLD );
87
88 if (m != n) {
89     printf( "[%d] Expected %d processes to wait at end, got %d\n", myrank, 
90             n, m );
91     }
92 if (myrank == 0) 
93     printf( "All processes completed test\n" );
94 }