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  * generate plist file
16  */
17 
18 #include "H5private.h"
19 #include "hdf5.h"
20 
21 static int encode_plist(hid_t plist_id, int little_endian, int word_length, const char *filename_prefix);
22 
23 int
main(void)24 main(void)
25 {
26     hid_t dcpl1;	       	/* dataset create prop. list */
27     hid_t dapl1;	       	/* dataset access prop. list */
28     hid_t dxpl1;	       	/* dataset xfer prop. list */
29     hid_t gcpl1;	       	/* group create prop. list */
30     hid_t ocpypl1;		    /* object copy prop. list */
31     hid_t ocpl1;	        /* object create prop. list */
32     hid_t lcpl1;	       	/* link create prop. list */
33     hid_t lapl1;	       	/* link access prop. list */
34     hid_t fapl1;	       	/* file access prop. list */
35     hid_t fcpl1;	       	/* file create prop. list */
36     hid_t strcpl1;	       	/* string create prop. list */
37     hid_t acpl1;	       	/* attribute create prop. list */
38 
39     herr_t ret = 0;
40     hsize_t chunk_size = 16384;	/* chunk size */
41     int fill = 2;            /* Fill value */
42     hsize_t max_size[1];        /* data space maximum size */
43     size_t nslots = 521 * 2;
44     size_t nbytes = 1048576 * 10;
45     double w0 = 0.5f;
46     unsigned max_compact;
47     unsigned min_dense;
48     const char* c_to_f = "x+32";
49     int little_endian;
50     int word_length;
51     H5AC_cache_config_t my_cache_config = {
52         H5AC__CURR_CACHE_CONFIG_VERSION,
53         1 /*TRUE*/,
54         0 /*FALSE*/,
55         0 /*FALSE*/,
56         "temp",
57         1 /*TRUE*/,
58         0 /*FALSE*/,
59         ( 2 * 2048 * 1024),
60         0.3f,
61         (64 * 1024 * 1024),
62         (4 * 1024 * 1024),
63         60000,
64         H5C_incr__threshold,
65         0.8f,
66         3.0f,
67         1 /*TRUE*/,
68         (8 * 1024 * 1024),
69         H5C_flash_incr__add_space,
70         2.0f,
71         0.25f,
72         H5C_decr__age_out_with_threshold,
73         0.997f,
74         0.8f,
75         1 /*TRUE*/,
76         (3 * 1024 * 1024),
77         3,
78         0 /*FALSE*/,
79         0.2f,
80         (256 * 2048),
81         H5AC_METADATA_WRITE_STRATEGY__PROCESS_0_ONLY};
82     H5AC_cache_image_config_t my_cache_image_config = {
83         H5AC__CURR_CACHE_IMAGE_CONFIG_VERSION,
84         TRUE,
85 	FALSE,
86         -1};
87 
88 
89     /* check endianess */
90     {
91         short int word = 0x0001;
92         char *byte = (char *) &word;
93 
94         if(byte[0] == 1)
95             /* little endian */
96             little_endian = 1;
97         else
98             /* big endian */
99             little_endian = 0;
100     }
101 
102     /* check word length */
103     {
104         word_length = 8 * sizeof(void *);
105     }
106 
107     /* Explicitly initialize the library, since we are including the private header file */
108     H5open();
109 
110     /******* ENCODE/DECODE DCPLS *****/
111     if((dcpl1 = H5Pcreate(H5P_DATASET_CREATE)) < 0)
112         assert(dcpl1 > 0);
113 
114     if((ret = encode_plist(dcpl1, little_endian, word_length, "testfiles/plist_files/def_dcpl_")) < 0)
115         assert(ret > 0);
116 
117     if((ret = H5Pset_chunk(dcpl1, 1, &chunk_size)) < 0)
118         assert(ret > 0);
119 
120     if((ret = H5Pset_alloc_time(dcpl1, H5D_ALLOC_TIME_LATE)) < 0)
121         assert(ret > 0);
122 
123     ret = H5Tconvert(H5T_NATIVE_INT, H5T_STD_I32BE, (size_t)1, &fill, NULL, H5P_DEFAULT);
124     assert(ret >= 0);
125     if((ret = H5Pset_fill_value(dcpl1, H5T_STD_I32BE, &fill)) < 0)
126         assert(ret > 0);
127 
128     if((ret = H5Pset_dset_no_attrs_hint(dcpl1, FALSE)) < 0)
129         assert(ret > 0);
130 
131     max_size[0] = 100;
132     if((ret = H5Pset_external(dcpl1, "ext1.data", (off_t)0,
133                          (hsize_t)(max_size[0] * sizeof(int)/4))) < 0)
134         assert(ret > 0);
135     if((ret = H5Pset_external(dcpl1, "ext2.data", (off_t)0,
136                          (hsize_t)(max_size[0] * sizeof(int)/4))) < 0)
137         assert(ret > 0);
138     if((ret = H5Pset_external(dcpl1, "ext3.data", (off_t)0,
139                          (hsize_t)(max_size[0] * sizeof(int)/4))) < 0)
140         assert(ret > 0);
141     if((ret = H5Pset_external(dcpl1, "ext4.data", (off_t)0,
142                          (hsize_t)(max_size[0] * sizeof(int)/4))) < 0)
143         assert(ret > 0);
144 
145     if((ret = encode_plist(dcpl1, little_endian, word_length, "testfiles/plist_files/dcpl_")) < 0)
146         assert(ret > 0);
147 
148     /* release resource */
149     if((ret = H5Pclose(dcpl1)) < 0)
150          assert(ret > 0);
151 
152 
153     /******* ENCODE/DECODE DAPLS *****/
154     if((dapl1 = H5Pcreate(H5P_DATASET_ACCESS)) < 0)
155         assert(dapl1 > 0);
156 
157     if((ret = encode_plist(dapl1, little_endian, word_length, "testfiles/plist_files/def_dapl_")) < 0)
158         assert(ret > 0);
159 
160     if((ret = H5Pset_chunk_cache(dapl1, nslots, nbytes, w0)) < 0)
161         assert(ret > 0);
162 
163     if((ret = encode_plist(dapl1, little_endian, word_length, "testfiles/plist_files/dapl_")) < 0)
164         assert(ret > 0);
165 
166     /* release resource */
167     if((ret = H5Pclose(dapl1)) < 0)
168          assert(ret > 0);
169 
170     /******* ENCODE/DECODE DXPLS *****/
171     if((dxpl1 = H5Pcreate(H5P_DATASET_XFER)) < 0)
172         assert(dxpl1 > 0);
173 
174     if((ret = encode_plist(dxpl1, little_endian, word_length, "testfiles/plist_files/def_dxpl_")) < 0)
175         assert(ret > 0);
176 
177     if((ret = H5Pset_btree_ratios(dxpl1, 0.2f, 0.6f, 0.2f)) < 0)
178         assert(ret > 0);
179     if((ret = H5Pset_hyper_vector_size(dxpl1, 5)) < 0)
180         assert(ret > 0);
181 #ifdef H5_HAVE_PARALLEL
182     if((ret = H5Pset_dxpl_mpio(dxpl1, H5FD_MPIO_COLLECTIVE)) < 0)
183         assert(ret > 0);
184     if((ret = H5Pset_dxpl_mpio_collective_opt(dxpl1, H5FD_MPIO_INDIVIDUAL_IO)) < 0)
185         assert(ret > 0);
186     if((ret = H5Pset_dxpl_mpio_chunk_opt(dxpl1, H5FD_MPIO_CHUNK_MULTI_IO)) < 0)
187         assert(ret > 0);
188     if((ret = H5Pset_dxpl_mpio_chunk_opt_ratio(dxpl1, 30)) < 0)
189         assert(ret > 0);
190     if((ret = H5Pset_dxpl_mpio_chunk_opt_num(dxpl1, 40)) < 0)
191         assert(ret > 0);
192 #endif/* H5_HAVE_PARALLEL */
193     if((ret = H5Pset_edc_check(dxpl1, H5Z_DISABLE_EDC)) < 0)
194         assert(ret > 0);
195     if((ret = H5Pset_data_transform(dxpl1, c_to_f)) < 0)
196         assert(ret > 0);
197 
198     if((ret = encode_plist(dxpl1, little_endian, word_length, "testfiles/plist_files/dxpl_")) < 0)
199         assert(ret > 0);
200 
201     /* release resource */
202     if((ret = H5Pclose(dxpl1)) < 0)
203          assert(ret > 0);
204 
205 
206     /******* ENCODE/DECODE GCPLS *****/
207     if((gcpl1 = H5Pcreate(H5P_GROUP_CREATE)) < 0)
208         assert(gcpl1 > 0);
209 
210     if((ret = encode_plist(gcpl1, little_endian, word_length, "testfiles/plist_files/def_gcpl_")) < 0)
211         assert(ret > 0);
212 
213     if((ret = H5Pset_local_heap_size_hint(gcpl1, 256)) < 0)
214          assert(ret > 0);
215 
216     if((ret = H5Pset_link_phase_change(gcpl1, 2, 2)) < 0)
217          assert(ret > 0);
218 
219     /* Query the group creation properties */
220     if((ret = H5Pget_link_phase_change(gcpl1, &max_compact, &min_dense)) < 0)
221          assert(ret > 0);
222 
223     if((ret = H5Pset_est_link_info(gcpl1, 3, 9)) < 0)
224          assert(ret > 0);
225 
226     if((ret = H5Pset_link_creation_order(gcpl1, (H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED))) < 0)
227          assert(ret > 0);
228 
229     if((ret = encode_plist(gcpl1, little_endian, word_length, "testfiles/plist_files/gcpl_")) < 0)
230         assert(ret > 0);
231 
232     /* release resource */
233     if((ret = H5Pclose(gcpl1)) < 0)
234          assert(ret > 0);
235 
236     /******* ENCODE/DECODE LCPLS *****/
237     if((lcpl1 = H5Pcreate(H5P_LINK_CREATE)) < 0)
238         assert(lcpl1 > 0);
239 
240     if((ret = encode_plist(lcpl1, little_endian, word_length, "testfiles/plist_files/def_lcpl_")) < 0)
241         assert(ret > 0);
242 
243     if((ret = H5Pset_create_intermediate_group(lcpl1, 1 /*TRUE*/)) < 0)
244         assert(ret > 0);
245 
246     if((ret = encode_plist(lcpl1, little_endian, word_length, "testfiles/plist_files/lcpl_")) < 0)
247         assert(ret > 0);
248 
249     /* release resource */
250     if((ret = H5Pclose(lcpl1)) < 0)
251         assert(ret > 0);
252 
253     /******* ENCODE/DECODE OCPYLS *****/
254     if((ocpypl1 = H5Pcreate(H5P_OBJECT_COPY)) < 0)
255         assert(ocpypl1 > 0);
256 
257     if((ret = encode_plist(ocpypl1, little_endian, word_length, "testfiles/plist_files/def_ocpypl_")) < 0)
258         assert(ret > 0);
259 
260     ret = H5Pset_copy_object(ocpypl1, H5O_COPY_EXPAND_EXT_LINK_FLAG);
261     assert(ret >= 0);
262 
263     ret = H5Padd_merge_committed_dtype_path(ocpypl1, "foo");
264     assert(ret >= 0);
265 
266     ret = H5Padd_merge_committed_dtype_path(ocpypl1, "bar");
267     assert(ret >= 0);
268 
269     if((ret = encode_plist(ocpypl1, little_endian, word_length, "testfiles/plist_files/ocpypl_")) < 0)
270         assert(ret > 0);
271 
272     /* release resource */
273     if((ret = H5Pclose(ocpypl1)) < 0)
274          assert(ret > 0);
275 
276     /******* ENCODE/DECODE OCPLS *****/
277     if((ocpl1 = H5Pcreate(H5P_OBJECT_CREATE)) < 0)
278         assert(ocpl1 > 0);
279 
280     if((ret = encode_plist(ocpl1, little_endian, word_length, "testfiles/plist_files/def_ocpl_")) < 0)
281         assert(ret > 0);
282 
283     if((ret = H5Pset_attr_creation_order(ocpl1, (H5P_CRT_ORDER_TRACKED | H5P_CRT_ORDER_INDEXED))) < 0)
284          assert(ret > 0);
285 
286     if((ret = H5Pset_attr_phase_change (ocpl1, 110, 105)) < 0)
287          assert(ret > 0);
288 
289     if((ret = H5Pset_filter (ocpl1, H5Z_FILTER_FLETCHER32, 0, (size_t)0, NULL)) < 0)
290         assert(ret > 0);
291 
292     if((ret = encode_plist(ocpl1, little_endian, word_length, "testfiles/plist_files/ocpl_")) < 0)
293         assert(ret > 0);
294 
295     /* release resource */
296     if((ret = H5Pclose(ocpl1)) < 0)
297         assert(ret > 0);
298 
299     /******* ENCODE/DECODE LAPLS *****/
300     if((lapl1 = H5Pcreate(H5P_LINK_ACCESS)) < 0)
301         assert(lapl1 > 0);
302 
303     if((ret = encode_plist(lapl1, little_endian, word_length, "testfiles/plist_files/def_lapl_")) < 0)
304         assert(ret > 0);
305 
306     if((ret = H5Pset_nlinks(lapl1, (size_t)134)) < 0)
307         assert(ret > 0);
308 
309     if((ret = H5Pset_elink_acc_flags(lapl1, H5F_ACC_RDONLY)) < 0)
310         assert(ret > 0);
311 
312     if((ret = H5Pset_elink_prefix(lapl1, "/tmpasodiasod")) < 0)
313         assert(ret > 0);
314 
315     /* Create FAPL for the elink FAPL */
316     if((fapl1 = H5Pcreate(H5P_FILE_ACCESS)) < 0)
317         assert(fapl1 > 0);
318     if((ret = H5Pset_alignment(fapl1, 2, 1024)) < 0)
319         assert(ret > 0);
320 
321     if((ret = H5Pset_elink_fapl(lapl1, fapl1)) < 0)
322         assert(ret > 0);
323 
324     /* Close the elink's FAPL */
325     if((ret = H5Pclose(fapl1)) < 0)
326         assert(ret > 0);
327 
328     if((ret = encode_plist(lapl1, little_endian, word_length, "testfiles/plist_files/lapl_")) < 0)
329         assert(ret > 0);
330 
331     /* release resource */
332     if((ret = H5Pclose(lapl1)) < 0)
333         assert(ret > 0);
334 
335     /******* ENCODE/DECODE FAPLS *****/
336     if((fapl1 = H5Pcreate(H5P_FILE_ACCESS)) < 0)
337         assert(fapl1 > 0);
338 
339     if((ret = encode_plist(fapl1, little_endian, word_length, "testfiles/plist_files/def_fapl_")) < 0)
340         assert(ret > 0);
341 
342     if((ret = H5Pset_family_offset(fapl1, 1024)) < 0)
343         assert(ret > 0);
344     if((ret = H5Pset_meta_block_size(fapl1, 2098452)) < 0)
345         assert(ret > 0);
346     if((ret = H5Pset_sieve_buf_size(fapl1, 1048576)) < 0)
347         assert(ret > 0);
348     if((ret = H5Pset_alignment(fapl1, 2, 1024)) < 0)
349         assert(ret > 0);
350     if((ret = H5Pset_cache(fapl1, 1024, 128, 10485760, 0.3f)) < 0)
351         assert(ret > 0);
352     if((ret = H5Pset_elink_file_cache_size(fapl1, 10485760)) < 0)
353         assert(ret > 0);
354     if((ret = H5Pset_gc_references(fapl1, 1)) < 0)
355         assert(ret > 0);
356     if((ret = H5Pset_small_data_block_size(fapl1, 2048)) < 0)
357         assert(ret > 0);
358     if((ret = H5Pset_libver_bounds(fapl1, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST)) < 0)
359         assert(ret > 0);
360     if((ret = H5Pset_fclose_degree(fapl1, H5F_CLOSE_WEAK)) < 0)
361         assert(ret > 0);
362     if((ret = H5Pset_multi_type(fapl1, H5FD_MEM_GHEAP)) < 0)
363         assert(ret > 0);
364     if((ret = H5Pset_mdc_config(fapl1, &my_cache_config)) < 0)
365         assert(ret > 0);
366     if((ret = H5Pset_mdc_image_config(fapl1, &my_cache_image_config)) < 0)
367         assert(ret > 0);
368 
369     if((ret = H5Pset_core_write_tracking(fapl1, TRUE, (size_t)(1024 * 1024))) < 0)
370         assert(ret > 0);
371 
372     if((ret = encode_plist(fapl1, little_endian, word_length, "testfiles/plist_files/fapl_")) < 0)
373         assert(ret > 0);
374 
375     /* release resource */
376     if((ret = H5Pclose(fapl1)) < 0)
377         assert(ret > 0);
378 
379     /******* ENCODE/DECODE FCPLS *****/
380     if((fcpl1 = H5Pcreate(H5P_FILE_CREATE)) < 0)
381         assert(fcpl1 > 0);
382 
383     if((ret = encode_plist(fcpl1, little_endian, word_length, "testfiles/plist_files/def_fcpl_")) < 0)
384         assert(ret > 0);
385 
386     if((ret = H5Pset_userblock(fcpl1, 1024) < 0))
387          assert(ret > 0);
388 
389     if((ret = H5Pset_istore_k(fcpl1, 3) < 0))
390          assert(ret > 0);
391 
392     if((ret = H5Pset_sym_k(fcpl1, 4, 5) < 0))
393          assert(ret > 0);
394 
395     if((ret = H5Pset_shared_mesg_nindexes(fcpl1, 8) < 0))
396          assert(ret > 0);
397 
398     if((ret = H5Pset_shared_mesg_index(fcpl1, 1,  H5O_SHMESG_SDSPACE_FLAG, 32) < 0))
399          assert(ret > 0);
400 
401    if((ret = H5Pset_shared_mesg_phase_change(fcpl1, 60, 20) < 0))
402          assert(ret > 0);
403 
404     if((ret = H5Pset_sizes(fcpl1, 8, 4) < 0))
405          assert(ret > 0);
406 
407     if((ret = H5Pset_file_space_strategy(fcpl1, H5F_FSPACE_STRATEGY_PAGE, TRUE, (hsize_t)1)) < 0)
408          assert(ret > 0);
409 
410     if((ret = H5Pset_file_space_page_size(fcpl1, (hsize_t)4096)) < 0)
411          assert(ret > 0);
412 
413     if((ret = encode_plist(fcpl1, little_endian, word_length, "testfiles/plist_files/fcpl_")) < 0)
414         assert(ret > 0);
415 
416     /* release resource */
417     if((ret = H5Pclose(fcpl1)) < 0)
418         assert(ret > 0);
419 
420     /******* ENCODE/DECODE STRCPLS *****/
421     strcpl1 = H5Pcreate(H5P_STRING_CREATE);
422     assert(strcpl1 > 0);
423 
424     ret = encode_plist(strcpl1, little_endian, word_length, "testfiles/plist_files/def_strcpl_");
425     assert(ret > 0);
426 
427     ret = H5Pset_char_encoding(strcpl1, H5T_CSET_UTF8);
428     assert(ret >= 0);
429 
430     ret = encode_plist(strcpl1, little_endian, word_length, "testfiles/plist_files/strcpl_");
431     assert(ret > 0);
432 
433     /* release resource */
434     ret = H5Pclose(strcpl1);
435     assert(ret >= 0);
436 
437     /******* ENCODE/DECODE ACPLS *****/
438     acpl1 = H5Pcreate(H5P_ATTRIBUTE_CREATE);
439     assert(acpl1 > 0);
440 
441     ret = encode_plist(acpl1, little_endian, word_length, "testfiles/plist_files/def_acpl_");
442     assert(ret > 0);
443 
444     ret = H5Pset_char_encoding(acpl1, H5T_CSET_UTF8);
445     assert(ret >= 0);
446 
447     ret = encode_plist(acpl1, little_endian, word_length, "testfiles/plist_files/acpl_");
448     assert(ret > 0);
449 
450     /* release resource */
451     ret = H5Pclose(acpl1);
452     assert(ret >= 0);
453 
454     return 0;
455 }
456 
457 static int
encode_plist(hid_t plist_id,int little_endian,int word_length,const char * filename_prefix)458 encode_plist(hid_t plist_id, int little_endian, int word_length, const char *filename_prefix)
459 {
460     int fd = 0; /* file descriptor */
461     herr_t ret = 0;
462     void *temp_buf = NULL;
463     size_t temp_size = 0;
464     ssize_t write_size;
465     char filename[1024];
466 
467     /* Generate filename */
468     if((ret = HDsnprintf(filename, sizeof(filename), "%s%d%s", filename_prefix, word_length, little_endian ? "le" : "be")) < 0)
469         HDassert(ret > 0);
470 
471     /* first call to encode returns only the size of the buffer needed */
472     if((ret = H5Pencode(plist_id, NULL, &temp_size)) < 0)
473         HDassert(ret > 0);
474 
475     temp_buf = (void *)HDmalloc(temp_size);
476     HDassert(temp_buf);
477 
478     if((ret = H5Pencode(plist_id, temp_buf, &temp_size)) < 0)
479         HDassert(ret > 0);
480 
481     fd = HDopen(filename, O_RDWR | O_CREAT | O_TRUNC, H5_POSIX_CREATE_MODE_RW);
482     HDassert(fd > 0);
483 
484     write_size = HDwrite(fd, temp_buf, temp_size);
485     HDassert(write_size == (ssize_t)temp_size);
486 
487     HDclose(fd);
488 
489     HDfree(temp_buf);
490 
491     return 1;
492 }
493 
494