2010-12-18 00:58:19 +01:00
|
|
|
/*
|
|
|
|
|
AllocationCluster(Test) - verify bulk (de)allocating a family of objects
|
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
|
|
|
|
|
|
* *****************************************************/
|
|
|
|
|
|
2017-02-22 01:54:20 +01:00
|
|
|
/** @file allocation-cluster-test.cpp
|
2017-02-22 03:17:18 +01:00
|
|
|
** unit test \ref AllocationCluster_test
|
2016-11-03 18:20:10 +01:00
|
|
|
*/
|
|
|
|
|
|
2010-12-18 00:58:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
|
|
|
#include "lib/test/test-helper.hpp"
|
|
|
|
|
#include "lib/allocation-cluster.hpp"
|
2024-05-15 19:59:05 +02:00
|
|
|
#include "lib/test/diagnostic-output.hpp"/////////////////TODO
|
|
|
|
|
#include "lib/iter-explorer.hpp"
|
|
|
|
|
#include "lib/util.hpp"
|
2010-12-18 00:58:19 +01:00
|
|
|
|
2024-05-15 19:59:05 +02:00
|
|
|
#include <array>
|
2010-12-18 00:58:19 +01:00
|
|
|
#include <vector>
|
|
|
|
|
#include <limits>
|
2024-05-15 19:59:05 +02:00
|
|
|
#include <functional>
|
|
|
|
|
//#include <boost/lexical_cast.hpp>
|
2010-12-18 00:58:19 +01:00
|
|
|
|
2024-05-15 19:59:05 +02:00
|
|
|
//using boost::lexical_cast;
|
|
|
|
|
using lib::explore;
|
2010-12-18 00:58:19 +01:00
|
|
|
using lib::test::showSizeof;
|
|
|
|
|
using util::isnil;
|
|
|
|
|
using ::Test;
|
|
|
|
|
|
|
|
|
|
using std::numeric_limits;
|
2024-05-15 19:59:05 +02:00
|
|
|
using std::function;
|
2010-12-18 00:58:19 +01:00
|
|
|
using std::vector;
|
2024-05-15 19:59:05 +02:00
|
|
|
using std::array;
|
2010-12-18 00:58:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace lib {
|
|
|
|
|
namespace test {
|
|
|
|
|
|
|
|
|
|
namespace { // a family of test dummy classes
|
|
|
|
|
|
2024-05-15 19:59:05 +02:00
|
|
|
const uint NUM_CLUSTERS = 5;
|
|
|
|
|
const uint NUM_TYPES = 20;
|
|
|
|
|
const uint NUM_OBJECTS = 500;
|
2010-12-18 00:58:19 +01:00
|
|
|
|
|
|
|
|
long checksum = 0; // validate proper pairing of ctor/dtor calls
|
|
|
|
|
|
|
|
|
|
template<uint i>
|
|
|
|
|
class Dummy
|
|
|
|
|
{
|
2024-05-15 19:59:05 +02:00
|
|
|
static_assert (0 < i);
|
|
|
|
|
array<uchar,i> content_;
|
2010-12-18 00:58:19 +01:00
|
|
|
|
|
|
|
|
public:
|
2024-05-15 19:59:05 +02:00
|
|
|
Dummy (uchar id=1)
|
2010-12-18 00:58:19 +01:00
|
|
|
{
|
2024-05-15 19:59:05 +02:00
|
|
|
content_.fill(id);
|
|
|
|
|
checksum += explore(content_).resultSum();
|
2010-12-18 00:58:19 +01:00
|
|
|
}
|
|
|
|
|
|
2024-05-15 19:59:05 +02:00
|
|
|
~Dummy()
|
2010-12-18 00:58:19 +01:00
|
|
|
{
|
2024-05-15 19:59:05 +02:00
|
|
|
checksum -= explore(content_).resultSum();
|
2010-12-18 00:58:19 +01:00
|
|
|
}
|
|
|
|
|
|
2024-05-15 19:59:05 +02:00
|
|
|
char getID() { return content_[0]; }
|
2010-12-18 00:58:19 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
template<uint i>
|
|
|
|
|
void
|
2024-05-15 19:59:05 +02:00
|
|
|
place_object (AllocationCluster& clu, uchar id)
|
|
|
|
|
{
|
|
|
|
|
clu.create<Dummy<i>> (id);
|
|
|
|
|
}
|
2010-12-18 00:58:19 +01:00
|
|
|
|
|
|
|
|
|
2024-05-15 19:59:05 +02:00
|
|
|
inline array<function<void(AllocationCluster&, uchar)>, NUM_TYPES>
|
|
|
|
|
buildTrampoline()
|
|
|
|
|
{
|
|
|
|
|
return { place_object<1>
|
|
|
|
|
, place_object<2>
|
|
|
|
|
, place_object<3>
|
|
|
|
|
, place_object<5>
|
|
|
|
|
, place_object<10>
|
|
|
|
|
, place_object<13>
|
|
|
|
|
, place_object<14>
|
|
|
|
|
, place_object<15>
|
|
|
|
|
, place_object<16>
|
|
|
|
|
, place_object<17>
|
|
|
|
|
, place_object<18>
|
|
|
|
|
, place_object<19>
|
|
|
|
|
, place_object<20>
|
|
|
|
|
, place_object<25>
|
|
|
|
|
, place_object<30>
|
|
|
|
|
, place_object<35>
|
|
|
|
|
, place_object<40>
|
|
|
|
|
, place_object<50>
|
|
|
|
|
, place_object<100>
|
|
|
|
|
, place_object<200>
|
|
|
|
|
};
|
|
|
|
|
}
|
2010-12-18 00:58:19 +01:00
|
|
|
|
|
|
|
|
void
|
2024-05-15 19:59:05 +02:00
|
|
|
fill (AllocationCluster& clu)
|
2010-12-18 00:58:19 +01:00
|
|
|
{
|
2024-05-15 19:59:05 +02:00
|
|
|
auto invoker = buildTrampoline();
|
2010-12-18 00:58:19 +01:00
|
|
|
for (uint i=0; i<NUM_OBJECTS; ++i)
|
2024-05-15 19:59:05 +02:00
|
|
|
invoker[rand() % NUM_TYPES] (clu, uchar(i));
|
2010-12-18 00:58:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-10-24 23:06:36 +02:00
|
|
|
/*********************************************************************//**
|
2010-12-18 00:58:19 +01:00
|
|
|
* @test verify the proper workings of our custom allocation scheme
|
|
|
|
|
* managing families of interconnected objects for the segments
|
|
|
|
|
* of the low-level model.
|
|
|
|
|
*/
|
|
|
|
|
class AllocationCluster_test : public Test
|
|
|
|
|
{
|
2024-05-15 19:59:05 +02:00
|
|
|
virtual void
|
|
|
|
|
run (Arg)
|
2010-12-18 00:58:19 +01:00
|
|
|
{
|
|
|
|
|
simpleUsage();
|
2024-05-15 19:59:05 +02:00
|
|
|
checkLifecycle();
|
2010-12-18 00:58:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
simpleUsage()
|
|
|
|
|
{
|
|
|
|
|
AllocationCluster clu;
|
|
|
|
|
|
2024-05-15 19:59:05 +02:00
|
|
|
char c1(123), c2(45);
|
|
|
|
|
Dummy<66>& ref1 = clu.create<Dummy<66>> ();
|
|
|
|
|
Dummy<77>& ref2 = clu.create<Dummy<77>> (c1);
|
|
|
|
|
Dummy<77>& ref3 = clu.create<Dummy<77>> (c2);
|
2010-12-18 00:58:19 +01:00
|
|
|
|
2024-05-15 19:59:05 +02:00
|
|
|
// TRACE (test, "%s", showSizeof(rX).c_str());///////////////////////OOO
|
2010-12-18 00:58:19 +01:00
|
|
|
|
2024-05-15 19:59:05 +02:00
|
|
|
//returned references actually point at the objects we created
|
|
|
|
|
CHECK (1 ==ref1.getID());
|
2010-12-18 00:58:19 +01:00
|
|
|
CHECK (123==ref2.getID());
|
2024-05-15 19:59:05 +02:00
|
|
|
CHECK (45 ==ref3.getID());
|
|
|
|
|
|
|
|
|
|
CHECK (1 == clu.numExtents());
|
|
|
|
|
CHECK (66+77+77 == clu.numBytes());
|
2012-04-30 04:28:16 +02:00
|
|
|
|
2024-05-15 19:59:05 +02:00
|
|
|
// now use objects and just let them go;
|
2010-12-18 00:58:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void
|
2024-05-15 19:59:05 +02:00
|
|
|
checkLifecycle()
|
2010-12-18 00:58:19 +01:00
|
|
|
{
|
|
|
|
|
CHECK (0==checksum);
|
|
|
|
|
{
|
2024-05-15 19:59:05 +02:00
|
|
|
vector<AllocationCluster> clusters (NUM_CLUSTERS);
|
|
|
|
|
for (auto& clu : clusters)
|
|
|
|
|
fill(clu);
|
2010-12-18 00:58:19 +01:00
|
|
|
CHECK (0!=checksum);
|
|
|
|
|
}
|
|
|
|
|
CHECK (0==checksum);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
LAUNCHER (AllocationCluster_test, "unit common");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}} // namespace lib::test
|