Block-Flow: veryfy proper handling of extent reuse
- use a checksum to prove that ctor / dtor of "content" is not invoked - let the usage of active extents "wrap around" so that the mem block is re-used - verify that the same data is still there
This commit is contained in:
parent
6409e0eb36
commit
f5813a1f29
3 changed files with 102 additions and 5 deletions
|
|
@ -276,8 +276,9 @@ namespace mem {
|
|||
REQUIRE (idx < extents_.size());
|
||||
REQUIRE (activeSlotCnt() > 0);
|
||||
|
||||
return start_ <= idx
|
||||
and idx < after_;
|
||||
return isWrapped()? (start_ <= idx and idx < extents_.size())
|
||||
or idx < after_
|
||||
: (start_ <= idx and idx < after_);
|
||||
}
|
||||
|
||||
Extent&
|
||||
|
|
|
|||
|
|
@ -28,7 +28,8 @@
|
|||
#include "lib/test/run.hpp"
|
||||
#include "vault/mem/extent-family.hpp"
|
||||
//#include "lib/time/timevalue.hpp"
|
||||
//#include "lib/format-cout.hpp"
|
||||
//#include "lib/format-cout.hpp"////////////////////TODO
|
||||
#include "lib/test/diagnostic-output.hpp"
|
||||
//#include "lib/util.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
|
@ -69,6 +70,7 @@ namespace test {
|
|||
simpleUsage();
|
||||
use_and_drop();
|
||||
iteration();
|
||||
reuseUnclean();
|
||||
wrapAround();
|
||||
}
|
||||
|
||||
|
|
@ -126,9 +128,9 @@ namespace test {
|
|||
{
|
||||
Extents extents{5};
|
||||
Iter it = extents.begin();
|
||||
CHECK (isnil (it));
|
||||
CHECK (isnil (it)); // no extents provided yet
|
||||
|
||||
extents.openNew(2); // allocate two Extents
|
||||
extents.openNew(2); // allot two extents for active use
|
||||
CHECK (it);
|
||||
CHECK (0 == it.getIndex());
|
||||
|
||||
|
|
@ -165,6 +167,77 @@ namespace test {
|
|||
|
||||
|
||||
|
||||
/** @test verify that neither constructors nor destructors are invoked
|
||||
* automatically when discarding or re-using extents.
|
||||
*/
|
||||
void
|
||||
reuseUnclean()
|
||||
{
|
||||
struct Probe
|
||||
{
|
||||
short val;
|
||||
Probe() : val(1 + rand() % 1000) { }
|
||||
~Probe() { val = 0; }
|
||||
};
|
||||
|
||||
using SpecialExtents = ExtentFamily<Probe, 100>;
|
||||
|
||||
SpecialExtents spex{3};
|
||||
spex.openNew(2);
|
||||
CHECK ( 0 == watch(spex).first());
|
||||
CHECK ( 2 == watch(spex).last());
|
||||
|
||||
// implant a new Probe object into each »slot« of the new extent
|
||||
auto& extent = *spex.begin();
|
||||
for (Probe& probe : extent)
|
||||
new(&probe) Probe;
|
||||
|
||||
auto calcChecksum = [](SpecialExtents::Extent& extent) -> size_t
|
||||
{
|
||||
size_t sum{0};
|
||||
for (Probe& probe : extent)
|
||||
sum += probe.val;
|
||||
return sum;
|
||||
};
|
||||
|
||||
size_t checksum = calcChecksum (*spex.begin());
|
||||
|
||||
// discard first extent, i.e. mark it as unused
|
||||
// while the underlying memory block remains allocated
|
||||
// and data within this block is not touched
|
||||
spex.dropOld(1);
|
||||
CHECK ( 1 == watch(spex).first());
|
||||
CHECK ( 2 == watch(spex).last());
|
||||
|
||||
// the »begin« (i.e. the first active extent is now another memory block
|
||||
CHECK (not isSameObject (extent, *spex.begin()));
|
||||
size_t checkSecond = calcChecksum (*spex.begin());
|
||||
CHECK (checkSecond != checksum);
|
||||
|
||||
// but the random data generated above still sits in the original (first) memory block
|
||||
CHECK (checksum == calcChecksum (extent));
|
||||
|
||||
// now let the actively allotted extents "wrap around"...
|
||||
spex.dropOld(1);
|
||||
CHECK ( 2 == watch(spex).first());
|
||||
CHECK ( 2 == watch(spex).last());
|
||||
spex.openNew(2);
|
||||
CHECK ( 2 == watch(spex).first());
|
||||
CHECK ( 1 == watch(spex).last());
|
||||
|
||||
auto iter = spex.begin();
|
||||
CHECK ( 2 == iter.getIndex());
|
||||
++iter;
|
||||
CHECK ( 0 == iter.getIndex());
|
||||
CHECK (isSameObject(*iter, extent));
|
||||
|
||||
// and during all those allotting and dropping, data in the memory block was not touched,
|
||||
// which also proves that constructors or destructors of the nominal "content" are not invoked
|
||||
CHECK (checksum == calcChecksum (extent));
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** @test verify in detail how iteration wraps around to also reuse
|
||||
* previously dropped extents, possibly rearranging the internal
|
||||
* management-vector to allow growing new extents at the end.
|
||||
|
|
|
|||
|
|
@ -78795,6 +78795,29 @@ Date:   Thu Apr 20 18:53:17 2023 +0200<br/>
|
|||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1689130091868" ID="ID_1078761905" MODIFIED="1689130098882" TEXT="reuseUnclean">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node COLOR="#338800" CREATED="1689130101082" ID="ID_602242804" MODIFIED="1689130136363" TEXT="spezielles Testobjekt">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
<node CREATED="1689130113232" ID="ID_1068658762" MODIFIED="1689130120747" TEXT="ctor belegt ein Feld mit Random-Werten"/>
|
||||
<node CREATED="1689130121418" ID="ID_745826511" MODIFIED="1689130134369" TEXT="dtor setzt das Feld auf 0 zurück"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1689130137965" ID="ID_856848414" MODIFIED="1689130148696" TEXT="einen größeren Block damit füllen">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1689130149324" ID="ID_102457936" MODIFIED="1689130158266" TEXT="Prüfsumme über alle diese Random-Zahlen">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1689130159170" ID="ID_1023088377" MODIFIED="1689130180869" TEXT="dann die aktiven Extents „rotieren“">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
<node COLOR="#435e98" CREATED="1689130236679" ID="ID_1843146082" MODIFIED="1689130275626" TEXT="der Block war zwischenzeitlich verworfen und wird nun neu belegt">
|
||||
<icon BUILTIN="info"/>
|
||||
</node>
|
||||
<node COLOR="#338800" CREATED="1689130190886" ID="ID_1953109784" MODIFIED="1689130271958" TEXT="verifizieren (Prüfsummen) daß die Daten im Block unverändert sind">
|
||||
<icon BUILTIN="button_ok"/>
|
||||
</node>
|
||||
</node>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1688863046274" ID="ID_121256425" MODIFIED="1688863054657" TEXT="iteration mit wrap-around">
|
||||
<icon BUILTIN="flag-yellow"/>
|
||||
<node BACKGROUND_COLOR="#eee5c3" COLOR="#990000" CREATED="1688863075348" ID="ID_619946525" MODIFIED="1688863105883" TEXT="Iteration in Normal-Stellung alloziert am Ende">
|
||||
|
|
|
|||
Loading…
Reference in a new issue