Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
teshsuite: smpi: MBI: Merge change form MBI.
[simgrid.git] / teshsuite / smpi / MBI / P2PMatchingGenerator.py
1 #! /usr/bin/python3
2 import os
3 import sys
4 import generator_utils as gen
5
6 template = """// @{generatedby}@
7 /* ///////////////////////// The MPI Bugs Initiative ////////////////////////
8
9   Origin: MBI
10
11   Description: @{shortdesc}@
12     @{longdesc}@
13
14   Version of MPI: Conforms to MPI 1.1, does not require MPI 2 implementation
15
16 BEGIN_MPI_FEATURES
17   P2P!basic: @{p2pfeature}@
18   P2P!nonblocking: @{ip2pfeature}@
19   P2P!persistent: @{persfeature}@
20   COLL!basic: Lacking
21   COLL!nonblocking: Lacking
22   COLL!persistent: Lacking
23   COLL!tools: Lacking
24   RMA: Lacking
25 END_MPI_FEATURES
26
27 BEGIN_MBI_TESTS
28   $ mpirun -np 2 ${EXE}
29   | @{outcome}@
30   | @{errormsg}@
31 END_MBI_TESTS
32 //////////////////////       End of MBI headers        /////////////////// */
33
34 #include <mpi.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37
38 #define buff_size 1
39
40 int main(int argc, char **argv) {
41   int nprocs = -1;
42   int rank = -1;
43   int its_raining = 0;
44   int src=0, dest=1;
45   int stag=0, rtag=0;
46
47   MPI_Init(&argc, &argv);
48   MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
49   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
50   printf("Hello from rank %d \\n", rank);
51
52   if (nprocs < 2)
53     printf("MBI ERROR: This test needs at least 2 processes to produce a bug!\\n");
54
55   MPI_Comm newcom = MPI_COMM_WORLD;
56   MPI_Datatype type = MPI_INT;
57
58   @{init1}@
59   @{init2}@
60
61   if (rank == 0) {
62     @{operation1}@ /* MBIERROR1 */
63     @{fini1}@
64   }else if (@{change_cond}@){
65     @{operation2}@ /* MBIERROR2 */
66     @{fini2}@
67   }
68
69   @{free1}@
70   @{free2}@
71
72   MPI_Finalize();
73   printf("Rank %d finished normally\\n", rank);
74   return 0;
75 }
76 """
77
78
79 for p in gen.send + gen.ssend + gen.bsend + gen.recv + gen.irecv + gen.isend:
80     patterns = {}
81     patterns = {'p': p}
82     patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
83     patterns['p2pfeature'] = 'Yes' if p in gen.send + gen.bsend + gen.ssend + gen.recv else 'Lacking'
84     patterns['ip2pfeature'] = 'Yes' if p in gen.isend + gen.irecv else 'Lacking'
85     patterns['persfeature'] = 'Lacking'
86     # patterns['persfeature'] = 'Yes' if p in gen.psend + gen.precv else 'Lacking'
87     patterns['p'] = p
88     patterns['init1'] = gen.init[p]("1")
89     patterns['init2'] = '' #gen.init[p2]("2")
90     patterns['fini1'] = gen.fini[p]("1")
91     patterns['fini2'] = '' #gen.fini[p2]("2")
92     patterns['free1'] = gen.free[p]("1")
93     patterns['free2'] = '' #gen.free[p]("2")
94     patterns['operation1'] = gen.operation[p]("1")
95     patterns['operation2'] = '' #gen.operation[p2]("2")
96     patterns['change_cond'] = 'rank == 1'
97
98     # Generate the incorrect matching with one call
99     replace = patterns.copy()
100     replace['shortdesc'] = 'Point to point @{p}@ is not matched'
101     replace['longdesc'] = 'Process 0 calls @{p}@ and is not matched'
102     replace['outcome'] = 'ERROR: CallMatching'
103     replace['errormsg'] = 'P2P mistmatch. @{p}@ at @{filename}@:@{line:MBIERROR1}@ is not matched.'
104     gen.make_file(template, f'CallOrdering_{p}_nok.c', replace)
105
106     # Generate the incorrect matching with two calls
107     replace = patterns.copy()
108     replace['shortdesc'] = 'Both point to point @{p}@ are not matched'
109     replace['longdesc'] = 'Processes 0 and 1 both call @{p}@ which are not matched'
110     replace['outcome'] = 'ERROR: CallMatching'
111     replace['errormsg'] = 'P2P mismatch. @{p}@ at @{filename}@:@{line:MBIERROR1}@ and @{p}@ at @{filename}@:@{line:MBIERROR2}@ are not matched.'
112     replace['operation2'] = gen.operation[p]("1")
113     replace['fini2'] = gen.fini[p]("1")
114     #replace['free2'] = gen.free[p]("2")
115     gen.make_file(template, f'CallOrdering_{p}_{p}_nok.c', replace)
116
117 for s in gen.send + gen.isend + gen.ssend + gen.bsend:
118     for r in gen.recv + gen.irecv:
119         patterns = {}
120         patterns = {'s': s, 'r': r}
121         patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
122         patterns['p2pfeature'] = 'Yes' if s in gen.send or r in gen.recv else 'Lacking'
123         patterns['ip2pfeature'] = 'Yes' if s in gen.isend or r in gen.irecv else 'Lacking'
124         patterns['persfeature'] = 'Lacking'
125         patterns['s'] = s
126         patterns['r'] = r
127         patterns['init1'] = gen.init[s]("1")
128         patterns['init2'] = gen.init[r]("2")
129         patterns['fini1'] = gen.fini[s]("1")
130         patterns['fini2'] = gen.fini[r]("2")
131         patterns['free1'] = gen.free[s]("1")
132         patterns['free2'] = gen.free[r]("2")
133         patterns['operation1'] = gen.operation[s]("1")
134         patterns['operation2'] = gen.operation[r]("2")
135         patterns['change_cond'] = '(rank == 1) && (its_raining)'
136
137         # Generate the incorrect matching because of the conditional
138         replace = patterns.copy()
139         replace['shortdesc'] = 'Point to point @{r}@ is never called.'
140         replace['longdesc'] = 'Point to point @{r}@ is never executed. Process 1 calls MPI_Finalize and causes a deadlock.'
141         replace['outcome'] = 'ERROR: CallMatching'
142         replace['errormsg'] = 'P2P mistmatch. @{r}@ at @{filename}@:@{line:MBIERROR2}@ is never called because of the conditional (@{change_cond}@).'
143         replace['operation1'] = gen.operation[s]("1")
144         replace['operation2'] = gen.operation[r]("2")
145         gen.make_file(template, f'CallOrdering_{r}_{s}_nok.c', replace)