Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
899e810f969afdd72ed1d4cf57825fb6aa46853b
[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   | @{outcome}@
30   | @{errormsg}@
31   $ mpirun -np 2 ${EXE} 2
32   | @{outcome}@
33   | @{errormsg}@
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['outcome'] = 'OK'
131         replace['errormsg'] = 'OK'
132         gen.make_file(template, f'InputHazardCallOrdering_{r}_{s}_ok.c', replace)
133
134         # Generate the incorrect matching
135         replace = patterns.copy()
136         replace['shortdesc'] = 'Missing Send function.'
137         replace['longdesc'] = 'Missing Send function call for a path depending to input, a deadlock is created.'
138         replace['outcome'] = 'ERROR: IHCallMatching'
139         replace['errormsg'] = 'P2P mistmatch. Missing @{r}@ at @{filename}@:@{line:MBIERROR}@.'
140         replace['errorcond'] = '/* MBIERROR */'
141         replace['operation1b'] = ''
142         replace['fini1b'] = ''
143         gen.make_file(template, f'InputHazardCallOrdering_{r}_{s}_nok.c', replace)
144
145 # COLLECTIVE
146 for c in gen.coll:
147     patterns = {}
148     patterns = {'c': c}
149     patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
150     patterns['p2pfeature'] = 'Lacking'
151     patterns['ip2pfeature'] = 'Lacking'
152     patterns['collfeature'] = 'Yes' if c in gen.coll else 'Lacking'
153     patterns['icollfeature'] = 'Yes' if c in gen.icoll else 'Lacking'
154     patterns['c'] = c
155
156     patterns['init1'] = gen.init[c]("1")
157     patterns['operation1a'] = gen.operation[c]("1")
158     patterns['operation1b'] = gen.operation[c]("1")
159     patterns['fini1a'] = gen.fini[c]("1")
160     patterns['fini1b'] = gen.fini[c]("1")
161     patterns['free1'] = gen.free[c]("1")
162
163     patterns['init2'] = gen.init[c]("2")
164     patterns['operation2'] = gen.operation[c]("2")
165     patterns['fini2'] = gen.fini[c]("2")
166     patterns['free2'] = gen.free[c]("2")
167
168     patterns['errorcond'] = ''
169     patterns['addcond'] = ''
170
171     # Generate a correct matching
172     replace = patterns.copy()
173     replace['shortdesc'] = 'Correct call ordering.'
174     replace['longdesc'] = 'Correct call ordering.'
175     replace['outcome'] = 'OK'
176     replace['errormsg'] = 'OK'
177     gen.make_file(template, f'InputHazardCallOrdering_{c}_ok.c', replace)
178
179     # Generate the incorrect matching
180     replace = patterns.copy()
181     replace['shortdesc'] = 'Missing collective function call.'
182     replace['longdesc'] = 'Missing collective function call for a path depending to input, a deadlock is created.'
183     replace['outcome'] = 'ERROR: IHCallMatching'
184     replace['errormsg'] = 'P2P mistmatch. Missing @{c}@ at @{filename}@:@{line:MBIERROR}@.'
185     replace['errorcond'] = '/* MBIERROR */'
186     replace['operation1b'] = ''
187     replace['fini1b'] = ''
188     gen.make_file(template, f'InputHazardCallOrdering_{c}_nok.c', replace)