Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill trailing spaces and tabs in MBI files
[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 from generator_utils import *
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, j=1, size=1;
54   int color =0;
55
56   MPI_Init(&argc, &argv);
57   MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
58   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
59   printf("Hello from rank %d \\n", rank);
60
61   if (nprocs < 2)
62     printf("MBI ERROR: This test needs at least 2 processes to produce a bug!\\n");
63
64   @{change_size}@
65   @{init}@
66   @{loop}@  
67   @{operation}@
68   @{cond}@  
69   @{fini}@
70   @{end}@  
71
72   @{free}@
73
74   MPI_Finalize();
75   printf("Rank %d finished normally\\n", rank);
76   return 0;
77 }
78 """
79
80 # Generate code with one collective
81 for call in tcoll:
82     patterns = {}
83     patterns = {'call': call}
84     patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
85     patterns['toolfeature'] = 'Yes'
86     patterns['call'] = call
87     patterns['operation'] = operation[call]("1")
88     patterns['init'] = init[call]("1")
89     patterns['fini'] = fini[call]("1")
90     patterns['free'] = free[call]("1")
91     missing = patterns['fini']
92     patterns['loop'] = ''
93     patterns['cond'] = ''
94     patterns['change_size'] = ''
95     patterns['end'] = ''
96
97     # Generate the correct code
98     replace = patterns
99     replace['shortdesc'] = '@{call}@ is correctly used'
100     replace['longdesc'] = f'{call} correctly used'
101     replace['outcome'] = 'OK'
102     replace['errormsg'] = ''
103     make_file(template, f'ResLeak_{call}_ok.c', replace)
104
105     # Generate the resleak
106     replace = patterns
107     replace['shortdesc'] = '@{call}@ has no free'
108     replace['longdesc'] = '@{call}@ has no free'
109     replace['outcome'] = f'ERROR: {error[call]}'
110     replace['errormsg'] = 'Resleak. @{call}@ at @{filename}@:@{line:MBIERROR}@ has no free.'
111     replace['fini'] = ' /* MBIERROR MISSING: ' + missing + ' */'
112     make_file(template, f'ResLeak_{call}_nok.c', replace)
113
114     # Generate multiple resleak
115     replace = patterns
116     replace['shortdesc'] = '@{call}@ lacks several free'
117     replace['longdesc'] = '@{call}@ lacks several free'
118     replace['outcome'] = f'ERROR: {error[call]}'
119     replace['errormsg'] = 'Resleak. @{call}@ at @{filename}@:@{line:MBIERROR}@ lacks several free.'
120     replace['change_size'] = 'size=PARAM_PER_ITERATION;'
121     replace['loop'] = 'for (i = 0; i < ITERATIONS; i++) {\n    for (j = 0; j < PARAM_PER_ITERATION; j++) {'
122     replace['cond'] = '      if (j < PARAM_PER_ITERATION - PARAM_LOST_PER_ITERATION) {'
123     replace['fini'] = fini[call]("1") + ' /* MBIERROR */'
124     replace['end'] = '      }\n                 }\n     }'
125     make_file(template, f'ResLeak_multiple_{call}_nok.c', replace)