Lumiera  0.pre.03
»edit your freedom«
scheduler-interface-test.cpp
Go to the documentation of this file.
1 /*
2  SchedulerInterface(Test) - verify invocation structure of the scheduler interface
3 
4  Copyright (C) Lumiera.org
5  2013, 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 
31 #include "lib/test/run.hpp"
32 #include "lib/util.hpp"
33 
34 #include "vault/real-clock.hpp"
38 
39 
40 namespace vault{
41 namespace gear {
42 namespace test {
43 
44  using util::isSameObject;
45 
46  using lib::time::Duration;
47  using lib::time::Offset;
48  using lib::time::FSecs;
49 
51 
52 
53  namespace { // test fixture: scheduling a dummy job operation...
54 
55 
56  Time TEST_START_TIME (vault::RealClock::now());
57  const Duration TEST_FRAME_DURATION(FSecs(1,2));
58 
59  inline Offset
60  dummyFrameStart (uint frameNr)
61  {
62  return frameNr * TEST_FRAME_DURATION;
63  }
64 
65  } //(End) test fixture
66 
67 
68 
69 
70 
72 
73 
74  /***********************************************************************/
81  class SchedulerInterface_test : public Test
82  {
83 
84  virtual void
85  run (Arg)
86  {
88 
89  verify_simple_job_specification (scheduler);
90  verify_job_specification_variations (scheduler);
92  }
93 
94 
95  void
96  verify_simple_job_specification (SchedulerFrontend& scheduler)
97  {
98  SchedulerDiagnostics monitor(scheduler);
99 
100  MockJob job;
101  Time deadline(TEST_START_TIME);
102 
103  scheduler.startJobTransaction()
104  .addJob(deadline, job)
105  .commit();
106 
107  CHECK ( monitor.is_scheduled_timebound (job));
108  CHECK (!monitor.is_scheduled_background (job));
109  CHECK (!monitor.is_scheduled_freewheeling (job));
110  }
111 
112 
113  void
114  verify_job_specification_variations (SchedulerFrontend& scheduler)
115  {
116  SchedulerDiagnostics monitor(scheduler);
117 
118  JobTransaction tx = scheduler.startJobTransaction();
119 
120  MockJob job1;
121  MockJob job2;
122 
123  tx.addFreewheeling(job1);
124  tx.addBackground (job2);
125 
126  CHECK (!monitor.is_scheduled_timebound (job1));
127  CHECK (!monitor.is_scheduled_timebound (job2));
128  CHECK (!monitor.is_scheduled_background (job1));
129  CHECK (!monitor.is_scheduled_background (job2));
130  CHECK (!monitor.is_scheduled_freewheeling (job1));
131  CHECK (!monitor.is_scheduled_freewheeling (job2));
132 
133  tx.commit();
134 
135  CHECK (!monitor.is_scheduled_timebound (job1));
136  CHECK (!monitor.is_scheduled_timebound (job2));
137 
138  CHECK ( monitor.is_scheduled_background (job1));
139  CHECK ( monitor.is_scheduled_freewheeling (job2));
140  }
141 
142 
153  void
155  {
156  SchedulerDiagnostics monitor(scheduler);
157 
158  JobTransaction startTx = scheduler.startJobTransaction();
159 
160  uint dummyLevel = 5;
161  specifyJobs (startTx, dummyLevel);
162 
163  startTx.commit();
164 
165  for (uint i=0; i <=5; ++i)
166  {
167  Time nominalTime(dummyFrameStart (i));
168  Time deadline(TEST_START_TIME + nominalTime);
169 
170  CHECK (monitor.has_job_scheduled_at (deadline));
171  CHECK (nominalTime == monitor.job_at(deadline).parameter.nominalTime);
172  }
173  }
174 
180  static void
181  specifyJobs (JobTransaction& currentTx, uint dummyLevel)
182  {
183  uint frameNr = dummyLevel;
184  Time nominalTime(dummyFrameStart(frameNr));
185  Time deadline(TEST_START_TIME + nominalTime);
186 
187  MockJob job{nominalTime, frameNr};
188 
189  currentTx.addJob (deadline, job);
190 
191  if (0 < dummyLevel)
192  {
193  JobTransaction dependentTx = currentTx.startPrerequisiteTx();
194  specifyJobs (dependentTx, dummyLevel-1);
195  currentTx.attach (dependentTx);
196  }
197  }
198  };
199 
200 
202  LAUNCHER(SchedulerInterface_test, "unit engine");
203 
204 }}} // namespace vault::gear::test
Mock data structures to support implementation testing of render job planning and frame dispatch...
An facility to check and monitor the internal workings of the scheduler.
Access point to the scheduler service provided by the back-end.
Definition context for jobs to be scheduled.
Definition: run.hpp:49
static void specifyJobs(JobTransaction &currentTx, uint dummyLevel)
recursive helper function to add several levels of prerequisites It is crucial for this function to b...
Mock setup for a render Job with NO action but built-in diagnostics.
void demonstrate_nested_job_specification(SchedulerFrontend &scheduler)
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:308
static lib::Depend< SchedulerFrontend > instance
access point to the Engine Interface.
Render engine diagnostic facility.
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
JobTransaction & addBackground(Job const &job)
define a job for background rendering.
JobTransaction & addFreewheeling(Job const &job)
define a render job to be calculated as soon as resources permit.
JobTransaction & attach(JobTransaction const &prerequisites)
define a set of prerequisites of the current JobTransaction.
boost::rational< int64_t > FSecs
rational representation of fractional seconds
Definition: timevalue.hpp:229
void commit()
finish this set of job definitions.
Offset measures a distance in time.
Definition: timevalue.hpp:367
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:477
Scheduler service access point for higher layers.
Front-end for simplified access to the current wall clock time.
Vault-Layer implementation namespace root.
JobTransaction & addJob(Time deadline, Job const &job)
define a render job for time-bound calculation
bool isSameObject(A const &a, B const &b)
compare plain object identity, bypassing any custom comparison operators.
Definition: util.hpp:372