* 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.
182 lines
6.5 KiB
C++
182 lines
6.5 KiB
C++
/*
|
||
FeedManifold(Test) - check consistency of buffer table chunk allocation
|
||
|
||
Copyright (C)
|
||
2008, Hermann Vosseler <Ichthyostega@web.de>
|
||
|
||
**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.
|
||
|
||
* *****************************************************************/
|
||
|
||
/** @file feed-manifold-test.cpp
|
||
** unit test \ref FeedManifold_test
|
||
*/
|
||
|
||
|
||
#include "lib/test/run.hpp"
|
||
#include "lib/error.hpp"
|
||
|
||
#include "steam/engine/proc-node.hpp"
|
||
#include "steam/engine/feed-manifold.hpp"
|
||
#include "lib/format-cout.hpp" ////////////////TODO
|
||
|
||
#include <memory>
|
||
|
||
using test::Test;
|
||
|
||
|
||
namespace steam {
|
||
namespace engine{
|
||
namespace test {
|
||
|
||
namespace { // used internally
|
||
|
||
const uint TABLE_SIZ = 100000;
|
||
const uint CHUNK_MAX = 8000;
|
||
const uint WIDTH_MAX = 3;
|
||
|
||
|
||
#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #1367 : Rebuild the Node Invocation
|
||
/** just some crap to pass in as ctor argument... */
|
||
template<class E>
|
||
struct DummyArray : lib::RefArray<E>
|
||
{
|
||
E decoy;
|
||
E const& operator[] (size_t) const { return decoy; }
|
||
size_t size() const { return CHUNK_MAX;}
|
||
};
|
||
DummyArray<ChannelDescriptor> dummy1;
|
||
DummyArray<InChanDescriptor> dummy2;
|
||
|
||
|
||
/** a "hijacked" Connectivity descriptor requesting
|
||
* a random number of inputs and outputs */
|
||
struct MockSizeRequest
|
||
: Connectivity
|
||
{
|
||
uint ii,oo;
|
||
|
||
MockSizeRequest()
|
||
: Connectivity(dummy1,dummy2,0,NodeID()),
|
||
ii(rani (CHUNK_MAX)),
|
||
oo(rani (CHUNK_MAX))
|
||
{ }
|
||
|
||
virtual uint getNrI() const { return ii; }
|
||
virtual uint getNrO() const { return oo; }
|
||
|
||
virtual BuffHandle callDown (StateClosure_OBSOLETE&, uint) const
|
||
{ throw lumiera::Error("not intended to be called"); }
|
||
};
|
||
#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #1367 : Rebuild the Node Invocation
|
||
|
||
|
||
|
||
#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #852
|
||
void*
|
||
detect_start_level (BuffTableStorage& sto)
|
||
{
|
||
return BuffTableChunk(MockSizeRequest(), sto ).outHandle;
|
||
} // address of first available storage element
|
||
|
||
|
||
inline void*
|
||
first_behind (BuffTable const& thisChunk, const uint nrI)
|
||
{
|
||
return &thisChunk.inHandle[nrI];
|
||
}
|
||
|
||
|
||
inline bool
|
||
not_within(void* candidate, void* lower, void* upper)
|
||
{
|
||
return (candidate < lower) || (upper <= candidate);
|
||
}
|
||
|
||
|
||
bool
|
||
consistencyCheck (BuffTable const& b, Connectivity const& num, void* lastLevel)
|
||
{
|
||
return (b.outHandle == lastLevel ) // storage is allocated continuously
|
||
&& (b.outBuff <= b.inBuff ) // input slots are behind the output slots
|
||
&& (b.outHandle <= b.inHandle)
|
||
&& (b.inBuff == &b.outBuff [num.nrO])
|
||
&& (b.inHandle == &b.outHandle[num.nrO])
|
||
&& (not_within(b.outBuff, b.outHandle, &b.inHandle[num.nrO])) // storage doesn't overlap
|
||
&& (not_within(b.inBuff, b.outHandle, &b.inHandle[num.nrO]))
|
||
&& (not_within(b.outHandle, b.outBuff, &b.inBuff[num.nrO]))
|
||
&& (not_within(b.inHandle, b.outBuff, &b.inBuff[num.nrO]))
|
||
;
|
||
}
|
||
#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #852
|
||
} // (End) internal defs
|
||
|
||
|
||
|
||
/***************************************************************//**
|
||
* @test create a random pattern of recursive invocations, each
|
||
* allocating a chunk out of a global buffer table storage.
|
||
* After returning, each allocation should be cleanly
|
||
* deallocated and the internal level in the storage vector
|
||
* should have doped to zero again.
|
||
*/
|
||
class FeedManifold_test : public Test
|
||
{
|
||
#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #852
|
||
using PSto = std::unique_ptr<BuffTableStorage>;
|
||
|
||
PSto pStorage;
|
||
#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #852
|
||
ulong counter;
|
||
|
||
void
|
||
run(Arg) override
|
||
{
|
||
seedRand(); ////////////////TODO RLY?
|
||
counter = 0;
|
||
|
||
#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #852
|
||
// allocate storage block to be used chunk wise
|
||
pStorage.reset (new BuffTableStorage (TABLE_SIZ));
|
||
|
||
invocation (0, detect_start_level(*pStorage));
|
||
|
||
pStorage.reset(0); // dtor throws assertion error if corrupted
|
||
|
||
cout << "BuffTable chunks allocated: "<<counter<< "\n";
|
||
#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #852
|
||
}
|
||
|
||
|
||
/** recurse down randomly
|
||
* until exhausting storage
|
||
*/
|
||
void invocation (uint consumed, void* lastLevel)
|
||
{
|
||
#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #833
|
||
MockSizeRequest numbers;
|
||
consumed += numbers.getNrI()+numbers.getNrO();
|
||
if (TABLE_SIZ <= consumed)
|
||
return; // end recursion
|
||
|
||
++counter;
|
||
BuffTableChunk thisChunk (numbers, *pStorage);
|
||
CHECK (consistencyCheck (thisChunk, numbers, lastLevel));
|
||
|
||
uint nrBranches ( 1 + rani(WIDTH_MAX));
|
||
while (nrBranches--)
|
||
invocation (consumed, first_behind (thisChunk,numbers.getNrI()));
|
||
#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #833
|
||
}
|
||
};
|
||
|
||
|
||
/** Register this test class... */
|
||
LAUNCHER (FeedManifold_test, "unit engine");
|
||
|
||
|
||
|
||
}}} // namespace steam::engine::test
|