diff --git a/CMakeLists.txt b/CMakeLists.txt index 7ee5925..1201438 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/include/blt/gp/stack.h b/include/blt/gp/stack.h index e461205..89f1d17 100644 --- a/include/blt/gp/stack.h +++ b/include/blt/gp/stack.h @@ -64,7 +64,8 @@ namespace blt::gp stream << (static_cast(data.total_used_bytes) / static_cast(data.total_size_bytes) * 100) << "%), "; stream << data.total_used_bytes << "/"; stream << data.total_no_meta_bytes << "("; - stream << (static_cast(data.total_used_bytes) / static_cast(data.total_no_meta_bytes) * 100) << "%), (empty space: "; + stream << (static_cast(data.total_used_bytes) / static_cast(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(data.total_dealloc_used) / static_cast(data.total_dealloc_no_meta * 100)) << "%)"; + stream << "(" << (static_cast(data.total_dealloc_used) / static_cast(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) @@ -346,6 +347,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 diff --git a/tests/stack_tests.cpp b/tests/stack_tests.cpp index 7af1dac..1b665fa 100644 --- a/tests/stack_tests.cpp +++ b/tests/stack_tests.cpp @@ -280,6 +280,59 @@ void test_basic() auto val = stack.pop(); 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{}); + 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()(nullptr, stack, stack); + auto val = stack.pop(); + stack.pop>(); + 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()(nullptr, stack, stack); + BLT_TRACE_STREAM << stack.size() << "\n"; + auto val = stack.pop(); + 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{}); + 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()(nullptr, stack, stack); + auto val = stack.pop(); + stack.pop>(); + 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()