Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix the generation of MBI test cases (and compile them with -Wno-unused-variable...
[simgrid.git] / teshsuite / smpi / MBI / RMAWinBufferGenerator.py
1 #! /usr/bin/python3
2 import os
3 import sys
4 from generator_utils import *
5
6 template = """// @{generatedby}@
7 /* ///////////////////////// The MPI Bugs Initiative ////////////////////////
8
9   Origin: @{origin}@
10
11   Description: @{shortdesc}@
12     @{longdesc}@
13
14
15 BEGIN_MPI_FEATURES
16   P2P!basic: Lacking
17   P2P!nonblocking: Lacking
18   P2P!persistent: Lacking
19   COLL!basic: Lacking
20   COLL!nonblocking: Lacking
21   COLL!persistent: Lacking
22   COLL!tools: Lacking
23   RMA: @{rmafeature}@
24 END_MPI_FEATURES
25
26 BEGIN_MBI_TESTS
27   $ mpirun -np 2 ${EXE}
28   | @{outcome}@
29   | @{errormsg}@
30 END_MBI_TESTS
31 //////////////////////       End of MBI headers        /////////////////// */
32
33 #include <mpi.h>
34 #include <stddef.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37
38 #define N 10
39
40 int * buffer;
41
42 static void get_win(MPI_Win *win) {
43   @{bufferalloc}@
44
45   MPI_Win_create(@{buffer}@, N * sizeof(int), 1, MPI_INFO_NULL, MPI_COMM_WORLD, win);
46
47   return;
48 }
49
50 int main(int argc, char *argv[]) {
51   int rank, numProcs;
52
53   MPI_Init(&argc, &argv);
54   MPI_Comm_size(MPI_COMM_WORLD, &numProcs);
55   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
56   printf("Hello from rank %d \\n", rank);
57
58   if (numProcs < 2)
59     printf("MBI ERROR: This test needs at least 2 processes to produce a bug!\\n");
60
61   MPI_Win win;
62
63   get_win(&win);
64
65   MPI_Win_fence(0, win);
66
67   if (rank == 0) {
68     int localbuf[N] = {12345};
69     MPI_Put(&localbuf, N, MPI_INT, 1, 0, N, MPI_INT, win);
70   }
71
72   MPI_Win_fence(0, win);
73
74   MPI_Win_free(&win);
75
76   @{bufferfree}@
77
78   MPI_Finalize();
79   printf("Rank %d finished normally\\n", rank);
80   return 0;
81 }
82
83 """
84
85
86 for b in ['missing', 'null',  'malloc', 'bufferSize']:
87     patterns = {}
88     patterns = {'b': b}
89     patterns['origin'] = "MPI-CorrBench"
90     patterns['generatedby'] = f'DO NOT EDIT: this file was generated by {os.path.basename(sys.argv[0])}. DO NOT EDIT.'
91     patterns['rmafeature'] = 'Yes'
92
93     replace = patterns
94     replace['shortdesc'] = 'Invalid buffer in window creation.'
95     replace['longdesc'] = 'Invalid buffer in window creation.'
96     replace['outcome'] = 'ERROR: InvalidBuffer'
97     replace['errormsg'] = '@{b}@ at @{filename}@:@{line:MBIERROR}@ has an invalid buffer'
98     replace['bufferfree'] = ''
99
100     ok = 'nok'
101     replace['buffer'] = 'buffer'
102
103     if b == 'missing':
104         replace['bufferalloc'] = '/* MBIERROR1 */'
105         replace['longdesc'] = 'Uninitialized buffer in window creation.'
106     elif b == 'null':
107         replace['bufferalloc'] = 'buffer = NULL; /* MBIERROR1 */'
108         replace['longdesc'] = 'Use NULL buffer in window creation.'
109     elif b == 'bufferSize':
110         replace['bufferalloc'] = 'buffer = malloc((N/2) * sizeof(int)); /* MBIERROR1 */'
111         replace['bufferfree'] = 'free(buffer);'
112         replace['longdesc'] = 'Unmatched size of buffer in window creation.'
113     else:
114         replace['bufferalloc'] = 'buffer = malloc(N * sizeof(int));'
115         replace['bufferfree'] = 'free(buffer);'
116         replace['longdesc'] = 'Correct initialized buffer in window creation.'
117         replace['outcome'] = 'OK'
118         replace['errormsg'] = ''
119         ok = 'ok'
120
121     make_file(template, f'InvalidParam_WinBuffer_{b}_{ok}.c', replace)