source: mainline/uspace/app/tester/mm/common.h@ ba8eecf

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since ba8eecf was 3e6a98c5, checked in by Jiri Svoboda <jiri@…>, 13 years ago

Standards-compliant boolean type.

  • Property mode set to 100644
File size: 3.3 KB
Line 
1/*
2 * Copyright (c) 2011 Martin Decky
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *
9 * - Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * - Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * - The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29/** @addtogroup tester
30 * @{
31 */
32/** @file
33 */
34
35#ifndef MM_COMMON_H_
36#define MM_COMMON_H_
37
38#include <sys/types.h>
39#include <stdbool.h>
40#include <adt/list.h>
41
42#define MAX_ALLOC (16 * 1024 * 1024)
43
44#define AREA_GRANULARITY 16
45#define AREA_SIZE (4 * PAGE_SIZE)
46
47typedef struct {
48 /* Address of the start of the block */
49 void *addr;
50
51 /* Size of the memory block */
52 size_t size;
53
54 /* Link to other blocks */
55 link_t link;
56} mem_block_t;
57
58typedef struct {
59 /* Address of the start of the area */
60 void *addr;
61
62 /* Size of the memory area */
63 size_t size;
64 /* Link to other areas */
65 link_t link;
66} mem_area_t;
67
68/*
69 * Subphase control structures: subphase termination conditions,
70 * probabilities of individual actions, subphase control structure.
71 */
72
73typedef struct {
74 unsigned int max_cycles;
75 unsigned int no_memory;
76 unsigned int no_allocated;
77} sp_term_cond_t;
78
79typedef struct {
80 unsigned int alloc;
81 unsigned int free;
82} sp_action_prob_t;
83
84typedef struct {
85 const char *name;
86 sp_term_cond_t cond;
87 sp_action_prob_t prob;
88} subphase_t;
89
90/*
91 * Phase control structures: The minimum and maximum block size that
92 * can be allocated during the phase execution, phase control structure.
93 */
94
95typedef struct {
96 size_t min_block_size;
97 size_t max_block_size;
98} ph_alloc_size_t;
99
100typedef struct {
101 const char *name;
102 ph_alloc_size_t alloc;
103 subphase_t *subphases;
104} phase_t;
105
106extern bool error_flag;
107extern size_t mem_allocated;
108extern size_t mem_blocks_count;
109
110#define RETURN_IF_ERROR \
111 do { \
112 if (error_flag) \
113 return; \
114 } while (0)
115
116extern void init_mem(void);
117extern void done_mem(void);
118
119extern mem_block_t *alloc_block(size_t);
120extern void free_block(mem_block_t *);
121extern void fill_block(mem_block_t *);
122extern void check_block(mem_block_t *);
123extern mem_block_t *get_random_block(void);
124
125extern mem_area_t *map_area(size_t);
126extern void fill_area(mem_area_t *);
127extern void unmap_area(mem_area_t *);
128
129#endif
130
131/** @}
132 */
Note: See TracBrowser for help on using the repository browser.