#include "test_scaffold.h" #include "gp/array.hpp" #include "gp/allocator/buddy.hpp" #include "gp/allocator/dummy.hpp" #include #include #include #include #include #include struct arraysum_test : public test_scaffold { arraysum_test() { name = __FILE__ ":1"; } virtual int run() { gp::array test; for(auto& elem : test) { elem = 12; } return std::accumulate(test.begin(), test.end(), 0) != 12*test.size(); } }; append_test dummy_sd45uisd3(new arraysum_test{}); struct optional_test : public test_scaffold { optional_test() { name = __FILE__ ":1"; } virtual int run() { int res = 0; { gp::optional test; if(test.has_value()) { res++; } test = 12; if(test.has_value()) { if(test.value()!=12) { res++; } } else { res++; } } { gp::optional test; if(test.has_value()) { res++; } test = std::ifstream("/proc/cpuinfo"); if(!test.has_value()) { res++; } } return res; } }; append_test dummy_mlyusisd3(new optional_test{}); struct buddy_test : public test_scaffold { buddy_test() { name = __FILE__ ":3"; } gp::array store; virtual int run() { int res = 0; { gp::buddy(4096)> bud{&*store.begin(), store.size()}; std::set ptr_set; for(int i = 0; i < 4096 / 8; i++) { void* v = bud.allocate(8); if(v == nullptr) throw gp::runtime_error("allocation failed"); ptr_set.insert(v); } std::cout << ptr_set.size() << "//" << ptr_set.count(nullptr); if(ptr_set.count(nullptr)!=0 || ptr_set.size()!=(4096/8)) throw gp::runtime_error("some allocations failed"); res++; res += nullptr == bud.allocate(8); if(nullptr != bud.allocate(8)) throw gp::runtime_error("allocation succeeded, failure was expected"); ++res; } return res; } }; append_test dummy_654sisd3(new buddy_test{});