Logo AND Algorithmique Numérique Distribuée

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