summaryrefslogtreecommitdiffstats
path: root/test/testhdf5.c
blob: 175f711c227d40b9570e195ffd861f1bdfe7cbde (plain)
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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by the Board of Trustees of the University of Illinois.         *
 * 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 files COPYING and Copyright.html.  COPYING can be found at the root   *
 * of the source code distribution tree; Copyright.html can be found at the  *
 * root level of an installed copy of the electronic HDF5 document set and   *
 * is linked from the top-level documents page.  It can also be found at     *
 * http://hdf.ncsa.uiuc.edu/HDF5/doc/Copyright.html.  If you do not have     *
 * access to either file, you may request a copy from hdfhelp@ncsa.uiuc.edu. *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/* $Id$ */

/*
   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 InitTest() calls in main() below.  Functions which depend
   on other functionality should be placed below the InitTest() 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

   EXPORTED ROUTINES/VARIABLES:
   Two variables are exported: num_errs, and Verbosity.

 */

#if defined __MWERKS__
#include <console.h>
#endif

#include <stdarg.h>

#define MAXNUMOFTESTS 30
#define HDF5_TEST_MASTER

/* Internal Variables */
static int              Index = 0;

/* Global variables */
int                     num_errs = 0;
int                     Verbosity;

/* ANY new test needs to have a prototype in tproto.h */
#include "testhdf5.h"

struct TestStruct {
    int    NumErrors;
    char   Description[64];
    int    SkipFlag;
    char   Name[16];
    void (*Call) (void);
    void (*Cleanup) (void);
} Test[MAXNUMOFTESTS];

static void             InitTest(const char *TheName, void (*TheCall) (void), void (*Cleanup) (void), const char *TheDescr);
static void             usage(void);

static void 
InitTest(const char *TheName, void (*TheCall) (void), void (*Cleanup) (void), const char *TheDescr)
{
    if (Index >= MAXNUMOFTESTS) {
        print_func("Uh-oh, too many tests added, increase MAXNUMOFTEST!\n");
        exit(-1);
    }                           /* end if */
    HDstrcpy(Test[Index].Description, TheDescr);
    HDstrcpy(Test[Index].Name, TheName);
    Test[Index].Call = TheCall;
    Test[Index].Cleanup = Cleanup;
    Test[Index].NumErrors = -1;
    Test[Index].SkipFlag = 0;
    Index++;
}

static void 
usage(void)
{
    int                    i;

    print_func("Usage: testhdf5 [-v[erbose] (l[ow]|m[edium]|h[igh]|0-10)] \n");
    print_func("               [-[e]x[clude] name+] \n");
    print_func("               [-o[nly] name+] \n");
    print_func("               [-b[egin] name] \n");
    print_func("               [-s[ummary]]  \n");
    print_func("               [-c[leanoff]]  \n");
    print_func("               [-n[ocaching]]  \n");
    print_func("               [-h[elp]]  \n");
    print_func("\n\n");
    print_func("verbose   controls the amount of information displayed\n");
    print_func("exclude   to exclude tests by name\n");
    print_func("only      to name tests which should be run\n");
    print_func("begin     start at the name of the test givin\n");
    print_func("summary   prints a summary of test results at the end\n");
    print_func("cleanoff  does not delete *.hdf files after execution of tests\n");
    print_func("nocaching do not turn on low-level DD caching\n");
    print_func("help      print out this information\n");
    print_func("\n\n");
    print_func("This program currently tests the following: \n\n");
    print_func("%16s %s\n", "Name", "Description");
    print_func("%16s %s\n", "----", "-----------");
    for (i = 0; i < Index; i++)
        print_func("%16s %s\n", Test[i].Name, Test[i].Description);
    print_func("\n\n");
}                               /* end usage() */

/*
 * 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)
 */
int 
print_func(const char *format,...)
{
    va_list                 arglist;
    int                     ret_value;

    va_start(arglist, format);
    ret_value = vprintf(format, arglist);
    va_end(arglist);
    return (ret_value);
}

