Lumiera  0.pre.03
»edit your freedom«
buff-table-test.cpp
Go to the documentation of this file.
1 /*
2  BuffTable(Test) - check consistency of buffer table chunk allocation
3 
4  Copyright (C) Lumiera.org
5  2008, Hermann Vosseler <Ichthyostega@web.de>
6 
7  This program is free software; you can redistribute it and/or
8  modify it under the terms of the GNU General Public License as
9  published by the Free Software Foundation; either version 2 of
10  the License, or (at your option) any later version.
11 
12  This program is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with this program; if not, write to the Free Software
19  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 
21 * *****************************************************/
22 
28 #include "lib/test/run.hpp"
29 #include "lib/error.hpp"
30 
33 #include "lib/ref-array.hpp"
34 #include "lib/format-cout.hpp"
35 
36 #include <memory>
37 
38 using test::Test;
39 
40 
41 namespace steam {
42 namespace engine{
43 namespace test {
44 
45  namespace { // used internally
46 
47  const uint TABLE_SIZ = 100000;
48  const uint CHUNK_MAX = 8000;
49  const uint WIDTH_MAX = 3;
50 
51 
53  template<class E>
55  {
56  E decoy;
57  E const& operator[] (size_t) const { return decoy; }
58  size_t size() const { return CHUNK_MAX;}
59  };
62 
63 
68  {
69  uint ii,oo;
70 
72  : WiringDescriptor(dummy1,dummy2,0,NodeID()),
73  ii(rand() % CHUNK_MAX),
74  oo(rand() % CHUNK_MAX)
75  { }
76 
77  virtual uint getNrI() const { return ii; }
78  virtual uint getNrO() const { return oo; }
79 
80  virtual BuffHandle callDown (State&, uint) const
81  { throw lumiera::Error("not intended to be called"); }
82  };
83 
84 
85 
86 #if false
87  void*
88  detect_start_level (BuffTableStorage& sto)
89  {
90  return BuffTableChunk(MockSizeRequest(), sto ).outHandle;
91  } // address of first available storage element
92 
93 
94  inline void*
95  first_behind (BuffTable const& thisChunk, const uint nrI)
96  {
97  return &thisChunk.inHandle[nrI];
98  }
99 
100 
101  inline bool
102  not_within(void* candidate, void* lower, void* upper)
103  {
104  return (candidate < lower) || (upper <= candidate);
105  }
106 
107 
108  bool
109  consistencyCheck (BuffTable const& b, WiringDescriptor const& num, void* lastLevel)
110  {
111  return (b.outHandle == lastLevel ) // storage is allocated continuously
112  && (b.outBuff <= b.inBuff ) // input slots are behind the output slots
113  && (b.outHandle <= b.inHandle)
114  && (b.inBuff == &b.outBuff [num.nrO])
115  && (b.inHandle == &b.outHandle[num.nrO])
116  && (not_within(b.outBuff, b.outHandle, &b.inHandle[num.nrO])) // storage doesn't overlap
117  && (not_within(b.inBuff, b.outHandle, &b.inHandle[num.nrO]))
118  && (not_within(b.outHandle, b.outBuff, &b.inBuff[num.nrO]))
119  && (not_within(b.inHandle, b.outBuff, &b.inBuff[num.nrO]))
120  ;
121  }
122 #endif
123  } // (End) internal defs
124 
125 
126 
127  /***************************************************************/
134  class BuffTable_test : public Test
135  {
136  using PSto = std::unique_ptr<BuffTableStorage>;
137 
138  PSto pStorage;
139  ulong counter;
140 
141  virtual void run(Arg)
142  {
143  counter = 0;
144 
145  // allocate storage block to be used chunk wise
146  pStorage.reset (new BuffTableStorage (TABLE_SIZ));
147 
148 #if false
149  invocation (0, detect_start_level(*pStorage));
150 #endif
151 
152  pStorage.reset(0); // dtor throws assertion error if corrupted
153 
154  cout << "BuffTable chunks allocated: "<<counter<< "\n";
155  }
156 
157 
161  void invocation (uint consumed, void* lastLevel)
162  {
163  MockSizeRequest numbers;
164  consumed += numbers.getNrI()+numbers.getNrO();
165  if (TABLE_SIZ <= consumed)
166  return; // end recursion
167 
168  ++counter;
169 #if false
170  BuffTableChunk thisChunk (numbers, *pStorage);
171  CHECK (consistencyCheck (thisChunk, numbers, lastLevel));
172 
173  uint nrBranches ( 1 + (rand() % WIDTH_MAX));
174  while (nrBranches--)
175  invocation (consumed, first_behind (thisChunk,numbers.getNrI()));
176 #endif
177  }
178  };
179 
180 
182  LAUNCHER (BuffTable_test, "unit engine");
183 
184 
185 
186 }}} // namespace steam::engine::test
Interface to the processing nodes and the render nodes network.
Abstraction to access the state of a currently ongoing render/calculation process, as it is tied to the supporting facilities of the vault layer.
Definition: state.hpp:59
Abstraction: Array of const references.
Definition: ref-array.hpp:48
Obsolete, to be rewritten /////TICKET #826 to be allocated on the stack while evaluating a ProcNode::...
Automatically use custom string conversion in C++ stream output.
Obsolete, to be rewritten /////TICKET #826.
Definition: run.hpp:49
void invocation(uint consumed, void *lastLevel)
recurse down randomly until exhausting storage
Steam-Layer implementation namespace root.
Abstract Base Class for all testcases.
Definition: run.hpp:62
Abstraction interface: array-like access by subscript.
Simple test class runner.
Lumiera error handling (C++ interface).
Handle for a buffer for processing data, abstracting away the actual implementation.
Definition: buffhandle.hpp:115
Identification tuple for denoting render nodes unambiguously.
Definition: frameid.hpp:51
virtual BuffHandle callDown(State &, uint) const
the wiring-dependent part of the node operation.
a "hijacked" WiringDescriptor requesting a random number of inputs and outputs
Obsolete, to be rewritten /////TICKET #826.
Interface: Description of the input and output ports, processing function and predecessor nodes for a...
Definition: procnode.hpp:78
Interface and Base definition for all Lumiera Exceptions.
Definition: error.hpp:71