Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add the remaining MBI generators
[simgrid.git] / teshsuite / smpi / MBI / P2PMatchingGenerator.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: @{p2pfeature}@ 
18         P2P!nonblocking: @{ip2pfeature}@
19         P2P!persistent: @{persfeature}0@
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 128
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         if (rank == 0) {
61         @{operation1}@ /* MBIERROR1 */
62                 @{fini1}@
63         }else if (@{change_cond}@){
64         @{operation2}@ /* MBIERROR2 */
65                 @{fini2}@
66         }
67
68   MPI_Finalize();
69   printf("Rank %d finished normally\\n", rank);
70   return 0;
71 }
72 """
73
74
75 for p in send + ssend + bsend + recv + irecv + isend:
76     patterns = {}
77     patterns = {'p': p}
78     patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
79     patterns['p2pfeature'] = 'Yes' if p in send + bsend + ssend + recv else 'Lacking'
80     patterns['ip2pfeature'] = 'Yes' if p in isend + irecv else 'Lacking'
81     patterns['persfeature'] = 'Lacking'
82     #patterns['persfeature'] = 'Yes' if p in psend + precv else 'Lacking'
83     patterns['p'] = p
84     patterns['init1'] = init[p]("1")
85     patterns['init2'] = '' #init[p2]("2")
86     patterns['fini1'] = fini[p]("1")
87     patterns['fini2'] = '' #fini[p2]("2")
88     patterns['operation1'] = operation[p]("1")
89     patterns['operation2'] = '' #operation[p2]("2")
90     patterns['change_cond'] = 'rank == 1'
91
92     # Generate the incorrect matching with one call
93     replace = patterns
94     replace['shortdesc'] = 'Point to point @{p}@ is not matched' 
95     replace['longdesc'] = 'Process 0 calls @{p}@ and is not matched'
96     replace['outcome'] = 'ERROR: CallMatching'
97     replace['errormsg'] = 'P2P mistmatch. @{p}@ at @{filename}@:@{line:MBIERROR1}@ is not matched.'
98     make_file(template, f'CallOrdering_{p}_nok.c', replace)
99
100     # Generate the incorrect matching with two calls
101     replace = patterns
102     replace['shortdesc'] = 'Both point to point @{p}@ are not matched' 
103     replace['longdesc'] = 'Processes 0 and 1 both call @{p}@ which are not matched'
104     replace['outcome'] = 'ERROR: CallMatching'
105     replace['errormsg'] = 'P2P mismatch. @{p}@ at @{filename}@:@{line:MBIERROR1}@ and @{p}@ at @{filename}@:@{line:MBIERROR2}@ are not matched.'
106     replace['operation2'] = operation[p]("1")
107     replace['fini2'] = fini[p]("1")
108     make_file(template, f'CallOrdering_{p}_{p}_nok.c', replace)
109
110 for s in send + isend + ssend + bsend:
111     for r in recv + irecv:
112         patterns = {}
113         patterns = {'s': s, 'r': r}
114         patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
115         patterns['p2pfeature'] = 'Yes' if s in send or r in recv else 'Lacking'
116         patterns['ip2pfeature'] = 'Yes' if s in isend or r in irecv else 'Lacking'
117         patterns['s'] = s
118         patterns['r'] = r
119         patterns['init1'] = init[s]("1")
120         patterns['init2'] = init[r]("2")
121         patterns['fini1'] = fini[s]("1")
122         patterns['fini2'] = fini[r]("2")
123         patterns['operation1'] = operation[s]("1")
124         patterns['operation2'] = operation[r]("2")
125         patterns['change_cond'] = '(rank == 1) && (its_raining)'
126
127         # Generate the incorrect matching because of the conditional
128         replace = patterns 
129         replace['shortdesc'] = 'Point to point @{r}@ is never called.'
130         replace['longdesc'] = 'Point to point @{r}@ is never executed. Process 1 calls MPI_Finalize and causes a deadlock.' 
131         replace['outcome'] = 'ERROR: CallMatching' 
132         replace['errormsg'] = 'P2P mistmatch. @{r}@ at @{filename}@:@{line:MBIERROR2}@ is never called because of the conditional (@{change_cond}@).' 
133         replace['operation1'] =  operation[s]("1")
134         replace['operation2'] = operation[r]("2")
135         make_file(template, f'CallOrdering_{r}_{s}_nok.c', replace)
136