WIP set up some new tests for brainstorming...

This commit is contained in:
Fischlurch 2009-08-31 00:49:08 +02:00
parent 2a54f92a98
commit c89726e2d8
8 changed files with 398 additions and 212 deletions

View file

@ -7,5 +7,17 @@ return: 0
END
PLANNED "SourceNode_test" SourceNode_test <<END
PLANNED "Proc Node basics" NodeBasic_test <<END
END
PLANNED "Proc Node fabrication" NodeFabrication_test <<END
END
PLANNED "Proc Node operation modes" NodeOperation_test <<END
END
PLANNED "source reading Node" NodeSource_test <<END
END

View file

@ -56,8 +56,11 @@ test_components_SOURCES = \
$(testcomponents_srcdir)/proc/control/command-registry-test.cpp \
$(testcomponents_srcdir)/proc/control/argument-tuple-accept-test.cpp \
$(testcomponents_srcdir)/proc/control/memento-tie-test.cpp \
$(testcomponents_srcdir)/proc/engine/bufftabletest.cpp \
$(testcomponents_srcdir)/proc/engine/sourcenodetest.cpp \
$(testcomponents_srcdir)/proc/engine/buff-table-test.cpp \
$(testcomponents_srcdir)/proc/engine/node-basic-test.cpp \
$(testcomponents_srcdir)/proc/engine/node-fabrication-test.cpp \
$(testcomponents_srcdir)/proc/engine/node-operation-test.cpp \
$(testcomponents_srcdir)/proc/engine/node-source-test.cpp \
$(testcomponents_srcdir)/proc/mobject/builder/buildertooltest.cpp \
$(testcomponents_srcdir)/proc/mobject/builder/buildsegmenttest.cpp \
$(testcomponents_srcdir)/proc/mobject/controller/rendersegmenttest.cpp \

View file

@ -0,0 +1,179 @@
/*
BuffTable(Test) - check consistency of buffer table chunk allocation
Copyright (C) Lumiera.org
2008, 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/test/run.hpp"
#include "lib/error.hpp"
#include "proc/engine/procnode.hpp"
#include "proc/engine/bufftable.hpp"
#include "lib/refarray.hpp"
#include <boost/scoped_ptr.hpp>
#include <iostream>
#include <ctime>
using test::Test;
using std::cout;
using std::rand;
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"); }
};
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)
&& (b.inBuff == &b.outBuff [num.getNrO()])
&& (b.inHandle == &b.outHandle[num.getNrO()])
&& (not_within(b.outBuff, b.outHandle, &b.inHandle[num.getNrO()])) // storage doesn't overlap
&& (not_within(b.inBuff, b.outHandle, &b.inHandle[num.getNrO()]))
&& (not_within(b.outHandle, b.outBuff, &b.inBuff[num.getNrO()]))
&& (not_within(b.inHandle, b.outBuff, &b.inBuff[num.getNrO()]))
;
}
} // (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;
std::srand (time (NULL));
// 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";
}
/** 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;
BuffTableChunk thisChunk (numbers, *pStorage);
ASSERT (consistencyCheck (thisChunk, numbers, lastLevel));
uint nrBranches ( 1 + (rand() % WIDTH_MAX));
while (nrBranches--)
invocation (consumed, first_behind (thisChunk,numbers.getNrI()));
}
};
/** Register this test class... */
LAUNCHER (BuffTable_test, "unit engine");
}} // namespace engine::test

View file

