Skip to content

Commit 96d8978

Browse files
Merge pull request #577 from lplewa/fuzz
Fuzz test fixes
2 parents af74d76 + be3ac99 commit 96d8978

File tree

2 files changed

+8
-47
lines changed

2 files changed

+8
-47
lines changed

test/fuzz/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ target_include_directories(${TEST_TARGET_NAME}
2323
PRIVATE ${UMF_CMAKE_SOURCE_DIR}/include)
2424
target_link_directories(${TEST_TARGET_NAME} PRIVATE ${LIBHWLOC_LIBRARY_DIRS})
2525

26-
add_fuzz_test(basic_long fuzz-long -max_total_time=600 -seed=1)
26+
add_fuzz_test(basic_long fuzz-long -max_total_time=600)

test/fuzz/umfFuzz.cpp

Lines changed: 7 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,19 @@ constexpr int MAX_POOLS_ALLOC_SIZE = 1 * 1024; // 1 kB
1212
constexpr int MAX_PROVIDER_ALLOC_SIZE = 100 * 1024; // 100 kB
1313

1414
int umf_memory_provider_create(TestState &test_state) {
15-
std::cout << "Begin creating a provider" << std::endl;
1615
umf_memory_provider_ops_t *provider_ops = umfOsMemoryProviderOps();
1716
umf_os_memory_provider_params_t params = umfOsMemoryProviderParamsDefault();
1817
umf_result_t res =
1918
umfMemoryProviderCreate(provider_ops, &params, &test_state.provider);
2019

2120
if (res != UMF_RESULT_SUCCESS) {
22-
std::cout << "Failed to create a memory provider: " << res << std::endl;
2321
return -1;
2422
}
25-
std::cout << "OS memory provider created at " << (void *)test_state.provider
26-
<< std::endl;
23+
2724
return 0;
2825
}
2926

3027
int umf_memory_provider_alloc(TestState &test_state) {
31-
std::cout << "Begin memory_provider_alloc" << std::endl;
3228
void *ptr;
3329
size_t alloc_size;
3430
constexpr size_t alignment = 0;
@@ -41,30 +37,22 @@ int umf_memory_provider_alloc(TestState &test_state) {
4137
int ret = test_state.get_next_alloc_size(test_state, alloc_size,
4238
MAX_PROVIDER_ALLOC_SIZE);
4339
if (ret != 0) {
44-
std::cout << "Failed to get alloc size" << std::endl;
4540
return -1;
4641
}
4742

4843
umf_result_t res = umfMemoryProviderAlloc(test_state.provider, alloc_size,
4944
alignment, &ptr);
5045
if (res != UMF_RESULT_SUCCESS) {
51-
std::cout << "Failed to allocate memory from the provider: " << res
52-
<< std::endl;
5346
return -1;
5447
}
5548
test_state.provider_memory_allocations.push_back(
5649
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+
6151
return 0;
6252
}
6353

6454
int umf_memory_provider_free(TestState &test_state) {
65-
std::cout << "Begin memory_provider_free" << std::endl;
6655
if (test_state.provider_memory_allocations.empty()) {
67-
std::cout << "No memory allocated" << std::endl;
6856
return -1;
6957
}
7058

@@ -74,21 +62,15 @@ int umf_memory_provider_free(TestState &test_state) {
7462
umfMemoryProviderFree(test_state.provider, alloc.first, alloc.second);
7563

7664
if (res != UMF_RESULT_SUCCESS) {
77-
std::cout << "Failed to free memory to the provider: " << res
78-
<< std::endl;
79-
;
8065
return -1;
8166
}
8267

83-
std::cout << "Freed memory from the provider at " << alloc.first
84-
<< " with alloc_size " << alloc.second << std::endl;
8568
test_state.provider_memory_allocations.pop_back();
8669
return 0;
8770
}
8871

8972
int umf_pool_create(TestState &test_state) {
9073
if (test_state.pools.size() > MAX_POOLS_VECTOR_SIZE) {
91-
std::cout << "Max pools limit reached" << std::endl;
9274
return -1;
9375
}
9476

@@ -100,77 +82,59 @@ int umf_pool_create(TestState &test_state) {
10082
umfPoolCreate(pool_ops, test_state.provider, pool_params, flags, &pool);
10183

10284
if (res != UMF_RESULT_SUCCESS) {
103-
std::cout << "Failed to create a pool: " << res << std::endl;
10485
return -1;
10586
}
10687

10788
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+
11190
return 0;
11291
}
11392

11493
int umf_pool_destroy(TestState &test_state) {
115-
std::cout << "Begin destroy pool" << std::endl;
11694
if (test_state.pools.empty()) {
117-
std::cout << "No pools created" << std::endl;
11895
return -1;
11996
}
12097
auto pool = (*test_state.pools.begin()).first;
12198
umfPoolDestroy(pool);
12299
test_state.pools.erase(pool);
123-
std::cout << "Destroyed pool at " << pool << std::endl;
100+
124101
return 0;
125102
}
126103

127104
int umf_pool_malloc(TestState &test_state) {
128-
std::cout << "Begin pool_malloc" << std::endl;
129105
if (test_state.pools.empty()) {
130-
std::cout << "No pools created" << std::endl;
131106
return -1;
132107
}
133108
size_t alloc_size;
134109
int ret = test_state.get_next_alloc_size(test_state, alloc_size,
135110
MAX_POOLS_ALLOC_SIZE);
136111
if (ret != 0) {
137-
std::cout << "Failed to get next allocation size" << std::endl;
138112
return -1;
139113
}
140114
auto &pool_entry = *test_state.pools.rbegin();
141115
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-
}
147116

148117
pool_entry.second.push_back(ptr);
149-
std::cout << "Allocated memory at " << ptr
150-
<< " with allocation size: " << alloc_size << std::endl;
118+
151119
return 0;
152120
}
153121

154122
int umf_free(TestState &test_state) {
155-
std::cout << "Begin releasing pool memory" << std::endl;
156123
for (auto &pool : test_state.pools) {
157124
if (pool.second.empty()) {
158125
continue;
159126
} else {
160127
umfFree(pool.second.back());
161128
pool.second.pop_back();
162-
std::cout << "Freed memory from the pool at: " << pool.second.back()
163-
<< std::endl;
164129
break;
165130
}
166-
std::cout << "No pool memory to free" << std::endl;
131+
167132
return -1;
168133
}
169134
return 0;
170135
}
171136

172137
void cleanup(TestState &test_state) {
173-
std::cout << "Begin cleanup state" << std::endl;
174138
for (auto &alloc : test_state.provider_memory_allocations) {
175139
umfMemoryProviderFree(test_state.provider, alloc.first, alloc.second);
176140
}
@@ -181,11 +145,8 @@ void cleanup(TestState &test_state) {
181145
}
182146
umfPoolDestroy(pool_entry.first);
183147
}
184-
std::cout << "Freed all allocated memory from provider and pools and "
185-
"destroyed all pools"
186-
<< std::endl;
148+
187149
umfMemoryProviderDestroy(test_state.provider);
188-
std::cout << "Destroyed the provider" << std::endl;
189150
}
190151

191152
extern "C" int LLVMFuzzerTestOneInput(uint8_t *data, size_t size) {

0 commit comments

Comments
 (0)