37 #include "lib/hash-combine.hpp" 78 ,std::numeric_limits<HashVal>::max()-SEQUENCE_SPREAD});
104 uint64_t
const& distinction_;
108 : distinction_{anchor}
123 | 0b1000
'1000'1000
'1000'1000
'1000'1000
'1000; //////////////////////////////TICKET #722 : not portable because HashVal ≡ size_t — should it be? 129 buildDataGenFrom (uint64_t const& anchor) 131 DistinctNucleus seed{anchor}; 132 return PseudoRandom{seed}; 137 accessAsTestFrame (void* memoryLocation) 139 REQUIRE (memoryLocation); 140 return *reinterpret_cast<TestFrame*> (memoryLocation); 144 /* ======= static TestFrame repository ======= */ 153 struct TestFrameTable 154 : deque<deque<TestFrame>> 156 TestFrameTable() = default; 159 getFrame (uint seqNr, uint chanNr) 161 if (chanNr >= this->size()) 163 ENSURE (chanNr < this->size()); 164 deque<TestFrame>& channel = at(chanNr); 166 if (seqNr >= channel.size()) 168 INFO (test, "Growing channel #%d of test frames %d -> %d elements." 169 , chanNr, channel.size(), seqNr+1); 170 for (uint nr=channel.size(); nr<=seqNr; ++nr) 171 channel.emplace_back (nr, chanNr); 173 ENSURE (seqNr < channel.size()); 174 return channel[seqNr]; 178 std::unique_ptr<TestFrameTable> testFrames; 180 }// (End) hidden impl details 186 testData (uint seqNr, uint chanNr) 189 testFrames = std::make_unique<TestFrameTable>(); 190 return testFrames->getFrame (seqNr, chanNr); 206 testFrames.reset(); // discard existing test data repository 207 dataSeed = drawSeed (lib::defaultGen); 214 /* ======= TestFrame class ======= */ 216 TestFrame::Meta::Meta (uint seq, uint family) 217 : _MARK_{stampHeader()} 219 , distinction{generateDiscriminator (seq,family)} 223 TestFrame::~TestFrame() 225 header_.stage = DISCARDED; 229 TestFrame::TestFrame (uint seq, uint family) 230 : header_{seq,family} 233 ASSERT (0 < header_.distinction); 234 ENSURE (CREATED == header_.stage); 235 ENSURE (isPristine()); 238 TestFrame::TestFrame (TestFrame const& o) 242 header_.stage = CREATED; 246 TestFrame::operator= (TestFrame const& o) 249 throw err::Logic ("target TestFrame already dead or unaccessible"); 250 if (not util::isSameAdr (this, o)) 254 header_.stage = CREATED; 271 TestFrame::Meta::isPlausible() const 273 return _MARK_ == stampHeader() 274 and stage <= DISCARDED; 278 TestFrame::accessHeader() 280 if (not header_.isPlausible()) 281 throw err::Invalid{"TestFrame: missing or corrupted metadata"}; 284 TestFrame::Meta const& 285 TestFrame::accessHeader() const 287 return unConst(this)->accessHeader(); 290 TestFrame::StageOfLife 291 TestFrame::currStage() const 293 return header_.isPlausible()? header_.stage 298 TestFrame::Meta::operator== (Meta const&o) const 300 return isPlausible() and o.isPlausible() 302 and checksum == o.checksum 303 and distinction == o.distinction; 307 TestFrame::operator== (void* memLocation) const 309 TestFrame& candidate (accessAsTestFrame (memLocation)); 310 return candidate.isSane() 311 && candidate == *this; 315 TestFrame::contentEquals (TestFrame const& o) const 317 return data() == o.data(); 330 TestFrame::buildData() 332 auto gen = buildDataGenFrom (accessHeader().distinction); 333 for (uint64_t& dat : data64()) 342 TestFrame::matchDistinction() const 344 auto gen = buildDataGenFrom (accessHeader().distinction); 345 for (uint64_t const& dat : data64()) 346 if (dat != gen.u64()) 353 TestFrame::computeChecksum() const 356 std::hash<char> getHash; 357 for (char const& dat : data()) 358 lib::hash::combine (checksum, getHash (dat)); 364 TestFrame::markChecksum() 366 return accessHeader().checksum = computeChecksum(); 371 TestFrame::hasValidChecksum() const 373 return accessHeader().checksum == computeChecksum(); 377 TestFrame::isSane() const 379 return header_.isPlausible(); 383 TestFrame::isValid() const 386 and hasValidChecksum(); 390 TestFrame::isPristine() const 393 and matchDistinction(); 397 TestFrame::isAlive() const 404 TestFrame::isDead() const 407 and (DISCARDED == currStage()); 416 TestFrame::isAlive (void* memLocation) 418 TestFrame& candidate (accessAsTestFrame (memLocation)); 419 return candidate.isAlive(); 423 TestFrame::isDead (void* memLocation) 425 TestFrame& candidate (accessAsTestFrame (memLocation)); 426 return candidate.isDead(); 430 }}} // namespace steam::engine::test
Access point to a selection of random number sources.
const size_t SEQUENCE_SPREAD
Offset to set the seed values of »families« apart.
Types marked with this mix-in may be moved but not copied.
Random entropyGen
a global RandomSequencer seeded with real entropy
Steam-Layer implementation namespace root.
auto distribute(DIST)
generic adapter: draw next number to use the given distribution
Mix-Ins to allow or prohibit various degrees of copying and cloning.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
Helper to use a single extension point for specialised hash functions.
Establishes a seed point for any instance or performance.
HashVal hash()
non-zero hash value from full 64bit range
Lumiera error handling (C++ interface).
size_t HashVal
a STL compatible hash value
Generating (pseudo) random numbers with controlled seed.
Unit test helper to generate fake test data frames.
uint64_t generateDiscriminator(uint seq, uint family)