Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid
[simgrid.git] / teshsuite / smpi / MBI / RMAInvalidArgGenerator.py
1 #! /usr/bin/python3
2 import os
3 import sys
4 import generator_utils as gen
5
6 template = """// @{generatedby}@
7 /* ///////////////////////// The MPI Bugs Initiative ////////////////////////
8
9   Origin: @{origin}@
10
11   Description: @{shortdesc}@
12     @{longdesc}@
13
14     Version of MPI: Conforms to MPI 1.1, does not require MPI 2 implementation
15
16 BEGIN_MPI_FEATURES
17     P2P!basic: Lacking
18     P2P!nonblocking: Lacking
19     P2P!persistent: Lacking
20     COLL!basic: Lacking
21     COLL!nonblocking: Lacking
22     COLL!persistent: Lacking
23     COLL!tools: Lacking
24     RMA: @{rmafeature}@
25 END_MPI_FEATURES
26
27 BEGIN_MBI_TESTS
28   $ mpirun -np 2 ${EXE}
29   | @{outcome}@
30   | @{errormsg}@
31 END_MBI_TESTS
32 //////////////////////       End of MBI headers        /////////////////// */
33
34 #include <mpi.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37
38 #define N 10
39
40 int main(int argc, char **argv) {
41   int nprocs = -1 , rank = -1;
42   MPI_Win win;
43   int *winbuf = (int *)@{malloc}@ // Window buffer
44
45   MPI_Init(&argc, &argv);
46   MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
47   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
48
49   if (nprocs < 2)
50     printf("MBI ERROR: This test needs at least 2 processes to produce a bug!\\n");
51
52   MPI_Datatype type = MPI_INT;
53   int target = (rank + 1) % nprocs;
54
55   MPI_Win_create(winbuf, N * sizeof(int), 1, MPI_INFO_NULL, MPI_COMM_WORLD, &win);
56
57
58   @{epoch}@
59
60   @{init}@
61   @{change_arg}@
62   @{operation}@ /* MBIERROR */
63
64   @{finEpoch}@
65
66   MPI_Win_free(&win);
67   free(winbuf);
68
69   MPI_Finalize();
70   printf("Rank %d finished normally\\n", rank);
71   return 0;
72 }
73 """
74
75
76 for e in gen.epoch:
77     for p in gen.rma:
78         patterns = {}
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'
83         patterns['p'] = p
84         patterns['e'] = e
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));"
91
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)
100
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 = (int *)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)
112
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)
122
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 */"
130         replace['init'] = ""
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)