Commit bf930c46 authored by Pietro Saccardi's avatar Pietro Saccardi

Test resident allocator.

parent a71a60be
Pipeline #568 passed with stages
in 2 minutes and 49 seconds
......@@ -19,7 +19,7 @@ add_library(pwmpi src/dma/cb.h src/bcm/base.h src/dma/ti.h src/mem/bmap.h src/dm
add_executable(pwmpi-demo src/main.cpp src/misc.h)
add_executable(pwmpi-test test/utmain.cpp test/test_allocation_table.cpp)
add_executable(pwmpi-test test/utmain.cpp test/test_allocation_table.cpp test/test_resident_allocator.cpp)
target_link_libraries(pwmpi-demo pwmpi)
target_link_libraries(pwmpi-test pwmpi)
......
......@@ -5,7 +5,6 @@
#include <catch2/catch.hpp>
#include <mem/allocation_table.h>
#include <array>
#include <misc.h>
namespace {
inline mem::chunk mkchunk(std::uintptr_t ofs, std::size_t sz) {
......
//
// Created by Pietro Saccardi on 04/09/2019.
//
#include <catch2/catch.hpp>
#include <mem/resident_allocator.h>
TEST_CASE("Allocate simple", "[resident_allocator]") {
mem::resident_memory_resource pmr;
static constexpr std::size_t sz = 100;
void * const addr = pmr.allocate(sz);
REQUIRE(pmr.pool_size() >= sz);
if (pmr.pool_size() > sz) {
REQUIRE(pmr.num_fragments() == 1);
REQUIRE(pmr.largest_fragment_size() == pmr.pool_size() - sz);
} else {
REQUIRE(pmr.num_fragments() == 0);
REQUIRE(pmr.largest_fragment_size() == 0);
}
REQUIRE(pmr.used_memory() == sz);
pmr.deallocate(addr, sz);
REQUIRE(pmr.num_fragments() == 1);
REQUIRE(pmr.largest_fragment_size() == pmr.pool_size());
REQUIRE(pmr.pool_size() >= sz);
REQUIRE(pmr.available_memory() == pmr.pool_size());
REQUIRE(pmr.used_memory() == 0);
const auto saved_spc = pmr.try_reduce_pool_size();
REQUIRE(saved_spc >= sz);
REQUIRE(pmr.num_fragments() == 0);
REQUIRE(pmr.pool_size() == 0);
REQUIRE(pmr.largest_fragment_size() == 0);
REQUIRE(pmr.available_memory() == 0);
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment