Skip to content

Commit 6bd6383

Browse files
authored
Add h5ls test files to gentest (#5559)
1 parent afd2b7a commit 6bd6383

File tree

4 files changed

+204
-26
lines changed

4 files changed

+204
-26
lines changed

tools/test/CMakeLists.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ set (HDF5_TOOLS
99
h5jam
1010
h5repack
1111
h5stat
12+
h5ls
1213
)
1314

1415
set (HDF5_TOOLS_MISC
@@ -40,10 +41,10 @@ if (HDF5_BUILD_GENERATORS)
4041
foreach(tool ${HDF5_TOOLS};${HDF5_TOOLS_MISC})
4142
if (${tool} IN_LIST HDF5_TOOLS_MISC)
4243
add_library(${tool}gentest OBJECT ${HDF5_TOOLS_TEST_SOURCE_DIR}/misc/${tool}gentest.c)
43-
target_include_directories (${tool}gentest PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_TEST_SRC_DIR};${HDF5_TOOLS_TST_DIR};${HDF5_TOOLS_ROOT_DIR}/misc;${HDF5_TOOLS_ROOT_DIR}/lib;${HDF5_SRC_BINARY_DIR};$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:${MPI_C_INCLUDE_DIRS}>")
44+
target_include_directories (${tool}gentest PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_TEST_SRC_DIR};${HDF5_TOOLS_TST_DIR};${HDF5_TOOLS_ROOT_DIR}/misc;${HDF5_TOOLS_ROOT_DIR}/lib;${HDF5_SRC_BINARY_DIR};$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:${MPI_C_INCLUDE_DIRS}>")
4445
else()
4546
add_library(${tool}gentest OBJECT ${HDF5_TOOLS_TEST_SOURCE_DIR}/${tool}/${tool}gentest.c)
46-
target_include_directories (${tool}gentest PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_TEST_SRC_DIR};${HDF5_TOOLS_TST_DIR};${HDF5_TOOLS_ROOT_DIR}/lib;${HDF5_SRC_BINARY_DIR};$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:${MPI_C_INCLUDE_DIRS}>")
47+
target_include_directories (${tool}gentest PRIVATE "${HDF5_SRC_INCLUDE_DIRS};${HDF5_TEST_SRC_DIR};${HDF5_TOOLS_TST_DIR};${HDF5_TOOLS_ROOT_DIR}/lib;${HDF5_SRC_BINARY_DIR};$<$<BOOL:${HDF5_ENABLE_PARALLEL}>:${MPI_C_INCLUDE_DIRS}>")
4748
endif()
4849

4950
if (HDF5_BUILD_STATIC_TOOLS)

tools/test/h5gentest.c

Lines changed: 75 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "h5repackgentest.h"
2323
#include "h5statgentest.h"
2424
#include "h5repartgentest.h"
25+
#include "h5lsgentest.h"
2526

2627
static int
2728
gen_h5copy_files(void)
@@ -379,6 +380,54 @@ gen_h5repart_files(void)
379380
return EXIT_SUCCESS;
380381
}
381382

383+
static int
384+
gen_h5ls_files(void)
385+
{
386+
int nerrors = 0;
387+
388+
gent_udfilter(H5LS_UDFILTER_FILE);
389+
390+
gent_all();
391+
gent_group();
392+
gent_dataset();
393+
gent_softlink();
394+
gent_softlink2();
395+
gent_str();
396+
397+
gent_vldatatypes();
398+
gent_compound_dt();
399+
gent_datareg();
400+
gent_empty();
401+
gent_hardlink();
402+
gent_loop();
403+
gent_nestcomp();
404+
405+
gent_group_comments();
406+
gent_array1();
407+
gent_attr_all();
408+
gent_attrreg();
409+
410+
gent_extlink();
411+
gent_extlinks();
412+
gent_null_space_group();
413+
414+
gent_udlink();
415+
416+
#ifdef H5_HAVE__FLOAT_16
417+
gent_float16();
418+
gent_float16_be();
419+
#endif
420+
#ifdef H5_HAVE_COMPLEX_NUMBERS
421+
gent_complex();
422+
gent_complex_be();
423+
#endif
424+
425+
nerrors += (gent_tdset() < 0 ? 1 : 0);
426+
gent_dataset_idx();
427+
428+
return nerrors;
429+
}
430+
382431
/*-------------------------------------------------------------------------
383432
* Function: usage
384433
*
@@ -404,6 +453,7 @@ usage(void)
404453
printf(" --h5repack Generate h5repack test files\n");
405454
printf(" --h5stat Generate h5stat test files\n");
406455
printf(" --h5repart Generate h5repart test files\n");
456+
printf(" --h5ls Generate h5ls test files\n");
407457
return;
408458
}
409459

@@ -414,29 +464,24 @@ int
414464
main(int argc, char *argv[])
415465
{
416466
/* command-line options: short and long-named parameters */
417-
static const char *s_opts = "hacdufjrsp";
418-
static struct h5_long_options l_opts[] = {{"help", no_arg, 'h'},
419-
{"all", no_arg, 'a'},
420-
{"h5copy", no_arg, 'c'},
421-
{"h5diff", no_arg, 'd'},
422-
{"h5dump", no_arg, 'u'},
423-
{"h5fc", no_arg, 'f'},
424-
{"h5jam", no_arg, 'j'},
425-
{"h5repack", no_arg, 'r'},
426-
{"h5stat", no_arg, 's'},
427-
{"h5repart", no_arg, 'p'},
428-
{NULL, 0, 0}};
429-
int i;
430-
int opt;
431-
bool run_all = false;
432-
bool run_h5copy = false;
433-
bool run_h5diff = false;
434-
bool run_h5dump = false;
435-
bool run_h5fc = false;
436-
bool run_h5jam = false;
437-
bool run_h5repack = false;
438-
bool run_h5stat = false;
439-
bool run_h5repart = false;
467+
static const char *s_opts = "hacdufjrspl";
468+
static struct h5_long_options l_opts[] = {
469+
{"help", no_arg, 'h'}, {"all", no_arg, 'a'}, {"h5copy", no_arg, 'c'},
470+
{"h5diff", no_arg, 'd'}, {"h5dump", no_arg, 'u'}, {"h5fc", no_arg, 'f'},
471+
{"h5jam", no_arg, 'j'}, {"h5repack", no_arg, 'r'}, {"h5stat", no_arg, 's'},
472+
{"h5repart", no_arg, 'p'}, {"h5ls", no_arg, 'l'}, {NULL, 0, 0}};
473+
int i;
474+
int opt;
475+
bool run_all = false;
476+
bool run_h5copy = false;
477+
bool run_h5diff = false;
478+
bool run_h5dump = false;
479+
bool run_h5fc = false;
480+
bool run_h5jam = false;
481+
bool run_h5repack = false;
482+
bool run_h5stat = false;
483+
bool run_h5repart = false;
484+
bool run_h5ls = false;
440485

441486
/* Check for no command line parameters */
442487
if (argc == 1) {
@@ -476,14 +521,16 @@ main(int argc, char *argv[])
476521
case 'p':
477522
run_h5repart = true;
478523
break;
524+
case 'l':
525+
run_h5ls = true;
479526
default:
480527
continue;
481528
}
482529
} /* end of while */
483530
}
484531

