Skip to content

Commit 9e4bf2b

Browse files
committed
Add tests of 2 attributes and total size > 2 GiB
1 parent 4abe1d8 commit 9e4bf2b

1 file changed

Lines changed: 185 additions & 4 deletions

File tree

test/largefile/large_attr.c

Lines changed: 185 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,8 @@
3030

3131
int main(int argc, char** argv)
3232
{
33-
char filename[256], *buf;
33+
char filename[256], *name, *buf;
34+
size_t i;
3435
int rank, nprocs, err, nerrs=0, verbose=0;
3536
int ncid, cmode, varid, dimid;
3637
MPI_Offset nelems, inq_nelems;
@@ -57,7 +58,7 @@ int main(int argc, char** argv)
5758
free(cmd_str);
5859
}
5960

60-
nelems = (MPI_Offset)NC_MAX_INT + 10;
61+
nelems = (MPI_Offset)NC_MAX_INT + 17;
6162
buf = (char*) malloc(nelems);
6263

6364
/* create a new file and put a large global attribute -------------------*/
@@ -66,6 +67,7 @@ int main(int argc, char** argv)
6667
CHECK_ERR
6768

6869
/* put a large (> 2GiB) global attribute */
70+
for (i=0; i<nelems; i++) buf[i] = 'a' + i % 16;
6971
err = ncmpi_put_att_text(ncid, NC_GLOBAL, "large_attr", nelems, buf);
7072
if (!(cmode & NC_64BIT_DATA)) EXP_ERR(NC_EINVAL)
7173
else CHECK_ERR
@@ -75,7 +77,7 @@ int main(int argc, char** argv)
7577
if (nerrs > 0) goto err_out;
7678

7779
/* open the file and read back the large global attribute ---------------*/
78-
err = ncmpi_open(MPI_COMM_WORLD, filename, NC_WRITE, info, &ncid);
80+
err = ncmpi_open(MPI_COMM_WORLD, filename, NC_NOWRITE, info, &ncid);
7981
CHECK_ERR
8082
if (err != NC_NOERR) goto err_out;
8183

@@ -86,9 +88,20 @@ int main(int argc, char** argv)
8688
nerrs++;
8789
}
8890

91+
for (i=0; i<nelems; i++) buf[i] = 0;
8992
err = ncmpi_get_att_text(ncid, NC_GLOBAL, "large_attr", buf);
9093
CHECK_ERR
9194

95+
for (i=0; i<nelems; i++) {
96+
char expect = 'a' + i % 16;
97+
if (buf[i] != 'a' + i % 16) {
98+
printf("Error at %s line %d: expecting attr[%zd] value %c but got %c\n",
99+
__FILE__,__LINE__,i,expect,buf[i]);
100+
nerrs++;
101+
break;
102+
}
103+
}
104+
92105
err = ncmpi_close(ncid); CHECK_ERR
93106
if (nerrs > 0) goto err_out;
94107

@@ -104,6 +117,7 @@ int main(int argc, char** argv)
104117
CHECK_ERR
105118

106119
/* put a large (> 2GiB) global attribute */
120+
for (i=0; i<nelems; i++) buf[i] = 'a' + i % 16;
107121
err = ncmpi_put_att_text(ncid, varid, "large_attr", nelems, buf);
108122
if (!(cmode & NC_64BIT_DATA)) EXP_ERR(NC_EINVAL)
109123
else CHECK_ERR
@@ -113,7 +127,7 @@ int main(int argc, char** argv)
113127
if (nerrs > 0) goto err_out;
114128

115129
/* open the file and read back the large global attribute ---------------*/
116-
err = ncmpi_open(MPI_COMM_WORLD, filename, NC_WRITE, info, &ncid);
130+
err = ncmpi_open(MPI_COMM_WORLD, filename, NC_NOWRITE, info, &ncid);
117131
CHECK_ERR
118132
if (err != NC_NOERR) goto err_out;
119133

@@ -127,9 +141,176 @@ int main(int argc, char** argv)
127141
nerrs++;
128142
}
129143

