Skip to content

Commit

Permalink
More fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mr-Wiseguy committed Oct 17, 2024
1 parent a6d63ae commit 1510e4a
Showing 1 changed file with 11 additions and 19 deletions.
30 changes: 11 additions & 19 deletions tests/test_general.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
// Authors: Pavel Kirienko <[email protected]>

#include "internal.hpp"
#include <cstdlib>
#include <algorithm>
#include <array>
#include <cstdlib>
#include <iostream>
#include <random>

Expand All @@ -27,24 +27,16 @@ constexpr std::size_t KiB = 1024U;
constexpr std::size_t MiB = KiB * KiB;

#ifdef _WIN32
void* my_aligned_alloc(size_t align, size_t size)
{
return _aligned_malloc(size, align);
}

void my_aligned_free(void* mem)
auto make_arena(size_t align, size_t size) -> std::shared_ptr<std::byte>
{
_aligned_free(mem);
return std::shared_ptr<std::byte>(static_cast<std::byte*>(_aligned_malloc(size, align)),
&_aligned_free);
}
#else
void* my_aligned_alloc(size_t align, size_t size)
{
return std::aligned_alloc(align, size);
}

void my_aligned_free(void* mem)
auto make_arena(size_t align, size_t size) -> std::shared_ptr<std::byte>
{
std::aligned_free(mem);
return std::shared_ptr<std::byte>(static_cast<std::byte*>(std::aligned_alloc(align, size)),
&_aligned_free);
}
#endif

Expand Down Expand Up @@ -159,7 +151,7 @@ TEST_CASE("General: allocate: OOM")
{
constexpr auto MiB256 = MiB * 256U;
constexpr auto ArenaSize = MiB256 + MiB;
const std::shared_ptr<std::byte> arena(static_cast<std::byte*>(my_aligned_alloc(64U, ArenaSize)), &my_aligned_free);
const std::shared_ptr<std::byte> arena = make_arena(64U, ArenaSize);

auto heap = init(arena.get(), ArenaSize);
REQUIRE(heap != nullptr);
Expand Down Expand Up @@ -200,7 +192,7 @@ TEST_CASE("General: allocate: smallest")
using internal::Fragment;

constexpr auto ArenaSize = MiB * 300U;
const std::shared_ptr<std::byte> arena(static_cast<std::byte*>(my_aligned_alloc(64U, ArenaSize)), &my_aligned_free);
const std::shared_ptr<std::byte> arena = make_arena(64U, ArenaSize);

auto heap = init(arena.get(), ArenaSize);
REQUIRE(heap != nullptr);
Expand Down Expand Up @@ -232,7 +224,7 @@ TEST_CASE("General: allocate: size_t overflow")
constexpr auto size_max = std::numeric_limits<uint32_t>::max();

constexpr auto ArenaSize = MiB * 300U;
const std::shared_ptr<std::byte> arena(static_cast<std::byte*>(my_aligned_alloc(64U, ArenaSize)), &my_aligned_free);
const std::shared_ptr<std::byte> arena = make_arena(64U, ArenaSize);

auto heap = init(arena.get(), ArenaSize);
REQUIRE(heap != nullptr);
Expand Down Expand Up @@ -504,7 +496,7 @@ TEST_CASE("General: random A")
using internal::Fragment;

constexpr auto ArenaSize = MiB * 300U;
const std::shared_ptr<std::byte> arena(static_cast<std::byte*>(my_aligned_alloc(64U, ArenaSize)), &my_aligned_free);
const std::shared_ptr<std::byte> arena = make_arena(64U, ArenaSize);
std::generate_n(arena.get(), ArenaSize, getRandomByte); // Random-fill the ENTIRE arena!
auto heap = init(arena.get(), ArenaSize);
REQUIRE(heap != nullptr);
Expand Down

0 comments on commit 1510e4a

Please sign in to comment.