test/dummy buffer provider finished and passes test
This commit is contained in:
parent
d6de8c8d1a
commit
2ae1e3c8f9
5 changed files with 82 additions and 58 deletions
|
|
@ -154,8 +154,13 @@ namespace engine {
|
|||
|
||||
void release()
|
||||
{
|
||||
REQUIRE (pBuffer_);
|
||||
descriptor_.release (*this);
|
||||
if (pBuffer_)
|
||||
{
|
||||
REQUIRE (isValid());
|
||||
descriptor_.release (*this);
|
||||
pBuffer_ = 0;
|
||||
}
|
||||
ENSURE (!isValid());
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -103,21 +103,21 @@ namespace engine {
|
|||
bool
|
||||
DiagnosticBufferProvider::buffer_was_used (uint bufferID) const
|
||||
{
|
||||
return pImpl_->access_or_create(bufferID).was_used();
|
||||
return pImpl_->access_emitted(bufferID).was_used();
|
||||
}
|
||||
|
||||
|
||||
bool
|
||||
DiagnosticBufferProvider::buffer_was_closed (uint bufferID) const
|
||||
{
|
||||
return pImpl_->access_or_create(bufferID).was_closed();
|
||||
return pImpl_->access_emitted(bufferID).was_closed();
|
||||
}
|
||||
|
||||
|
||||
void*
|
||||
DiagnosticBufferProvider::accessMemory (uint bufferID) const
|
||||
{
|
||||
return pImpl_->access_or_create(bufferID).accessMemory();
|
||||
return pImpl_->access_emitted(bufferID).accessMemory();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -32,7 +32,6 @@
|
|||
#include "proc/engine/tracking-heap-block-provider.hpp"
|
||||
|
||||
#include <boost/noncopyable.hpp>
|
||||
#include <tr1/functional>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
|
|
@ -41,9 +40,6 @@ using util::and_all;
|
|||
using std::vector;
|
||||
using lib::ScopedHolder;
|
||||
using lib::ScopedPtrVect;
|
||||
using std::tr1::function;
|
||||
using std::tr1::bind;
|
||||
using std::tr1::placeholders::_1;
|
||||
|
||||
|
||||
|
||||
|
|
@ -57,12 +53,11 @@ namespace engine {
|
|||
using diagn::Block;
|
||||
|
||||
/** helper to find Block entries
|
||||
* based on the storage used by the buffer,
|
||||
* which is maintained by this Block entry */
|
||||
* based on their raw memory address */
|
||||
inline bool
|
||||
identifyBlock (Block const& inQuestion, void* storage)
|
||||
{
|
||||
return inQuestion.accessMemory() == storage;
|
||||
return storage == &inQuestion;
|
||||
}
|
||||
|
||||
/** build a searching predicate */
|
||||
|
|
@ -74,11 +69,11 @@ namespace engine {
|
|||
|
||||
template<class VEC>
|
||||
inline Block*
|
||||
pick_Block_by_storage (VEC& vec, void* bufferLocation)
|
||||
pick_Block_by_storage (VEC& vec, void* blockLocation)
|
||||
{
|
||||
typename VEC::iterator pos
|
||||
= std::find_if (vec.begin(),vec.end()
|
||||
,search_for_block_using_this_storage(bufferLocation));
|
||||
,search_for_block_using_this_storage(blockLocation));
|
||||
if (pos!=vec.end())
|
||||
return &(*pos);
|
||||
else
|
||||
|
|
@ -157,9 +152,9 @@ namespace engine {
|
|||
|
||||
|
||||
Block*
|
||||
find (void* bufferLocation)
|
||||
find (void* blockLocation)
|
||||
{
|
||||
return pick_Block_by_storage (*blockList_, bufferLocation);
|
||||
return pick_Block_by_storage (*blockList_, blockLocation);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -210,6 +205,8 @@ namespace engine {
|
|||
namespace { // Details of allocation and accounting
|
||||
|
||||
const uint MAX_BUFFERS = 50;
|
||||
|
||||
diagn::Block emptyPlaceholder(0);
|
||||
|
||||
} // (END) Details of allocation and accounting
|
||||
|
||||
|
|
@ -281,13 +278,12 @@ namespace engine {
|
|||
}
|
||||
|
||||
diagn::Block&
|
||||
TrackingHeapBlockProvider::access_or_create (uint bufferID)
|
||||
TrackingHeapBlockProvider::access_emitted (uint bufferID)
|
||||
{
|
||||
while (!withinOutputSequence (bufferID))
|
||||
outSeq_.manage (new diagn::Block(0)); /////////TICKET #856 really need a better way of returning a fallback
|
||||
|
||||
ENSURE (withinOutputSequence (bufferID));
|
||||
return outSeq_[bufferID];
|
||||
if (!withinOutputSequence (bufferID))
|
||||
return emptyPlaceholder;
|
||||
else
|
||||
return outSeq_[bufferID];
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
@ -318,9 +314,9 @@ namespace engine {
|
|||
}
|
||||
|
||||
diagn::Block*
|
||||
TrackingHeapBlockProvider::searchInOutSeqeuence (void* bufferLocation)
|
||||
TrackingHeapBlockProvider::searchInOutSeqeuence (void* blockLocation)
|
||||
{
|
||||
return pick_Block_by_storage (outSeq_, bufferLocation);
|
||||
return pick_Block_by_storage (outSeq_, blockLocation);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -144,7 +144,7 @@ namespace engine {
|
|||
|
||||
size_t emittedCnt() const;
|
||||
|
||||
diagn::Block& access_or_create (uint bufferID);
|
||||
diagn::Block& access_emitted (uint bufferID);
|
||||
|
||||
template<typename TY>
|
||||
TY& accessAs (uint bufferID);
|
||||
|
|
@ -173,7 +173,7 @@ namespace engine {
|
|||
if (!withinOutputSequence (bufferID))
|
||||
throw error::Invalid ("Buffer with the given ID not yet emitted");
|
||||
|
||||
diagn::Block& memoryBlock = access_or_create (bufferID);
|
||||
diagn::Block& memoryBlock = access_emitted (bufferID);
|
||||
TY* converted = reinterpret_cast<TY*> (memoryBlock.accessMemory());
|
||||
|
||||
REQUIRE (converted);
|
||||
|
|
|
|||
|
|
@ -23,34 +23,19 @@
|
|||
|
||||
#include "lib/error.hpp"
|
||||
#include "lib/test/run.hpp"
|
||||
//#include "lib/test/test-helper.hpp"
|
||||
//#include "lib/util-foreach.hpp"
|
||||
//#include "proc/play/diagnostic-output-slot.hpp"
|
||||
#include "proc/engine/tracking-heap-block-provider.hpp"
|
||||
#include "proc/engine/testframe.hpp"
|
||||
//#include "proc/engine/diagnostic-buffer-provider.hpp"
|
||||
#include "proc/engine/buffhandle.hpp"
|
||||
//#include "proc/engine/bufftable.hpp"
|
||||
|
||||
//#include <boost/format.hpp>
|
||||
//#include <iostream>
|
||||
#include <vector>
|
||||
#include <cstdlib>
|
||||
#include <vector>
|
||||
|
||||
//using boost::format;
|
||||
//using std::string;
|
||||
//using std::cout;
|
||||
using std::rand;
|
||||
//using util::for_each;
|
||||
|
||||
|
||||
namespace engine{
|
||||
namespace test {
|
||||
|
||||
// using lib::AllocationCluster;
|
||||
// using mobject::session::PEffect;
|
||||
// using ::engine::BuffHandle;
|
||||
// using lumiera::error::LUMIERA_ERROR_LIFECYCLE;
|
||||
|
||||
|
||||
namespace { // Test fixture
|
||||
|
|
@ -62,7 +47,7 @@ namespace test {
|
|||
|
||||
|
||||
bool
|
||||
has_expectedContent (uint nr, diagn::Block& memoryBlock)
|
||||
has_expectedContent (uint nr, diagn::Block& memoryBlock)
|
||||
{
|
||||
void* mem = memoryBlock.accessMemory();
|
||||
uint data = *static_cast<uint*> (mem);
|
||||
|
|
@ -71,7 +56,7 @@ namespace test {
|
|||
}
|
||||
|
||||
bool
|
||||
verifyUsedBlock (uint nr, diagn::Block& memoryBlock)
|
||||
verifyUsedBlock (uint nr, diagn::Block& memoryBlock)
|
||||
{
|
||||
return memoryBlock.was_used()
|
||||
&& memoryBlock.was_closed()
|
||||
|
|
@ -113,7 +98,7 @@ namespace test {
|
|||
provider.emitBuffer (testBuff);
|
||||
provider.releaseBuffer(testBuff);
|
||||
|
||||
diagn::Block& block0 = provider.access_or_create(0);
|
||||
diagn::Block& block0 = provider.access_emitted(0);
|
||||
CHECK (testData(dataID) == block0.accessMemory());
|
||||
}
|
||||
|
||||
|
|
@ -138,7 +123,7 @@ namespace test {
|
|||
|
||||
for (uint nr=0; nr<numElms; ++nr)
|
||||
{
|
||||
CHECK (verifyUsedBlock (nr, provider.access_or_create(nr)));
|
||||
CHECK (verifyUsedBlock (nr, provider.access_emitted(nr)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -156,37 +141,75 @@ namespace test {
|
|||
BuffHandle bu4 = provider.lockBuffer (buffType);
|
||||
BuffHandle bu5 = provider.lockBuffer (buffType);
|
||||
|
||||
CHECK (5 == provider.emittedCnt());
|
||||
|
||||
provider.accessAs<uint>(0) = 20;
|
||||
provider.accessAs<uint>(1) = 21;
|
||||
provider.accessAs<uint>(2) = 22;
|
||||
provider.accessAs<uint>(3) = 23;
|
||||
provider.accessAs<uint>(4) = 24;
|
||||
// buffers are locked,
|
||||
// but still within the per-type allocation pool
|
||||
// while the output sequence is still empty
|
||||
CHECK (!provider.access_emitted(0).was_used());
|
||||
CHECK (!provider.access_emitted(1).was_used());
|
||||
CHECK (!provider.access_emitted(2).was_used());
|
||||
CHECK (!provider.access_emitted(3).was_used());
|
||||
CHECK (!provider.access_emitted(4).was_used());
|
||||
|
||||
// can use the buffers for real
|
||||
bu1.accessAs<uint>() = 1;
|
||||
bu2.accessAs<uint>() = 2;
|
||||
bu3.accessAs<uint>() = 3;
|
||||
bu4.accessAs<uint>() = 4;
|
||||
bu5.accessAs<uint>() = 5;
|
||||
|
||||
CHECK (20 == provider.accessAs<uint>(0));
|
||||
CHECK (21 == provider.accessAs<uint>(1));
|
||||
CHECK (22 == provider.accessAs<uint>(2));
|
||||
CHECK (23 == provider.accessAs<uint>(3));
|
||||
CHECK (24 == provider.accessAs<uint>(4));
|
||||
CHECK (0 == provider.emittedCnt());
|
||||
|
||||
// now emit buffers in shuffled order
|
||||
provider.emitBuffer (bu3);
|
||||
provider.emitBuffer (bu1);
|
||||
provider.emitBuffer (bu5);
|
||||
provider.emitBuffer (bu4);
|
||||
provider.emitBuffer (bu2);
|
||||
|
||||
CHECK (5 == provider.emittedCnt());
|
||||
|
||||
CHECK (3 == provider.accessAs<uint>(0));
|
||||
CHECK (1 == provider.accessAs<uint>(1));
|
||||
CHECK (5 == provider.accessAs<uint>(2));
|
||||
CHECK (4 == provider.accessAs<uint>(3));
|
||||
CHECK (2 == provider.accessAs<uint>(4));
|
||||
|
||||
CHECK ( provider.access_emitted(0).was_used());
|
||||
CHECK ( provider.access_emitted(1).was_used());
|
||||
CHECK ( provider.access_emitted(2).was_used());
|
||||
CHECK ( provider.access_emitted(3).was_used());
|
||||
CHECK ( provider.access_emitted(4).was_used());
|
||||
|
||||
CHECK (!provider.access_emitted(0).was_closed());
|
||||
CHECK (!provider.access_emitted(1).was_closed());
|
||||
CHECK (!provider.access_emitted(2).was_closed());
|
||||
CHECK (!provider.access_emitted(3).was_closed());
|
||||
CHECK (!provider.access_emitted(4).was_closed());
|
||||
|
||||
bu5.release();
|
||||
CHECK (!provider.access_emitted(0).was_closed());
|
||||
CHECK (!provider.access_emitted(1).was_closed());
|
||||
CHECK ( provider.access_emitted(2).was_closed());
|
||||
CHECK (!provider.access_emitted(3).was_closed());
|
||||
CHECK (!provider.access_emitted(4).was_closed());
|
||||
|
||||
bu2.release();
|
||||
bu2.release();
|
||||
bu5.release();
|
||||
CHECK (!provider.access_emitted(0).was_closed());
|
||||
CHECK (!provider.access_emitted(1).was_closed());
|
||||
CHECK ( provider.access_emitted(2).was_closed());
|
||||
CHECK (!provider.access_emitted(3).was_closed());
|
||||
CHECK ( provider.access_emitted(4).was_closed());
|
||||
|
||||
CHECK (!bu2);
|
||||
CHECK (bu3);
|
||||
|
||||
bu1.release();
|
||||
bu3.release();
|
||||
bu4.release();
|
||||
|
||||
CHECK (5 == provider.emittedCnt());
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue