Coverage Report

Created: 2026-01-08 06:16

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/hdf5/src/H5FAtest.c
Line
Count
Source
1
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2
 * Copyright by The HDF Group.                                               *
3
 * All rights reserved.                                                      *
4
 *                                                                           *
5
 * This file is part of HDF5.  The full HDF5 copyright notice, including     *
6
 * terms governing use, modification, and redistribution, is contained in    *
7
 * the LICENSE file, which can be found at the root of the source code       *
8
 * distribution tree, or in https://www.hdfgroup.org/licenses.               *
9
 * If you do not have access to either file, you may request a copy from     *
10
 * help@hdfgroup.org.                                                        *
11
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
12
13
/*
14
 * Purpose:     Fixed array testing functions.
15
 *
16
 */
17
18
/**********************/
19
/* Module Declaration */
20
/**********************/
21
22
#include "H5FAmodule.h" /* This source code file is part of the H5FA module */
23
#define H5FA_TESTING
24
25
/***********************/
26
/* Other Packages Used */
27
/***********************/
28
29
/***********/
30
/* Headers */
31
/***********/
32
#include "H5private.h"   /* Generic Functions     */
33
#include "H5Eprivate.h"  /* Error handling        */
34
#include "H5FApkg.h"     /* Fixed Arrays        */
35
#include "H5FLprivate.h" /* Free Lists                           */
36
#include "H5VMprivate.h" /* Vector functions      */
37
38
/****************/
39
/* Local Macros */
40
/****************/
41
42
/* Sanity checking value for callback contexts */
43
0
#define H5FA__TEST_BOGUS_VAL 42
44
45
/******************/
46
/* Local Typedefs */
47
/******************/
48
49
/* Callback context */
50
typedef struct H5FA__test_ctx_t {
51
    uint32_t bogus; /* Placeholder field to verify that context is working */
52
} H5FA__test_ctx_t;
53
54
/********************/
55
/* Package Typedefs */
56
/********************/
57
58
/********************/
59
/* Local Prototypes */
60
/********************/
61
62
/* Fixed array class callbacks */
63
static void  *H5FA__test_crt_context(void *udata);
64
static herr_t H5FA__test_dst_context(void *ctx);
65
static herr_t H5FA__test_fill(void *nat_blk, size_t nelmts);
66
static herr_t H5FA__test_encode(void *raw, const void *elmt, size_t nelmts, void *ctx);
67
static herr_t H5FA__test_decode(const void *raw, void *elmt, size_t nelmts, void *ctx);
68
static herr_t H5FA__test_debug(FILE *stream, int indent, int fwidth, hsize_t idx, const void *elmt);
69
static void  *H5FA__test_crt_dbg_context(H5F_t *f, haddr_t obj_addr);
70
71
/*********************/
72
/* Package Variables */
73
/*********************/
74
75
/* Fixed array testing class information */
76
const H5FA_class_t H5FA_CLS_TEST[1] = {{
77
    H5FA_CLS_TEST_ID,           /* Type of Fixed array */
78
    "Testing",                  /* Name of fixed array class */
79
    sizeof(uint64_t),           /* Size of native element */
80
    H5FA__test_crt_context,     /* Create context */
81
    H5FA__test_dst_context,     /* Destroy context */
82
    H5FA__test_fill,            /* Fill block of missing elements callback */
83
    H5FA__test_encode,          /* Element encoding callback */
84
    H5FA__test_decode,          /* Element decoding callback */
85
    H5FA__test_debug,           /* Element debugging callback */
86
    H5FA__test_crt_dbg_context, /* Create debugging context */
87
    H5FA__test_dst_context      /* Destroy debugging context */
88
}};
89
90
/*****************************/
91
/* Library Private Variables */
92
/*****************************/
93
94
/*******************/
95
/* Local Variables */
96
/*******************/
97
98
/* Declare a free list to manage the H5FA__test_ctx_t struct */
99
H5FL_DEFINE_STATIC(H5FA__test_ctx_t);
100
101
/*-------------------------------------------------------------------------
102
 * Function:    H5FA__test_crt_context
103
 *
104
 * Purpose:     Create context for callbacks
105
 *
106
 * Return:      Success:    non-NULL
107
 *              Failure:    NULL
108
 *
109
 *-------------------------------------------------------------------------
110
 */
111
static void *
112
H5FA__test_crt_context(void H5_ATTR_UNUSED *udata)
113
0
{
114
0
    H5FA__test_ctx_t *ctx; /* Context for callbacks */
115
0
    void             *ret_value = NULL;
116
117
0
    FUNC_ENTER_PACKAGE
118
119
    /* Allocate new context structure */
120
0
    if (NULL == (ctx = H5FL_MALLOC(H5FA__test_ctx_t)))
121
0
        HGOTO_ERROR(H5E_FARRAY, H5E_CANTALLOC, NULL, "can't allocate fixed array client callback context");
122
123
    /* Initialize the context */
124
0
    ctx->bogus = H5FA__TEST_BOGUS_VAL;
125
126
    /* Set return value */
127
0
    ret_value = ctx;
128
129
0
done:
130
0
    FUNC_LEAVE_NOAPI(ret_value)
131
0
} /* end H5FA__test_crt_context() */
132
133
/*-------------------------------------------------------------------------
134
 * Function:    H5FA__test_dst_context
135
 *
136
 * Purpose:     Destroy context for callbacks
137
 *
138
 * Return:      SUCCEED/FAIL
139
 *
140
 *-------------------------------------------------------------------------
141
 */
