xo-umbrella2/xo-alloc2/utest/random_allocs.hpp
Roland Conybeare 6a82040d48 git subrepo clone git@github.com:Rconybea/xo-alloc2.git xo-alloc2
subrepo:
  subdir:   "xo-alloc2"
  merged:   "4039c29f"
upstream:
  origin:   "git@github.com:Rconybea/xo-alloc2.git"
  branch:   "main"
  commit:   "4039c29f"
git-subrepo:
  version:  "0.4.9"
  origin:   "???"
  commit:   "???"
2026-06-06 22:01:14 -04:00

46 lines
1.4 KiB
C++

/** @file random_allocs.hpp
*
* @author Roland Conybeare, Dec 2025
**/
#pragma once
#include "Allocator.hpp"
#include <xo/facet/obj.hpp>
#include <xo/randomgen/xoshiro256.hpp>
namespace utest {
/* note: trivial REQUIRE() call in else branch bc we still want
* catch2 to count assertions when verification succeeds
*/
# define REQUIRE_ORCAPTURE(ok_flag, catch_flag, expr) \
if (catch_flag) { \
REQUIRE((expr)); \
} else { \
REQUIRE(true); \
ok_flag &= (expr); \
}
# define REQUIRE_ORFAIL(ok_flag, catch_flag, expr) \
REQUIRE_ORCAPTURE(ok_flag, catch_flag, expr); \
if (!ok_flag) \
return ok_flag
struct AllocUtil {
using AAllocator = xo::mm::AAllocator;
/** generate a random sequence of allocations.
* verify allocator behavior
**/
static bool random_allocs(std::uint32_t n_alloc,
std::uint32_t max_alloc_z,
bool catch_flag,
xo::rng::xoshiro256ss * p_rgen,
xo::facet::obj<AAllocator> alloc);
};
}
/* end random_allocs.hpp */