2009-08-31 00:49:08 +02:00
|
|
|
/*
|
|
|
|
|
BuffTable(Test) - check consistency of buffer table chunk allocation
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2009-08-31 00:49:08 +02:00
|
|
|
Copyright (C) Lumiera.org
|
|
|
|
|
2008, Hermann Vosseler <Ichthyostega@web.de>
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2009-08-31 00:49:08 +02:00
|
|
|
This program is free software; you can redistribute it and/or
|
|
|
|
|
modify it under the terms of the GNU General Public License as
|
2010-12-17 23:28:49 +01:00
|
|
|
published by the Free Software Foundation; either version 2 of
|
|
|
|
|
the License, or (at your option) any later version.
|
|
|
|
|
|
2009-08-31 00:49:08 +02:00
|
|
|
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.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2009-08-31 00:49:08 +02:00
|
|
|
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.
|
2010-12-17 23:28:49 +01:00
|
|
|
|
2009-08-31 00:49:08 +02:00
|
|
|
* *****************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
|
|
|
#include "lib/error.hpp"
|
|
|
|
|
|
|
|
|
|
#include "proc/engine/procnode.hpp"
|
2011-09-17 17:29:16 +02:00
|
|
|
#include "proc/engine/bufftable-obsolete.hpp"
|
2010-03-08 04:43:24 +01:00
|
|
|
#include "lib/ref-array.hpp"
|
2009-08-31 00:49:08 +02:00
|
|
|
|
|
|
|
|
#include <boost/scoped_ptr.hpp>
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
|
|
using test::Test;
|
|
|
|
|
using std::cout;
|
|
|
|
|
using std::rand;
|
|
|
|
|
|
|
|
|
|
|
2011-12-02 17:50:44 +01:00
|
|
|
namespace proc {
|
2009-08-31 00:49:08 +02:00
|
|
|
namespace engine{
|
|
|
|
|
namespace test {
|
|
|
|
|
|
|
|
|
|
namespace { // used internally
|
|
|
|
|
|
|
|
|
|
const uint TABLE_SIZ = 100000;
|
|
|
|
|
const uint CHUNK_MAX = 8000;
|
|
|
|
|
const uint WIDTH_MAX = 3;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** 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" WiringDescriptor requesting
|
|
|
|
|
* a random number of inputs and outputs */
|
|
|
|
|
struct MockSizeRequest
|
|
|
|
|
: WiringDescriptor
|
|
|
|
|
{
|
|
|
|
|
uint ii,oo;
|
|
|
|
|
|
|
|
|
|
MockSizeRequest()
|
|
|
|
|
: WiringDescriptor(dummy1,dummy2,0,NodeID()),
|
|
|
|
|
ii(rand() % CHUNK_MAX),
|
|
|
|
|
oo(rand() % CHUNK_MAX)
|
|
|
|
|
{ }
|
|
|
|
|
|
|
|
|
|
virtual uint getNrI() const { return ii; }
|
|
|
|
|
virtual uint getNrO() const { return oo; }
|
|
|
|
|
|
|
|
|
|
virtual BuffHandle callDown (State&, uint) const
|
|
|
|
|
{ throw lumiera::Error("not intended to be called"); }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-10-17 02:00:48 +02:00
|
|
|
#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #852
|
2009-08-31 00:49:08 +02:00
|
|
|
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, WiringDescriptor 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)
|
2009-09-05 18:15:58 +02:00
|
|
|
&& (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]))
|
2009-08-31 00:49:08 +02:00
|
|
|
;
|
|
|
|
|
}
|
2011-10-17 02:00:48 +02:00
|
|
|
#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #852
|
2009-08-31 00:49:08 +02:00
|
|
|
} // (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 BuffTable_test : public Test
|
|
|
|
|
{
|
|
|
|
|
typedef boost::scoped_ptr<BuffTableStorage> PSto;
|
|
|
|
|
|
|
|
|
|
PSto pStorage;
|
|
|
|
|
ulong counter;
|
|
|
|
|
|
|
|
|
|
virtual void run(Arg)
|
|
|
|
|
{
|
|
|
|
|
counter = 0;
|
|
|
|
|
|
|
|
|
|
// allocate storage block to be used chunk wise
|
|
|
|
|
pStorage.reset (new BuffTableStorage (TABLE_SIZ));
|
|
|
|
|
|
2011-10-17 02:00:48 +02:00
|
|
|
#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #852
|
2009-08-31 00:49:08 +02:00
|
|
|
invocation (0, detect_start_level(*pStorage));
|
2011-10-17 02:00:48 +02:00
|
|
|
#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #852
|
2009-08-31 00:49:08 +02:00
|
|
|
|
|
|
|
|
pStorage.reset(0); // dtor throws assertion error if corrupted
|
|
|
|
|
|
|
|
|
|
cout << "BuffTable chunks allocated: "<<counter<< "\n";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** recurse down randomly
|
|
|
|
|
* until exhausting storage
|
|
|
|
|
*/
|
|
|
|
|
void invocation (uint consumed, void* lastLevel)
|
|
|
|
|
{
|
|
|
|
|
MockSizeRequest numbers;
|
|
|
|
|
consumed += numbers.getNrI()+numbers.getNrO();
|
|
|
|
|
if (TABLE_SIZ <= consumed)
|
|
|
|
|
return; // end recursion
|
|
|
|
|
|
|
|
|
|
++counter;
|
2011-09-18 15:05:18 +02:00
|
|
|
#if false /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #833
|
2009-08-31 00:49:08 +02:00
|
|
|
BuffTableChunk thisChunk (numbers, *pStorage);
|
2010-12-10 02:55:40 +01:00
|
|
|
CHECK (consistencyCheck (thisChunk, numbers, lastLevel));
|
2009-08-31 00:49:08 +02:00
|
|
|
|
|
|
|
|
uint nrBranches ( 1 + (rand() % WIDTH_MAX));
|
|
|
|
|
while (nrBranches--)
|
|
|
|
|
invocation (consumed, first_behind (thisChunk,numbers.getNrI()));
|
2011-09-18 15:05:18 +02:00
|
|
|
#endif /////////////////////////////////////////////////////////////////////////////////////////////////////////////UNIMPLEMENTED :: TICKET #833
|
2009-08-31 00:49:08 +02:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Register this test class... */
|
|
|
|
|
LAUNCHER (BuffTable_test, "unit engine");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2011-12-02 17:50:44 +01:00
|
|
|
}}} // namespace proc::engine::test
|