Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
New option to detect dangerous code mixing collectives and P2P in a deadlocking way
[simgrid.git] / teshsuite / smpi / MBI / ResleakGenerator.py
index 67fdd96..c33d197 100755 (executable)
@@ -5,7 +5,7 @@
 
 import os
 import sys
-from generator_utils import *
+import generator_utils as gen
 
 template = """// @{generatedby}@
 /* ///////////////////////// The MPI Bugs Initiative ////////////////////////
@@ -15,17 +15,17 @@ template = """// @{generatedby}@
   Description: @{shortdesc}@
     @{longdesc}@
 
-       Version of MPI: Conforms to MPI 1.1, does not require MPI 2 implementation
+  Version of MPI: Conforms to MPI 1.1, does not require MPI 2 implementation
 
 BEGIN_MPI_FEATURES
-       P2P!basic: Lacking
-       P2P!nonblocking: Lacking
-       P2P!persistent: Lacking
-       COLL!basic: Lacking
-       COLL!nonblocking: Lacking 
-       COLL!persistent: Lacking
-       COLL!tools: @{toolfeature}@
-       RMA: Lacking
+  P2P!basic: Lacking
+  P2P!nonblocking: Lacking
+  P2P!persistent: Lacking
+  COLL!basic: Lacking
+  COLL!nonblocking: Lacking
+  COLL!persistent: Lacking
+  COLL!tools: @{toolfeature}@
+  RMA: Lacking
 END_MPI_FEATURES
 
 BEGIN_MBI_TESTS
@@ -50,8 +50,9 @@ static void myOp(int *invec, int *inoutvec, int *len, MPI_Datatype *dtype) {
 int main(int argc, char **argv) {
   int nprocs = -1;
   int rank = -1;
-       int i=1, j=1, size=1;
-       int color =0;
+  int i=1;
+  int j=0;
+  int size=1;
 
   MPI_Init(&argc, &argv);
   MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
@@ -61,15 +62,15 @@ int main(int argc, char **argv) {
   if (nprocs < 2)
     printf("MBI ERROR: This test needs at least 2 processes to produce a bug!\\n");
 
-       @{change_size}@
+  @{change_size}@
   @{init}@
-       @{loop}@        
-  @{operation}@ 
-       @{cond}@        
-       @{fini}@
-       @{end}@ 
+  @{loop}@
+  @{operation}@
+  @{cond}@
+  @{fini}@
+  @{end}@
 
-       @{free}@
+  @{free}@
 
   MPI_Finalize();
   printf("Rank %d finished normally\\n", rank);
@@ -78,16 +79,16 @@ int main(int argc, char **argv) {
 """
 
 # Generate code with one collective
-for call in tcoll:
+for call in gen.tcoll:
     patterns = {}
     patterns = {'call': call}
     patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
-    patterns['toolfeature'] = 'Yes' 
+    patterns['toolfeature'] = 'Yes'
     patterns['call'] = call
-    patterns['operation'] = operation[call]("1")
-    patterns['init'] = init[call]("1")
-    patterns['fini'] = fini[call]("1")
-    patterns['free'] = free[call]("1")
+    patterns['operation'] = gen.operation[call]("1")
+    patterns['init'] = gen.init[call]("1")
+    patterns['fini'] = gen.fini[call]("1")
+    patterns['free'] = gen.free[call]("1")
     missing = patterns['fini']
     patterns['loop'] = ''
     patterns['cond'] = ''
@@ -95,31 +96,31 @@ for call in tcoll:
     patterns['end'] = ''
 
     # Generate the correct code
-    replace = patterns
-    replace['shortdesc'] = '@{call}@ is correctly used' 
-    replace['longdesc'] = f'{call} correctly used' 
+    replace = patterns.copy()
+    replace['shortdesc'] = '@{call}@ is correctly used'
+    replace['longdesc'] = f'{call} correctly used'
     replace['outcome'] = 'OK'
     replace['errormsg'] = ''
-    make_file(template, f'ResLeak_{call}_ok.c', replace)
+    gen.make_file(template, f'ResLeak_{call}_ok.c', replace)
 
     # Generate the resleak
-    replace = patterns
+    replace = patterns.copy()
     replace['shortdesc'] = '@{call}@ has no free'
     replace['longdesc'] = '@{call}@ has no free'
-    replace['outcome'] = f'ERROR: {error[call]}'
+    replace['outcome'] = f'ERROR: {gen.error[call]}'
     replace['errormsg'] = 'Resleak. @{call}@ at @{filename}@:@{line:MBIERROR}@ has no free.'
     replace['fini'] = ' /* MBIERROR MISSING: ' + missing + ' */'
-    make_file(template, f'ResLeak_{call}_nok.c', replace)
+    gen.make_file(template, f'ResLeak_{call}_nok.c', replace)
 
     # Generate multiple resleak
-    replace = patterns
+    replace = patterns.copy()
     replace['shortdesc'] = '@{call}@ lacks several free'
     replace['longdesc'] = '@{call}@ lacks several free'
-    replace['outcome'] = f'ERROR: {error[call]}'
+    replace['outcome'] = f'ERROR: {gen.error[call]}'
     replace['errormsg'] = 'Resleak. @{call}@ at @{filename}@:@{line:MBIERROR}@ lacks several free.'
     replace['change_size'] = 'size=PARAM_PER_ITERATION;'
-    replace['loop'] = 'for (i = 0; i < ITERATIONS; i++) {\n            for (j = 0; j < PARAM_PER_ITERATION; j++) {'
-    replace['cond'] = '                        if (j < PARAM_PER_ITERATION - PARAM_LOST_PER_ITERATION) {'
-    replace['fini'] = fini[call]("1") + ' /* MBIERROR */'
-    replace['end'] = '                 }\n             }\n     }'
-    make_file(template, f'ResLeak_multiple_{call}_nok.c', replace)
+    replace['loop'] = 'for (i = 0; i < ITERATIONS; i++) {\n    for (j = 0; j < PARAM_PER_ITERATION; j++) {'
+    replace['cond'] = '      if (j < PARAM_PER_ITERATION - PARAM_LOST_PER_ITERATION) {'
+    replace['fini'] = gen.fini[call]("1") + ' /* MBIERROR */'
+    replace['end'] = '      }\n     }\n   }'
+    gen.make_file(template, f'ResLeak_multiple_{call}_nok.c', replace)