@@ -12,23 +12,19 @@ constexpr int MAX_POOLS_ALLOC_SIZE = 1 * 1024; // 1 kB
12
12
constexpr int MAX_PROVIDER_ALLOC_SIZE = 100 * 1024 ; // 100 kB
13
13
14
14
int umf_memory_provider_create (TestState &test_state) {
15
- std::cout << " Begin creating a provider" << std::endl;
16
15
umf_memory_provider_ops_t *provider_ops = umfOsMemoryProviderOps ();
17
16
umf_os_memory_provider_params_t params = umfOsMemoryProviderParamsDefault ();
18
17
umf_result_t res =
19
18
umfMemoryProviderCreate (provider_ops, ¶ms, &test_state.provider );
20
19
21
20
if (res != UMF_RESULT_SUCCESS) {
22
- std::cout << " Failed to create a memory provider: " << res << std::endl;
23
21
return -1 ;
24
22
}
25
- std::cout << " OS memory provider created at " << (void *)test_state.provider
26
- << std::endl;
23
+
27
24
return 0 ;
28
25
}
29
26
30
27
int umf_memory_provider_alloc (TestState &test_state) {
31
- std::cout << " Begin memory_provider_alloc" << std::endl;
32
28
void *ptr;
33
29
size_t alloc_size;
34
30
constexpr size_t alignment = 0 ;
@@ -41,30 +37,22 @@ int umf_memory_provider_alloc(TestState &test_state) {
41
37
int ret = test_state.get_next_alloc_size (test_state, alloc_size,
42
38
MAX_PROVIDER_ALLOC_SIZE);
43
39
if (ret != 0 ) {
44
- std::cout << " Failed to get alloc size" << std::endl;
45
40
return -1 ;
46
41
}
47
42
48
43
umf_result_t res = umfMemoryProviderAlloc (test_state.provider , alloc_size,
49
44
alignment, &ptr);
50
45
if (res != UMF_RESULT_SUCCESS) {
51
- std::cout << " Failed to allocate memory from the provider: " << res
52
- << std::endl;
53
46
return -1 ;
54
47
}
55
48
test_state.provider_memory_allocations .push_back (
56
49
std::make_pair (ptr, alloc_size));
57
- std::cout << " Allocated memory at " << ptr << " with alloc_size "
58
- << alloc_size << std::endl;
59
- std::cout << " Size of vector with allocated memory from the provider: "
60
- << test_state.provider_memory_allocations .size () << std::endl;
50
+
61
51
return 0 ;
62
52
}
63
53
64
54
int umf_memory_provider_free (TestState &test_state) {
65
- std::cout << " Begin memory_provider_free" << std::endl;
66
55
if (test_state.provider_memory_allocations .empty ()) {
67
- std::cout << " No memory allocated" << std::endl;
68
56
return -1 ;
69
57
}
70
58
@@ -74,21 +62,15 @@ int umf_memory_provider_free(TestState &test_state) {
74
62
umfMemoryProviderFree (test_state.provider , alloc.first , alloc.second );
75
63
76
64
if (res != UMF_RESULT_SUCCESS) {
77
- std::cout << " Failed to free memory to the provider: " << res
78
- << std::endl;
79
- ;
80
65
return -1 ;
81
66
}
82
67
83
- std::cout << " Freed memory from the provider at " << alloc.first
84
- << " with alloc_size " << alloc.second << std::endl;
85
68
test_state.provider_memory_allocations .pop_back ();
86
69
return 0 ;
87
70
}
88
71
89
72
int umf_pool_create (TestState &test_state) {
90
73
if (test_state.pools .size () > MAX_POOLS_VECTOR_SIZE) {
91
- std::cout << " Max pools limit reached" << std::endl;
92
74
return -1 ;
93
75
}
94
76
@@ -100,77 +82,59 @@ int umf_pool_create(TestState &test_state) {
100
82
umfPoolCreate (pool_ops, test_state.provider , pool_params, flags, &pool);
101
83
102
84
if (res != UMF_RESULT_SUCCESS) {
103
- std::cout << " Failed to create a pool: " << res << std::endl;
104
85
return -1 ;
105
86
}
106
87
107
88
test_state.pools .insert (std::make_pair (pool, std::vector<void *>()));
108
- std::cout << " Scalable memory pool created at " << pool
109
- << " and pools available: " << test_state.pools .size ()
110
- << std::endl;
89
+
111
90
return 0 ;
112
91
}
113
92
114
93
int umf_pool_destroy (TestState &test_state) {
115
- std::cout << " Begin destroy pool" << std::endl;
116
94
if (test_state.pools .empty ()) {
117
- std::cout << " No pools created" << std::endl;
118
95
return -1 ;
119
96
}
120
97
auto pool = (*test_state.pools .begin ()).first ;
121
98
umfPoolDestroy (pool);
122
99
test_state.pools .erase (pool);
123
- std::cout << " Destroyed pool at " << pool << std::endl;
100
+
124
101
return 0 ;
125
102
}
126
103
127
104
int umf_pool_malloc (TestState &test_state) {
128
- std::cout << " Begin pool_malloc" << std::endl;
129
105
if (test_state.pools .empty ()) {
130
- std::cout << " No pools created" << std::endl;
131
106
return -1 ;
132
107
}
133
108
size_t alloc_size;
134
109
int ret = test_state.get_next_alloc_size (test_state, alloc_size,
135
110
MAX_POOLS_ALLOC_SIZE);
136
111
if (ret != 0 ) {
137
- std::cout << " Failed to get next allocation size" << std::endl;
138
112
return -1 ;
139
113
}
140
114
auto &pool_entry = *test_state.pools .rbegin ();
141
115
void *ptr = umfPoolMalloc (pool_entry.first , alloc_size);
142
- if (!ptr) {
143
- std::cout
144
- << " Failed to allocate memory in the pool with handle address: "
145
- << pool_entry.first << std::endl;
146
- }
147
116
148
117
pool_entry.second .push_back (ptr);
149
- std::cout << " Allocated memory at " << ptr
150
- << " with allocation size: " << alloc_size << std::endl;
118
+
151
119
return 0 ;
152
120
}
153
121
154
122
int umf_free (TestState &test_state) {
155
- std::cout << " Begin releasing pool memory" << std::endl;
156
123
for (auto &pool : test_state.pools ) {
157
124
if (pool.second .empty ()) {
158
125
continue ;
159
126
} else {
160
127
umfFree (pool.second .back ());
161
128
pool.second .pop_back ();
162
- std::cout << " Freed memory from the pool at: " << pool.second .back ()
163
- << std::endl;
164
129
break ;
165
130
}
166
- std::cout << " No pool memory to free " << std::endl;
131
+
167
132
return -1 ;
168
133
}
169
134
return 0 ;
170
135
}
171
136
172
137
void cleanup (TestState &test_state) {
173
- std::cout << " Begin cleanup state" << std::endl;
174
138
for (auto &alloc : test_state.provider_memory_allocations ) {
175
139
umfMemoryProviderFree (test_state.provider , alloc.first , alloc.second );
176
140
}
@@ -181,11 +145,8 @@ void cleanup(TestState &test_state) {
181
145
}
182
146
umfPoolDestroy (pool_entry.first );
183
147
}
184
- std::cout << " Freed all allocated memory from provider and pools and "
185
- " destroyed all pools"
186
- << std::endl;
148
+
187
149
umfMemoryProviderDestroy (test_state.provider );
188
- std::cout << " Destroyed the provider" << std::endl;
189
150
}
190
151
191
152
extern " C" int LLVMFuzzerTestOneInput (uint8_t *data, size_t size) {
0 commit comments