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)
5  2023, 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 
19 #include "lib/test/run.hpp"
21 #include "lib/util.hpp"
22 
23 using test::Test;
24 using util::isSameObject;
25 
26 
27 namespace vault{
28 namespace gear {
29 namespace test {
30 
31 
32 
33 
34  /********************************************************************/
40  {
41 
42  virtual void
43  run (Arg)
44  {
45  simpleUsage();
50  verify_isDue();
51  }
52 
53 
56  void
58  {
59  SchedulerInvocation sched;
60  Activity activity;
61  Time when{1,2,3};
62  Time dead{2,3,4};
63 
64  CHECK (not sched.peekHead());
65 
66  sched.instruct ({activity, when, dead});
67  sched.feedPrioritisation();
68  CHECK (sched.peekHead());
69 
70  Activity* head = sched.pullHead();
71  CHECK (not sched.peekHead());
72  CHECK (isSameObject (*head, activity));
73  }
74 
75 
76 
81  void
83  {
84  SchedulerInvocation sched;
85  Activity one{1u,1u};
86  Activity two{2u,2u};
87  Activity wee{3u,3u};
88  Time t{5,5};
89 
90  sched.instruct ({one, t});
91  sched.instruct ({two, t});
92  sched.instruct ({wee, t});
93  CHECK (not sched.peekHead());
94 
95  sched.feedPrioritisation();
96  CHECK (isSameObject (*sched.pullHead(), one));
97  CHECK (isSameObject (*sched.pullHead(), two));
98  CHECK (isSameObject (*sched.pullHead(), wee));
99  CHECK (not sched.peekHead());
100  CHECK (sched.empty());
101  }
102 
103 
104 
110  void
112  {
113  SchedulerInvocation sched;
114  Activity a1{1u,1u};
115  Activity a2{2u,2u};
116  Activity a3{3u,3u};
117  Activity a4{4u,4u};
118 
119  sched.instruct ({a2, Time{2,0}});
120  sched.instruct ({a4, Time{4,0}});
121  sched.feedPrioritisation();
122  CHECK (isSameObject (*sched.peekHead(), a2));
123 
124  sched.instruct ({a3, Time{3,0}});
125  sched.instruct ({a1, Time{1,0}});
126  CHECK (isSameObject (*sched.peekHead(), a2));
127 
128  sched.feedPrioritisation();
129  CHECK (isSameObject (*sched.pullHead(), a1));
130  CHECK (isSameObject (*sched.pullHead(), a2));
131  CHECK (isSameObject (*sched.pullHead(), a3));
132  CHECK (isSameObject (*sched.pullHead(), a4));
133  }
134 
135 
136 
140  void
142  {
143  SchedulerInvocation sched;
144  Activity a1{1u,1u};
145  Activity a2{2u,2u};
146  Activity a3{3u,3u};
147  Activity a4{4u,4u};
148 
149  sched.feedPrioritisation ({a1, Time{0,5}});
150  sched.feedPrioritisation ({a2, Time{0,5}});
151  sched.feedPrioritisation ({a3, Time{0,5}});
152  sched.feedPrioritisation ({a4, Time{0,4}});
153  CHECK (isSameObject (*sched.pullHead(), a4));
154  CHECK (isSameObject (*sched.pullHead(), a3));
155  CHECK (isSameObject (*sched.pullHead(), a1));
156  CHECK (isSameObject (*sched.pullHead(), a2));
157  CHECK (not sched.pullHead());
158  }
159 
160 
161 
165  void
167  {
168  SchedulerInvocation sched;
169  Activity a1{1u,1u};
170 
171  sched.feedPrioritisation ({a1, Time{0,5}});
172  CHECK (isSameObject (*sched.peekHead(), a1));
173  CHECK ( sched.isDue (Time{0,10}));
174  CHECK ( sched.isDue (Time{0,5}));
175  CHECK (not sched.isDue (Time{0,1}));
176 
177  sched.pullHead();
178  CHECK (not sched.peekHead());
179  CHECK (not sched.isDue (Time{0,1}));
180  CHECK (not sched.isDue (Time{0,10}));
181  }
182 
183 
184 
195  void
197  {
198  SchedulerInvocation sched;
199  Activity act;
200 
201  sched.feedPrioritisation ({act, Time{2,0}, Time{3,0}});
202  CHECK (Time(2,0) == sched.headTime());
203  CHECK ( sched.isDue (Time{2,0}));
204  CHECK (not sched.isMissed (Time{2,0}));
205  CHECK (not sched.isMissed (Time{3,0}));
206  CHECK ( sched.isMissed (Time{4,0}));
207 
208  CHECK (not sched.isOutdated (Time{2,0}));
209  CHECK (not sched.isOutdated (Time{3,0}));
210  CHECK ( sched.isOutdated (Time{4,0}));
211 
212  sched.feedPrioritisation ({act, Time{1,0}, Time{3,0}, ManifestationID{5}});
213  CHECK (Time(1,0) == sched.headTime());
214  CHECK ( sched.isOutdated (Time{1,0}));
215  CHECK (not sched.isMissed (Time{1,0}));
216 
217  sched.activate (ManifestationID{5});
218  CHECK (Time(1,0) == sched.headTime());
219  CHECK ( sched.isDue (Time{1,0}));
220  CHECK (not sched.isOutdated (Time{1,0}));
221  CHECK (not sched.isOutdated (Time{3,0}));
222  CHECK ( sched.isOutdated (Time{4,0}));
223  CHECK ( sched.isMissed (Time{4,0}));
224  CHECK ( sched.isDue (Time{4,0}));
225 
226  sched.activate (ManifestationID{23});
227  CHECK (not sched.isOutdated (Time{1,0}));
228 
229  sched.drop (ManifestationID{5});
230  CHECK (Time(1,0) == sched.headTime());
231  CHECK ( sched.isOutdated (Time{1,0}));
232  CHECK ( sched.isOutdated (Time{4,0}));
233  CHECK ( sched.isMissed (Time{4,0}));
234  CHECK (not sched.isMissed (Time{1,0}));
235  CHECK ( sched.isDue (Time{1,0}));
236 
237  sched.feedPrioritisation ({act, Time{0,0}, Time{2,0}, ManifestationID{23}, true});
238  CHECK (Time(0,0) == sched.headTime()); // ^^^^ marked as compulsory
239  CHECK (not sched.isMissed (Time{1,0}));
240  CHECK (not sched.isOutdated (Time{1,0}));
241  CHECK (not sched.isOutOfTime(Time{2,0})); // still OK /at/ deadline
242  CHECK ( sched.isOutOfTime(Time{3,0})); // ↯ past deadline yet marked as compulsory
243  CHECK ( sched.isOutdated (Time{3,0}));
244  CHECK ( sched.isMissed (Time{3,0}));
245 
246  sched.drop (ManifestationID{5});
247  CHECK ( sched.isOutOfTime(Time{3,0})); // Manifestation-5 is altogether irrelevant for this case
248 
249  sched.drop (ManifestationID{23});
250  CHECK (Time(0,0) == sched.headTime());
251  CHECK ( sched.isOutdated (Time{1,0}));
252  CHECK (not sched.isOutOfTime(Time{2,0}));
253  CHECK (not sched.isOutOfTime(Time{3,0})); // the disabled manifestation-23 masks the fatal out-of-time state
254  CHECK ( sched.isOutdated (Time{3,0}));
255  CHECK ( sched.isMissed (Time{3,0}));
256 
257  sched.pullHead();
258  CHECK (Time(1,0) == sched.headTime());
259  CHECK ( sched.isOutdated (Time{1,0}));
260  CHECK ( sched.isDue (Time{1,0}));
261 
262  sched.pullHead();
263  CHECK (Time(2,0) == sched.headTime());
264  CHECK (not sched.isOutdated (Time{2,0}));
265  CHECK ( sched.isOutdated (Time{4,0}));
266  CHECK ( sched.isMissed (Time{4,0}));
267  CHECK ( sched.isDue (Time{4,0}));
268 
269  sched.pullHead();
270  CHECK (Time::NEVER == sched.headTime());
271  CHECK (not sched.isMissed (Time{4,0}));
272  CHECK (not sched.isOutdated (Time{4,0}));
273  CHECK (not sched.isDue (Time{4,0}));
274  CHECK (sched.empty());
275  }
276  };
277 
278 
280  LAUNCHER (SchedulerInvocation_test, "unit engine");
281 
282 
283 
284 }}} // namespace vault::gear::test
Record to describe an Activity, to happen within the Scheduler&#39;s control flow.
Definition: activity.hpp:226
Definition: run.hpp:40
Lumiera&#39;s internal time value datatype.
Definition: timevalue.hpp:299
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:53
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:84
Simplistic 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 the 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:314
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, based directly on the referee&#39;s memory identities. ...
Definition: util.hpp:421