-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathevents_callbacks.c
395 lines (289 loc) · 13.1 KB
/
events_callbacks.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
/*
* events_callbacks.c
*
* Test event callback registration and free
* Test handle and callback get/set info
*
*/
#include "events_common.h"
char user_data_string[MAX_STRING] = "Test String";
// Test flags
int event_cb_success = 0;
int event_free_cb_success = 0;
int event_free_cb_user_data_access = 1;
int event_handle_get_info_success = 1;
int event_handle_set_info_success = 1;
int event_handle_set_info_updated = 0;
int event_callback_get_info_success = 1;
int event_callback_set_info_success = 1;
int event_callback_set_info_updated = 0;
int event_handle_alloc_event_index_exceed_handled = 1;
int event_handle_alloc_event_index_negative_handled = 1;
void print_results() {
if ( 0 != rank ) return;
print_pf_result("MPI_T_event_register_callback", "Event Callback Success", event_cb_success);
print_pf_result("MPI_T_event_handle_free", "Event Free Callback Success", event_free_cb_success);
print_pf_result("MPI_T_event_handle_free", "Event Free user_data access", event_free_cb_user_data_access);
print_pf_result("MPI_T_event_handle_get_info", "Successful call", event_handle_get_info_success);
print_pf_result("MPI_T_event_handle_set_info", "Successful call", event_handle_set_info_success);
print_pf_result("MPI_T_event_handle_set_info", "Key added to Info object", event_handle_set_info_updated);
print_pf_result("MPI_T_event_callback_get_info", "Successful call", event_callback_get_info_success);
print_pf_result("MPI_T_event_callback_set_info", "Successful call", event_callback_set_info_success);
print_pf_result("MPI_T_event_callback_set_info", "Key added to Info object", event_callback_set_info_updated);
if ( do_failure_tests ) {
print_pf_result("MPI_T_event_handle_alloc", "Handled event index too large", event_handle_alloc_event_index_exceed_handled);
print_pf_result("MPI_T_event_handle_alloc", "Handled negative event index", event_handle_alloc_event_index_negative_handled);
}
fprintf(outstream, "%-*s - %-*s : %6d\n", func_width, "TOTAL ERROR COUNT", metric_width, "", error_count);
}
void test_event_cb_function(MPI_T_event_instance event, MPI_T_event_registration handle, MPI_T_cb_safety cb_safety, void *user_data) {
print_debug("In cb_function : %s %s %d\n", __func__, __FILE__, __LINE__);
//print_debug("user_data is :%s:\n", (char*)user_data);
//print_debug("user_data_string is :%s:\n", (char*)user_data_string);
event_cb_success = 1;
if ( NULL == user_data || strcmp(user_data, user_data_string) )
print_error("test_event_cb_function could not access user_data", NO_MPI_ERROR_CODE, TEST_CONTINUE);
}
void test_free_event_cb_function(MPI_T_event_registration handle, MPI_T_cb_safety cb_safety, void *user_data) {
print_debug("In cb_function : %s %s %d\n", __func__, __FILE__, __LINE__);
print_debug("user_data is :%s:\n", (char*)user_data);
event_free_cb_success = 1;
if ( NULL == user_data || strcmp(user_data, user_data_string) ) {
print_error("test_event_free_cb_function could not access user_data", NO_MPI_ERROR_CODE, TEST_CONTINUE);
event_free_cb_user_data_access = 0;
}
}
void test_handle_alloc_register_free() {
int retval;
MPI_T_event_registration event_registration;
// TEST MPI_T_event_handle_alloc
//
print_debug("Testing expected success for index %d\n", event_index);
retval = MPI_T_event_handle_alloc(event_index, MPI_COMM_WORLD, MPI_INFO_NULL, &event_registration) ;
if ( retval != MPI_SUCCESS )
print_error("MPI_T_event_handle_alloc did not return MPI_SUCCESS", retval, TEST_EXIT);
// Test MPI_T_event_handle_alloc invalid arguments
if ( do_failure_tests ) {
int bad_event_index;
MPI_T_event_registration bad_event_registration;
bad_event_index = 11111111;
print_debug("Testing expected failure for index %d\n", bad_event_index);
retval = MPI_T_event_handle_alloc(bad_event_index, MPI_COMM_WORLD, MPI_INFO_NULL, &bad_event_registration) ;
if ( retval == MPI_SUCCESS ) {
print_error("MPI_T_event_handle_alloc returned MPI_SUCCESS with too large index", retval, TEST_EXIT);
event_handle_alloc_event_index_exceed_handled = 0;
}
else
print_debug("MPI_T_event_handle_alloc handled too large index\n", retval, TEST_EXIT);
bad_event_index = -1;
print_debug("Testing expected failure for index %d\n", bad_event_index);
retval = MPI_T_event_handle_alloc(bad_event_index, MPI_COMM_WORLD, MPI_INFO_NULL, &bad_event_registration) ;
if ( retval == MPI_SUCCESS ) {
print_error("MPI_T_event_handle_alloc returned MPI_SUCCESS with negative index", retval, TEST_EXIT);
event_handle_alloc_event_index_negative_handled = 0;
}
else
print_debug("MPI_T_event_handle_alloc handled negative index\n", retval, TEST_EXIT);
}
// TEST MPI_T_event_register_callback
//
cb_user_data = (void*)user_data_string;
print_debug("cb_user_data is %s\n", cb_user_data);
print_debug("Testing expected MPI_T_event_register_callback success for index %d\n", event_index);
retval = MPI_T_event_register_callback(event_registration, MPI_T_CB_REQUIRE_ASYNC_SIGNAL_SAFE, MPI_INFO_NULL, cb_user_data, test_event_cb_function);
if ( retval != MPI_SUCCESS )
print_error("MPI_T_event_register_callback did not return MPI_SUCCESS", retval, TEST_EXIT);
if ( do_failure_tests ) {
}
generate_callback_activity();
//}
// TEST MPI_T_event_handle_free
//
retval = MPI_T_event_handle_free(event_registration, cb_user_data, test_free_event_cb_function);
if ( retval != MPI_SUCCESS )
print_error("MPI_T_event_handle_free did not return MPI_SUCCESS", retval, TEST_EXIT);
if ( do_failure_tests ) {
}
}
void print_info_obj(MPI_Info info) {
int i, retval, vallen = MPI_MAX_INFO_VAL, nkeys, flag;
char key[MPI_MAX_INFO_KEY];
char value[MPI_MAX_INFO_VAL+1];
retval = MPI_Info_get_nkeys(info, &nkeys);
if ( retval != MPI_SUCCESS )
print_error("MPI_Info_get_nkeys did not return MPI_SUCCESS", retval, TEST_CONTINUE);
print_debug("MPI_Info_get_nkeys nkeys is %d\n", nkeys);
for ( i = 0; i < nkeys; i++ ) {
MPI_Info_get_nthkey( info, i, key );
retval = MPI_Info_get( info, key, vallen, value, &flag );
if ( retval != MPI_SUCCESS ) {
print_error("MPI_Info_get did not return MPI_SUCCESS", retval, TEST_CONTINUE);
}
else
print_debug("Info entry index %2d - %d:%s:%s:%d\n", i, flag, key, value);
}
}
void test_info() {
int retval, vallen = MPI_MAX_INFO_VAL, nkeys, flag, initial_nkeys = 0;
MPI_T_event_registration event_registration;
char key[MPI_MAX_INFO_KEY];
char value[MPI_MAX_INFO_VAL+1];
MPI_Info info;
MPI_T_cb_safety cb_safety = MPI_T_CB_REQUIRE_ASYNC_SIGNAL_SAFE;
//
// Tests
//
// - Test for successful calls to all get/set info
// - Check to see if set info calls add values for get calls
// - Record initial nkeys count
// - Add unique key
// - get_info
// - See if nkeys has increased
//
// Set Up Test
//
// Allocate a handle to use for testing
retval = MPI_T_event_handle_alloc(event_index, MPI_COMM_WORLD, MPI_INFO_NULL, &event_registration) ;
if ( retval != MPI_SUCCESS )
print_error("MPI_T_event_handle_alloc did not return MPI_SUCCESS", retval, TEST_EXIT);
//
// Get Handle Info
//
retval = MPI_T_event_handle_get_info(event_registration, &info);
if ( retval != MPI_SUCCESS ) {
print_error("MPI_T_event_handle_get_info did not return MPI_SUCCESS", retval, TEST_CONTINUE);
event_handle_get_info_success = 0;
}
//
// Get And Store Handle Info Key Count
//
retval = MPI_Info_get_nkeys(info, &nkeys);
if ( retval != MPI_SUCCESS )
print_error("MPI_Info_get_nkeys did not return MPI_SUCCESS", retval, TEST_CONTINUE);
else
initial_nkeys = nkeys;
print_debug("MPI_Info_get_nkeys nkeys is %d\n", nkeys);
//
// Add Entry To Handle Info
//
retval = MPI_Info_set(info, "randomkey", "randomkeyvalue");
if ( retval != MPI_SUCCESS )
print_error("MPI_info_set did not return MPI_SUCCESS", retval, TEST_CONTINUE);
print_info_obj(info);
retval = MPI_Info_get_nkeys(info, &nkeys);
if ( retval != MPI_SUCCESS )
print_error("MPI_Info_get_nkeys did not return MPI_SUCCESS", retval, TEST_CONTINUE);
print_debug("After MPI_Info_set, MPI_Info_get_nkeys nkeys is %d\n", nkeys);
//
// Confirm Entry Has Been Added
//
MPI_Info_get_nthkey( info, 0, key );
retval = MPI_Info_get( info, key, vallen, value, &flag );
if ( retval != MPI_SUCCESS ) {
print_error("MPI_Info_get did not return MPI_SUCCESS", retval, TEST_CONTINUE);
}
else
print_debug("Verifying that info values are %d:%s:%s:%d\n", flag, key, value);
//
// Set Handle Info
//
retval = MPI_T_event_handle_set_info(event_registration, info);
if ( retval != MPI_SUCCESS ) {
print_error("MPI_T_event_handle_set_info did not return MPI_SUCCESS", retval, TEST_CONTINUE);
event_handle_set_info_success = 0;
}
//
// Get Event Handle Info
//
retval = MPI_T_event_handle_get_info(event_registration, &info);
if ( retval != MPI_SUCCESS )
print_error("MPI_T_event_handle_get_info did not return MPI_SUCCESS", retval, TEST_CONTINUE);
//
// Test For Increase In Nkeys To Confirm Update
//
retval = MPI_Info_get_nkeys(info, &nkeys);
if ( retval != MPI_SUCCESS )
print_error("MPI_Info_get_nkeys did not return MPI_SUCCESS", retval, TEST_CONTINUE);
if ( nkeys > initial_nkeys )
event_handle_set_info_updated = 1;
else
print_error("MPI_T_event_handle_set_info did not update info object", NO_MPI_ERROR_CODE, TEST_CONTINUE);
print_debug("MPI_T_event_handle_get_info nkeys is %d\n", nkeys);
// Register Callback
retval = MPI_T_event_register_callback(event_registration, cb_safety, MPI_INFO_NULL, cb_user_data, test_event_cb_function);
if ( retval != MPI_SUCCESS )
print_error("MPI_T_event_register_callback did not return MPI_SUCCESS", retval, TEST_EXIT);
//
// Get Handle Info
//
retval = MPI_T_event_callback_get_info(event_registration, cb_safety, &info);
if ( retval != MPI_SUCCESS ) {
print_error("MPI_T_event_callback_get_info did not return MPI_SUCCESS", retval, TEST_CONTINUE);
event_callback_get_info_success = 0;
}
//
// Get And Store Callback Info Key Count
//
retval = MPI_Info_get_nkeys(info, &nkeys);
if ( retval != MPI_SUCCESS )
print_error("MPI_Info_get_nkeys did not return MPI_SUCCESS", retval, TEST_CONTINUE);
else
initial_nkeys = nkeys;
print_debug("MPI_Info_get_nkeys nkeys is %d\n", nkeys);
//
// Add Entry To Callback Info
//
retval = MPI_Info_set(info, "randomkey", "randomkeyvalue");
if ( retval != MPI_SUCCESS )
print_error("MPI_info_set did not return MPI_SUCCESS", retval, TEST_CONTINUE);
print_info_obj(info);
retval = MPI_Info_get_nkeys(info, &nkeys);
if ( retval != MPI_SUCCESS )
print_error("MPI_Info_get_nkeys did not return MPI_SUCCESS", retval, TEST_CONTINUE);
print_debug("After MPI_Info_set, MPI_Info_get_nkeys nkeys is %d\n", nkeys);
//
// Confirm Entry Has Been Added
//
MPI_Info_get_nthkey( info, 0, key );
retval = MPI_Info_get( info, key, vallen, value, &flag );
if ( retval != MPI_SUCCESS ) {
print_error("MPI_Info_get did not return MPI_SUCCESS", retval, TEST_CONTINUE);
}
else
print_debug("Verifying that info values are %d:%s:%s:%d\n", flag, key, value);
//
// Set Callback Info
//
retval = MPI_T_event_callback_set_info(event_registration, cb_safety, info);
if ( retval != MPI_SUCCESS ) {
print_error("MPI_T_event_callback_set_info did not return MPI_SUCCESS", retval, TEST_CONTINUE);
event_callback_set_info_success = 0;
}
//
// Get Event Callback Info
//
retval = MPI_T_event_callback_get_info(event_registration, cb_safety, &info);
if ( retval != MPI_SUCCESS )
print_error("MPI_T_event_callback_get_info did not return MPI_SUCCESS", retval, TEST_CONTINUE);
//
// Test For Increase In Nkeys To Confirm Update
//
retval = MPI_Info_get_nkeys(info, &nkeys);
if ( retval != MPI_SUCCESS )
print_error("MPI_Info_get_nkeys did not return MPI_SUCCESS", retval, TEST_CONTINUE);
if ( nkeys > initial_nkeys )
event_callback_set_info_updated = 1;
else
print_error("MPI_T_event_callback_set_info did not update info object", NO_MPI_ERROR_CODE, TEST_CONTINUE);
print_debug("MPI_T_event_callback_get_info nkeys is %d\n", nkeys);
}
int main (int argc, char** argv)
{
test_init("MPI_T Events Callback Tests", argc, argv);
test_handle_alloc_register_free();
test_info();
print_results();
MPI_T_finalize();
MPI_Finalize();
return 0;
}