485532
if (!run_all && !run_h5copy && !run_h5diff && !run_h5dump && !run_h5fc && !run_h5jam && !run_h5repack &&
486-
!run_h5stat && !run_h5repart) {
533+
!run_h5stat && !run_h5repart && !run_h5ls) {
487534
usage();
488535
return EXIT_FAILURE;
489536
}
@@ -498,6 +545,7 @@ main(int argc, char *argv[])
498545
gen_h5repack_files();
499546
gen_h5stat_files();
500547
gen_h5repart_files();
548+
gen_h5ls_files();
501549
}
502550
else {
503551
if (run_h5copy) {
@@ -524,6 +572,9 @@ main(int argc, char *argv[])
524572
if (run_h5repart) {
525573
gen_h5repart_files();
526574
}
575+
if (run_h5ls) {
576+
gen_h5ls_files();
577+
}
527578
}
528579

529580
return EXIT_SUCCESS;

tools/test/h5ls/h5lsgentest.c

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2+
* Copyright by The HDF Group. *
3+
* All rights reserved. *
4+
* *
5+
* This file is part of HDF5. The full HDF5 copyright notice, including *
6+
* terms governing use, modification, and redistribution, is contained in *
7+
* the LICENSE file, which can be found at the root of the source code *
8+
* distribution tree, or in https://www.hdfgroup.org/licenses. *
9+
* If you do not have access to either file, you may request a copy from *
10+
11+
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12+
13+
#include "hdf5.h"
14+
#include "H5private.h"
15+
#include "h5lsgentest.h"
16+
17+
#define TDSET_FILENAME "tdset2.h5"
18+
19+
herr_t
20+
gent_tdset(void)
21+
{
22+
hid_t file_id, dataset1_id, dataset2_id;
23+
hid_t dataspace1_id, dataspace2_id;
24+
hid_t datatype1_id, datatype2_id;
25+
hid_t plist_id;
26+
hsize_t dims1[2] = {10, 20};
27+
hsize_t maxdims1[2] = {H5S_UNLIMITED, 20};
28+
hsize_t dims2[2] = {30, 10};
29+
hsize_t maxdims2[2] = {30, H5S_UNLIMITED};
30+
hsize_t chunk_dims[2] = {5, 5};
31+
int i, j;
32+
int data1[10][20];
33+
double data2[30][10];
34+
herr_t status = SUCCEED;
35+
36+
/* Initialize data for dataset 1 */
37+
for (i = 0; i < 10; i++) {
38+
for (j = 0; j < 20; j++) {
39+
data1[i][j] = j;
40+
}
41+
}
42+
43+
/* Initialize data for dataset 2 */
44+
for (i = 0; i < 30; i++) {
45+
for (j = 0; j < 10; j++) {
46+
data2[i][j] = (double)j;
47+
}
48+
}
49+
50+
/* Create a new file using default properties */
51+
file_id = H5Fcreate(TDSET_FILENAME, H5F_ACC_TRUNC, H5P_DEFAULT, H5P_DEFAULT);
52+
53+
/* Create the data space for the first dataset */
54+
dataspace1_id = H5Screate_simple(2, dims1, maxdims1);
55+
56+
/* Create the data space for the second dataset */
57+
dataspace2_id = H5Screate_simple(2, dims2, maxdims2);
58+
59+
/* Create the dataset creation property list */
60+
plist_id = H5Pcreate(H5P_DATASET_CREATE);
61+
62+
/* Set the chunk size */
63+
status = H5Pset_chunk(plist_id, 2, chunk_dims);
64+
65+
/* Create the datatype for the first dataset (32-bit big-endian integer) */
66+
datatype1_id = H5Tcopy(H5T_STD_I32BE);
67+
68+
/* Create the datatype for the second dataset (64-bit big-endian float) */
69+
datatype2_id = H5Tcopy(H5T_IEEE_F64BE);
70+
71+
/* Create the first dataset */
72+
dataset1_id =
73+
H5Dcreate2(file_id, "dset1", datatype1_id, dataspace1_id, H5P_DEFAULT, plist_id, H5P_DEFAULT);
74+
75+
/* Write the first dataset */
76+
status = H5Dwrite(dataset1_id, H5T_NATIVE_INT, H5S_ALL, H5S_ALL, H5P_DEFAULT, data1);
77+
78+
/* Create the second dataset */
79+
dataset2_id =
80+
H5Dcreate2(file_id, "dset2", datatype2_id, dataspace2_id, H5P_DEFAULT, plist_id, H5P_DEFAULT);
81+
82+
/* Write the second dataset */
83+
status = H5Dwrite(dataset2_id, H5T_NATIVE_DOUBLE, H5S_ALL, H5S_ALL, H5P_DEFAULT, data2);
84+
85+
/* Close the datasets */
86+
status = H5Dclose(dataset1_id);
87+
status = H5Dclose(dataset2_id);
88+
89+
/* Close the datatypes */
90+
status = H5Tclose(datatype1_id);
91+
status = H5Tclose(datatype2_id);
92+
93+
/* Close the dataspaces */
94+
status = H5Sclose(dataspace1_id);
95+
status = H5Sclose(dataspace2_id);
96+
97+
/* Close the property list */
98+
status = H5Pclose(plist_id);
99+
100+
/* Close the file */
101+
status = H5Fclose(file_id);
102+
103+
return status;
104+
}

tools/test/h5ls/h5lsgentest.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2+
* Copyright by The HDF Group. *
3+
* All rights reserved. *
4+
* *
5+
* This file is part of HDF5. The full HDF5 copyright notice, including *
6+
* terms governing use, modification, and redistribution, is contained in *
7+
* the LICENSE file, which can be found at the root of the source code *
8+
* distribution tree, or in https://www.hdfgroup.org/licenses. *
9+
* If you do not have access to either file, you may request a copy from *
10+
11+
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12+
13+
#ifndef H5LS_GENTEST_H
14+
#define H5LS_GENTEST_H
15+
16+
#include "hdf5.h"
17+
18+
#define H5LS_UDFILTER_FILE "tudfilter.h5"
19+
20+
herr_t gent_tdset(void);
21+
22+
#endif /* H5LS_GENTEST_H */

0 commit comments

Comments
 (0)