forked from HDFGroup/hdf5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcache_image.c
7799 lines (6089 loc) · 225 KB
/
cache_image.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
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
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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 LICENSE 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 *
* [email protected]. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
* This file contains tests specific to the cache image
* feature implemented in H5C.c
*/
#include "cache_common.h"
#include "genall5.h"
/* global variable declarations: */
static const char *FILENAMES[] = {"cache_image_test", NULL};
/* local utility function declarations */
static void create_datasets(hid_t file_id, int min_dset, int max_dset);
static void delete_datasets(hid_t file_id, int min_dset, int max_dset);
static void open_hdf5_file(bool create_file, bool mdci_sbem_expected, bool read_only, bool set_mdci_fapl,
bool config_fsm, bool set_eoc, const char *hdf_file_name,
unsigned cache_image_flags, hid_t *file_id_ptr, H5F_t **file_ptr_ptr,
H5C_t **cache_ptr_ptr);
static void attempt_swmr_open_hdf5_file(bool create_file, bool set_mdci_fapl, const char *hdf_file_name);
static void verify_datasets(hid_t file_id, int min_dset, int max_dset);
/* local test function declarations */
static unsigned check_cache_image_ctl_flow_1(bool single_file_vfd);
static unsigned check_cache_image_ctl_flow_2(bool single_file_vfd);
static unsigned check_cache_image_ctl_flow_3(bool single_file_vfd);
static unsigned check_cache_image_ctl_flow_4(bool single_file_vfd);
static unsigned check_cache_image_ctl_flow_5(bool single_file_vfd);
static unsigned check_cache_image_ctl_flow_6(bool single_file_vfd);
static unsigned cache_image_smoke_check_1(bool single_file_vfd);
static unsigned cache_image_smoke_check_2(bool single_file_vfd);
static unsigned cache_image_smoke_check_3(bool single_file_vfd);
static unsigned cache_image_smoke_check_4(bool single_file_vfd);
static unsigned cache_image_smoke_check_5(bool single_file_vfd);
static unsigned cache_image_smoke_check_6(bool single_file_vfd);
static unsigned cache_image_api_error_check_1(bool single_file_vfd);
static unsigned cache_image_api_error_check_2(bool single_file_vfd);
static unsigned cache_image_api_error_check_3(bool single_file_vfd);
static unsigned cache_image_api_error_check_4(bool single_file_vfd);
static unsigned get_free_sections_test(bool single_file_vfd);
static unsigned evict_on_close_test(bool single_file_vfd);
/****************************************************************************/
/***************************** Utility Functions ****************************/
/****************************************************************************/
/*-------------------------------------------------------------------------
* Function: create_datasets()
*
* Purpose: If pass is true on entry, create the specified datasets
* in the indicated file.
*
* Datasets and their contents must be well known, as we
* will verify that they contain the expected data later.
*
* On failure, set pass to false, and set failure_mssg
* to point to an appropriate failure message.
*
* Do nothing if pass is false on entry.
*
* Return: void
*
*-------------------------------------------------------------------------
*/
#define CHUNK_SIZE 10
#define DSET_SIZE (40 * CHUNK_SIZE)
#define MAX_NUM_DSETS 256
static void
create_datasets(hid_t file_id, int min_dset, int max_dset)
{
const char *fcn_name = "create_datasets()";
char dset_name[64];
bool show_progress = false;
bool valid_chunk;
bool verbose = false;
int cp = 0;
int i, j, k, l, m;
int data_chunk[CHUNK_SIZE][CHUNK_SIZE];
herr_t status;
hid_t dataspace_id = H5I_INVALID_HID;
hid_t filespace_ids[MAX_NUM_DSETS];
hid_t memspace_id = H5I_INVALID_HID;
hid_t dataset_ids[MAX_NUM_DSETS];
hid_t properties = H5I_INVALID_HID;
hsize_t dims[2];
hsize_t a_size[2];
hsize_t offset[2];
hsize_t chunk_size[2];
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
assert(0 <= min_dset);
assert(min_dset <= max_dset);
assert(max_dset < MAX_NUM_DSETS);
/* create the datasets */
if (pass) {
i = min_dset;
while ((pass) && (i <= max_dset)) {
/* create a dataspace for the chunked dataset */
dims[0] = DSET_SIZE;
dims[1] = DSET_SIZE;
dataspace_id = H5Screate_simple(2, dims, NULL);
if (dataspace_id < 0) {
pass = false;
failure_mssg = "H5Screate_simple() failed.";
}
/* set the dataset creation plist to specify that the raw data is
* to be partitioned into 10X10 element chunks.
*/
if (pass) {
chunk_size[0] = CHUNK_SIZE;
chunk_size[1] = CHUNK_SIZE;
properties = H5Pcreate(H5P_DATASET_CREATE);
if (properties < 0) {
pass = false;
failure_mssg = "H5Pcreate() failed.";
}
}
if (pass) {
if (H5Pset_chunk(properties, 2, chunk_size) < 0) {
pass = false;
failure_mssg = "H5Pset_chunk() failed.";
}
}
/* create the dataset */
if (pass) {
snprintf(dset_name, sizeof(dset_name), "/dset%03d", i);
dataset_ids[i] = H5Dcreate2(file_id, dset_name, H5T_STD_I32BE, dataspace_id, H5P_DEFAULT,
properties, H5P_DEFAULT);
if (dataset_ids[i] < 0) {
pass = false;
failure_mssg = "H5Dcreate() failed.";
}
}
/* get the file space ID */
if (pass) {
filespace_ids[i] = H5Dget_space(dataset_ids[i]);
if (filespace_ids[i] < 0) {
pass = false;
failure_mssg = "H5Dget_space() failed.";
}
}
i++;
}
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
/* create the mem space to be used to read and write chunks */
if (pass) {
dims[0] = CHUNK_SIZE;
dims[1] = CHUNK_SIZE;
memspace_id = H5Screate_simple(2, dims, NULL);
if (memspace_id < 0) {
pass = false;
failure_mssg = "H5Screate_simple() failed.";
}
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
/* select in memory hyperslab */
if (pass) {
offset[0] = 0; /*offset of hyperslab in memory*/
offset[1] = 0;
a_size[0] = CHUNK_SIZE; /*size of hyperslab*/
a_size[1] = CHUNK_SIZE;
status = H5Sselect_hyperslab(memspace_id, H5S_SELECT_SET, offset, NULL, a_size, NULL);
if (status < 0) {
pass = false;
failure_mssg = "H5Sselect_hyperslab() failed.";
}
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
/* initialize all datasets on a round robin basis */
i = 0;
while ((pass) && (i < DSET_SIZE)) {
j = 0;
while ((pass) && (j < DSET_SIZE)) {
m = min_dset;
while ((pass) && (m <= max_dset)) {
/* initialize the slab */
for (k = 0; k < CHUNK_SIZE; k++) {
for (l = 0; l < CHUNK_SIZE; l++) {
data_chunk[k][l] = (DSET_SIZE * DSET_SIZE * m) + (DSET_SIZE * (i + k)) + j + l;
}
}
/* select on disk hyperslab */
offset[0] = (hsize_t)i; /*offset of hyperslab in file*/
offset[1] = (hsize_t)j;
a_size[0] = CHUNK_SIZE; /*size of hyperslab*/
a_size[1] = CHUNK_SIZE;
status = H5Sselect_hyperslab(filespace_ids[m], H5S_SELECT_SET, offset, NULL, a_size, NULL);
if (status < 0) {
pass = false;
failure_mssg = "disk H5Sselect_hyperslab() failed.";
}
/* write the chunk to file */
status = H5Dwrite(dataset_ids[m], H5T_NATIVE_INT, memspace_id, filespace_ids[m], H5P_DEFAULT,
data_chunk);
if (status < 0) {
pass = false;
failure_mssg = "H5Dwrite() failed.";
}
m++;
}
j += CHUNK_SIZE;
}
i += CHUNK_SIZE;
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
/* read data from datasets and validate it */
i = 0;
while ((pass) && (i < DSET_SIZE)) {
j = 0;
while ((pass) && (j < DSET_SIZE)) {
m = min_dset;
while ((pass) && (m <= max_dset)) {
/* select on disk hyperslab */
offset[0] = (hsize_t)i; /* offset of hyperslab in file */
offset[1] = (hsize_t)j;
a_size[0] = CHUNK_SIZE; /* size of hyperslab */
a_size[1] = CHUNK_SIZE;
status = H5Sselect_hyperslab(filespace_ids[m], H5S_SELECT_SET, offset, NULL, a_size, NULL);
if (status < 0) {
pass = false;
failure_mssg = "disk hyperslab create failed.";
}
/* read the chunk from file */
if (pass) {
status = H5Dread(dataset_ids[m], H5T_NATIVE_INT, memspace_id, filespace_ids[m],
H5P_DEFAULT, data_chunk);
if (status < 0) {
pass = false;
failure_mssg = "disk hyperslab create failed.";
}
}
/* validate the slab */
if (pass) {
valid_chunk = true;
for (k = 0; k < CHUNK_SIZE; k++) {
for (l = 0; l < CHUNK_SIZE; l++) {
if (data_chunk[k][l] !=
((DSET_SIZE * DSET_SIZE * m) + (DSET_SIZE * (i + k)) + j + l)) {
valid_chunk = false;
if (verbose) {
fprintf(stdout, "data_chunk[%0d][%0d] = %0d, expect %0d.\n", k, l,
data_chunk[k][l],
((DSET_SIZE * DSET_SIZE * m) + (DSET_SIZE * (i + k)) + j + l));
fprintf(stdout, "m = %d, i = %d, j = %d, k = %d, l = %d\n", m, i, j, k,
l);
}
}
}
}
if (!valid_chunk) {
pass = false;
failure_mssg = "slab validation failed.";
if (verbose) {
fprintf(stdout, "Chunk (%0d, %0d) in /dset%03d is invalid.\n", i, j, m);
}
}
}
m++;
}
j += CHUNK_SIZE;
}
i += CHUNK_SIZE;
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
/* close the file spaces */
i = min_dset;
while ((pass) && (i <= max_dset)) {
if (H5Sclose(filespace_ids[i]) < 0) {
pass = false;
failure_mssg = "H5Sclose() failed.";
}
i++;
}
/* close the datasets */
i = min_dset;
while ((pass) && (i <= max_dset)) {
if (H5Dclose(dataset_ids[i]) < 0) {
pass = false;
failure_mssg = "H5Dclose() failed.";
}
i++;
}
/* close the mem space */
if (pass) {
if (H5Sclose(memspace_id) < 0) {
pass = false;
failure_mssg = "H5Sclose(memspace_id) failed.";
}
}
} /* create_datasets() */
/*-------------------------------------------------------------------------
* Function: delete_datasets()
*
* Purpose: If pass is true on entry, verify and then delete the
* dataset(s) indicated by min_dset and max_dset in the
* indicated file.
*
* Datasets and their contents must be well know, as we
* will verify that they contain the expected data later.
*
* On failure, set pass to false, and set failure_mssg
* to point to an appropriate failure message.
*
* Do nothing if pass is false on entry.
*
* Return: void
*
*-------------------------------------------------------------------------
*/
static void
delete_datasets(hid_t file_id, int min_dset, int max_dset)
{
const char *fcn_name = "delete_datasets()";
char dset_name[64];
bool show_progress = false;
int cp = 0;
int i;
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
assert(0 <= min_dset);
assert(min_dset <= max_dset);
assert(max_dset < MAX_NUM_DSETS);
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
/* first, verify the contents of the target dataset(s) */
verify_datasets(file_id, min_dset, max_dset);
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
/* now delete the target datasets */
if (pass) {
i = min_dset;
while ((pass) && (i <= max_dset)) {
snprintf(dset_name, sizeof(dset_name), "/dset%03d", i);
if (H5Ldelete(file_id, dset_name, H5P_DEFAULT) < 0) {
pass = false;
failure_mssg = "H5Ldelete() failed.";
}
i++;
}
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
} /* delete_datasets() */
/*-------------------------------------------------------------------------
* Function: open_hdf5_file()
*
* Purpose: If pass is true on entry, create or open the specified HDF5
* and test to see if it has a metadata cache image superblock
* extension message.
*
* Set pass to false and issue a suitable failure
* message if either the file contains a metadata cache image
* superblock extension and mdci_sbem_expected is true, or
* vice versa.
*
* If mdci_sbem_expected is true, also verify that the metadata
* cache has been advised of this.
*
* If read_only is true, open the file read only. Otherwise
* open the file read/write.
*
* If set_mdci_fapl is true, set the metadata cache image
* FAPL entry when opening the file, and verify that the
* metadata cache is notified.
*
* If config_fsm is true, setup the persistent free space
* manager. Note that this flag may only be set if
* create_file is also true.
*
* Return pointers to the cache data structure and file data
* structures.
*
* On failure, set pass to false, and set failure_mssg
* to point to an appropriate failure message.
*
* Do nothing if pass is false on entry.
*
* Return: void
*
*-------------------------------------------------------------------------
*/
static void
open_hdf5_file(bool create_file, bool mdci_sbem_expected, bool read_only, bool set_mdci_fapl, bool config_fsm,
bool set_eoc, const char *hdf_file_name, unsigned cache_image_flags, hid_t *file_id_ptr,
H5F_t **file_ptr_ptr, H5C_t **cache_ptr_ptr)
{
const char *fcn_name = "open_hdf5_file()";
bool show_progress = false;
bool verbose = false;
int cp = 0;
hid_t fapl_id = H5I_INVALID_HID;
hid_t fcpl_id = H5I_INVALID_HID;
hid_t file_id = H5I_INVALID_HID;
herr_t result;
H5F_t *file_ptr = NULL;
H5C_t *cache_ptr = NULL;
H5C_cache_image_ctl_t image_ctl;
H5AC_cache_image_config_t cache_image_config = {H5AC__CURR_CACHE_IMAGE_CONFIG_VERSION, true, false,
H5AC__CACHE_IMAGE__ENTRY_AGEOUT__NONE};
if (pass) {
/* opening the file both read only and with a cache image
* requested is a contradiction. We resolve it by ignoring
* the cache image request silently.
*/
if ((create_file && mdci_sbem_expected) || (create_file && read_only) ||
(config_fsm && !create_file) || (hdf_file_name == NULL) ||
((set_mdci_fapl) && (cache_image_flags == 0)) ||
((set_mdci_fapl) && ((cache_image_flags & ~H5C_CI__ALL_FLAGS) != 0)) || (file_id_ptr == NULL) ||
(file_ptr_ptr == NULL) || (cache_ptr_ptr == NULL)) {
failure_mssg = "Bad param(s) on entry to open_hdf5_file().\n";
pass = false;
}
else if (verbose) {
fprintf(stdout, "%s: HDF file name = \"%s\".\n", fcn_name, hdf_file_name);
}
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
/* create a file access property list. */
if (pass) {
fapl_id = h5_fileaccess();
if (fapl_id < 0) {
pass = false;
failure_mssg = "h5_fileaccess() failed.\n";
}
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
/* call H5Pset_libver_bounds() on the fapl_id */
if (pass) {
if (H5Pset_libver_bounds(fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) {
pass = false;
failure_mssg = "H5Pset_libver_bounds() failed.\n";
}
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
/* get metadata cache image config -- verify that it is the default */
if (pass) {
result = H5Pget_mdc_image_config(fapl_id, &cache_image_config);
if (result < 0) {
pass = false;
failure_mssg = "H5Pget_mdc_image_config() failed.\n";
}
if ((cache_image_config.version != H5AC__CURR_CACHE_IMAGE_CONFIG_VERSION) ||
(cache_image_config.generate_image != false) ||
(cache_image_config.save_resize_status != false) ||
(cache_image_config.entry_ageout != H5AC__CACHE_IMAGE__ENTRY_AGEOUT__NONE)) {
pass = false;
failure_mssg = "Unexpected default cache image config.\n";
}
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
/* set metadata cache image fapl entry if indicated */
if ((pass) && (set_mdci_fapl)) {
/* set cache image config fields to taste */
cache_image_config.generate_image = true;
cache_image_config.save_resize_status = false;
cache_image_config.entry_ageout = H5AC__CACHE_IMAGE__ENTRY_AGEOUT__NONE;
result = H5Pset_mdc_image_config(fapl_id, &cache_image_config);
if (result < 0) {
pass = false;
failure_mssg = "H5Pset_mdc_image_config() failed.\n";
}
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
/* setup the persistent free space manager if indicated */
if ((pass) && (config_fsm)) {
fcpl_id = H5Pcreate(H5P_FILE_CREATE);
if (fcpl_id <= 0) {
pass = false;
failure_mssg = "H5Pcreate(H5P_FILE_CREATE) failed.";
}
}
if ((pass) && (config_fsm)) {
if (H5Pset_file_space_strategy(fcpl_id, H5F_FSPACE_STRATEGY_PAGE, true, (hsize_t)1) < 0) {
pass = false;
failure_mssg = "H5Pset_file_space_strategy() failed.";
}
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
/* set evict on close if indicated */
if ((pass) && (set_eoc)) {
if (H5Pset_evict_on_close(fapl_id, true) < 0) {
pass = false;
failure_mssg = "H5Pset_evict_on_close() failed.";
}
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
/* open the file */
if (pass) {
if (create_file) {
if (fcpl_id != -1)
file_id = H5Fcreate(hdf_file_name, H5F_ACC_TRUNC, fcpl_id, fapl_id);
else
file_id = H5Fcreate(hdf_file_name, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id);
}
else {
if (read_only)
file_id = H5Fopen(hdf_file_name, H5F_ACC_RDONLY, fapl_id);
else
file_id = H5Fopen(hdf_file_name, H5F_ACC_RDWR, fapl_id);
}
/* tidy up */
H5Pclose(fapl_id);
if (file_id < 0) {
pass = false;
failure_mssg = "H5Fcreate() or H5Fopen() failed.\n";
}
else {
file_ptr = (struct H5F_t *)H5VL_object_verify(file_id, H5I_FILE);
if (file_ptr == NULL) {
pass = false;
failure_mssg = "Can't get file_ptr.";
if (verbose) {
fprintf(stdout, "%s: Can't get file_ptr.\n", fcn_name);
}
}
}
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
/* get a pointer to the files internal data structure and then
* to the cache structure
*/
if (pass) {
if (file_ptr->shared->cache == NULL) {
pass = false;
failure_mssg = "can't get cache pointer(1).\n";
}
else {
cache_ptr = file_ptr->shared->cache;
}
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
/* verify expected metadata cache status */
/* get the cache image control structure from the cache, and verify
* that it contains the expected values.
*
* Then set the flags in this structure to the specified value.
*/
if (pass) {
if (H5C__get_cache_image_config(cache_ptr, &image_ctl) < 0) {
pass = false;
failure_mssg = "error returned by H5C__get_cache_image_config().";
}
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
if (pass) {
if (set_mdci_fapl) {
if (read_only) {
if ((image_ctl.version != H5AC__CURR_CACHE_IMAGE_CONFIG_VERSION) ||
(image_ctl.generate_image != false) || (image_ctl.save_resize_status != false) ||
(image_ctl.entry_ageout != H5AC__CACHE_IMAGE__ENTRY_AGEOUT__NONE) ||
(image_ctl.flags != H5C_CI__ALL_FLAGS)) {
pass = false;
failure_mssg = "Unexpected image_ctl values(1).\n";
}
}
else {
if ((image_ctl.version != H5AC__CURR_CACHE_IMAGE_CONFIG_VERSION) ||
(image_ctl.generate_image != true) || (image_ctl.save_resize_status != false) ||
(image_ctl.entry_ageout != H5AC__CACHE_IMAGE__ENTRY_AGEOUT__NONE) ||
(image_ctl.flags != H5C_CI__ALL_FLAGS)) {
pass = false;
failure_mssg = "Unexpected image_ctl values(2).\n";
}
}
}
else {
if ((image_ctl.version != H5AC__CURR_CACHE_IMAGE_CONFIG_VERSION) ||
(image_ctl.generate_image != false) || (image_ctl.save_resize_status != false) ||
(image_ctl.entry_ageout != H5AC__CACHE_IMAGE__ENTRY_AGEOUT__NONE) ||
(image_ctl.flags != H5C_CI__ALL_FLAGS)) {
pass = false;
failure_mssg = "Unexpected image_ctl values(3).\n";
}
}
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
if ((pass) && (set_mdci_fapl)) {
image_ctl.flags = cache_image_flags;
if (H5C_set_cache_image_config(file_ptr, cache_ptr, &image_ctl) < 0) {
pass = false;
failure_mssg = "error returned by H5C_set_cache_image_config().";
}
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
if (pass) {
if (cache_ptr->close_warning_received == true) {
pass = false;
failure_mssg = "Unexpected value of close_warning_received.\n";
}
if (mdci_sbem_expected) {
if (read_only) {
if ((cache_ptr->load_image != true) || (cache_ptr->delete_image != false)) {
pass = false;
failure_mssg = "mdci sb extension message not present?\n";
}
}
else {
if ((cache_ptr->load_image != true) || (cache_ptr->delete_image != true)) {
pass = false;
failure_mssg = "mdci sb extension message not present?\n";
}
}
}
else {
if ((cache_ptr->load_image == true) || (cache_ptr->delete_image == true)) {
pass = false;
failure_mssg = "mdci sb extension message present?\n";
}
}
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
if (pass) {
*file_id_ptr = file_id;
*file_ptr_ptr = file_ptr;
*cache_ptr_ptr = cache_ptr;
}
if (show_progress)
fprintf(stdout, "%s: cp = %d -- exiting.\n", fcn_name, cp++);
} /* open_hdf5_file() */
/*-------------------------------------------------------------------------
* Function: attempt_swmr_open_hdf5_file()
*
* Purpose: If pass is true on entry, attempt to create or open the
* specified HDF5 file with SWMR, and also with cache image
* creation if requested.
*
* In all cases, the attempted open or create should fail.
*
* Do nothing if pass is false on entry.
*
* Return: void
*
*-------------------------------------------------------------------------
*/
static void
attempt_swmr_open_hdf5_file(const bool create_file, const bool set_mdci_fapl, const char *hdf_file_name)
{
const char *fcn_name = "attempt_swmr_open_hdf5_file()";
bool show_progress = false;
int cp = 0;
hid_t fapl_id = H5I_INVALID_HID;
hid_t file_id = H5I_INVALID_HID;
herr_t result;
H5AC_cache_image_config_t cache_image_config = {H5AC__CURR_CACHE_IMAGE_CONFIG_VERSION, true, false,
H5AC__CACHE_IMAGE__ENTRY_AGEOUT__NONE};
/* create a file access property list. */
if (pass) {
fapl_id = h5_fileaccess();
if (fapl_id < 0) {
pass = false;
failure_mssg = "h5_fileaccess() failed.\n";
}
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
/* call H5Pset_libver_bounds() on the fapl_id */
if (pass) {
if (H5Pset_libver_bounds(fapl_id, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0) {
pass = false;
failure_mssg = "H5Pset_libver_bounds() failed.\n";
}
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
/* set metadata cache image fapl entry if indicated */
if ((pass) && (set_mdci_fapl)) {
/* set cache image config fields to taste */
cache_image_config.generate_image = true;
cache_image_config.save_resize_status = false;
cache_image_config.entry_ageout = H5AC__CACHE_IMAGE__ENTRY_AGEOUT__NONE;
result = H5Pset_mdc_image_config(fapl_id, &cache_image_config);
if (result < 0) {
pass = false;
failure_mssg = "H5Pset_mdc_image_config() failed.\n";
}
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
/* open the file */
if (pass) {
if (create_file) {
H5E_BEGIN_TRY
{
file_id = H5Fcreate(hdf_file_name, H5F_ACC_TRUNC | H5F_ACC_SWMR_WRITE, H5P_DEFAULT, fapl_id);
}
H5E_END_TRY
}
else {
H5E_BEGIN_TRY
{
file_id = H5Fopen(hdf_file_name, H5F_ACC_RDWR | H5F_ACC_SWMR_WRITE, fapl_id);
}
H5E_END_TRY
}
if (file_id >= 0) {
pass = false;
failure_mssg = "SWMR H5Fcreate() or H5Fopen() succeeded.\n";
}
}
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
} /* attempt_swmr_open_hdf5_file() */
/*-------------------------------------------------------------------------
* Function: verify_datasets()
*
* Purpose: If pass is true on entry, verify that the datasets in the
* file exist and contain the expected data.
*
* Note that these datasets were created by
* create_datasets() above. Thus any changes in that
* function must be reflected in this function, and
* vise-versa.
*
* On failure, set pass to false, and set failure_mssg
* to point to an appropriate failure message.
*
* Do nothing if pass is false on entry.
*
* Return: void
*
*-------------------------------------------------------------------------
*/
static void
verify_datasets(hid_t file_id, int min_dset, int max_dset)
{
const char *fcn_name = "verify_datasets()";
char dset_name[64];
bool show_progress = false;
bool valid_chunk;
bool verbose = false;
int cp = 0;
int i, j, k, l, m;
int data_chunk[CHUNK_SIZE][CHUNK_SIZE];
herr_t status;
hid_t filespace_ids[MAX_NUM_DSETS];
hid_t memspace_id = H5I_INVALID_HID;
hid_t dataset_ids[MAX_NUM_DSETS];
hsize_t dims[2];
hsize_t a_size[2];
hsize_t offset[2];
if (show_progress)
fprintf(stdout, "%s: cp = %d.\n", fcn_name, cp++);
assert(0 <= min_dset);
assert(min_dset <= max_dset);
assert(max_dset < MAX_NUM_DSETS);
/* open the datasets */
if (pass) {
i = min_dset;
while ((pass) && (i <= max_dset)) {
/* open the dataset */