2011-09-17 01:50:11 +02:00
|
|
|
|
/*
|
|
|
|
|
|
BufferProviderProtocol(Test) - demonstration of buffer provider usage cycle
|
|
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
Copyright (C)
|
|
|
|
|
|
2011, Hermann Vosseler <Ichthyostega@web.de>
|
2011-09-17 01:50:11 +02:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
**Lumiera** 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. See the file COPYING for further details.
|
2011-09-17 01:50:11 +02:00
|
|
|
|
|
Copyright: clarify and simplify the file headers
* Lumiera source code always was copyrighted by individual contributors
* there is no entity "Lumiera.org" which holds any copyrights
* Lumiera source code is provided under the GPL Version 2+
== Explanations ==
Lumiera as a whole is distributed under Copyleft, GNU General Public License Version 2 or above.
For this to become legally effective, the ''File COPYING in the root directory is sufficient.''
The licensing header in each file is not strictly necessary, yet considered good practice;
attaching a licence notice increases the likeliness that this information is retained
in case someone extracts individual code files. However, it is not by the presence of some
text, that legally binding licensing terms become effective; rather the fact matters that a
given piece of code was provably copyrighted and published under a license. Even reformatting
the code, renaming some variables or deleting parts of the code will not alter this legal
situation, but rather creates a derivative work, which is likewise covered by the GPL!
The most relevant information in the file header is the notice regarding the
time of the first individual copyright claim. By virtue of this initial copyright,
the first author is entitled to choose the terms of licensing. All further
modifications are permitted and covered by the License. The specific wording
or format of the copyright header is not legally relevant, as long as the
intention to publish under the GPL remains clear. The extended wording was
based on a recommendation by the FSF. It can be shortened, because the full terms
of the license are provided alongside the distribution, in the file COPYING.
2024-11-17 23:42:55 +01:00
|
|
|
|
* *****************************************************************/
|
2011-09-17 01:50:11 +02:00
|
|
|
|
|
2017-02-22 01:54:20 +01:00
|
|
|
|
/** @file buffer-provider-protocol-test.cpp
|
2017-02-22 03:17:18 +01:00
|
|
|
|
** unit test \ref BufferProviderProtocol_test
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2011-09-17 01:50:11 +02:00
|
|
|
|
|
|
|
|
|
|
#include "lib/error.hpp"
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
|
|
|
|
#include "lib/test/test-helper.hpp"
|
2024-06-15 18:14:00 +02:00
|
|
|
|
#include "lib/test/tracking-dummy.hpp"
|
2011-09-17 18:25:45 +02:00
|
|
|
|
#include "lib/util-foreach.hpp"
|
2018-11-15 23:42:43 +01:00
|
|
|
|
#include "steam/engine/testframe.hpp"
|
2026-01-23 22:16:13 +01:00
|
|
|
|
#include "steam/engine/test-rand-ontology.hpp"
|
2018-11-15 23:42:43 +01:00
|
|
|
|
#include "steam/engine/diagnostic-buffer-provider.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
|
|
|
|
|
|
|
|
|
|
|
2026-01-25 00:19:30 +01:00
|
|
|
|
namespace steam {
|
2011-09-17 01:50:11 +02:00
|
|
|
|
namespace engine{
|
|
|
|
|
|
namespace test {
|
|
|
|
|
|
|
2011-11-26 00:09:59 +01:00
|
|
|
|
using lib::test::Dummy;
|
|
|
|
|
|
|
2018-11-15 23:59:23 +01:00
|
|
|
|
using steam::engine::BuffHandle;
|
2024-03-16 02:04:47 +01:00
|
|
|
|
using LERR_(LIFECYCLE);
|
|
|
|
|
|
using LERR_(LOGIC);
|
2011-09-17 01:50:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace { // Test fixture
|
|
|
|
|
|
|
2011-09-17 18:25:45 +02:00
|
|
|
|
const uint TEST_ELMS = 20;
|
|
|
|
|
|
|
2011-10-19 02:47:11 +02:00
|
|
|
|
|
2026-01-23 22:16:13 +01:00
|
|
|
|
HashVal
|
|
|
|
|
|
do_some_computation (TestFrame const& src, TestFrame& work, int64_t* data)
|
2011-10-19 02:47:11 +02:00
|
|
|
|
{
|
2026-01-23 22:16:13 +01:00
|
|
|
|
REQUIRE (data);
|
|
|
|
|
|
ont::Param param = src.getChecksum();
|
|
|
|
|
|
ont::manipulateFrame (&work, &src, param);
|
|
|
|
|
|
for (uint i=0; i<TestFrame::BUFFSIZ; ++i)
|
|
|
|
|
|
*(data+i) = work.data()[i];
|
|
|
|
|
|
return work.getChecksum();
|
2011-10-19 02:47:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2011-09-17 01:50:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-24 23:06:36 +02:00
|
|
|
|
/**************************************************************************//**
|
2026-01-23 22:16:13 +01:00
|
|
|
|
* @test document the usage patterns of the »Buffer Provider Protocol«
|
|
|
|
|
|
* Notably this protocol is used by the Render Engine during recursive `pull()`
|
|
|
|
|
|
* calls to claim and release the working buffers for each step; furthermore,
|
|
|
|
|
|
* also the output buffers are packaged as `BuffHandle` and used through this
|
|
|
|
|
|
* protocol.
|
|
|
|
|
|
*
|
|
|
|
|
|
* However, the actual `BufferProvider` implementation used here is instrumented
|
|
|
|
|
|
* for diagnostics and does not actually _manage_ buffers; rather each buffer
|
|
|
|
|
|
* is allocated on the heap and never released, so that any allocation and
|
|
|
|
|
|
* all buffer contents can be verified after the fact.
|
2011-09-17 01:50:11 +02:00
|
|
|
|
*/
|
|
|
|
|
|
class BufferProviderProtocol_test : public Test
|
|
|
|
|
|
{
|
|
|
|
|
|
virtual void
|
2025-06-07 23:59:57 +02:00
|
|
|
|
run (Arg)
|
2011-09-17 01:50:11 +02:00
|
|
|
|
{
|
2011-09-17 18:25:45 +02:00
|
|
|
|
verifySimpleUsage();
|
2026-01-23 22:16:13 +01:00
|
|
|
|
verifyRenderingUsage();
|
2026-02-12 02:28:41 +01:00
|
|
|
|
// verifyObjectAttachment();
|
|
|
|
|
|
// verifyObjectAttachmentFailure(); //////////////////////////OOO need a completely new test case to cover behaviour of failed ctor calls
|
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
|
2026-02-08 23:44:17 +01:00
|
|
|
|
DiagnosticBufferProvider provider;
|
2011-09-17 01:50:11 +02:00
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
2026-02-08 23:44:17 +01:00
|
|
|
|
auto diagnostic = watch(provider);
|
|
|
|
|
|
CHECK (diagnostic.buffer_was_used (0));
|
|
|
|
|
|
CHECK (diagnostic.buffer_was_closed (0));
|
2011-09-17 01:50:11 +02:00
|
|
|
|
|
2026-02-08 23:44:17 +01:00
|
|
|
|
CHECK (testData(0) == diagnostic.accessMemory (0));
|
2011-09-17 01:50:11 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2026-01-23 22:16:13 +01:00
|
|
|
|
/** @test demonstrate the full sequence of invocations during rendering
|
|
|
|
|
|
*/
|
2011-09-17 01:50:11 +02:00
|
|
|
|
void
|
2026-01-23 22:16:13 +01:00
|
|
|
|
verifyRenderingUsage()
|
2011-09-17 01:50:11 +02:00
|
|
|
|
{
|
2026-01-23 22:16:13 +01:00
|
|
|
|
// Test fixture: allows to track/verify allocations after the fact
|
2026-02-08 23:44:17 +01:00
|
|
|
|
DiagnosticBufferProvider provider;
|
2011-09-17 18:25:45 +02:00
|
|
|
|
|
2026-01-23 22:16:13 +01:00
|
|
|
|
using DataBuff = std::array<int64_t, TestFrame::BUFFSIZ>;
|
|
|
|
|
|
constexpr auto BUFFSIZ = sizeof(DataBuff);
|
2011-09-17 18:25:45 +02:00
|
|
|
|
|
2026-01-23 22:16:13 +01:00
|
|
|
|
BuffDescr desc1 = provider.getDescriptor<size_t>();
|
|
|
|
|
|
BuffDescr desc2 = provider.getDescriptor<TestFrame>(); // note: implies also sizeof(TestFrame)
|
|
|
|
|
|
BuffDescr desc3 = provider.getDescriptorFor(BUFFSIZ); // Can also request fixed sized raw storage.
|
2026-02-15 23:39:13 +01:00
|
|
|
|
CHECK (desc1.isValid());
|
|
|
|
|
|
CHECK (desc2.isValid());
|
|
|
|
|
|
CHECK (desc3.isValid());
|
2011-09-17 18:25:45 +02:00
|
|
|
|
|
2026-01-23 22:16:13 +01:00
|
|
|
|
uint num1 = desc1.announce(TEST_ELMS);
|
|
|
|
|
|
uint num2 = desc1.announce(TEST_ELMS + 1);
|
|
|
|
|
|
uint num3 = desc2.announce(TEST_ELMS * 2);
|
|
|
|
|
|
CHECK (num1 == TEST_ELMS);
|
|
|
|
|
|
CHECK (num2 == TEST_ELMS + 1);
|
|
|
|
|
|
CHECK (num3 == TEST_ELMS * 2);
|
2011-09-17 18:25:45 +02:00
|
|
|
|
|
2026-01-23 22:16:13 +01:00
|
|
|
|
// emulate a progressive processing
|
|
|
|
|
|
BuffHandle workBuff = desc2.lockBuffer();
|
|
|
|
|
|
workBuff.accessAs<TestFrame>() = testData(0);
|
|
|
|
|
|
for (uint i=0; i<TEST_ELMS; ++i)
|
|
|
|
|
|
{
|
|
|
|
|
|
BuffHandle srcBuff = workBuff;
|
|
|
|
|
|
workBuff = desc2.lockBuffer();
|
|
|
|
|
|
|
|
|
|
|
|
BuffHandle markBuff = desc1.lockBuffer();
|
|
|
|
|
|
BuffHandle dataBuff = desc3.lockBuffer();
|
|
|
|
|
|
CHECK (srcBuff.isValid());
|
|
|
|
|
|
CHECK (markBuff.isValid());
|
|
|
|
|
|
CHECK (workBuff.isValid());
|
|
|
|
|
|
CHECK (dataBuff.isValid());
|
|
|
|
|
|
|
|
|
|
|
|
TestFrame& src = srcBuff.accessAs<TestFrame>();
|
|
|
|
|
|
size_t& mark = markBuff.accessAs<size_t>();
|
|
|
|
|
|
TestFrame& work = workBuff.accessAs<TestFrame>();
|
|
|
|
|
|
DataBuff& data = dataBuff.accessAs<DataBuff>();
|
|
|
|
|
|
|
|
|
|
|
|
mark = do_some_computation (src,work, &data[0]);
|
|
|
|
|
|
|
|
|
|
|
|
srcBuff.emit();
|
|
|
|
|
|
dataBuff.emit();
|
|
|
|
|
|
markBuff.emit();
|
|
|
|
|
|
|
|
|
|
|
|
srcBuff.release();
|
|
|
|
|
|
dataBuff.release();
|
|
|
|
|
|
markBuff.release();
|
|
|
|
|
|
// note : workBuff passed to next iteration
|
|
|
|
|
|
}
|
|
|
|
|
|
CHECK (workBuff.isValid());
|
|
|
|
|
|
auto endSum = workBuff.accessAs<TestFrame>().getChecksum();
|
|
|
|
|
|
workBuff.release(); // note: not every buffer need be emitted.
|
2026-02-15 23:39:13 +01:00
|
|
|
|
CHECK (!workBuff);
|
2011-09-17 18:25:45 +02:00
|
|
|
|
|
2026-02-08 23:44:17 +01:00
|
|
|
|
auto diagnostic = watch(provider);
|
|
|
|
|
|
CHECK (diagnostic.buffer_was_used (0));
|
|
|
|
|
|
CHECK (diagnostic.buffer_was_closed (0));
|
|
|
|
|
|
// CHECK (diagnostic.all_buffers_released()); ///////////////OOO do we need this API?
|
2011-09-17 01:50:11 +02:00
|
|
|
|
}
|
2011-11-26 00:09:59 +01:00
|
|
|
|
|
|
|
|
|
|
|
2026-02-12 02:28:41 +01:00
|
|
|
|
#if false //////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1410 : disabled code to disentangle BufferProvider implementation
|
2011-11-26 00:09:59 +01:00
|
|
|
|
void
|
|
|
|
|
|
verifyObjectAttachment()
|
|
|
|
|
|
{
|
2026-02-08 23:44:17 +01:00
|
|
|
|
DiagnosticBufferProvider provider;
|
2024-07-15 18:52:59 +02:00
|
|
|
|
BuffDescr type_A = provider.getDescriptorFor(sizeof(TestFrame));
|
|
|
|
|
|
BuffDescr type_B = provider.getDescriptorFor(sizeof(int));
|
|
|
|
|
|
BuffDescr type_C = provider.getDescriptor<int>();
|
2011-11-26 00:09:59 +01:00
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
|
{
|
2026-02-08 23:44:17 +01:00
|
|
|
|
DiagnosticBufferProvider provider;
|
2024-07-15 18:52:59 +02:00
|
|
|
|
BuffDescr type_D = provider.getDescriptorFor(sizeof(Dummy));
|
2011-11-26 00:09:59 +01:00
|
|
|
|
|
|
|
|
|
|
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>() );
|
|
|
|
|
|
}
|
2026-02-12 02:28:41 +01:00
|
|
|
|
#endif /////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1410 : (end) disabled code
|
2011-09-17 01:50:11 +02:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
2026-01-25 00:19:30 +01:00
|
|
|
|
LAUNCHER (BufferProviderProtocol_test, "unit engine");
|
2011-09-17 01:50:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
|
}}} // namespace steam::engine::test
|