int 
main(int argc, char *argv[])
{
    int                     CLLoop;     /* Command Line Loop */
    int                     Loop, Loop1;
    int                     Summary = 0;
    int                     CleanUp = 1;
    int                     Cache = 1;
    unsigned                major, minor, release;

#if !(defined MAC || defined __MWERKS__ || defined SYMANTEC_C)
    /* Un-buffer the stdout and stderr */
    setbuf(stderr, NULL);
    setbuf(stdout, NULL);
#endif

    /*
     * Turn off automatic error reporting since we do it ourselves.  Besides,
     * half the functions this test calls are private, so automatic error
     * reporting wouldn't do much good since it's triggered at the API layer.
     */
#ifdef H5_WANT_H5_V1_6_COMPAT
    H5Eset_auto (NULL, NULL);
#else
    H5Eset_auto (H5E_DEFAULT, NULL, NULL);
#endif /* H5_WANT_H5_V1_6_COMPAT */

    /* Tests are generally arranged from least to most complexity... */
    InitTest("configure", test_configure, cleanup_configure, "Configure definitions");
    InitTest("metadata", test_metadata, cleanup_metadata, "Encode/decode metadata code");
    InitTest("tbbt", test_tbbt, NULL,  "Threaded, Balanced, Binary Trees");
    InitTest("tst", test_tst, NULL,  "Ternary Search Trees");
    InitTest("heap", test_heap, NULL,  "Memory Heaps");
    InitTest("refstr", test_refstr, NULL,  "Reference Counted Strings");
    InitTest("file", test_file, cleanup_file, "Low-Level File I/O");
    InitTest("h5s",  test_h5s,  cleanup_h5s,  "Dataspaces");
    InitTest("attr", test_attr, cleanup_attr,  "Attributes");
    InitTest("select", test_select, cleanup_select,  "Selections");
    InitTest("time", test_time, cleanup_time,  "Time Datatypes");
    InitTest("reference", test_reference, cleanup_reference,  "References");
    InitTest("vltypes", test_vltypes, cleanup_vltypes,  "Variable-Length Datatypes");
    InitTest("vlstrings", test_vlstrings, cleanup_vlstrings,  "Variable-Length Strings");
    InitTest("iterate", test_iterate, cleanup_iterate,  "Group & Attribute Iteration");
    InitTest("array", test_array, cleanup_array,  "Array Datatypes");
    InitTest("genprop", test_genprop, cleanup_genprop,  "Generic Properties");
    InitTest("misc", test_misc, cleanup_misc,  "Miscellaneous");

    Verbosity = 4;              /* Default Verbosity is Low */
    H5get_libversion(&major, &minor, &release);

    print_func("\nFor help use: testhdf5 -help\n");
    print_func("Linked with hdf5 version %u.%u release %u\n",
	       (unsigned)major, (unsigned)minor, (unsigned)release);
    for (CLLoop = 1; CLLoop < argc; CLLoop++) {
        if ((argc > CLLoop + 1) && ((HDstrcmp(argv[CLLoop], "-verbose") == 0) ||
                                    (HDstrcmp(argv[CLLoop], "-v") == 0))) {
            if (argv[CLLoop + 1][0] == 'l')
                Verbosity = 4;
            else if (argv[CLLoop + 1][0] == 'm')
                Verbosity = 6;
            else if (argv[CLLoop + 1][0] == 'h')
                Verbosity = 10;
            else
                Verbosity = atoi(argv[CLLoop + 1]);
        }                       /* end if */
        if ((argc > CLLoop) && ((HDstrcmp(argv[CLLoop], "-summary") == 0) ||
                                (HDstrcmp(argv[CLLoop], "-s") == 0)))
            Summary = 1;

        if ((argc > CLLoop) && ((HDstrcmp(argv[CLLoop], "-help") == 0) ||
                                (HDstrcmp(argv[CLLoop], "-h") == 0))) {
            usage();
            exit(0);
        }
        if ((argc > CLLoop) && ((HDstrcmp(argv[CLLoop], "-cleanoff") == 0) ||
                                (HDstrcmp(argv[CLLoop], "-c") == 0)))
            CleanUp = 0;

        if ((argc > CLLoop) && ((HDstrcmp(argv[CLLoop], "-nocache") == 0) ||
                                (HDstrcmp(argv[CLLoop], "-n") == 0))) {
            Cache = 0;
	    printf ("Cache = %d\n", Cache);
	}

        if ((argc > CLLoop + 1) && ((HDstrcmp(argv[CLLoop], "-exclude") == 0) ||
                                    (HDstrcmp(argv[CLLoop], "-x") == 0))) {
            Loop = CLLoop + 1;
            while ((Loop < argc) && (argv[Loop][0] != '-')) {
                for (Loop1 = 0; Loop1 < Index; Loop1++)
                    if (HDstrcmp(argv[Loop], Test[Loop1].Name) == 0)
                        Test[Loop1].SkipFlag = 1;
                Loop++;
            }                   /* end while */
        }                       /* end if */
        if ((argc > CLLoop + 1) && ((HDstrcmp(argv[CLLoop], "-begin") == 0) ||
                                    (HDstrcmp(argv[CLLoop], "-b") == 0))) {
            Loop = CLLoop + 1;
            while ((Loop < argc) && (argv[Loop][0] != '-')) {
                for (Loop1 = 0; Loop1 < Index; Loop1++) {
                    if (HDstrcmp(argv[Loop], Test[Loop1].Name) != 0)
                        Test[Loop1].SkipFlag = 1;
                    if (HDstrcmp(argv[Loop], Test[Loop1].Name) == 0)
                        Loop1 = Index;
                }               /* end for */
                Loop++;
            }                   /* end while */
        }                       /* end if */
        if ((argc > CLLoop + 1) && ((HDstrcmp(argv[CLLoop], "-only") == 0) ||
                                    (HDstrcmp(argv[CLLoop], "-o") == 0))) {
            for (Loop = 0; Loop < Index; Loop++)
                Test[Loop].SkipFlag = 1;
            Loop = CLLoop + 1;
            while ((Loop < argc) && (argv[Loop][0] != '-')) {
                for (Loop1 = 0; Loop1 < Index; Loop1++)
                    if (HDstrcmp(argv[Loop], Test[Loop1].Name) == 0)
                        Test[Loop1].SkipFlag = 0;
                Loop++;
            }                   /* end while */
        }                       /* end if */
    }                           /* end for */

#ifdef NOT_YET
    if (Cache)                  /* turn on caching, unless we were instucted not to */
        Hcache(CACHE_ALL_FILES, TRUE);
#endif /* NOT_YET */

    for (Loop = 0; Loop < Index; Loop++) {
        if (Test[Loop].SkipFlag) {
            MESSAGE(2, ("Skipping -- %s \n", Test[Loop].Description));
        } else {
            MESSAGE(2, ("Testing  -- %s (%s) \n", Test[Loop].Description,
                        Test[Loop].Name));
            MESSAGE(5, ("===============================================\n"));
            Test[Loop].NumErrors = num_errs;
            (*Test[Loop].Call) ();
            Test[Loop].NumErrors = num_errs - Test[Loop].NumErrors;
            MESSAGE(5, ("===============================================\n"));
            MESSAGE(5, ("There were %d errors detected.\n\n", (int) Test[Loop].NumErrors));
        }                       /* end else */
    }                           /* end for */

    MESSAGE(2, ("\n\n"))
        if (num_errs)
        print_func("!!! %d Error(s) were detected !!!\n\n", (int) num_errs);
    else
        print_func("All tests were successful. \n\n");

    if (Summary) {
        print_func("Summary of Test Results:\n");
        print_func("Name of Test     Errors Description of Test\n");
        print_func("---------------- ------ --------------------------------------\n");

        for (Loop = 0; Loop < Index; Loop++) {
            if (Test[Loop].NumErrors == -1)
                print_func("%16s %6s %s\n", Test[Loop].Name, "N/A", Test[Loop].Description);
            else
                print_func("%16s %6d %s\n", Test[Loop].Name, (int) Test[Loop].NumErrors,
                           Test[Loop].Description);
        }                       /* end for */
        print_func("\n\n");
    }                           /* end if */
    if (CleanUp && !getenv("HDF5_NOCLEANUP")) {
        MESSAGE(2, ("\nCleaning Up temp files...\n\n"));

        /* call individual cleanup routines in each source module */
        for (Loop = 0; Loop < Index; Loop++)
            if (!Test[Loop].SkipFlag && Test[Loop].Cleanup!=NULL)
                (*Test[Loop].Cleanup) ();
    }
    return (num_errs);
}                               /* end main() */