142
static herr_t
143
H5FA__test_dst_context(void *_ctx)
144
0
{
145
0
    H5FA__test_ctx_t *ctx = (H5FA__test_ctx_t *)_ctx; /* Callback context to destroy */
146
147
0
    FUNC_ENTER_PACKAGE_NOERR
148
149
    /* Sanity checks */
150
0
    assert(H5FA__TEST_BOGUS_VAL == ctx->bogus);
151
152
    /* Release context structure */
153
0
    ctx = H5FL_FREE(H5FA__test_ctx_t, ctx);
154
155
0
    FUNC_LEAVE_NOAPI(SUCCEED)
156
0
} /* end H5FA__test_dst_context() */
157
158
/*-------------------------------------------------------------------------
159
 * Function:    H5FA__test_fill
160
 *
161
 * Purpose:     Fill "missing elements" in block of elements
162
 *
163
 * Return:      SUCCEED/FAIL
164
 *
165
 *-------------------------------------------------------------------------
166
 */
167
static herr_t
168
H5FA__test_fill(void *nat_blk, size_t nelmts)
169
0
{
170
0
    uint64_t fill_val = H5FA_TEST_FILL; /* Value to fill elements with */
171
172
0
    FUNC_ENTER_PACKAGE_NOERR
173
174
    /* Sanity checks */
175
0
    assert(nat_blk);
176
0
    assert(nelmts);
177
178
0
    H5VM_array_fill(nat_blk, &fill_val, sizeof(uint64_t), nelmts);
179
180
0
    FUNC_LEAVE_NOAPI(SUCCEED)
181
0
} /* end H5FA__test_fill() */
182
183
/*-------------------------------------------------------------------------
184
 * Function:    H5FA__test_encode
185
 *
186
 * Purpose:     Encode an element from "native" to "raw" form
187
 *
188
 * Return:      SUCCEED/FAIL
189
 *
190
 *-------------------------------------------------------------------------
191
 */
192
static herr_t
193
H5FA__test_encode(void *raw, const void *_elmt, size_t nelmts, void H5_ATTR_UNUSED *_ctx)
194
0
{
195
#ifndef NDEBUG
196
    H5FA__test_ctx_t *ctx = (H5FA__test_ctx_t *)_ctx; /* Callback context to destroy */
197
#endif
198
0
    const uint64_t *elmt = (const uint64_t *)_elmt; /* Convenience pointer to native elements */
199
200
0
    FUNC_ENTER_PACKAGE_NOERR
201
202
    /* Sanity checks */
203
0
    assert(raw);
204
0
    assert(elmt);
205
0
    assert(nelmts);
206
0
    assert(H5FA__TEST_BOGUS_VAL == ctx->bogus);
207
208
    /* Encode native elements into raw elements */
209
0
    while (nelmts) {
210
        /* Encode element */
211
        /* (advances 'raw' pointer) */
212
0
        UINT64ENCODE(raw, *elmt);
213
214
        /* Advance native element pointer */
215
0
        elmt++;
216
217
        /* Decrement # of elements to encode */
218
0
        nelmts--;
219
0
    } /* end while */
220
221
0
    FUNC_LEAVE_NOAPI(SUCCEED)
222
0
} /* end H5FA__test_encode() */
223
224
/*-------------------------------------------------------------------------
225
 * Function:    H5FA__test_decode
226
 *
227
 * Purpose:     Decode an element from "raw" to "native" form
228
 *
229
 * Return:      SUCCEED/FAIL
230
 *
231
 *-------------------------------------------------------------------------
232
 */
233
static herr_t
234
H5FA__test_decode(const void *_raw, void *_elmt, size_t nelmts, void H5_ATTR_UNUSED *_ctx)
235
0
{
236
#ifndef NDEBUG
237
    H5FA__test_ctx_t *ctx = (H5FA__test_ctx_t *)_ctx; /* Callback context to destroy */
238
#endif
239
0
    uint64_t      *elmt = (uint64_t *)_elmt;     /* Convenience pointer to native elements */
240
0
    const uint8_t *raw  = (const uint8_t *)_raw; /* Convenience pointer to raw elements */
241
242
0
    FUNC_ENTER_PACKAGE_NOERR
243
244
    /* Sanity checks */
245
0
    assert(raw);
246
0
    assert(elmt);
247
0
    assert(nelmts);
248
0
    assert(H5FA__TEST_BOGUS_VAL == ctx->bogus);
249
250
    /* Decode raw elements into native elements */
251
0
    while (nelmts) {
252
        /* Decode element */
253
        /* (advances 'raw' pointer) */
254
0
        UINT64DECODE(raw, *elmt);
255
256
        /* Advance native element pointer */
257
0
        elmt++;
258
259
        /* Decrement # of elements to decode */
260
0
        nelmts--;
261
0
    } /* end while */
262
263
0
    FUNC_LEAVE_NOAPI(SUCCEED)
264
0
} /* end H5FA__test_decode() */
265
266
/*-------------------------------------------------------------------------
267
 * Function:    H5FA__test_debug
268
 *
269
 * Purpose:     Display an element for debugging
270
 *
271
 * Return:      SUCCEED/FAIL
272
 *
273
 *-------------------------------------------------------------------------
274
 */
