Lumiera 0.pre.04
»edit your freedom«
Loading...
Searching...
No Matches
mock-dispatcher.cpp
Go to the documentation of this file.
1/*
2 MockDispatcher - diagnostic render job and frame dispatcher
3
4 Copyright (C)
5 2013, Hermann Vosseler <Ichthyostega@web.de>
6
7  **Lumiera** is free software; you can redistribute it and/or modify it
8  under the terms of the GNU General Public License as published by the
9  Free Software Foundation; either version 2 of the License, or (at your
10  option) any later version. See the file COPYING for further details.
11
12* *****************************************************************/
13
37#include "vault/real-clock.hpp"
38#include "lib/hash-combine.hpp"
39#include "lib/null-value.hpp"
40#include "lib/depend.hpp"
41#include "lib/util.hpp"
42
43#include <functional>
44#include <unordered_map>
45
46
47namespace steam {
48namespace engine{
49namespace test {
50
51 namespace { // MockJob and DummyClosure implementation details...
52
53 using lib::rani;
54 using lib::HashVal;
55 using lib::NullValue;
57 using std::unordered_map;
59
61
62
63 const int MAX_PARAM_A(1000);
64 const int MAX_PARAM_B(10);
65
66
75 : public JobClosure
76 {
77 void
78 invokeJobOperation (JobParameter parameter) override
79 {
80 invocationLog_[hash_value (parameter)] = Invocation(parameter);
81 }
82
84 getJobKind() const override
85 {
86 return META_JOB;
87 }
88
100 buildInstanceID (HashVal seed) const override
101 {
102 InvocationInstanceID instance;
103 instance.part.a = seed;
104 return instance;
105 }
106
107 size_t
108 hashOfInstance (InvocationInstanceID invoKey) const override
109 {
110 std::hash<size_t> hashr;
111 HashVal res = hashr (invoKey.frameNumber);
112 lib::hash::combine (res, hashr (invoKey.part.t));
113 return res;
114 }
115
116
117 /* === Logging/Reporting of job invocation === */
118
120 {
123 int a,b;
124
125 Invocation (JobParameter param)
126 : nominal{TimeValue(param.nominalTime)}
127 , real{RealClock::now()}
128 , a{param.invoKey.part.a}
129 , b{param.invoKey.part.b}
130 { }
131
133 : nominal{Time::ANYTIME}
134 , real{Time::NEVER}
135 , a{MAX_PARAM_A}, b{0}
136 { }
137 };
138
140 unordered_map<HashVal,Invocation> invocationLog_;
141
142
143 public:
144 Invocation const&
145 queryInvocation (JobParameter param) const
146 {
147 return access_or_default (invocationLog_, hash_value(param)
149 }
150
151 void
153 {
154 invocationLog_.clear();
155 }
156 };
157
158
159
162
165
166 }// (End)Implementation details
167
168
169
170
171
172
173
174
175 Job
177 {
178 InvocationInstanceID invoKey;
179 invoKey.part.a = rani (MAX_PARAM_A);
180 invoKey.part.b = rani (2*MAX_PARAM_B - MAX_PARAM_B);
181
182 Time nominalTime = lib::test::randTime();
183
184 return Job(dummyClosure, invoKey, nominalTime);
185 }
186
187
188 Job
189 MockJob::build (Time nominalTime, int additionalKey)
190 {
191 InvocationInstanceID invoKey;
192 invoKey.part.a = additionalKey;
193 invoKey.part.b = rani (2*MAX_PARAM_B - MAX_PARAM_B);
194
195 return Job(dummyClosure, invoKey, nominalTime);
196 }
197
198
199 bool
201 {
202 REQUIRE (job.usesClosure (dummyClosure));
203
204 return Time::NEVER != dummyClosure.queryInvocation(job.parameter).real;
205 }
206
207
208 Time
210 {
211 REQUIRE (job.usesClosure (dummyClosure));
212
213 return dummyClosure.queryInvocation(job.parameter).real;
214 }
215
216
217 Time
219 {
220 REQUIRE (job.usesClosure (dummyClosure));
221
222 return dummyClosure.queryInvocation(job.parameter).nominal;
223 }
224
225
226 int
228 {
229 REQUIRE (job.usesClosure (dummyClosure));
230
231 return dummyClosure.queryInvocation(job.parameter).a;
232 }
233
234
238 {
239 return dummyClosure;
240 }
241
248 bool
250 {
252 JobClosure& jobFunctor = static_cast<JobClosure&> (*job.jobClosure);
253 return lumiera_invokey_eq (&util::unConst(job).parameter.invoKey, &empty)
254 and util::isSameObject (jobFunctor, nopFunctor());
255 }
256
257
258
259}}} // namespace steam::engine::test
Access point to singletons and other kinds of dependencies designated by type.
Definition depend.hpp:281
basic constant internal time value.
a mutable time value, behaving like a plain number, allowing copy and re-accessing
Lumiera's internal time value datatype.
static const Time NEVER
border condition marker value. NEVER >= any time value
static bool was_invoked(Job const &job)
static Time invocationNominalTime(Job const &job)
static int invocationAdditionalKey(Job const &job)
static Job build()
uses random job definition values
static Time invocationTime(Job const &job)
static JobClosure & getFunctor()
static bool isNopJob(Job const &)
size_t hashOfInstance(InvocationInstanceID invoKey) const override
unordered_map< HashVal, Invocation > invocationLog_
recording MockJob invocations
InvocationInstanceID buildInstanceID(HashVal seed) const override
Generate a specifically marked invocationKey for use in unit-tests.
Convenience frontend to access the current raw system time.
Interface of the closure for frame rendering jobs.
Definition job.h:244
Individual frame rendering task, forwarding to a closure.
Definition job.h:276
bool usesClosure(JobClosure const &) const
Definition job.cpp:89
Singleton services and Dependency Injection.
Hash combine function extracted from LibBoost 1.67 Combine two hash values to form a composite depend...
int lumiera_invokey_eq(void *l, void *r)
Definition job.cpp:154
JobKind
Definition job.h:64
@ META_JOB
render process self organisation
Definition job.h:67
struct InvocationInstanceID::@62 part
FrameCnt frameNumber
Definition job.h:109
opaque ID attached to each individual job invocation.
Definition job.h:105
Mock data structures to support implementation testing of render job planning and frame dispatch.
void combine(size_t &combinedHash, size_t additionalHash)
meld the additional hash value into the given base hash value.
int rani(uint bound=_iBOUND())
Definition random.hpp:135
size_t HashVal
a STL compatible hash value
Definition hash-value.h:52
const int MAX_PARAM_A(1000)
random test values 0...1000
DummyClosure dummyClosure
actual instance of the test dummy job functor
const int MAX_PARAM_B(10)
random test values -10...+10
Steam-Layer implementation namespace root.
Test runner and basic definitions for tests.
bool isSameObject(A const &a, B const &b)
compare plain object identity, based directly on the referee's memory identities.
Definition util.hpp:421
OBJ * unConst(const OBJ *)
shortcut to save some typing when having to define const and non-const variants of member functions
Definition util.hpp:358
MAP::mapped_type const & access_or_default(MAP &map, typename MAP::key_type const &key, typename MAP::mapped_type const &refDefault)
expose a reference to a map entry, with fall-back to some default object
Definition util.hpp:292
lumiera_jobParameter const & JobParameter
Definition job.h:205
Generic implementation of a JobFunctor to perform no calculations.
Singleton-style holder for NIL or default values.
Front-end for simplified access to the current wall clock time.
Singleton holder for NIL or default value objects.
Primary class template for std::hash.
A collection of frequently used helper functions to support unit testing.
a family of time value like entities and their relationships.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...