144+
for (i=0; i<nelems; i++) buf[i] = 0;
130145
err = ncmpi_get_att_text(ncid, varid, "large_attr", buf);
131146
CHECK_ERR
132147

148+
for (i=0; i<nelems; i++) {
149+
char expect = 'a' + i % 16;
150+
if (buf[i] != 'a' + i % 16) {
151+
printf("Error at %s line %d: expecting attr[%zd] value %c but got %c\n",
152+
__FILE__,__LINE__,i,expect,buf[i]);
153+
nerrs++;
154+
break;
155+
}
156+
}
157+
158+
err = ncmpi_close(ncid); CHECK_ERR
159+
if (nerrs > 0) goto err_out;
160+
161+
/* create a new file and put 2 global attributes, total size > 2 GiB ----*/
162+
nelems /= 2;
163+
164+
cmode = NC_CLOBBER | NC_64BIT_DATA;
165+
err = ncmpi_create(MPI_COMM_WORLD, filename, cmode, info, &ncid);
166+
CHECK_ERR
167+
168+
/* put two global attributes (total size > 2GiB) */
169+
for (i=0; i<nelems; i++) buf[i] = 'a' + i % 16;
170+
err = ncmpi_put_att_text(ncid, NC_GLOBAL, "large_attr_0", nelems, buf);
171+
if (!(cmode & NC_64BIT_DATA)) EXP_ERR(NC_EINVAL)
172+
else CHECK_ERR
173+
174+
err = ncmpi_put_att_text(ncid, NC_GLOBAL, "large_attr_1", nelems, buf);
175+
if (!(cmode & NC_64BIT_DATA)) EXP_ERR(NC_EINVAL)
176+
else CHECK_ERR
177+
178+
err = ncmpi_enddef(ncid); CHECK_ERR
179+
err = ncmpi_close(ncid); CHECK_ERR
180+
if (nerrs > 0) goto err_out;
181+
182+
/* open the file and read back the large global attributes --------------*/
183+
err = ncmpi_open(MPI_COMM_WORLD, filename, NC_NOWRITE, info, &ncid);
184+
CHECK_ERR
185+
if (err != NC_NOERR) goto err_out;
186+
187+
name = "large_attr_0";
188+
err = ncmpi_inq_attlen(ncid, NC_GLOBAL, name, &inq_nelems);
189+
if (inq_nelems != nelems) {
190+
printf("Error at %s line %d: expecting attr %s nelems %lld but got %lld\n",
191+
__FILE__,__LINE__,name, nelems,inq_nelems);
192+
nerrs++;
193+
}
194+
195+
for (i=0; i<nelems; i++) buf[i] = 0;
196+
err = ncmpi_get_att_text(ncid, NC_GLOBAL, name, buf);
197+
CHECK_ERR
198+
199+
for (i=0; i<nelems; i++) {
200+
char expect = 'a' + i % 16;
201+
if (buf[i] != 'a' + i % 16) {
202+
printf("Error at %s line %d: expecting attr[%zd] value %c but got %c\n",
203+
__FILE__,__LINE__,i,expect,buf[i]);
204+
nerrs++;
205+
break;
206+
}
207+
}
208+
209+
name = "large_attr_1";
210+
err = ncmpi_inq_attlen(ncid, NC_GLOBAL, name, &inq_nelems);
211+
if (inq_nelems != nelems) {
212+
printf("Error at %s line %d: expecting attr %s nelems %lld but got %lld\n",
213+
__FILE__,__LINE__,name, nelems,inq_nelems);
214+
nerrs++;
215+
}
216+
217+
for (i=0; i<nelems; i++) buf[i] = 0;
218+
err = ncmpi_get_att_text(ncid, NC_GLOBAL, name, buf);
219+
CHECK_ERR
220+
221+
for (i=0; i<nelems; i++) {
222+
char expect = 'a' + i % 16;
223+
if (buf[i] != 'a' + i % 16) {
224+
printf("Error at %s line %d: expecting attr[%zd] value %c but got %c\n",
225+
__FILE__,__LINE__,i,expect,buf[i]);
226+
nerrs++;
227+
break;
228+
}
229+
}
230+
231+
err = ncmpi_close(ncid); CHECK_ERR
232+
if (nerrs > 0) goto err_out;
233+
234+
/* create a new file and put 2 local attributes, total size > 2 GiB -----*/
235+
cmode = NC_CLOBBER | NC_64BIT_DATA;
236+
err = ncmpi_create(MPI_COMM_WORLD, filename, cmode, info, &ncid);
237+
CHECK_ERR
238+
239+
err = ncmpi_def_dim(ncid, "time", NC_UNLIMITED, &dimid);
240+
CHECK_ERR
241+
242+
err = ncmpi_def_var(ncid, "var", NC_INT, 1, &dimid, &varid);
243+
CHECK_ERR
244+
245+
for (i=0; i<nelems; i++) buf[i] = 'a' + i % 16;
246+
247+
/* put two local attributes (total size > 2GiB) */
248+
name = "large_attr_0";
249+
err = ncmpi_put_att_text(ncid, varid, name, nelems, buf);
250+
if (!(cmode & NC_64BIT_DATA)) EXP_ERR(NC_EINVAL)
251+
else CHECK_ERR
252+
253+
name = "large_attr_1";
254+
err = ncmpi_put_att_text(ncid, varid, name, nelems, buf);
255+
if (!(cmode & NC_64BIT_DATA)) EXP_ERR(NC_EINVAL)
256+
else CHECK_ERR
257+
258+
err = ncmpi_enddef(ncid); CHECK_ERR
259+
err = ncmpi_close(ncid); CHECK_ERR
260+
if (nerrs > 0) goto err_out;
261+
262+
/* open the file and read back the two local attributes -----------------*/
263+
err = ncmpi_open(MPI_COMM_WORLD, filename, NC_NOWRITE, info, &ncid);
264+
CHECK_ERR
265+
if (err != NC_NOERR) goto err_out;
266+
267+
err = ncmpi_inq_varid(ncid, "var", &varid);
268+
CHECK_ERR
269+
270+
name = "large_attr_0";
271+
err = ncmpi_inq_attlen(ncid, varid, name, &inq_nelems);
272+
if (inq_nelems != nelems) {
273+
printf("Error at %s line %d: expecting attr %s len %lld but got %lld\n",
274+
__FILE__,__LINE__,name,nelems,inq_nelems);
275+
nerrs++;
276+
}
277+
278+
for (i=0; i<nelems; i++) buf[i] = 0;
279+
err = ncmpi_get_att_text(ncid, varid, name, buf);
280+
CHECK_ERR
281+
282+
for (i=0; i<nelems; i++) {
283+
char expect = 'a' + i % 16;
284+
if (buf[i] != 'a' + i % 16) {
285+
printf("Error at %s line %d: expecting attr[%zd] value %c but got %c\n",
286+
__FILE__,__LINE__,i,expect,buf[i]);
287+
nerrs++;
288+
break;
289+
}
290+
}
291+
292+
name = "large_attr_1";
293+
err = ncmpi_inq_attlen(ncid, varid, name, &inq_nelems);
294+
if (inq_nelems != nelems) {
295+
printf("Error at %s line %d: expecting attr %s len %lld but got %lld\n",
296+
__FILE__,__LINE__,name,nelems,inq_nelems);
297+
nerrs++;
298+
}
299+
300+
for (i=0; i<nelems; i++) buf[i] = 0;
301+
err = ncmpi_get_att_text(ncid, varid, name, buf);
302+
CHECK_ERR
303+
304+
for (i=0; i<nelems; i++) {
305+
char expect = 'a' + i % 16;
306+
if (buf[i] != 'a' + i % 16) {
307+
printf("Error at %s line %d: expecting attr[%zd] value %c but got %c\n",
308+
__FILE__,__LINE__,i,expect,buf[i]);
309+
nerrs++;
310+
break;
311+
}
312+
}
313+
133314
err = ncmpi_close(ncid); CHECK_ERR
134315
if (nerrs > 0) goto err_out;
135316

0 commit comments

Comments
 (0)