summaryrefslogtreecommitdiffstats
path: root/test/swmr_remove_reader.c
blob: 1fae5e713b0550f2d7e2e569b46905880834e312 (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
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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Copyright by The HDF Group.                                               *
 * 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 COPYING file, which can be found at the root of the source code       *
 * distribution tree, or in https://support.hdfgroup.org/ftp/HDF5/releases.  *
 * If you do not have access to either file, you may request a copy from     *
 * help@hdfgroup.org.                                                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/*-------------------------------------------------------------------------
 *
 * Created:     swmr_remove_reader.c
 *
 * Purpose:     Reads data from a randomly selected subset of the datasets
 *              in the SWMR test file.  Unlike the regular reader, these
 *              datasets will be shrinking.
 *
 *              This program is intended to run concurrently with the
 *              swmr_remove_writer program.
 *
 *-------------------------------------------------------------------------
 */

/***********/
/* Headers */
/***********/

#include "h5test.h"
#include "swmr_common.h"

/*******************/
/* Local Variables */
/*******************/

static hid_t symbol_tid = -1;

/********************/
/* Local Prototypes */
/********************/

static int check_dataset(hid_t fid, unsigned verbose, const char *sym_name,
    symbol_t *record, hid_t rec_sid);
static int read_records(const char *filename, unsigned verbose, unsigned long nseconds,
    unsigned poll_time, unsigned ncommon, unsigned nrandom);
static void usage(void);


/*-------------------------------------------------------------------------
 * Function:    check_dataset
 *
 * Purpose:     For a given dataset, checks to make sure that the stated
 *              and actual sizes are the same.  If they are not, then
 *              we have an inconsistent dataset due to a SWMR error.
 *
 * Parameters:  hid_t fid
 *              The SWMR test file's ID.
 *
 *              unsigned verbose
 *              Whether verbose console output is desired.
 *
 *              const char *sym_name
 *              The name of the dataset from which to read.
 *
 *              symbol_t *record
 *              Memory for the record.  Must be pre-allocated.
 *
 *              hid_t rec_sid
 *              The memory dataspace for access.  It's always the same so
 *              there is no need to re-create it every time this function
 *              is called.
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *-------------------------------------------------------------------------
 */
static int
check_dataset(hid_t fid, unsigned verbose, const char *sym_name, symbol_t *record,
    hid_t rec_sid)
{
    hid_t dsid;                 /* Dataset ID */
    hid_t file_sid;             /* Dataset's space ID */
    hssize_t snpoints;          /* Number of elements in dataset */
    hsize_t start[2] = {0, 0}, count[2] = {1, 1}; /* Hyperslab selection values */

    HDassert(fid >= 0);
    HDassert(sym_name);
    HDassert(record);
    HDassert(rec_sid >= 0);

    /* Open dataset for symbol */
    if((dsid = H5Dopen2(fid, sym_name, H5P_DEFAULT)) < 0)
        return -1;

    /* Get the dataset's dataspace */
    if((file_sid = H5Dget_space(dsid)) < 0)
        return -1;

    /* Get the number of elements (= records, for 1-D datasets) */
    if((snpoints = H5Sget_simple_extent_npoints(file_sid)) < 0)
        return -1;

    /* Emit informational message */
    if(verbose)
        HDfprintf(stderr, "Symbol = '%s', # of records = %lld\n", sym_name, (long long)snpoints);

    /* Check if there are records for symbol */
    if(snpoints > 0) {
        /* Choose a random record in the dataset, choosing the last record half
         * the time */
        start[1] = (hsize_t)(HDrandom() % (snpoints * 2));
        if(start[1] > (hsize_t)(snpoints - 1))
            start[1] = (hsize_t)(snpoints - 1);
        if(H5Sselect_hyperslab(file_sid, H5S_SELECT_SET, start, NULL, count, NULL) < 0)
            return -1;

        /* Read record from dataset */
#ifdef FILLVAL_WORKS
        /* When shrinking the dataset, we cannot guarantee that the buffer will
         * even be touched, unless there is a fill value.  Since fill values do
         * not work with SWMR currently (see note in swmr_generator.c), we
         * simply initialize rec_id to 0. */
        record->rec_id = (uint64_t)ULLONG_MAX - 1;
#else /* FILLVAL_WORKS */
        record->rec_id = (uint64_t)0;
#endif /* FILLVAL_WORKS */
        if(H5Dread(dsid, symbol_tid, rec_sid, file_sid, H5P_DEFAULT, record) < 0)
            return -1;

        /* Verify record value - note that it may be the fill value, because the
         * chunk may be deleted before the object header has the updated
         * dimensions */
        if(record->rec_id != start[1] && record->rec_id != (uint64_t)0) {
            HDfprintf(stderr, "*** ERROR ***\n");
            HDfprintf(stderr, "Incorrect record value!\n");
            HDfprintf(stderr, "Symbol = '%s', # of records = %lld, record->rec_id = %llx\n", sym_name, (long long)snpoints, (unsigned long long)record->rec_id);
            return -1;
        } /* end if */
    } /* end if */

    /* Close the dataset's dataspace */
    if(H5Sclose(file_sid) < 0)
        return -1;

    /* Close dataset for symbol */
    if(H5Dclose(dsid) < 0)
        return -1;

    return 0;
} /* end check_dataset() */


/*-------------------------------------------------------------------------
 * Function:    read_records
 *
 * Purpose:     For a given dataset, checks to make sure that the stated
 *              and actual sizes are the same.  If they are not, then
 *              we have an inconsistent dataset due to a SWMR error.
 *
 *              The "common" datasets are a random selection from among
 *              the level 0 datasets.  The "random" datasets are a random
 *              selection from among all the file's datasets.  This scheme
 *              ensures that the level 0 datasets are interrogated vigorously.
 *
 * Parameters:  const char *filename
 *              The SWMR test file's name.
 *
 *              unsigned verbose
 *              Whether verbose console output is desired.
 *
 *              unsigned long nseconds
 *              The amount of time to read records (ns).
 *
 *              unsigned poll_time
 *              The amount of time to sleep (s).
 *
 *              unsigned ncommon
 *              The number of common/non-random datasets that will be opened.
 *
 *              unsigned nrandom
 *              The number of random datasets that will be opened.
 *
 * Return:      Success:    0
 *              Failure:    -1
 *
 *-------------------------------------------------------------------------
 */
static int
read_records(const char *filename, unsigned verbose, unsigned long nseconds,
    unsigned poll_time, unsigned ncommon, unsigned nrandom)
{
    time_t start_time;          /* Starting time */
    time_t curr_time;           /* Current time */
    symbol_info_t **sym_com = NULL;     /* Pointers to array of common dataset IDs */
    symbol_info_t **sym_rand = NULL;    /* Pointers to array of random dataset IDs */
    hid_t mem_sid;              /* Memory dataspace ID */
    hid_t fid;                  /* SWMR test file ID */
    hid_t fapl;                 /* File access property list */
    symbol_t record;            /* The record to add to the dataset */
    unsigned v;                 /* Local index variable */

    HDassert(filename);
    HDassert(nseconds != 0);
    HDassert(poll_time != 0);

    /* Reset the record */
    /* (record's 'info' field might need to change for each record written, also) */
    HDmemset(&record, 0, sizeof(record));

    /* Emit informational message */
    if(verbose)
        HDfprintf(stderr, "Choosing datasets\n");

    /* Allocate space for 'common' datasets, if any */
    if(ncommon > 0) {
        /* Allocate array to hold pointers to symbols for common datasets */
        if(NULL == (sym_com = (symbol_info_t **)HDmalloc(sizeof(symbol_info_t *) * ncommon)))
            return -1;

        /* Open the common datasets */
        for(v = 0; v < ncommon; v++) {
            unsigned offset;                /* Offset of symbol to use */

            /* Determine the offset of the symbol, within level 0 symbols */
            /* (level 0 symbols are the most common symbols) */
            offset = (unsigned)HDrandom() % symbol_count[0];
            sym_com[v] = &symbol_info[0][offset];

            /* Emit informational message */
            if(verbose)
                HDfprintf(stderr, "Common symbol #%u = '%s'\n", v, symbol_info[0][offset].name);
        } /* end for */
    } /* end if */

    /* Allocate space for 'random' datasets, if any */
    if(nrandom > 0) {
        /* Allocate array to hold pointers to symbols for random datasets */
        if(NULL == (sym_rand = (symbol_info_t **)HDmalloc(sizeof(symbol_info_t *) * nrandom)))
            return -1;

        /* Determine the random datasets */
        for(v = 0; v < nrandom; v++) {
            symbol_info_t *sym;         /* Symbol to use */

            /* Determine the symbol, within all symbols */
            if(NULL == (sym = choose_dataset()))
                return -1;
            sym_rand[v] = sym;

            /* Emit informational message */
            if(verbose)
                HDfprintf(stderr, "Random symbol #%u = '%s'\n", v, sym->name);
        } /* end for */
    } /* end if */

    /* Create a dataspace for the record to read */
    if((mem_sid = H5Screate(H5S_SCALAR)) < 0)
        return -1;

    /* Emit informational message */
    if(verbose)
        HDfprintf(stderr, "Reading records\n");

    /* Get the starting time */
    start_time = HDtime(NULL);
    curr_time = start_time;

    /* Create file access property list */
    if((fapl = h5_fileaccess()) < 0)
        return -1;

    /* Loop over reading records until [at least] the correct # of seconds have passed */
    while(curr_time < (time_t)(start_time + (time_t)nseconds)) {

        /* Emit informational message */
        if(verbose)
             HDfprintf(stderr, "Opening file: %s\n", filename);

        /* Open the file */
        if((fid = H5Fopen(filename, H5F_ACC_RDONLY | H5F_ACC_SWMR_READ, fapl)) < 0)
            return -1;

        /* Check 'common' datasets, if any */
        if(ncommon > 0) {
            /* Emit informational message */
            if(verbose)
                HDfprintf(stderr, "Checking common symbols\n");

            /* Iterate over common datasets */
            for(v = 0; v < ncommon; v++) {
                /* Check common dataset */
                if(check_dataset(fid, verbose, sym_com[v]->name, &record, mem_sid) < 0)
                    return -1;
                HDmemset(&record, 0, sizeof(record));
            } /* end for */
        } /* end if */

        /* Check 'random' datasets, if any */
        if(nrandom > 0) {
            /* Emit informational message */
            if(verbose)
                HDfprintf(stderr, "Checking random symbols\n");

            /* Iterate over random datasets */
            for(v = 0; v < nrandom; v++) {
                /* Check random dataset */
                if(check_dataset(fid, verbose, sym_rand[v]->name, &record, mem_sid) < 0)
                    return -1;
                HDmemset(&record, 0, sizeof(record));
            } /* end for */
        } /* end if */

        /* Emit informational message */
        if(verbose)
            HDfprintf(stderr, "Closing file\n");

        /* Close the file */
        if(H5Fclose(fid) < 0)
            return -1;

        /* Sleep for the appropriate # of seconds */
        HDsleep(poll_time);

        /* Retrieve the current time */
        curr_time = HDtime(NULL);
    } /* end while */

    /* Close the fapl */
    if(H5Pclose(fapl) < 0)
        return -1;

    /* Close the memory dataspace */
    if(H5Sclose(mem_sid) < 0)
        return -1;

    /* Emit informational message */
    if(verbose)
        HDfprintf(stderr, "Closing datasets\n");

    /* Close 'random' datasets, if any */
    if(nrandom > 0) {
        /* Release array holding dataset ID's for random datasets */
        HDfree(sym_rand);
    } /* end if */

    /* Close 'common' datasets, if any */
    if(ncommon > 0) {
        /* Release array holding dataset ID's for common datasets */
        HDfree(sym_com);
    } /* end if */

    return 0;
} /* end read_records() */

static void
usage(void)
{
    printf("\n");
    printf("Usage error!\n");
    printf("\n");
    printf("Usage: swmr_remove_reader [-q] [-s <# of seconds to sleep between\n");
    printf("    polling>] [-h <# of common symbols to poll>] [-l <# of random symbols\n");
    printf("    to poll>] [-r <random seed>] <# of seconds to test>\n");
    printf("\n");
    printf("Defaults to verbose (no '-q' given), 1 second between polling ('-s 1'),\n");
    printf("5 common symbols to poll ('-h 5'), 10 random symbols to poll ('-l 10'),\n");
    printf("and will generate a random seed (no -r given).\n");
    printf("\n");
    HDexit(1);
} 

int main(int argc, const char *argv[])
{
    long nseconds = 0;      /* # of seconds to test */
    int poll_time = 1;      /* # of seconds between polling */
    int ncommon = 5;        /* # of common symbols to poll */
    int nrandom = 10;       /* # of random symbols to poll */
    unsigned verbose = 1;   /* Whether to emit some informational messages */
    unsigned use_seed = 0;  /* Set to 1 if a seed was set on the command line */
    unsigned random_seed = 0;   /* Random # seed */
    unsigned u;             /* Local index variables */
    int temp;

    /* Parse command line options */
    if(argc < 2)
        usage();
    if(argc > 1) {
        u = 1;
        while(u < (unsigned)argc) {
            if(argv[u][0] == '-') {
                switch(argv[u][1]) {
                    /* # of common symbols to poll */
                    case 'h':
                        ncommon = HDatoi(argv[u + 1]);
                        if(ncommon < 0)
                            usage();
                        u += 2;
                        break;

                    /* # of random symbols to poll */
                    case 'l':
                        nrandom = HDatoi(argv[u + 1]);
                        if(nrandom < 0)
                            usage();
                        u += 2;
                        break;

                    /* Be quiet */
                    case 'q':
                        verbose = 0;
                        u++;
                        break;

                    /* Random # seed */
                    case 'r':
                        use_seed = 1;
                        temp = HDatoi(argv[u + 1]);
                        if(temp < 0)
                            usage();
                        else
                            random_seed = (unsigned)temp;
                        u += 2;
                        break;

                    /* # of seconds between polling */
                    case 's':
                        poll_time = HDatoi(argv[u + 1]);
                        if(poll_time < 0)
                            usage();
                        u += 2;
                        break;

                    default:
                        usage();
                        break;
                } /* end switch */
            } /* end if */
            else {
                /* Get the number of records to append */
                nseconds = HDatol(argv[u]);
                if(nseconds <= 0)
                    usage();

                u++;
            } /* end else */
        } /* end while */
    } /* end if */
    if(nseconds <= 0)
        usage();
    if(poll_time >= nseconds)
        usage();

    /* Emit informational message */
    if(verbose) {
        HDfprintf(stderr, "Parameters:\n");
        HDfprintf(stderr, "\t# of seconds between polling = %d\n", poll_time);
        HDfprintf(stderr, "\t# of common symbols to poll = %d\n", ncommon);
        HDfprintf(stderr, "\t# of random symbols to poll = %d\n", nrandom);
        HDfprintf(stderr, "\t# of seconds to test = %ld\n", nseconds);
    } /* end if */

    /* Set the random seed */
    if(0 == use_seed) {
        struct timeval t;
        HDgettimeofday(&t, NULL);
        random_seed = (unsigned)(t.tv_usec);
    } /* end if */
    HDsrandom(random_seed);
    /* ALWAYS emit the random seed for possible debugging */
    HDfprintf(stderr, "Using reader random seed: %u\n", random_seed);

    /* Emit informational message */
    if(verbose)
        HDfprintf(stderr, "Generating symbol names\n");

    /* Generate dataset names */
    if(generate_symbols() < 0) {
        HDfprintf(stderr, "Error generating symbol names!\n");
        HDexit(1);
    } /* end if */

    /* Create datatype for creating datasets */
    if((symbol_tid = create_symbol_datatype()) < 0)
        return -1;

    /* Reading records from datasets */
    if(read_records(FILENAME, verbose, (unsigned long)nseconds, (unsigned)poll_time, (unsigned)ncommon, (unsigned)nrandom) < 0) {
        HDfprintf(stderr, "Error reading records from datasets!\n");
        HDexit(1);
    } /* end if */

    /* Emit informational message */
    if(verbose)
        HDfprintf(stderr, "Releasing symbols\n");

    /* Clean up the symbols */
    if(shutdown_symbols() < 0) {
        HDfprintf(stderr, "Error releasing symbols!\n");
        HDexit(1);
    } /* end if */

    /* Emit informational message */
    if(verbose)
        HDfprintf(stderr, "Closing objects\n");

    /* Close objects created */
    if(H5Tclose(symbol_tid) < 0) {
        HDfprintf(stderr, "Error closing symbol datatype!\n");
        HDexit(1);
    } /* end if */

    return 0;
}
"> HDprintf("!!! Expected:\n%s\n!!!Actual:\n%s\n", \ (expected), (actual)); \ } \ } #ifdef JSVERIFY_EXP_ACT /*---------------------------------------------------------------------------- * * Macro: JSVERIFY() * * Purpose: * * Verify that two long integers are equal. * If unequal, print failure message * (with `reason`, if not NULL; expected/actual if NULL) * and jump to `error` at end of function * * Programmer: Jacob Smith * 2017-10-24 * *---------------------------------------------------------------------------- */ #define JSVERIFY(expected, actual, reason) \ if ((long)(actual) != (long)(expected)) { \ JSERR_LONG((expected), (actual), (reason)) \ goto error; \ } /* JSVERIFY */ /*---------------------------------------------------------------------------- * * Macro: JSVERIFY_NOT() * * Purpose: * * Verify that two long integers are _not_ equal. * If equal, print failure message * (with `reason`, if not NULL; expected/actual if NULL) * and jump to `error` at end of function * * Programmer: Jacob Smith * 2017-10-24 * *---------------------------------------------------------------------------- */ #define JSVERIFY_NOT(expected, actual, reason) \ if ((long)(actual) == (long)(expected)) { \ JSERR_LONG((expected), (actual), (reason)) \ goto error; \ } /* JSVERIFY_NOT */ /*---------------------------------------------------------------------------- * * Macro: JSVERIFY_STR() * * Purpose: * * Verify that two strings are equal. * If unequal, print failure message * (with `reason`, if not NULL; expected/actual if NULL) * and jump to `error` at end of function * * Programmer: Jacob Smith * 2017-10-24 * *---------------------------------------------------------------------------- */ #define JSVERIFY_STR(expected, actual, reason) \ if (strcmp((actual), (expected)) != 0) { \ JSERR_STR((expected), (actual), (reason)); \ goto error; \ } /* JSVERIFY_STR */ #else /* JSVERIFY_EXP_ACT not defined * * Repeats macros above, but with actual/expected parameters reversed. */ /*---------------------------------------------------------------------------- * Macro: JSVERIFY() * See: JSVERIFY documentation above. * Programmer: Jacob Smith * 2017-10-14 *---------------------------------------------------------------------------- */ #define JSVERIFY(actual, expected, reason) \ if ((long)(actual) != (long)(expected)) { \ JSERR_LONG((expected), (actual), (reason)); \ goto error; \ } /* JSVERIFY */ /*---------------------------------------------------------------------------- * Macro: JSVERIFY_NOT() * See: JSVERIFY_NOT documentation above. * Programmer: Jacob Smith * 2017-10-14 *---------------------------------------------------------------------------- */ #define JSVERIFY_NOT(actual, expected, reason) \ if ((long)(actual) == (long)(expected)) { \ JSERR_LONG((expected), (actual), (reason)) \ goto error; \ } /* JSVERIFY_NOT */ /*---------------------------------------------------------------------------- * Macro: JSVERIFY_STR() * See: JSVERIFY_STR documentation above. * Programmer: Jacob Smith * 2017-10-14 *---------------------------------------------------------------------------- */ #define JSVERIFY_STR(actual, expected, reason) \ if (strcmp((actual), (expected)) != 0) { \ JSERR_STR((expected), (actual), (reason)); \ goto error; \ } /* JSVERIFY_STR */ #endif /* ifdef/else JSVERIFY_EXP_ACT */ /******************************** * OTHER MACROS AND DEFINITIONS * ********************************/ /* copied from src/hdfs.c */ #ifdef H5_HAVE_LIBHDFS #define MAXADDR (((haddr_t)1<<(8*sizeof(HDoff_t)-1))-1) #endif /* H5_HAVE_LIBHDFS */ #define HDFS_NAMENODE_NAME_MAX_SIZE 128 /******************************* * FILE-LOCAL GLOBAL VARIABLES * *******************************/ #ifdef H5_HAVE_LIBHDFS static const char filename_missing[] = "/tmp/missing.txt"; static const char filename_bard[] = "/tmp/t8.shakespeare.txt"; static const char filename_raven[] = "/tmp/Poe_Raven.txt"; static const char filename_example_h5[] = "/tmp/t.h5"; #endif /* H5_HAVE_LIBHDFS */ static H5FD_hdfs_fapl_t default_fa = { 1, /* fa version */ "localhost", /* namenode name */ 0, /* namenode port */ "", /* user name */ "", /* kerberos path */ 1024, /* buffer size */ }; /****************** * TEST FUNCTIONS * ******************/ /*--------------------------------------------------------------------------- * * Function: test_fapl_config_validation() * * Purpose: * * Test data consistency of fapl configuration. * Tests `H5FD_hdfs_validate_config` indirectly through `H5Pset_fapl_hdfs`. * * Return: * * PASSED : 0 * FAILED : 1 * * Programmer: Jacob Smith * 2018-04-25 * * Changes: None. * *--------------------------------------------------------------------------- */ static int test_fapl_config_validation(void) { /********************* * test-local macros * *********************/ /************************* * test-local structures * *************************/ struct testcase { const char *msg; herr_t expected; H5FD_hdfs_fapl_t config; }; /************************ * test-local variables * ************************/ hid_t fapl_id = -1; /* file access property list ID */ H5FD_hdfs_fapl_t config; H5FD_hdfs_fapl_t fa_fetch; herr_t success = SUCCEED; unsigned int i = 0; unsigned int ncases = 6; /* should equal number of cases */ struct testcase *case_ptr = NULL; /* dumb work-around for possible */ /* dynamic cases creation because */ /* of compiler warnings Wlarger-than */ struct testcase cases_arr[] = { { "default config fapl", SUCCEED, { 1, /* version */ "localhost", /* namenode_name */ 0, /* namenode_port number */ "some_user", /* user_name */ "", /* kerberos_ticket_cache path */ -1, /* stream_buffer_size */ }, }, { "invalid version number (2)", FAIL, { 2, /* version */ "localhost", /* namenode_name */ 0, /* namenode_port number */ "some_user", /* user_name */ "", /* kerberos_ticket_cache path */ -1, /* stream_buffer_size */ }, }, { "invalid version number (0)", FAIL, { 0, /* version */ "localhost", /* namenode_name */ 0, /* namenode_port number */ "some_user", /* user_name */ "", /* kerberos_ticket_cache path */ -1, /* stream_buffer_size */ }, }, { "nonsense kerberos path still ok?", SUCCEED, { 1, /* version */ "localhost", /* namenode_name */ 0, /* namenode_port number */ "some_user", /* user_name */ "pathToSomewhere", /* kerberos_ticket_cache path */ -1, /* stream_buffer_size */ }, }, { "namenode port number too high", FAIL, { 1, /* version */ "localhost", /* namenode_name */ 88000, /* namenode_port number */ "some_user", /* user_name */ "", /* kerberos_ticket_cache path */ -1, /* stream_buffer_size */ }, }, { "negative namenode port number", FAIL, { 1, /* version */ "localhost", /* namenode_name */ -1, /* namenode_port number */ "some_user", /* user_name */ "", /* kerberos_ticket_cache path */ -1, /* stream_buffer_size */ }, }, }; TESTING("HDFS fapl configuration validation"); /********* * TESTS * *********/ for (i = 0; i < ncases; i++) { /*--------------- * per-test setup *--------------- */ case_ptr = &cases_arr[i]; fapl_id = H5Pcreate(H5P_FILE_ACCESS); FAIL_IF( fapl_id < 0 ) /* sanity-check */ /*----------------------------------- * Actually test -- set fapl. * Mute stack trace in failure cases. *----------------------------------- */ H5E_BEGIN_TRY { /* `H5FD_hdfs_validate_config(...)` is static/private * to src/hdfs.c and cannot (and should not?) be tested directly? * Instead, validate config through public api. */ success = H5Pset_fapl_hdfs(fapl_id, &case_ptr->config); } H5E_END_TRY; JSVERIFY( case_ptr->expected, success, case_ptr->msg ) /* Make sure we can get back what we put in. * Only valid if the fapl configuration does not result in error. */ if (success == SUCCEED) { config = case_ptr->config; JSVERIFY( SUCCEED, H5Pget_fapl_hdfs(fapl_id, &fa_fetch), "unable to get fapl" ) JSVERIFY( H5FD__CURR_HDFS_FAPL_T_VERSION, fa_fetch.version, "invalid version number" ) JSVERIFY( config.version, fa_fetch.version, "version number mismatch" ) JSVERIFY( config.namenode_port, fa_fetch.namenode_port, "namenode port mismatch" ) JSVERIFY( config.stream_buffer_size, fa_fetch.stream_buffer_size, "streambuffer size mismatch" ) JSVERIFY_STR( config.namenode_name, fa_fetch.namenode_name, NULL ) JSVERIFY_STR( config.user_name, fa_fetch.user_name, NULL ) JSVERIFY_STR( config.kerberos_ticket_cache, fa_fetch.kerberos_ticket_cache, NULL ) } /*----------------------------- * per-test sanitation/teardown *----------------------------- */ FAIL_IF( FAIL == H5Pclose(fapl_id) ) fapl_id = -1; } /* for each test case */ PASSED(); return 0; error: /*********** * CLEANUP * ***********/ if (fapl_id < 0) { H5E_BEGIN_TRY { (void)H5Pclose(fapl_id); } H5E_END_TRY; } return 1; } /* end test_fapl_config_validation() */ /*------------------------------------------------------------------------- * * Function: test_hdfs_fapl() * * Purpose: Tests the file handle interface for the HDFS driver. * * For now, test only fapl & flags. Extend as the * work on the VFD continues. * * Return: Success: 0 * Failure: 1 * * Programmer: Jacob Smith * 2018-04-25 * * Changes: None. * *------------------------------------------------------------------------- */ static int test_hdfs_fapl(void) { /************************ * test-local variables * ************************/ hid_t fapl_id = -1; /* file access property list ID */ hid_t driver_id = -1; /* ID for this VFD */ unsigned long driver_flags = 0; /* VFD feature flags */ H5FD_hdfs_fapl_t hdfs_fa_0 = { 1, /* version*/ "", /* node name */ 9000, /* node port */ "", /* username */ "", /* kerb cache path */ 1024, /* stream buffer size */ }; TESTING("HDFS fapl "); /* Set property list and file name for HDFS driver. */ fapl_id = H5Pcreate(H5P_FILE_ACCESS); FAIL_IF( fapl_id < 0 ) FAIL_IF( FAIL == H5Pset_fapl_hdfs(fapl_id, &hdfs_fa_0) ) driver_id = H5Pget_driver(fapl_id); FAIL_IF( driver_id < 0 ) /**************** * Check that the VFD feature flags are correct * SPEC MAY CHANGE ******************/ FAIL_IF( H5FDdriver_query(driver_id, &driver_flags) < 0 ) JSVERIFY_NOT( 0, (driver_flags & H5FD_FEAT_DATA_SIEVE), "bit(s) in `driver_flags` must align with " "H5FD_FEAT_DATA_SIEVE" ) JSVERIFY( H5FD_FEAT_DATA_SIEVE, driver_flags, "H5FD_FEAT_DATA_SIEVE should be the only supported flag") PASSED(); return 0; error: H5E_BEGIN_TRY { (void)H5Pclose(fapl_id); } H5E_END_TRY; return 1; } /* end test_hdfs_fapl() */ /*--------------------------------------------------------------------------- * * Function: test_vfd_open() * * Purpose: * * Demonstrate/specify VFD-level "Open" failure cases * * Return: * * PASSED : 0 * FAILED : 1 * * Programmer: Jacob Smith * 2018-06-07 * *--------------------------------------------------------------------------- */ static int test_vfd_open(void) { #ifndef H5_HAVE_LIBHDFS TESTING("HDFS VFD-level open"); SKIPPED(); puts(" HDFS VFD is not enabled"); fflush(stdout); return 0; #else /********************* * test-local macros * *********************/ /* selectors for which fapl to use in testcase */ #define FAPL_H5P_DEFAULT -2 #define FAPL_UNCONFIGURED -3 /* H5P_FILE_ACCESS */ #define FAPL_HDFS -4 /************************* * test-local structures * *************************/ struct test_condition { const char *message; const char *url; unsigned flags; int which_fapl; haddr_t maxaddr; hbool_t might_use_other_driver; }; /************************ * test-local variables * ************************/ struct test_condition failing_conditions[] = { { "default property list (H5P_DEFAULT) is invalid", filename_bard, H5F_ACC_RDONLY, FAPL_H5P_DEFAULT, MAXADDR, TRUE, }, { "generic file access property list is invalid", filename_bard, H5F_ACC_RDONLY, FAPL_UNCONFIGURED, MAXADDR, TRUE, }, { "filename cannot be null", NULL, H5F_ACC_RDONLY, FAPL_HDFS, MAXADDR, FALSE, }, { "filename cannot be empty", "", H5F_ACC_RDONLY, FAPL_HDFS, MAXADDR, FALSE, }, { "file at filename must exist", filename_missing, H5F_ACC_RDONLY, FAPL_HDFS, MAXADDR, FALSE, }, { "read-write flag not supported", filename_bard, H5F_ACC_RDWR, FAPL_HDFS, MAXADDR, FALSE, }, { "truncate flag not supported", filename_bard, H5F_ACC_TRUNC, FAPL_HDFS, MAXADDR, FALSE, }, { "create flag not supported", filename_bard, H5F_ACC_CREAT, FAPL_HDFS, MAXADDR, FALSE, }, { "EXCL flag not supported", filename_bard, H5F_ACC_EXCL, FAPL_HDFS, MAXADDR, FALSE, }, { "maxaddr cannot be 0 (caught in `H5FD_open()`)", filename_bard, H5F_ACC_RDONLY, FAPL_HDFS, 0, FALSE, }, }; unsigned i = 0; unsigned failing_conditions_count = 10; H5FD_t *fd = NULL; hid_t fapl_hdfs = -1; hid_t fapl_unconfigured = -1; TESTING("HDFS VFD-level open"); fapl_unconfigured = H5Pcreate(H5P_FILE_ACCESS); FAIL_IF( fapl_unconfigured < 0 ) fapl_hdfs = H5Pcreate(H5P_FILE_ACCESS); FAIL_IF( fapl_hdfs < 0 ) FAIL_IF( FAIL == H5Pset_fapl_hdfs(fapl_hdfs, &default_fa) ) /********* * TESTS * *********/ /* all the test cases that will _not_ open */ for (i = 0; i < failing_conditions_count; i++) { struct test_condition T = failing_conditions[i]; hid_t fapl_id = H5P_DEFAULT; fd = NULL; if (T.which_fapl == FAPL_UNCONFIGURED) { fapl_id = fapl_unconfigured; } else if (T.which_fapl == FAPL_HDFS) { fapl_id = fapl_hdfs; } #if HDFS_TEST_DEBUG HDfprintf(stderr, "testing: %s\n", T.message); #endif /* HDFS_TEST_DEBUG */ H5E_BEGIN_TRY { fd = H5FDopen(T.url, T.flags, fapl_id, T.maxaddr); } H5E_END_TRY; if (NULL != fd) { if (TRUE == T.might_use_other_driver && H5FD_HDFS != fd->driver_id) { HDfprintf(stderr, "\n!!!!! WARNING !!!!!\n" \ " Successful open of file on local system " \ "with non-HDFS VFD.\n"); JSVERIFY(SUCCEED, H5FDclose(fd), "unable to close errant open"); fd = NULL; } else { JSVERIFY(1, 0, T.message); /* print message and fail */ } } } FAIL_IF( NULL != fd ) /* sanity check */ #if HDFS_TEST_DEBUG HDfprintf(stderr, "nominal open\n"); #endif /* HDFS_TEST_DEBUG */ /* finally, show that a file can be opened */ fd = H5FDopen( filename_bard, H5F_ACC_RDONLY, fapl_hdfs, MAXADDR); FAIL_IF( NULL == fd ) /************ * TEARDOWN * ************/ #if HDFS_TEST_DEBUG HDfprintf(stderr, "teardown...\n"); #endif /* HDFS_TEST_DEBUG */ FAIL_IF( FAIL == H5FDclose(fd) ) fd = NULL; FAIL_IF( FAIL == H5Pclose(fapl_hdfs) ) fapl_hdfs = -1; FAIL_IF( FAIL == H5Pclose(fapl_unconfigured) ) fapl_unconfigured = -1; PASSED(); return 0; error: /*********** * CLEANUP * ***********/ if (fd) { (void)H5FDclose(fd); } H5E_BEGIN_TRY { if (fapl_hdfs >= 0) { (void)H5Pclose(fapl_hdfs); } if (fapl_unconfigured >= 0) { (void)H5Pclose(fapl_unconfigured); } } H5E_END_TRY; return 1; #undef FAPL_H5P_DEFAULT #undef FAPL_UNCONFIGURED #undef FAPL_HDFS #endif /* H5_HAVE_LIBHDFS */ } /* end test_vfd_open() */ /*--------------------------------------------------------------------------- * * Function: test_eof_eoa() * * Purpose: * * Demonstrate behavior of get_eof, get_eoa, and set_eoa. * * Return: * * PASSED : 0 * FAILED : 1 * * Programmer: Jacob Smith * 2018-06-07 * *--------------------------------------------------------------------------- */ static int test_eof_eoa(void) { #ifndef H5_HAVE_LIBHDFS TESTING("HDFS eof/eoa gets and sets"); SKIPPED(); puts(" HDFS VFD is not enabled"); fflush(stdout); return 0; #else /********************* * test-local macros * *********************/ /************************* * test-local structures * *************************/ /************************ * test-local variables * ************************/ H5FD_t *fd_shakespeare = NULL; hid_t fapl_id = -1; TESTING("HDFS eof/eoa gets and sets"); /********* * SETUP * *********/ fapl_id = H5Pcreate(H5P_FILE_ACCESS); FAIL_IF( 0 > fapl_id ) FAIL_IF( FAIL == H5Pset_fapl_hdfs(fapl_id, &default_fa) ) fd_shakespeare = H5FDopen( filename_bard, H5F_ACC_RDONLY, fapl_id, HADDR_UNDEF); FAIL_IF( NULL == fd_shakespeare ) /********* * TESTS * *********/ /* verify as found */ JSVERIFY( 5458199, H5FDget_eof(fd_shakespeare, H5FD_MEM_DEFAULT), NULL ) JSVERIFY( H5FDget_eof(fd_shakespeare, H5FD_MEM_DEFAULT), H5FDget_eof(fd_shakespeare, H5FD_MEM_DRAW), "mismatch between DEFAULT and RAW memory types" ) JSVERIFY( 0, H5FDget_eoa(fd_shakespeare, H5FD_MEM_DEFAULT), "EoA should be unset by H5FDopen" ) /* set EoA below EoF */ JSVERIFY( SUCCEED, H5FDset_eoa(fd_shakespeare, H5FD_MEM_DEFAULT, 44442202), "unable to set EoA (lower)" ) JSVERIFY( 5458199, H5FDget_eof(fd_shakespeare, H5FD_MEM_DEFAULT), "EoF changed" ) JSVERIFY( 44442202, H5FDget_eoa(fd_shakespeare, H5FD_MEM_DEFAULT), "EoA unchanged" ) /* set EoA above EoF */ JSVERIFY( SUCCEED, H5FDset_eoa(fd_shakespeare, H5FD_MEM_DEFAULT, 6789012), "unable to set EoA (higher)" ) JSVERIFY( 5458199, H5FDget_eof(fd_shakespeare, H5FD_MEM_DEFAULT), "EoF changed" ) JSVERIFY( 6789012, H5FDget_eoa(fd_shakespeare, H5FD_MEM_DEFAULT), "EoA unchanged" ) /************ * TEARDOWN * ************/ FAIL_IF( FAIL == H5FDclose(fd_shakespeare) ) fd_shakespeare = NULL; FAIL_IF( FAIL == H5Pclose(fapl_id) ) fapl_id = -1; PASSED(); return 0; error: /*********** * CLEANUP * ***********/ if (fd_shakespeare != NULL) { (void)H5FDclose(fd_shakespeare); } if (fapl_id >= 0) { H5E_BEGIN_TRY { (void)H5Pclose(fapl_id); } H5E_END_TRY; } return 1; #endif /* H5_HAVE_LIBHDFS */ } /* end test_eof_eoa() */ /*----------------------------------------------------------------------------- * * Function: test_H5FDread_without_eoa_set_fails() * * Purpose: * * Demonstrate a not-obvious constraint by the library, preventing * file read before EoA is set * * Programmer: Jacob Smith * 2018-06-08 * *----------------------------------------------------------------------------- */ static int test_H5FDread_without_eoa_set_fails(void) { #ifndef H5_HAVE_LIBHDFS TESTING("HDFS VFD read-eoa temporal coupling library limitation"); SKIPPED(); puts(" HDFS VFD is not enabled"); fflush(stdout); return 0; #else char buffer[HDFS_TEST_MAX_BUF_SIZE]; unsigned int i = 0; H5FD_t *file_shakespeare = NULL; hid_t fapl_id = -1; TESTING("HDFS VFD read-eoa temporal coupling library limitation"); /********* * SETUP * *********/ /* create HDFS fapl */ fapl_id = H5Pcreate(H5P_FILE_ACCESS); FAIL_IF( fapl_id < 0 ) FAIL_IF( FAIL == H5Pset_fapl_hdfs(fapl_id, &default_fa) ) file_shakespeare = H5FDopen( filename_bard, H5F_ACC_RDONLY, fapl_id, MAXADDR); FAIL_IF( NULL == file_shakespeare ) JSVERIFY( 0, H5FDget_eoa(file_shakespeare, H5FD_MEM_DEFAULT), "EoA should remain unset by H5FDopen" ) /* zero buffer contents */ for (i = 0; i < HDFS_TEST_MAX_BUF_SIZE; i++) { buffer[i] = 0; } /******** * TEST * ********/ H5E_BEGIN_TRY { /* mute stack trace on expected failure */ JSVERIFY( FAIL, H5FDread(file_shakespeare, H5FD_MEM_DRAW, H5P_DEFAULT, 1200699, 102, buffer), "cannot read before eoa is set" ) } H5E_END_TRY; for (i = 0; i < HDFS_TEST_MAX_BUF_SIZE; i++) { JSVERIFY( 0, (unsigned)buffer[i], "buffer was modified by write!" ) } /************ * TEARDOWN * ************/ FAIL_IF( FAIL == H5FDclose(file_shakespeare) ) file_shakespeare = NULL; FAIL_IF( FAIL == H5Pclose(fapl_id) ) fapl_id = -1; PASSED(); return 0; error: /*********** * CLEANUP * ***********/ if (file_shakespeare) { (void)H5FDclose(file_shakespeare); } if (fapl_id >= 0) { H5E_BEGIN_TRY { (void)H5Pclose(fapl_id); } H5E_END_TRY; } return 1; #endif /* H5_HAVE_LIBHDFS */ } /* end test_H5FDread_without_eoa_set_fails() */ /*--------------------------------------------------------------------------- * * Function: test_read() * * Purpose: * * Return: * * PASSED : 0 * FAILED : 1 * * Programmer: Jacob Smith * 2018-06-08 * *--------------------------------------------------------------------------- */ static int test_read(void) { #ifndef H5_HAVE_LIBHDFS TESTING("HDFS VFD read/range-gets"); SKIPPED(); puts(" HDFS VFD is not enabled"); fflush(stdout); return 0; #else /********************* * test-local macros * *********************/ /************************* * test-local structures * *************************/ struct testcase { const char *message; /* purpose of test case */ haddr_t eoa_set; /* set file EOA to this prior to read */ size_t addr; /* offset of read in file */ size_t len; /* length of read in file */ herr_t success; /* expected return value of read function */ const char *expected; /* expected contents of buffer; failure ignores */ }; /************************ * test-local variables * ************************/ struct testcase cases[] = { { "successful range-get", 6464, 5691, 32, /* fancy quotes are three bytes each(?) */ SUCCEED, "Quoth the Raven “Nevermore.”", }, { "read past EOA fails (EOA < EOF < addr)", 3000, 4000, 100, FAIL, NULL, }, { "read overlapping EOA fails (EOA < addr < EOF < (addr+len))", 3000, 8000, 100, FAIL, NULL, }, { "read past EOA/EOF fails ((EOA==EOF) < addr)", 6464, 7000, 100, FAIL, NULL, }, { "read overlapping EOA/EOF fails (addr < (EOA==EOF) < (addr+len))", 6464, 6400, 100, FAIL, NULL, }, { "read between EOF and EOA fails (EOF < addr < (addr+len) < EOA)", 8000, 7000, 100, FAIL, NULL, }, }; unsigned testcase_count = 6; unsigned test_i = 0; struct testcase test; herr_t open_return = FAIL; char buffer[HDFS_TEST_MAX_BUF_SIZE]; unsigned int i = 0; H5FD_t *file_raven = NULL; hid_t fapl_id = -1; TESTING("HDFS VFD read/range-gets"); /********* * SETUP * *********/ /* create HDFS fapl */ fapl_id = H5Pcreate(H5P_FILE_ACCESS); FAIL_IF( fapl_id < 0 ) FAIL_IF( FAIL == H5Pset_fapl_hdfs(fapl_id, &default_fa) ) /* zero buffer contents */ for (i = 0; i < HDFS_TEST_MAX_BUF_SIZE; i++) { buffer[i] = 0; } /* open file */ file_raven = H5FDopen( filename_raven, H5F_ACC_RDONLY, fapl_id, HADDR_UNDEF); /* Demonstrate success with "automatic" value */ FAIL_IF( NULL == file_raven ) JSVERIFY( 6464, H5FDget_eof(file_raven, H5FD_MEM_DEFAULT), NULL ) /********* * TESTS * *********/ for (test_i = 0; test_i < testcase_count; test_i++) { /* -------------- * * per-test setup * * -------------- */ test = cases[test_i]; open_return = FAIL; FAIL_IF( HDFS_TEST_MAX_BUF_SIZE < test.len ) /* buffer too small! */ FAIL_IF( FAIL == H5FDset_eoa( file_raven, H5FD_MEM_DEFAULT, test.eoa_set) ) /* zero buffer contents */ for (i = 0; i < HDFS_TEST_MAX_BUF_SIZE; i++) { buffer[i] = 0; } /* ------------ * * conduct test * * ------------ */ H5E_BEGIN_TRY { open_return = H5FDread( file_raven, H5FD_MEM_DRAW, H5P_DEFAULT, test.addr, test.len, buffer); } H5E_END_TRY; JSVERIFY( test.success, open_return, test.message ) if (open_return == SUCCEED) { JSVERIFY_STR( test.expected, buffer, NULL ) } } /* for each testcase */ /************ * TEARDOWN * ************/ FAIL_IF( FAIL == H5FDclose(file_raven) ) file_raven = NULL; FAIL_IF( FAIL == H5Pclose(fapl_id) ) fapl_id = -1; PASSED(); return 0; error: /*********** * CLEANUP * ***********/ if (file_raven != 0) { (void)H5FDclose(file_raven); } if (fapl_id >= 0) { H5E_BEGIN_TRY { (void)H5Pclose(fapl_id); } H5E_END_TRY; } return 1; #endif /* H5_HAVE_LIBHDFS */ } /* end test_read() */ /*--------------------------------------------------------------------------- * * Function: test_noops_and_autofails() * * Purpose: * * Demonstrate the unavailable and do-nothing routines unique to * Read-Only VFD. * * Return: * * PASSED : 0 * FAILED : 1 * * Programmer: Jacob Smith * 2017-11-06 * * Changes: * + modify from S3VFD codebase to HDFS; Minor changes, mostly. * + Jacob Smith 2018-06-08 * *--------------------------------------------------------------------------- */ static int test_noops_and_autofails(void) { #ifndef H5_HAVE_LIBHDFS TESTING("HDFS VFD always-fail and no-op routines"); SKIPPED(); puts(" HDFS VFD is not enabled"); fflush(stdout); return 0; #else /********************* * test-local macros * *********************/ /************************* * test-local structures * *************************/ /************************ * test-local variables * ************************/ hid_t fapl_id = -1; H5FD_t *file = NULL; const char data[36] = "The Force shall be with you, always"; TESTING("HDFS VFD always-fail and no-op routines"); /********* * SETUP * *********/ /* create HDFS fapl */ fapl_id = H5Pcreate(H5P_FILE_ACCESS); FAIL_IF( fapl_id < 0 ) FAIL_IF( FAIL == H5Pset_fapl_hdfs(fapl_id, &default_fa) ) /* open file */ file = H5FDopen( filename_bard, H5F_ACC_RDONLY, fapl_id, HADDR_UNDEF); FAIL_IF( NULL == file ) /********* * TESTS * *********/ /* auto-fail calls to write and truncate */ H5E_BEGIN_TRY { JSVERIFY( FAIL, H5FDwrite(file, H5FD_MEM_DRAW, H5P_DEFAULT, 1000, 35, data), "write must fail" ) } H5E_END_TRY; H5E_BEGIN_TRY { JSVERIFY( FAIL, H5FDtruncate(file, H5P_DEFAULT, FALSE), "truncate must fail" ) } H5E_END_TRY; H5E_BEGIN_TRY { JSVERIFY( FAIL, H5FDtruncate(file, H5P_DEFAULT, TRUE), "truncate must fail (closing)" ) } H5E_END_TRY; /* no-op calls to `lock()` and `unlock()` */ JSVERIFY( SUCCEED, H5FDlock(file, TRUE), "lock always succeeds; has no effect" ) JSVERIFY( SUCCEED, H5FDlock(file, FALSE), NULL ) JSVERIFY( SUCCEED, H5FDunlock(file), NULL ) /* Lock/unlock with null file or similar error crashes tests. * HDassert in calling heirarchy, `H5FD[un]lock()` and `H5FD_[un]lock()` */ /************ * TEARDOWN * ************/ FAIL_IF( FAIL == H5FDclose(file) ) file = NULL; FAIL_IF( FAIL == H5Pclose(fapl_id) ) fapl_id = -1; PASSED(); return 0; error: /*********** * CLEANUP * ***********/ if (fapl_id >= 0) { H5E_BEGIN_TRY { (void)H5Pclose(fapl_id); } H5E_END_TRY; } if (file != NULL) { (void)H5FDclose(file); } return 1; #endif /* H5_HAVE_LIBHDFS */ } /* end test_noops_and_autofails() */ /*--------------------------------------------------------------------------- * * Function: test_cmp() * * Purpose: * * Verify "file comparison" behavior. * * Return: * * PASSED : 0 * FAILED : 1 * * Programmer: Jacob Smith * 2017-11-06 * *--------------------------------------------------------------------------- */ static int test_cmp(void) { TESTING("HDFS cmp (comparison)"); SKIPPED(); HDfprintf( stderr, " TODO: Distinct valid fapls to open the same file.\n"); return 0; } /* end test_cmp() */ /*--------------------------------------------------------------------------- * * Function: test_H5F_integration() * * Purpose: * * Demonstrate H5F (File interface) behavior with files on HDFS. * * Return: * * PASSED : 0 * FAILED : 1 * * Programmer: Jacob Smith * 2017-11-07 * * Changes: * + modify from S3VFD codebase to HDFS; Minor changes, mostly. * + Jacob Smith 2018-06-08 * *--------------------------------------------------------------------------- */ static int test_H5F_integration(void) { #ifndef H5_HAVE_LIBHDFS TESTING("HDFS file access through HD5F library (H5F API)"); SKIPPED(); puts(" HDFS VFD is not enabled"); fflush(stdout); return 0; #else /********************* * test-local macros * *********************/ /************************* * test-local structures * *************************/ /************************ * test-local variables * ************************/ hid_t file = -1; hid_t fapl_id = -1; TESTING("HDFS file access through HD5F library (H5F API)"); /********* * SETUP * *********/ fapl_id = H5Pcreate(H5P_FILE_ACCESS); FAIL_IF( 0 > fapl_id ) FAIL_IF( FAIL == H5Pset_fapl_hdfs(fapl_id, &default_fa) ) /********* * TESTS * *********/ /* Read-Write Open access is not allowed with this file driver. */ H5E_BEGIN_TRY { FAIL_IF( 0 <= H5Fopen( filename_example_h5, H5F_ACC_RDWR, fapl_id) ) } H5E_END_TRY; /* H5Fcreate() is not allowed with this file driver. */ H5E_BEGIN_TRY { FAIL_IF( 0 <= H5Fcreate( filename_missing, H5F_ACC_RDONLY, H5P_DEFAULT, fapl_id) ) } H5E_END_TRY; /* Successful open. */ file = H5Fopen( filename_example_h5, H5F_ACC_RDONLY, fapl_id); FAIL_IF( file < 0 ) /************ * TEARDOWN * ************/ FAIL_IF( FAIL == H5Fclose(file) ) file = -1; FAIL_IF( FAIL == H5Pclose(fapl_id) ) fapl_id = -1; PASSED(); return 0; error: /*********** * CLEANUP * ***********/ #if HDFS_TEST_DEBUG HDprintf("\nerror!"); fflush(stdout); #endif /* HDFS_TEST_DEBUG */ if (fapl_id >= 0) { H5E_BEGIN_TRY { (void)H5Pclose(fapl_id); } H5E_END_TRY; } if (file > 0) { (void)H5Fclose(file); } return 1; #endif /* H5_HAVE_LIBHDFS */ } /* test_H5F_integration */ /*------------------------------------------------------------------------- * * Function: main * * Purpose: Tests the basic features of Virtual File Drivers * * Return: Success: 0 * Failure: 1 * * Programmer: Jacob Smith * 2017-10-23 * *------------------------------------------------------------------------- */ int main(void) { int nerrors = 0; /****************** * commence tests * ******************/ static char hdfs_namenode_name[HDFS_NAMENODE_NAME_MAX_SIZE] = ""; const char *hdfs_namenode_name_env = NULL; hdfs_namenode_name_env = HDgetenv("HDFS_TEST_NAMENODE_NAME"); if (hdfs_namenode_name_env == NULL || hdfs_namenode_name_env[0] == '\0') { HDstrncpy(hdfs_namenode_name, "localhost", HDFS_NAMENODE_NAME_MAX_SIZE); } else { HDstrncpy( /* TODO: error-check? */ default_fa.namenode_name, hdfs_namenode_name_env, HDFS_NAMENODE_NAME_MAX_SIZE); } h5_reset(); HDprintf("Testing hdfs VFD functionality.\n"); nerrors += test_fapl_config_validation(); nerrors += test_hdfs_fapl(); nerrors += test_vfd_open(); nerrors += test_eof_eoa(); nerrors += test_H5FDread_without_eoa_set_fails(); nerrors += test_read(); nerrors += test_noops_and_autofails(); nerrors += test_cmp(); nerrors += test_H5F_integration(); if (nerrors > 0) { HDprintf("***** %d hdfs TEST%s FAILED! *****\n", nerrors, nerrors > 1 ? "S" : ""); nerrors = 1; } else { HDprintf("All hdfs tests passed.\n"); } return nerrors; /* 0 if no errors, 1 if any errors */ } /* end main() */