2017-02-22 03:17:18 +01:00
|
|
|
|
/*
|
2026-02-07 23:56:29 +01:00
|
|
|
|
DiagnosticBufferProvider(Test) - verify a support facility for diagnostic/test purposes
|
2011-11-11 01:44:01 +01: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
|
|
|
|
Copyright (C)
|
|
|
|
|
|
2011, Hermann Vosseler <Ichthyostega@web.de>
|
2011-11-11 01:44:01 +01: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-11-11 01:44:01 +01: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-11-11 01:44:01 +01:00
|
|
|
|
|
2017-02-22 01:54:20 +01:00
|
|
|
|
/** @file tracking-heap-block-provider-test.cpp
|
2026-02-07 23:56:29 +01:00
|
|
|
|
** unit test \ref DiagnosticBufferProvider_test
|
2016-11-03 18:20:10 +01:00
|
|
|
|
*/
|
|
|
|
|
|
|
2011-11-11 01:44:01 +01:00
|
|
|
|
|
|
|
|
|
|
#include "lib/error.hpp"
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
2026-02-10 23:48:09 +01:00
|
|
|
|
#include "steam/engine/diagnostic-buffer-provider.hpp"
|
2026-02-11 20:05:08 +01:00
|
|
|
|
#include "steam/engine/buffhandle-attach.hpp" ///////////////////////////////////////////////////////////TICKET 1410 : remove unnecessary API
|
2018-11-15 23:42:43 +01:00
|
|
|
|
#include "steam/engine/testframe.hpp"
|
2026-02-12 20:21:30 +01:00
|
|
|
|
#include "lib/test/diagnostic-output.hpp"//////////////////TODO
|
2011-11-11 01:44:01 +01:00
|
|
|
|
|
2011-11-21 03:26:08 +01:00
|
|
|
|
#include <vector>
|
2011-11-11 01:44:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
|
namespace steam {
|
2011-11-11 01:44:01 +01:00
|
|
|
|
namespace engine{
|
|
|
|
|
|
namespace test {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace { // Test fixture
|
|
|
|
|
|
|
|
|
|
|
|
const size_t TEST_ELM_SIZE = sizeof(uint);
|
|
|
|
|
|
const uint MAX_ELMS = 50;
|
|
|
|
|
|
|
|
|
|
|
|
std::vector<uint> testNumbers(MAX_ELMS);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2011-11-21 03:26:08 +01:00
|
|
|
|
has_expectedContent (uint nr, diagn::Block& memoryBlock)
|
2011-11-11 01:44:01 +01:00
|
|
|
|
{
|
2026-02-12 02:28:41 +01:00
|
|
|
|
#if false //////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1410 : disabled code to disentangle BufferProvider implementation
|
2011-11-11 01:44:01 +01:00
|
|
|
|
void* mem = memoryBlock.accessMemory();
|
|
|
|
|
|
uint data = *static_cast<uint*> (mem);
|
|
|
|
|
|
|
|
|
|
|
|
return data == testNumbers[nr];
|
2026-02-12 02:28:41 +01:00
|
|
|
|
#endif /////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1410 : (end) disabled code
|
2011-11-11 01:44:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool
|
2011-11-21 03:26:08 +01:00
|
|
|
|
verifyUsedBlock (uint nr, diagn::Block& memoryBlock)
|
2011-11-11 01:44:01 +01:00
|
|
|
|
{
|
2026-02-12 02:28:41 +01:00
|
|
|
|
#if false //////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1410 : disabled code to disentangle BufferProvider implementation
|
2011-11-11 23:33:59 +01:00
|
|
|
|
return memoryBlock.was_used()
|
2025-06-07 23:59:57 +02:00
|
|
|
|
and memoryBlock.was_closed()
|
|
|
|
|
|
and has_expectedContent (nr, memoryBlock);
|
2026-02-12 02:28:41 +01:00
|
|
|
|
#endif /////////////////////////////////////////////////////////////////////////////////////////////////////TICKET #1410 : (end) disabled code
|
2011-11-11 01:44:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-24 23:06:36 +02:00
|
|
|
|
/******************************************************************//**
|
2026-02-07 23:56:29 +01:00
|
|
|
|
* @test verify support to write mock components for buffer management.
|
2026-02-10 23:48:09 +01:00
|
|
|
|
* - HeapMemBufferStore is a „braindead“ implementation of the BufferProvider
|
2026-02-07 23:56:29 +01:00
|
|
|
|
* interface: it just claims new heap blocks and never de-allocates them.
|
|
|
|
|
|
* - adding a layer of instrumentation, the DiagnosticBufferProvider allows
|
|
|
|
|
|
* to count and verify allocated buffers and their content after the fact.
|
2011-11-11 01:44:01 +01:00
|
|
|
|
*/
|
2026-02-07 23:56:29 +01:00
|
|
|
|
class DiagnosticBufferProvider_test : public Test
|
2011-11-11 01:44:01 +01:00
|
|
|
|
{
|
|
|
|
|
|
virtual void
|
2025-06-07 23:59:57 +02:00
|
|
|
|
run (Arg)
|
2011-11-11 01:44:01 +01:00
|
|
|
|
{
|
2024-11-13 02:23:23 +01:00
|
|
|
|
seedRand();
|
|
|
|
|
|
|
2011-11-11 01:44:01 +01:00
|
|
|
|
simpleExample();
|
|
|
|
|
|
verifyStandardCase();
|
|
|
|
|
|
verifyTestProtocol();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
simpleExample()
|
|
|
|
|
|
{
|
2026-02-10 23:48:09 +01:00
|
|
|
|
DiagnosticBufferProvider provider;
|
2011-11-11 01:44:01 +01:00
|
|
|
|
|
|
|
|
|
|
BuffHandle testBuff = provider.lockBufferFor<TestFrame>();
|
|
|
|
|
|
CHECK (testBuff);
|
|
|
|
|
|
CHECK (testBuff.accessAs<TestFrame>().isSane());
|
|
|
|
|
|
|
2024-11-13 02:23:23 +01:00
|
|
|
|
uint dataID = 1 + rani(29);
|
2011-11-11 01:44:01 +01:00
|
|
|
|
testBuff.accessAs<TestFrame>() = testData(dataID);
|
|
|
|
|
|
|
2011-11-15 04:47:31 +01:00
|
|
|
|
provider.emitBuffer (testBuff);
|
2011-11-11 01:44:01 +01:00
|
|
|
|
provider.releaseBuffer(testBuff);
|
|
|
|
|
|
|
2026-02-12 20:21:30 +01:00
|
|
|
|
SHOW_EXPR(watch(provider).created.cnt())
|
|
|
|
|
|
SHOW_EXPR(watch(provider).emitted.cnt())
|
|
|
|
|
|
SHOW_EXPR(watch(provider).released.cnt())
|
|
|
|
|
|
CHECK (1 == watch(provider).created.cnt());
|
|
|
|
|
|
CHECK (1 == watch(provider).emitted.cnt());
|
|
|
|
|
|
CHECK (1 == watch(provider).released.cnt());
|
|
|
|
|
|
diagn::Block block0 = watch(provider).emitted[0];
|
|
|
|
|
|
CHECK (testData(dataID) == block0.accessMemory());
|
2011-11-11 01:44:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
verifyStandardCase()
|
|
|
|
|
|
{
|
2026-02-10 23:48:09 +01:00
|
|
|
|
DiagnosticBufferProvider provider;
|
2011-11-11 01:44:01 +01:00
|
|
|
|
|
2024-07-15 18:52:59 +02:00
|
|
|
|
BuffDescr buffType = provider.getDescriptorFor(TEST_ELM_SIZE);
|
2011-11-11 01:44:01 +01:00
|
|
|
|
uint numElms = provider.announce(MAX_ELMS, buffType);
|
|
|
|
|
|
CHECK (0 < numElms);
|
|
|
|
|
|
CHECK (numElms <= MAX_ELMS);
|
|
|
|
|
|
|
|
|
|
|
|
for (uint i=0; i<numElms; ++i)
|
|
|
|
|
|
{
|
2011-11-15 04:47:31 +01:00
|
|
|
|
BuffHandle buff = provider.lockBuffer(buffType);
|
2024-11-13 02:23:23 +01:00
|
|
|
|
buff.accessAs<uint>() = testNumbers[i] = rani(100000);
|
2011-11-15 04:47:31 +01:00
|
|
|
|
provider.emitBuffer (buff);
|
2011-11-11 01:44:01 +01:00
|
|
|
|
provider.releaseBuffer(buff);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
for (uint nr=0; nr<numElms; ++nr)
|
|
|
|
|
|
{
|
2026-02-10 23:48:09 +01:00
|
|
|
|
// CHECK (verifyUsedBlock (nr, provider.access_emitted(nr))); ///////////////////////////////OOO provide suitable diagnostic API!
|
2011-11-11 01:44:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
|
verifyTestProtocol()
|
|
|
|
|
|
{
|
2026-02-10 23:48:09 +01:00
|
|
|
|
DiagnosticBufferProvider provider;
|
2011-11-11 01:44:01 +01:00
|
|
|
|
|
2024-07-15 18:52:59 +02:00
|
|
|
|
BuffDescr buffType = provider.getDescriptorFor(TEST_ELM_SIZE);
|
2011-11-11 01:44:01 +01:00
|
|
|
|
|
2011-11-15 04:47:31 +01:00
|
|
|
|
BuffHandle bu1 = provider.lockBuffer (buffType);
|
|
|
|
|
|
BuffHandle bu2 = provider.lockBuffer (buffType);
|
|
|
|
|
|
BuffHandle bu3 = provider.lockBuffer (buffType);
|
|
|
|
|
|
BuffHandle bu4 = provider.lockBuffer (buffType);
|
|
|
|
|
|
BuffHandle bu5 = provider.lockBuffer (buffType);
|
2011-11-11 01:44:01 +01:00
|
|
|
|
|
2011-11-21 03:26:08 +01:00
|
|
|
|
// buffers are locked,
|
|
|
|
|
|
// but still within the per-type allocation pool
|
|
|
|
|
|
// while the output sequence is still empty
|
2026-02-10 23:48:09 +01:00
|
|
|
|
// CHECK (!provider.access_emitted(0).was_used()); ///////////////////////////////OOO provide suitable diagnostic API!
|
|
|
|
|
|
// 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());
|
2011-11-11 01:44:01 +01:00
|
|
|
|
|
2011-11-21 03:26:08 +01:00
|
|
|
|
// can use the buffers for real
|
2011-11-11 01:44:01 +01:00
|
|
|
|
bu1.accessAs<uint>() = 1;
|
|
|
|
|
|
bu2.accessAs<uint>() = 2;
|
|
|
|
|
|
bu3.accessAs<uint>() = 3;
|
|
|
|
|
|
bu4.accessAs<uint>() = 4;
|
|
|
|
|
|
bu5.accessAs<uint>() = 5;
|
|
|
|
|
|
|
2026-02-10 23:48:09 +01:00
|
|
|
|
// CHECK (0 == provider.emittedCnt()); ///////////////////////////////OOO provide suitable diagnostic API!
|
2011-11-11 01:44:01 +01:00
|
|
|
|
|
2011-11-21 03:26:08 +01:00
|
|
|
|
// now emit buffers in shuffled order
|
2011-11-15 04:47:31 +01:00
|
|
|
|
provider.emitBuffer (bu3);
|
|
|
|
|
|
provider.emitBuffer (bu1);
|
|
|
|
|
|
provider.emitBuffer (bu5);
|
|
|
|
|
|
provider.emitBuffer (bu4);
|
|
|
|
|
|
provider.emitBuffer (bu2);
|
2011-11-11 01:44:01 +01:00
|
|
|
|
|
2026-02-10 23:48:09 +01:00
|
|
|
|
// CHECK (5 == provider.emittedCnt()); ///////////////////////////////OOO provide suitable diagnostic API!
|
2011-11-21 03:26:08 +01:00
|
|
|
|
|
2026-02-10 23:48:09 +01:00
|
|
|
|
// CHECK (3 == provider.accessAs<uint>(0)); ///////////////////////////////OOO provide suitable diagnostic API!
|
|
|
|
|
|
// CHECK (1 == provider.accessAs<uint>(1));
|
|
|
|
|
|
// CHECK (5 == provider.accessAs<uint>(2));
|
|
|
|
|
|
// CHECK (4 == provider.accessAs<uint>(3));
|
|
|
|
|
|
// CHECK (2 == provider.accessAs<uint>(4));
|
2011-11-21 03:26:08 +01:00
|
|
|
|
|
2026-02-10 23:48:09 +01:00
|
|
|
|
// CHECK ( provider.access_emitted(0).was_used()); ///////////////////////////////OOO provide suitable diagnostic API!
|
|
|
|
|
|
// 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());
|
2011-11-21 03:26:08 +01:00
|
|
|
|
|
2026-02-10 23:48:09 +01:00
|
|
|
|
// 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());
|
2011-11-21 03:26:08 +01:00
|
|
|
|
|
|
|
|
|
|
bu5.release();
|
2026-02-10 23:48:09 +01:00
|
|
|
|
// 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());
|
2011-11-21 03:26:08 +01:00
|
|
|
|
|
|
|
|
|
|
bu2.release();
|
|
|
|
|
|
bu2.release();
|
|
|
|
|
|
bu5.release();
|
2026-02-10 23:48:09 +01:00
|
|
|
|
// 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());
|
2011-11-21 03:26:08 +01:00
|
|
|
|
|
|
|
|
|
|
CHECK (!bu2);
|
|
|
|
|
|
CHECK (bu3);
|
|
|
|
|
|
|
|
|
|
|
|
bu1.release();
|
|
|
|
|
|
bu3.release();
|
|
|
|
|
|
bu4.release();
|
|
|
|
|
|
|
2026-02-10 23:48:09 +01:00
|
|
|
|
// CHECK (5 == provider.emittedCnt()); ///////////////////////////////OOO provide suitable diagnostic API!
|
2011-11-11 01:44:01 +01:00
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
2026-02-07 23:56:29 +01:00
|
|
|
|
LAUNCHER (DiagnosticBufferProvider_test, "unit player");
|
2011-11-11 01:44:01 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2018-11-15 23:55:13 +01:00
|
|
|
|
}}} // namespace steam::engine::test
|