Browse Source

Fixed a buf in ring_list, found another (see test cases)

pull/5/head
Ludovic 'Archivist' Lagouardette 3 years ago
parent
commit
43c9503ace
6 changed files with 99 additions and 18 deletions
  1. +1
    -1
      Makefile
  2. +1
    -1
      include/gp/flat_tree.hpp
  3. +6
    -6
      include/gp/ring_list.hpp
  4. +71
    -10
      tests/gp_test.cpp
  5. +5
    -0
      tests/math.cpp
  6. +15
    -0
      tests/test_scaffold.h

+ 1
- 1
Makefile View File

@ -1,5 +1,5 @@
CXX= clang++-10
CXXFLAGS= --std=c++17 -O0 -pthread -DGP_TESTS -DFUZZ_STRENGTH=500 -pedantic -Werror \
CXXFLAGS= --std=c++17 -O3 -pthread -DGP_TESTS -DFUZZ_STRENGTH=500 -DNO_BENCH=0 -pedantic -Werror \
-Wno-unknown-attributes -frtti \
-g -fprofile-instr-generate -fcoverage-mapping \
-fsanitize=address -fno-omit-frame-pointer

+ 1
- 1
include/gp/flat_tree.hpp View File

@ -6,6 +6,6 @@
template<typename T, size_t depth>
class flat_tree {
gp::array<T, (p">(1 << depth) << 1) & 1> data_;
gp::array<T, (1 << depth) - 1> data_;
};

+ 6
- 6
include/gp/ring_list.hpp View File

@ -131,8 +131,8 @@ namespace gp {
}
void remove(explorer& value) {
auto& v = o">*value;
if(v == explore()) {
auto v = n">value.pos;
if(v == any_node) {
if(v->next == v) {
any_node = nullptr;
} else {
@ -142,10 +142,10 @@ namespace gp {
stitch_around(value.pos);
}
allocator& used_allocator = alloc;
vp">.value->~T();
gp_config::assertion(used_allocator.deallocate(vp">.value), "Bad free of value");
value.pos->~node();
gp_config::assertion(used_allocator.deallocate(value.pos), "Bad free of node");
vo">->value->~T();
gp_config::assertion(used_allocator.deallocate(vo">->value), "Bad free of value");
v->~node();
gp_config::assertion(used_allocator.deallocate(v), "Bad free of node");
}
};
}

+ 71
- 10
tests/gp_test.cpp View File

@ -316,16 +316,17 @@ struct buddy_fuzz_test : public test_scaffold {
}
auto reference = std::chrono::steady_clock::now() - start;
std::cout
<< "Fuzzing timed at "
<< std::chrono::duration_cast<std::chrono::microseconds>(duration).count()
<< "µs for "
<< FUZZ_STRENGTH
<< " (reference: "
<< std::chrono::duration_cast<std::chrono::microseconds>(reference).count()
<< "µs)"
<< std::endl;
if(do_bench){
std::cout
<< "Fuzzing timed at "
<< std::chrono::duration_cast<std::chrono::microseconds>(duration).count()
<< "µs for "
<< FUZZ_STRENGTH
<< " (reference: "
<< std::chrono::duration_cast<std::chrono::microseconds>(reference).count()
<< "µs)"
<< std::endl;
}
return res;
}
@ -688,3 +689,63 @@ struct endian_test : public test_scaffold {
};
append_test dummy_45zelotf5f5(new endian_test{});
struct alloc_bench_test : public test_scaffold {
alloc_bench_test() {
name = __FILE__ ":12";
}
virtual int run() {
int res = 0;
auto store = std::make_unique<std::array<char, 1 << 16>>();
using buddy_loc = gp::buddy<>;
using arena_loc = gp::arena<>;
buddy_loc bud{&*store->begin(), store->size()};
arena_loc are{&*store->begin(), store->size()};
for(size_t divider = 2; divider < 32; ++divider)
{
gp::ring_list<int, buddy_loc> a{bud};
gp::ring_list<int, arena_loc> b{are};
std::cout <<
"ARE | " << "INS | " << divider << " | " <<
time_operation([&](){
for(size_t i = 0; i < store->size()/sizeof(gp::ring_list<int, arena_loc>::node)/divider; i++) {
b.insert(i);
}
}).count() << std::endl;
std::cout <<
"ARE | " << "DEL | " << divider << " | " <<
time_operation([&](){
for(size_t i = 0; i < store->size()/sizeof(gp::ring_list<int, arena_loc>::node)/divider; i++) {
gp::ring_list<int, arena_loc>::explorer e = b.explore();
b.remove(e);
}
}).count() << std::endl;
std::cout <<
"BUD | " << "INS | " << divider << " | " <<
time_operation([&](){
for(size_t i = 0; i < store->size()/sizeof(gp::ring_list<int, buddy_loc>::node)/divider; i++) {
a.insert(i);
}
}).count() << std::endl;
std::cout <<
"BUD | " << "DEL | " << divider << " | " <<
time_operation([&](){
for(size_t i = 0; i < store->size()/sizeof(gp::ring_list<int, buddy_loc>::node)/divider; i++) {
gp::ring_list<int, buddy_loc>::explorer e = a.explore();
a.remove(e);
}
}).count() << std::endl;
}
return res;
}
};
append_test dummy_jhgspo5d5(new alloc_bench_test{});

+ 5
- 0
tests/math.cpp View File

@ -28,6 +28,11 @@ struct sin_test : public test_scaffold {
float ref = cos(i);
res += 0.3 < gp::abs<float>(ref - v)*100.0/(gp::abs(ref+0.00000001));
}
for(float i = 0; i < 100; i += 0.1) {
float v = gp::cos(i)*gp::cos(i) + gp::sin(i)*gp::sin(i);
res += 1 + gp_config::rendering::epsilon < v;
res += 1 - gp_config::rendering::epsilon > v;
}
return res;
}

+ 15
- 0
tests/test_scaffold.h View File

@ -2,6 +2,21 @@
#include <string>
#include <vector>
#include <memory>
#include <chrono>
#ifndef NO_BENCH
#define NO_BENCH 1
#endif
constexpr bool do_bench = 1 - NO_BENCH;
template<typename fn>
std::chrono::microseconds time_operation(fn op) {
auto start = std::chrono::high_resolution_clock::now();
op();
auto time = std::chrono::high_resolution_clock::now() - start;
return std::chrono::duration_cast<std::chrono::microseconds>(time);
}
struct test_scaffold{
std::string name;

Loading…
Cancel
Save