2011-09-17 01:50:11 +02:00
|
|
|
/*
|
|
|
|
|
BufferProviderProtocol(Test) - demonstration of buffer provider usage cycle
|
|
|
|
|
|
|
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2011, Hermann Vosseler <Ichthyostega@web.de>
|
|
|
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
|
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
|
|
|
|
|
|
* *****************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "lib/error.hpp"
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
|
|
|
#include "lib/test/test-helper.hpp"
|
2011-11-26 00:09:59 +01:00
|
|
|
#include "lib/test/testdummy.hpp"
|
2011-09-17 18:25:45 +02:00
|
|
|
#include "lib/util-foreach.hpp"
|
2011-09-18 15:28:58 +02:00
|
|
|
#include "proc/engine/testframe.hpp"
|
2011-09-17 01:50:11 +02:00
|
|
|
#include "proc/engine/diagnostic-buffer-provider.hpp"
|
2011-11-25 20:23:31 +01:00
|
|
|
#include "proc/engine/buffhandle-attach.hpp"
|
2011-09-17 18:25:45 +02:00
|
|
|
#include "proc/engine/bufftable.hpp"
|
2011-09-17 01:50:11 +02:00
|
|
|
|
2011-11-26 00:09:59 +01:00
|
|
|
using util::isSameObject;
|
2011-09-17 18:25:45 +02:00
|
|
|
using util::for_each;
|
2011-09-17 01:50:11 +02:00
|
|
|
|
|
|
|
|
|
2011-12-02 17:50:44 +01:00
|
|
|
namespace proc {
|
2011-09-17 01:50:11 +02:00
|
|
|
namespace engine{
|
|
|
|
|
namespace test {
|
|
|
|
|
|
2011-11-26 00:09:59 +01:00
|
|
|
using lib::test::Dummy;
|
|
|
|
|
|
2011-12-02 17:50:44 +01:00
|
|
|
using proc::engine::BuffHandle;
|
2011-11-26 00:09:59 +01:00
|
|
|
using error::LUMIERA_ERROR_LOGIC;
|
|
|
|
|
using error::LUMIERA_ERROR_LIFECYCLE;
|
2011-09-17 01:50:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace { // Test fixture
|
|
|
|
|
|
2011-09-17 18:25:45 +02:00
|
|
|
const uint TEST_SIZE = 1024*1024;
|
|
|
|
|
const uint TEST_ELMS = 20;
|
|
|
|
|
|
2011-10-19 02:47:11 +02:00
|
|
|
|
|
|
|
|
void
|
|
|
|
|
do_some_calculations (BuffHandle const& buffer)
|
|
|
|
|
{
|
|
|
|
|
UNIMPLEMENTED ("some verifiable test/dummy buffer accessing operations");
|
|
|
|
|
}
|
|
|
|
|
|
2011-09-17 01:50:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2011-11-26 00:09:59 +01:00
|
|
|
/******************************************************************************
|
|
|
|
|
* @test verify and demonstrate the usage cycle of data buffers for the engine
|
|
|
|
|
* based on the BufferProvider interface. This is kind of a "dry run"
|
|
|
|
|
* for documentation purposes, because the BufferProvider implementation
|
|
|
|
|
* used here is just a diagnostics facility, allowing to investigate
|
|
|
|
|
* the state of individual buffers even after "releasing" them.
|
|
|
|
|
*
|
|
|
|
|
* This test should help understanding the sequence of buffer management
|
|
|
|
|
* operations performed at various stages while passing an calculation job
|
|
|
|
|
* through the render engine.
|
2011-09-17 01:50:11 +02:00
|
|
|
*/
|
|
|
|
|
class BufferProviderProtocol_test : public Test
|
|
|
|
|
{
|
|
|
|
|
virtual void
|
|
|
|
|
run (Arg)
|
|
|
|
|
{
|
2011-09-17 18:25:45 +02:00
|
|
|
verifySimpleUsage();
|
2011-09-17 01:50:11 +02:00
|
|
|
verifyStandardCase();
|
2011-11-26 00:09:59 +01:00
|
|
|
verifyObjectAttachment();
|
|
|
|
|
verifyObjectAttachmentFailure();
|
2011-09-17 01:50:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
verifySimpleUsage()
|
|
|
|
|
{
|
|
|
|
|
// Create Test fixture.
|
|
|
|
|
// In real usage, a suitable memory/frame/buffer provider
|
|
|
|
|
// will be preconfigured, depending on the usage context
|
|
|
|
|
BufferProvider& provider = DiagnosticBufferProvider::build();
|
|
|
|
|
|
|
|
|
|
BuffHandle buff = provider.lockBufferFor<TestFrame>();
|
|
|
|
|
CHECK (buff.isValid());
|
|
|
|
|
CHECK (sizeof(TestFrame) <= buff.size());
|
2011-11-24 03:33:23 +01:00
|
|
|
buff.accessAs<TestFrame>() = testData(0);
|
2011-09-17 01:50:11 +02:00
|
|
|
|
2011-11-24 03:33:23 +01:00
|
|
|
TestFrame& content = buff.accessAs<TestFrame>();
|
|
|
|
|
CHECK (testData(0) == content);
|
2011-09-17 01:50:11 +02:00
|
|
|
|
2011-11-26 00:09:59 +01:00
|
|
|
buff.emit();
|
2011-09-17 01:50:11 +02:00
|
|
|
buff.release();
|
|
|
|
|
CHECK (!buff.isValid());
|
2011-09-19 01:42:37 +02:00
|
|
|
VERIFY_ERROR (LIFECYCLE, buff.accessAs<TestFrame>() );
|
2011-09-17 01:50:11 +02:00
|
|
|
|
2011-09-19 01:42:37 +02:00
|
|
|
DiagnosticBufferProvider& checker = DiagnosticBufferProvider::access(provider);
|
2011-09-17 01:50:11 +02:00
|
|
|
CHECK (checker.buffer_was_used (0));
|
|
|
|
|
CHECK (checker.buffer_was_closed (0));
|
|
|
|
|
|
2011-09-21 02:23:12 +02:00
|
|
|
CHECK (testData(0) == checker.accessMemory (0));
|
2011-09-17 01:50:11 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
verifyStandardCase()
|
|
|
|
|
{
|
2011-10-19 02:47:11 +02:00
|
|
|
#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #829
|
2011-09-17 01:50:11 +02:00
|
|
|
// Create Test fixture.
|
|
|
|
|
// In real usage, a suitable memory/frame/buffer provider
|
|
|
|
|
// will be preconfigured, depending on the usage context
|
|
|
|
|
BufferProvider& provider = DiagnosticBufferProvider::build();
|
2011-09-17 18:25:45 +02:00
|
|
|
|
2011-10-17 02:00:48 +02:00
|
|
|
BufferDescriptor desc1 = provider.getDescriptor<TestFrame>(); // note: implies also sizeof(TestFrame)
|
2011-09-17 18:25:45 +02:00
|
|
|
BufferDescriptor desc2 = provider.getDescriptorFor(TEST_SIZE);
|
|
|
|
|
CHECK (desc1.verifyValidity());
|
|
|
|
|
CHECK (desc2.verifyValidity());
|
|
|
|
|
|
2011-10-19 02:47:11 +02:00
|
|
|
uint num1 = provider.announce(TEST_ELMS, desc1);
|
|
|
|
|
uint num2 = provider.announce(TEST_ELMS, desc2);
|
2011-09-17 18:25:45 +02:00
|
|
|
CHECK (num1 == TEST_ELMS);
|
|
|
|
|
CHECK (0 < num2 && num2 <=TEST_ELMS);
|
|
|
|
|
|
|
|
|
|
const size_t STORAGE_SIZE = BuffTable::Storage<2*TEST_ELMS>::size;
|
|
|
|
|
char storage[STORAGE_SIZE];
|
2011-09-18 01:02:31 +02:00
|
|
|
BuffTable& tab =
|
|
|
|
|
BuffTable::prepare(STORAGE_SIZE, storage)
|
2011-10-19 02:47:11 +02:00
|
|
|
.announce(num1, desc1)
|
|
|
|
|
.announce(num2, desc2)
|
2011-09-18 01:02:31 +02:00
|
|
|
.build();
|
2011-09-17 18:25:45 +02:00
|
|
|
|
2011-09-18 01:02:31 +02:00
|
|
|
tab.lockBuffers();
|
2011-09-17 18:25:45 +02:00
|
|
|
for_each (tab.buffers(), do_some_calculations);
|
|
|
|
|
tab.releaseBuffers();
|
|
|
|
|
|
2011-10-19 02:47:11 +02:00
|
|
|
DiagnosticBufferProvider& checker = DiagnosticBufferProvider::access(provider);
|
2011-09-17 18:25:45 +02:00
|
|
|
CHECK (checker.all_buffers_released());
|
2011-09-17 01:50:11 +02:00
|
|
|
#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #829
|
|
|
|
|
}
|
2011-11-26 00:09:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
verifyObjectAttachment()
|
|
|
|
|
{
|
|
|
|
|
BufferProvider& provider = DiagnosticBufferProvider::build();
|
|
|
|
|
BufferDescriptor type_A = provider.getDescriptorFor(sizeof(TestFrame));
|
|
|
|
|
BufferDescriptor type_B = provider.getDescriptorFor(sizeof(int));
|
|
|
|
|
BufferDescriptor type_C = provider.getDescriptor<int>();
|
|
|
|
|
|
|
|
|
|
BuffHandle handle_A = provider.lockBuffer(type_A);
|
|
|
|
|
BuffHandle handle_B = provider.lockBuffer(type_B);
|
|
|
|
|
BuffHandle handle_C = provider.lockBuffer(type_C);
|
|
|
|
|
|
|
|
|
|
CHECK (handle_A);
|
|
|
|
|
CHECK (handle_B);
|
|
|
|
|
CHECK (handle_C);
|
|
|
|
|
|
|
|
|
|
CHECK (sizeof(TestFrame) == handle_A.size());
|
|
|
|
|
CHECK (sizeof( int ) == handle_B.size());
|
|
|
|
|
CHECK (sizeof( int ) == handle_C.size());
|
|
|
|
|
|
|
|
|
|
TestFrame& embeddedFrame = handle_A.create<TestFrame>();
|
|
|
|
|
CHECK (isSameObject (*handle_A, embeddedFrame));
|
|
|
|
|
CHECK (embeddedFrame.isAlive());
|
|
|
|
|
CHECK (embeddedFrame.isSane());
|
|
|
|
|
|
|
|
|
|
VERIFY_ERROR (LOGIC, handle_B.create<TestFrame>()); // too small to hold a TestFrame
|
|
|
|
|
VERIFY_ERROR (LIFECYCLE, handle_C.create<int>()); // has already an attached TypeHandler (creating an int)
|
|
|
|
|
|
|
|
|
|
handle_A.release();
|
|
|
|
|
handle_B.release();
|
|
|
|
|
handle_C.release();
|
|
|
|
|
|
|
|
|
|
CHECK (embeddedFrame.isDead());
|
|
|
|
|
CHECK (embeddedFrame.isSane());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
verifyObjectAttachmentFailure()
|
|
|
|
|
{
|
|
|
|
|
BufferProvider& provider = DiagnosticBufferProvider::build();
|
|
|
|
|
BufferDescriptor type_D = provider.getDescriptorFor(sizeof(Dummy));
|
|
|
|
|
|
|
|
|
|
Dummy::checksum() = 0;
|
|
|
|
|
BuffHandle handle_D = provider.lockBuffer(type_D);
|
|
|
|
|
CHECK (0 == Dummy::checksum()); // nothing created thus far
|
|
|
|
|
|
|
|
|
|
handle_D.create<Dummy>();
|
|
|
|
|
CHECK (0 < Dummy::checksum());
|
|
|
|
|
|
|
|
|
|
handle_D.release();
|
|
|
|
|
CHECK (0 == Dummy::checksum());
|
|
|
|
|
|
|
|
|
|
BuffHandle handle_DD = provider.lockBuffer(type_D);
|
|
|
|
|
|
|
|
|
|
CHECK (0 == Dummy::checksum());
|
|
|
|
|
Dummy::activateCtorFailure();
|
|
|
|
|
|
|
|
|
|
CHECK (handle_DD.isValid());
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
handle_DD.create<Dummy>();
|
|
|
|
|
NOTREACHED ("Dummy ctor should fail");
|
|
|
|
|
}
|
|
|
|
|
catch (int val)
|
|
|
|
|
{
|
|
|
|
|
CHECK (!handle_DD.isValid());
|
|
|
|
|
|
|
|
|
|
CHECK (0 < Dummy::checksum());
|
|
|
|
|
CHECK (val == Dummy::checksum());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VERIFY_ERROR (LIFECYCLE, handle_DD.accessAs<Dummy>() );
|
|
|
|
|
VERIFY_ERROR (LIFECYCLE, handle_DD.create<Dummy>() );
|
|
|
|
|
}
|
2011-09-17 01:50:11 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
|
|
|
|
LAUNCHER (BufferProviderProtocol_test, "unit player");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-02 17:50:44 +01:00
|
|
|
}}} // namespace proc::engine::test
|