1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
|
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Copyright by The HDF Group. *
* All rights reserved. *
* *
* This file is part of HDF5. The full HDF5 copyright notice, including *
* terms governing use, modification, and redistribution, is contained in *
* the COPYING file, which can be found at the root of the source code *
* distribution tree, or in https://www.hdfgroup.org/licenses. *
* If you do not have access to either file, you may request a copy from *
* help@hdfgroup.org. *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/*
FILE
testhdf5.c - HDF5 testing framework main file.
REMARKS
General test wrapper for HDF5 base library test programs
DESIGN
Each test function should be implemented as function having no
parameters and returning void (i.e. no return value). They should be put
into the list of AddTest() calls in main() below. Functions which depend
on other functionality should be placed below the AddTest() call for the
base functionality testing.
Each test module should include testhdf5.h and define a unique set of
names for test files they create.
BUGS/LIMITATIONS
*/
/* ANY new test needs to have a prototype in testhdf5.h */
#include "testhdf5.h"
int nerrors = 0;
char *paraprefix = NULL; /* for command line option para-prefix */
/* Length of multi-file VFD filename buffers */
#define H5TEST_MULTI_FILENAME_LEN 1024
uint64_t vol_cap_flags_g = H5VL_CAP_FLAG_NONE;
/*
* This routine is designed to provide equivalent functionality to 'printf'
* and allow easy replacement for environments which don't have stdin/stdout
* available. (i.e. Windows & the Mac)
*/
H5_ATTR_FORMAT(printf, 1, 2)
int
print_func(const char *format, ...)
{
va_list arglist;
int ret_value;
va_start(arglist, format);
ret_value = HDvprintf(format, arglist);
va_end(arglist);
return ret_value;
}
/*
* This routine is designed to provide equivalent functionality to 'printf'
* and also increment the error count for the testing framework.
*/
int
TestErrPrintf(const char *format, ...)
{
va_list arglist;
int ret_value;
/* Increment the error count */
nerrors++;
/* Print the requested information */
va_start(arglist, format);
ret_value = HDvprintf(format, arglist);
va_end(arglist);
/* Return the length of the string produced (like printf() does) */
return ret_value;
}
#ifdef H5_HAVE_PARALLEL
/*-------------------------------------------------------------------------
* Function: getenv_all
*
* Purpose: Used to get the environment that the root MPI task has.
* name specifies which environment variable to look for
* val is the string to which the value of that environment
* variable will be copied.
*
* NOTE: The pointer returned by this function is only
* valid until the next call to getenv_all and the data
* stored there must be copied somewhere else before any
* further calls to getenv_all take place.
*
* Return: pointer to a string containing the value of the environment variable
* NULL if the variable doesn't exist in task 'root's environment.
*-------------------------------------------------------------------------
*/
char *
getenv_all(MPI_Comm comm, int root, const char *name)
{
int mpi_size, mpi_rank, mpi_initialized, mpi_finalized;
int len;
static char *env = NULL;
assert(name);
MPI_Initialized(&mpi_initialized);
MPI_Finalized(&mpi_finalized);
if (mpi_initialized && !mpi_finalized) {
MPI_Comm_rank(comm, &mpi_rank);
MPI_Comm_size(comm, &mpi_size);
assert(root < mpi_size);
/* The root task does the getenv call
* and sends the result to the other tasks */
if (mpi_rank == root) {
env = HDgetenv(name);
if (env) {
len = (int)HDstrlen(env);
MPI_Bcast(&len, 1, MPI_INT, root, comm);
MPI_Bcast(env, len, MPI_CHAR, root, comm);
}
else {
/* len -1 indicates that the variable was not in the environment */
len = -1;
MPI_Bcast(&len, 1, MPI_INT, root, comm);
}
}
else {
MPI_Bcast(&len, 1, MPI_INT, root, comm);
if (len >= 0) {
if (env == NULL)
env = (char *)malloc((size_t)len + 1);
else if (HDstrlen(env) < (size_t)len)
env = (char *)realloc(env, (size_t)len + 1);
MPI_Bcast(env, len, MPI_CHAR, root, comm);
env[len] = '\0';
}
else {
if (env)
free(env);
env = NULL;
}
}
#ifndef NDEBUG
MPI_Barrier(comm);
#endif
}
else {
/* use original getenv */
if (env)
free(env);
env = HDgetenv(name);
} /* end if */
return env;
}
#endif
/*-------------------------------------------------------------------------
* Function: h5_fileaccess
*
* Purpose: Returns a file access template which is the default template
* but with a file driver, VOL connector, or libver bound set
* according to a constant or environment variable
*
* Return: Success: A file access property list
* Failure: H5I_INVALID_HID
*
*-------------------------------------------------------------------------
*/
hid_t
h5_fileaccess(void)
{
hid_t fapl_id = H5I_INVALID_HID;
if ((fapl_id = H5Pcreate(H5P_FILE_ACCESS)) < 0)
goto error;
/* Finally, check for libver bounds */
if (h5_get_libver_fapl(fapl_id) < 0)
goto error;
return fapl_id;
error:
if (fapl_id != H5I_INVALID_HID)
H5Pclose(fapl_id);
return H5I_INVALID_HID;
} /* end h5_fileaccess() */
/*-------------------------------------------------------------------------
* Function: h5_get_libver_fapl
*
* Purpose: Sets the library version bounds for a FAPL according to the
* value in the constant or environment variable "HDF5_LIBVER_BOUNDS".
*
* Return: Success: 0
* Failure: -1
*
*-------------------------------------------------------------------------
*/
herr_t
h5_get_libver_fapl(hid_t fapl)
{
const char *env = NULL; /* HDF5_DRIVER environment variable */
const char *tok = NULL; /* strtok pointer */
char *lasts = NULL; /* Context pointer for strtok_r() call */
char buf[1024]; /* buffer for tokenizing HDF5_DRIVER */
/* Get the environment variable, if it exists */
env = HDgetenv("HDF5_LIBVER_BOUNDS");
#ifdef HDF5_LIBVER_BOUNDS
/* Use the environment variable, then the compile-time constant */
if (!env)
env = HDF5_LIBVER_BOUNDS;
#endif
/* If the environment variable was not set, just return
* without modifying the FAPL.
*/
if (!env || !*env)
goto done;
/* Get the first 'word' of the environment variable.
* If it's nothing (environment variable was whitespace)
* just return the default fapl.
*/
HDstrncpy(buf, env, sizeof(buf));
buf[sizeof(buf) - 1] = '\0';
if (NULL == (tok = HDstrtok_r(buf, " \t\n\r", &lasts)))
goto done;
if (!HDstrcmp(tok, "latest")) {
/* use the latest format */
if (H5Pset_libver_bounds(fapl, H5F_LIBVER_LATEST, H5F_LIBVER_LATEST) < 0)
goto error;
} /* end if */
else {
/* Unknown setting */
goto error;
} /* end else */
done:
return 0;
error:
return -1;
} /* end h5_get_libver_fapl() */
#ifndef HDF5_PARAPREFIX
#define HDF5_PARAPREFIX ""
#endif
static char *
h5_fixname_real(const char *base_name, hid_t fapl, const char *_suffix, char *fullname, size_t size,
hbool_t nest_printf, hbool_t subst_for_superblock)
{
const char *prefix = NULL;
const char *driver_env_var = NULL; /* HDF5_DRIVER environment variable */
char *ptr, last = '\0';
const char *suffix = _suffix;
size_t i, j;
hid_t driver = -1;
int isppdriver = 0; /* if the driver is MPI parallel */
if (!base_name || !fullname || size < 1)
return NULL;
memset(fullname, 0, size);
/* Determine if driver is set by environment variable. If it is,
* only generate a suffix if fixing the filename for the superblock
* file. */
driver_env_var = HDgetenv(HDF5_DRIVER);
if (driver_env_var && (H5P_DEFAULT == fapl) && subst_for_superblock)
fapl = H5P_FILE_ACCESS_DEFAULT;
/* figure out the suffix */
if (H5P_DEFAULT != fapl) {
if ((driver = H5Pget_driver(fapl)) < 0)
return NULL;
if (suffix) {
if (H5FD_FAMILY == driver) {
if (subst_for_superblock)
suffix = "-000000.h5";
else
suffix = nest_printf ? "-%%06d.h5" : "-%06d.h5";
}
else if (H5FD_MULTI == driver) {
/* Check the HDF5_DRIVER environment variable in case
* we are using the split driver since both of those
* use the multi VFD under the hood.
*/
if (driver_env_var && !HDstrcmp(driver_env_var, "split")) {
/* split VFD */
if (subst_for_superblock)
suffix = ".h5.meta";
}
else {
/* multi VFD */
if (subst_for_superblock)
suffix = "-s.h5";
else
suffix = NULL;
}
}
}
}
/* Must first check fapl is not H5P_DEFAULT (-1) because H5FD_XXX
* could be of value -1 if it is not defined.
*/
isppdriver = ((H5P_DEFAULT != fapl) || driver_env_var) && (H5FD_MPIO == driver);
#if 0
/* Check HDF5_NOCLEANUP environment setting.
* (The #ifdef is needed to prevent compile failure in case MPI is not
* configured.)
*/
if (isppdriver) {
#ifdef H5_HAVE_PARALLEL
if (getenv_all(MPI_COMM_WORLD, 0, HDF5_NOCLEANUP))
SetTestNoCleanup();
#endif /* H5_HAVE_PARALLEL */
}
else {
if (HDgetenv(HDF5_NOCLEANUP))
SetTestNoCleanup();
}
#endif
/* Check what prefix to use for test files. Process HDF5_PARAPREFIX and
* HDF5_PREFIX.
* Use different ones depending on parallel or serial driver used.
* (The #ifdef is needed to prevent compile failure in case MPI is not
* configured.)
*/
if (isppdriver) {
#ifdef H5_HAVE_PARALLEL
/*
* For parallel:
* First use command line option, then the environment
* variable, then try the constant
*/
static int explained = 0;
prefix = (paraprefix ? paraprefix : getenv_all(MPI_COMM_WORLD, 0, "HDF5_PARAPREFIX"));
if (!prefix && !explained) {
/* print hint by process 0 once. */
int mpi_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &mpi_rank);
if (mpi_rank == 0)
printf("*** Hint ***\n"
"You can use environment variable HDF5_PARAPREFIX to "
"run parallel test files in a\n"
"different directory or to add file type prefix. e.g.,\n"
" HDF5_PARAPREFIX=pfs:/PFS/user/me\n"
" export HDF5_PARAPREFIX\n"
"*** End of Hint ***\n");
explained = TRUE;
#ifdef HDF5_PARAPREFIX
prefix = HDF5_PARAPREFIX;
#endif /* HDF5_PARAPREFIX */
}
#endif /* H5_HAVE_PARALLEL */
}
else {
/*
* For serial:
* First use the environment variable, then try the constant
*/
prefix = HDgetenv("HDF5_PREFIX");
#ifdef HDF5_PREFIX
if (!prefix)
prefix = HDF5_PREFIX;
#endif /* HDF5_PREFIX */
}
/* Prepend the prefix value to the base name */
if (prefix && *prefix) {
if (isppdriver) {
/* This is a parallel system */
char *subdir;
if (!HDstrcmp(prefix, HDF5_PARAPREFIX)) {
/*
* If the prefix specifies the HDF5_PARAPREFIX directory, then
* default to using the "/tmp/$USER" or "/tmp/$LOGIN"
* directory instead.
*/
char *user, *login;
user = HDgetenv("USER");
login = HDgetenv("LOGIN");
subdir = (user ? user : login);
if (subdir) {
for (i = 0; i < size && prefix[i]; i++)
fullname[i] = prefix[i];
fullname[i++] = '/';
for (j = 0; i < size && subdir[j]; ++i, ++j)
fullname[i] = subdir[j];
}
}
if (!fullname[0]) {
/* We didn't append the prefix yet */
HDstrncpy(fullname, prefix, size);
fullname[size - 1] = '\0';
}
if (HDstrlen(fullname) + HDstrlen(base_name) + 1 < size) {
/*
* Append the base_name with a slash first. Multiple
* slashes are handled below.
*/
h5_stat_t buf;
if (HDstat(fullname, &buf) < 0)
/* The directory doesn't exist just yet */
if (HDmkdir(fullname, (mode_t)0755) < 0 && errno != EEXIST)
/*
* We couldn't make the "/tmp/${USER,LOGIN}"
* subdirectory. Default to PREFIX's original
* prefix value.
*/
HDstrcpy(fullname, prefix);
HDstrcat(fullname, "/");
HDstrcat(fullname, base_name);
}
else {
/* Buffer is too small */
return NULL;
}
}
else {
if (HDsnprintf(fullname, size, "%s/%s", prefix, base_name) == (int)size)
/* Buffer is too small */
return NULL;
}
}
else if (HDstrlen(base_name) >= size) {
/* Buffer is too small */
return NULL;
}
else {
HDstrcpy(fullname, base_name);
}
/* Append a suffix */
if (suffix) {
if (HDstrlen(fullname) + HDstrlen(suffix) >= size)
return NULL;
HDstrcat(fullname, suffix);
}
/* Remove any double slashes in the filename */
for (ptr = fullname, i = j = 0; ptr && i < size; i++, ptr++) {
if (*ptr != '/' || last != '/')
fullname[j++] = *ptr;
last = *ptr;
}
return fullname;
}
char *
h5_fixname(const char *base_name, hid_t fapl, char *fullname, size_t size)
{
return (h5_fixname_real(base_name, fapl, ".h5", fullname, size, FALSE, FALSE));
}
char *
h5_fixname_superblock(const char *base_name, hid_t fapl_id, char *fullname, size_t size)
{
return (h5_fixname_real(base_name, fapl_id, ".h5", fullname, size, FALSE, TRUE));
}
hbool_t
h5_using_default_driver(const char *drv_name)
{
hbool_t ret_val = TRUE;
assert(H5_DEFAULT_VFD == H5FD_SEC2);
if (!drv_name)
drv_name = HDgetenv(HDF5_DRIVER);
if (drv_name)
return (!HDstrcmp(drv_name, "sec2") || !HDstrcmp(drv_name, "nomatch"));
return ret_val;
}
herr_t
h5_driver_is_default_vfd_compatible(hid_t fapl_id, hbool_t *default_vfd_compatible)
{
unsigned long feat_flags = 0;
hid_t driver_id = H5I_INVALID_HID;
herr_t ret_value = SUCCEED;
assert(fapl_id >= 0);
assert(default_vfd_compatible);
if (fapl_id == H5P_DEFAULT)
fapl_id = H5P_FILE_ACCESS_DEFAULT;
if ((driver_id = H5Pget_driver(fapl_id)) < 0)
return FAIL;
if (H5FDdriver_query(driver_id, &feat_flags) < 0)
return FAIL;
*default_vfd_compatible = (feat_flags & H5FD_FEAT_DEFAULT_VFD_COMPATIBLE);
return ret_value;
} /* end h5_driver_is_default_vfd_compatible() */
int
main(int argc, char *argv[])
{
#if defined(H5_PARALLEL_TEST)
MPI_Init(&argc, &argv);
#else
(void)argc;
(void)argv;
#endif
printf("===================================\n");
printf("HDF5 TESTS START\n");
printf("===================================\n");
/* Initialize testing framework */
/* TestInit(argv[0], NULL, NULL); */
/* Tests are generally arranged from least to most complexity... */
/* AddTest("config", test_configure, cleanup_configure, "Configure definitions", NULL); */
printf("** CONFIGURE DEFINITIONS **\n");
test_configure();
printf("\n");
/* AddTest("metadata", test_metadata, cleanup_metadata, "Encoding/decoding metadata", NULL); */
/* AddTest("checksum", test_checksum, cleanup_checksum, "Checksum algorithm", NULL); */
printf("** CHECKSUM ALGORITHM **\n");
test_checksum();
printf("\n");
/* AddTest("tst", test_tst, NULL, "Ternary Search Trees", NULL); */
/* AddTest("heap", test_heap, NULL, "Memory Heaps", NULL); */
/* AddTest("skiplist", test_skiplist, NULL, "Skip Lists", NULL); */
/* AddTest("refstr", test_refstr, NULL, "Reference Counted Strings", NULL); */
/* AddTest("file", test_file, cleanup_file, "Low-Level File I/O", NULL); */
printf("** LOW-LEVEL FILE I/O **\n");
test_file();
printf("\n");
/* AddTest("objects", test_h5o, cleanup_h5o, "Generic Object Functions", NULL); */
printf("** GENERIC OBJECT FUNCTIONS **\n");
test_h5o();
printf("\n");
/* AddTest("h5s", test_h5s, cleanup_h5s, "Dataspaces", NULL); */
printf("** DATASPACES **\n");
test_h5s();
printf("\n");
/* AddTest("coords", test_coords, cleanup_coords, "Dataspace coordinates", NULL); */
printf("** DATASPACE COORDINATES **\n");
test_coords();
printf("\n");
/* AddTest("sohm", test_sohm, cleanup_sohm, "Shared Object Header Messages", NULL); */
/* AddTest("attr", test_attr, cleanup_attr, "Attributes", NULL); */
printf("** ATTRIBUTES **\n");
test_attr();
printf("\n");
/* AddTest("select", test_select, cleanup_select, "Selections", NULL); */
printf("** SELECTIONS **\n");
test_select();
printf("\n");
/* AddTest("time", test_time, cleanup_time, "Time Datatypes", NULL); */
printf("** TIME DATATYPES**\n");
test_time();
printf("\n");
/* AddTest("ref_deprec", test_reference_deprec, cleanup_reference_deprec, "Deprecated References", NULL);
*/
/* AddTest("ref", test_reference, cleanup_reference, "References", NULL); */
printf("** REFERENCES **\n");
test_reference();
printf("\n");
/* AddTest("vltypes", test_vltypes, cleanup_vltypes, "Variable-Length Datatypes", NULL); */
printf("** VARIABLE-LENGTH DATATYPES **\n");
test_vltypes();
printf("\n");
/* AddTest("vlstrings", test_vlstrings, cleanup_vlstrings, "Variable-Length Strings", NULL); */
printf("** VARIABLE-LENGTH STRINGS **\n");
test_vlstrings();
printf("\n");
/* AddTest("iterate", test_iterate, cleanup_iterate, "Group & Attribute Iteration", NULL); */
printf("** GROUP & ATTRIBUTE ITERATION **\n");
test_iterate();
printf("\n");
/* AddTest("array", test_array, cleanup_array, "Array Datatypes", NULL); */
printf("** ARRAY DATATYPES **\n");
test_array();
printf("\n");
/* AddTest("genprop", test_genprop, cleanup_genprop, "Generic Properties", NULL); */
printf("** GENERIC PROPERTIES **\n");
test_genprop();
printf("\n");
/* AddTest("unicode", test_unicode, cleanup_unicode, "UTF-8 Encoding", NULL); */
printf("** UTF-8 ENCODING **\n");
test_unicode();
printf("\n");
/* AddTest("id", test_ids, NULL, "User-Created Identifiers", NULL); */
printf("** USER-CREATED IDENTIFIERS **\n");
test_ids();
printf("\n");
/* AddTest("misc", test_misc, cleanup_misc, "Miscellaneous", NULL); */
printf("** MISCELLANEOUS **\n");
test_misc();
printf("\n");
/* Display testing information */
/* TestInfo(argv[0]); */
/* Parse command line arguments */
/* TestParseCmdLine(argc,argv); */
/* Perform requested testing */
/* PerformTests(); */
/* Display test summary, if requested */
/* if (GetTestSummary())
TestSummary(); */
/* Clean up test files, if allowed */
if (/* GetTestCleanup() && */ !getenv("HDF5_NOCLEANUP")) {
/* TestCleanup(); */
printf("TEST CLEANUP\n");
H5E_BEGIN_TRY
cleanup_configure();
cleanup_checksum();
cleanup_file();
cleanup_h5o();
cleanup_h5s();
cleanup_coords();
cleanup_attr();
cleanup_select();
cleanup_time();
cleanup_reference();
cleanup_vltypes();
cleanup_vlstrings();
cleanup_iterate();
cleanup_array();
cleanup_genprop();
cleanup_unicode();
cleanup_misc();
H5E_END_TRY;
printf("\n");
}
/* Release test infrastructure */
/* TestShutdown(); */
/* Exit failure if errors encountered; else exit success. */
/* No need to print anything since PerformTests() already does. */
if (nerrors /* GetTestNumErrs() */ > 0) {
printf("** HDF5 tests failed with %d errors **\n", nerrors);
exit(EXIT_FAILURE);
}
else {
printf("** HDF5 tests ran successfully **\n");
exit(EXIT_SUCCESS);
}
} /* end main() */
|