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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
* distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* Programmer: Quincey Koziol
* Wednesday, April 8, 2020
*
* Purpose: Tests event sets.
*/
#include "h5test.h"
#include "H5srcdir.h"
#define EVENT_SET_NUM_CONNECTOR_IDS 2
const char *FILENAME[] = {"event_set_1", NULL};
hid_t connector_ids_g[EVENT_SET_NUM_CONNECTOR_IDS];
herr_t fake_wait_request_wait(void *req, uint64_t timeout, H5VL_request_status_t *status);
herr_t fake_wait_request_free(void *req);
/* A VOL class struct that describes a VOL class with no
* functionality, other than a wait that returns success.
*/
static const H5VL_class_t fake_wait_vol_g = {
H5VL_VERSION, /* VOL class struct version */
((H5VL_class_value_t)501), /* value */
"fake_wait", /* name */
0, /* connector version */
0, /* capability flags */
NULL, /* initialize */
NULL, /* terminate */
{
/* info_cls */
(size_t)0, /* size */
NULL, /* copy */
NULL, /* compare */
NULL, /* free */
NULL, /* to_str */
NULL, /* from_str */
},
{
/* wrap_cls */
NULL, /* get_object */
NULL, /* get_wrap_ctx */
NULL, /* wrap_object */
NULL, /* unwrap_object */
NULL, /* free_wrap_ctx */
},
{
/* attribute_cls */
NULL, /* create */
NULL, /* open */
NULL, /* read */
NULL, /* write */
NULL, /* get */
NULL, /* specific */
NULL, /* optional */
NULL /* close */
},
{
/* dataset_cls */
NULL, /* create */
NULL, /* open */
NULL, /* read */
NULL, /* write */
NULL, /* get */
NULL, /* specific */
NULL, /* optional */
NULL /* close */
},
{
/* datatype_cls */
NULL, /* commit */
NULL, /* open */
NULL, /* get */
NULL, /* specific */
NULL, /* optional */
NULL /* close */
},
{
/* file_cls */
NULL, /* create */
NULL, /* open */
NULL, /* get */
NULL, /* specific */
NULL, /* optional */
NULL /* close */
},
{
/* group_cls */
NULL, /* create */
NULL, /* open */
NULL, /* get */
NULL, /* specific */
NULL, /* optional */
NULL /* close */
},
{
/* link_cls */
NULL, /* create */
NULL, /* copy */
NULL, /* move */
NULL, /* get */
NULL, /* specific */
NULL /* optional */
},
{
/* object_cls */
NULL, /* open */
NULL, /* copy */
NULL, /* get */
NULL, /* specific */
NULL /* optional */
},
{
/* introspect_cls */
NULL, /* get_conn_cls */
NULL, /* get_cap_flags */
NULL, /* opt_query */
},
{
/* request_cls */
fake_wait_request_wait, /* wait */
NULL, /* notify */
NULL, /* cancel */
NULL, /* specific */
NULL, /* optional */
fake_wait_request_free /* free */
},
{
/* blob_cls */
NULL, /* put */
NULL, /* get */
NULL, /* specific */
NULL /* optional */
},
{
/* token_cls */
NULL, /* cmp */
NULL, /* to_str */
NULL /* from_str */
},
NULL /* optional */
};
herr_t
fake_wait_request_wait(void H5_ATTR_UNUSED *req, uint64_t H5_ATTR_UNUSED timeout,
H5VL_request_status_t *status)
{
/* Set status if requested */
if (status)
*status = H5VL_REQUEST_STATUS_SUCCEED;
return 0;
} /* end H5_daos_req_wait() */
herr_t
fake_wait_request_free(void H5_ATTR_UNUSED *req)
{
return 0;
} /* end fake_wait_request_free() */
/*-------------------------------------------------------------------------
* Function: test_es_create
*
* Purpose: Tests creating event sets.
*
* Return: Success: 0
* Failure: number of errors
*
* Programmer: Quincey Koziol
* Thursday, April 9, 2020
*
*-------------------------------------------------------------------------
*/
static int
test_es_create(void)
{
hid_t es_id; /* Event set ID */
size_t count; /* # of events in set */
size_t num_errs; /* # of failed events in set */
uint64_t num_ops; /* # of events inserted into set */
hbool_t err_occurred; /* Whether an error has occurred */
TESTING("event set creation");
/* Create an event set */
if ((es_id = H5EScreate()) < 0)
TEST_ERROR;
/* Query the # of events in empty event set */
count = 0;
if (H5ESget_count(es_id, &count) < 0)
TEST_ERROR;
if (count > 0)
FAIL_PUTS_ERROR("should be empty event set");
/* Check for errors */
err_occurred = FALSE;
if (H5ESget_err_status(es_id, &err_occurred) < 0)
TEST_ERROR;
if (err_occurred)
FAIL_PUTS_ERROR("should not be an error for the event set");
/* Check errors count */
num_errs = 0;
if (H5ESget_err_count(es_id, &num_errs) < 0)
TEST_ERROR;
if (num_errs)
FAIL_PUTS_ERROR("should not be any errors for the event set");
/* Check errors count */
num_ops = 0;
if (H5ESget_op_counter(es_id, &num_ops) < 0)
TEST_ERROR;
if (num_ops)
FAIL_PUTS_ERROR("should not be any operations for the event set yet");
/* Close the event set */
if (H5ESclose(es_id) < 0)
TEST_ERROR;
PASSED();
return 0;
error:
H5E_BEGIN_TRY
{
H5ESclose(es_id);
}
H5E_END_TRY;
return 1;
}
/*-------------------------------------------------------------------------
* Function: test_es_none
*
* Purpose: Tests for passing H5ES_NONE to H5ES routines
*
* Return: Success: 0
* Failure: number of errors
*
* Programmer: Quincey Koziol
* Friday, February 26, 2021
*
*-------------------------------------------------------------------------
*/
static int
test_es_none(void)
{
TESTING("event set H5ES_NONE");
/* Wait */
if (H5ESwait(H5ES_NONE, 0, NULL, NULL) < 0)
TEST_ERROR;
/* Cancel */
if (H5EScancel(H5ES_NONE, NULL, NULL) < 0)
TEST_ERROR;
/* Get count */
if (H5ESget_count(H5ES_NONE, NULL) < 0)
TEST_ERROR;
/* Get op counter */
if (H5ESget_op_counter(H5ES_NONE, NULL) < 0)
TEST_ERROR;
/* Get error status */
if (H5ESget_err_status(H5ES_NONE, NULL) < 0)
TEST_ERROR;
/* Get error count */
if (H5ESget_err_count(H5ES_NONE, NULL) < 0)
TEST_ERROR;
/* Get error info */
if (H5ESget_err_info(H5ES_NONE, 0, NULL, NULL) < 0)
TEST_ERROR;
/* Register insert function */
if (H5ESregister_insert_func(H5ES_NONE, NULL, NULL) < 0)
TEST_ERROR;
/* Register complete function */
if (H5ESregister_complete_func(H5ES_NONE, NULL, NULL) < 0)
TEST_ERROR;
/* Close */
if (H5ESclose(H5ES_NONE) < 0)
TEST_ERROR;
PASSED();
return 0;
error:
return 1;
}
/*-------------------------------------------------------------------------
* Function: test_es_get_requests
*
* Purpose: Tests getting requests from event set.
*
* Return: Success: 0
* Failure: number of errors
*
* Programmer: Neil Fortner
* Wednesday, November 24, 2021
*
*-------------------------------------------------------------------------
*/
static int
test_es_get_requests(void)
{
hid_t es_id; /* Event set ID */
hid_t connector_ids[2]; /* Connector IDs */
void *requests[2]; /* Requests */
int req_targets[2]; /* Dummy targets for void * requests */
size_t count; /* # of events in set */
hbool_t op_failed; /* Whether an operation failed (unused) */
TESTING("event set get requests");
/* Create an event set */
if ((es_id = H5EScreate()) < 0)
TEST_ERROR;
/* Get number of requests in event set */
count = 3;
if (H5ESget_requests(es_id, H5_ITER_NATIVE, NULL, NULL, 0, &count) < 0)
TEST_ERROR;
if (count != 0)
TEST_ERROR;
/* Get only connector IDs */
count = 3;
connector_ids[0] = H5I_INVALID_HID;
connector_ids[1] = H5I_INVALID_HID;
if (H5ESget_requests(es_id, H5_ITER_NATIVE, connector_ids, NULL, 2, &count) < 0)
TEST_ERROR;
if (count != 0)
TEST_ERROR;
if (connector_ids[0] != H5I_INVALID_HID)
TEST_ERROR;
if (connector_ids[1] != H5I_INVALID_HID)
TEST_ERROR;
/* Get only requests */
count = 3;
requests[0] = NULL;
requests[1] = NULL;
if (H5ESget_requests(es_id, H5_ITER_NATIVE, NULL, requests, 2, &count) < 0)
TEST_ERROR;
if (count != 0)
TEST_ERROR;
if (requests[0] != NULL)
TEST_ERROR;
if (requests[1] != NULL)
TEST_ERROR;
/* Get both */
count = 3;
connector_ids[0] = H5I_INVALID_HID;
connector_ids[1] = H5I_INVALID_HID;
requests[0] = NULL;
requests[1] = NULL;
if (H5ESget_requests(es_id, H5_ITER_NATIVE, connector_ids, requests, 2, &count) < 0)
TEST_ERROR;
if (count != 0)
TEST_ERROR;
if (connector_ids[0] != H5I_INVALID_HID)
TEST_ERROR;
if (connector_ids[1] != H5I_INVALID_HID)
TEST_ERROR;
if (requests[0] != NULL)
TEST_ERROR;
if (requests[1] != NULL)
TEST_ERROR;
/* Insert event into event set */
if (H5ESinsert_request(es_id, connector_ids_g[0], &req_targets[0]) < 0)
TEST_ERROR;
/* Get number of requests in event set */
count = 0;
if (H5ESget_requests(es_id, H5_ITER_NATIVE, NULL, NULL, 0, &count) < 0)
TEST_ERROR;
if (count != 1)
TEST_ERROR;
/* Get only connector IDs */
count = 0;
connector_ids[0] = H5I_INVALID_HID;
connector_ids[1] = H5I_INVALID_HID;
if (H5ESget_requests(es_id, H5_ITER_NATIVE, connector_ids, NULL, 2, &count) < 0)
TEST_ERROR;
if (count != 1)
TEST_ERROR;
if (connector_ids[0] != connector_ids_g[0])
TEST_ERROR;
if (connector_ids[1] != H5I_INVALID_HID)
TEST_ERROR;
/* Get only requests */
count = 0;
requests[0] = NULL;
requests[1] = NULL;
if (H5ESget_requests(es_id, H5_ITER_NATIVE, NULL, requests, 2, &count) < 0)
TEST_ERROR;
if (count != 1)
TEST_ERROR;
if (requests[0] != &req_targets[0])
TEST_ERROR;
if (requests[1] != NULL)
TEST_ERROR;
/* Get both */
count = 0;
connector_ids[0] = H5I_INVALID_HID;
connector_ids[1] = H5I_INVALID_HID;
requests[0] = NULL;
requests[1] = NULL;
if (H5ESget_requests(es_id, H5_ITER_NATIVE, connector_ids, requests, 2, &count) < 0)
TEST_ERROR;
if (count != 1)
TEST_ERROR;
if (connector_ids[0] != connector_ids_g[0])
TEST_ERROR;
if (connector_ids[1] != H5I_INVALID_HID)
TEST_ERROR;
if (requests[0] != &req_targets[0])
TEST_ERROR;
if (requests[1] != NULL)
TEST_ERROR;
/* Insert second event into event set */
if (H5ESinsert_request(es_id, connector_ids_g[1], &req_targets[1]) < 0)
TEST_ERROR;
/* Get number of requests in event set */
count = 0;
if (H5ESget_requests(es_id, H5_ITER_NATIVE, NULL, NULL, 0, &count) < 0)
TEST_ERROR;
if (count != 2)
TEST_ERROR;
/* Get only connector IDs */
count = 0;
connector_ids[0] = H5I_INVALID_HID;
connector_ids[1] = H5I_INVALID_HID;
if (H5ESget_requests(es_id, H5_ITER_INC, connector_ids, NULL, 2, &count) < 0)
TEST_ERROR;
if (count != 2)
TEST_ERROR;
if (connector_ids[0] != connector_ids_g[0])
TEST_ERROR;
if (connector_ids[1] != connector_ids_g[1])
TEST_ERROR;
/* Try with H5_ITER_DEC */
count = 0;
connector_ids[0] = H5I_INVALID_HID;
connector_ids[1] = H5I_INVALID_HID;
if (H5ESget_requests(es_id, H5_ITER_DEC, connector_ids, NULL, 2, &count) < 0)
TEST_ERROR;
if (count != 2)
TEST_ERROR;
if (connector_ids[0] != connector_ids_g[1])
TEST_ERROR;
if (connector_ids[1] != connector_ids_g[0])
TEST_ERROR;
/* Get only requests */
count = 0;
requests[0] = NULL;
requests[1] = NULL;
if (H5ESget_requests(es_id, H5_ITER_INC, NULL, requests, 2, &count) < 0)
TEST_ERROR;
if (count != 2)
TEST_ERROR;
if (requests[0] != &req_targets[0])
TEST_ERROR;
if (requests[1] != &req_targets[1])
TEST_ERROR;
/* Try with H5_ITER_DEC */
count = 0;
requests[0] = NULL;
requests[1] = NULL;
if (H5ESget_requests(es_id, H5_ITER_DEC, NULL, requests, 2, &count) < 0)
TEST_ERROR;
if (count != 2)
TEST_ERROR;
if (requests[0] != &req_targets[1])
TEST_ERROR;
if (requests[1] != &req_targets[0])
TEST_ERROR;
/* Get both */
count = 0;
connector_ids[0] = H5I_INVALID_HID;
connector_ids[1] = H5I_INVALID_HID;
requests[0] = NULL;
requests[1] = NULL;
if (H5ESget_requests(es_id, H5_ITER_INC, connector_ids, requests, 2, &count) < 0)
TEST_ERROR;
if (count != 2)
TEST_ERROR;
if (connector_ids[0] != connector_ids_g[0])
TEST_ERROR;
if (connector_ids[1] != connector_ids_g[1])
TEST_ERROR;
if (requests[0] != &req_targets[0])
TEST_ERROR;
if (requests[1] != &req_targets[1])
TEST_ERROR;
/* Try with H5_ITER_DEC */
count = 0;
connector_ids[0] = H5I_INVALID_HID;
connector_ids[1] = H5I_INVALID_HID;
requests[0] = NULL;
requests[1] = NULL;
if (H5ESget_requests(es_id, H5_ITER_DEC, connector_ids, requests, 2, &count) < 0)
TEST_ERROR;
if (count != 2)
TEST_ERROR;
if (connector_ids[0] != connector_ids_g[1])
TEST_ERROR;
if (connector_ids[1] != connector_ids_g[0])
TEST_ERROR;
if (requests[0] != &req_targets[1])
TEST_ERROR;
if (requests[1] != &req_targets[0])
TEST_ERROR;
/* Get only first connector ID */
count = 0;
connector_ids[0] = H5I_INVALID_HID;
connector_ids[1] = H5I_INVALID_HID;
if (H5ESget_requests(es_id, H5_ITER_INC, connector_ids, NULL, 1, &count) < 0)
TEST_ERROR;
if (count != 2)
TEST_ERROR;
if (connector_ids[0] != connector_ids_g[0])
TEST_ERROR;
if (connector_ids[1] != H5I_INVALID_HID)
TEST_ERROR;
/* Try with H5_ITER_DEC */
count = 0;
connector_ids[0] = H5I_INVALID_HID;
connector_ids[1] = H5I_INVALID_HID;
if (H5ESget_requests(es_id, H5_ITER_DEC, connector_ids, NULL, 1, &count) < 0)
TEST_ERROR;
if (count != 2)
TEST_ERROR;
if (connector_ids[0] != connector_ids_g[1])
TEST_ERROR;
if (connector_ids[1] != H5I_INVALID_HID)
TEST_ERROR;
/* Get only first request */
count = 0;
requests[0] = NULL;
requests[1] = NULL;
if (H5ESget_requests(es_id, H5_ITER_INC, NULL, requests, 1, &count) < 0)
TEST_ERROR;
if (count != 2)
TEST_ERROR;
if (requests[0] != &req_targets[0])
TEST_ERROR;
if (requests[1] != NULL)
TEST_ERROR;
/* Try with H5_ITER_DEC */
count = 0;
requests[0] = NULL;
requests[1] = NULL;
if (H5ESget_requests(es_id, H5_ITER_DEC, NULL, requests, 1, &count) < 0)
TEST_ERROR;
if (count != 2)
TEST_ERROR;
if (requests[0] != &req_targets[1])
TEST_ERROR;
if (requests[1] != NULL)
TEST_ERROR;
/* Get only first of both */
count = 0;
connector_ids[0] = H5I_INVALID_HID;
connector_ids[1] = H5I_INVALID_HID;
requests[0] = NULL;
requests[1] = NULL;
if (H5ESget_requests(es_id, H5_ITER_INC, connector_ids, requests, 1, &count) < 0)
TEST_ERROR;
if (connector_ids[0] != connector_ids_g[0])
TEST_ERROR;
if (connector_ids[1] != H5I_INVALID_HID)
TEST_ERROR;
if (requests[0] != &req_targets[0])
TEST_ERROR;
if (requests[1] != NULL)
TEST_ERROR;
/* Try with H5_ITER_DEC */
count = 0;
connector_ids[0] = H5I_INVALID_HID;
connector_ids[1] = H5I_INVALID_HID;
requests[0] = NULL;
requests[1] = NULL;
if (H5ESget_requests(es_id, H5_ITER_DEC, connector_ids, requests, 1, &count) < 0)
TEST_ERROR;
if (connector_ids[0] != connector_ids_g[1])
TEST_ERROR;
if (connector_ids[1] != H5I_INVALID_HID)
TEST_ERROR;
if (requests[0] != &req_targets[1])
TEST_ERROR;
if (requests[1] != NULL)
TEST_ERROR;
/* Close the event set */
if (H5ESwait(es_id, 10000000, &count, &op_failed) < 0)
TEST_ERROR;
if (H5ESclose(es_id) < 0)
TEST_ERROR;
PASSED();
return 0;
error:
H5E_BEGIN_TRY
{
H5ESclose(es_id);
}
H5E_END_TRY;
return 1;
}
/*-------------------------------------------------------------------------
* Function: main
*
* Purpose: Tests event sets
*
* Return: Success: EXIT_SUCCESS
* Failure: EXIT_FAILURE
*
* Programmer: Quincey Koziol
* Wednesday, April 8, 2020
*
*-------------------------------------------------------------------------
*/
int
main(void)
{
hid_t fapl_id = H5I_INVALID_HID; /* File access property list */
int i; /* Local index variable */
int nerrors = 0; /* Error count */
/* Setup */
h5_reset();
fapl_id = h5_fileaccess();
/* Register dummy connector IDs */
for (i = 0; i < EVENT_SET_NUM_CONNECTOR_IDS; i++)
if ((connector_ids_g[i] = H5VLregister_connector(&fake_wait_vol_g, H5P_DEFAULT)) < 0)
TEST_ERROR;
/* Tests */
nerrors += test_es_create();
nerrors += test_es_none();
nerrors += test_es_get_requests();
/* Unregister dummy connectors */
for (i = 0; i < EVENT_SET_NUM_CONNECTOR_IDS; i++)
if (H5VLunregister_connector(connector_ids_g[i]) < 0)
TEST_ERROR;
/* Cleanup */
h5_cleanup(FILENAME, fapl_id);
/* Check for any errors */
if (nerrors)
goto error;
/* Report status */
HDputs("All event set tests passed.");
exit(EXIT_SUCCESS);
error:
HDputs("***** EVENT SET TESTS FAILED *****");
exit(EXIT_FAILURE);
} /* end main() */
|