Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Sync MBI generators with upstream modifications
[simgrid.git] / teshsuite / smpi / MBI / MissingWaitandStartGenerator.py
1 #! /usr/bin/python3
2 import os
3 import sys
4 from generator_utils import *
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: Lacking
18         P2P!nonblocking: @{ip2pfeature}@
19         P2P!persistent: @{persfeature}@
20         COLL!basic: Lacking
21         COLL!nonblocking: @{icollfeature}@
22         COLL!persistent: @{cpersfeature}@
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
39 int main(int argc, char **argv) {
40   int nprocs = -1;
41   int rank = -1;
42         int root = 0;
43
44   MPI_Init(&argc, &argv);
45   MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
46   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
47   printf("Hello from rank %d \\n", rank);
48
49   if (nprocs < 2)
50     printf("MBI ERROR: This test needs at least 2 processes to produce a bug!\\n");
51
52         MPI_Comm newcom = MPI_COMM_WORLD;
53         MPI_Datatype type = MPI_INT;
54   MPI_Op op = MPI_SUM;
55         int stag = 0, rtag = 0;
56   int buff_size = 1;
57
58         int dbs = sizeof(int)*nprocs; /* Size of the dynamic buffers for alltoall and friends */
59
60   int dest = (rank == nprocs - 1) ? (0) : (rank + 1);
61   int src = (rank == 0) ? (nprocs - 1) : (rank - 1); 
62
63   @{init1}@
64   @{init2}@
65
66   @{operation1}@ /* MBIERROR */ 
67   @{start1}@
68   @{operation2}@ 
69   @{start2}@
70
71         @{fini1}@ 
72         @{fini2}@  
73
74         @{free1}@
75         @{free2}@
76
77   MPI_Finalize();
78   printf("Rank %d finished normally\\n", rank);
79   return 0;
80 }
81 """
82
83
84 for s in isend + psend:
85     for r in irecv + precv:
86         patterns = {}
87         patterns = {'s': s, 'r': r}
88         patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'  
89         patterns['persfeature'] = 'Yes' if s in psend or r in precv  else 'Lacking'
90         patterns['ip2pfeature'] = 'Yes' if s in isend or r in irecv  else 'Lacking' 
91         patterns['icollfeature'] = 'Lacking' 
92         patterns['cpersfeature'] = 'Lacking' 
93         patterns['s'] = s 
94         patterns['r'] = r 
95         patterns['init1'] = init[s]("1") 
96         patterns['init2'] = init[r]("2") 
97         patterns['start1'] = start[s]("1") 
98         startPers = patterns['start1'] 
99         patterns['start2'] = start[r]("2")
100         patterns['operation1'] = operation[s]("1") 
101         patterns['operation2'] = operation[r]("2") 
102         patterns['fini1'] = fini[s]("1") 
103         wait = patterns['fini1'] 
104         patterns['fini2'] = fini[r]("2") 
105         patterns['free1'] = free[s]("1") 
106         Reqfree = patterns['free1'] 
107         patterns['free2'] = free[r]("2") 
108
109                                 # Generate the correct code
110         replace = patterns 
111         replace['shortdesc'] = 'Correct matching' 
112         replace['longdesc'] = f'No error'
113         replace['outcome'] = 'OK' 
114         replace['errormsg'] = 'OK' 
115         make_file(template, f'ReqLifecycle_{s}_{r}_ok.c', replace)
116
117                                 # Generate the code with a missing wait
118         replace = patterns 
119         replace['shortdesc'] = 'Missing wait' 
120         replace['longdesc'] = 'Missing Wait. @{s}@ at @{filename}@:@{line:MBIERROR}@ has no completion.' 
121         replace['outcome'] = 'ERROR: MissingWait' 
122         replace['errormsg'] = 'ERROR: MissingWait' 
123         replace['fini1'] =  ' /* MBIERROR MISSING: ' + wait + ' */' 
124         make_file(template, f'ReqLifecycle_MissingWait_{s}_{r}_nok.c', replace)
125                 
126         if s in psend:
127                                         # Generate the code with a missing start - persistent only
128             replace = patterns
129             replace['shortdesc'] = 'Missing start'
130             replace['longdesc'] = 'Missing start. @{s}@ at @{filename}@:@{line:MBIERROR}@ has no start'
131             replace['outcome'] = 'ERROR: MissingStart'
132             replace['errormsg'] = 'ERROR: MissingStart'
133             replace['fini1'] = fini[s]("1")
134             replace['start1'] = ' /* MBIERROR MISSING: ' + startPers + ' */'
135             make_file(template, f'ReqLifecycle_MissingStart_{s}_{r}_nok.c', replace) 
136                                         # Generate the code with a missing free - persistent only
137             replace = patterns
138             replace['shortdesc'] = 'Missing free'
139             replace['longdesc'] = 'Missing free. @{s}@ at @{filename}@:@{line:MBIERROR}@ has no free'
140             replace['outcome'] = 'ERROR: RequestLeak'
141             replace['errormsg'] = 'ERROR: RequestLeak'
142             replace['start1'] = start[s]("1")
143             replace['free1'] = ' /* MBIERROR MISSING: ' + Reqfree + ' */'
144             make_file(template, f'ResLeak_nofree_{s}_{r}_nok.c', replace) 
145
146
147 # Collectives only
148 for c in pcoll + icoll + ibarrier:
149     patterns = {}
150     patterns = {'c': c}
151     patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
152     patterns['persfeature'] = 'Lacking'
153     patterns['ip2pfeature'] = 'Lacking'
154     patterns['cpersfeature'] = 'Yes' if c in pcoll else 'Lacking'
155     patterns['icollfeature'] = 'Yes' if c in icoll + ibarrier else 'Lacking'
156     patterns['c'] = c
157     patterns['init1'] = init[c]("1")
158     patterns['operation1'] = operation[c]("1")
159     patterns['start1'] = start[c]("1") 
160     patterns['fini1'] = fini[c]("1")
161     patterns['free1'] = free[c]("1")
162     opstart = patterns['start1']
163     opwait = patterns['fini1'] 
164     opfree = patterns['free1'] 
165     patterns['init2'] = ""
166     patterns['operation2'] = ""
167     patterns['start2'] = ""
168     patterns['fini2'] = "" 
169     patterns['free2'] = "" 
170
171                 # Generate the code with a missing wait 
172     replace = patterns
173     replace['shortdesc'] = 'Missing wait'
174     replace['longdesc'] = 'Missing Wait. @{c}@ at @{filename}@:@{line:MBIERROR}@ has no completion' 
175     replace['outcome'] = 'ERROR: MissingWait'
176     replace['errormsg'] = 'ERROR: MissingWait'
177     replace['fini1'] = ' /* MBIERROR MISSING: ' + opwait + ' */' 
178     replace['free1'] = ' /* MISSING: ' + replace['free1'] + ' (to not free the buffer before an internal wait */'
179     make_file(template, f'ReqLifecycle_MissingWait_{c}_nok.c', replace)
180
181     if c in pcoll:              
182                           # Generate the code with a missing start - persistent only
183         replace = patterns 
184         replace['shortdesc'] = 'Missing start functio' 
185         replace['longdesc'] = 'Missing Start. @{c}@ at @{filename}@:@{line:MBIERROR}@ has no start' 
186         replace['outcome'] = 'ERROR: MissingStart'
187         replace['errormsg'] = 'ERROR: MissingStart'
188         replace['fini1'] = fini[c]("1") 
189         replace['start1'] = ' /* MBIERROR MISSING: ' + opstart + ' */' 
190         make_file(template, f'ReqLifecycle_MissingStart_{c}_nok.c', replace)
191
192                           # Generate the code with a resleak (no free) - persistent only
193         replace = patterns
194         replace['shortdesc'] = 'Missing free'
195         replace['longdesc'] = 'Missing free. @{c}@ at @{filename}@:@{line:MBIERROR}@ has no free' 
196         replace['outcome'] = 'ERROR: RequestLeak'
197         replace['errormsg'] = 'ERROR: RequestLeak'
198         replace['start1'] = start[c]("1")
199         replace['free1'] = ' /* MBIERROR MISSING: ' + opfree + ' */' 
200         make_file(template, f'ResLeak_nofree_{c}_nok.c', replace)