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
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Tests to verify behavior of minimized dataset object headers.
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
#include "hdf5.h"
#include "h5test.h"
/******************
* TESTING MACROS *
******************/
/* basenames of test files created in this test suite */
#define OHMIN_FILENAME_A "ohdr_min_a"
#define OHMIN_FILENAME_B "ohdr_min_b"
/* used for object header size comparison */
#define EQ 1
#define LT 2
#define GT 3
/*********************
* UTILITY FUNCTIONS *
*********************/
/* ---------------------------------------------------------------------------
* Function: put_attribute()
*
* Purpose: Set an attribute with the given information.
*
* If the out parameter `attr_id` is negative, a new attribute will be
* created with the given information. Else, it will attempt to update the
* attribute with the new value.
*
* `dataspace_id` ignored if `attribute_id` >= 0
*
* Return: 0 (success) or -1 (failure)
*
* ---------------------------------------------------------------------------
*/
static herr_t
put_attribute(hid_t loc_id, const char *attrname, const void *attrvalue, hid_t datatype_id, hid_t dataspace_id, hid_t *attribute_id)
{
if((*attribute_id) < 0) {
hid_t id = -1;
id = H5Acreate(loc_id, attrname, datatype_id, dataspace_id, H5P_DEFAULT, H5P_DEFAULT);
if(id < 0)
return FAIL;
*attribute_id = id;
}
return H5Awrite(*attribute_id, datatype_id, attrvalue);
} /* put_attribute */
/* ---------------------------------------------------------------------------
* Function: count_attributes()
*
* Purpose: Count the number of attributes attached to an object.
*
* TODO: If the location id is that of a file, tries to count all the
* attributes present in the file.
*
* Return: -1 if an error occurred, else the number of attributes.
*
* ---------------------------------------------------------------------------
*/
static int
count_attributes(hid_t dset_id)
{
H5O_info_t info;
if(0 > H5Oget_info(dset_id, &info, H5O_INFO_ALL))
return -1;
else
return (int)info.num_attrs; /* should never exceed int bounds */
} /* count_attributes */
/* ---------------------------------------------------------------------------
* Function: _oh_getsize()
*
* Purpose: Get the total space used by the object header
*
*
* Return: SUCCEED/FAIL. On success, stores size in `size_out` pointer.
*
* ---------------------------------------------------------------------------
*/
static herr_t
_oh_getsize(hid_t did, hsize_t *size_out)
{
H5O_info_t info;
if(FAIL == H5Oget_info2(did, &info, H5O_INFO_HDR))
return FAIL;
*size_out = info.hdr.space.total;
return SUCCEED;
} /* _oh_getsize */
/* ---------------------------------------------------------------------------
* Function: oh_compare()
*
* Purpose: Compare the TOTAL space used by datasets' object headers.
*
*
* Return: negative value if an error occurred,
* else positive #defined indicator value EQ, LT, GT.
*
* ---------------------------------------------------------------------------
*/
static int
oh_compare(hid_t did1, hid_t did2)
{
hsize_t space1 = 0;
hsize_t space2 = 0;
if(FAIL == _oh_getsize(did1, &space1))
return -1;
if(FAIL == _oh_getsize(did2, &space2))
return -2;
if(space1 < space2)
return LT;
else if(space1 > space2)
return GT;
else
return EQ;
}
/******************
* TEST FUNCTIONS *
******************/
/* ---------------------------------------------------------------------------
* Demonstrate attribute addition to datasets.
* Conduct additions side-by-side with a standard datataset and one with
* minimized dataset object headers.
* ---------------------------------------------------------------------------
*/
static herr_t
test_minimized_oh_attribute_addition(void)
{
hsize_t array_10[1] = {10}; /* dataspace extent */
char buffer[10] = ""; /* to inspect string attribute */
int a_out = 0;
char filename[512] = "";
hid_t int_type_id = -1;
hid_t char_type_id = -1;
hid_t dcpl_id = -1;
hid_t dspace_id = -1;
hid_t dspace_scalar_id = -1;
hid_t dset_id = -1;
hid_t mindset_id = -1;
hid_t attr_1_id = -1;
hid_t attr_1a_id = -1;
hid_t attr_2_id = -1;
hid_t attr_2a_id = -1;
hid_t attr_3_id = -1;
hid_t attr_3a_id = -1;
hid_t file_id = -1;
herr_t ret;
int count = 0;
TESTING("attribute additions to [un]minimized dataset")
/*********
* SETUP *
*********/
if(h5_fixname(OHMIN_FILENAME_A, H5P_DEFAULT, filename, sizeof(filename)) == NULL)
TEST_ERROR
dspace_id = H5Screate_simple(1, array_10, NULL);
if(dspace_id < 0) TEST_ERROR
dspace_scalar_id = H5Screate(H5S_SCALAR);
if(dspace_scalar_id < 0) TEST_ERROR
char_type_id = H5Tcopy(H5T_NATIVE_CHAR);
if(char_type_id < 0) TEST_ERROR
int_type_id = H5Tcopy(H5T_NATIVE_INT);
if(int_type_id < 0) TEST_ERROR
dcpl_id = H5Pcreate(H5P_DATASET_CREATE);
if(dcpl_id < 0) TEST_ERROR
ret = H5Pset_dset_no_attrs_hint(dcpl_id, TRUE);
if(ret < 0) TEST_ERROR
file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
if(file_id < 0) TEST_ERROR
H5E_BEGIN_TRY {
count = count_attributes(dset_id);
} H5E_END_TRY;
if(count != -1) TEST_ERROR
dset_id = H5Dcreate(file_id, "dataset", int_type_id, dspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
if(dset_id < 0) TEST_ERROR
mindset_id = H5Dcreate(file_id, "mindataset", int_type_id, dspace_id, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
if(mindset_id < 0) TEST_ERROR
/********************
* TEST/DEMONSTRATE *
********************/
/* -------------------
* no attributes added
*/
count = count_attributes(dset_id);
if(count != 0) TEST_ERROR
count = count_attributes(mindset_id);
if(count != 0) TEST_ERROR
/* -----------------
* add one attribute
*/
ret = put_attribute(dset_id, "PURPOSE", "DEMO", char_type_id, dspace_id, &attr_1_id);
if(ret < 0) TEST_ERROR
ret = put_attribute(mindset_id, "PURPOSE", "DEMO", char_type_id, dspace_id, &attr_1a_id);
if(ret < 0) TEST_ERROR
count = count_attributes(dset_id);
if(count != 1) TEST_ERROR
count = count_attributes(mindset_id);
if(count != 1) TEST_ERROR
ret = H5Aread(attr_1_id, char_type_id, buffer);
if(ret < 0) TEST_ERROR
if(HDstrcmp("DEMO", buffer)) TEST_ERROR
ret = H5Aread(attr_1a_id, char_type_id, buffer);
if(ret < 0) TEST_ERROR
if(HDstrcmp("DEMO", buffer)) TEST_ERROR
/* -----------------
* modify one attribute
*/
ret = put_attribute(dset_id, "PURPOSE", "REWRITE", char_type_id, -1, &attr_1_id);
if(ret < 0) TEST_ERROR
ret = put_attribute(mindset_id, "PURPOSE", "REWRITE", char_type_id, -1, &attr_1a_id);
if(ret < 0) TEST_ERROR
count = count_attributes(dset_id);
if(count != 1) TEST_ERROR
count = count_attributes(mindset_id);
if(count != 1) TEST_ERROR
ret = H5Aread(attr_1_id, char_type_id, buffer);
if(ret < 0) TEST_ERROR
if(HDstrcmp("REWRITE", buffer)) TEST_ERROR
ret = H5Aread(attr_1a_id, char_type_id, buffer);
if(ret < 0) TEST_ERROR
if(HDstrcmp("REWRITE", buffer)) TEST_ERROR
/* -----------------
* add second attribute
*/
a_out = 5;
ret = put_attribute(dset_id, "RANK", &a_out, int_type_id, dspace_scalar_id, &attr_2_id);
if(ret < 0) TEST_ERROR
a_out = 3;
ret = put_attribute(mindset_id, "RANK", &a_out, int_type_id, dspace_scalar_id, &attr_2a_id);
if(ret < 0) TEST_ERROR
count = count_attributes(dset_id);
if(count != 2) TEST_ERROR
count = count_attributes(mindset_id);
if(count != 2) TEST_ERROR
ret = H5Aread(attr_2_id, int_type_id, &a_out);
if(ret < 0) TEST_ERROR
if(a_out != 5) TEST_ERROR
ret = H5Aread(attr_2a_id, int_type_id, &a_out);
if(ret < 0) TEST_ERROR
if(a_out != 3) TEST_ERROR
/* -----------------
* add third attribute
*/
a_out = -86;
ret = put_attribute(dset_id, "FLAVOR", &a_out, int_type_id, dspace_scalar_id, &attr_3_id);
if(ret < 0) TEST_ERROR
a_out = 2185;
ret = put_attribute(mindset_id, "FLAVOR", &a_out, int_type_id, dspace_scalar_id, &attr_3a_id);
if(ret < 0) TEST_ERROR
count = count_attributes(dset_id);
if(count != 3) TEST_ERROR
count = count_attributes(mindset_id);
if(count != 3) TEST_ERROR
ret = H5Aread(attr_3_id, int_type_id, &a_out);
if(ret < 0) TEST_ERROR
if(a_out != -86) TEST_ERROR
ret = H5Aread(attr_3a_id, int_type_id, &a_out);
if(ret < 0) TEST_ERROR
if(a_out != 2185) TEST_ERROR
/************
* TEARDOWN *
************/
if(H5Tclose(int_type_id) < 0) TEST_ERROR
if(H5Tclose(char_type_id) < 0) TEST_ERROR
if(H5Pclose(dcpl_id) < 0) TEST_ERROR
if(H5Sclose(dspace_id) < 0) TEST_ERROR
if(H5Dclose(dset_id) < 0) TEST_ERROR
if(H5Dclose(mindset_id) < 0) TEST_ERROR
if(H5Aclose(attr_1_id) < 0) TEST_ERROR
if(H5Aclose(attr_1a_id) < 0) TEST_ERROR
if(H5Aclose(attr_2_id) < 0) TEST_ERROR
if(H5Aclose(attr_2a_id) < 0) TEST_ERROR
if(H5Aclose(attr_3_id) < 0) TEST_ERROR
if(H5Aclose(attr_3a_id) < 0) TEST_ERROR
if(H5Fclose(file_id) < 0) TEST_ERROR
PASSED()
return SUCCEED;
error :
H5E_BEGIN_TRY {
(void)H5Tclose(int_type_id);
(void)H5Tclose(char_type_id);
(void)H5Pclose(dcpl_id);
(void)H5Sclose(dspace_id);
(void)H5Dclose(dset_id);
(void)H5Dclose(mindset_id);
(void)H5Aclose(attr_1_id);
(void)H5Aclose(attr_1a_id);
(void)H5Aclose(attr_2_id);
(void)H5Aclose(attr_2a_id);
(void)H5Aclose(attr_3_id);
(void)H5Aclose(attr_3a_id);
(void)H5Fclose(file_id);
} H5E_END_TRY;
return FAIL;
} /* test_minimized_oh_attribute_addition */
/* ---------------------------------------------------------------------------
* Compare header sizes against when headers have been minimized.
* ---------------------------------------------------------------------------
*/
static herr_t
test_minimized_oh_size_comparisons(void)
{
hsize_t array_10[1] = {10}; /* dataspace extents */
/* IDs that are file-agnostic */
hid_t dspace_id = -1;
hid_t int_type_id = -1;
hid_t dcpl_minimize = -1;
hid_t dcpl_dontmin = -1;
/* IDs for non-minimzed file open */
hid_t file_f_id = -1; /* lower 'f' for standard file setting */
hid_t dset_f_x_id = -1; /* 'x' for default */
hid_t dset_f_N_id = -1; /* 'N' for explcit non-minimized dset */
hid_t dset_f_Y_id = -1; /* 'Y' for minimzed dset */
/* IDs for minimzed file open */
hid_t file_F_id = -1; /* upper 'F' for minimzed file setting */
hid_t dset_F_x_id = -1; /* 'x' for default */
hid_t dset_F_N_id = -1; /* 'N' for explcit non-minimized dset */
hid_t dset_F_Y_id = -1; /* 'Y' for minimzed dset */
char filename_a[512] = "";
char filename_b[512] = "";
herr_t ret;
TESTING("default size comparisons");
/*********
* SETUP *
*********/
if(h5_fixname(OHMIN_FILENAME_A, H5P_DEFAULT, filename_a, sizeof(filename_a)) == NULL)
TEST_ERROR
if(h5_fixname(OHMIN_FILENAME_B, H5P_DEFAULT, filename_b, sizeof(filename_b)) == NULL)
TEST_ERROR
dcpl_minimize = H5Pcreate(H5P_DATASET_CREATE);
if(dcpl_minimize < 0) TEST_ERROR
ret = H5Pset_dset_no_attrs_hint(dcpl_minimize, TRUE);
if(ret < 0) TEST_ERROR
dcpl_dontmin = H5Pcreate(H5P_DATASET_CREATE);
if(dcpl_dontmin < 0) TEST_ERROR
ret = H5Pset_dset_no_attrs_hint(dcpl_dontmin, FALSE);
if(ret < 0) TEST_ERROR
dspace_id = H5Screate_simple(1, array_10, NULL);
if(dspace_id < 0) TEST_ERROR
int_type_id = H5Tcopy(H5T_NATIVE_INT);
if(int_type_id < 0) TEST_ERROR
file_f_id = H5Fcreate(filename_a, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
if(file_f_id < 0) TEST_ERROR
dset_f_x_id = H5Dcreate(file_f_id, "default", int_type_id, dspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
if(dset_f_x_id < 0) TEST_ERROR
dset_f_N_id = H5Dcreate(file_f_id, "dsetNOT", int_type_id, dspace_id, H5P_DEFAULT, dcpl_dontmin, H5P_DEFAULT);
if(dset_f_N_id < 0) TEST_ERROR
dset_f_Y_id = H5Dcreate(file_f_id, "dsetMIN", int_type_id, dspace_id, H5P_DEFAULT, dcpl_minimize, H5P_DEFAULT);
if(dset_f_x_id < 0) TEST_ERROR
file_F_id = H5Fcreate(filename_b, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
if(file_F_id < 0) TEST_ERROR
ret = H5Fset_dset_no_attrs_hint(file_F_id, TRUE);
if(ret < 0) TEST_ERROR
dset_F_x_id = H5Dcreate(file_F_id, "default", int_type_id, dspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
if(dset_F_x_id < 0) TEST_ERROR
dset_F_N_id = H5Dcreate(file_F_id, "dsetNOT", int_type_id, dspace_id, H5P_DEFAULT, dcpl_dontmin, H5P_DEFAULT);
if(dset_F_N_id < 0) TEST_ERROR
dset_F_Y_id = H5Dcreate(file_F_id, "dsetMIN", int_type_id, dspace_id, H5P_DEFAULT, dcpl_minimize, H5P_DEFAULT);
if(dset_F_Y_id < 0) TEST_ERROR
/*********
* TESTS *
*********/
if(oh_compare(dset_f_x_id, dset_f_x_id) != EQ) TEST_ERROR /* identity */
if(oh_compare(dset_f_x_id, dset_f_N_id) != EQ) TEST_ERROR
if(oh_compare(dset_f_x_id, dset_f_Y_id) != GT) TEST_ERROR
if(oh_compare(dset_f_N_id, dset_f_Y_id) != GT) TEST_ERROR
if(oh_compare(dset_F_x_id, dset_F_N_id) != EQ) TEST_ERROR
if(oh_compare(dset_F_x_id, dset_F_Y_id) != EQ) TEST_ERROR
if(oh_compare(dset_F_N_id, dset_F_Y_id) != EQ) TEST_ERROR
if(oh_compare(dset_F_x_id, dset_f_Y_id) != EQ) TEST_ERROR
if(oh_compare(dset_F_x_id, dset_f_x_id) != LT) TEST_ERROR
/************
* TEARDOWN *
************/
if(H5Sclose(dspace_id) < 0) TEST_ERROR
if(H5Tclose(int_type_id) < 0) TEST_ERROR
if(H5Pclose(dcpl_minimize) < 0) TEST_ERROR
if(H5Pclose(dcpl_dontmin) < 0) TEST_ERROR
if(H5Fclose(file_f_id) < 0) TEST_ERROR
if(H5Dclose(dset_f_x_id) < 0) TEST_ERROR
if(H5Dclose(dset_f_N_id) < 0) TEST_ERROR
if(H5Dclose(dset_f_Y_id) < 0) TEST_ERROR
if(H5Fclose(file_F_id) < 0) TEST_ERROR
if(H5Dclose(dset_F_x_id) < 0) TEST_ERROR
if(H5Dclose(dset_F_N_id) < 0) TEST_ERROR
if(H5Dclose(dset_F_Y_id) < 0) TEST_ERROR
PASSED()
return SUCCEED;
error :
H5E_BEGIN_TRY {
(void)H5Pclose(dcpl_minimize);
(void)H5Pclose(dcpl_dontmin);
(void)H5Sclose(dspace_id);
(void)H5Tclose(int_type_id);
(void)H5Fclose(file_f_id);
(void)H5Dclose(dset_f_x_id);
(void)H5Dclose(dset_f_N_id);
(void)H5Dclose(dset_f_Y_id);
(void)H5Fclose(file_F_id);
(void)H5Dclose(dset_F_x_id);
(void)H5Dclose(dset_F_N_id);
(void)H5Dclose(dset_F_Y_id);
} H5E_END_TRY;
return FAIL;
} /* test_minimized_oh_size_comparisons */
/* ---------------------------------------------------------------------------
* Test minimized dataset object header with filter/pipeline message
* ---------------------------------------------------------------------------
*/
static herr_t
test_minimized_oh_with_filter(void)
{
char filename[512] = "";
const hsize_t extents[1] = {1024}; /* extents of dataspace */
const unsigned filter_values[] = {0}; /* TBD */
const hsize_t chunk_dim[] = {32}; /* needed for filter */
const int ndims = 1;
hid_t dspace_id = -1;
hid_t dtype_id = -1;
hid_t dcpl_xZ_id = -1;
hid_t dcpl_mx_id = -1;
hid_t dcpl_mZ_id = -1;
hid_t dset_xx_id = -1;
hid_t dset_xZ_id = -1;
hid_t dset_mx_id = -1;
hid_t dset_mZ_id = -1;
hid_t file_id = -1;
herr_t ret;
/* | default | minimize
* ----------+---------+---------
* no filter | xx | mx
* ----------+---------+---------
* filter | xZ | mZ
*/
TESTING("with filter message");
/*********
* SETUP *
*********/
if(h5_fixname(OHMIN_FILENAME_A, H5P_DEFAULT, filename, sizeof(filename)) == NULL)
TEST_ERROR
dcpl_mx_id = H5Pcreate(H5P_DATASET_CREATE);
if(dcpl_mx_id < 0) TEST_ERROR
ret = H5Pset_dset_no_attrs_hint(dcpl_mx_id, TRUE);
if(ret < 0) TEST_ERROR
dcpl_xZ_id = H5Pcreate(H5P_DATASET_CREATE);
if(dcpl_xZ_id < 0) TEST_ERROR
ret = H5Pset_chunk(dcpl_xZ_id, ndims, chunk_dim);
if(ret < 0) TEST_ERROR
ret = H5Pset_filter(dcpl_xZ_id, H5Z_FILTER_DEFLATE, H5Z_FLAG_OPTIONAL, 0, filter_values);
if(ret < 0) TEST_ERROR
dcpl_mZ_id = H5Pcreate(H5P_DATASET_CREATE);
if(dcpl_mZ_id < 0) TEST_ERROR
ret = H5Pset_dset_no_attrs_hint(dcpl_mZ_id, TRUE);
if(ret < 0) TEST_ERROR
ret = H5Pset_chunk(dcpl_mZ_id, ndims, chunk_dim);
if(ret < 0) TEST_ERROR
ret = H5Pset_filter( dcpl_mZ_id, H5Z_FILTER_DEFLATE, H5Z_FLAG_OPTIONAL, 0, filter_values);
if(ret < 0) TEST_ERROR
dspace_id = H5Screate_simple(1, extents, extents);
if(dspace_id < 0) TEST_ERROR
dtype_id = H5Tcopy(H5T_NATIVE_INT);
if(dtype_id < 0) TEST_ERROR
file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
if(file_id < 0) TEST_ERROR
dset_xx_id = H5Dcreate(file_id, "xx", dtype_id, dspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
if(dset_xx_id < 0) TEST_ERROR
dset_mx_id = H5Dcreate(file_id, "Mx", dtype_id, dspace_id, H5P_DEFAULT, dcpl_mx_id, H5P_DEFAULT);
if(dset_mx_id < 0) TEST_ERROR
dset_xZ_id = H5Dcreate(file_id, "xZ", dtype_id, dspace_id, H5P_DEFAULT, dcpl_xZ_id, H5P_DEFAULT);
if(dset_xZ_id < 0) TEST_ERROR
dset_mZ_id = H5Dcreate(file_id, "MZ", dtype_id, dspace_id, H5P_DEFAULT, dcpl_mZ_id, H5P_DEFAULT);
if(dset_mZ_id < 0) TEST_ERROR
/*********
* TESTS *
*********/
if(oh_compare(dset_mx_id, dset_xx_id) != LT) TEST_ERROR
if(oh_compare(dset_mx_id, dset_xZ_id) != LT) TEST_ERROR
if(oh_compare(dset_mZ_id, dset_mx_id) != GT) TEST_ERROR
if(oh_compare(dset_mZ_id, dset_xZ_id) != LT) TEST_ERROR
/************
* TEARDOWN *
************/
if(H5Sclose(dspace_id) < 0) TEST_ERROR
if(H5Tclose(dtype_id) < 0) TEST_ERROR
if(H5Pclose(dcpl_xZ_id) < 0) TEST_ERROR
if(H5Pclose(dcpl_mx_id) < 0) TEST_ERROR
if(H5Pclose(dcpl_mZ_id) < 0) TEST_ERROR
if(H5Dclose(dset_xx_id) < 0) TEST_ERROR
if(H5Dclose(dset_xZ_id) < 0) TEST_ERROR
if(H5Dclose(dset_mx_id) < 0) TEST_ERROR
if(H5Dclose(dset_mZ_id) < 0) TEST_ERROR
if(H5Fclose(file_id) < 0) TEST_ERROR
PASSED()
return SUCCEED;
error:
H5E_BEGIN_TRY {
(void)H5Sclose(dspace_id);
(void)H5Tclose(dtype_id);
(void)H5Pclose(dcpl_xZ_id);
(void)H5Pclose(dcpl_mx_id);
(void)H5Pclose(dcpl_mZ_id);
(void)H5Dclose(dset_xx_id);
(void)H5Dclose(dset_xZ_id);
(void)H5Dclose(dset_mx_id);
(void)H5Dclose(dset_mZ_id);
(void)H5Fclose(file_id);
} H5E_END_TRY;
return FAIL;
} /* test_minimized_oh_with_filter */
/* ---------------------------------------------------------------------------
* Test minimized dataset object header and recording modification times.
* ---------------------------------------------------------------------------
*/
static herr_t
test_minimized_oh_modification_times(void)
{
/* test-local structure for parameterized testing
*/
struct testcase {
unsigned oh_version;
};
char filename[512] = "";
const hsize_t extents[1] = {128}; /* extents of dataspace */
hid_t dspace_id = -1;
hid_t dtype_id = -1;
hid_t dcpl_xT_id = -1; /* Track modtime */
hid_t dcpl_mx_id = -1; /* minimized */
hid_t dcpl_mT_id = -1; /* minimized, Track */
hid_t dcpl_mN_id = -1; /* minimized, do Not track */
hid_t dset_xx_id = -1;
hid_t dset_xT_id = -1;
hid_t dset_mx_id = -1;
hid_t dset_mT_id = -1;
hid_t dset_mN_id = -1;
hid_t file_id = -1;
hid_t fapl_id = -1;
herr_t ret;
unsigned i = 0; /* for testcase loop */
unsigned n_cases = 2; /* must match `cases` array size below */
struct testcase cases[2] = {
{ 1, }, /* version 1 object header */
{ 2, }, /* version 2 object header */
};
TESTING("with modification times");
/*********
* SETUP *
*********/
if(h5_fixname(OHMIN_FILENAME_A, H5P_DEFAULT, filename, sizeof(filename)) == NULL)
TEST_ERROR
dcpl_mx_id = H5Pcreate(H5P_DATASET_CREATE);
if(dcpl_mx_id < 0) TEST_ERROR
ret = H5Pset_dset_no_attrs_hint(dcpl_mx_id, TRUE);
if(ret < 0) TEST_ERROR
dcpl_xT_id = H5Pcreate(H5P_DATASET_CREATE);
if(dcpl_xT_id < 0) TEST_ERROR
ret = H5Pset_obj_track_times(dcpl_xT_id, TRUE);
if(ret < 0) TEST_ERROR
dcpl_mT_id = H5Pcreate(H5P_DATASET_CREATE);
if(dcpl_mT_id < 0) TEST_ERROR
ret = H5Pset_dset_no_attrs_hint(dcpl_mT_id, TRUE);
if(ret < 0) TEST_ERROR
ret = H5Pset_obj_track_times(dcpl_mT_id, TRUE);
if(ret < 0) TEST_ERROR
dcpl_mN_id = H5Pcreate(H5P_DATASET_CREATE);
if(dcpl_mN_id < 0) TEST_ERROR
ret = H5Pset_dset_no_attrs_hint(dcpl_mN_id, TRUE);
if(ret < 0) TEST_ERROR
ret = H5Pset_obj_track_times(dcpl_mN_id, FALSE);
if(ret < 0) TEST_ERROR
dspace_id = H5Screate_simple(1, extents, extents);
if(dspace_id < 0) TEST_ERROR
dtype_id = H5Tcopy(H5T_NATIVE_INT);
if(dtype_id < 0) TEST_ERROR
for (i = 0; i < n_cases; i++) {
/* -------------- *
* per-case setup *
* -------------- */
fapl_id = H5P_DEFAULT;
if(cases[i].oh_version > 1) {
fapl_id = H5Pcreate(H5P_FILE_ACCESS);
if(fapl_id < 0) TEST_ERROR
ret = H5Pset_libver_bounds(fapl_id, H5F_LIBVER_V18, H5F_LIBVER_V110);
if(ret < 0) TEST_ERROR
}
file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id);
if(file_id < 0) TEST_ERROR
dset_xx_id = H5Dcreate( file_id, "xx", dtype_id, dspace_id, H5P_DEFAULT, H5P_DEFAULT, H5P_DEFAULT);
if(dset_xx_id < 0) TEST_ERROR
dset_mx_id = H5Dcreate(file_id, "mx", dtype_id, dspace_id, H5P_DEFAULT, dcpl_mx_id, H5P_DEFAULT);
if(dset_mx_id < 0) TEST_ERROR
dset_xT_id = H5Dcreate(file_id, "xT", dtype_id, dspace_id, H5P_DEFAULT, dcpl_xT_id, H5P_DEFAULT);
if(dset_xT_id < 0) TEST_ERROR
dset_mT_id = H5Dcreate(file_id, "mT", dtype_id, dspace_id, H5P_DEFAULT, dcpl_mT_id, H5P_DEFAULT);
if(dset_mT_id < 0) TEST_ERROR
dset_mN_id = H5Dcreate(file_id, "mN", dtype_id, dspace_id, H5P_DEFAULT, dcpl_mN_id, H5P_DEFAULT);
if(dset_mN_id < 0) TEST_ERROR
/* ----- *
* TESTS *
* ----- */
/* sanity check */
if(oh_compare(dset_mx_id, dset_xx_id) != LT) TEST_ERROR
if(oh_compare(dset_mx_id, dset_xT_id) != LT) TEST_ERROR
if(oh_compare(dset_xx_id, dset_xT_id) != EQ) TEST_ERROR
if(oh_compare(dset_mx_id, dset_mT_id) != EQ) TEST_ERROR
if(oh_compare(dset_mN_id, dset_mT_id) != LT) TEST_ERROR
if(oh_compare(dset_mT_id, dset_xT_id) != LT) TEST_ERROR
/* ----------------- *
* per-case teardown *
* ----------------- */
if(H5Dclose(dset_xx_id) < 0) TEST_ERROR
if(H5Dclose(dset_xT_id) < 0) TEST_ERROR
if(H5Dclose(dset_mx_id) < 0) TEST_ERROR
if(H5Dclose(dset_mT_id) < 0) TEST_ERROR
if(H5Dclose(dset_mN_id) < 0) TEST_ERROR
if(H5Fclose(file_id) < 0) TEST_ERROR
if((fapl_id != H5P_DEFAULT) && (H5Pclose(fapl_id) < 0))
TEST_ERROR
} /* for each version tested */
/************
* TEARDOWN *
************/
if(H5Sclose(dspace_id) < 0) TEST_ERROR
if(H5Tclose(dtype_id) < 0) TEST_ERROR
if(H5Pclose(dcpl_xT_id) < 0) TEST_ERROR
if(H5Pclose(dcpl_mx_id) < 0) TEST_ERROR
if(H5Pclose(dcpl_mT_id) < 0) TEST_ERROR
if(H5Pclose(dcpl_mN_id) < 0) TEST_ERROR
PASSED()
return SUCCEED;
error:
H5E_BEGIN_TRY {
(void)H5Sclose(dspace_id);
(void)H5Tclose(dtype_id);
(void)H5Pclose(dcpl_xT_id);
(void)H5Pclose(dcpl_mx_id);
(void)H5Pclose(dcpl_mT_id);
(void)H5Pclose(dcpl_mN_id);
(void)H5Dclose(dset_xx_id);
(void)H5Dclose(dset_xT_id);
(void)H5Dclose(dset_mx_id);
(void)H5Dclose(dset_mT_id);
(void)H5Dclose(dset_mN_id);
(void)H5Fclose(file_id);
(void)H5Pclose(fapl_id);
} H5E_END_TRY;
return FAIL;
} /* test_minimized_oh_modification_times */
/* ---------------------------------------------------------------------------
* Test minimized dataset object header with a fill value set.
* ---------------------------------------------------------------------------
*/
static herr_t
test_minimized_oh_fillvalue_backwards_compatability(void)
{
char filename[512] = "";
const hsize_t extents[1] = {64}; /* extents of dataspace */
const int fill[1] = {343}; /* fill value of dataset */
hid_t file_id = -1;
hid_t dtype_id = -1;
hid_t dspace_id = -1;
hid_t dcpl_id = -1;
hid_t fapl_id = -1;
hid_t dset_0_id = -1;
hid_t dset_1_id = -1;
herr_t ret;
/*********
* SETUP *
*********/
TESTING("with fill values and different libver support");
if(h5_fixname(OHMIN_FILENAME_A, H5P_DEFAULT, filename, sizeof(filename)) == NULL)
TEST_ERROR
dspace_id = H5Screate_simple(1, extents, extents);
if(dspace_id < 0) TEST_ERROR
dtype_id = H5Tcopy(H5T_NATIVE_INT);
if(dtype_id < 0) TEST_ERROR
dcpl_id = H5Pcreate(H5P_DATASET_CREATE);
if(dcpl_id < 0) TEST_ERROR
ret = H5Pset_dset_no_attrs_hint(dcpl_id, TRUE);
if(ret == FAIL) TEST_ERROR;
ret = H5Pset_fill_value(dcpl_id, dtype_id, fill);
if(ret == FAIL) TEST_ERROR;
fapl_id = H5Pcreate(H5P_FILE_ACCESS);
if(fapl_id < 0) TEST_ERROR
ret = H5Pset_libver_bounds(fapl_id, H5F_LIBVER_EARLIEST, H5F_LIBVER_LATEST);
if(ret == FAIL) TEST_ERROR;
file_id = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl_id);
if(file_id < 0) TEST_ERROR
dset_0_id = H5Dcreate(file_id, "fullrange", dtype_id, dspace_id, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
if(dset_0_id < 0) TEST_ERROR
/* Close file and re-open with different libver bounds.
* Dataset "fullrange" must also be closed for expected reopen behavior.
*/
if(H5Fclose(file_id) < 0) TEST_ERROR;
if(H5Dclose(dset_0_id) < 0) TEST_ERROR
ret = H5Pset_libver_bounds(fapl_id, H5F_LIBVER_V18, H5F_LIBVER_LATEST);
if(ret == FAIL) TEST_ERROR;
file_id = H5Fopen(filename, H5F_ACC_RDWR, fapl_id);
if(file_id < 0) TEST_ERROR
dset_1_id = H5Dcreate(file_id, "upperrange", dtype_id, dspace_id, H5P_DEFAULT, dcpl_id, H5P_DEFAULT);
if(dset_1_id < 0) TEST_ERROR
/* re-open "fullrange" dataset
*/
dset_0_id = H5Dopen2(file_id, "fullrange", H5P_DEFAULT);
if(dset_0_id < 0) TEST_ERROR
/*********
* TESTS *
*********/
/* dset not supporting pre-1.08 should be smaller? */
if(oh_compare(dset_1_id, dset_0_id) != LT) TEST_ERROR
/************
* TEARDOWN *
************/
if(H5Sclose(dspace_id) < 0) TEST_ERROR
if(H5Tclose(dtype_id) < 0) TEST_ERROR
if(H5Pclose(dcpl_id) < 0) TEST_ERROR
if(H5Pclose(fapl_id) < 0) TEST_ERROR
if(H5Dclose(dset_0_id) < 0) TEST_ERROR
if(H5Dclose(dset_1_id) < 0) TEST_ERROR
if(H5Fclose(file_id) < 0) TEST_ERROR;
PASSED()
return SUCCEED;
error:
H5E_BEGIN_TRY {
(void)H5Sclose(dspace_id);
(void)H5Tclose(dtype_id);
(void)H5Pclose(dcpl_id);
(void)H5Pclose(fapl_id);
(void)H5Dclose(dset_0_id);
(void)H5Dclose(dset_1_id);
(void)H5Fclose(file_id);
} H5E_END_TRY;
return FAIL;
} /* test_minimized_oh_fillvalue_backwards_compatability */
/********
* MAIN *
********/
/* ---------------------------------------------------------------------------
* Main function is main. Runs tests.
*
* Returns number of failed tests.
* ---------------------------------------------------------------------------
*/
int
main(void)
{
int nerrors = 0;
HDprintf("Testing minimized dataset object headers.\n");
nerrors += test_minimized_oh_attribute_addition();
nerrors += test_minimized_oh_size_comparisons();
nerrors += test_minimized_oh_with_filter();
nerrors += test_minimized_oh_modification_times();
nerrors += test_minimized_oh_fillvalue_backwards_compatability();
if(nerrors < 0)
HDprintf("***** %d MINIMIZED DATASET OHDR TEST%s FAILED! *****\n", nerrors, nerrors > 1 ? "S" : "");
else
HDprintf("All minimized dataset object header tests passed.\n");
return nerrors;
} /* main */
|