From 991eec81853d839d29e3ec45c5414d3e5a5547ac Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Mon, 17 Oct 2011 02:00:48 +0200 Subject: [PATCH] draft test to simulate a complete buffer metadata usage cycle --- src/proc/engine/buffer-metadata.hpp | 16 ++-- src/proc/engine/buffhandle.hpp | 3 + .../proc/engine/buff-table-test.cpp | 8 +- .../proc/engine/buffer-metadata-test.cpp | 84 +++++++++++++++++++ .../engine/buffer-provider-protocol-test.cpp | 2 +- tests/components/proc/engine/testframe.hpp | 4 +- 6 files changed, 101 insertions(+), 16 deletions(-) diff --git a/src/proc/engine/buffer-metadata.hpp b/src/proc/engine/buffer-metadata.hpp index d6a4cd477..6addaf574 100644 --- a/src/proc/engine/buffer-metadata.hpp +++ b/src/proc/engine/buffer-metadata.hpp @@ -479,22 +479,20 @@ namespace engine { /** create a sub-type, using a different type/handler functor */ Key - key (HashVal parentKey, TypeHandler const& instanceFunc) + key (Key const& parentKey, TypeHandler const& instanceFunc) { - Key parentEntry (get (parentKey)); - return trackKey (parentEntry, instanceFunc); + return trackKey (parentKey, instanceFunc); } /** create a sub-type, using a different private-ID (implementation defined) */ Key - key (HashVal parentKey, LocalKey specifics) + key (Key const& parentKey, LocalKey specifics) { - Key parentEntry (get (parentKey)); - return trackKey (parentEntry, specifics); + return trackKey (parentKey, specifics); } Key - key (HashVal parentKey, const void* concreteBuffer) + key (Key const& parentKey, const void* concreteBuffer) { UNIMPLEMENTED ("create sub-object key for concrete buffer"); } @@ -526,7 +524,7 @@ namespace engine { /* == memory management == */ - Entry& markLocked (HashVal parentKey, const void* buffer); + Entry& markLocked (Key const& parentKey, const void* buffer); void release (HashVal key); private: @@ -558,7 +556,7 @@ namespace engine { /** */ inline Metadata::Entry& - Metadata::markLocked (HashVal parentKey, const void* buffer) + Metadata::markLocked (Key const& parentKey, const void* buffer) { UNIMPLEMENTED ("transition to locked state"); if (!buffer) diff --git a/src/proc/engine/buffhandle.hpp b/src/proc/engine/buffhandle.hpp index 8401bdb17..df7018e05 100644 --- a/src/proc/engine/buffhandle.hpp +++ b/src/proc/engine/buffhandle.hpp @@ -61,6 +61,9 @@ namespace engine { * For each kind of buffer, there is somewhere a BufferProvider responsible for the * actual storage management. This provider may "lock" a buffer for actual use, * returning a BuffHandle. + * @note this descriptor and especially the #subClassification_ is really owned + * by the BufferProvider, which may use (and even change) the opaque contents + * to organise the internal buffer management. * * @todo try to move that definition into buffer-provider.hpp ////////////////////////////////////TICKET #249 */ diff --git a/tests/components/proc/engine/buff-table-test.cpp b/tests/components/proc/engine/buff-table-test.cpp index 06ff34e54..76f9c2f2d 100644 --- a/tests/components/proc/engine/buff-table-test.cpp +++ b/tests/components/proc/engine/buff-table-test.cpp @@ -81,7 +81,7 @@ namespace test { -#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #833 +#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #852 void* detect_start_level (BuffTableStorage& sto) { @@ -117,7 +117,7 @@ namespace test { && (not_within(b.inHandle, b.outBuff, &b.inBuff[num.nrO])) ; } -#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #833 +#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #852 } // (End) internal defs @@ -144,9 +144,9 @@ namespace test { // allocate storage block to be used chunk wise pStorage.reset (new BuffTableStorage (TABLE_SIZ)); -#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #833 +#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #852 invocation (0, detect_start_level(*pStorage)); -#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #833 +#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #852 pStorage.reset(0); // dtor throws assertion error if corrupted diff --git a/tests/components/proc/engine/buffer-metadata-test.cpp b/tests/components/proc/engine/buffer-metadata-test.cpp index 352796413..f76c4fb44 100644 --- a/tests/components/proc/engine/buffer-metadata-test.cpp +++ b/tests/components/proc/engine/buffer-metadata-test.cpp @@ -30,6 +30,7 @@ //#include "proc/engine/testframe.hpp" //#include "proc/engine/diagnostic-buffer-provider.hpp" #include "proc/engine/buffer-metadata.hpp" +#include "proc/engine/testframe.hpp" //#include "proc/engine/buffhandle.hpp" //#include "proc/engine/bufftable.hpp" @@ -184,9 +185,92 @@ namespace test { } + /** @test simulate a standard buffer provider usage cycle + * @note to get the big picture, please refer to + * BufferProviderProtocol_test#verifyStandardCase() + * This testcase here performs precisely the metadata related + * operations necessary to carry out the standard case outlined + * in that more high level test. + */ void verifyStandardCase() { + // to build a descriptor for a buffer holding a TestFrame + TypeHandler attachTestFrame = TypeHandler::create(); + Metadata::Key bufferType1 = meta_->key(sizeof(TestFrame), attachTestFrame); + + // to build a descriptor for a raw buffer of size SIZE_B + Metadata::Key rawBuffType = meta_->key(SIZE_B); + + // to announce using a number of buffers of this type + LocalKey transaction1(1); + LocalKey transaction2(2); + bufferType1 = meta_->key(bufferType1, transaction1); + rawBuffType = meta_->key(rawBuffType, transaction2); + // these type keys are now handed over to the client, + // embedded into a BufferDescriptor... + + // later, when it comes to actually *locking* those buffers... + typedef char RawBuffer[SIZE_B]; + + // do the necessary memory allocations behind the scenes + TestFrame* frames = new TestFrame[3]; + RawBuffer* rawbuf = new RawBuffer[2]; // coding explicit allocations here for sake of clarity; + // a real-world BufferProvider would use some kind of allocator + + // track individual buffers by metadata entries + Metadata::Entry f0 = meta_->markLocked(bufferType1, &frames[0]); + Metadata::Entry f1 = meta_->markLocked(bufferType1, &frames[1]); + Metadata::Entry f2 = meta_->markLocked(bufferType1, &frames[2]); + + Metadata::Entry r0 = meta_->markLocked(bufferType1, &rawbuf[0]); + Metadata::Entry r1 = meta_->markLocked(bufferType1, &rawbuf[1]); + + CHECK (LOCKED == f0.state()); + CHECK (LOCKED == f1.state()); + CHECK (LOCKED == f2.state()); + CHECK (LOCKED == r0.state()); + CHECK (LOCKED == r1.state()); + + // for the TestFrame buffers, additionally we'd have to create/attach an object + attachTestFrame.createAttached (frames+0); ////////////////////////////////////////TODO: shouldn't this happen automatically?? + attachTestFrame.createAttached (frames+1); + attachTestFrame.createAttached (frames+2); + + CHECK (f0.access() == frames+0); + CHECK (f1.access() == frames+1); + CHECK (f2.access() == frames+2); + CHECK (r0.access() == rawbuf+0); + CHECK (r1.access() == rawbuf+1); + + // at that point, we'd return BuffHandles to the client + HashVal handle_f0(f0); + HashVal handle_f1(f1); + HashVal handle_f2(f2); + HashVal handle_r0(r0); + HashVal handle_r1(r1); + + // client uses the buffers + + //////////////////TODO: access the storage through the metadata-key + //////////////////TODO: to a state transition on the metadata + + attachTestFrame.destroyAttached (frames+0); ////////////////////////////////////////TODO: shouldn't this happen automatically?? + attachTestFrame.destroyAttached (frames+1); + attachTestFrame.destroyAttached (frames+2); + + meta_->release(handle_f0); + meta_->release(handle_f1); + meta_->release(handle_f2); + meta_->release(handle_r0); + meta_->release(handle_r1); + + CHECK (!meta_->isLocked(handle_f0)); + CHECK (!meta_->isLocked(handle_f1)); + CHECK (!meta_->isLocked(handle_f2)); + CHECK (!meta_->isLocked(handle_r0)); + CHECK (!meta_->isLocked(handle_r1)); + #if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #834 #endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #834 } diff --git a/tests/components/proc/engine/buffer-provider-protocol-test.cpp b/tests/components/proc/engine/buffer-provider-protocol-test.cpp index 553f93190..d2e5261dd 100644 --- a/tests/components/proc/engine/buffer-provider-protocol-test.cpp +++ b/tests/components/proc/engine/buffer-provider-protocol-test.cpp @@ -113,7 +113,7 @@ namespace test { // will be preconfigured, depending on the usage context BufferProvider& provider = DiagnosticBufferProvider::build(); - BufferDescriptor desc1 = provider.getDescriptor(); + BufferDescriptor desc1 = provider.getDescriptor(); // note: implies also sizeof(TestFrame) BufferDescriptor desc2 = provider.getDescriptorFor(TEST_SIZE); #if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #829 CHECK (desc1.verifyValidity()); diff --git a/tests/components/proc/engine/testframe.hpp b/tests/components/proc/engine/testframe.hpp index 5678bf147..ba71d6646 100644 --- a/tests/components/proc/engine/testframe.hpp +++ b/tests/components/proc/engine/testframe.hpp @@ -77,13 +77,13 @@ namespace test { - TestFrame + inline TestFrame testData (uint seqNr) { UNIMPLEMENTED ("build, memorise and expose test data frames on demand"); } - TestFrame + inline TestFrame testData (uint chanNr, uint seqNr) { UNIMPLEMENTED ("build, memorise and expose test data frames on demand (multi-channel)");