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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 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 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 *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
*
* Purpose: Tests chunk query API functions
*
* Modification:
* Many tests were added for HDFFV-10677. -BMR, August 2019
*
* Test structure:
* main()
* test_basic_query()
* test_get_chunk_info_highest_v18()
* test_get_chunk_info_v110()
* test_chunk_info_single_chunk()
* test_chunk_info_implicit()
* test_chunk_info_fixed_array()
* test_chunk_info_extensible_array()
* test_chunk_info_version2_btrees()
* test_failed_attempts()
* test_flt_msk_with_skip_compress()
*
* Helper functions:
* verify_idx_nchunks()
* verify_get_chunk_info()
* verify_get_chunk_info_by_coord()
* verify_empty_chunk_info()
* index_type_str()
*
*/
#define H5D_FRIEND
#define H5D_TESTING /* to use H5D__ functions */
#include "H5Dpkg.h"
#include "testhdf5.h"
#ifdef H5_HAVE_FILTER_DEFLATE
#include "zlib.h"
#endif
/* Test file names, using H5F_libver_t as indices */
const char *FILENAME[] = {"tchunk_info_earliest", "tchunk_info_v18", "tchunk_info_v110",
"tchunk_info_v112", "tchunk_info_v114", NULL};
/* File to be used in test_failed_attempts */
#define FILTERMASK_FILE "tflt_msk"
#define BASIC_FILE "basic_query"
/* Parameters for testing chunk querying */
#define SIMPLE_CHUNKED_DSET_NAME "Chunked Dataset"
#define CONTIGUOUS_DSET_NAME "Contiguous Dataset"
#define EMPTY_DSET_NAME "Empty Dataset"
#define EMPTY_EARLY_ALLOC_DSET_NAME "Empty Dataset with ALLOC_TIME_EARLY"
#define SINGLE_CHUNK_DSET_NAME "Single Chunk Index Dataset"
#define IMPLICIT_INDEX_DSET_NAME "Implicit Index Dataset"
#define FIXED_ARR_INDEX_DSET_NAME "Fixed Array Index Dataset"
#define EXT_ARR_INDEX_DSET_NAME "Extensible Array Index Dataset"
#define V2_BTREE_INDEX_DSET_NAME "Version 2 B-Tree Index Dataset"
#define SKIP_FILTER_DSET_NAME "Dataset with Skipping One Filter"
#define FILENAME_BUF_SIZE 256 /* Size for file names */
#define RANK 2 /* Rank for datasets */
/* Dimension of the dataset */
#define NX 24
#define NY 16
/* Dimension of the chunk */
#define CHUNK_NX 6
#define CHUNK_NY 4
/* X/Y coords of first chunk written */
#define START_CHK_X 0
#define START_CHK_Y 2
/* X/Y coord of last chunk written */
#define END_CHK_X 2
#define END_CHK_Y 4
/* X and Y coords of an empty chunk */
#define EMPTY_CHK_X 0
#define EMPTY_CHK_Y 0
/* Size of a chunk when the entire dataset is a one single chunk */
#define SINGLE_CHK_SIZE (NX * NY * sizeof(int))
/* Size of a chunk */
#define CHK_SIZE (CHUNK_NX * CHUNK_NY * sizeof(int))
/* Size of an empty chunk */
#define EMPTY_CHK_SIZE 0
/* Number of maximum chunks without extending */
#define NUM_CHUNKS ((NX / CHUNK_NX) * (NY / CHUNK_NY))
/* Number of chunks that have been written */
#define NUM_CHUNKS_WRITTEN 4
#define ONE_CHUNK_WRITTEN 1
#define TWO_CHUNKS_WRITTEN 2
#define NO_CHUNK_WRITTEN 0
/* For testing invalid arguments */
#define NONEXIST_CHK_INDEX 3
#define OUTOFRANGE_CHK_INDEX 5
#define INVALID_CHK_INDEX 5
/* For compressed data */
#define DEFLATE_SIZE_ADJUST(s) (ceil(((double)(s)) * 1.001) + 12.0)
/* For use in error reporting */
#define MSG_CHK_ADDR "Chunk address should not be HADDR_UNDEF because of H5D_ALLOC_TIME_EARLY."
#define MSG_CHK_SIZE "Chunk size should not be 0 because of H5D_ALLOC_TIME_EARLY."
/* Utility function to initialize arguments */
void reinit_vars(unsigned *read_flt_msk, haddr_t *addr, hsize_t *size);
/* Helper function containing common code that verifies indexing type
and number of chunks */
static int verify_idx_nchunks(hid_t dset, hid_t dspace, H5D_chunk_index_t exp_idx_type,
hsize_t exp_num_chunks);
static int verify_get_chunk_info(hid_t dset, hid_t dspace, hsize_t chk_index, hsize_t exp_chk_size,
hsize_t *exp_offset, unsigned exp_flt_msk);
static int verify_get_chunk_info_by_coord(hid_t dset, hsize_t *offset, hsize_t exp_chk_size,
unsigned exp_flt_msk);
static int verify_empty_chunk_info(hid_t dset, hsize_t *offset);
static const char *index_type_str(H5D_chunk_index_t idx_type);
/*-------------------------------------------------------------------------
* Function: reinit_vars (helper function)
*
* Purpose: Wipes out variables for the next use, used in various tests.
*
* Return: Won't fail
*
* Date: September 2018
*
*-------------------------------------------------------------------------
*/
void
reinit_vars(unsigned *read_flt_msk, haddr_t *addr, hsize_t *size)
{
if (read_flt_msk)
*read_flt_msk = 0;
if (addr)
*addr = 0;
if (size)
*size = 0;
}
/*-------------------------------------------------------------------------
* Function: verify_get_chunk_info (helper function)
*
* Purpose: Verifies that H5Dget_chunk_info returns correct
* values for a chunk.
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Date: August 2019
*
*-------------------------------------------------------------------------
*/
static int
verify_get_chunk_info(hid_t dset, hid_t dspace, hsize_t chk_index, hsize_t exp_chk_size, hsize_t *exp_offset,
unsigned exp_flt_msk)
{
unsigned read_flt_msk = 0; /* Read filter mask */
hsize_t out_offset[2] = {0, 0}; /* Buffer to get offset coordinates */
hsize_t size = 0; /* Size of an allocated/written chunk */
haddr_t addr = 0; /* Address of an allocated/written chunk */
if (H5Dget_chunk_info(dset, dspace, chk_index, out_offset, &read_flt_msk, &addr, &size) < 0)
TEST_ERROR
CHECK(addr, HADDR_UNDEF, "H5Dget_chunk_info");
VERIFY(size, exp_chk_size, "H5Dget_chunk_info, chunk size");
VERIFY(read_flt_msk, exp_flt_msk, "H5Dget_chunk_info, filter mask");
VERIFY(out_offset[0], exp_offset[0], "H5Dget_chunk_info, offset[0]");
VERIFY(out_offset[1], exp_offset[1], "H5Dget_chunk_info, offset[1]");
return SUCCEED;
error:
return FAIL;
}
/*-------------------------------------------------------------------------
* Function: verify_get_chunk_info_by_coord (helper function)
*
* Purpose: Verifies that H5Dget_chunk_info_by_coord returns correct
* values for a chunk.
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Date: August 2019
*
*-------------------------------------------------------------------------
*/
static int
verify_get_chunk_info_by_coord(hid_t dset, hsize_t *offset, hsize_t exp_chk_size, unsigned exp_flt_msk)
{
unsigned read_flt_msk = 0; /* Read filter mask */
hsize_t size = 0; /* Size of an allocated/written chunk */
haddr_t addr = 0; /* Address of an allocated/written chunk */
/* Get info of the chunk at logical coordinates specified by offset */
if (H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size) < 0)
TEST_ERROR
CHECK(addr, HADDR_UNDEF, "H5Dget_chunk_info_by_coord");
VERIFY(size, exp_chk_size, "H5Dget_chunk_info_by_coord, chunk size");
VERIFY(read_flt_msk, exp_flt_msk, "H5Dget_chunk_info_by_coord, filter mask");
return SUCCEED;
error:
return FAIL;
}
/*-------------------------------------------------------------------------
* Function: verify_empty_chunk_info (helper function)
*
* Purpose: Verifies that H5Dget_chunk_info_by_coord returns correct
* values for an empty chunk.
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Date: August 2018
*
*-------------------------------------------------------------------------
*/
static int
verify_empty_chunk_info(hid_t dset, hsize_t *offset)
{
unsigned read_flt_msk = 0; /* Read filter mask */
hsize_t size = 0; /* Size of an allocated/written chunk */
haddr_t addr = 0; /* Address of an allocated/written chunk */
/* Get info of the chunk at logical coordinates specified by offset */
if (H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size) < 0)
TEST_ERROR
VERIFY(addr, HADDR_UNDEF, "H5Dget_chunk_info_by_coord, chunk address");
VERIFY(size, EMPTY_CHK_SIZE, "H5Dget_chunk_info_by_coord, chunk size");
return SUCCEED;
error:
return FAIL;
}
/*-------------------------------------------------------------------------
* Function: index_type_str (helper function)
*
* Purpose: Returns the string containing the text associated with the
* given indexing scheme. For use in error messages.
*
* Return: Success: a valid indexing scheme string
* Failure: a note indicating the indexing type is invalid
*
* Date: August 2019
*
*-------------------------------------------------------------------------
*/
static const char *
index_type_str(H5D_chunk_index_t idx_type)
{
switch (idx_type) {
case H5D_CHUNK_IDX_SINGLE:
return ("Single Chunk index type");
case H5D_CHUNK_IDX_NONE:
return ("Implicit index type");
case H5D_CHUNK_IDX_FARRAY:
return ("Fixed Array index type");
case H5D_CHUNK_IDX_EARRAY:
return ("Extensible Array index type");
case H5D_CHUNK_IDX_BT2:
return ("Version 2 B-tree index type");
case H5D_CHUNK_IDX_BTREE:
return ("Version 1 B-tree index type (default)");
case H5D_CHUNK_IDX_NTYPES:
default:
return ("invalid index type");
}
} /* index_type_str */
/*-------------------------------------------------------------------------
* Function: verify_selected_chunks (helper function)
*
* Purpose: Reads the chunks within the boundery {start,end} and verify
* the values against the populated data.
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Date: August 2019
*
*-------------------------------------------------------------------------
*/
static int
verify_selected_chunks(hid_t dset, hid_t plist, hsize_t *start, hsize_t *end)
{
int read_buf[CHUNK_NX][CHUNK_NY];
int expected_buf[NUM_CHUNKS][CHUNK_NX][CHUNK_NY]; /* Expected data */
unsigned read_flt_msk = 0; /* Filter mask read back */
hsize_t offset[2] = {0, 0}; /* Offset coordinates of a chunk */
hsize_t chk_index; /* Chunk index */
hsize_t ii, jj; /* Array indices */
int n;
HDmemset(&read_buf, 0, sizeof(read_buf));
/* Initialize the array of chunk data for all NUM_CHUNKS chunks, this is
the same as the written data and will be used to verify the read data */
for (n = 0; n < NUM_CHUNKS; n++)
for (ii = 0; ii < CHUNK_NX; ii++)
for (jj = 0; jj < CHUNK_NY; jj++)
expected_buf[n][ii][jj] = (int)(ii * jj) + 1;
/* Read each chunk within the boundery of {start,end} and verify the
values against the expected data */
chk_index = 0;
for (ii = start[0]; ii < end[0]; ii++)
for (jj = start[1]; jj < end[1]; jj++, chk_index++) {
offset[0] = ii * CHUNK_NX;
offset[1] = jj * CHUNK_NY;
/* Read the current chunk */
if (H5Dread_chunk(dset, plist, offset, &read_flt_msk, read_buf) < 0)
TEST_ERROR
/* Verify that read chunk is the same as the corresponding written one */
if (HDmemcmp(expected_buf[chk_index], read_buf, CHUNK_NX * CHUNK_NY) != 0) {
HDfprintf(stderr,
"Read chunk differs from written chunk at offset (%" PRIuHSIZE ",%" PRIuHSIZE ")\n",
offset[0], offset[1]);
return FAIL;
}
}
return SUCCEED;
error:
return FAIL;
} /* verify_selected_chunks */
/*-------------------------------------------------------------------------
* Function: write_selected_chunks (helper function)
*
* Purpose: Verifies that chunk indexing scheme and number of chunks of
* the dataset matches the expected values, then write data to
* a subset of chunks. This function opens the dataset then
* closes it after writing.
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Date: August 2019
*
*-------------------------------------------------------------------------
*/
static int
write_selected_chunks(hid_t dset, hid_t plist, hsize_t *start, hsize_t *end, unsigned flt_msk)
{
int direct_buf[NUM_CHUNKS][CHUNK_NX][CHUNK_NY]; /* Data in chunks */
hsize_t offset[2]; /* Offset coordinates of a chunk */
hsize_t chk_index; /* Chunk index */
hsize_t ii, jj; /* Array indices */
int n;
/* Initialize the array of chunk data for all NUM_CHUNKS chunks */
for (n = 0; n < NUM_CHUNKS; n++)
for (ii = 0; ii < CHUNK_NX; ii++)
for (jj = 0; jj < CHUNK_NY; jj++)
direct_buf[n][ii][jj] = (int)(ii * jj) + 1;
/* Write NUM_CHUNKS_WRITTEN chunks at the following logical coords:
(0,2) (0,3) (1,2) (1,3) */
chk_index = 0;
for (ii = start[0]; ii < end[0]; ii++)
for (jj = start[1]; jj < end[1]; jj++, chk_index++) {
offset[0] = ii * CHUNK_NX;
offset[1] = jj * CHUNK_NY;
if (H5Dwrite_chunk(dset, plist, flt_msk, offset, CHK_SIZE, (void *)direct_buf[chk_index]) < 0)
TEST_ERROR
}
return SUCCEED;
error:
return FAIL;
} /* write_selected_chunks */
/*-------------------------------------------------------------------------
* Function: verify_idx_nchunks (helper function)
*
* Purpose: Verifies that chunk indexing scheme and number of chunks of
* the dataset match the expected values.
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Date: August 2019
*
*-------------------------------------------------------------------------
*/
static int
verify_idx_nchunks(hid_t dset, hid_t dspace, H5D_chunk_index_t exp_idx_type, hsize_t exp_num_chunks)
{
H5D_chunk_index_t idx_type; /* Dataset chunk index type */
hsize_t nchunks = 0; /* Number of chunks */
/* Get the chunk indexing type of the dataset */
if (H5Dget_chunk_index_type(dset, &idx_type) < 0)
TEST_ERROR
/* Ensure the correct chunk indexing scheme is used */
if (idx_type != exp_idx_type) {
char msg[256];
HDsprintf(msg, "Should be using %s.\n", index_type_str(idx_type));
FAIL_PUTS_ERROR(msg);
}
/* Get and verify the number of chunks */
if (H5Dget_num_chunks(dset, dspace, &nchunks) < 0)
TEST_ERROR
VERIFY(nchunks, exp_num_chunks, "H5Dget_num_chunks, number of chunks");
/* Get and verify the number of chunks again, passing in H5S_ALL */
if (H5Dget_num_chunks(dset, H5S_ALL, &nchunks) < 0)
TEST_ERROR
VERIFY(nchunks, exp_num_chunks, "H5Dget_num_chunks, number of chunks");
return SUCCEED;
error:
return FAIL;
} /* verify_idx_nchunks */
/*-------------------------------------------------------------------------
* Function: test_get_chunk_info_highest_v18
*
* Purpose: Test getting various chunk information
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Note: Note that the dataspace argument in these new functions are
* currently not used. The functionality involved the dataspace
* will be implemented in the next version.
*
* Description:
* This function tests the new API functions added for EED-343:
* H5Dget_num_chunks, H5Dget_chunk_info, and
* H5Dget_chunk_info_by_coord for high bound up to 1.8.
*
* Date: September 2018
*
*-------------------------------------------------------------------------
*/
static herr_t
test_get_chunk_info_highest_v18(hid_t fapl)
{
char filename[FILENAME_BUF_SIZE]; /* File name */
hid_t chunkfile = H5I_INVALID_HID; /* File ID */
hid_t dspace = H5I_INVALID_HID; /* Dataspace ID */
hid_t dset = H5I_INVALID_HID; /* Dataset ID */
hid_t cparms = H5I_INVALID_HID; /* Creation plist */
hsize_t chunk_dims[2] = {CHUNK_NX, CHUNK_NY}; /* Chunk dimensions */
int direct_buf[CHUNK_NX][CHUNK_NY]; /* Data chunk */
hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED}; /* 2 unlimited dims */
hsize_t out_offset[2]; /* Buffer to get offset coordinates */
hsize_t size = 0; /* Size of an allocated/written chunk */
hsize_t nchunks = 0; /* Number of chunks */
haddr_t addr = 0; /* Address of an allocated/written chunk */
hsize_t chk_index = 0; /* Index of a chunk */
hsize_t dims[2] = {NX, NY}; /* Dataset dimensions */
unsigned flt_msk = 0; /* Filter mask */
unsigned read_flt_msk = 0; /* Filter mask after direct read */
int fillvalue = -1; /* Fill value */
int aggression = 9; /* Compression aggression setting */
hsize_t offset[2] = {0, 0}; /* Offset coordinates of a chunk */
#ifdef H5_HAVE_FILTER_DEFLATE
const Bytef *z_src = (const Bytef *)(direct_buf);
Bytef * z_dst; /*destination buffer */
uLongf z_dst_nbytes = (uLongf)DEFLATE_SIZE_ADJUST(CHK_SIZE);
uLong z_src_nbytes = (uLong)CHK_SIZE;
#endif /* end H5_HAVE_FILTER_DEFLATE */
void * inbuf = NULL; /* Pointer to new buffer */
hsize_t chunk_size = CHK_SIZE; /* Size of a chunk, can be compressed or not */
hsize_t ii, jj; /* Array indices */
int n; /* Used as chunk index, but int to avoid conversion warning */
herr_t ret; /* Temporary returned value for verifying failure */
TESTING("getting chunk information in file with version prior to 1.10");
/* Create the file */
h5_fixname(FILENAME[H5F_LIBVER_V18], fapl, filename, sizeof filename);
/* Set version bounds for creating the file. High bound to V18 to test
chunked dataset that use B-tree v1 structures to index chunks. */
if (H5Pset_libver_bounds(fapl, H5F_LIBVER_EARLIEST, H5F_LIBVER_V18) < 0)
TEST_ERROR
chunkfile = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl);
if (chunkfile < 0)
TEST_ERROR
/* Create the file and memory dataspace */
if ((dspace = H5Screate_simple(RANK, dims, maxdims)) < 0)
TEST_ERROR
/* Set dset creation properties with chunking, compression, and fillvalue */
if ((cparms = H5Pcreate(H5P_DATASET_CREATE)) < 0)
TEST_ERROR
if (H5Pset_chunk(cparms, RANK, chunk_dims) < 0)
TEST_ERROR
#ifdef H5_HAVE_FILTER_DEFLATE
if (H5Pset_deflate(cparms, (unsigned)aggression) < 0)
TEST_ERROR
#endif /* end H5_HAVE_FILTER_DEFLATE */
/* Set fill value */
if (H5Pset_fill_value(cparms, H5T_NATIVE_INT, &fillvalue) < 0)
TEST_ERROR
/* Create a new dataset using cparms creation properties */
dset = H5Dcreate2(chunkfile, SIMPLE_CHUNKED_DSET_NAME, H5T_NATIVE_INT, dspace, H5P_DEFAULT, cparms,
H5P_DEFAULT);
if (dset < 0)
TEST_ERROR
/* Initialize a chunk of data */
for (ii = 0; ii < CHUNK_NX; ii++)
for (jj = 0; jj < CHUNK_NY; jj++)
direct_buf[ii][jj] = (int)(ii * jj) + 1;
#ifdef H5_HAVE_FILTER_DEFLATE
/* Allocate input (compressed) buffer */
inbuf = HDmalloc(z_dst_nbytes);
/* Set chunk size to the compressed chunk size and the chunk point
to the compressed data chunk */
chunk_size = (hsize_t)z_dst_nbytes;
z_dst = (Bytef *)inbuf;
/* Perform compression from the source to the destination buffer */
ret = compress2(z_dst, &z_dst_nbytes, z_src, z_src_nbytes, aggression);
/* Check for various zlib errors */
if (Z_BUF_ERROR == ret) {
HDfprintf(stderr, "overflow");
TEST_ERROR
}
else if (Z_MEM_ERROR == ret) {
HDfprintf(stderr, "deflate memory error");
TEST_ERROR
}
else if (Z_OK != ret) {
HDfprintf(stderr, "other deflate error");
TEST_ERROR
}
#else
/* Allocate input (non-compressed) buffer */
inbuf = HDmalloc(CHK_SIZE);
HDmemcpy(inbuf, direct_buf, CHK_SIZE);
#endif /* end H5_HAVE_FILTER_DEFLATE */
/* Write only NUM_CHUNKS_WRITTEN chunks at the following logical coords:
(0,2) (0,3) (1,2) (1,3) */
n = 0;
for (ii = START_CHK_X; ii < END_CHK_X; ii++)
for (jj = START_CHK_Y; jj < END_CHK_Y; jj++, n++) {
offset[0] = ii * CHUNK_NX;
offset[1] = jj * CHUNK_NY;
ret = H5Dwrite_chunk(dset, H5P_DEFAULT, flt_msk, offset, chunk_size, (void *)inbuf);
if (ret < 0)
TEST_ERROR
}
/* Free the input buffer */
if (inbuf)
HDfree(inbuf);
if (H5Fflush(dset, H5F_SCOPE_LOCAL) < 0)
TEST_ERROR
/* Close the dataset */
if (H5Dclose(dset) < 0)
TEST_ERROR
/* ...open it again to test the chunk query functions */
if ((dset = H5Dopen2(chunkfile, SIMPLE_CHUNKED_DSET_NAME, H5P_DEFAULT)) < 0)
TEST_ERROR
/* Get and verify the number of chunks written */
if (H5Dget_num_chunks(dset, dspace, &nchunks) < 0)
TEST_ERROR
VERIFY(nchunks, NUM_CHUNKS_WRITTEN, "H5Dget_num_chunks, number of chunks");
/* Get and verify info of the last written chunk again, passing in H5S_ALL
this time */
offset[0] = 6;
offset[1] = 12;
if (verify_get_chunk_info(dset, H5S_ALL, NUM_CHUNKS_WRITTEN - 1, chunk_size, offset, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info failed\n");
/* Attempt to get info of a non-existing chunk, should fail */
chk_index = OUTOFRANGE_CHK_INDEX;
H5E_BEGIN_TRY
{
ret = H5Dget_chunk_info(dset, H5S_ALL, chk_index, out_offset, &read_flt_msk, &addr, &size);
}
H5E_END_TRY;
if (ret != FAIL)
FAIL_PUTS_ERROR(" Attempt to get info of a non-existing chunk.");
/* Attempt to get info of empty chunks, verify the returned addr and size */
offset[0] = 0;
offset[1] = 0;
if (verify_empty_chunk_info(dset, offset) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info_by_coord on empty chunk failed\n");
offset[0] = 3 * CHUNK_NX;
offset[1] = 3 * CHUNK_NY;
if (verify_empty_chunk_info(dset, offset) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info_by_coord on empty chunk failed\n");
/* Go through all written chunks, get their info and verify the values */
chk_index = 0;
for (ii = START_CHK_X; ii < END_CHK_X; ii++)
for (jj = START_CHK_Y; jj < END_CHK_Y; jj++, chk_index++) {
offset[0] = ii * CHUNK_NX;
offset[1] = jj * CHUNK_NY;
if (verify_get_chunk_info(dset, dspace, chk_index, chunk_size, offset, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info failed\n");
/* Use the same offset to pass into the next ...by_coord function */
if (verify_get_chunk_info_by_coord(dset, offset, chunk_size, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info_by_coord failed\n");
}
/* Close the first dataset */
if (H5Dclose(dset) < 0)
TEST_ERROR
/* Create an empty dataset and close it */
dset = H5Dcreate2(chunkfile, EMPTY_DSET_NAME, H5T_NATIVE_INT, dspace, H5P_DEFAULT, cparms, H5P_DEFAULT);
if (dset < 0)
TEST_ERROR
if (H5Dclose(dset) < 0)
TEST_ERROR
/* Reopen the empty dataset to verify the chunk query functions on it */
if ((dset = H5Dopen2(chunkfile, EMPTY_DSET_NAME, H5P_DEFAULT)) < 0)
TEST_ERROR
/* Verify that the number of chunks is 0 */
if (H5Dget_num_chunks(dset, dspace, &nchunks) < 0)
TEST_ERROR
VERIFY(nchunks, NO_CHUNK_WRITTEN, "H5Dget_num_chunks, number of chunks");
/* Attempt to get info of a chunk from an empty dataset, should fail */
chk_index = OUTOFRANGE_CHK_INDEX;
H5E_BEGIN_TRY
{
ret = H5Dget_chunk_info(dset, dspace, chk_index, out_offset, &read_flt_msk, &addr, &size);
}
H5E_END_TRY;
if (ret != FAIL)
FAIL_PUTS_ERROR(" Attempt to get info of a non-existing chunk.");
/* Attempt to get info of a chunk given its coords from an empty dataset,
should succeed with the returned address as HADDR_UNDEF and size as 0 */
offset[0] = EMPTY_CHK_X;
offset[1] = EMPTY_CHK_Y;
if (verify_empty_chunk_info(dset, offset) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info_by_coord on empty chunk failed\n");
if (H5Dclose(dset) < 0)
TEST_ERROR
/************************************************************************
* Test empty dataset with H5D_ALLOC_TIME_EARLY *
************************************************************************/
/* Set space allocation to early so that chunk query functions will
retrieve chunk information even though the dataset is empty */
if (H5Pset_alloc_time(cparms, H5D_ALLOC_TIME_EARLY) < 0)
TEST_ERROR
/* Create an empty dataset and close it */
dset = H5Dcreate2(chunkfile, EMPTY_EARLY_ALLOC_DSET_NAME, H5T_NATIVE_INT, dspace, H5P_DEFAULT, cparms,
H5P_DEFAULT);
if (dset < 0)
TEST_ERROR
if (H5Dclose(dset) < 0)
TEST_ERROR
/* Reopen the empty dataset to verify the chunk query functions on it */
if ((dset = H5Dopen2(chunkfile, EMPTY_EARLY_ALLOC_DSET_NAME, H5P_DEFAULT)) < 0)
TEST_ERROR
/* Verify that the number of chunks is NUM_CHUNKS */
if (H5Dget_num_chunks(dset, dspace, &nchunks) < 0)
TEST_ERROR
if (nchunks != NUM_CHUNKS)
TEST_ERROR
/* Attempt to get info of a chunk from an empty dataset, verify the
returned address and size in the case of H5D_ALLOC_TIME_EARLY */
chk_index = NONEXIST_CHK_INDEX;
reinit_vars(&read_flt_msk, &addr, &size);
ret = H5Dget_chunk_info(dset, dspace, chk_index, out_offset, &read_flt_msk, &addr, &size);
if (ret < 0)
TEST_ERROR
/* Because of H5D_ALLOC_TIME_EARLY, addr cannot be HADDR_UNDEF and size not 0 */
if (addr == HADDR_UNDEF)
TEST_ERROR
if (size == EMPTY_CHK_SIZE)
TEST_ERROR
chk_index = 10;
reinit_vars(&read_flt_msk, &addr, &size);
ret = H5Dget_chunk_info(dset, dspace, chk_index, out_offset, &read_flt_msk, &addr, &size);
if (ret < 0)
TEST_ERROR
/* Because of H5D_ALLOC_TIME_EARLY, addr cannot be HADDR_UNDEF and size not 0 */
if (addr == HADDR_UNDEF)
TEST_ERROR
if (size == EMPTY_CHK_SIZE)
TEST_ERROR
/* Attempt to get info of a chunk given its coords from an empty dataset,
verify the returned address and size */
offset[0] = 0;
offset[1] = 0;
if (H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size) < 0)
TEST_ERROR
/* Because of H5D_ALLOC_TIME_EARLY, addr cannot be HADDR_UNDEF and size not 0 */
if (addr == HADDR_UNDEF)
TEST_ERROR
if (size == 0)
TEST_ERROR
if (H5Dclose(dset) < 0)
TEST_ERROR
/* Close/release resources. */
if (H5Sclose(dspace) < 0)
TEST_ERROR
if (H5Pclose(cparms) < 0)
TEST_ERROR
if (H5Fclose(chunkfile) < 0)
TEST_ERROR
PASSED();
return SUCCEED;
error:
H5E_BEGIN_TRY
{
H5Dclose(dset);
H5Sclose(dspace);
H5Pclose(cparms);
H5Fclose(chunkfile);
}
H5E_END_TRY;
H5_FAILED();
return FAIL;
} /* test_get_chunk_info_highest_v18() */
/*-------------------------------------------------------------------------
* Function: test_chunk_info_single_chunk
*
* Purpose: Test getting various chunk information when Single Chunk
* index type is used
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Note: Note that the dataspace argument in these new functions are
* currently not used. The functionality involved the dataspace
* will be implemented in the next version.
*
* Date: November 2018
*
*-------------------------------------------------------------------------
*/
static herr_t
test_chunk_info_single_chunk(const char *filename, hid_t fapl)
{
hid_t chunkfile = H5I_INVALID_HID; /* File ID */
hid_t dspace = H5I_INVALID_HID; /* Dataspace ID */
hid_t dset = H5I_INVALID_HID; /* Dataset ID */
hid_t cparms = H5I_INVALID_HID; /* Creation plist */
hsize_t dims[2] = {NX, NY}; /* Dataset dimensions */
hsize_t chunk_dims[2] = {NX, NY}; /* Chunk dimensions */
int data_buf[NX][NY]; /* Input buffer */
H5D_chunk_index_t idx_type; /* Dataset chunk index type */
unsigned flt_msk = 0; /* Filter mask */
unsigned read_flt_msk = 0; /* Filter mask after direct read */
hsize_t offset[2]; /* Offset coordinates of a chunk */
hsize_t out_offset[2] = {0, 0}; /* Buffer to get offset coordinates */
hsize_t size = 0; /* Size of an allocated/written chunk */
hsize_t nchunks = 0; /* Number of chunks */
haddr_t addr = 0; /* Address of an allocated/written chunk */
hsize_t chk_index = 0; /* Index of a chunk */
hsize_t ii, jj; /* Array indices */
herr_t ret; /* Temporary returned value for verifying failure */
TESTING(" Single Chunk index");
/* Open the file for reading/writing */
if ((chunkfile = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
TEST_ERROR
/* Create dataspace */
if ((dspace = H5Screate_simple(RANK, dims, NULL)) < 0)
TEST_ERROR
/* Enable chunking */
if ((cparms = H5Pcreate(H5P_DATASET_CREATE)) < 0)
TEST_ERROR
if (H5Pset_chunk(cparms, RANK, chunk_dims) < 0)
TEST_ERROR
/* Create a new dataset using cparms creation properties */
dset = H5Dcreate2(chunkfile, SINGLE_CHUNK_DSET_NAME, H5T_NATIVE_INT, dspace, H5P_DEFAULT, cparms,
H5P_DEFAULT);
if (dset < 0)
TEST_ERROR
/* Close the dataset */
if (H5Dclose(dset) < 0)
TEST_ERROR
/* ...open it again to test the chunk query functions on a single empty
chunk */
if ((dset = H5Dopen2(chunkfile, SINGLE_CHUNK_DSET_NAME, H5P_DEFAULT)) < 0)
TEST_ERROR
/* Ensure the correct chunk indexing scheme is used */
if (H5Dget_chunk_index_type(dset, &idx_type) < 0)
TEST_ERROR
if (idx_type != H5D_CHUNK_IDX_SINGLE)
FAIL_PUTS_ERROR("Should be using Single Chunk index type");
/* Get the number of chunks and verify that no chunk has been written */
if (H5Dget_num_chunks(dset, dspace, &nchunks) < 0)
TEST_ERROR
if (nchunks != NO_CHUNK_WRITTEN)
TEST_ERROR
/* Initialize the array of chunk data for the single chunk */
for (ii = 0; ii < NX; ii++)
for (jj = 0; jj < NY; jj++)
data_buf[ii][jj] = (int)(ii * jj);
/* Write the chunk */
if (H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data_buf) < 0)
TEST_ERROR
/* Get and verify that one chunk had been written */
if (H5Dget_num_chunks(dset, dspace, &nchunks) < 0)
TEST_ERROR
if (nchunks != ONE_CHUNK_WRITTEN)
TEST_ERROR
/* Offset of the only chunk */
offset[0] = 0;
offset[1] = 0;
/* Get and verify info of the first and only chunk */
if (verify_get_chunk_info(dset, H5S_ALL, 0, SINGLE_CHK_SIZE, offset, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Verification H5Dget_chunk_info failed\n");
/* Get and verify info of the chunk at logical coordinates (0,0) */
if (verify_get_chunk_info_by_coord(dset, offset, SINGLE_CHK_SIZE, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info_by_coord failed\n");
/* Attempt to get chunk info given an invalid chunk index and verify
* that failure occurs */
chk_index = INVALID_CHK_INDEX;
reinit_vars(&read_flt_msk, &addr, &size);
H5E_BEGIN_TRY
{
ret = H5Dget_chunk_info(dset, dspace, chk_index, out_offset, &read_flt_msk, &addr, &size);
}
H5E_END_TRY;
if (ret != FAIL)
TEST_ERROR
/* Release resourse */
if (H5Dclose(dset) < 0)
TEST_ERROR
if (H5Sclose(dspace) < 0)
TEST_ERROR
if (H5Fclose(chunkfile) < 0)
TEST_ERROR
PASSED();
return SUCCEED;
error:
H5E_BEGIN_TRY
{
H5Dclose(dset);
H5Sclose(dspace);
H5Pclose(cparms);
H5Fclose(chunkfile);
}
H5E_END_TRY;
H5_FAILED();
return FAIL;
} /* test_chunk_info_single_chunk() */
/*-------------------------------------------------------------------------
* Function: test_chunk_info_implicit
*
* Purpose: Test getting various chunk information when Implicit
* index type is used
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Note: Note that the dataspace argument in these new functions are
* currently not used. The functionality involved the dataspace
* will be implemented in the next version.
*
* Date: November 2018
*
*-------------------------------------------------------------------------
*/
static herr_t
test_chunk_info_implicit(char *filename, hid_t fapl)
{
hid_t chunkfile = H5I_INVALID_HID; /* File ID */
hid_t dspace = H5I_INVALID_HID; /* Dataspace ID */
hid_t dset = H5I_INVALID_HID; /* Dataset ID */
hid_t cparms = H5I_INVALID_HID; /* Creation plist */
hsize_t dims[2] = {NX, NY}; /* Dataset dimensions */
hsize_t chunk_dims[2] = {CHUNK_NX, CHUNK_NY}; /* Chunk dimensions */
unsigned flt_msk = 0; /* Filter mask */
hsize_t chk_index = 0; /* Index of a chunk */
hsize_t ii, jj; /* Array indices */
hsize_t start[2] = {START_CHK_X, START_CHK_Y}; /* Start position */
hsize_t end[2] = {END_CHK_X, END_CHK_Y}; /* End position */
TESTING(" Implicit index");
/* Open the file for reading/writing */
if ((chunkfile = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
TEST_ERROR
/* Create dataspace */
if ((dspace = H5Screate_simple(RANK, dims, NULL)) < 0)
TEST_ERROR
/* Enable chunking */
if ((cparms = H5Pcreate(H5P_DATASET_CREATE)) < 0)
TEST_ERROR
if (H5Pset_chunk(cparms, RANK, chunk_dims) < 0)
TEST_ERROR
/* Set allocation time to early */
if (H5Pset_alloc_time(cparms, H5D_ALLOC_TIME_EARLY) < 0)
TEST_ERROR
/* Create a new dataset using cparms creation properties */
dset = H5Dcreate2(chunkfile, IMPLICIT_INDEX_DSET_NAME, H5T_NATIVE_INT, dspace, H5P_DEFAULT, cparms,
H5P_DEFAULT);
if (dset < 0)
TEST_ERROR
/* Close the dataset */
if (H5Dclose(dset) < 0)
TEST_ERROR
/* Open the dataset again to test getting chunk info */
if ((dset = H5Dopen2(chunkfile, IMPLICIT_INDEX_DSET_NAME, H5P_DEFAULT)) < 0)
TEST_ERROR
/* Verify chunk indexing scheme and number of chunks */
if (verify_idx_nchunks(dset, dspace, H5D_CHUNK_IDX_NONE, NUM_CHUNKS) == FAIL)
FAIL_PUTS_ERROR("Verification and write failed\n");
/* Write NUM_CHUNKS_WRITTEN chunks at the following logical coords:
(0,2) (0,3) (1,2) (1,3) */
if (write_selected_chunks(dset, H5P_DEFAULT, start, end, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Writing to selected chunks failed\n");
/* Go through all chunks, and get their info and verify the values */
chk_index = 0;
for (ii = 0; ii < NX / CHUNK_NX; ii++)
for (jj = 0; jj < NY / CHUNK_NY; jj++, chk_index++) {
hsize_t offset[2] = {ii * CHUNK_NX, jj * CHUNK_NY};
if (verify_get_chunk_info(dset, H5S_ALL, chk_index, CHK_SIZE, offset, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info failed\n");
/* Get info of a chunk and verify its information. Note that
all chunks in this dataset are allocated because of the property
H5D_ALLOC_TIME_EARLY */
if (verify_get_chunk_info_by_coord(dset, offset, CHK_SIZE, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info_by_coord failed\n");
}
/* Release resourse */
if (H5Dclose(dset) < 0)
TEST_ERROR
if (H5Sclose(dspace) < 0)
TEST_ERROR
if (H5Pclose(cparms) < 0)
TEST_ERROR
if (H5Fclose(chunkfile) < 0)
TEST_ERROR
PASSED();
return SUCCEED;
error:
H5E_BEGIN_TRY
{
H5Dclose(dset);
H5Sclose(dspace);
H5Pclose(cparms);
H5Fclose(chunkfile);
}
H5E_END_TRY;
H5_FAILED();
return FAIL;
} /* test_chunk_info_implicit() */
/*-------------------------------------------------------------------------
* Function: test_chunk_info_fixed_array
*
* Purpose: Test getting various chunk information when Fixed Array
* index type is used
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Note: Note that the dataspace argument in these new functions are
* currently not used. The functionality involved the dataspace
* will be implemented in the next version.
*
* Date: November 2018
*
*-------------------------------------------------------------------------
*/
static herr_t
test_chunk_info_fixed_array(const char *filename, hid_t fapl)
{
hid_t chunkfile = H5I_INVALID_HID; /* File ID */
hid_t dspace = H5I_INVALID_HID; /* Dataspace ID */
hid_t dset = H5I_INVALID_HID; /* Dataset ID */
hid_t cparms = H5I_INVALID_HID; /* Creation plist */
hsize_t dims[2] = {NX, NY}; /* Dataset dimensions */
hsize_t chunk_dims[2] = {CHUNK_NX, CHUNK_NY}; /* Chunk dimensions */
unsigned flt_msk = 0; /* Filter mask */
unsigned read_flt_msk = 0; /* Filter mask after direct read */
hsize_t offset[2]; /* Offset coordinates of a chunk */
hsize_t start[2] = {START_CHK_X, START_CHK_Y}; /* Start position */
hsize_t end[2] = {END_CHK_X, END_CHK_Y}; /* End position */
hsize_t out_offset[2] = {0, 0}; /* Buffer to get offset coordinates */
hsize_t size = 0; /* Size of an allocated/written chunk */
hsize_t nchunks = 0; /* Number of chunks */
haddr_t addr = 0; /* Address of an allocated/written chunk */
hsize_t chk_index = 0; /* Index of a chunk */
hsize_t ii, jj; /* Array indices */
herr_t ret; /* Temporary returned value for verifying failure */
TESTING(" Fixed Array index");
/* Open the file for reading/writing */
if ((chunkfile = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
TEST_ERROR
/* Create dataspace */
if ((dspace = H5Screate_simple(RANK, dims, NULL)) < 0)
TEST_ERROR
/* Enable chunking */
if ((cparms = H5Pcreate(H5P_DATASET_CREATE)) < 0)
TEST_ERROR
if (H5Pset_chunk(cparms, RANK, chunk_dims) < 0)
TEST_ERROR
/* Create a new dataset using cparms creation properties */
dset = H5Dcreate2(chunkfile, FIXED_ARR_INDEX_DSET_NAME, H5T_NATIVE_INT, dspace, H5P_DEFAULT, cparms,
H5P_DEFAULT);
if (dset < 0)
TEST_ERROR
/* Close the dataset */
if (H5Dclose(dset) < 0)
TEST_ERROR
/* Open the dataset again to test getting chunk info */
if ((dset = H5Dopen2(chunkfile, FIXED_ARR_INDEX_DSET_NAME, H5P_DEFAULT)) < 0)
TEST_ERROR
/* Verify chunk indexing scheme and number of chunks */
if (verify_idx_nchunks(dset, dspace, H5D_CHUNK_IDX_FARRAY, NO_CHUNK_WRITTEN) == FAIL)
FAIL_PUTS_ERROR("Verification and write failed\n");
/* Write NUM_CHUNKS_WRITTEN chunks at the following logical coords:
(0,2) (0,3) (1,2) (1,3) */
if (write_selected_chunks(dset, H5P_DEFAULT, start, end, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Writing to selected chunks failed\n");
/* Get and verify the number of chunks written */
if (H5Dget_num_chunks(dset, dspace, &nchunks) < 0)
TEST_ERROR
VERIFY(nchunks, NUM_CHUNKS_WRITTEN, "H5Dget_num_chunks, number of chunks");
/* Get and verify info of each written chunk */
chk_index = 0;
for (ii = START_CHK_X; ii < END_CHK_X; ii++)
for (jj = START_CHK_Y; jj < END_CHK_Y; jj++, chk_index++) {
offset[0] = ii * CHUNK_NX;
offset[1] = jj * CHUNK_NY;
if (verify_get_chunk_info(dset, dspace, chk_index, CHK_SIZE, offset, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info failed\n");
}
/* Attempt to get info using an out-of-range index, chk_index is now > NUM_CHUNKS_WRITTEN. should fail */
H5E_BEGIN_TRY
{
ret = H5Dget_chunk_info(dset, dspace, chk_index, out_offset, &read_flt_msk, &addr, &size);
}
H5E_END_TRY;
if (ret != FAIL)
FAIL_PUTS_ERROR(" Attempted to get info of a chunk using an out-of-range index.");
/* Attempt to get info of empty chunks, verify the returned address and size */
offset[0] = 0;
offset[1] = 0;
if (verify_empty_chunk_info(dset, offset) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info_by_coord on empty chunk failed\n");
offset[0] = 3 * CHUNK_NX;
offset[1] = 3 * CHUNK_NY;
if (verify_empty_chunk_info(dset, offset) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info_by_coord on empty chunk failed\n");
/* Read and verify values of selected chunks */
if (verify_selected_chunks(dset, H5P_DEFAULT, start, end) < 0)
/* Release resourse */
if (H5Dclose(dset) < 0)
TEST_ERROR
if (H5Sclose(dspace) < 0)
TEST_ERROR
if (H5Fclose(chunkfile) < 0)
TEST_ERROR
PASSED();
return SUCCEED;
error:
H5E_BEGIN_TRY
{
H5Dclose(dset);
H5Sclose(dspace);
H5Pclose(cparms);
H5Fclose(chunkfile);
}
H5E_END_TRY;
H5_FAILED();
return FAIL;
} /* test_chunk_info_fixed_array() */
/*-------------------------------------------------------------------------
* Function: test_chunk_info_extensible_array
*
* Purpose: Test getting various chunk information when Extensible Array
* index type is used
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Note: Note that the dataspace argument in these new functions are
* currently not used. The functionality involved the dataspace
* will be implemented in the next version.
*
* Date: November 2018
*
*-------------------------------------------------------------------------
*/
static herr_t
test_chunk_info_extensible_array(const char *filename, hid_t fapl)
{
hid_t chunkfile = H5I_INVALID_HID; /* File ID */
hid_t dspace = H5I_INVALID_HID; /* Dataspace ID */
hid_t dset = H5I_INVALID_HID; /* Dataset ID */
hid_t cparms = H5I_INVALID_HID; /* Creation plist */
hsize_t dims[2] = {NX, NY}; /* Dataset dimensions */
hsize_t chunk_dims[2] = {CHUNK_NX, CHUNK_NY}; /* Chunk dimensions */
hsize_t maxdims[2] = {H5S_UNLIMITED, NY}; /* One unlimited dimension */
unsigned flt_msk = 0; /* Filter mask */
unsigned read_flt_msk = 0; /* Filter mask after direct read */
hsize_t offset[2]; /* Offset coordinates of a chunk */
hsize_t start[2] = {START_CHK_X, START_CHK_Y}; /* Start position */
hsize_t end[2] = {END_CHK_X, END_CHK_Y}; /* End position */
hsize_t out_offset[2] = {0, 0}; /* Buffer to get offset coordinates */
hsize_t size = 0; /* Size of an allocated/written chunk */
hsize_t nchunks = 0; /* Number of chunks */
haddr_t addr = 0; /* Address of an allocated/written chunk */
hsize_t chk_index = 0; /* Index of a chunk */
hsize_t ii, jj; /* Array indices */
herr_t ret; /* Temporary returned value for verifying failure */
TESTING(" Extensible Array index");
/* Open the file for reading/writing */
if ((chunkfile = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
TEST_ERROR
/* Create dataspace */
if ((dspace = H5Screate_simple(RANK, dims, maxdims)) < 0)
TEST_ERROR
/* Enable chunking */
if ((cparms = H5Pcreate(H5P_DATASET_CREATE)) < 0)
TEST_ERROR
if (H5Pset_chunk(cparms, RANK, chunk_dims) < 0)
TEST_ERROR
/* Create a new dataset using cparms creation properties */
dset = H5Dcreate2(chunkfile, EXT_ARR_INDEX_DSET_NAME, H5T_NATIVE_INT, dspace, H5P_DEFAULT, cparms,
H5P_DEFAULT);
if (dset < 0)
TEST_ERROR
/* Close the dataset */
if (H5Dclose(dset) < 0)
TEST_ERROR
/* Open the dataset again to test getting chunk info */
if ((dset = H5Dopen2(chunkfile, EXT_ARR_INDEX_DSET_NAME, H5P_DEFAULT)) < 0)
TEST_ERROR
/* Verify chunk indexing scheme and number of chunks */
if (verify_idx_nchunks(dset, dspace, H5D_CHUNK_IDX_EARRAY, NO_CHUNK_WRITTEN) == FAIL)
FAIL_PUTS_ERROR("Verification and write failed\n");
/* Write NUM_CHUNKS_WRITTEN chunks at the following logical coords:
(0,2) (0,3) (1,2) (1,3) */
if (write_selected_chunks(dset, H5P_DEFAULT, start, end, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Writing to selected chunks failed\n");
/* Get and verify the number of chunks written */
if (H5Dget_num_chunks(dset, dspace, &nchunks) < 0)
TEST_ERROR
VERIFY(nchunks, NUM_CHUNKS_WRITTEN, "H5Dget_num_chunks, number of chunks");
/* Get and verify info of each written chunk */
chk_index = 0;
for (ii = START_CHK_X; ii < END_CHK_X; ii++)
for (jj = START_CHK_Y; jj < END_CHK_Y; jj++, chk_index++) {
offset[0] = ii * CHUNK_NX;
offset[1] = jj * CHUNK_NY;
if (verify_get_chunk_info(dset, dspace, chk_index, CHK_SIZE, offset, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info failed\n");
if (verify_get_chunk_info_by_coord(dset, offset, CHK_SIZE, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info_by_coord failed\n");
}
/* Attempt to get info using an out-of-range index, should fail */
chk_index = OUTOFRANGE_CHK_INDEX;
H5E_BEGIN_TRY
{
ret = H5Dget_chunk_info(dset, dspace, chk_index, out_offset, &read_flt_msk, &addr, &size);
}
H5E_END_TRY;
if (ret != FAIL)
FAIL_PUTS_ERROR(" Attempted to get info of a chunk using an out-of-range index.");
/* Attempt to get info of empty chunks, verify the returned address and size */
offset[0] = 0;
offset[1] = 0;
if (verify_empty_chunk_info(dset, offset) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info_by_coord on empty chunk failed\n");
offset[0] = 3 * CHUNK_NX;
offset[1] = 3 * CHUNK_NY;
if (verify_empty_chunk_info(dset, offset) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info_by_coord on empty chunk failed\n");
/* Read and verify values of selected chunks */
if (verify_selected_chunks(dset, H5P_DEFAULT, start, end) < 0)
/* Release resourse */
if (H5Dclose(dset) < 0)
TEST_ERROR
if (H5Sclose(dspace) < 0)
TEST_ERROR
if (H5Fclose(chunkfile) < 0)
TEST_ERROR
PASSED();
return SUCCEED;
error:
H5E_BEGIN_TRY
{
H5Dclose(dset);
H5Sclose(dspace);
H5Pclose(cparms);
H5Fclose(chunkfile);
}
H5E_END_TRY;
H5_FAILED();
return FAIL;
} /* test_chunk_info_extensible_array() */
/*-------------------------------------------------------------------------
* Function: test_chunk_info_version2_btrees
*
* Purpose: Test getting various chunk information when Version 2 B-trees
* index type is used
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Note: Note that the dataspace argument in these new functions are
* currently not used. The functionality involved the dataspace
* will be implemented in the next version.
*
* Date: November 2018
*
*-------------------------------------------------------------------------
*/
static herr_t
test_chunk_info_version2_btrees(const char *filename, hid_t fapl)
{
hid_t chunkfile = H5I_INVALID_HID; /* File ID */
hid_t dspace = H5I_INVALID_HID; /* Dataspace ID */
hid_t dset = H5I_INVALID_HID; /* Dataset ID */
hid_t cparms = H5I_INVALID_HID; /* Creation plist */
hsize_t dims[2] = {NX, NY}; /* Dataset dimensions */
hsize_t chunk_dims[2] = {CHUNK_NX, CHUNK_NY}; /* Chunk dimensions */
hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED}; /* Two unlimited dims */
unsigned flt_msk = 0; /* Filter mask */
unsigned read_flt_msk = 0; /* Filter mask after direct read */
hsize_t offset[2]; /* Offset coordinates of a chunk */
hsize_t start[2] = {START_CHK_X, START_CHK_Y}; /* Start position */
hsize_t end[2] = {END_CHK_X, END_CHK_Y}; /* End position */
hsize_t out_offset[2] = {0, 0}; /* Buffer to get offset coordinates */
hsize_t size = 0; /* Size of an allocated/written chunk */
hsize_t nchunks = 0; /* Number of chunks */
haddr_t addr = 0; /* Address of an allocated/written chunk */
hsize_t chk_index = 0; /* Index of a chunk */
hsize_t ii, jj; /* Array indices */
herr_t ret; /* Temporary returned value for verifying failure */
TESTING(" Version 2 B-trees index");
/* Open the file for reading/writing */
if ((chunkfile = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
TEST_ERROR
/* Create dataspace */
if ((dspace = H5Screate_simple(RANK, dims, maxdims)) < 0)
TEST_ERROR
/* Enable chunking */
if ((cparms = H5Pcreate(H5P_DATASET_CREATE)) < 0)
TEST_ERROR
if (H5Pset_chunk(cparms, RANK, chunk_dims) < 0)
TEST_ERROR
/* Create a new dataset using cparms creation properties */
dset = H5Dcreate2(chunkfile, V2_BTREE_INDEX_DSET_NAME, H5T_NATIVE_INT, dspace, H5P_DEFAULT, cparms,
H5P_DEFAULT);
if (dset < 0)
TEST_ERROR
/* Close the dataset */
if (H5Dclose(dset) < 0)
TEST_ERROR
/* Open the dataset again to test getting chunk info */
if ((dset = H5Dopen2(chunkfile, V2_BTREE_INDEX_DSET_NAME, H5P_DEFAULT)) < 0)
TEST_ERROR
/* Verify chunk indexing scheme and number of chunks */
if (verify_idx_nchunks(dset, dspace, H5D_CHUNK_IDX_BT2, NO_CHUNK_WRITTEN) == FAIL)
FAIL_PUTS_ERROR("Verification and write failed\n");
/* Write NUM_CHUNKS_WRITTEN chunks at the following logical coords:
(0,2) (0,3) (1,2) (1,3) */
if (write_selected_chunks(dset, H5P_DEFAULT, start, end, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Writing to selected chunks failed\n");
/* Get and verify the number of chunks written */
if (H5Dget_num_chunks(dset, dspace, &nchunks) < 0)
TEST_ERROR
VERIFY(nchunks, NUM_CHUNKS_WRITTEN, "H5Dget_num_chunks, number of chunks");
/* Go through all written chunks, get their info and verify the values */
chk_index = 0;
for (ii = START_CHK_X; ii < END_CHK_X; ii++)
for (jj = START_CHK_Y; jj < END_CHK_Y; jj++, chk_index++) {
offset[0] = ii * CHUNK_NX;
offset[1] = jj * CHUNK_NY;
if (verify_get_chunk_info(dset, dspace, chk_index, CHK_SIZE, offset, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info failed\n");
if (verify_get_chunk_info_by_coord(dset, offset, CHK_SIZE, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info_by_coord failed\n");
}
/* Attempt to provide out-of-range offsets, should fail */
chk_index = OUTOFRANGE_CHK_INDEX;
H5E_BEGIN_TRY
{
ret = H5Dget_chunk_info(dset, dspace, chk_index, out_offset, &read_flt_msk, &addr, &size);
}
H5E_END_TRY;
if (ret != FAIL)
FAIL_PUTS_ERROR(" Attempted to get info of a chunk using an out-of-range index.");
/* Attempt to get info of empty chunks, verify the returned address and size */
offset[0] = 0;
offset[1] = 0;
if (verify_empty_chunk_info(dset, offset) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info_by_coord on empty chunk failed\n");
offset[0] = 3 * CHUNK_NX;
offset[1] = 3 * CHUNK_NY;
if (verify_empty_chunk_info(dset, offset) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info_by_coord on empty chunk failed\n");
/* Read and verify values of selected chunks */
if (verify_selected_chunks(dset, H5P_DEFAULT, start, end) < 0)
/* Release resourse */
if (H5Dclose(dset) < 0)
TEST_ERROR
if (H5Sclose(dspace) < 0)
TEST_ERROR
if (H5Fclose(chunkfile) < 0)
TEST_ERROR
PASSED();
return SUCCEED;
error:
H5E_BEGIN_TRY
{
H5Dclose(dset);
H5Sclose(dspace);
H5Pclose(cparms);
H5Fclose(chunkfile);
}
H5E_END_TRY;
H5_FAILED();
return FAIL;
} /* test_chunk_info_version2_btrees() */
/*-------------------------------------------------------------------------
* Function: test_basic_query
*
* Purpose: Tests basic operations to ensure the chunk query functions
* work properly.
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Note: Note that the dataspace argument in these new functions are
* currently not used. The functionality involved the dataspace
* will be implemented in the next version.
*
* Date: August 2019
*
*-------------------------------------------------------------------------
*/
static herr_t
test_basic_query(hid_t fapl)
{
char filename[FILENAME_BUF_SIZE]; /* File name */
hid_t basicfile = H5I_INVALID_HID; /* File ID */
hid_t dspace = H5I_INVALID_HID; /* Dataspace ID */
hid_t dset = H5I_INVALID_HID; /* Dataset ID */
hid_t cparms = H5I_INVALID_HID; /* Creation plist */
hsize_t dims[2] = {NX, NY}; /* Dataset dimensions */
hsize_t chunk_dims[2] = {CHUNK_NX, CHUNK_NY}; /* Chunk dimensions */
int direct_buf[CHUNK_NX][CHUNK_NY]; /* Data in chunks */
unsigned flt_msk = 0; /* Filter mask */
unsigned read_flt_msk = 0; /* Filter mask after direct read */
hsize_t offset[2]; /* Offset coordinates of a chunk */
hsize_t out_offset[2] = {0, 0}; /* Buffer to get offset coordinates */
hsize_t size = 0; /* Size of an allocated/written chunk */
hsize_t nchunks = 0; /* Number of chunks */
haddr_t addr = 0; /* Address of an allocated/written chunk */
hsize_t chk_index = 0; /* Index of a chunk */
hsize_t ii, jj; /* Array indices */
herr_t ret; /* Temporary returned value for verifying failure */
TESTING("basic operations");
/* Create the file */
h5_fixname(BASIC_FILE, fapl, filename, sizeof filename);
/* Create a new file. */
if ((basicfile = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
TEST_ERROR;
/* Create dataspace */
if ((dspace = H5Screate_simple(RANK, dims, NULL)) < 0)
TEST_ERROR
/* Enable chunking */
if ((cparms = H5Pcreate(H5P_DATASET_CREATE)) < 0)
TEST_ERROR
if (H5Pset_chunk(cparms, RANK, chunk_dims) < 0)
TEST_ERROR
/* Create a new dataset using cparms creation properties */
dset = H5Dcreate2(basicfile, SIMPLE_CHUNKED_DSET_NAME, H5T_NATIVE_INT, dspace, H5P_DEFAULT, cparms,
H5P_DEFAULT);
if (dset < 0)
TEST_ERROR
/* Get the number of chunks and verify that no chunk has been written */
if (H5Dget_num_chunks(dset, dspace, &nchunks) < 0)
TEST_ERROR
VERIFY(nchunks, NO_CHUNK_WRITTEN, "H5Dget_num_chunks, number of chunks");
/* Initialize the array of chunk data for the single chunk */
for (ii = 0; ii < CHUNK_NX; ii++)
for (jj = 0; jj < CHUNK_NY; jj++)
direct_buf[ii][jj] = (int)(ii * jj);
/* Write the chunk of data */
offset[0] = CHUNK_NX;
offset[1] = CHUNK_NY;
if (H5Dwrite_chunk(dset, H5P_DEFAULT, flt_msk, offset, CHK_SIZE, direct_buf) < 0)
TEST_ERROR;
/* Get and verify that one chunk had been written */
if (H5Dget_num_chunks(dset, dspace, &nchunks) < 0)
TEST_ERROR
VERIFY(nchunks, ONE_CHUNK_WRITTEN, "H5Dget_num_chunks, number of chunks");
/* Get and verify info of the first and only chunk */
if (verify_get_chunk_info(dset, H5S_ALL, 0, CHK_SIZE, offset, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Verification H5Dget_chunk_info failed\n");
/* Get and verify info of the chunk at the offset (CHUNK_NX,CHUNK_NY) */
if (verify_get_chunk_info_by_coord(dset, offset, CHK_SIZE, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info_by_coord failed\n");
/* Attempt to get chunk info given an invalid chunk index and verify
* that failure occurs */
chk_index = INVALID_CHK_INDEX;
reinit_vars(&read_flt_msk, &addr, &size);
H5E_BEGIN_TRY
{
ret = H5Dget_chunk_info(dset, dspace, chk_index, out_offset, &read_flt_msk, &addr, &size);
}
H5E_END_TRY;
if (ret != FAIL)
TEST_ERROR
/* Write the chunk of data to another location */
offset[0] = 0;
offset[1] = 0;
if (H5Dwrite_chunk(dset, H5P_DEFAULT, flt_msk, offset, CHK_SIZE, direct_buf) < 0)
TEST_ERROR;
/* Get and verify that two chunks had been written */
if (H5Dget_num_chunks(dset, dspace, &nchunks) < 0)
TEST_ERROR
VERIFY(nchunks, TWO_CHUNKS_WRITTEN, "H5Dget_num_chunks, number of chunks");
/* Get and verify info of the first written chunk in the dataset, its
offset should be (0,0) */
if (verify_get_chunk_info(dset, H5S_ALL, 0, CHK_SIZE, offset, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Verification H5Dget_chunk_info failed\n");
/* Get and verify info of the chunk at the offset (0,0) */
if (verify_get_chunk_info_by_coord(dset, offset, CHK_SIZE, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info_by_coord failed\n");
/* Get and verify info of the second written chunk in the dataset, its
offset should be (CHUNK_NX, CHUNK_NY) */
offset[0] = CHUNK_NX;
offset[1] = CHUNK_NY;
if (verify_get_chunk_info(dset, H5S_ALL, 1, CHK_SIZE, offset, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Verification H5Dget_chunk_info failed\n");
/* Get and verify info of the chunk at the offset (CHUNK_NX, CHUNK_NY) */
if (verify_get_chunk_info_by_coord(dset, offset, CHK_SIZE, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info_by_coord failed\n");
/* Get and verify info of an empty chunk, at offset
(2*CHUNK_NX, 2*CHUNK_NY) */
offset[0] = 2 * CHUNK_NX;
offset[1] = 2 * CHUNK_NY;
/* Get and verify info of the chunk at the offset (CHUNK_NX, CHUNK_NY) */
if (verify_empty_chunk_info(dset, offset) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info_by_coord on empty chunk failed\n");
/* Release resourse */
if (H5Dclose(dset) < 0)
TEST_ERROR
if (H5Sclose(dspace) < 0)
TEST_ERROR
if (H5Pclose(cparms) < 0)
TEST_ERROR
if (H5Fclose(basicfile) < 0)
TEST_ERROR
/* Remove the test file */
HDremove(filename);
PASSED();
return SUCCEED;
error:
H5E_BEGIN_TRY
{
H5Dclose(dset);
H5Sclose(dspace);
H5Pclose(cparms);
H5Fclose(basicfile);
}
H5E_END_TRY;
H5_FAILED();
return FAIL;
} /* test_basic_query() */
/*-------------------------------------------------------------------------
* Function: test_failed_attempts
*
* Purpose: Test attempting to use chunk query functions incorrectly.
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Note: Note that the dataspace argument in these new functions are
* currently not used. The functionality involved the dataspace
* will be implemented in the next version.
*
* Date: August 2019
*
*-------------------------------------------------------------------------
*/
static herr_t
test_failed_attempts(const char *filename, hid_t fapl)
{
hid_t chunkfile = H5I_INVALID_HID; /* File ID */
hid_t dspace = H5I_INVALID_HID; /* Dataspace ID */
hid_t dset = H5I_INVALID_HID; /* Dataset ID */
hsize_t dims[2] = {NX, NY}; /* Dataset dimensions */
int data_buf[NX][NY]; /* Input buffer */
unsigned read_flt_msk = 0; /* Filter mask after direct read */
hsize_t offset[2]; /* Offset coordinates of a chunk */
hsize_t out_offset[2] = {0, 0}; /* Buffer to get offset coordinates */
hsize_t size = 0; /* Size of an allocated/written chunk */
hsize_t nchunks = 0; /* Number of chunks */
haddr_t addr = 0; /* Address of an allocated/written chunk */
hsize_t chk_index = 0; /* Index of a chunk */
hsize_t ii, jj; /* Array indices */
herr_t ret; /* Temporary returned value for verifying failure */
TESTING(" Invalid Operations");
/* Open the file for reading/writing */
if ((chunkfile = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
TEST_ERROR
/* Create dataspace */
if ((dspace = H5Screate_simple(RANK, dims, NULL)) < 0)
TEST_ERROR
/* Create a contiguous dataset */
dset = H5Dcreate2(chunkfile, CONTIGUOUS_DSET_NAME, H5T_NATIVE_INT, dspace, H5P_DEFAULT, H5P_DEFAULT,
H5P_DEFAULT);
if (dset < 0)
TEST_ERROR
/* Initialize the array of data */
for (ii = 0; ii < NX; ii++)
for (jj = 0; jj < NY; jj++)
data_buf[ii][jj] = (int)(ii * jj);
/* Write the data */
if (H5Dwrite(dset, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data_buf) < 0)
TEST_ERROR
/* Close the dataset */
if (H5Dclose(dset) < 0)
TEST_ERROR
/* Open it again to test the chunk query functions on contiguous dataset */
if ((dset = H5Dopen2(chunkfile, CONTIGUOUS_DSET_NAME, H5P_DEFAULT)) < 0)
TEST_ERROR
/* Attempt to get the number of chunks on contiguous dataset, should fail */
H5E_BEGIN_TRY { ret = H5Dget_num_chunks(dset, dspace, &nchunks); }
H5E_END_TRY;
if (ret != FAIL)
FAIL_PUTS_ERROR(" Attempt a chunk query function on a contiguous dataset.")
/* Attempt to get chunk info on contiguous data, should fail */
chk_index = 0;
reinit_vars(&read_flt_msk, &addr, &size);
H5E_BEGIN_TRY
{
ret = H5Dget_chunk_info(dset, dspace, chk_index, out_offset, &read_flt_msk, &addr, &size);
}
H5E_END_TRY;
if (ret != FAIL)
FAIL_PUTS_ERROR(" Attempt a chunk query function on a contiguous dataset.")
/* Attempt to get chunk info at logical coordinates (0,0) on contiguous
* dataset, should fail */
offset[0] = 0;
offset[1] = 0;
H5E_BEGIN_TRY { ret = H5Dget_chunk_info_by_coord(dset, offset, &read_flt_msk, &addr, &size); }
H5E_END_TRY;
if (ret != FAIL)
FAIL_PUTS_ERROR(" Attempt a chunk query function on a contiguous dataset.")
/* Release resourse */
if (H5Dclose(dset) < 0)
TEST_ERROR
if (H5Sclose(dspace) < 0)
TEST_ERROR
if (H5Fclose(chunkfile) < 0)
TEST_ERROR
PASSED();
return SUCCEED;
error:
H5E_BEGIN_TRY
{
H5Dclose(dset);
H5Sclose(dspace);
H5Fclose(chunkfile);
}
H5E_END_TRY;
H5_FAILED();
return FAIL;
} /* test_failed_attempts() */
/*-------------------------------------------------------------------------
* Function: test_get_chunk_info_v110
*
* Purpose: Test getting various chunk information in version 1.10.
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Note: Note that the dataspace argument in these new functions are
* currently not used. The functionality involved the dataspace
* will be implemented in the next version.
*
* Description:
* This function tests the new API functions added for HDFFV-10677:
* H5Dget_num_chunks, H5Dget_chunk_info, and
* H5Dget_chunk_info_by_coord for low bound beyond 1.8.
*
* Date: October 2018
*
*-------------------------------------------------------------------------
*/
static herr_t
test_get_chunk_info_v110(hid_t fapl)
{
char filename[FILENAME_BUF_SIZE]; /* File name */
hid_t chunkfile = H5I_INVALID_HID; /* File ID */
H5F_libver_t low, high; /* File format bounds */
TESTING("getting chunk information in file with versions 1.10 and later");
HDprintf("\n"); /* to list sub-tests */
/* Set high bound to the current latest version */
high = H5F_LIBVER_LATEST;
/* Test getting info of chunked datasets in version combo up to 1.10 */
for (low = H5F_LIBVER_V110; low <= H5F_LIBVER_LATEST; low++) {
/* Set version bounds for creating file */
if (H5Pset_libver_bounds(fapl, low, high) < 0)
TEST_ERROR
/* Create the file */
h5_fixname(FILENAME[low], fapl, filename, sizeof filename);
chunkfile = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
if (chunkfile < 0)
TEST_ERROR
/* Close the file, individual tests will re-open the file with different
libvers via the fapl */
if (H5Fclose(chunkfile) < 0)
TEST_ERROR
/* Test getting chunk info when Single Chunk index type is used */
if (test_chunk_info_single_chunk(filename, fapl) < 0)
TEST_ERROR
/* Test getting chunk info when Implicit index type is used */
if (test_chunk_info_implicit(filename, fapl) < 0)
TEST_ERROR
/* Test getting chunk info when Fixed Array index type is used */
if (test_chunk_info_fixed_array(filename, fapl) < 0)
TEST_ERROR
/* Test getting chunk info when Extensible Array index type is used */
if (test_chunk_info_extensible_array(filename, fapl) < 0)
TEST_ERROR
/* Test getting chunk info when Version 2 B-trees index type is used */
if (test_chunk_info_version2_btrees(filename, fapl) < 0)
TEST_ERROR
/* Test various attempts to use the functions incorrectly */
if (test_failed_attempts(filename, fapl) < 0)
TEST_ERROR
} /* for low libver bound */
return SUCCEED;
error:
H5_FAILED();
return FAIL;
} /* test_get_chunk_info_v110() */
/*-------------------------------------------------------------------------
* Function: test_flt_msk_with_skip_compress
*
* Purpose: Test getting chunk info when compression filter is skipped.
*
* Return: Success: SUCCEED
* Failure: FAIL
*
* Date: August 2019 (based on direct_chunk.c/test_skip_compress_write1)
*
*-------------------------------------------------------------------------
*/
static herr_t
test_flt_msk_with_skip_compress(hid_t fapl)
{
char filename[FILENAME_BUF_SIZE]; /* File name */
hid_t filter_file = H5I_INVALID_HID; /* File ID for filter mask */
hid_t dspace = H5I_INVALID_HID; /* Dataspace ID */
hid_t mem_space = H5I_INVALID_HID; /* Dataspace ID */
hid_t dset = H5I_INVALID_HID; /* Dataset ID */
hid_t cparms = H5I_INVALID_HID; /* Creation plist */
hid_t dxpl = H5I_INVALID_HID; /* Transfer plist */
hsize_t dims[2] = {NX, NY}; /* Dataset dimensions */
hsize_t maxdims[2] = {H5S_UNLIMITED, H5S_UNLIMITED}; /* 2 unlimited dims */
hsize_t chunk_dims[2] = {CHUNK_NX, CHUNK_NY}; /* Chunk dimensions */
int direct_buf[CHUNK_NX][CHUNK_NY]; /* One chunk of data */
int check_chunk[CHUNK_NX][CHUNK_NY]; /* Buffer to read data in */
int read_direct_buf[CHUNK_NX][CHUNK_NY]; /* Buffer to read a chunk */
hsize_t read_buf_size = 0; /* buf size */
unsigned flt_msk = 0; /* Filter mask */
unsigned read_flt_msk = 0; /* Filter mask after direct read */
hsize_t offset[2] = {0, 0}; /* Offset coordinates of a chunk */
hsize_t nchunks = 0; /* Number of chunks */
hsize_t chk_index = 0; /* Index of a chunk */
int aggression = 9; /* Compression aggression setting */
hsize_t start[2]; /* Start of hyperslab */
hsize_t stride[2]; /* Stride of hyperslab */
hsize_t count[2]; /* Block count */
hsize_t block[2]; /* Block sizes */
int ii, jj; /* Array indices */
TESTING("getting filter mask when compression filter is skipped");
/* Create the file */
h5_fixname(FILTERMASK_FILE, fapl, filename, sizeof filename);
/* Create a new file. */
if ((filter_file = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT)) < 0)
TEST_ERROR;
/* Create file data space with unlimited dimensions. */
if ((dspace = H5Screate_simple(RANK, dims, maxdims)) < 0)
TEST_ERROR;
/* Create memory data space. */
if ((mem_space = H5Screate_simple(RANK, chunk_dims, NULL)) < 0)
TEST_ERROR;
/* Create dataset create property list with chunking and compression
enabled. */
if ((cparms = H5Pcreate(H5P_DATASET_CREATE)) < 0)
TEST_ERROR;
if (H5Pset_chunk(cparms, RANK, chunk_dims) < 0)
TEST_ERROR;
if (H5Pset_deflate(cparms, (unsigned)aggression) < 0)
TEST_ERROR;
/* Create a new dataset using cparms creation properties. */
if ((dset = H5Dcreate2(filter_file, SKIP_FILTER_DSET_NAME, H5T_NATIVE_INT, dspace, H5P_DEFAULT, cparms,
H5P_DEFAULT)) < 0)
TEST_ERROR;
/* Create transfer property list for writing */
if ((dxpl = H5Pcreate(H5P_DATASET_XFER)) < 0)
TEST_ERROR;
/* Initialize data for one chunk */
for (ii = 0; ii < CHUNK_NX; ii++)
for (jj = 0; jj < CHUNK_NY; jj++)
direct_buf[ii][jj] = (int)(ii * jj);
/* Indicate the compression filter is to be skipped. */
flt_msk = 0x00000001;
/* Write a chunk of uncompressed data */
offset[0] = CHUNK_NX;
offset[1] = CHUNK_NY;
if (H5Dwrite_chunk(dset, H5P_DEFAULT, flt_msk, offset, CHK_SIZE, direct_buf) < 0)
TEST_ERROR;
if (H5Fflush(dset, H5F_SCOPE_LOCAL) < 0)
TEST_ERROR;
/* Close and re-open the dataset */
if (H5Dclose(dset) < 0)
TEST_ERROR;
if ((dset = H5Dopen2(filter_file, SKIP_FILTER_DSET_NAME, H5P_DEFAULT)) < 0)
TEST_ERROR;
/* Select hyperslab for the chunk just written in the file */
start[0] = CHUNK_NX;
start[1] = CHUNK_NY;
stride[0] = 1;
stride[1] = 1;
count[0] = 1;
count[1] = 1;
block[0] = CHUNK_NX;
block[1] = CHUNK_NY;
if (H5Sselect_hyperslab(dspace, H5S_SELECT_SET, start, stride, count, block) < 0)
TEST_ERROR;
/* Read the chunk back */
if (H5Dread(dset, H5T_NATIVE_INT, mem_space, dspace, H5P_DEFAULT, check_chunk) < 0)
TEST_ERROR;
/* Check that the values read are the same as the values written */
for (ii = 0; ii < CHUNK_NX; ii++)
for (jj = 0; jj < CHUNK_NY; jj++)
if (direct_buf[ii][jj] != check_chunk[ii][jj]) {
HDprintf(" 1. Read different values than written.");
HDprintf(" At index %d,%d\n", ii, jj);
HDprintf(" direct_buf=%d, check_chunk=%d\n", direct_buf[ii][jj], check_chunk[ii][jj]);
TEST_ERROR;
}
/* Query chunk storage size */
if (H5Dget_chunk_storage_size(dset, offset, &read_buf_size) < 0)
TEST_ERROR;
if (read_buf_size != CHK_SIZE)
TEST_ERROR;
/* Read the raw chunk back with H5Dread_chunk */
HDmemset(&read_direct_buf, 0, sizeof(read_direct_buf));
if (H5Dread_chunk(dset, H5P_DEFAULT, offset, &read_flt_msk, read_direct_buf) < 0)
TEST_ERROR;
if (read_flt_msk != flt_msk)
TEST_ERROR;
/* Check that the direct chunk read is the same as the chunk written */
for (ii = 0; ii < CHUNK_NX; ii++)
for (jj = 0; jj < CHUNK_NY; jj++)
if (direct_buf[ii][jj] != read_direct_buf[ii][jj]) {
HDprintf(" 1. Read different values than written.");
HDprintf(" At index %d,%d\n", ii, jj);
HDprintf(" direct_buf=%d, read_direct_buf=%d\n", direct_buf[ii][jj],
read_direct_buf[ii][jj]);
TEST_ERROR;
}
/* Get and verify the number of chunks written */
if (H5Dget_num_chunks(dset, H5S_ALL, &nchunks) < 0)
TEST_ERROR
VERIFY(nchunks, ONE_CHUNK_WRITTEN, "H5Dget_num_chunks, number of chunks");
/* Get and verify info of the first and only chunk */
chk_index = 0;
offset[0] = CHUNK_NX;
offset[1] = CHUNK_NY;
if (verify_get_chunk_info(dset, H5S_ALL, chk_index, CHK_SIZE, offset, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info failed\n");
/* Get info of the chunk at the specified offsets and verify its info */
if (verify_get_chunk_info_by_coord(dset, offset, CHK_SIZE, flt_msk) == FAIL)
FAIL_PUTS_ERROR("Verification of H5Dget_chunk_info_by_coord failed\n");
/* Release resourse */
if (H5Dclose(dset) < 0)
TEST_ERROR
if (H5Sclose(mem_space) < 0)
TEST_ERROR
if (H5Sclose(dspace) < 0)
TEST_ERROR
if (H5Pclose(cparms) < 0)
TEST_ERROR
if (H5Pclose(dxpl) < 0)
TEST_ERROR
if (H5Fclose(filter_file) < 0)
TEST_ERROR
/* Remove the test file */
HDremove(filename);
PASSED();
return SUCCEED;
error:
H5E_BEGIN_TRY
{
H5Dclose(dset);
H5Sclose(mem_space);
H5Sclose(dspace);
H5Pclose(cparms);
H5Pclose(dxpl);
H5Fclose(filter_file);
}
H5E_END_TRY;
H5_FAILED();
return FAIL;
} /* test_flt_msk_with_skip_compress() */
/*-------------------------------------------------------------------------
* Function: main
*
* Purpose: Tests functions related to chunk information
*
* Return: EXIT_SUCCESS/EXIT_FAILURE
*
* Programmer: Binh-Minh Ribler
* November 5, 2018
*
*-------------------------------------------------------------------------
*/
int
main(void)
{
hid_t fapl = H5I_INVALID_HID; /* File access property list */
int nerrors = 0; /* Number of errors so far */
h5_reset();
/* Create a copy of file access property list */
if ((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
TEST_ERROR
/* Test basic operations on the chunk query functions */
nerrors += test_basic_query(fapl) < 0 ? 1 : 0;
/* Tests getting chunk information of version 1.8 and prior */
nerrors += test_get_chunk_info_highest_v18(fapl) < 0 ? 1 : 0;
/* Tests getting chunk information of version 1.10 */
nerrors += test_get_chunk_info_v110(fapl) < 0 ? 1 : 0;
/* Tests getting filter mask when compression filter is skipped */
nerrors += test_flt_msk_with_skip_compress(fapl) < 0 ? 1 : 0;
if (nerrors)
goto error;
HDprintf("All chunk query tests passed.\n");
h5_cleanup(FILENAME, fapl);
return EXIT_SUCCESS;
error:
nerrors = MAX(1, nerrors);
HDprintf("***** %d QUERY CHUNK INFO TEST%s FAILED! *****\n", nerrors, 1 == nerrors ? "" : "S");
return EXIT_FAILURE;
}
/****************************************************************************
Additional tests to be added:
- do the query when extending the dataset (shrink or expand)
- verify that invalid input parameters are handled properly
****************************************************************************/
|