Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid
[simgrid.git] / teshsuite / smpi / MBI / InputHazardGenerator.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: Lacking
20   COLL!basic: @{collfeature}@
21   COLL!nonblocking: @{icollfeature}@
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} 1
29   | @{outcome1}@
30   | @{errormsg1}@
31   $ mpirun -np 2 ${EXE} 2
32   | @{outcome2}@
33   | @{errormsg2}@
34 END_MBI_TESTS
35 //////////////////////       End of MBI headers        /////////////////// */
36
37 #include <mpi.h>
38 #include <stdio.h>
39 #include <stdlib.h>
40
41 #define N 10
42
43 int main(int argc, char **argv) {
44   int nprocs = -1;
45   int rank = -1;
46   MPI_Status sta;
47   int i=0;
48   int root = 0;
49   int stag=0;
50   int rtag=0;
51   int buff_size = N;
52
53   MPI_Init(&argc, &argv);
54   MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
55   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
56   printf("Hello from rank %d \\n", rank);
57
58   if (nprocs < 2)
59     printf("MBI ERROR: This test needs at least 2 processes to produce a bug!\\n");
60
61   if (argc < 2)
62     printf("MBI ERROR: This test needs at least 1 argument to produce a bug!\\n");
63
64   int dbs = sizeof(int)*nprocs; /* Size of the dynamic buffers for alltoall and friends */
65   MPI_Comm newcom = MPI_COMM_WORLD;
66   MPI_Datatype type = MPI_INT;
67   MPI_Op op = MPI_SUM;
68
69   int n = atoi(argv[1]);
70   int buffer[N] = {42};
71
72   @{init1}@
73   @{init2}@
74
75   if (rank == 0) {
76     if ((n % 2) == 0) { @{errorcond}@
77       @{operation1b}@
78       @{fini1b}@
79     } else {
80       @{operation1a}@
81       @{fini1a}@
82     }
83   } else @{addcond}@ {
84     @{operation2}@
85     @{fini2}@
86   }
87
88   @{free1}@
89   @{free2}@
90
91   MPI_Finalize();
92
93   printf("Rank %d finished normally\\n", rank);
94   return 0;
95 }
96 """
97
98 # P2P
99 for s in gen.send + gen.isend:
100     for r in gen.recv + gen.irecv:
101         patterns = {}
102         patterns = {'s': s, 'r': r}
103         patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
104         patterns['p2pfeature'] = 'Yes' if s in gen.send or r in gen.recv else 'Lacking'
105         patterns['ip2pfeature'] = 'Yes' if s in gen.isend or r in gen.irecv else 'Lacking'
106         patterns['collfeature'] = 'Lacking'
107         patterns['icollfeature'] = 'Lacking'
108         patterns['s'] = s
109         patterns['r'] = r
110
111         patterns['init1'] = gen.init[s]("1")
112         patterns['operation1a'] = gen.operation[s]("1").replace("buf1", "buffer").replace("dest", "1")
113         patterns['operation1b'] = gen.operation[s]("1").replace("buf1", "buffer").replace("dest", "1")
114         patterns['fini1a'] = gen.fini[s]("1")
115         patterns['fini1b'] = gen.fini[s]("1")
116         patterns['free1'] = gen.free[s]("1")
117
118         patterns['init2'] = gen.init[r]("2")
119         patterns['operation2'] = gen.operation[r]("2").replace("buf2", "buffer").replace("src", "0")
120         patterns['fini2'] = gen.fini[r]("2")
121         patterns['free2'] = gen.free[r]("2")
122
123         patterns['errorcond'] = ''
124         patterns['addcond'] = 'if (rank == 1)'
125
126         # Generate a correct matching
127         replace = patterns.copy()
128         replace['shortdesc'] = 'Correct call ordering.'
129         replace['longdesc'] = 'Correct call ordering.'
130         replace['outcome1'] = 'OK'
131         replace['errormsg1'] = 'OK'
132         replace['outcome2'] = 'OK'
133         replace['errormsg2'] = 'OK'
134         gen.make_file(template, f'InputHazardCallOrdering_{r}_{s}_ok.c', replace)
135
136         # Generate the incorrect matching
137         replace = patterns.copy()
138         replace['shortdesc'] = 'Missing Send function.'
139         replace['longdesc'] = 'Missing Send function call for a path depending to input, a deadlock is created.'
140         replace['outcome1'] = 'OK'
141         replace['errormsg1'] = 'OK'
142         replace['outcome2'] = 'ERROR: IHCallMatching'
143         replace['errormsg2'] = 'P2P mistmatch. Missing @{r}@ at @{filename}@:@{line:MBIERROR}@.'
144         replace['errorcond'] = '/* MBIERROR */'
145         replace['operation1b'] = ''
146         replace['fini1b'] = ''
147         gen.make_file(template, f'InputHazardCallOrdering_{r}_{s}_nok.c', replace)
148
149 # COLLECTIVE
150 for c in gen.coll:
151     patterns = {}
152     patterns = {'c': c}
153     patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
154     patterns['p2pfeature'] = 'Lacking'
155     patterns['ip2pfeature'] = 'Lacking'
156     patterns['collfeature'] = 'Yes' if c in gen.coll else 'Lacking'
157     patterns['icollfeature'] = 'Yes' if c in gen.icoll else 'Lacking'
158     patterns['c'] = c
159
160     patterns['init1'] = gen.init[c]("1")
161     patterns['operation1a'] = gen.operation[c]("1")
162     patterns['operation1b'] = gen.operation[c]("1")
163     patterns['fini1a'] = gen.fini[c]("1")
164     patterns['fini1b'] = gen.fini[c]("1")
165     patterns['free1'] = gen.free[c]("1")
166
167     patterns['init2'] = gen.init[c]("2")
168     patterns['operation2'] = gen.operation[c]("2")
169     patterns['fini2'] = gen.fini[c]("2")
170     patterns['free2'] = gen.free[c]("2")
171
172     patterns['errorcond'] = ''
173     patterns['addcond'] = ''
174
175     # Generate a correct matching
176     replace = patterns.copy()
177     replace['shortdesc'] = 'Correct call ordering.'
178     replace['longdesc'] = 'Correct call ordering.'
179     replace['outcome1'] = 'OK'
180     replace['errormsg1'] = 'OK'
181     replace['outcome2'] = 'OK'
182     replace['errormsg2'] = 'OK'
183     gen.make_file(template, f'InputHazardCallOrdering_{c}_ok.c', replace)
184
185     # Generate the incorrect matching
186     replace = patterns.copy()
187     replace['shortdesc'] = 'Missing collective function call.'
188     replace['longdesc'] = 'Missing collective function call for a path depending to input, a deadlock is created.'
189     replace['outcome1'] = 'OK'
190     replace['errormsg1'] = 'OK'
191     replace['outcome2'] = 'ERROR: IHCallMatching'
192     replace['errormsg2'] = 'P2P mistmatch. Missing @{c}@ at @{filename}@:@{line:MBIERROR}@.'
193     replace['errorcond'] = '/* MBIERROR */'
194     replace['operation1b'] = ''
195     replace['fini1b'] = ''
196     gen.make_file(template, f'InputHazardCallOrdering_{c}_nok.c', replace)