1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group.                                               *
3  * Copyright by the Board of Trustees of the University of Illinois.         *
4  * All rights reserved.                                                      *
5  *                                                                           *
6  * This file is part of HDF5.  The full HDF5 copyright notice, including     *
7  * terms governing use, modification, and redistribution, is contained in    *
8  * the COPYING file, which can be found at the root of the source code       *
9  * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
10  * If you do not have access to either file, you may request a copy from     *
11  * help@hdfgroup.org.                                                        *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 /*
15  * Serial tests for encoding/decoding plists
16  */
17 
18 #include "testhdf5.h"
19 #include "H5ACprivate.h"
20 #include "H5Pprivate.h"
21 
22 static int
test_encode_decode(hid_t orig_pl)23 test_encode_decode(hid_t orig_pl)
24 {
25     hid_t pl = (-1);               /* Decoded property list */
26     void *temp_buf = NULL;      /* Pointer to encoding buffer */
27     size_t temp_size = 0;       /* Size of encoding buffer */
28 
29     /* first call to encode returns only the size of the buffer needed */
30     if(H5Pencode(orig_pl, NULL, &temp_size) < 0)
31         STACK_ERROR
32 
33     if(NULL == (temp_buf = (void *)HDmalloc(temp_size)))
34         TEST_ERROR
35 
36     if(H5Pencode(orig_pl, temp_buf, &temp_size) < 0)
37         STACK_ERROR
38 
39     if((pl = H5Pdecode(temp_buf)) < 0)
40         STACK_ERROR
41 
42     if(!H5Pequal(orig_pl, pl))
43         PUTS_ERROR("encoding-decoding cycle failed\n")
44 
45     if((H5Pclose(pl)) < 0)
46         STACK_ERROR
47 
48     HDfree(temp_buf);
49 
50     /* Success */
51     return(0);
52 
53 error:
54     if(temp_buf)
55         HDfree(temp_buf);
56 
57      H5E_BEGIN_TRY {
58         H5Pclose(pl);
59     } H5E_END_TRY;
60 
61     return(-1);
62 } /* end test_encode_decode() */
63 
64 int
main(void)65 main(void)
66 {
67     hid_t dcpl;      /* dataset create prop. list */
68     hid_t dapl;      /* dataset access prop. list */
69     hid_t dxpl;      /* dataset xfer prop. list */
70     hid_t gcpl;      /* group create prop. list */
71     hid_t ocpypl;    /* object copy prop. list */
72     hid_t ocpl;      /* object create prop. list */
73     hid_t lcpl;      /* link create prop. list */
74     hid_t lapl;      /* link access prop. list */
75     hid_t fapl;      /* file access prop. list */
76     hid_t fcpl;      /* file create prop. list */
77     hid_t strcpl;    /* string create prop. list */
78     hid_t acpl;      /* attribute create prop. list */
79 
80     hsize_t chunk_size[2] = {16384, 4};    /* chunk size */
81     double fill = 2.7f;     /* Fill value */
82     hsize_t max_size[1];    /* data space maximum size */
83     size_t nslots = 521 * 2;
84     size_t nbytes = 1048576 * 10;
85     double w0 = 0.5f;
86     unsigned max_compact;
87     unsigned min_dense;
88     const char* c_to_f = "x+32";
89     H5AC_cache_config_t my_cache_config = {
90         H5AC__CURR_CACHE_CONFIG_VERSION,
91         TRUE,
92         FALSE,
93         FALSE,
94         "temp",
95         TRUE,
96         FALSE,
97         ( 2 * 2048 * 1024),
98         0.3f,
99         (64 * 1024 * 1024),
100         (4 * 1024 * 1024),
101         60000,
102         H5C_incr__threshold,
103         0.8f,
104         3.0f,
105         TRUE,
106         (8 * 1024 * 1024),
107         H5C_flash_incr__add_space,
108         2.0f,
109         0.25f,
110         H5C_decr__age_out_with_threshold,
111         0.997f,
112         0.8f,
113         TRUE,
114         (3 * 1024 * 1024),
115         3,
116         FALSE,
117         0.2f,
118         (256 * 2048),
119         H5AC__DEFAULT_METADATA_WRITE_STRATEGY};
120 
121     H5AC_cache_image_config_t my_cache_image_config = {
122         H5AC__CURR_CACHE_IMAGE_CONFIG_VERSION,
123         TRUE,
124         FALSE,
125         -1 };
126 
127     if(VERBOSE_MED)
128         HDprintf("Encode/Decode DCPLs\n");
129 
130     /******* ENCODE/DECODE DCPLS *****/
131     TESTING("Default DCPL Encoding/Decoding");
132     if((dcpl = H5Pcreate(H5P_DATASET_CREATE)) < 0)
133         FAIL_STACK_ERROR
134 
135     /* Test encoding & decoding default property list */
136     if(test_encode_decode(dcpl) < 0)
137         FAIL_PUTS_ERROR("Default DCPL encoding/decoding failed\n")
138 
139     PASSED();
140 
141     TESTING("DCPL Encoding/Decoding");
142 
143     if((H5Pset_chunk(dcpl, 2, chunk_size)) < 0)
144         FAIL_STACK_ERROR
145 
146     if((H5Pset_alloc_time(dcpl, H5D_ALLOC_TIME_LATE)) < 0)
147         FAIL_STACK_ERROR
148 
149     if((H5Pset_fill_value(dcpl, H5T_NATIVE_DOUBLE, &fill)) < 0)
150         FAIL_STACK_ERROR
151 
152     if((H5Pset_dset_no_attrs_hint(dcpl, FALSE)) < 0)
153         FAIL_STACK_ERROR
154 
155     max_size[0] = 100;
156     if((H5Pset_external(dcpl, "ext1.data", (off_t)0,
157                          (hsize_t)(max_size[0] * sizeof(int)/4))) < 0)
158         FAIL_STACK_ERROR
159     if((H5Pset_external(dcpl, "ext2.data", (off_t)0,
160                          (hsize_t)(max_size[0] * sizeof(int)/4))) < 0)
161         FAIL_STACK_ERROR
162     if((H5Pset_external(dcpl, "ext3.data", (off_t)0,
163                          (hsize_t)(max_size[0] * sizeof(int)/4))) < 0)
164         FAIL_STACK_ERROR
165     if((H5Pset_external(dcpl, "ext4.data", (off_t)0,
166                          (hsize_t)(max_size[0] * sizeof(int)/4))) < 0)
167         FAIL_STACK_ERROR
168 
169     /* Test encoding & decoding property list */
170     if(test_encode_decode(dcpl) < 0)
171         FAIL_PUTS_ERROR("DCPL encoding/decoding failed\n")
172 
173     /* release resource */
174     if((H5Pclose(dcpl)) < 0)
175          FAIL_STACK_ERROR
176 
177     PASSED();
178 
179 
180     /******* ENCODE/DECODE DAPLS *****/
181     TESTING("Default DAPL Encoding/Decoding");
182     if((dapl = H5Pcreate(H5P_DATASET_ACCESS)) < 0)
183         FAIL_STACK_ERROR
184 
185     /* Test encoding & decoding default property list */
186     if(test_encode_decode(dapl) < 0)
187         FAIL_PUTS_ERROR("Default DAPL encoding/decoding failed\n")
188 
189     PASSED();
190 
191     TESTING("DAPL Encoding/Decoding");
192 
193     if((H5Pset_chunk_cache(dapl, nslots, nbytes, w0)) < 0)
194         FAIL_STACK_ERROR
195 
196     /* Test encoding & decoding property list */
197     if(test_encode_decode(dapl) < 0)
198         FAIL_PUTS_ERROR("DAPL encoding/decoding failed\n")
199 
200     /* release resource */
201     if((H5Pclose(dapl)) < 0)
202          FAIL_STACK_ERROR
203 
204     PASSED();
205 
206 
207     /******* ENCODE/DECODE OCPLS *****/
208     TESTING("Default OCPL Encoding/Decoding");
209     if((ocpl = H5Pcreate(H5P_OBJECT_CREATE)) < 0)
210         FAIL_STACK_ERROR
211 
212     /* Test encoding & decoding default property list */
213     if(test_encode_decode(ocpl) < 0)
214         FAIL_PUTS_ERROR("Default OCPL encoding/decoding failed\n")
215 
216     PASSED();
217 
218     TESTING("OCPL Encoding/Decoding");
219 
220     if((H5Pset_attr_creation_order(ocpl, (H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED))) < 0)
221          FAIL_STACK_ERROR
222 
223     if((H5Pset_attr_phase_change (ocpl, 110, 105)) < 0)
224          FAIL_STACK_ERROR
225 
226     if((H5Pset_filter (ocpl, H5Z_FILTER_FLETCHER32, 0, (size_t)0, NULL)) < 0)
227         FAIL_STACK_ERROR
228 
229     /* Test encoding & decoding property list */
230     if(test_encode_decode(ocpl) < 0)
231         FAIL_PUTS_ERROR("OCPL encoding/decoding failed\n")
232 
233     /* release resource */
234     if((H5Pclose(ocpl)) < 0)
235         FAIL_STACK_ERROR
236 
237     PASSED();
238 
239 
240     /******* ENCODE/DECODE DXPLS *****/
241     TESTING("Default DXPL Encoding/Decoding");
242     if((dxpl = H5Pcreate(H5P_DATASET_XFER)) < 0)
243         FAIL_STACK_ERROR
244 
245     /* Test encoding & decoding default property list */
246     if(test_encode_decode(dxpl) < 0)
247         FAIL_PUTS_ERROR("Default DXPL encoding/decoding failed\n")
248 
249     PASSED();
250 
251     TESTING("DXPL Encoding/Decoding");
252 
253     if((H5Pset_btree_ratios(dxpl, 0.2f, 0.6f, 0.2f)) < 0)
254         FAIL_STACK_ERROR
255     if((H5Pset_hyper_vector_size(dxpl, 5)) < 0)
256         FAIL_STACK_ERROR
257 #ifdef H5_HAVE_PARALLEL
258     if((H5Pset_dxpl_mpio(dxpl, H5FD_MPIO_COLLECTIVE)) < 0)
259         FAIL_STACK_ERROR
260     if((H5Pset_dxpl_mpio_collective_opt(dxpl, H5FD_MPIO_INDIVIDUAL_IO)) < 0)
261         FAIL_STACK_ERROR
262     if((H5Pset_dxpl_mpio_chunk_opt(dxpl, H5FD_MPIO_CHUNK_MULTI_IO)) < 0)
263         FAIL_STACK_ERROR
264     if((H5Pset_dxpl_mpio_chunk_opt_ratio(dxpl, 30)) < 0)
265         FAIL_STACK_ERROR
266     if((H5Pset_dxpl_mpio_chunk_opt_num(dxpl, 40)) < 0)
267         FAIL_STACK_ERROR
268 #endif/* H5_HAVE_PARALLEL */
269     if((H5Pset_edc_check(dxpl, H5Z_DISABLE_EDC)) < 0)
270         FAIL_STACK_ERROR
271     if((H5Pset_data_transform(dxpl, c_to_f)) < 0)
272         FAIL_STACK_ERROR
273 
274     /* Test encoding & decoding property list */
275     if(test_encode_decode(dxpl) < 0)
276         FAIL_PUTS_ERROR("DXPL encoding/decoding failed\n")
277 
278     /* release resource */
279     if((H5Pclose(dxpl)) < 0)
280          FAIL_STACK_ERROR
281 
282     PASSED();
283 
284 
285     /******* ENCODE/DECODE GCPLS *****/
286     TESTING("Default GCPL Encoding/Decoding");
287     if((gcpl = H5Pcreate(H5P_GROUP_CREATE)) < 0)
288         FAIL_STACK_ERROR
289 
290     /* Test encoding & decoding default property list */
291     if(test_encode_decode(gcpl) < 0)
292         FAIL_PUTS_ERROR("Default GCPL encoding/decoding failed\n")
293 
294     PASSED();
295 
296     TESTING("GCPL Encoding/Decoding");
297 
298     if((H5Pset_local_heap_size_hint(gcpl, 256)) < 0)
299          FAIL_STACK_ERROR
300 
301     if((H5Pset_link_phase_change(gcpl, 2, 2)) < 0)
302          FAIL_STACK_ERROR
303 
304     /* Query the group creation properties */
305     if((H5Pget_link_phase_change(gcpl, &max_compact, &min_dense)) < 0)
306          FAIL_STACK_ERROR
307 
308     if((H5Pset_est_link_info(gcpl, 3, 9)) < 0)
309          FAIL_STACK_ERROR
310 
311     if((H5Pset_link_creation_order(gcpl, (H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED))) < 0)
312          FAIL_STACK_ERROR
313 
314     /* Test encoding & decoding property list */
315     if(test_encode_decode(gcpl) < 0)
316         FAIL_PUTS_ERROR("GCPL encoding/decoding failed\n")
317 
318     /* release resource */
319     if((H5Pclose(gcpl)) < 0)
320          FAIL_STACK_ERROR
321 
322     PASSED();
323 
324 
325     /******* ENCODE/DECODE LCPLS *****/
326     TESTING("Default LCPL Encoding/Decoding");
327     if((lcpl = H5Pcreate(H5P_LINK_CREATE)) < 0)
328         FAIL_STACK_ERROR
329 
330     /* Test encoding & decoding default property list */
331     if(test_encode_decode(lcpl) < 0)
332         FAIL_PUTS_ERROR("Default LCPL encoding/decoding failed\n")
333 
334     PASSED();
335 
336     TESTING("LCPL Encoding/Decoding");
337 
338     if((H5Pset_create_intermediate_group(lcpl, TRUE)) < 0)
339         FAIL_STACK_ERROR
340 
341     /* Test encoding & decoding property list */
342     if(test_encode_decode(lcpl) < 0)
343         FAIL_PUTS_ERROR("LCPL encoding/decoding failed\n")
344 
345     /* release resource */
346     if((H5Pclose(lcpl)) < 0)
347         FAIL_STACK_ERROR
348 
349     PASSED();
350 
351 
352     /******* ENCODE/DECODE LAPLS *****/
353     TESTING("Default LAPL Encoding/Decoding");
354     if((lapl = H5Pcreate(H5P_LINK_ACCESS)) < 0)
355         FAIL_STACK_ERROR
356 
357     /* Test encoding & decoding default property list */
358     if(test_encode_decode(lapl) < 0)
359         FAIL_PUTS_ERROR("Default LAPL encoding/decoding failed\n")
360 
361     PASSED();
362 
363     TESTING("LAPL Encoding/Decoding");
364 
365     if((H5Pset_nlinks(lapl, (size_t)134)) < 0)
366         FAIL_STACK_ERROR
367 
368     if((H5Pset_elink_acc_flags(lapl, H5F_ACC_RDONLY)) < 0)
369         FAIL_STACK_ERROR
370 
371     if((H5Pset_elink_prefix(lapl, "/tmpasodiasod")) < 0)
372         FAIL_STACK_ERROR
373 
374     /* Create FAPL for the elink FAPL */
375     if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
376         FAIL_STACK_ERROR
377     if((H5Pset_alignment(fapl, 2, 1024)) < 0)
378         FAIL_STACK_ERROR
379 
380     if((H5Pset_elink_fapl(lapl, fapl)) < 0)
381         FAIL_STACK_ERROR
382 
383     /* Close the elink's FAPL */
384     if((H5Pclose(fapl)) < 0)
385         FAIL_STACK_ERROR
386 
387     /* Test encoding & decoding property list */
388     if(test_encode_decode(lapl) < 0)
389         FAIL_PUTS_ERROR("LAPL encoding/decoding failed\n")
390 
391     /* release resource */
392     if((H5Pclose(lapl)) < 0)
393         FAIL_STACK_ERROR
394 
395     PASSED();
396 
397 
398     /******* ENCODE/DECODE OCPYPLS *****/
399     TESTING("Default OCPYPL Encoding/Decoding");
400     if((ocpypl = H5Pcreate(H5P_OBJECT_COPY)) < 0)
401         FAIL_STACK_ERROR
402 
403     /* Test encoding & decoding default property list */
404     if(test_encode_decode(ocpypl) < 0)
405         FAIL_PUTS_ERROR("Default OCPYPL encoding/decoding failed\n")
406 
407     PASSED();
408 
409     TESTING("OCPYPL Encoding/Decoding");
410 
411     if((H5Pset_copy_object(ocpypl, H5O_COPY_EXPAND_EXT_LINK_FLAG)) < 0)
412         FAIL_STACK_ERROR
413 
414     if((H5Padd_merge_committed_dtype_path(ocpypl, "foo")) < 0)
415         FAIL_STACK_ERROR
416     if((H5Padd_merge_committed_dtype_path(ocpypl, "bar")) < 0)
417         FAIL_STACK_ERROR
418 
419     /* Test encoding & decoding property list */
420     if(test_encode_decode(ocpypl) < 0)
421         FAIL_PUTS_ERROR("OCPYPL encoding/decoding failed\n")
422 
423     /* release resource */
424     if((H5Pclose(ocpypl)) < 0)
425          FAIL_STACK_ERROR
426 
427     PASSED();
428 
429 
430     /******* ENCODE/DECODE FAPLS *****/
431     TESTING("Default FAPL Encoding/Decoding");
432     if((fapl = H5Pcreate(H5P_FILE_ACCESS)) < 0)
433         FAIL_STACK_ERROR
434 
435     /* Test encoding & decoding default property list */
436     if(test_encode_decode(fapl) < 0)
437         FAIL_PUTS_ERROR("Default FAPL encoding/decoding failed\n")
438 
439     PASSED();
440 
441     TESTING("FAPL Encoding/Decoding");
442 
443     if((H5Pset_family_offset(fapl, 1024)) < 0)
444         FAIL_STACK_ERROR
445     if((H5Pset_meta_block_size(fapl, 2098452)) < 0)
446         FAIL_STACK_ERROR
447     if((H5Pset_sieve_buf_size(fapl, 1048576)) < 0)
448         FAIL_STACK_ERROR
449     if((H5Pset_alignment(fapl, 2, 1024)) < 0)
450         FAIL_STACK_ERROR
451     if((H5Pset_cache(fapl, 1024, 128, 10485760, 0.3f)) < 0)
452         FAIL_STACK_ERROR
453     if((H5Pset_elink_file_cache_size(fapl, 10485760)) < 0)
454         FAIL_STACK_ERROR
455     if((H5Pset_gc_references(fapl, 1)) < 0)
456         FAIL_STACK_ERROR
457     if((H5Pset_small_data_block_size(fapl, 2048)) < 0)
458         FAIL_STACK_ERROR
459     if((H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST)) < 0)
460         FAIL_STACK_ERROR
461     if((H5Pset_fclose_degree(fapl, H5F_CLOSE_WEAK)) < 0)
462         FAIL_STACK_ERROR
463     if((H5Pset_multi_type(fapl, H5FD_MEM_GHEAP)) < 0)
464         FAIL_STACK_ERROR
465     if((H5Pset_mdc_config(fapl, &my_cache_config)) < 0)
466         FAIL_STACK_ERROR
467     if((H5Pset_mdc_image_config(fapl, &my_cache_image_config)) < 0)
468         FAIL_STACK_ERROR
469     if((H5Pset_core_write_tracking(fapl, TRUE, 1024 * 1024)) < 0)
470         FAIL_STACK_ERROR
471 
472     /* Test encoding & decoding property list */
473     if(test_encode_decode(fapl) < 0)
474         FAIL_PUTS_ERROR("FAPL encoding/decoding failed\n")
475 
476     /* release resource */
477     if((H5Pclose(fapl)) < 0)
478         FAIL_STACK_ERROR
479 
480     PASSED();
481 
482 
483     /******* ENCODE/DECODE FCPLS *****/
484     TESTING("Default FCPL Encoding/Decoding");
485 
486     if((fcpl = H5Pcreate(H5P_FILE_CREATE)) < 0)
487         FAIL_STACK_ERROR
488 
489     /* Test encoding & decoding default property list */
490     if(test_encode_decode(fcpl) < 0)
491         FAIL_PUTS_ERROR("Default FCPL encoding/decoding failed\n")
492 
493     PASSED();
494 
495     TESTING("FCPL Encoding/Decoding");
496 
497     if((H5Pset_userblock(fcpl, 1024) < 0))
498          FAIL_STACK_ERROR
499 
500     if((H5Pset_istore_k(fcpl, 3) < 0))
501          FAIL_STACK_ERROR
502 
503     if((H5Pset_sym_k(fcpl, 4, 5) < 0))
504          FAIL_STACK_ERROR
505 
506     if((H5Pset_shared_mesg_nindexes(fcpl, 8) < 0))
507          FAIL_STACK_ERROR
508 
509     if((H5Pset_shared_mesg_index(fcpl, 1,  H5O_SHMESG_SDSPACE_FLAG, 32) < 0))
510          FAIL_STACK_ERROR
511 
512    if((H5Pset_shared_mesg_phase_change(fcpl, 60, 20) < 0))
513          FAIL_STACK_ERROR
514 
515     if((H5Pset_sizes(fcpl, 8, 4) < 0))
516          FAIL_STACK_ERROR
517 
518     /* Test encoding & decoding property list */
519     if(test_encode_decode(fcpl) < 0)
520         FAIL_PUTS_ERROR("FCPL encoding/decoding failed\n")
521 
522     /* release resource */
523     if((H5Pclose(fcpl)) < 0)
524         FAIL_STACK_ERROR
525 
526     PASSED();
527 
528 
529     /******* ENCODE/DECODE STRCPLS *****/
530     TESTING("Default STRCPL Encoding/Decoding");
531 
532     if((strcpl = H5Pcreate(H5P_STRING_CREATE)) < 0)
533         FAIL_STACK_ERROR
534 
535     /* Test encoding & decoding default property list */
536     if(test_encode_decode(strcpl) < 0)
537         FAIL_PUTS_ERROR("Default STRCPL encoding/decoding failed\n")
538 
539     PASSED();
540 
541     TESTING("STRCPL Encoding/Decoding");
542 
543     if((H5Pset_char_encoding(strcpl, H5T_CSET_UTF8) < 0))
544          FAIL_STACK_ERROR
545 
546     /* Test encoding & decoding property list */
547     if(test_encode_decode(strcpl) < 0)
548         FAIL_PUTS_ERROR("STRCPL encoding/decoding failed\n")
549 
550     /* release resource */
551     if((H5Pclose(strcpl)) < 0)
552         FAIL_STACK_ERROR
553 
554     PASSED();
555 
556 
557     /******* ENCODE/DECODE ACPLS *****/
558     TESTING("Default ACPL Encoding/Decoding");
559 
560     if((acpl = H5Pcreate(H5P_ATTRIBUTE_CREATE)) < 0)
561         FAIL_STACK_ERROR
562 
563     /* Test encoding & decoding default property list */
564     if(test_encode_decode(acpl) < 0)
565         FAIL_PUTS_ERROR("Default ACPL encoding/decoding failed\n")
566 
567     PASSED();
568 
569     TESTING("ACPL Encoding/Decoding");
570 
571     if((H5Pset_char_encoding(acpl, H5T_CSET_UTF8) < 0))
572          FAIL_STACK_ERROR
573 
574     /* Test encoding & decoding property list */
575     if(test_encode_decode(acpl) < 0)
576         FAIL_PUTS_ERROR("ACPL encoding/decoding failed\n")
577 
578     /* release resource */
579     if((H5Pclose(acpl)) < 0)
580         FAIL_STACK_ERROR
581 
582     PASSED();
583 
584 
585     return 0;
586 
587 error:
588     HDprintf("***** Plist Encode/Decode tests FAILED! *****\n");
589     return 1;
590 }
591 
592