more stack tests, remove debug statement
parent
58b68b70bb
commit
9a43cd7e81
|
@ -1,5 +1,5 @@
|
|||
cmake_minimum_required(VERSION 3.25)
|
||||
project(blt-gp VERSION 0.0.100)
|
||||
project(blt-gp VERSION 0.0.101)
|
||||
|
||||
include(CTest)
|
||||
|
||||
|
|
|
@ -64,7 +64,8 @@ namespace blt::gp
|
|||
stream << (static_cast<double>(data.total_used_bytes) / static_cast<double>(data.total_size_bytes) * 100) << "%), ";
|
||||
stream << data.total_used_bytes << "/";
|
||||
stream << data.total_no_meta_bytes << "(";
|
||||
stream << (static_cast<double>(data.total_used_bytes) / static_cast<double>(data.total_no_meta_bytes) * 100) << "%), (empty space: ";
|
||||
stream << (static_cast<double>(data.total_used_bytes) / static_cast<double>(data.total_no_meta_bytes) * 100)
|
||||
<< "%), (empty space: ";
|
||||
stream << data.total_remaining_bytes << ") blocks: " << data.blocks << " || unallocated space: ";
|
||||
stream << data.total_dealloc_used << "/";
|
||||
stream << data.total_dealloc;
|
||||
|
@ -74,7 +75,8 @@ namespace blt::gp
|
|||
stream << data.total_dealloc_used << "/";
|
||||
stream << data.total_dealloc_no_meta;
|
||||
if (data.total_dealloc_no_meta > 0)
|
||||
stream << "(" << (static_cast<double>(data.total_dealloc_used) / static_cast<double>(data.total_dealloc_no_meta * 100)) << "%)";
|
||||
stream << "(" << (static_cast<double>(data.total_dealloc_used) / static_cast<double>(data.total_dealloc_no_meta * 100))
|
||||
<< "%)";
|
||||
stream << ", (empty space: " << data.total_dealloc_remaining << ")]";
|
||||
return stream;
|
||||
}
|
||||
|
@ -176,7 +178,6 @@ namespace blt::gp
|
|||
#endif
|
||||
#endif
|
||||
auto diff = head->used_bytes_in_block() - bytes;
|
||||
BLT_TRACE(diff);
|
||||
// if there is not enough room left to pop completely off the block, then move to the next previous block
|
||||
// and pop from it, update the amount of bytes to reflect the amount removed from the current block
|
||||
if (diff < 0)
|
||||
|
@ -347,6 +348,31 @@ namespace blt::gp
|
|||
return (size + (MAX_ALIGNMENT - 1)) & ~(MAX_ALIGNMENT - 1);
|
||||
}
|
||||
|
||||
inline static constexpr auto metadata_size()
|
||||
{
|
||||
return sizeof(typename block::block_metadata_t);
|
||||
}
|
||||
|
||||
inline static constexpr auto block_size()
|
||||
{
|
||||
return sizeof(block);
|
||||
}
|
||||
|
||||
inline static constexpr auto page_size()
|
||||
{
|
||||
return PAGE_SIZE;
|
||||
}
|
||||
|
||||
inline static constexpr auto page_size_no_meta()
|
||||
{
|
||||
return page_size() - metadata_size();
|
||||
}
|
||||
|
||||
inline static constexpr auto page_size_no_block()
|
||||
{
|
||||
return page_size() - block_size();
|
||||
}
|
||||
|
||||
private:
|
||||
struct block
|
||||
{
|
||||
|
|
|
@ -280,6 +280,59 @@ void test_basic()
|
|||
auto val = stack.pop<float>();
|
||||
RUN_TEST(val != 60.000000f, stack, "Basic 2 Test Passed", "Basic 2 Test Failed. Unexpected value produced '%lf'", val);
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
BLT_ASSERT(stack.empty() && "Stack was not empty after basic evaluation.");
|
||||
}
|
||||
BLT_INFO("Testing basic with stack over boundary");
|
||||
{
|
||||
blt::gp::stack_allocator stack;
|
||||
stack.push(std::array<blt::u8, blt::gp::stack_allocator::page_size_no_block() - sizeof(float)>{});
|
||||
stack.push(50.0f);
|
||||
stack.push(10.0f);
|
||||
auto size = stack.size();
|
||||
BLT_TRACE_STREAM << size << "\n";
|
||||
BLT_ASSERT(size.blocks > 1 && "Stack doesn't have more than one block!");
|
||||
basic_2.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
|
||||
auto val = stack.pop<float>();
|
||||
stack.pop<std::array<blt::u8, blt::gp::stack_allocator::page_size_no_block() - sizeof(float)>>();
|
||||
RUN_TEST(val != 60.000000f, stack, "Basic 2 Boundary Test Passed", "Basic 2 Test Failed. Unexpected value produced '%lf'", val);
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
BLT_ASSERT(stack.empty() && "Stack was not empty after basic evaluation over stack boundary");
|
||||
}
|
||||
}
|
||||
|
||||
void test_mixed()
|
||||
{
|
||||
BLT_INFO("Testing mixed with stack");
|
||||
{
|
||||
blt::gp::stack_allocator stack;
|
||||
stack.push(50.0f);
|
||||
stack.push(10.0f);
|
||||
stack.push(true);
|
||||
stack.push(false);
|
||||
basic_mixed_4.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
auto val = stack.pop<float>();
|
||||
RUN_TEST(val != 50.000000f, stack, "Mixed 4 Test Passed", "Mixed 4 Test Failed. Unexpected value produced '%lf'", val);
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
BLT_ASSERT(stack.empty() && "Stack was not empty after basic evaluation.");
|
||||
}
|
||||
BLT_INFO("Testing mixed with stack over boundary");
|
||||
{
|
||||
blt::gp::stack_allocator stack;
|
||||
stack.push(std::array<blt::u8, blt::gp::stack_allocator::page_size_no_block() - sizeof(float)>{});
|
||||
stack.push(50.0f);
|
||||
stack.push(10.0f);
|
||||
stack.push(false);
|
||||
stack.push(true);
|
||||
auto size = stack.size();
|
||||
BLT_TRACE_STREAM << size << "\n";
|
||||
BLT_ASSERT(size.blocks > 1 && "Stack doesn't have more than one block!");
|
||||
basic_mixed_4.make_callable<blt::gp::detail::empty_t>()(nullptr, stack, stack);
|
||||
auto val = stack.pop<float>();
|
||||
stack.pop<std::array<blt::u8, blt::gp::stack_allocator::page_size_no_block() - sizeof(float)>>();
|
||||
RUN_TEST(val != 10.000000f, stack, "Mixed 4 Boundary Test Passed", "Mixed 4 Test Failed. Unexpected value produced '%lf'", val);
|
||||
BLT_TRACE_STREAM << stack.size() << "\n";
|
||||
BLT_ASSERT(stack.empty() && "Stack was not empty after basic evaluation over stack boundary");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -287,6 +340,8 @@ void test_operators()
|
|||
{
|
||||
log_box box("-----------------------{Operator Testing}-----------------------", BLT_INFO_STREAM);
|
||||
test_basic();
|
||||
BLT_NEWLINE();
|
||||
test_mixed();
|
||||
}
|
||||
|
||||
int main()
|
||||
|
|
Loading…
Reference in New Issue