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)
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 
22 #include "lib/test/run.hpp"
23 #include "lib/util.hpp"
24 
25 #include "vault/real-clock.hpp"
29 
30 
31 namespace vault{
32 namespace gear {
33 namespace test {
34 
35  using util::isSameObject;
36 
37  using lib::time::Duration;
38  using lib::time::Offset;
39  using lib::time::FSecs;
40 
42 
43 
44  namespace { // test fixture: scheduling a dummy job operation...
45 
46 
47  Time TEST_START_TIME (vault::RealClock::now());
48  const Duration TEST_FRAME_DURATION(FSecs(1,2));
49 
50  inline Offset
51  dummyFrameStart (uint frameNr)
52  {
53  return frameNr * TEST_FRAME_DURATION;
54  }
55 
56  } //(End) test fixture
57 
58 
59 
60 
61 
63 
64 
65  /***********************************************************************/
72  class SchedulerInterface_test : public Test
73  {
74 
75  virtual void
76  run (Arg)
77  {
78  seedRand();
80 
81  verify_simple_job_specification (scheduler);
82  verify_job_specification_variations (scheduler);
84  }
85 
86 
87  void
88  verify_simple_job_specification (SchedulerFrontend& scheduler)
89  {
90  SchedulerDiagnostics monitor(scheduler);
91 
92  MockJob job;
93  Time deadline(TEST_START_TIME);
94 
95  scheduler.startJobTransaction()
96  .addJob(deadline, job)
97  .commit();
98 
99  CHECK ( monitor.is_scheduled_timebound (job));
100  CHECK (!monitor.is_scheduled_background (job));
101  CHECK (!monitor.is_scheduled_freewheeling (job));
102  }
103 
104 
105  void
106  verify_job_specification_variations (SchedulerFrontend& scheduler)
107  {
108  SchedulerDiagnostics monitor(scheduler);
109 
110  JobTransaction tx = scheduler.startJobTransaction();
111 
112  MockJob job1;
113  MockJob job2;
114 
115  tx.addFreewheeling(job1);
116  tx.addBackground (job2);
117 
118  CHECK (!monitor.is_scheduled_timebound (job1));
119  CHECK (!monitor.is_scheduled_timebound (job2));
120  CHECK (!monitor.is_scheduled_background (job1));
121  CHECK (!monitor.is_scheduled_background (job2));
122  CHECK (!monitor.is_scheduled_freewheeling (job1));
123  CHECK (!monitor.is_scheduled_freewheeling (job2));
124 
125  tx.commit();
126 
127  CHECK (!monitor.is_scheduled_timebound (job1));
128  CHECK (!monitor.is_scheduled_timebound (job2));
129 
130  CHECK ( monitor.is_scheduled_background (job1));
131  CHECK ( monitor.is_scheduled_freewheeling (job2));
132  }
133 
134 
145  void
147  {
148  SchedulerDiagnostics monitor(scheduler);
149 
150  JobTransaction startTx = scheduler.startJobTransaction();
151 
152  uint dummyLevel = 5;
153  specifyJobs (startTx, dummyLevel);
154 
155  startTx.commit();
156 
157  for (uint i=0; i <=5; ++i)
158  {
159  Time nominalTime(dummyFrameStart (i));
160  Time deadline(TEST_START_TIME + nominalTime);
161 
162  CHECK (monitor.has_job_scheduled_at (deadline));
163  CHECK (nominalTime == monitor.job_at(deadline).parameter.nominalTime);
164  }
165  }
166 
172  static void
173  specifyJobs (JobTransaction& currentTx, uint dummyLevel)
174  {
175  uint frameNr = dummyLevel;
176  Time nominalTime(dummyFrameStart(frameNr));
177  Time deadline(TEST_START_TIME + nominalTime);
178 
179  MockJob job{nominalTime, frameNr};
180 
181  currentTx.addJob (deadline, job);
182 
183  if (0 < dummyLevel)
184  {
185  JobTransaction dependentTx = currentTx.startPrerequisiteTx();
186  specifyJobs (dependentTx, dummyLevel-1);
187  currentTx.attach (dependentTx);
188  }
189  }
190  };
191 
192 
194  LAUNCHER(SchedulerInterface_test, "unit engine");
195 
196 }}} // 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:40
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:299
static lib::Depend< SchedulerFrontend > instance
access point to the Engine Interface.
Render engine diagnostic facility.
Simplistic 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:220
void commit()
finish this set of job definitions.
Offset measures a distance in time.
Definition: timevalue.hpp:358
Duration is the internal Lumiera time metric.
Definition: timevalue.hpp:468
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, based directly on the referee&#39;s memory identities. ...
Definition: util.hpp:421