Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of framagit.org:simgrid/simgrid
[simgrid.git] / teshsuite / smpi / MBI / ResleakGenerator.py
1 #! /usr/bin/python3
2
3 # Copyright 2021-2022. The MBI project. All rights reserved.
4 # This program is free software; you can redistribute it and/or modify it under the terms of the license (GNU GPL).
5
6 import os
7 import sys
8 import generator_utils as gen
9
10 template = """// @{generatedby}@
11 /* ///////////////////////// The MPI Bugs Initiative ////////////////////////
12
13   Origin: MBI
14
15   Description: @{shortdesc}@
16     @{longdesc}@
17
18   Version of MPI: Conforms to MPI 1.1, does not require MPI 2 implementation
19
20 BEGIN_MPI_FEATURES
21   P2P!basic: Lacking
22   P2P!nonblocking: Lacking
23   P2P!persistent: Lacking
24   COLL!basic: Lacking
25   COLL!nonblocking: Lacking
26   COLL!persistent: Lacking
27   COLL!tools: @{toolfeature}@
28   RMA: Lacking
29 END_MPI_FEATURES
30
31 BEGIN_MBI_TESTS
32   $ mpirun -np 2 ${EXE}
33   | @{outcome}@
34   | @{errormsg}@
35 END_MBI_TESTS
36 //////////////////////       End of MBI headers        /////////////////// */
37
38 #include <mpi.h>
39 #include <stdio.h>
40
41 #define ITERATIONS 100
42 #define PARAM_PER_ITERATION 3
43 #define PARAM_LOST_PER_ITERATION 1
44
45 static void myOp(int *invec, int *inoutvec, int *len, MPI_Datatype *dtype) {
46   for (int i = 0; i < *len; i++)
47     inoutvec[i] += invec[i];
48 }
49
50 int main(int argc, char **argv) {
51   int nprocs = -1;
52   int rank = -1;
53   int i=1;
54   int j=0;
55   int size=1;
56
57   MPI_Init(&argc, &argv);
58   MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
59   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
60   printf("Hello from rank %d \\n", rank);
61
62   if (nprocs < 2)
63     printf("MBI ERROR: This test needs at least 2 processes to produce a bug!\\n");
64
65   @{change_size}@
66   @{init}@
67   @{loop}@
68   @{operation}@
69   @{cond}@
70   @{fini}@
71   @{end}@
72
73   @{free}@
74
75   MPI_Finalize();
76   printf("Rank %d finished normally\\n", rank);
77   return 0;
78 }
79 """
80
81 # Generate code with one collective
82 for call in gen.tcoll:
83     patterns = {}
84     patterns = {'call': call}
85     patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
86     patterns['toolfeature'] = 'Yes'
87     patterns['call'] = call
88     patterns['operation'] = gen.operation[call]("1")
89     patterns['init'] = gen.init[call]("1")
90     patterns['fini'] = gen.fini[call]("1")
91     patterns['free'] = gen.free[call]("1")
92     missing = patterns['fini']
93     patterns['loop'] = ''
94     patterns['cond'] = ''
95     patterns['change_size'] = ''
96     patterns['end'] = ''
97
98     # Generate the correct code
99     replace = patterns.copy()
100     replace['shortdesc'] = '@{call}@ is correctly used'
101     replace['longdesc'] = f'{call} correctly used'
102     replace['outcome'] = 'OK'
103     replace['errormsg'] = ''
104     gen.make_file(template, f'ResLeak_{call}_ok.c', replace)
105
106     # Generate the resleak
107     replace = patterns.copy()
108     replace['shortdesc'] = '@{call}@ has no free'
109     replace['longdesc'] = '@{call}@ has no free'
110     replace['outcome'] = f'ERROR: {gen.error[call]}'
111     replace['errormsg'] = 'Resleak. @{call}@ at @{filename}@:@{line:MBIERROR}@ has no free.'
112     replace['fini'] = ' /* MBIERROR MISSING: ' + missing + ' */'
113     gen.make_file(template, f'ResLeak_{call}_nok.c', replace)
114
115     # Generate multiple resleak
116     replace = patterns.copy()
117     replace['shortdesc'] = '@{call}@ lacks several free'
118     replace['longdesc'] = '@{call}@ lacks several free'
119     replace['outcome'] = f'ERROR: {gen.error[call]}'
120     replace['errormsg'] = 'Resleak. @{call}@ at @{filename}@:@{line:MBIERROR}@ lacks several free.'
121     replace['change_size'] = 'size=PARAM_PER_ITERATION;'
122     replace['loop'] = 'for (i = 0; i < ITERATIONS; i++) {\n    for (j = 0; j < PARAM_PER_ITERATION; j++) {'
123     replace['cond'] = '      if (j < PARAM_PER_ITERATION - PARAM_LOST_PER_ITERATION) {'
124     replace['fini'] = gen.fini[call]("1") + ' /* MBIERROR */'
125     replace['end'] = '      }\n     }\n   }'
126     gen.make_file(template, f'ResLeak_multiple_{call}_nok.c', replace)