@ -1,181 +0,0 @@
/*
BuffTable(Test) - check consistency of buffer table chunk allocation
Copyright (C) Lumiera.org
2008, 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/test/run.hpp"
#include "lib/error.hpp"
#include "proc/engine/procnode.hpp"
#include "proc/engine/bufftable.hpp"
#include "lib/refarray.hpp"
#include <boost/scoped_ptr.hpp>
#include <iostream>
#include <ctime>
using test::Test;
using std::cout;
using std::rand;
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"); }
};
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)
&& (b.inBuff == &b.outBuff [num.getNrO()])
&& (b.inHandle == &b.outHandle[num.getNrO()])
&& (not_within(b.outBuff, b.outHandle, &b.inHandle[num.getNrO()])) // storage doesn't overlap
&& (not_within(b.inBuff, b.outHandle, &b.inHandle[num.getNrO()]))
&& (not_within(b.outHandle, b.outBuff, &b.inBuff[num.getNrO()]))
&& (not_within(b.inHandle, b.outBuff, &b.inBuff[num.getNrO()]))
;
}
} // (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;
std::srand (time (NULL));
// 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";
}
/** 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;
BuffTableChunk thisChunk (numbers, *pStorage);
ASSERT (consistencyCheck (thisChunk, numbers, lastLevel));
uint nrBranches ( 1 + (rand() % WIDTH_MAX));
while (nrBranches--)
invocation (consumed, first_behind (thisChunk,numbers.getNrI()));
}
};
/** Register this test class... */
LAUNCHER (BuffTable_test, "unit engine");
} // namespace test
} // namespace engine

View file

@ -0,0 +1,59 @@
/*
NodeBasic(Test) - unit test covering render node basic lifecycle and usage
Copyright (C) Lumiera.org
2009, 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/test/run.hpp"
//#include "lib/factory.hpp"
//#include "lib/util.hpp"
//#include <boost/format.hpp>
#include <iostream>
//using boost::format;
using std::string;
using std::cout;
namespace engine{
namespace test {
/*******************************************************************
* @test basic render node properties and behaviour.
*/
class NodeBasic_test : public Test
{
virtual void run(Arg)
{
UNIMPLEMENTED ("build a simple render node and then activate it");
}
};
/** Register this test class... */
LAUNCHER (NodeBasic_test, "unit engine");
}} // namespace engine::test

View file

@ -0,0 +1,59 @@
/*
NodeFabrication(Test) - building render nodes
Copyright (C) Lumiera.org
2009, 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/test/run.hpp"
//#include "lib/factory.hpp"
//#include "lib/util.hpp"
//#include <boost/format.hpp>
#include <iostream>
//using boost::format;
using std::string;
using std::cout;
namespace engine{
namespace test {
/*******************************************************************
* @test creating and wiring various kinds of render nodes.
*/
class NodeFabrication_test : public Test
{
virtual void run(Arg)
{
UNIMPLEMENTED ("build and wire some render nodes");
}
};
/** Register this test class... */
LAUNCHER (NodeFabrication_test, "unit engine");
}} // namespace engine::test

View file

@ -0,0 +1,59 @@
/*
NodeOperation(Test) - verify proper render node operation and calldown
Copyright (C) Lumiera.org
2009, 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/test/run.hpp"
//#include "lib/factory.hpp"
//#include "lib/util.hpp"
//#include <boost/format.hpp>
#include <iostream>
//using boost::format;
using std::string;
using std::cout;
namespace engine{
namespace test {
/*******************************************************************
* @test check render node operation modes and collaboration.
*/
class NodeOperation_test : public Test
{
virtual void run(Arg)
{
UNIMPLEMENTED ("operate some render nodes as linked together");
}
};
/** Register this test class... */
LAUNCHER (NodeOperation_test, "unit engine");
}} // namespace engine::test

View file

@ -1,5 +1,5 @@
/*
SourceNode(Test) - unit test of the source reading render node
NodeSource(Test) - unit test of the source reading render node
Copyright (C) Lumiera.org
2008, Hermann Vosseler <Ichthyostega@web.de>
@ -33,31 +33,27 @@ using std::string;
using std::cout;
namespace engine
{
namespace test
namespace engine{
namespace test {
/*******************************************************************
* @test the source reading render node.
*/
class NodeSource_test : public Test
{
/*******************************************************************
* @test the source reading render node.
*/
class SourceNode_test : public Test
{
virtual void run(Arg)
{
UNIMPLEMENTED ("render node pulling source data from backend");
}
};
/** Register this test class... */
LAUNCHER (SourceNode_test, "unit engine");
} // namespace test
} // namespace engine
virtual void run(Arg)
{
UNIMPLEMENTED ("render node pulling source data from backend");
}
};
/** Register this test class... */
LAUNCHER (NodeSource_test, "unit engine");
}} // namespace engine::test