4 import generator_utils as gen
6 template = """// @{generatedby}@
7 /* ///////////////////////// The MPI Bugs Initiative ////////////////////////
11 Description: @{shortdesc}@
14 Version of MPI: Conforms to MPI 1.1, does not require MPI 2 implementation
18 P2P!nonblocking: Lacking
19 P2P!persistent: Lacking
21 COLL!nonblocking: Lacking
22 COLL!persistent: Lacking
32 ////////////////////// End of MBI headers /////////////////// */
40 int main(int argc, char **argv) {
41 int nprocs = -1 , rank = -1;
43 int *winbuf = @{malloc}@ // Window buffer
45 MPI_Init(&argc, &argv);
46 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
47 MPI_Comm_rank(MPI_COMM_WORLD, &rank);
50 printf("MBI ERROR: This test needs at least 2 processes to produce a bug!\\n");
52 MPI_Datatype type = MPI_INT;
53 int target = (rank + 1) % nprocs;
55 MPI_Win_create(winbuf, N * sizeof(int), 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
62 @{operation}@ /* MBIERROR */
70 printf("Rank %d finished normally\\n", rank);
79 patterns = {'e': e, 'p': p}
80 patterns['origin'] = "MBI"
81 patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
82 patterns['rmafeature'] = 'Yes'
85 patterns['epoch'] = gen.epoch[e]("1")
86 patterns['finEpoch'] = gen.finEpoch[e]("1")
87 patterns['init'] = gen.init[p]("1")
88 patterns['operation'] = gen.operation[p]("1")
89 patterns['change_arg'] = ""
90 patterns['malloc'] = "malloc(N * sizeof(int));"
92 # Generate a code with a null type
93 replace = patterns.copy()
94 replace['shortdesc'] = 'Invalid argument in one-sided operation.'
95 replace['longdesc'] = 'A one-sided operation has MPI_DATATYPE_NULL as a type.'
96 replace['outcome'] = 'ERROR: InvalidDatatype'
97 replace['change_arg'] = 'type = MPI_DATATYPE_NULL;'
98 replace['errormsg'] = '@{p}@ at @{filename}@:@{line:MBIERROR}@ has MPI_DATATYPE_NULL as a type'
99 gen.make_file(template, f'InvalidParam_DatatypeNull_{e}_{p}_nok.c', replace)
101 # Generate a code with a null buffer (move to RMAWinBufferGenerator)
102 # replace = patterns.copy()
103 # replace['origin'] = 'MPI-Corrbench'
104 # replace['shortdesc'] = 'nullptr is invalid in one-sided operation.'
105 # replace['longdesc'] = 'A one-sided operation has an invalid buffer.'
106 # replace['outcome'] = 'ERROR: InvalidBuffer'
107 # replace['init'] = 'int * localbuf1 = malloc(sizeof(int));'
108 # replace['change_arg'] = 'localbuf1 = NULL;'
109 # replace['operation'] = gen.operation[p]("1").replace('&localbuf1', 'localbuf1')
110 # replace['errormsg'] = '@{p}@ at @{filename}@:@{line:MBIERROR}@ has an invalid buffer'
111 # gen.make_file(template, f'InvalidParam_BufferNull_{e}_{p}_nok.c', replace)
113 # Generate a code with an invalid type
114 replace = patterns.copy()
115 replace['origin'] = 'MBI'
116 replace['shortdesc'] = 'Invalid argument in one-sided operation.'
117 replace['longdesc'] = 'Use of an invalid datatype in one-sided operation.'
118 replace['outcome'] = 'ERROR: InvalidDatatype'
119 replace['change_arg'] = 'MPI_Type_contiguous (2, MPI_INT, &type); MPI_Type_commit(&type);MPI_Type_free(&type); /* MBIERROR2 */'
120 replace['errormsg'] = 'Invalid Datatype in @{p}@ at @{filename}@:@{line:MBIERROR}@'
121 gen.make_file(template, f'InvalidParam_Datatype_{e}_{p}_nok.c', replace)
123 # Generate a code with invalid buffer
124 replace = patterns.copy()
125 patterns['origin'] = "MPI-Corrbench"
126 replace['shortdesc'] = 'Invalid invalid buffer (buffer must be allocated)'
127 replace['longdesc'] = 'Use of an invalid buffer in MPI_Win_create.'
128 replace['outcome'] = 'ERROR: InvalidBuffer'
129 replace['malloc'] = "NULL; /* MBIERROR2 */"
131 replace['operation'] = ""
132 replace['change_arg'] = ""
133 replace['errormsg'] = 'Invalid buffer in Win_create at @{filename}@:@{line:MBIERROR2}@'
134 gen.make_file(template, f'InvalidParam_InvalidBufferWinCreate_{e}_{p}_nok.c', replace)