summaryrefslogtreecommitdiff
path: root/src/H5MPtest.c
blob: b3f2e24c5af2051cf543a40dc92ee07991922318 (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
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * 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.                                                        *
 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */

/* Programmer:  Quincey Koziol <koziol@ncsa.uiuc.edu>
 *              Tuesday, May  3, 2005
 *
 * Purpose:	Memory pool testing functions.
 */

#include "H5MPmodule.h"         /* This source code file is part of the H5MP module */
#define H5MP_TESTING		/*include H5MP testing funcs*/

/* Private headers */
#include "H5private.h"		/* Generic Functions			*/
#include "H5MPpkg.h"		/* Memory Pools				*/
#include "H5Eprivate.h"		/* Error handling		  	*/

/* Static Prototypes */

/* Package variables */


/*-------------------------------------------------------------------------
 * Function:	H5MP_get_pool_free_size
 *
 * Purpose:	Retrieve the total amount of free space in entire pool
 *
 * Return:	Success:	non-negative
 *
 *		Failure:	negative
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, May  3, 2005
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
herr_t
H5MP_get_pool_free_size(const H5MP_pool_t *mp, size_t *free_size)
{
    FUNC_ENTER_NOAPI_NOINIT_NOERR

    /* Check arguments. */
    HDassert(mp);
    HDassert(free_size);

    /* Get memory pool's free space */
    *free_size = mp->free_size;

    FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5MP_get_pool_free_size() */


/*-------------------------------------------------------------------------
 * Function:	H5MP_get_pool_first_page
 *
 * Purpose:	Retrieve the first page in a memory pool
 *
 * Return:	Success:	non-negative
 *
 *		Failure:	negative
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, May  3, 2005
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
herr_t
H5MP_get_pool_first_page(const H5MP_pool_t *mp, H5MP_page_t **page)
{
    FUNC_ENTER_NOAPI_NOINIT_NOERR

    /* Check arguments. */
    HDassert(mp);
    HDassert(page);

    /* Get memory pool's first page */
    *page = mp->first;

    FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5MP_get_pool_first_page() */


/*-------------------------------------------------------------------------
 * Function:	H5MP_pool_is_free_size_correct
 *
 * Purpose:	Check that the free space reported in each page corresponds
 *              to the free size in each page and that the free space in the
 *              free blocks for a page corresponds with the free space for
 *              the page.
 *
 * Return:	Success:	non-negative
 *
 *		Failure:	negative
 *
 * Programmer:	Quincey Koziol
 *              Wednesday, May  3, 2005
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
htri_t
H5MP_pool_is_free_size_correct(const H5MP_pool_t *mp)
{
    H5MP_page_t *page;          /* Pointer to current page */
    size_t pool_free;           /* Size of pages' free space */
    htri_t ret_value = TRUE;    /* Return value */

    FUNC_ENTER_NOAPI_NOINIT_NOERR

    /* Check arguments. */
    HDassert(mp);

    /* Iterate through pages, checking the free size & accumulating the
     * free space for all the pages */
    page = mp->first;
    pool_free = 0;
    while(page != NULL) {
        H5MP_page_blk_t *blk;           /* Pointer to current free block */
        size_t page_free;               /* Size of blocks on free list */

        /* Iterate through the blocks in page, accumulating free space */
        blk = (H5MP_page_blk_t *)((unsigned char *)page + H5MP_BLOCK_ALIGN(sizeof(H5MP_page_t)));
        page_free = 0;
        while(blk != NULL) {
            if(blk->is_free)
                page_free += blk->size;
            blk = blk->next;
        } /* end while */

        /* Check that the free space from the blocks on the free list
         * corresponds to space in page */
#ifdef QAK
HDfprintf(stderr,"%s: page_free = %Zu, page->free_size = %Zu\n", "H5MP_pool_is_free_size_correct", page_free, page->free_size);
#endif /* QAK */
        if(page_free != page->free_size)
            HGOTO_DONE (FALSE)

        /* Increment the amount of free space in pool */
        pool_free += page->free_size;

        /* Advance to next page */
        page = page->next;
    } /* end while */

    /* Check that the free space from the pages
     * corresponds to free space in pool */
#ifdef QAK
HDfprintf(stderr,"%s: pool_free = %Zu, mp->free_size = %Zu\n", "H5MP_pool_is_free_size_correct", pool_free, mp->free_size);
#endif /* QAK */
    if(pool_free != mp->free_size)
        HGOTO_DONE (FALSE)

done:
    FUNC_LEAVE_NOAPI(ret_value)
} /* H5MP_pool_is_free_size_correct() */


/*-------------------------------------------------------------------------
 * Function:	H5MP_get_page_free_size
 *
 * Purpose:	Retrieve the amount of free space in given page
 *
 * Return:	Success:	non-negative
 *
 *		Failure:	negative
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, May  3, 2005
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
herr_t
H5MP_get_page_free_size(const H5MP_page_t *page, size_t *free_size)
{
    FUNC_ENTER_NOAPI_NOINIT_NOERR

    /* Check arguments. */
    HDassert(page);
    HDassert(free_size);

    /* Get memory page's free space */
    *free_size = page->free_size;

    FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5MP_get_page_free_size() */


/*-------------------------------------------------------------------------
 * Function:	H5MP_get_page_next_page
 *
 * Purpose:	Retrieve the next page in the pool
 *
 * Return:	Success:	non-negative
 *
 *		Failure:	negative
 *
 * Programmer:	Quincey Koziol
 *              Tuesday, May  3, 2005
 *
 * Modifications:
 *
 *-------------------------------------------------------------------------
 */
herr_t
H5MP_get_page_next_page(const H5MP_page_t *page, H5MP_page_t **next_page)
{
    FUNC_ENTER_NOAPI_NOINIT_NOERR

    /* Check arguments. */
    HDassert(page);
    HDassert(next_page);

    /* Get next memory page */
    *next_page = page->next;

    FUNC_LEAVE_NOAPI(SUCCEED)
} /* H5MP_get_page_next_page() */