forked from HDFGroup/vol-tests
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvol_file_test.c
2798 lines (2267 loc) · 83 KB
/
vol_file_test.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 COPYING file, which can be found at the root of the source code *
* distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases. *
* If you do not have access to either file, you may request a copy from *
* [email protected]. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "vol_file_test.h"
static int test_create_file(void);
static int test_create_file_invalid_params(void);
static int test_create_file_excl(void);
static int test_open_file(void);
static int test_open_file_invalid_params(void);
static int test_open_nonexistent_file(void);
static int test_file_open_overlap(void);
static int test_file_permission(void);
static int test_reopen_file(void);
static int test_close_file_invalid_id(void);
static int test_flush_file(void);
static int test_file_is_accessible(void);
static int test_file_property_lists(void);
static int test_get_file_intent(void);
static int test_get_file_obj_count(void);
static int test_file_mounts(void);
static int test_get_file_name(void);
#if 0 /* for native VOL connector test only */
static int test_filespace_info(void);
static int test_get_file_id(void);
static int test_file_close_degree(void);
static int test_get_file_free_sections(void);
static int test_get_file_size(void);
static int test_get_file_image(void);
static int test_get_file_info(void);
static int test_get_file_vfd_handle(void);
static int test_double_group_open(void);
#endif /* for native VOL connector test only */
/*
* The array of file tests to be performed.
*/
static int (*file_tests[])(void) = {
test_create_file,
test_create_file_invalid_params,
test_create_file_excl,
test_open_file,
test_open_file_invalid_params,
test_open_nonexistent_file,
test_file_open_overlap,
test_file_permission,
test_reopen_file,
test_close_file_invalid_id,
test_flush_file,
test_file_is_accessible,
test_file_property_lists,
test_get_file_intent,
test_get_file_obj_count,
test_file_mounts,
test_get_file_name,
#if 0 /* for native VOL connector test only */
test_filespace_info,
test_get_file_id,
test_file_close_degree,
test_get_file_free_sections,
test_get_file_size,
test_get_file_image,
test_get_file_info,
test_get_file_vfd_handle,
test_double_group_open
#endif /* for native VOL connector test only */
};
/*
* Tests that a file can be created with the VOL connector.
*/
static int
test_create_file(void)
{
hid_t file_id = H5I_INVALID_HID;
TESTING("H5Fcreate");
if ((file_id = H5Fcreate(FILE_CREATE_TEST_FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
H5_FAILED();
HDprintf(" couldn't create file '%s'\n", FILE_CREATE_TEST_FILENAME);
goto error;
}
if (H5Fclose(file_id) < 0)
TEST_ERROR
PASSED();
return 0;
error:
H5E_BEGIN_TRY {
H5Fclose(file_id);
} H5E_END_TRY;
return 1;
}
/*
* Tests that a file can't be created when H5Fcreate is passed
* invalid parameters.
*/
static int
test_create_file_invalid_params(void)
{
hid_t file_id = H5I_INVALID_HID;
TESTING_MULTIPART("H5Fcreate with invalid parameters");
BEGIN_MULTIPART {
PART_BEGIN(H5Fcreate_invalid_name) {
TESTING_2("H5Fcreate with invalid file name");
H5E_BEGIN_TRY {
file_id = H5Fcreate(NULL, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
} H5E_END_TRY;
if (file_id >= 0) {
H5_FAILED();
HDprintf(" file was created with a NULL name!\n");
H5Fclose(file_id);
PART_ERROR(H5Fcreate_invalid_name);
}
H5E_BEGIN_TRY {
file_id = H5Fcreate("", H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
} H5E_END_TRY;
if (file_id >= 0) {
H5_FAILED();
HDprintf(" file was created with an invalid name of ''!\n");
H5Fclose(file_id);
PART_ERROR(H5Fcreate_invalid_name);
}
PASSED();
} PART_END(H5Fcreate_invalid_name);
PART_BEGIN(H5Fcreate_invalid_flags) {
TESTING_2("H5Fcreate with invalid flags");
H5E_BEGIN_TRY {
file_id = H5Fcreate(FILE_CREATE_INVALID_PARAMS_FILE_NAME, H5F_ACC_RDWR, H5P_DEFAULT, H5P_DEFAULT);
} H5E_END_TRY;
if (file_id >= 0) {
H5_FAILED();
HDprintf(" file was created with invalid flag H5F_ACC_RDWR!\n");
H5Fclose(file_id);
PART_ERROR(H5Fcreate_invalid_flags);
}
H5E_BEGIN_TRY {
file_id = H5Fcreate(FILE_CREATE_INVALID_PARAMS_FILE_NAME, H5F_ACC_CREAT, H5P_DEFAULT, H5P_DEFAULT);
} H5E_END_TRY;
if (file_id >= 0) {
H5_FAILED();
HDprintf(" file was created with invalid flag H5F_ACC_CREAT!\n");
H5Fclose(file_id);
PART_ERROR(H5Fcreate_invalid_flags);
}
H5E_BEGIN_TRY {
file_id = H5Fcreate(FILE_CREATE_INVALID_PARAMS_FILE_NAME, H5F_ACC_SWMR_READ, H5P_DEFAULT, H5P_DEFAULT);
} H5E_END_TRY;
if (file_id >= 0) {
H5_FAILED();
HDprintf(" file was created with invalid flag H5F_ACC_SWMR_READ!\n");
H5Fclose(file_id);
PART_ERROR(H5Fcreate_invalid_flags);
}
PASSED();
} PART_END(H5Fcreate_invalid_flags);
PART_BEGIN(H5Fcreate_invalid_fcpl) {
TESTING_2("H5Fcreate with invalid FCPL");
H5E_BEGIN_TRY {
file_id = H5Fcreate(FILE_CREATE_INVALID_PARAMS_FILE_NAME, H5F_ACC_TRUNC, H5I_INVALID_HID, H5P_DEFAULT);
} H5E_END_TRY;
if (file_id >= 0) {
H5_FAILED();
HDprintf(" file was created with invalid FCPL!\n");
H5Fclose(file_id);
PART_ERROR(H5Fcreate_invalid_fcpl);
}
PASSED();
} PART_END(H5Fcreate_invalid_fcpl);
} END_MULTIPART;
return 0;
error:
H5E_BEGIN_TRY {
/* Attempt to remove the file if it ended up being created. */
H5Fdelete(FILE_CREATE_INVALID_PARAMS_FILE_NAME, H5P_DEFAULT);
H5Fclose(file_id);
} H5E_END_TRY;
return 1;
}
/*
* Tests that file creation will fail when a file is created
* using the H5F_ACC_EXCL flag while the file already exists.
*/
static int
test_create_file_excl(void)
{
hid_t file_id = H5I_INVALID_HID, file_id2 = H5I_INVALID_HID;
TESTING("H5Fcreate with H5F_ACC_EXCL/H5F_ACC_TRUNC flag");
if ((file_id = H5Fcreate(FILE_CREATE_EXCL_FILE_NAME, H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
H5_FAILED();
HDprintf(" couldn't create first file\n");
goto error;
}
/* Close the file */
if (H5Fclose(file_id) < 0)
TEST_ERROR
/* Try again with H5F_ACC_EXCL. This should fail because the file already
* exists on disk from the previous steps.
*/
H5E_BEGIN_TRY {
file_id = H5Fcreate(FILE_CREATE_EXCL_FILE_NAME, H5F_ACC_EXCL, H5P_DEFAULT, H5P_DEFAULT);
} H5E_END_TRY;
if (file_id >= 0) {
H5_FAILED();
HDprintf(" created already existing file using H5F_ACC_EXCL flag!\n");
goto error;
}
/* Test creating with H5F_ACC_TRUNC. This will truncate the existing file on disk. */
if((file_id = H5Fcreate(FILE_CREATE_EXCL_FILE_NAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
H5_FAILED();
HDprintf(" couldn't truncate the existing file\n");
goto error;
}
if (H5Fclose(file_id) < 0)
TEST_ERROR
PASSED();
return 0;
error:
H5E_BEGIN_TRY {
H5Fclose(file_id);
H5Fclose(file_id2);
} H5E_END_TRY;
return 1;
}
/*
* Tests that a file can be opened with the VOL connector.
*/
static int
test_open_file(void)
{
hid_t file_id = H5I_INVALID_HID;
TESTING_MULTIPART("H5Fopen");
BEGIN_MULTIPART {
PART_BEGIN(H5Fopen_rdonly) {
TESTING_2("H5Fopen in read-only mode")
if ((file_id = H5Fopen(vol_test_filename, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) {
H5_FAILED();
HDprintf(" unable to open file '%s' in read-only mode\n", vol_test_filename);
PART_ERROR(H5Fopen_rdonly);
}
PASSED();
} PART_END(H5Fopen_rdonly);
if (file_id >= 0) {
H5E_BEGIN_TRY {
H5Fclose(file_id);
} H5E_END_TRY;
file_id = H5I_INVALID_HID;
}
PART_BEGIN(H5Fopen_rdwrite) {
TESTING_2("H5Fopen in read-write mode")
if ((file_id = H5Fopen(vol_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) {
H5_FAILED();
HDprintf(" unable to open file '%s' in read-write mode\n", vol_test_filename);
PART_ERROR(H5Fopen_rdwrite);
}
PASSED();
} PART_END(H5Fopen_rdwrite);
if (file_id >= 0) {
H5E_BEGIN_TRY {
H5Fclose(file_id);
} H5E_END_TRY;
file_id = H5I_INVALID_HID;
}
/*
* XXX: SWMR open flags
*/
} END_MULTIPART;
return 0;
error:
H5E_BEGIN_TRY {
H5Fclose(file_id);
} H5E_END_TRY;
return 1;
}
/*
* Tests that a file can't be opened when H5Fopen is given
* invalid parameters.
*/
static int
test_open_file_invalid_params(void)
{
hid_t file_id = H5I_INVALID_HID;
TESTING_MULTIPART("H5Fopen with invalid parameters");
BEGIN_MULTIPART {
PART_BEGIN(H5Fopen_invalid_name) {
TESTING_2("H5Fopen with invalid file name");
H5E_BEGIN_TRY {
file_id = H5Fopen(NULL, H5F_ACC_RDWR, H5P_DEFAULT);
} H5E_END_TRY;
if (file_id >= 0) {
H5_FAILED();
HDprintf(" file was opened with a NULL name!\n");
H5Fclose(file_id);
PART_ERROR(H5Fopen_invalid_name);
}
H5E_BEGIN_TRY {
file_id = H5Fopen("", H5F_ACC_RDWR, H5P_DEFAULT);
} H5E_END_TRY;
if (file_id >= 0) {
H5_FAILED();
HDprintf(" file was opened with an invalid name of ''!\n");
H5Fclose(file_id);
PART_ERROR(H5Fopen_invalid_name);
}
PASSED();
} PART_END(H5Fopen_invalid_name);
PART_BEGIN(H5Fopen_invalid_flags) {
TESTING_2("H5Fopen with invalid flags");
H5E_BEGIN_TRY {
file_id = H5Fopen(vol_test_filename, H5F_ACC_TRUNC, H5P_DEFAULT);
} H5E_END_TRY;
if (file_id >= 0) {
H5_FAILED();
HDprintf(" file was opened with invalid flag H5F_ACC_TRUNC!\n");
H5Fclose(file_id);
PART_ERROR(H5Fopen_invalid_flags);
}
H5E_BEGIN_TRY {
file_id = H5Fopen(vol_test_filename, H5F_ACC_EXCL, H5P_DEFAULT);
} H5E_END_TRY;
if (file_id >= 0) {
H5_FAILED();
HDprintf(" file was opened with invalid flag H5F_ACC_EXCL!\n");
H5Fclose(file_id);
PART_ERROR(H5Fopen_invalid_flags);
}
PASSED();
} PART_END(H5Fopen_invalid_flags);
} END_MULTIPART;
return 0;
error:
H5E_BEGIN_TRY {
H5Fclose(file_id);
} H5E_END_TRY;
return 1;
}
/*
* A test to ensure that opening a file which doesn't exist will fail.
*/
static int
test_open_nonexistent_file(void)
{
hid_t file_id = H5I_INVALID_HID;
char test_filename[VOL_TEST_FILENAME_MAX_LENGTH];
TESTING("for invalid opening of a non-existent file")
HDsnprintf(test_filename, VOL_TEST_FILENAME_MAX_LENGTH, "%s", NONEXISTENT_FILENAME);
/* XXX: Make sure to first delete the file so we know for sure it doesn't exist */
H5E_BEGIN_TRY {
file_id = H5Fopen(test_filename, H5F_ACC_RDWR, H5P_DEFAULT);
} H5E_END_TRY;
if (file_id >= 0) {
H5_FAILED();
HDprintf(" non-existent file was opened!\n");
goto error;
}
PASSED();
return 0;
error:
H5E_BEGIN_TRY {
H5Fclose(file_id);
} H5E_END_TRY;
return 1;
}
/*
* Tests that a file can be opened read-only or read-write
* and things are handled appropriately.
*/
static int
test_file_permission(void)
{
hid_t file_id = H5I_INVALID_HID;
hid_t dset_id = H5I_INVALID_HID, dspace_id = H5I_INVALID_HID;
hid_t group_id = H5I_INVALID_HID, attr_id = H5I_INVALID_HID;
hid_t dtype_id = H5I_INVALID_HID;
herr_t ret = -1;
TESTING_MULTIPART("file permissions (invalid creation of objects in read-only file)");
TESTING_2("test setup")
if ((file_id = H5Fcreate(FILE_PERMISSION_TEST_FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
H5_FAILED();
HDprintf(" couldn't create file '%s'\n", FILE_PERMISSION_TEST_FILENAME);
goto error;
}
if ((dspace_id = H5Screate(H5S_SCALAR)) < 0) {
H5_FAILED();
HDprintf(" couldn't create data space\n");
goto error;
}
if ((dset_id = H5Dcreate2(file_id, FILE_PERMISSION_TEST_DSET_NAME, H5T_STD_U32LE, dspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
H5_FAILED();
HDprintf(" couldn't create data set: %s\n", FILE_PERMISSION_TEST_DSET_NAME);
goto error;
}
if (H5Dclose(dset_id) < 0)
TEST_ERROR
if (H5Fclose(file_id) < 0)
TEST_ERROR
/* Open the file (with read-only permission) */
if ((file_id = H5Fopen(FILE_PERMISSION_TEST_FILENAME, H5F_ACC_RDONLY, H5P_DEFAULT)) < 0) {
H5_FAILED();
HDprintf(" couldn't open file\n");
goto error;
}
PASSED();
BEGIN_MULTIPART {
PART_BEGIN(H5Gcreate_rdonly_file) {
TESTING_2("invalid creation of group in read-only file")
/* Create a group with the read-only file handle (should fail) */
H5E_BEGIN_TRY {
group_id = H5Gcreate2(file_id, FILE_PERMISSION_TEST_GRP_NAME, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
} H5E_END_TRY;
if (group_id >= 0) {
H5_FAILED();
HDprintf(" a group was created in a read-only file!\n");
PART_ERROR(H5Gcreate_rdonly_file);
}
H5E_BEGIN_TRY {
group_id = H5Gcreate_anon(file_id, H5P_DEFAULT, H5P_DEFAULT);
} H5E_END_TRY;
if (group_id >= 0) {
H5_FAILED();
HDprintf(" a group was created in a read-only file!\n");
PART_ERROR(H5Gcreate_rdonly_file);
}
PASSED();
} PART_END(H5Gcreate_rdonly_file);
PART_BEGIN(H5Dcreate_rdonly_file) {
TESTING_2("invalid creation of dataset in read-only file")
/* Create a dataset with the read-only file handle (should fail) */
H5E_BEGIN_TRY {
dset_id = H5Dcreate2(file_id, FILE_PERMISSION_TEST_DSET2_NAME, H5T_STD_U32LE, dspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
} H5E_END_TRY;
if (dset_id >= 0) {
H5_FAILED();
HDprintf(" a dataset was created in a read-only file!\n");
PART_ERROR(H5Dcreate_rdonly_file);
}
H5E_BEGIN_TRY {
dset_id = H5Dcreate_anon(file_id, H5T_STD_U32LE, dspace_id, H5P_DEFAULT, H5P_DEFAULT);
} H5E_END_TRY;
if (dset_id >= 0) {
H5_FAILED();
HDprintf(" a dataset was created in a read-only file!\n");
PART_ERROR(H5Dcreate_rdonly_file);
}
PASSED();
} PART_END(H5Dcreate_rdonly_file);
PART_BEGIN(H5Acreate_rdonly_file) {
TESTING_2("invalid creation of attribute in read-only file")
/* Create an attribute with the read-only file handle (should fail) */
H5E_BEGIN_TRY {
attr_id = H5Acreate2(file_id, FILE_PERMISSION_TEST_ATTR_NAME, H5T_NATIVE_INT, dspace_id, H5P_DEFAULT, H5P_DEFAULT);
} H5E_END_TRY;
if (attr_id >= 0) {
H5_FAILED();
HDprintf(" an attribute was created in a read-only file!\n");
PART_ERROR(H5Acreate_rdonly_file);
}
PASSED();
} PART_END(H5Acreate_rdonly_file);
PART_BEGIN(H5Tcommit_rdonly_file) {
TESTING_2("invalid creation of committed datatype in read-only file")
if ((dtype_id = H5Tcopy(H5T_NATIVE_INT)) < 0) {
H5_FAILED();
HDprintf(" couldn't copy a native datatype\n");
PART_ERROR(H5Tcommit_rdonly_file);
}
/* Commit a datatype with the read-only file handle (should fail) */
H5E_BEGIN_TRY {
ret = H5Tcommit2(file_id, FILE_PERMISSION_TEST_NAMED_DTYPE, dtype_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
} H5E_END_TRY;
if (ret >= 0) {
H5_FAILED();
HDprintf(" a named datatype was committed in a read-only file!\n");
PART_ERROR(H5Tcommit_rdonly_file);
}
H5E_BEGIN_TRY {
ret = H5Tcommit_anon(file_id, dtype_id, H5P_DEFAULT, H5P_DEFAULT);
} H5E_END_TRY;
if (ret >= 0) {
H5_FAILED();
HDprintf(" a named datatype was committed in a read-only file!\n");
PART_ERROR(H5Tcommit_rdonly_file);
}
PASSED();
} PART_END(H5Tcommit_rdonly_file);
} END_MULTIPART;
TESTING_2("test cleanup")
if (H5Tclose(dtype_id) < 0)
TEST_ERROR
if (H5Sclose(dspace_id) < 0)
TEST_ERROR
if (H5Fclose(file_id) < 0)
TEST_ERROR
PASSED();
return 0;
error:
H5E_BEGIN_TRY {
H5Sclose(dspace_id);
H5Dclose(dset_id);
H5Aclose(attr_id);
H5Tclose(dtype_id);
H5Gclose(group_id);
H5Fclose(file_id);
} H5E_END_TRY;
return 1;
}
/*
* A test to check that a file can be re-opened with H5Freopen.
*/
static int
test_reopen_file(void)
{
hid_t file_id = H5I_INVALID_HID, file_id2 = H5I_INVALID_HID;
TESTING("re-open of a file with H5Freopen")
if ((file_id = H5Fopen(vol_test_filename, H5F_ACC_RDWR, H5P_DEFAULT)) < 0) {
H5_FAILED();
HDprintf(" couldn't open file\n");
goto error;
}
if ((file_id2 = H5Freopen(file_id)) < 0) {
H5_FAILED();
HDprintf(" couldn't re-open file\n");
goto error;
}
if (H5Fclose(file_id) < 0)
TEST_ERROR
if (H5Fclose(file_id2) < 0)
TEST_ERROR
PASSED();
return 0;
error:
H5E_BEGIN_TRY {
H5Fclose(file_id);
H5Fclose(file_id2);
} H5E_END_TRY;
return 1;
}
/*
* A test to check that H5Fclose doesn't succeed for an
* invalid file ID */
static int
test_close_file_invalid_id(void)
{
herr_t err_ret = -1;
TESTING("H5Fclose with an invalid ID")
H5E_BEGIN_TRY {
err_ret = H5Fclose(H5I_INVALID_HID);
} H5E_END_TRY;
if (err_ret >= 0) {
H5_FAILED();
HDprintf(" closed an invalid file ID!\n");
goto error;
}
PASSED();
return 0;
error:
return 1;
}
/*
* A test to check that a file can be flushed using H5Fflush.
*/
static int
test_flush_file(void)
{
hid_t file_id = H5I_INVALID_HID;
hid_t dspace_id = H5I_INVALID_HID, dset_id = H5I_INVALID_HID;
char dset_name[32];
unsigned u;
TESTING_MULTIPART("H5Fflush")
TESTING_2("test setup")
if ((file_id = H5Fcreate(FILE_FLUSH_TEST_FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
H5_FAILED();
HDprintf(" couldn't create file '%s'\n", FILE_FLUSH_TEST_FILENAME);
goto error;
}
/* Create multiple small datasets in file */
if ((dspace_id = H5Screate(H5S_SCALAR)) < 0) {
H5_FAILED();
HDprintf(" couldn't create data space\n");
goto error;
}
for(u = 0; u < 10; u++) {
HDsprintf(dset_name, "Dataset %u", u);
if ((dset_id = H5Dcreate2(file_id, dset_name, H5T_STD_U32LE, dspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
H5_FAILED();
HDprintf(" couldn't create data set: %s\n", dset_name);
goto error;
}
if (H5Dclose(dset_id) < 0)
TEST_ERROR
}
PASSED();
BEGIN_MULTIPART {
PART_BEGIN(H5Fflush_local) {
TESTING_2("file flushing at local scope")
if (H5Fflush(file_id, H5F_SCOPE_LOCAL) < 0) {
H5_FAILED();
HDprintf(" unable to flush file with scope H5F_SCOPE_LOCAL\n");
PART_ERROR(H5Fflush_local);
}
PASSED();
} PART_END(H5Fflush_local);
PART_BEGIN(H5Fflush_global) {
TESTING_2("file flushing at global scope")
if (H5Fflush(file_id, H5F_SCOPE_GLOBAL) < 0) {
H5_FAILED();
HDprintf(" unable to flush file with scope H5F_SCOPE_GLOBAL\n");
PART_ERROR(H5Fflush_global);
}
PASSED();
} PART_END(H5Fflush_global);
} END_MULTIPART;
TESTING_2("test cleanup")
if (H5Sclose(dspace_id) < 0)
TEST_ERROR
if (H5Fclose(file_id) < 0)
TEST_ERROR
PASSED();
return 0;
error:
H5E_BEGIN_TRY {
H5Sclose(dspace_id);
H5Dclose(dset_id);
H5Fclose(file_id);
} H5E_END_TRY;
return 1;
}
/*
* A test for H5Fis_accessible.
*/
static int
test_file_is_accessible(void)
{
const char * const fake_filename = "nonexistent_file.h5";
htri_t is_accessible = -1;
TESTING_MULTIPART("H5Fis_accessible")
BEGIN_MULTIPART {
PART_BEGIN(H5Fis_accessible_valid_file) {
TESTING_2("H5Fis_accessible on existing file")
if ((is_accessible = H5Fis_accessible(vol_test_filename, H5P_DEFAULT)) < 0) {
H5_FAILED();
HDprintf(" couldn't determine if file '%s' is accessible with VOL connector\n", vol_test_filename);
PART_ERROR(H5Fis_accessible_valid_file);
}
if (!is_accessible) {
H5_FAILED();
HDprintf(" file '%s' is not accessible with VOL connector\n", vol_test_filename);
PART_ERROR(H5Fis_accessible_valid_file);
}
PASSED();
} PART_END(H5Fis_accessible_valid_file);
is_accessible = -1;
PART_BEGIN(H5Fis_accessible_invalid_file) {
TESTING_2("H5Fis_accessible on non-existing file")
H5E_BEGIN_TRY {
is_accessible = H5Fis_accessible(fake_filename, H5P_DEFAULT);
} H5E_END_TRY;
if (is_accessible > 0) {
H5_FAILED();
HDprintf(" non-existent file '%s' was accessible with VOL connector: is_accessible=%d!\n", fake_filename, is_accessible);
PART_ERROR(H5Fis_accessible_invalid_file);
}
PASSED();
} PART_END(H5Fis_accessible_invalid_file);
} END_MULTIPART;
return 0;
error:
return 1;
}
/*
* A test to check that a VOL connector stores and can return a valid copy
* of a FAPL and FCPL used upon file access and creation time, respectively.
*/
static int
test_file_property_lists(void)
{
hsize_t prop_val = 0;
hid_t file_id1 = H5I_INVALID_HID, file_id2 = H5I_INVALID_HID;
hid_t fcpl_id1 = H5I_INVALID_HID, fcpl_id2 = H5I_INVALID_HID;
hid_t fapl_id1 = H5I_INVALID_HID, fapl_id2 = H5I_INVALID_HID;
char test_filename1[VOL_TEST_FILENAME_MAX_LENGTH], test_filename2[VOL_TEST_FILENAME_MAX_LENGTH];
TESTING_MULTIPART("file property list operations")
TESTING_2("test setup")
HDsnprintf(test_filename1, VOL_TEST_FILENAME_MAX_LENGTH, "%s", FILE_PROPERTY_LIST_TEST_FNAME1);
HDsnprintf(test_filename2, VOL_TEST_FILENAME_MAX_LENGTH, "%s", FILE_PROPERTY_LIST_TEST_FNAME2);
if ((fcpl_id1 = H5Pcreate(H5P_FILE_CREATE)) < 0) {
H5_FAILED();
HDprintf(" couldn't create FCPL\n");
goto error;
}
if (H5Pset_userblock(fcpl_id1, FILE_PROPERTY_LIST_TEST_FCPL_PROP_VAL) < 0) {
H5_FAILED();
HDprintf(" failed to set test property on FCPL\n");
goto error;
}
if ((file_id1 = H5Fcreate(test_filename1, H5F_ACC_TRUNC, fcpl_id1, H5P_DEFAULT)) < 0) {
H5_FAILED();
HDprintf(" couldn't create file\n");
goto error;
}
if ((file_id2 = H5Fcreate(test_filename2, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0) {
H5_FAILED();
HDprintf(" couldn't create file\n");
goto error;
}
if (H5Pclose(fcpl_id1) < 0)
TEST_ERROR
PASSED();
BEGIN_MULTIPART {
PART_BEGIN(H5Fget_create_plist) {
TESTING_2("H5Fget_create_plist")
/* Try to receive copies of the two property lists, one which has the property set and one which does not */
if ((fcpl_id1 = H5Fget_create_plist(file_id1)) < 0) {
H5_FAILED();
HDprintf(" couldn't get FCPL\n");
PART_ERROR(H5Fget_create_plist);
}
if ((fcpl_id2 = H5Fget_create_plist(file_id2)) < 0) {
H5_FAILED();
HDprintf(" couldn't get FCPL\n");
PART_ERROR(H5Fget_create_plist);
}
/* Ensure that property list 1 has the property set and property list 2 does not */
if (H5Pget_userblock(fcpl_id1, &prop_val) < 0) {
H5_FAILED();
HDprintf(" failed to retrieve test property from FCPL\n");
PART_ERROR(H5Fget_create_plist);
}
if (prop_val != FILE_PROPERTY_LIST_TEST_FCPL_PROP_VAL) {
H5_FAILED();
HDprintf(" retrieved test property value '%llu' did not match expected value '%llu'\n",
(long long unsigned) prop_val, (long long unsigned) FILE_PROPERTY_LIST_TEST_FCPL_PROP_VAL);
PART_ERROR(H5Fget_create_plist);
}
if (H5Pget_userblock(fcpl_id2, &prop_val) < 0) {
H5_FAILED();
HDprintf(" failed to retrieve test property from FCPL\n");
PART_ERROR(H5Fget_create_plist);
}
if (prop_val == FILE_PROPERTY_LIST_TEST_FCPL_PROP_VAL) {
HDprintf(" retrieved test property value '%llu' matched control value '%llu' when it shouldn't have\n",
(long long unsigned) prop_val, (long long unsigned) FILE_PROPERTY_LIST_TEST_FCPL_PROP_VAL);
PART_ERROR(H5Fget_create_plist);
}
PASSED();
} PART_END(H5Fget_create_plist);
PART_BEGIN(H5Fget_access_plist) {
TESTING_2("H5Fget_access_plist")
/* Due to the nature of needing to supply a FAPL with the VOL connector having been set on it to the H5Fcreate()
* call, we cannot exactly test using H5P_DEFAULT as the FAPL for one of the create calls in this test. However,
* the use of H5Fget_access_plist() will still be used to check that the FAPL is correct after both creating and
* opening a file.
*/
if ((fapl_id1 = H5Fget_access_plist(file_id1)) < 0) {
H5_FAILED();
HDprintf(" couldn't get FAPL\n");
PART_ERROR(H5Fget_access_plist);
}
if ((fapl_id2 = H5Fget_access_plist(file_id2)) < 0) {
H5_FAILED();
HDprintf(" couldn't get FAPL\n");
PART_ERROR(H5Fget_access_plist);
}
PASSED();
} PART_END(H5Fget_access_plist);
/* Now see if we can still retrieve copies of the property lists upon opening
* (instead of creating) a file. If they were reconstructed properly upon file
* open, the creation property lists should also have the same test values
* as set before.
*/
if (fcpl_id1 >= 0) {
H5E_BEGIN_TRY {
H5Pclose(fcpl_id1);
} H5E_END_TRY;
fcpl_id1 = H5I_INVALID_HID;
}
if (fcpl_id2 >= 0) {
H5E_BEGIN_TRY {
H5Pclose(fcpl_id2);
} H5E_END_TRY;
fcpl_id2 = H5I_INVALID_HID;
}
if (fapl_id1 >= 0) {
H5E_BEGIN_TRY {
H5Pclose(fapl_id1);
} H5E_END_TRY;
fapl_id1 = H5I_INVALID_HID;
}
if (fapl_id2 >= 0) {
H5E_BEGIN_TRY {
H5Pclose(fapl_id2);
} H5E_END_TRY;
fapl_id2 = H5I_INVALID_HID;
}
if (file_id1 >= 0) {
H5E_BEGIN_TRY {
H5Fclose(file_id1);
} H5E_END_TRY;