|
@ -1,8 +1,10 @@ |
|
|
#include "test_scaffold.h"
|
|
|
#include "test_scaffold.h"
|
|
|
#include "gp/array.hpp"
|
|
|
#include "gp/array.hpp"
|
|
|
|
|
|
#include "gp/allocator/aggregator.hpp"
|
|
|
#include "gp/allocator/buddy.hpp"
|
|
|
#include "gp/allocator/buddy.hpp"
|
|
|
#include "gp/allocator/dummy.hpp"
|
|
|
#include "gp/allocator/dummy.hpp"
|
|
|
#include "gp/algorithm/repeat.hpp"
|
|
|
#include "gp/algorithm/repeat.hpp"
|
|
|
|
|
|
#include "gp/ring_list.hpp"
|
|
|
#include <thread>
|
|
|
#include <thread>
|
|
|
#include <chrono>
|
|
|
#include <chrono>
|
|
|
#include <set>
|
|
|
#include <set>
|
|
@ -12,9 +14,15 @@ |
|
|
#include <random>
|
|
|
#include <random>
|
|
|
#include <iomanip>
|
|
|
#include <iomanip>
|
|
|
#include <iostream>
|
|
|
#include <iostream>
|
|
|
#include <fstream>
|
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
#include <algorithm>
|
|
|
#include <algorithm>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef FUZZ_STRENGTH
|
|
|
|
|
|
#define FUZZ_STRENGTH 2048
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
#define MACRO_STRGEN(X) #X
|
|
|
#define MACRO_STRGEN(X) #X
|
|
|
#define MACRO_STR(X) MACRO_STRGEN(X)
|
|
|
#define MACRO_STR(X) MACRO_STRGEN(X)
|
|
|
|
|
|
|
|
@ -331,4 +339,94 @@ struct buddy_fuzz_test : public test_scaffold { |
|
|
}; |
|
|
}; |
|
|
|
|
|
|
|
|
append_test dummy_df987sd3(new buddy_fuzz_test{781017366}); |
|
|
append_test dummy_df987sd3(new buddy_fuzz_test{781017366}); |
|
|
append_test dummy_df4sisd3(new buddy_fuzz_test{}); |
|
|
|
|
|
|
|
|
append_test dummy_df4sisd3(new buddy_fuzz_test{}); |
|
|
|
|
|
|
|
|
|
|
|
struct ring_list_test : public test_scaffold { |
|
|
|
|
|
ring_list_test() { |
|
|
|
|
|
name = __FILE__ ":5"; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
virtual int run() { |
|
|
|
|
|
int res = 0; |
|
|
|
|
|
alignas(8) gp::array<char, 4096> store; |
|
|
|
|
|
using local_allocator = gp::buddy<gp::dummy_allocator, gp::math::msb<uint64_t>(4096)>; |
|
|
|
|
|
local_allocator bud{&*store.begin(), store.size()}; |
|
|
|
|
|
{ |
|
|
|
|
|
using string_ring = gp::ring_list<std::string, local_allocator, false>; |
|
|
|
|
|
auto p = new(bud.allocate(sizeof(std::string))) std::string("Hello"); |
|
|
|
|
|
auto orig = new(bud.allocate(sizeof(string_ring::node))) string_ring::node(p); |
|
|
|
|
|
string_ring ring{orig, bud}; |
|
|
|
|
|
ring.insert("World"); |
|
|
|
|
|
auto it = ring.explore(); |
|
|
|
|
|
std::string test = ""; |
|
|
|
|
|
do{ |
|
|
|
|
|
test += *it; |
|
|
|
|
|
++it; |
|
|
|
|
|
}while(it != ring.explore()); |
|
|
|
|
|
res += (test != "HelloWorld"); |
|
|
|
|
|
} |
|
|
|
|
|
return res; |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
append_test dummy_867fdrgsd3(new ring_list_test{}); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
struct aggregator_test : public test_scaffold { |
|
|
|
|
|
aggregator_test() { |
|
|
|
|
|
name = std::string(__FILE__ "seed_") + std::to_string(seed) + ":6"; |
|
|
|
|
|
rng.seed(seed); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
std::mt19937 rng{}; |
|
|
|
|
|
int seed = std::random_device{}(); |
|
|
|
|
|
|
|
|
|
|
|
virtual int run() { |
|
|
|
|
|
int res = 0; |
|
|
|
|
|
alignas(8) gp::array<char, 4096> store; |
|
|
|
|
|
using local_allocator = gp::buddy<gp::dummy_allocator, gp::math::msb<uint64_t>(4096)>; |
|
|
|
|
|
local_allocator bud{&*store.begin(), store.size()}; |
|
|
|
|
|
alignas(8) gp::array<char, 4096> store2; |
|
|
|
|
|
local_allocator bud2{&*store2.begin(), store2.size()}; |
|
|
|
|
|
|
|
|
|
|
|
gp::aggregator allocator{bud}; |
|
|
|
|
|
allocator.insert(bud2); |
|
|
|
|
|
{ |
|
|
|
|
|
std::vector<void*> ptr_set; |
|
|
|
|
|
auto get_random_mem_qt = [&]() -> size_t { |
|
|
|
|
|
return 1+rng()%(store.size()-1); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
auto start = std::chrono::steady_clock::now(); |
|
|
|
|
|
{ |
|
|
|
|
|
gp::repeat(FUZZ_STRENGTH, [&](){ |
|
|
|
|
|
void* ptr; |
|
|
|
|
|
auto sz = get_random_mem_qt(); |
|
|
|
|
|
size_t tries = 0; |
|
|
|
|
|
std::shuffle( |
|
|
|
|
|
ptr_set.begin(), |
|
|
|
|
|
ptr_set.end(), |
|
|
|
|
|
rng |
|
|
|
|
|
); |
|
|
|
|
|
while(!(ptr = allocator.allocate(sz))) |
|
|
|
|
|
{ |
|
|
|
|
|
void* free_ptr = ptr_set.back(); |
|
|
|
|
|
ptr_set.pop_back(); |
|
|
|
|
|
gp_config::assertion(allocator.deallocate(free_ptr), "could not free sample"); |
|
|
|
|
|
gp_config::assertion(++tries <= store.size(), "infinite fuzzing"); |
|
|
|
|
|
} |
|
|
|
|
|
ptr_set.emplace_back(ptr); |
|
|
|
|
|
}); |
|
|
|
|
|
for(auto ptr : ptr_set) |
|
|
|
|
|
{ |
|
|
|
|
|
bud.deallocate(ptr); |
|
|
|
|
|
} |
|
|
|
|
|
ptr_set.resize(0); |
|
|
|
|
|
} |
|
|
|
|
|
auto duration = std::chrono::steady_clock::now() - start; |
|
|
|
|
|
} |
|
|
|
|
|
return res; |
|
|
|
|
|
} |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
append_test dummy_8ijfsd658(new aggregator_test{}); |