29 using std::unique_ptr;
41 using LERR_(LIFECYCLE);
50 TY* ptr =
reinterpret_cast<TY*
> (entry.access());
57 mark_as_Buffer(X& something)
59 return reinterpret_cast<metadata::Buff*
> (std::addressof(something));
63 const size_t TEST_MAX_SIZE = 1024 * 1024;
66 auto SOME_POINTER = mark_as_Buffer(JUST_SOMETHING);
86 unique_ptr<BufferMetadata>
meta_;
92 SIZE_A = 1 +
rani(TEST_MAX_SIZE);
93 SIZE_B = 1 +
rani(TEST_MAX_SIZE);
95 CHECK (ensure_proper_fixture());
96 verifyBasicProperties();
103 ensure_proper_fixture()
108 return (SIZE_A != SIZE_B)
109 && (JUST_SOMETHING != meta_->key(SIZE_A))
110 && (JUST_SOMETHING != meta_->key(SIZE_B))
116 verifyBasicProperties()
132 CHECK ( & meta_->get(key));
133 CHECK ( & meta_->get(key1));
134 CHECK ( & meta_->get(key2));
136 CHECK ( isSameObject (meta_->get(key), meta_->get(key)));
137 CHECK ( isSameObject (meta_->get(key), meta_->get(key1)));
138 CHECK (!isSameObject (meta_->get(key), meta_->get(key2)));
142 CHECK (
NIL == m1.state());
143 CHECK (!meta_->isLocked(key));
150 CHECK (!isSameObject (m1,m2));
151 CHECK (
NIL == m1.state());
152 CHECK (
LOCKED == m2.state());
153 CHECK (SOME_POINTER == m2.access());
156 HashVal keyX = meta_->key(key1, SOME_POINTER);
157 CHECK (meta_->isLocked(keyX));
158 CHECK (keyX != key1);
161 CHECK ( isSameObject (m1, meta_->get(key)));
162 CHECK ( isSameObject (m1, meta_->get(key1)));
163 CHECK ( isSameObject (m2, meta_->get(keyX)));
164 CHECK ( key1 == m2.parentKey());
167 CHECK (
LOCKED == m2.state());
170 CHECK (SOME_POINTER == m2.access());
171 CHECK ( meta_->isLocked(keyX));
172 CHECK ( meta_->isKnown(keyX));
176 CHECK (!meta_->isLocked(keyX));
177 CHECK ( meta_->isKnown(keyX));
178 CHECK ( meta_->isKnown(key1));
181 CHECK ( isSameObject (m2, meta_->get(keyX)));
184 meta_->release(keyX);
185 CHECK (!meta_->isLocked(keyX));
186 CHECK (!meta_->isKnown(keyX));
187 CHECK ( meta_->isKnown(key1));
203 TypeHandler attachTestFrame = TypeHandler::create<TestFrame>();
212 bufferType1 = meta_->key(bufferType1, transaction1);
213 rawBuffType = meta_->key(rawBuffType, transaction2);
218 using RawBuffer = std::byte;
219 void* storage = malloc (2*SIZE_B);
222 RawBuffer* rawbuf = (RawBuffer*)storage;
226 metadata::Entry& f0 = meta_->markLocked(bufferType1, mark_as_Buffer(frames[0]));
227 metadata::Entry& f1 = meta_->markLocked(bufferType1, mark_as_Buffer(frames[1]));
228 metadata::Entry& f2 = meta_->markLocked(bufferType1, mark_as_Buffer(frames[2]));
230 metadata::Entry& r0 = meta_->markLocked(rawBuffType, mark_as_Buffer(rawbuf[ 0]));
231 metadata::Entry& r1 = meta_->markLocked(rawBuffType, mark_as_Buffer(rawbuf[SIZE_B]));
233 CHECK (
LOCKED == f0.state());
234 CHECK (
LOCKED == f1.state());
235 CHECK (
LOCKED == f2.state());
236 CHECK (
LOCKED == r0.state());
237 CHECK (
LOCKED == r1.state());
239 CHECK (transaction1 == f0.localTag());
240 CHECK (transaction1 == f1.localTag());
241 CHECK (transaction1 == f2.localTag());
242 CHECK (transaction2 == r0.localTag());
243 CHECK (transaction2 == r1.localTag());
245 auto adr =[](
auto* x){
return reinterpret_cast<size_t>(x); };
247 CHECK (adr(f0.access()) == adr(frames+0));
248 CHECK (adr(f1.access()) == adr(frames+1));
249 CHECK (adr(f2.access()) == adr(frames+2));
250 CHECK (adr(r0.access()) == adr(rawbuf+0 ));
251 CHECK (adr(r1.access()) == adr(rawbuf+SIZE_B));
254 CHECK (defaultFrame == f0.access());
255 CHECK (defaultFrame == f1.access());
256 CHECK (defaultFrame == f2.access());
266 accessAs<TestFrame> (f0) =
testData(1);
267 accessAs<TestFrame> (f1) =
testData(2);
268 accessAs<TestFrame> (f2) =
testData(3);
274 CHECK (TestFrame::isAlive (f0.access()));
275 CHECK (TestFrame::isAlive (f1.access()));
276 CHECK (TestFrame::isAlive (f2.access()));
278 strncpy (& accessAs<char> (r0), randStr(SIZE_B - 1).c_str(), SIZE_B);
279 strncpy (& accessAs<char> (r1), randStr(SIZE_B - 1).c_str(), SIZE_B);
295 meta_->release(handle_f0);
296 meta_->release(handle_f1);
297 meta_->release(handle_f2);
298 meta_->release(handle_r0);
299 meta_->release(handle_r1);
301 CHECK (TestFrame::isDead (&frames[0]));
302 CHECK (TestFrame::isDead (&frames[1]));
303 CHECK (TestFrame::isDead (&frames[2]));
309 CHECK (!meta_->isLocked(handle_f0));
310 CHECK (!meta_->isLocked(handle_f1));
311 CHECK (!meta_->isLocked(handle_f2));
312 CHECK (!meta_->isLocked(handle_r0));
313 CHECK (!meta_->isLocked(handle_r1));
322 CHECK (
NIL == meta_->get(key).state());
323 CHECK (meta_->get(key).isTypeKey());
324 CHECK (!meta_->isLocked(key));
334 CHECK (
LOCKED == entry.state());
335 CHECK (!entry.isTypeKey());
337 CHECK (SOME_POINTER == entry.access());
343 CHECK (
EMITTED == entry.state());
344 CHECK (entry.isLocked());
349 CHECK (
EMITTED == entry.state());
352 CHECK (
FREE == entry.state());
353 CHECK (!entry.isLocked());
354 CHECK (!entry.isTypeKey());
364 auto* SOME_OTHER_LOCATION = mark_as_Buffer(*
this);
365 entry.lock (SOME_OTHER_LOCATION);
366 CHECK (
LOCKED == entry.state());
367 CHECK (entry.isLocked());
372 CHECK (
BLOCKED == entry.state());
378 CHECK (SOME_OTHER_LOCATION == entry.access());
381 CHECK (!entry.isLocked());
384 meta_->lock(key, SOME_POINTER);
385 CHECK (entry.isLocked());
389 CHECK (
BLOCKED == entry.state());
390 CHECK (SOME_POINTER == entry.access());
394 CHECK (meta_->isKnown(entry));
395 CHECK (entry.isLocked());
398 meta_->release(entry);
399 CHECK (!meta_->isKnown(entry));
400 CHECK ( meta_->isKnown(key));
allocated buffer, no longer in use
Mock data frame for simulated rendering.
AnyPair entry(Query< TY > const &query, typename WrapReturn< TY >::Wrapper &obj)
helper to simplify creating mock table entries, wrapped correctly
int rani(uint bound=_iBOUND())
#define VERIFY_ERROR(ERROR_ID, ERRONEOUS_STATEMENT)
Macro to verify that a statement indeed raises an exception.
allocated buffer blocked by protocol failure
an opaque mark to be used by the BufferProvider implementation.
allocated buffer, returned from client
allocated buffer actively in use
Entry & mark(BufferState newState)
Buffer state machine.
Steam-Layer implementation namespace root.
string randStr(size_t len)
create garbage string of given length
Simplistic test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
A collection of frequently used helper functions to support unit testing.
Lumiera error handling (C++ interface).
size_t HashVal
a STL compatible hash value
A pair of functors to maintain a datastructure within a buffer.
abstract entry, not yet allocated
Unit test helper to generate fake test data frames.
placeholder type for the contents of a data buffer.
A complete metadata Entry, based on a Key.
TestFrame & testData(uint seqNr, uint chanNr)
Helper to access a specific frame of test data at a fixed memory location.
bool isSameObject(A const &a, B const &b)
compare plain object identity, based directly on the referee's memory identities. ...