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 * Purpose: Test to verify that the infinite loop closing library/abort failure
16 * is fixed when the application creates and removes dense attributes
17 * (See HDFFV-10659).
18 */
19
20
21 #include "h5test.h"
22
23 /* The test file name */
24 const char *FILENAME[] = {
25 "del_many_dense_attrs",
26 NULL
27 };
28
29 #define ATTR_COUNT 64 /* The number of attributes */
30
31 /*-------------------------------------------------------------------------
32 * Function: catch_signal
33 *
34 * Purpose: The signal handler to catch the SIGABRT signal.
35 *
36 * Return: No return
37 *
38 * Programmer: Vailin Choi
39 *
40 *-------------------------------------------------------------------------
41 */
catch_signal(int H5_ATTR_UNUSED signo)42 static void catch_signal(int H5_ATTR_UNUSED signo)
43 {
44 HDexit(EXIT_FAILURE);
45 } /* catch_signal() */
46
47
48 /*-------------------------------------------------------------------------
49 * Function: main
50 *
51 * Purpose: Test to verify that the infinite loop closing library/abort failure
52 * is fixed when the application creates and removes dense attributes
53 * (See HDFFV-10659).
54 *
55 * Return: Success: exit(EXIT_SUCCESS)
56 * Failure: exit(EXIT_FAILURE)
57 *
58 * Programmer: Vailin Choi; Dec 2018
59 *
60 *-------------------------------------------------------------------------
61 */
62 int
main(void)63 main(void)
64 {
65 hid_t fid = -1; /* HDF5 File ID */
66 hid_t gid = -1; /* Group ID */
67 hid_t sid = -1; /* Dataspace ID */
68 hid_t aid = -1; /* Attribute ID */
69 hid_t tid = -1; /* Datatype ID */
70 hid_t fapl = -1; /* File access property lists */
71 hid_t gcpl = -1; /* Group creation property list */
72 char aname[50]; /* Name of attribute */
73 char *basename="attr"; /* Name prefix for attribute */
74 char filename[100]; /* File name */
75 int i; /* Local index variable */
76
77 /* Testing setup */
78 h5_reset();
79
80 /* To exit from the file for SIGABRT signal */
81 if(HDsignal(SIGABRT, catch_signal) == SIG_ERR)
82 TEST_ERROR
83
84 fapl = h5_fileaccess();
85 h5_fixname(FILENAME[0], fapl, filename, sizeof(filename));
86
87 /* Set to latest format */
88 if(H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
89 TEST_ERROR
90
91 /* Create the file */
92 if((fid = H5Fcreate(filename, H5F_ACC_TRUNC, H5P_DEFAULT, fapl)) < 0)
93 TEST_ERROR
94
95 /* Close the file */
96 if(H5Fclose(fid) < 0)
97 TEST_ERROR
98
99 /* Re-open the file */
100 if((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
101 TEST_ERROR
102
103 /* Create the group creation property list */
104 if((gcpl = H5Pcreate(H5P_GROUP_CREATE)) < 0)
105 TEST_ERROR
106
107 /* Set to use dense storage for all attributes on the group */
108 if(H5Pset_attr_phase_change(gcpl, 0, 0) < 0)
109 TEST_ERROR
110
111 /* Create the group in the file */
112 if((gid = H5Gcreate2(fid, "group", H5P_DEFAULT, gcpl, H5P_DEFAULT)) < 0)
113 TEST_ERROR
114
115 /* Create dataspace */
116 if((sid = H5Screate(H5S_SCALAR)) < 0)
117 TEST_ERROR
118
119 /* Get a copy of the datatype */
120 if((tid = H5Tcopy(H5T_NATIVE_FLOAT)) < 0)
121 TEST_ERROR
122
123 /* Create attributes in the group */
124 for(i = ATTR_COUNT; i >= 0; i--) {
125 /* Set up the attribute name */
126 HDsprintf(aname, "%s%d", basename, i);
127
128 /* Create the attribute */
129 if((aid = H5Acreate2(gid, aname, tid, sid, H5P_DEFAULT, H5P_DEFAULT)) < 0)
130 TEST_ERROR
131
132 /* Write to the attribute */
133 if(H5Awrite(aid, tid, &i) < 0)
134 TEST_ERROR
135
136 /* Close the attribute */
137 if(H5Aclose(aid) < 0)
138 TEST_ERROR
139 }
140
141 /* Close the datatype */
142 if(H5Tclose(tid) < 0)
143 TEST_ERROR
144
145 /* Close the dataspace */
146 if(H5Sclose(sid) < 0)
147 TEST_ERROR
148
149 /* Close the group */
150 if(H5Gclose(gid) < 0)
151 TEST_ERROR
152
153 /* Close the group creation property list */
154 if(H5Pclose(gcpl) < 0)
155 TEST_ERROR
156
157 /* Close the file */
158 if(H5Fclose(fid) < 0)
159 TEST_ERROR
160
161 /* Re-open the file */
162 if((fid = H5Fopen(filename, H5F_ACC_RDWR, fapl)) < 0)
163 TEST_ERROR
164
165 /* Open the group */
166 if((gid = H5Gopen2(fid, "group", H5P_DEFAULT)) < 0)
167 TEST_ERROR
168
169 /* Delete the attributes */
170 for (i = 0; i <= ATTR_COUNT; i++) {
171 /* Set up the attribute name */
172 HDsprintf(aname, "%s%d", basename, i);
173
174 /* Delete the attribute */
175 if(H5Adelete(gid, aname) < 0)
176 TEST_ERROR
177 } /* end for */
178
179 /* Close the group */
180 if(H5Gclose(gid) < 0)
181 TEST_ERROR
182
183 /* Close the file */
184 if(H5Fclose(fid) < 0)
185 TEST_ERROR
186
187 h5_cleanup(FILENAME, fapl);
188
189 return(EXIT_SUCCESS);
190
191 error:
192 H5E_BEGIN_TRY {
193 H5Gclose(gid);
194 H5Sclose(sid);
195 H5Tclose(tid);
196 H5Aclose(aid);
197 H5Fclose(fid);
198 H5Pclose(gcpl);
199 H5Pclose(fapl);
200 } H5E_END_TRY
201
202 return EXIT_FAILURE;
203 }
204