forked from openmeeg/hdf5-matio
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtsohm.c
4022 lines (3370 loc) · 144 KB
/
tsohm.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. *
* Copyright by the Board of Trustees of the University of Illinois. *
* 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 files COPYING and Copyright.html. COPYING can be found at the root *
* of the source code distribution tree; Copyright.html can be found at the *
* root level of an installed copy of the electronic HDF5 document set and *
* is linked from the top-level documents page. It can also be found at *
* http://hdfgroup.org/HDF5/doc/Copyright.html. If you do not have *
* access to either file, you may request a copy from [email protected]. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/***********************************************************
*
* Test program: tsohm
*
* Test Shared Object Header Messages
*
*************************************************************/
#include "testhdf5.h"
/*
* This file needs to access private information from the H5F package.
* This file also needs to access the file testing code.
*/
#define H5F_PACKAGE
#define H5F_TESTING
#include "H5Fpkg.h" /* File access */
/* Default SOHM values */
#define DEF_NUM_INDEXES 0
const unsigned def_type_flags[H5O_SHMESG_MAX_NINDEXES] = {0,0,0,0,0,0};
const unsigned def_minsizes[H5O_SHMESG_MAX_NINDEXES] = {250,250,250,250,250,250};
#define DEF_L2B 50
#define DEF_B2L 40
/* Non-default SOHM values for testing */
#define TEST_NUM_INDEXES 4
const unsigned test_type_flags[H5O_SHMESG_MAX_NINDEXES] =
{H5O_SHMESG_FILL_FLAG,
H5O_SHMESG_DTYPE_FLAG | H5O_SHMESG_ATTR_FLAG,
H5O_SHMESG_SDSPACE_FLAG,
H5O_SHMESG_PLINE_FLAG,
0, 0};
const unsigned test_minsizes[H5O_SHMESG_MAX_NINDEXES] = {0, 2, 40, 100, 3, 1000};
#define TEST_L2B 65
#define TEST_B2L 64
#define FILENAME "tsohm.h5"
#define FILENAME_SRC "tsohm_src.h5"
#define FILENAME_DST "tsohm_dst.h5"
#define NAME_BUF_SIZE 512
/* How much overhead counts as "not much" when converting B-trees, etc. */
#define OVERHEAD_ALLOWED 1.15
#define NUM_DATASETS 10
#define NUM_ATTRIBUTES 100
typedef struct dtype1_struct {
int i1;
char str[10];
int i2;
int i3;
int i4;
int i5;
int i6;
int i7;
int i8;
float f1;
} dtype1_struct;
#define DTYPE2_SIZE 1024
const char *DSETNAME[] = {
"dataset0", "dataset1",
"dataset2", "dataset3",
"dataset4", "dataset5",
"dataset6", "dataset7",
"dataset8", "dataset9",
"dataset10", "dataset11",
NULL
};
const char *EXTRA_DSETNAME[] = {
"ex_dataset0", "ex_dataset1",
"ex_dataset2", "ex_dataset3",
"ex_dataset4", "ex_dataset5",
"ex_dataset6", "ex_dataset7",
"ex_dataset8", "ex_dataset9",
"ex_dataset10", "ex_dataset11",
"ex_dataset12", "ex_dataset13",
"ex_dataset14", "ex_dataset15",
"ex_dataset16", "ex_dataset17",
"ex_dataset18", "ex_dataset19",
NULL
};
#define SOHM_HELPER_NUM_EX_DSETS 20
typedef struct complex_t {
double re;
double im;
} complex_t;
#define ENUM_NUM_MEMBS 20
const char *ENUM_NAME[] = {
"enum_member0", "enum_member1",
"enum_member2", "enum_member3",
"enum_member4", "enum_member5",
"enum_member6", "enum_member7",
"enum_member8", "enum_member9",
"enum_member10", "enum_member11",
"enum_member12", "enum_member13",
"enum_member14", "enum_member15",
"enum_member16", "enum_member17",
"enum_member18", "enum_member19",
NULL
};
const int ENUM_VAL[] = {
0, 13,
-500, 63,
64, -64,
65, 2048,
1, 2,
-1, 7,
130, -5000,
630, 640,
-640, 650,
20480, 10,
-1001, -10
};
#define SIZE2_RANK1 6
#define SIZE2_RANK2 10
#define SIZE2_DIMS {1, 2, 3, 4, 5, 6, 7, 8, 9, 10}
#define LONG_STRING "00 index. A long string used for testing. To create new strings, set the first two characters to be some ASCII number other than 00, such as 01."
/* Struct returned from size2_helper function */
typedef struct size2_helper_struct {
h5_stat_size_t empty_size;
h5_stat_size_t first_dset;
h5_stat_size_t second_dset;
h5_stat_size_t dsets1;
h5_stat_size_t dsets2;
h5_stat_size_t interleaved;
h5_stat_size_t attrs1;
h5_stat_size_t attrs2;
} size2_helper_struct;
/* Number of distinct messages for the sohm_delete test */
#define DELETE_NUM_MESGS 7
#define HALF_DELETE_NUM_MESGS 3
#define DELETE_DIMS {1,1,1,1,1,1,1}
#define DELETE_MIN_MESG_SIZE 10
#define DELETE_MAX_MESG_SIZE 60
/* Number of dimensions in extend_dset test */
#define EXTEND_NDIMS 2
/* Dimensions for external_dtype test */
#define NX 10
#define NY 10
/* Helper function prototypes */
static hid_t make_dtype_1(void);
static hid_t make_dtype_2(void);
static hid_t close_reopen_file(hid_t file, const char* filename, hid_t fapl_id);
static void test_sohm_attrs(void);
#ifdef NOT_NOW
static void size2_dump_struct(const char *name, size2_helper_struct *sizes);
#endif /* NOT_NOW */
static void size2_verify(void);
static void test_sohm_delete(void);
static void test_sohm_delete_revert(void);
static void test_sohm_extlink(void);
/****************************************************************
**
** check_fcpl_values(): Helper function for test_sohm_fcpl.
** Verifies that the *_in and *_out parameters are equal.
**
****************************************************************/
static void check_fcpl_values(hid_t fcpl_id, const unsigned nindexes_in,
const unsigned *flags_in, const unsigned *minsizes_in,
unsigned l2b, unsigned b2l)
{
unsigned num_indexes;
unsigned index_flags, min_mesg_size;
unsigned list_size, btree_size;
unsigned x;
herr_t ret;
/* Verify number of indexes is set to default */
ret = H5Pget_shared_mesg_nindexes(fcpl_id, &num_indexes);
CHECK_I(ret, "H5Pget_shared_mesg_nindexes");
VERIFY(num_indexes, nindexes_in, "H5Pget_shared_mesg_nindexes");
/* Verify index flags and minsizes are set */
for(x=0; x<num_indexes; ++x)
{
ret = H5Pget_shared_mesg_index(fcpl_id, x, &index_flags, &min_mesg_size);
CHECK_I(ret, "H5Pget_shared_mesg_index");
VERIFY(index_flags, flags_in[x], "H5Pget_shared_mesg_index");
VERIFY(min_mesg_size, minsizes_in[x], "H5Pget_shared_mesg_index");
}
/* Check list-to-btree and btree-to-list values */
ret = H5Pget_shared_mesg_phase_change(fcpl_id, &list_size, &btree_size);
CHECK_I(ret, "H5Pset_shared_mesg_phase_change");
VERIFY(list_size, l2b, "H5Pset_shared_mesg_phase_change");
VERIFY(btree_size, b2l, "H5Pset_shared_mesg_phase_change");
}
/****************************************************************
**
** test_sohm_fcpl(): Test File Creation Property Lists.
**
****************************************************************/
static void test_sohm_fcpl(void)
{
hid_t fid = -1;
hid_t fcpl_id = -1;
hid_t fcpl2_id = -1;
unsigned x;
herr_t ret; /* Generic return value */
/* Output message about test being performed */
MESSAGE(5, ("Testing File Creation Properties for Shared Messages\n"));
fcpl_id = H5Pcreate(H5P_FILE_CREATE);
CHECK_I(fcpl_id, "H5Pcreate");
/* Verify fcpl values */
check_fcpl_values(fcpl_id, DEF_NUM_INDEXES, def_type_flags, def_minsizes, DEF_L2B, DEF_B2L);
/* Create a file with this fcpl and make sure that all the values can be
* retrieved.
*/
fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl_id, H5P_DEFAULT);
CHECK_I(fid, "H5Fcreate");
fcpl2_id = H5Fget_create_plist(fid);
CHECK_I(fcpl2_id, "H5Fcreate");
/* Verify fcpl values */
check_fcpl_values(fcpl2_id, DEF_NUM_INDEXES, def_type_flags, def_minsizes, DEF_L2B, DEF_B2L);
ret = H5Pclose(fcpl2_id);
CHECK_I(ret, "H5Pclose");
/* Close and re-open the file. Make sure that fcpl values are still
* correct.
*/
ret = H5Fclose(fid);
CHECK_I(ret, "H5Fclose");
fid = H5Fopen(FILENAME, H5F_ACC_RDWR, H5P_DEFAULT);
CHECK_I(fid, "H5Fopen");
fcpl2_id = H5Fget_create_plist(fid);
CHECK_I(ret, "H5Fcreate");
/* Verify fcpl values */
check_fcpl_values(fcpl2_id, DEF_NUM_INDEXES, def_type_flags, def_minsizes, DEF_L2B, DEF_B2L);
/* Clean up */
ret = H5Pclose(fcpl2_id);
CHECK_I(ret, "H5Pclose");
ret = H5Pclose(fcpl_id);
CHECK_I(ret, "H5Pclose");
ret = H5Fclose(fid);
CHECK_I(ret, "H5Fclose");
/* Start over with a non-default fcpl */
fcpl_id = H5Pcreate(H5P_FILE_CREATE);
CHECK_I(fcpl_id, "H5Pcreate");
/* Set up index values */
ret = H5Pset_shared_mesg_nindexes(fcpl_id, TEST_NUM_INDEXES);
CHECK_I(ret, "H5Pset_shared_mesg_nindexes");
for(x = 0; x < TEST_NUM_INDEXES; ++x) {
ret = H5Pset_shared_mesg_index(fcpl_id, x, test_type_flags[x], test_minsizes[x]);
CHECK_I(ret, "H5Pset_shared_mesg_index");
} /* end for */
ret = H5Pset_shared_mesg_phase_change(fcpl_id, TEST_L2B, TEST_B2L);
CHECK_I(ret, "H5Pset_shared_mesg_phase_change");
check_fcpl_values(fcpl_id, TEST_NUM_INDEXES, test_type_flags, test_minsizes, TEST_L2B, TEST_B2L);
/* Use the fcpl to create a file and get it back again */
fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl_id, H5P_DEFAULT);
CHECK_I(fid, "H5Fcreate");
fcpl2_id = H5Fget_create_plist(fid);
CHECK_I(fcpl2_id, "H5Fcreate");
/* Verify fcpl values */
check_fcpl_values(fcpl2_id, TEST_NUM_INDEXES, test_type_flags, test_minsizes, TEST_L2B, TEST_B2L);
ret = H5Pclose(fcpl2_id);
CHECK_I(ret, "H5Pclose");
/* Close and re-open the file. Make sure that fcpl values are still
* correct.
*/
ret = H5Fclose(fid);
CHECK_I(ret, "H5Fclose");
fid = H5Fopen(FILENAME, H5F_ACC_RDWR, H5P_DEFAULT);
CHECK_I(fid, "H5Fopen");
fcpl2_id = H5Fget_create_plist(fid);
CHECK_I(ret, "H5Fcreate");
/* Verify fcpl values */
check_fcpl_values(fcpl2_id, TEST_NUM_INDEXES, test_type_flags, test_minsizes, TEST_L2B, TEST_B2L);
/* Clean up */
ret = H5Pclose(fcpl2_id);
CHECK_I(ret, "H5Pclose");
ret = H5Fclose(fid);
CHECK_I(ret, "H5Fclose");
/* Test giving bogus values to H5P* functions */
H5E_BEGIN_TRY {
/* Trying to create too many indexes should fail */
ret = H5Pset_shared_mesg_nindexes(fcpl_id, H5O_SHMESG_MAX_NINDEXES + 1);
VERIFY(ret, -1, "H5Pset_shared_mesg_nindexes");
/* Trying to set index to an index higher than the current number
* of indexes should fail.
*/
ret = H5Pset_shared_mesg_index(fcpl_id, H5O_SHMESG_MAX_NINDEXES, 0, 15);
VERIFY(ret, -1, "H5Pset_shared_mesg_index");
ret = H5Pset_shared_mesg_index(fcpl_id, TEST_NUM_INDEXES, 0, 15);
VERIFY(ret, -1, "H5Pset_shared_mesg_index");
/* Setting an unknown flag (all flags + 1) should fail */
ret = H5Pset_shared_mesg_index(fcpl_id, 1, H5O_SHMESG_ALL_FLAG + 1, 15);
VERIFY(ret, -1, "H5Pset_shared_mesg_index");
/* Try setting two different indexes to hold fill messages. They
* should hold even very small messages for testing, even though we
* wouldn't really want to share such tiny messages in the real world.
*/
ret = H5Pset_shared_mesg_index(fcpl_id, 0, H5O_SHMESG_FILL_FLAG, 15);
CHECK_I(ret, "H5Pset_shared_mesg_index");
ret = H5Pset_shared_mesg_index(fcpl_id, 1, H5O_SHMESG_FILL_FLAG, 15);
CHECK_I(ret, "H5Pset_shared_mesg_index");
fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl_id, H5P_DEFAULT);
VERIFY(fid, -1, "H5Fcreate");
ret = H5Pset_shared_mesg_index(fcpl_id, 1, H5O_SHMESG_DTYPE_FLAG | H5O_SHMESG_FILL_FLAG, 15);
CHECK_I(ret, "H5Pset_shared_mesg_index");
fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl_id, H5P_DEFAULT);
VERIFY(fid, -1, "H5Fcreate");
/* Test list/btree cutoffs. We can set these to any positive value,
* but if the list max is less than the btree min we'll get an error
* when the file is created.
*/
ret = H5Pset_shared_mesg_phase_change(fcpl_id, 10, 12);
VERIFY(ret, -1, "H5Pset_shared_mesg_phase_change");
/* Setting them to extremely large values should also fail */
ret = H5Pset_shared_mesg_phase_change(fcpl_id, H5O_SHMESG_MAX_LIST_SIZE + 1, 0);
VERIFY(ret, -1, "H5Pset_shared_mesg_phase_change");
ret = H5Pset_shared_mesg_phase_change(fcpl_id, 10, H5O_SHMESG_MAX_LIST_SIZE + 10);
VERIFY(ret, -1, "H5Pset_shared_mesg_phase_change");
ret = H5Pset_shared_mesg_phase_change(fcpl_id, H5O_SHMESG_MAX_LIST_SIZE, H5O_SHMESG_MAX_LIST_SIZE+1);
VERIFY(ret, -1, "H5Pset_shared_mesg_phase_change");
} H5E_END_TRY
/* Actually, the list max can be exactly 1 greater than the
* btree min, but no more. Also, the errors above shouldn't
* have corrupted the fcpl, although we do need to reset the
* second index that we changed above.
*/
ret = H5Pset_shared_mesg_index(fcpl_id, 1, test_type_flags[1], 15);
CHECK_I(ret, "H5Pset_shared_mesg_index");
ret = H5Pset_shared_mesg_phase_change(fcpl_id, 10, 11);
CHECK_I(ret, "H5Pset_shared_mesg_phase_change");
fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl_id, H5P_DEFAULT);
CHECK_I(fid, "H5Fcreate");
ret = H5Fclose(fid);
CHECK_I(ret, "H5Fclose");
/* Test edge cases; H5O_SHMESG_MAX_NINDEXES and H5O_SHMESG_MAX_LIST_SIZE should be
* valid values. Also, creating a file with uninitialized indexes
* (indexes 3-5) should work.
*/
ret = H5Pset_shared_mesg_nindexes(fcpl_id, H5O_SHMESG_MAX_NINDEXES);
CHECK_I(ret, "H5Pset_shared_mesg_nindexes");
ret = H5Pset_shared_mesg_phase_change(fcpl_id, H5O_SHMESG_MAX_LIST_SIZE, H5O_SHMESG_MAX_LIST_SIZE);
CHECK_I(ret, "H5Pset_shared_mesg_phase_change");
fid = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl_id, H5P_DEFAULT);
CHECK_I(fid, "H5Fcreate");
/* Clean up */
ret = H5Pclose(fcpl_id);
CHECK_I(ret, "H5Pclose");
ret = H5Fclose(fid);
CHECK_I(ret, "H5Fclose");
}
/*-------------------------------------------------------------------------
* Function: make_dtype_1
*
* Purpose: Creates a complicated datatype for use in testing
* shared object header messages. The important thing is that
* the datatypes must take a lot of space to store on disk.
*
* Return: Success: datatype ID (should be closed by calling function)
* Failure: negative
*
* Programmer: James Laird
* Saturday, August 26, 2006
*
*-------------------------------------------------------------------------
*/
static hid_t
make_dtype_1(void)
{
hid_t dtype1_id = -1;
hid_t str_id = -1;
/* Create compound datatype. */
if((dtype1_id = H5Tcreate(H5T_COMPOUND, sizeof(struct dtype1_struct))) < 0) TEST_ERROR
if(H5Tinsert(dtype1_id, "i1", HOFFSET(dtype1_struct, i1), H5T_NATIVE_INT) < 0) TEST_ERROR
str_id = H5Tcopy(H5T_C_S1);
if(H5Tset_size(str_id, (size_t)10) < 0) TEST_ERROR
if(H5Tinsert(dtype1_id, "string", HOFFSET(dtype1_struct, str), str_id) < 0) TEST_ERROR
if(H5Tinsert(dtype1_id, "i2", HOFFSET(dtype1_struct, i2), H5T_NATIVE_INT) < 0) TEST_ERROR
if(H5Tinsert(dtype1_id, "i3", HOFFSET(dtype1_struct, i3), H5T_NATIVE_INT) < 0) TEST_ERROR
if(H5Tinsert(dtype1_id, "i4", HOFFSET(dtype1_struct, i4), H5T_NATIVE_INT) < 0) TEST_ERROR
if(H5Tinsert(dtype1_id, "i5", HOFFSET(dtype1_struct, i5), H5T_NATIVE_INT) < 0) TEST_ERROR
if(H5Tinsert(dtype1_id, "i6", HOFFSET(dtype1_struct, i6), H5T_NATIVE_INT) < 0) TEST_ERROR
if(H5Tinsert(dtype1_id, "i7", HOFFSET(dtype1_struct, i7), H5T_NATIVE_INT) < 0) TEST_ERROR
if(H5Tinsert(dtype1_id, "i8", HOFFSET(dtype1_struct, i8), H5T_NATIVE_INT) < 0) TEST_ERROR
if(H5Tinsert(dtype1_id, "f1", HOFFSET(dtype1_struct, f1), H5T_NATIVE_FLOAT) < 0) TEST_ERROR
if(H5Tclose(str_id) < 0) TEST_ERROR
return dtype1_id;
error:
H5E_BEGIN_TRY {
H5Tclose(str_id);
H5Tclose(dtype1_id);
} H5E_END_TRY
return -1;
}
/*-------------------------------------------------------------------------
* Function: make_dtype_2
*
* Purpose: Creates complicated datatypes for use in testing
* shared object header messages. The important thing is that
* the datatypes must take a lot of space to store on disk.
*
* Return: Success: datatype ID (should be closed by calling function)
* Failure: negative
*
* Programmer: James Laird
* Saturday, August 26, 2006
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static hid_t
make_dtype_2(void)
{
hid_t dtype2_id = -1;
hid_t enum_id= -1;
hid_t int_id=-1;
int x;
hsize_t dims[] = {2, 1, 2, 4};
size_t size;
/* Create an int with a strange precision */
if((int_id = H5Tcopy(H5T_NATIVE_INT)) < 0) TEST_ERROR
if(H5Tset_precision(int_id, (size_t)24) < 0) TEST_ERROR
/* Create an enumeration using that int */
if((enum_id = H5Tenum_create(int_id)) < 0) TEST_ERROR
for(x = 0; x < ENUM_NUM_MEMBS; x++)
if(H5Tenum_insert(enum_id, ENUM_NAME[x], &ENUM_VAL[x]) < 0) TEST_ERROR
/* Create arrays of arrays of arrays of enums */
if((dtype2_id = H5Tarray_create2(enum_id, 3, dims)) < 0) TEST_ERROR
if((dtype2_id = H5Tarray_create2(dtype2_id, 4, dims)) < 0) TEST_ERROR
if((dtype2_id = H5Tarray_create2(dtype2_id, 2, dims)) < 0) TEST_ERROR
if((dtype2_id = H5Tarray_create2(dtype2_id, 1, dims)) < 0) TEST_ERROR
if(H5Tclose(enum_id) < 0) TEST_ERROR
if(H5Tclose(int_id) < 0) TEST_ERROR
/* Check the datatype size. If this is different than the #defined
* size then the fills values will have the wrong size.
*/
size = H5Tget_size(dtype2_id);
if(size != DTYPE2_SIZE) TEST_ERROR
return dtype2_id;
error:
H5E_BEGIN_TRY {
H5Tclose(dtype2_id);
H5Tclose(enum_id);
H5Tclose(int_id);
} H5E_END_TRY
return -1;
}
/*-------------------------------------------------------------------------
* Function: close_reopen_file
*
* Purpose: Closes a file and then reopens it. Used to ensure that
* SOHMs are written to and read from disk
*
* Return: Success: new hid_t for the file
* Failure: Negative
*
* Programmer: James Laird
* Wednesday, October 4, 2006
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static hid_t
close_reopen_file(hid_t file, const char* filename, hid_t fapl_id)
{
hid_t fid;
if(H5Fclose(file) < 0) FAIL_STACK_ERROR
if((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl_id)) < 0) FAIL_STACK_ERROR
return(fid);
error:
return -1;
}
/*-------------------------------------------------------------------------
* Function: size1_helper
*
* Purpose: Creates object headers that use a large datatype message.
*
* Used in test_sohm_basic. Should close the file ID passed in.
* Set test_file_closing to 1 to add file closing and reopening
* whenever possible (to test that SOHMs are written correctly
* on disk and not just in memory).
*
* Return: Success: file ID (may not be the same one passed in)
* Failure: Negative
*
* Programmer: James Laird
* Monday, April 10, 2006
*
*-------------------------------------------------------------------------
*/
static hid_t
size1_helper(hid_t file, const char* filename, hid_t fapl_id, int test_file_closing)
{
dtype1_struct wdata;
dtype1_struct rdata;
hid_t dtype1_id = -1;
hid_t space_id = -1;
hid_t dset_id = -1;
hsize_t dim1[1];
int x;
/* Closing and re-opening the file takes a long time on systems without
* local disks. Don't close and reopen if express testing is enabled.
*/
if(GetTestExpress() > 1)
test_file_closing = 0;
/* Intialize wdata */
HDmemset(&wdata, 0, sizeof(wdata));
wdata.i1 = 11;
HDstrcpy(wdata.str, "string");
wdata.i2 = 22;
wdata.i3 = 33;
wdata.i4 = 44;
wdata.i5 = 55;
wdata.i6 = 66;
wdata.i7 = 77;
wdata.i8 = 88;
wdata.f1 = 0.0;
/* Intialize rdata */
HDmemset(&rdata, 0, sizeof(rdata));
if((dtype1_id = make_dtype_1()) < 0) TEST_ERROR
/* Create the dataspace and dataset */
dim1[0] = 1;
if((space_id = H5Screate_simple(1, dim1, NULL)) < 0) TEST_ERROR
if((dset_id = H5Dcreate2(file, DSETNAME[0], dtype1_id, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR
/* Test writing and reading */
if(H5Dwrite(dset_id, dtype1_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wdata) < 0) FAIL_STACK_ERROR
if(H5Dread(dset_id, dtype1_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata) < 0) FAIL_STACK_ERROR
if(rdata.i1 != wdata.i1 || rdata.i2 != wdata.i2 || HDstrcmp(rdata.str, wdata.str)) {
H5_FAILED(); AT();
printf("incorrect read data\n");
goto error;
} /* end if */
if(H5Dclose(dset_id) < 0) FAIL_STACK_ERROR
/* Close and re-open the file if requested*/
if(test_file_closing)
if((file = close_reopen_file(file, filename, fapl_id)) < 0) TEST_ERROR
/* Create more datasets with the same datatype */
if((dset_id = H5Dcreate2(file, DSETNAME[1], dtype1_id, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) FAIL_STACK_ERROR
if(H5Dclose(dset_id) < 0) FAIL_STACK_ERROR
/* Close and re-open the file if requested*/
if(test_file_closing)
if((file = close_reopen_file(file, filename, fapl_id)) < 0) TEST_ERROR
if((dset_id = H5Dcreate2(file, DSETNAME[2], dtype1_id, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR
if(H5Dclose(dset_id) < 0) TEST_ERROR
/* Close and re-open the file if requested*/
if(test_file_closing)
if((file = close_reopen_file(file, filename, fapl_id)) < 0) TEST_ERROR
if((dset_id = H5Dcreate2(file,DSETNAME[3],dtype1_id,space_id,H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR
/* Write data to dataset 3 for later */
if(H5Dwrite(dset_id, dtype1_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, &wdata) < 0) TEST_ERROR
if(H5Dclose(dset_id) < 0) TEST_ERROR
if(H5Tclose(dtype1_id) < 0) TEST_ERROR
/* Close and re-open the file if requested*/
if(test_file_closing)
if((file = close_reopen_file(file, filename, fapl_id)) < 0) TEST_ERROR
/* Make sure the data has been written successfully */
if((dset_id = H5Dopen2(file, DSETNAME[0], H5P_DEFAULT)) < 0) TEST_ERROR
if((dtype1_id = H5Dget_type(dset_id)) < 0) TEST_ERROR
/* Read data back again */
HDmemset(&rdata, 0, sizeof(rdata));
if(H5Dread(dset_id, dtype1_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata) < 0) {
H5_FAILED(); AT();
printf("Can't read data\n");
goto error;
} /* end if */
if(rdata.i1 != wdata.i1 || rdata.i2 != wdata.i2 || HDstrcmp(rdata.str, wdata.str)) {
H5_FAILED(); AT();
printf("incorrect read data\n");
goto error;
} /* end if */
if(H5Dclose(dset_id) < 0) TEST_ERROR
/* Create several copies of the dataset (this increases the amount of space saved by sharing the datatype message) */
for(x = 0; x < SOHM_HELPER_NUM_EX_DSETS; x++) {
if((dset_id = H5Dcreate2(file, EXTRA_DSETNAME[x], dtype1_id, space_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT)) < 0) TEST_ERROR
if(H5Dclose(dset_id) < 0) TEST_ERROR
/* Close and re-open the file if requested*/
if(test_file_closing)
if((file = close_reopen_file(file, filename, fapl_id)) < 0) TEST_ERROR
} /* end for */
if(H5Tclose(dtype1_id) < 0) TEST_ERROR
if(H5Sclose(space_id) < 0) TEST_ERROR
/* Ensure that we can still read data back from dataset 3 */
if((dset_id = H5Dopen2(file, DSETNAME[3], H5P_DEFAULT)) < 0) TEST_ERROR
if((dtype1_id = H5Dget_type(dset_id)) < 0) TEST_ERROR
/* Read data back again */
HDmemset(&rdata, 0, sizeof(rdata));
if(H5Dread(dset_id, dtype1_id, H5S_ALL, H5S_ALL, H5P_DEFAULT, &rdata) < 0) {
H5_FAILED(); AT();
printf("Can't read data\n");
goto error;
} /* end if */
if(rdata.i1 != wdata.i1 || rdata.i2 != wdata.i2 || HDstrcmp(rdata.str, wdata.str)) {
H5_FAILED(); AT();
printf("incorrect read data\n");
goto error;
} /* end if */
if(H5Dclose(dset_id) < 0) TEST_ERROR
if(H5Tclose(dtype1_id) < 0) TEST_ERROR
return file;
error:
H5E_BEGIN_TRY {
H5Sclose(space_id);
H5Tclose(dtype1_id);
H5Dclose(dset_id);
H5Fclose(file);
} H5E_END_TRY
return -1;
}
/*-------------------------------------------------------------------------
* Function: test_sohm_size1
*
* Purpose: Tests shared object header messages with a large datatype
*
* Programmer: James Laird
* Monday, April 10, 2006
*
* Modifications:
*
*-------------------------------------------------------------------------
*/
static void test_sohm_size1(void)
{
hid_t file = -1;
hid_t fcpl_id = -1;
hid_t fapl_id = -1;
hsize_t sohm_oh_size;
hsize_t sohm_btree_oh_size;
h5_stat_size_t norm_empty_filesize;
h5_stat_size_t sohm_empty_filesize;
h5_stat_size_t sohm_btree_empty_filesize;
h5_stat_size_t norm_final_filesize;
h5_stat_size_t sohm_final_filesize;
h5_stat_size_t sohm_btree_final_filesize;
h5_stat_size_t norm_final_filesize2;
h5_stat_size_t sohm_final_filesize2;
h5_stat_size_t sohm_btree_final_filesize2;
H5O_info_t oinfo;
unsigned num_indexes = 1;
unsigned index_flags = H5O_SHMESG_DTYPE_FLAG;
unsigned min_mesg_size = 50;
unsigned list_max = 11;
unsigned btree_min = 10;
herr_t ret;
MESSAGE(5, ("Testing that shared datatypes save space\n"));
/* Create a FAPL with "semi" close degree, to detect dangling IDs */
fapl_id = H5Pcreate(H5P_FILE_ACCESS);
CHECK_I(fapl_id, "H5Pcreate");
ret = H5Pset_fclose_degree(fapl_id, H5F_CLOSE_SEMI);
CHECK_I(ret, "H5Pset_fclose_degree");
/* Create a file with SOHMs disabled and get its size */
fcpl_id = H5Pcreate(H5P_FILE_CREATE);
CHECK_I(fcpl_id, "H5Pcreate");
ret = H5Pset_shared_mesg_nindexes(fcpl_id, 0);
CHECK_I(ret, "H5Pset_shared_mesg_nindexes");
file = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl_id, fapl_id);
CHECK_I(file, "H5Fcreate");
ret = H5Fclose(file);
CHECK_I(ret, "H5Fclose");
/* Get the file size */
norm_empty_filesize = h5_get_file_size(FILENAME, fapl_id);
/* Add a bunch of large datatypes to the file */
file = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl_id);
CHECK_I(file, "H5Fopen");
file = size1_helper(file, FILENAME, fapl_id, 0);
CHECK_I(file, "size1_helper");
ret = H5Fclose(file);
CHECK_I(ret, "H5Fclose");
/* Get the new file size */
norm_final_filesize = h5_get_file_size(FILENAME, fapl_id);
/* Use the same property list to create a new file. */
file = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl_id, fapl_id);
CHECK_I(file, "H5Fcreate");
ret = H5Pclose(fcpl_id);
CHECK_I(ret, "H5Pclose");
/* Add the same large datatypes, but keep closing and re-opening the file */
file = size1_helper(file, FILENAME, fapl_id, 1);
CHECK_I(file, "size1_helper");
ret = H5Fclose(file);
CHECK_I(ret, "H5Fclose");
/* Get the file size */
norm_final_filesize2 = h5_get_file_size(FILENAME, fapl_id);
/* Now do the same thing for a file with SOHMs enabled */
/* Create FCPL with SOHMs enabled */
fcpl_id = H5Pcreate(H5P_FILE_CREATE);
CHECK_I(fcpl_id, "H5Pcreate");
/* Tests one index holding only datatype messages */
ret = H5Pset_shared_mesg_nindexes(fcpl_id, num_indexes);
CHECK_I(ret, "H5Pset_shared_mesg_nindexes");
ret = H5Pset_shared_mesg_index(fcpl_id, 0, index_flags, min_mesg_size);
CHECK_I(ret, "H5Pset_shared_mesg_index");
ret = H5Pset_shared_mesg_phase_change(fcpl_id, list_max, btree_min);
CHECK_I(ret, "H5Pset_shared_mesg_phase_change");
/* Create a file */
file = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl_id, fapl_id);
CHECK_I(file, "H5Fcreate");
ret = H5Fclose(file);
CHECK_I(ret, "H5Fclose");
sohm_empty_filesize = h5_get_file_size(FILENAME, fapl_id);
/* Add a bunch of datatypes to this file */
file = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl_id);
CHECK_I(file, "H5Fopen");
file = size1_helper(file, FILENAME, fapl_id, 0);
CHECK_I(file, "size1_helper");
/* Get the size of a dataset object header */
ret = H5Oget_info_by_name(file, DSETNAME[0], &oinfo, H5P_DEFAULT);
CHECK_I(ret, "H5Oget_info_by_name");
ret = H5Fclose(file);
CHECK_I(ret, "H5Fclose");
sohm_oh_size = oinfo.hdr.space.total;
/* Get the new file size */
sohm_final_filesize = h5_get_file_size(FILENAME, fapl_id);
/* Use the same property list to create a new file. */
file = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl_id, fapl_id);
CHECK_I(file, "H5Fcreate");
ret = H5Pclose(fcpl_id);
CHECK_I(ret, "H5Pclose");
/* Add the same large datatypes, but keep closing and re-opening the file */
file = size1_helper(file, FILENAME, fapl_id, 1);
CHECK_I(file, "size1_helper");
ret = H5Fclose(file);
CHECK_I(ret, "H5Fclose");
/* Get the file size */
sohm_final_filesize2 = h5_get_file_size(FILENAME, fapl_id);
/* Create FCPL with SOHMs enabled that uses a B-tree index */
fcpl_id = H5Pcreate(H5P_FILE_CREATE);
CHECK_I(fcpl_id, "H5Pcreate");
/* Tests one index holding only datatype messages */
ret = H5Pset_shared_mesg_nindexes(fcpl_id, num_indexes);
CHECK_I(ret, "H5Pset_shared_mesg_nindexes");
ret = H5Pset_shared_mesg_index(fcpl_id, 0, index_flags, min_mesg_size);
CHECK_I(ret, "H5Pset_shared_mesg_index");
ret = H5Pset_shared_mesg_phase_change(fcpl_id, 0, 0);
CHECK_I(ret, "H5Pset_shared_mesg_phase_change");
/* Create a file */
file = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl_id, fapl_id);
CHECK_I(file, "H5Fcreate");
ret = H5Fclose(file);
CHECK_I(ret, "H5Fclose");
sohm_btree_empty_filesize = h5_get_file_size(FILENAME, fapl_id);
/* Add a bunch of datatypes to this file */
file = H5Fopen(FILENAME, H5F_ACC_RDWR, fapl_id);
CHECK_I(file, "H5Fopen");
file = size1_helper(file, FILENAME, fapl_id, 0);
CHECK_I(file, "size1_helper");
/* Get the size of a dataset object header */
ret = H5Oget_info_by_name(file, DSETNAME[0], &oinfo, H5P_DEFAULT);
CHECK_I(ret, "H5Oget_info_by_name");
ret = H5Fclose(file);
CHECK_I(ret, "H5Fclose");
sohm_btree_oh_size = oinfo.hdr.space.total;
/* Get the new file size */
sohm_btree_final_filesize = h5_get_file_size(FILENAME, fapl_id);
/* Use the same property list to create a new file. */
file = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl_id, fapl_id);
CHECK_I(file, "H5Fcreate");
ret = H5Pclose(fcpl_id);
CHECK_I(ret, "H5Pclose");
/* Add the same large datatypes, but keep closing and re-opening the file */
file = size1_helper(file, FILENAME, fapl_id, 1);
CHECK_I(file, "size1_helper");
ret = H5Fclose(file);
CHECK_I(ret, "H5Fclose");
/* Get the file size */
sohm_btree_final_filesize2 = h5_get_file_size(FILENAME, fapl_id);
/* Check that all sizes make sense */
/* Object headers in SOHM files should be smaller than normal object
* headers. How the SOHM messages are stored shouldn't affect the
* size of the object header.
*/
if(sohm_oh_size != sohm_btree_oh_size)
VERIFY(sohm_btree_oh_size, 1, "H5Oget_info_by_name");
/* Both sohm files should be bigger than a normal file when empty.
* It's hard to say whether a B-tree with no nodes allocated should be
* smaller than a list with SOHM_HELPER_NUM_DTYPES elements.
* The sizes here shouldn't really be 1; it's just used to ensure that the
* error code triggers.
*/
if(sohm_empty_filesize <= norm_empty_filesize)
VERIFY(sohm_empty_filesize, 1, "h5_get_file_size");
if(sohm_btree_empty_filesize <= norm_empty_filesize)
VERIFY(sohm_btree_empty_filesize, 1, "h5_get_file_size");
/* When full, the sohm btree file should be smaller than the normal file.
* The sohm list file should be at least as small, since it doesn't need the
* overhead of a B-tree.
*/
if(sohm_btree_final_filesize >= norm_final_filesize)
VERIFY(sohm_btree_final_filesize, 1, "h5_get_file_size");
if(sohm_final_filesize > sohm_btree_final_filesize)
VERIFY(sohm_final_filesize, 1, "h5_get_file_size");
/* This shouldn't change even if we open and close the file */
if(sohm_btree_final_filesize2 >= norm_final_filesize2)
VERIFY(sohm_btree_final_filesize2, 1, "h5_get_file_size");
if(sohm_final_filesize2 > sohm_btree_final_filesize2)
VERIFY(sohm_final_filesize2, 1, "h5_get_file_size");
ret = H5Pclose(fapl_id);
CHECK_I(ret, "H5Pclose");
}
/*-------------------------------------------------------------------------
* Function: sohm_attr_helper
*
* Purpose: Given an fcpl, tests creating attributes with and without
* committed datatypes.
*
* Programmer: James Laird
* Thursday, November 30, 2006
*
*-------------------------------------------------------------------------
*/
static void sohm_attr_helper(hid_t fcpl_id)
{
hid_t file_id;
hid_t type_id;
hid_t space_id;
hid_t group_id;
hid_t attr_id, attr_id2;
hsize_t dims = 2;
int wdata[2] = {7, 42};
int rdata[2];
herr_t ret;
size_t x;
/*----------------------------------------------------------------------------
* Test attribute with transient datatype
*/
/* Create a file using the fcpl */
file_id = H5Fcreate(FILENAME, H5F_ACC_TRUNC, fcpl_id, H5P_DEFAULT);
CHECK_I(file_id, "H5Fcreate");
/* Create a normal datatype and dataset */
type_id = H5Tcopy(H5T_NATIVE_INT);
CHECK_I(type_id, "H5Tcopy");
space_id = H5Screate_simple(1, &dims, &dims);