42# include <gtest/gtest.h>
65 Array<L> distinct_frames(
const int n)
68 for (
int k = 0;
k < n; ++
k)
72 frames.
append(std::move(frame));
81TEST(StationaryDetectorAllocation, AFailedBufferingReachesTheCaller)
84 GTEST_SKIP() <<
"ThreadSanitizer replaces the global operator new";
86 constexpr int Frames = 40;
87 const Array<L> frames = distinct_frames(Frames);
93 for (
int k = 1;
k < Frames; ++
k)
95 SCOPED_TRACE(
"step " + std::to_string(
k));
99 const Fail_At failing(1);
104 catch (
const std::bad_alloc &)
108 refused += refused_allocations;
116 EXPECT_EQ(refused_allocations, 0u) <<
"no std::bad_alloc reached the caller";
120 EXPECT_GT(refused, 0u) <<
"the buffers did not grow under a failure";
126 EXPECT_EQ(*det.
cycle_length(),
static_cast<size_t>(Frames - 5));
133TEST(StationaryDetectorAllocation, AFullSmallWindowKeepsEachHashWithItsStep)
136 GTEST_SKIP() <<
"ThreadSanitizer replaces the global operator new";
138 constexpr int Frames = 24;
139 const Array<L> frames = distinct_frames(Frames);
140 for (
size_t window = 1; window <= 12; ++window)
142 SCOPED_TRACE(
"window " + std::to_string(window));
145 for (
int k = 1;
k < Frames; ++
k)
149 const Fail_At failing(1);
154 catch (
const std::bad_alloc &)
162 EXPECT_EQ(refused_allocations, 0u) <<
"no std::bad_alloc reached the caller";
168 const size_t seen = Frames - window;
182TEST(StationaryDetectorAllocation, AFrameLostToAFailureMakesNoLongerCycle)
185 GTEST_SKIP() <<
"ThreadSanitizer replaces the global operator new";
187 constexpr size_t Window = 32;
188 const Array<L> frames = distinct_frames(
static_cast<int>(Window) + 2);
189 for (
const size_t again : {
size_t{0},
size_t{1}})
191 SCOPED_TRACE(
"the frame " + std::to_string(again) +
" at the step 34");
195 for (
size_t k = 1;
k <= Window + 1; ++
k)
197 const Fail_At failing(
k == Window ? 1 : 1000000);
202 catch (
const std::bad_alloc &)
207 ASSERT_EQ(lost, 1u) <<
"the buffering of the step 32 did not allocate";
222 for (
size_t k = 1;
k <= Window; ++
k)
A global operator new that a test can make fail.
#define ALEPH_ALLOCATION_FAILURE_UNDER_TSAN
Phase-7 observability layer for cellular automata engines.
Simple dynamic array with automatic resizing and functional operations.
T & append(const T &data)
Append a copy of data
Lattice that adds boundary-aware access on top of a storage.
Detects fixed points and short cycles via frame hashing.
std::size_t buffered_hashes() const noexcept
Return the number of buffered hashes.
std::optional< std::size_t > cycle_start() const noexcept
Return the cycle start step.
bool cycle_detected() const noexcept
Return whether a cycle has been detected.
std::optional< std::size_t > cycle_length() const noexcept
Return the detected cycle length.
void on_step_end(std::size_t step, const Lattice &frame)
Check the completed frame against the recent hash window.
void on_step_begin(const std::size_t step, const Lattice &frame)
Seed the detector with the initial frame hash.
Main namespace for Aleph-w library functions.
The lattice wraps around on every axis.
Dynamic array container with automatic resizing.
Cellular automata lattice with pluggable boundary policies.
Dense, contiguous storage for cellular automata cells (1D/2D/3D).