Lumiera  0.pre.03
»edit your freedom«
scheduler-invocation-test.cpp
Go to the documentation of this file.
1 /*
2  SchedulerInvocation(Test) - verify queue processing in the scheduler
3 
4  Copyright (C) Lumiera.org
5  2023, 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"
30 #include "lib/util.hpp"
31 
32 using test::Test;
33 using util::isSameObject;
34 
35 
36 namespace vault{
37 namespace gear {
38 namespace test {
39 
40 
41 
42 
43  /********************************************************************/
49  {
50 
51  virtual void
52  run (Arg)
53  {
54  simpleUsage();
59  verify_isDue();
60  }
61 
62 
65  void
67  {
68  SchedulerInvocation sched;
69  Activity activity;
70  Time when{1,2,3};
71  Time dead{2,3,4};
72 
73  CHECK (not sched.peekHead());
74 
75  sched.instruct ({activity, when, dead});
76  sched.feedPrioritisation();
77  CHECK (sched.peekHead());
78 
79  Activity* head = sched.pullHead();
80  CHECK (not sched.peekHead());
81  CHECK (isSameObject (*head, activity));
82  }
83 
84 
85 
90  void
92  {
93  SchedulerInvocation sched;
94  Activity one{1u,1u};
95  Activity two{2u,2u};
96  Activity wee{3u,3u};
97  Time t{5,5};
98 
99  sched.instruct ({one, t});
100  sched.instruct ({two, t});
101  sched.instruct ({wee, t});
102  CHECK (not sched.peekHead());
103 
104  sched.feedPrioritisation();
105  CHECK (isSameObject (*sched.pullHead(), one));
106  CHECK (isSameObject (*sched.pullHead(), two));
107  CHECK (isSameObject (*sched.pullHead(), wee));
108  CHECK (not sched.peekHead());
109  CHECK (sched.empty());
110  }
111 
112 
113 
119  void
121  {
122  SchedulerInvocation sched;
123  Activity a1{1u,1u};
124  Activity a2{2u,2u};
125  Activity a3{3u,3u};
126  Activity a4{4u,4u};
127 
128  sched.instruct ({a2, Time{2,0}});
129  sched.instruct ({a4, Time{4,0}});
130  sched.feedPrioritisation();
131  CHECK (isSameObject (*sched.peekHead(), a2));
132 
133  sched.instruct ({a3, Time{3,0}});
134  sched.instruct ({a1, Time{1,0}});
135  CHECK (isSameObject (*sched.peekHead(), a2));
136 
137  sched.feedPrioritisation();
138  CHECK (isSameObject (*sched.pullHead(), a1));
139  CHECK (isSameObject (*sched.pullHead(), a2));
140  CHECK (isSameObject (*sched.pullHead(), a3));
141  CHECK (isSameObject (*sched.pullHead(), a4));
142  }
143 
144 
145 
149  void
151  {
152  SchedulerInvocation sched;
153  Activity a1{1u,1u};
154  Activity a2{2u,2u};
155  Activity a3{3u,3u};
156  Activity a4{4u,4u};
157 
158  sched.feedPrioritisation ({a1, Time{0,5}});
159  sched.feedPrioritisation ({a2, Time{0,5}});
160  sched.feedPrioritisation ({a3, Time{0,5}});
161  sched.feedPrioritisation ({a4, Time{0,4}});
162  CHECK (isSameObject (*sched.pullHead(), a4));
163  CHECK (isSameObject (*sched.pullHead(), a3));
164  CHECK (isSameObject (*sched.pullHead(), a1));
165  CHECK (isSameObject (*sched.pullHead(), a2));
166  CHECK (not sched.pullHead());
167  }
168 
169 
170 
174  void
176  {
177  SchedulerInvocation sched;
178  Activity a1{1u,1u};
179 
180  sched.feedPrioritisation ({a1, Time{0,5}});
181  CHECK (isSameObject (*sched.peekHead(), a1));
182  CHECK ( sched.isDue (Time{0,10}));
183  CHECK ( sched.isDue (Time{0,5}));
184  CHECK (not sched.isDue (Time{0,1}));
185 
186  sched.pullHead();
187  CHECK (not sched.peekHead());
188  CHECK (not sched.isDue (Time{0,1}));
189  CHECK (not sched.isDue (Time{0,10}));
190  }
191 
192 
193 
204  void
206  {
207  SchedulerInvocation sched;
208  Activity act;
209 
210  sched.feedPrioritisation ({act, Time{2,0}, Time{3,0}});
211  CHECK (Time(2,0) == sched.headTime());
212  CHECK ( sched.isDue (Time{2,0}));
213  CHECK (not sched.isMissed (Time{2,0}));
214  CHECK (not sched.isMissed (Time{3,0}));
215  CHECK ( sched.isMissed (Time{4,0}));
216 
217  CHECK (not sched.isOutdated (Time{2,0}));
218  CHECK (not sched.isOutdated (Time{3,0}));
219  CHECK ( sched.isOutdated (Time{4,0}));
220 
221  sched.feedPrioritisation ({act, Time{1,0}, Time{3,0}, ManifestationID{5}});
222  CHECK (Time(1,0) == sched.headTime());
223  CHECK ( sched.isOutdated (Time{1,0}));
224  CHECK (not sched.isMissed (Time{1,0}));
225 
226  sched.activate (ManifestationID{5});
227  CHECK (Time(1,0) == sched.headTime());
228  CHECK ( sched.isDue (Time{1,0}));
229  CHECK (not sched.isOutdated (Time{1,0}));
230  CHECK (not sched.isOutdated (Time{3,0}));
231  CHECK ( sched.isOutdated (Time{4,0}));
232  CHECK ( sched.isMissed (Time{4,0}));
233  CHECK ( sched.isDue (Time{4,0}));
234 
235  sched.activate (ManifestationID{23});
236  CHECK (not sched.isOutdated (Time{1,0}));
237 
238  sched.drop (ManifestationID{5});
239  CHECK (Time(1,0) == sched.headTime());
240  CHECK ( sched.isOutdated (Time{1,0}));
241  CHECK ( sched.isOutdated (Time{4,0}));
242  CHECK ( sched.isMissed (Time{4,0}));
243  CHECK (not sched.isMissed (Time{1,0}));
244  CHECK ( sched.isDue (Time{1,0}));
245 
246  sched.feedPrioritisation ({act, Time{0,0}, Time{2,0}, ManifestationID{23}, true});
247  CHECK (Time(0,0) == sched.headTime()); // ^^^^ marked as compulsory
248  CHECK (not sched.isMissed (Time{1,0}));
249  CHECK (not sched.isOutdated (Time{1,0}));
250  CHECK (not sched.isOutOfTime(Time{2,0})); // still OK /at/ deadline
251  CHECK ( sched.isOutOfTime(Time{3,0})); // ↯ past deadline yet marked as compulsory
252  CHECK ( sched.isOutdated (Time{3,0}));
253  CHECK ( sched.isMissed (Time{3,0}));
254 
255  sched.drop (ManifestationID{5});
256  CHECK ( sched.isOutOfTime(Time{3,0})); // Manifestation-5 is altogether irrelevant for this case
257 
258  sched.drop (ManifestationID{23});
259  CHECK (Time(0,0) == sched.headTime());
260  CHECK ( sched.isOutdated (Time{1,0}));
261  CHECK (not sched.isOutOfTime(Time{2,0}));
262  CHECK (not sched.isOutOfTime(Time{3,0})); // the disabled manifestation-23 masks the fatal out-of-time state
263  CHECK ( sched.isOutdated (Time{3,0}));
264  CHECK ( sched.isMissed (Time{3,0}));
265 
266  sched.pullHead();
267  CHECK (Time(1,0) == sched.headTime());
268  CHECK ( sched.isOutdated (Time{1,0}));
269  CHECK ( sched.isDue (Time{1,0}));
270 
271  sched.pullHead();
272  CHECK (Time(2,0) == sched.headTime());
273  CHECK (not sched.isOutdated (Time{2,0}));
274  CHECK ( sched.isOutdated (Time{4,0}));
275  CHECK ( sched.isMissed (Time{4,0}));
276  CHECK ( sched.isDue (Time{4,0}));
277 
278  sched.pullHead();
279  CHECK (Time::NEVER == sched.headTime());
280  CHECK (not sched.isMissed (Time{4,0}));
281  CHECK (not sched.isOutdated (Time{4,0}));
282  CHECK (not sched.isDue (Time{4,0}));
283  CHECK (sched.empty());
284  }
285  };
286 
287 
289  LAUNCHER (SchedulerInvocation_test, "unit engine");
290 
291 
292 
293 }}} // namespace vault::gear::test
Record to describe an Activity, to happen within the Scheduler&#39;s control flow.
Definition: activity.hpp:235
Definition: run.hpp:49
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:308
void instruct(ActivationEvent actEvent)
Accept an ActivationEvent with an Activity for time-bound execution.
void activate(ManifestationID manID)
Enable entries marked with a specific ManifestationID to be processed.
Abstract Base Class for all testcases.
Definition: run.hpp:62
Layer-1 of the Scheduler: queueing and prioritisation of activities.
bool isOutdated(Time now) const
determine if Activity at scheduler is outdated and should be discarded
Marker for current (and obsolete) manifestations of a CalcStream processed by the Render-Engine...
Definition: activity.hpp:93
Simple test class runner.
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
bool isMissed(Time now) const
determine if Activity at scheduler head missed it&#39;s deadline
ExampleStrategy::Qualifier two(string additionalArg)
definition of another qualifier two(arg), accepting an additional argument
static const Time NEVER
border condition marker value. NEVER >= any time value
Definition: timevalue.hpp:323
bool isOutOfTime(Time now) const
detect a compulsory Activity at scheduler head with missed deadline
ExampleStrategy::Qualifier one()
definition of a qualifier one()
ActivationEvent pullHead()
Retrieve from the scheduling queue the entry with earliest start time.
void feedPrioritisation()
Pick up all new events from the entrance queue and enqueue them to be retrieved ordered by start time...
Vault-Layer implementation namespace root.
bool isDue(Time now) const
Determine if there is work to do right now.
Scheduler Layer-1 : time based dispatch.
bool isSameObject(A const &a, B const &b)
compare plain object identity, bypassing any custom comparison operators.
Definition: util.hpp:372