275
static herr_t
276
H5FA__test_debug(FILE *stream, int indent, int fwidth, hsize_t idx, const void *elmt)
277
0
{
278
0
    char temp_str[128]; /* Temporary string, for formatting */
279
280
0
    FUNC_ENTER_PACKAGE_NOERR
281
282
    /* Sanity checks */
283
0
    assert(stream);
284
0
    assert(elmt);
285
286
    /* Print element */
287
0
    snprintf(temp_str, sizeof(temp_str), "Element #%llu:", (unsigned long long)idx);
288
0
    fprintf(stream, "%*s%-*s %llu\n", indent, "", fwidth, temp_str,
289
0
            (unsigned long long)*(const uint64_t *)elmt);
290
291
0
    FUNC_LEAVE_NOAPI(SUCCEED)
292
0
} /* end H5FA__test_debug() */
293
294
/*-------------------------------------------------------------------------
295
 * Function:    H5FA__test_crt_dbg_context
296
 *
297
 * Purpose:     Create context for debugging callback
298
 *
299
 * Return:      Success:    non-NULL
300
 *              Failure:    NULL
301
 *
302
 *-------------------------------------------------------------------------
303
 */
304
static void *
305
H5FA__test_crt_dbg_context(H5F_t H5_ATTR_UNUSED *f, haddr_t H5_ATTR_UNUSED obj_addr)
306
0
{
307
0
    H5FA__test_ctx_t *ctx; /* Context for callbacks */
308
0
    void             *ret_value = NULL;
309
310
0
    FUNC_ENTER_PACKAGE
311
312
    /* Allocate new context structure */
313
0
    if (NULL == (ctx = H5FL_MALLOC(H5FA__test_ctx_t)))
314
0
        HGOTO_ERROR(H5E_FARRAY, H5E_CANTALLOC, NULL, "can't allocate fixed array client callback context");
315
316
    /* Initialize the context */
317
0
    ctx->bogus = H5FA__TEST_BOGUS_VAL;
318
319
    /* Set return value */
320
0
    ret_value = ctx;
321
322
0
done:
323
0
    FUNC_LEAVE_NOAPI(ret_value)
324
0
} /* end H5FA__test_crt_dbg_context() */
325
326
/*-------------------------------------------------------------------------
327
 * Function:    H5FA__get_cparam_test
328
 *
329
 * Purpose:     Retrieve the parameters used to create the fixed array
330
 *
331
 * Return:      SUCCEED/FAIL
332
 *
333
 *-------------------------------------------------------------------------
334
 */
335
herr_t
336
H5FA__get_cparam_test(const H5FA_t *fa, H5FA_create_t *cparam)
337
0
{
338
0
    FUNC_ENTER_PACKAGE_NOERR
339
340
    /* Check arguments. */
341
0
    assert(fa);
342
0
    assert(cparam);
343
344
    /* Get fixed array creation parameters */
345
0
    cparam->raw_elmt_size = fa->hdr->cparam.raw_elmt_size;
346
0
    cparam->nelmts        = fa->hdr->cparam.nelmts;
347
348
0
    FUNC_LEAVE_NOAPI(SUCCEED)
349
0
} /* end H5FA__get_cparam_test() */
350
351
/*-------------------------------------------------------------------------
352
 * Function:    H5FA__cmp_cparam_test
353
 *
354
 * Purpose:     Compare the parameters used to create the fixed array
355
 *
356
 * Return:      An integer value like strcmp
357
 *
358
 *-------------------------------------------------------------------------
359
 */
360
int
361
H5FA__cmp_cparam_test(const H5FA_create_t *cparam1, const H5FA_create_t *cparam2)
362
0
{
363
0
    int ret_value = 0;
364
365
0
    FUNC_ENTER_PACKAGE_NOERR
366
367
    /* Check arguments. */
368
0
    assert(cparam1);
369
0
    assert(cparam2);
370
371
    /* Compare creation parameters for array */
372
0
    if (cparam1->raw_elmt_size < cparam2->raw_elmt_size)
373
0
        ret_value = -1;
374
0
    else if (cparam1->raw_elmt_size > cparam2->raw_elmt_size)
375
0
        ret_value = 1;
376
377
0
    FUNC_LEAVE_NOAPI(ret_value)
378
379
0
} /* end H5FA__cmp_cparam_test() */