70 #ifndef VAULT_GEAR_TEST_ACTIVITY_DETECTOR_H 71 #define VAULT_GEAR_TEST_ACTIVITY_DETECTOR_H 112 const string MARK_INC{
"IncSeq"};
113 const string MARK_SEQ{
"Seq"};
115 using SIG_JobDiagnostic = void(
Time, int32_t);
116 const size_t JOB_ARG_POS_TIME = 0;
118 const string CTX_POST{
"CTX-post"};
119 const string CTX_WORK{
"CTX-work"};
120 const string CTX_DONE{
"CTX-done"};
121 const string CTX_TICK{
"CTX-tick"};
153 operator bool()
const {
return _Parent::operator bool(); }
157 ActivityMatch& beforeInvocation (
string match) {
return delegate (&EventMatch::beforeCall, move(match)); }
161 ActivityMatch& afterInvocation (
string match) {
return delegate (&EventMatch::afterCall, move(match)); }
166 template<
typename...ARGS>
170 return delegate (&EventMatch::arg<ARGS...>, args...);
189 afterSeqIncrement (uint seqNr)
191 _Parent::afterEvent(MARK_INC, util::toString(seqNr));
199 return delegate (&EventMatch::argPos<Time const&>,
size_t(JOB_ARG_POS_TIME), time);
209 template<
typename...ARGS>
214 (this->*fun) (forward<ARGS> (args)...));
238 template<
typename RET,
typename...ARGS>
242 using ImplFun = std::function<RET(ARGS...)>;
254 , seqNr_{&invocationSeqNr}
262 template<
typename VAL>
266 retVal_ = std::forward<VAL> (riggedResponse);
267 return std::move (*
this);
275 implFun_ = std::forward<FUN> (customImpl);
276 return std::move (*
this);
283 operator() (ARGS ...args)
const 286 .
addAttrib (MARK_SEQ, util::toString(*seqNr_));
287 return implFun_? implFun_(std::forward<ARGS>(args)...)
291 operator string()
const 293 return log_->
getID()+
"."+id_;
298 template<
typename SIG>
306 using Type =
typename RebindVariadic<DiagnosticFun, SigTypes>::Type;
320 MockOp mockOperation_;
328 mockOperation_(
Time{
TimeValue{param.nominalTime}}, param.invoKey.part.a);
331 string diagnostic()
const override 333 return "JobFun-"+
string{mockOperation_};
344 : mockOperation_{move (mockedJobOperation)}
362 return reinterpret_cast<Activity*
> (data_.callback.arg);
368 return unConst(
this)->target();
374 ,
void* executionCtx)
override 380 log_(util::toString(now) +
" ⧐ ");
381 return activity::PASS;
386 log_(util::toString(now) +
" ⧐ " + util::toString (*target()));
387 return target()->activate (now, ctx);
394 ,
void* executionCtx)
override 400 log_(util::toString(now) +
" --notify-↯• ");
401 return activity::PASS;
406 log_(util::toString(now) +
" --notify-↯> " + util::toString (*target()));
407 return target()->dispatch (now, ctx);
412 getDeadline()
const override 415 return target()->data_.condition.getDeadline();
421 diagnostic()
const override 423 return "Probe("+
string{log_}+
")";
429 , log_{
id, masterLog, invocationSeqNr}
433 :
Activity{*
this,
reinterpret_cast<size_t> (&subject)}
434 , log_{
id, masterLog, invocationSeqNr}
439 operator string()
const 448 if (act and act->verb_ == HOOK)
452 return probe->invoked_;
461 std::deque<MockJobFunctor> mockOps_{};
462 std::deque<ActivityProbe> mockActs_{};
467 : eventLog_{
"ActivityDetector" + (isnil (
id)?
string{}:
"("+
id+
")")}
471 operator string()
const 473 return util::join (eventLog_);
479 return "\n____Event-Log___________________________\n" 480 + util::join (eventLog_,
"\n")
481 +
"\n────╼━━━━━━━━╾──────────────────────────" 491 eventLog_.
clear (newID);
499 eventLog_.
event (MARK_INC, util::toString(invocationSeq_));
500 return invocationSeq_;
506 return invocationSeq_;
516 template<
typename SIG>
520 using Functor =
typename _DiagnosticFun<SIG>::Type;
521 return Functor{
id, eventLog_, invocationSeq_};
525 buildMockJobFunctor (
string id)
527 return mockOps_.emplace_back (
528 buildDiagnosticFun<SIG_JobDiagnostic> (
id));
532 buildMockJob (
string id =
"" 533 ,
Time nominal = lib::test::randTime()
534 ,
size_t extra = rand())
537 invoKey.part.a = extra;
538 invoKey.part.t = _raw(nominal);
539 return Job{buildMockJobFunctor (isnil(
id)?
"mockJob-"+util::toString(nominal) :
id)
548 return mockActs_.emplace_back (
id, eventLog_, invocationSeq_);
555 return mockActs_.emplace_back (subject
556 ,isnil(
id)?
"tap-"+subject.showVerb()+util::showAddr(subject)
566 wiring = wiring? & buildActivationTap (*wiring,
id)
567 : & buildActivationProbe (isnil(
id)?
"tail-"+util::showAddr(&wiring) :
id);
572 buildGateWatcher (
Activity& gate,
string id =
"")
574 insertActivationTap (gate.
next,
"after-" + (isnil(
id)? gate.showVerb()+util::showAddr(gate) :
id));
575 return buildActivationTap (gate,
id);
579 watchGate (
Activity*& wiring,
string id =
"")
581 wiring = wiring? & buildGateWatcher (*wiring,
id)
582 : & buildActivationProbe (isnil(
id)?
"tail-"+util::showAddr(&wiring) :
id);
587 Time invokeTime (
Activity const* hook) {
return ActivityProbe::lastInvoked (hook); }
588 bool wasInvoked (
Activity const* hook) {
return invokeTime(hook).isRegular(); }
589 Time invokeTime (
Activity const& hook) {
return invokeTime (&hook); }
590 bool wasInvoked (
Activity const& hook) {
return wasInvoked (&hook); }
595 using SIG_work = void(
Time,
size_t);
596 using SIG_done = void(
Time,
size_t);
622 operator string()
const {
return "≺test::CTX≻"; }
630 verifyInvocation (
string fun)
636 ensureNoInvocation (
string fun)
642 verifySeqIncrement (uint seqNr)
static const Time ANYTIME
border condition marker value. ANYTIME <= any time value
DiagnosticFun && returning(VAL &&riggedResponse)
prepare a response value to return from the mock invocation
a mutable time value, behaving like a plain number, allowing copy and re-accessing ...
EventLog & event(string text)
log some text as event
EventMatch & locateCall(string match)
basic search for some specific function invocation
Record to describe an Activity, to happen within the Scheduler's control flow.
DiagnosticFun && implementedAs(FUN &&customImpl)
use the given λ to provide (optional) implementation logic
Generic implementation of a JobFunctor to perform no calculations.
void invokeJobOperation(JobParameter param) override
rigged diagnostic implementation of job invocation
Support for verifying the occurrence of events from unit tests.
Any copy and copy construction prohibited.
Activity & insertActivationTap(Activity *&wiring, string id="")
build ActivationProbe to record each activation before passing it to the subject
Helper to log and verify the occurrence of events.
A rigged CALLBACK-Activity to watch passing of activations.
activity::Proc activation(Activity &thisHook, Time now, void *executionCtx) override
Callback on activation of the corresponding HOOK-Activity.
EventMatch verifyEvent(string match) const
start a query to match for some event.
A Mock functor, logging all invocations into the EventLog.
Lumiera's internal time value datatype.
ItemWrapper & defaultInit()
implant a default-initialised instance of the payload type
EventMatch & attrib(string key, string valueMatch)
refine filter to additionally match on a specific attribute
auto buildDiagnosticFun(string id)
Generic testing helper: build a λ-mock, logging all invocations.
EventMatch verifyCall(string match) const
start a query to match especially a function call
ActivityMatch & seq(uint seqNr)
qualifier: additionally require the indicated sequence number
EventMatch ensureNot(string match) const
start a query to ensure the given expression does not match.
Diagnostic context to record and evaluate activations within the Scheduler.
Metaprogramming tools for transforming functor types.
EventMatch & beforeEvent(string match)
find a match for an "event" after the current point of reference
EventLog & clear()
purge log contents while retaining just the original Header-ID
Extension point to invoke a callback from Activity activation.
ActivityMatch & delegate(_Parent &(_Parent::*fun)(ARGS...), ARGS &&...args)
Tiny helper functions and shortcuts to be used everywhere Consider this header to be effectively incl...
EventLog & call(string target, string function)
Log occurrence of a function call with no arguments.
Activity & buildActivationTap(Activity const &subject, string id="")
build ActivationProbe to record each activation before passing it to the subject
boost::rational< int64_t > FSecs
rational representation of fractional seconds
A collection of frequently used helper functions to support unit testing.
test and diagnostic and research
Activity & buildActivationProbe(string id)
build a rigged HOOK-Activity to record each invocation
uint incrementSeq()
increment the internal invocation sequence number
probe window + count-down; activate next Activity, else re-schedule
Activity * next
Activities are organised into chains to represent relations based on verbs.
EventMatch & id(string classifier)
refine filter to additionally match on the ID attribute
ActivityMatch & beforeSeqIncrement(uint seqNr)
special query to match an increment of the sequence number
Definition of a render job.
opaque ID attached to each individual job invocation.
Basic set of definitions and includes commonly used together (Vault).
static const Time NEVER
border condition marker value. NEVER >= any time value
Interface of the closure for frame rendering jobs.
Offset measures a distance in time.
EventLog & addAttrib(string const &key, X &&initialiser, ARGS &&...args)
Qualify the latest entry: set further attribute(s)
A Mocked job operation to detect any actual invocation.
Mock setup of the execution context for Activity activation.
Proc
Result instruction from Activity activation.
invoke an extension point through the activity::Hook interface
Individual frame rendering task, forwarding to a closure.
ActivityMatch & timeArg(Time const &time)
qualifier: additionally match the nominal time argument of JobFunctor invocation
a family of time value like entities and their relationships.
basic constant internal time value.
Time SCHED_TIME_MARKER
marker value for "current scheduler time" used in tests
ActivityMatch & arg(ARGS const &...args)
qualifier: additionally match the function arguments
Vault-Layer implementation namespace root.
Metaprogramming with type sequences based on variadic template parameters.
activity::Proc notify(Activity &thisHook, Time now, void *executionCtx) override
Callback when dispatching a NOTIFY-Activity to thisHook.
Library implementation: smart-pointer variations, wrappers and managing holders.
string newID(Symbol prefix)
create a random new ID
Stub/Test implementation of the JobFunctor interface for a render job to do nothing at all ...
Descriptor for a piece of operational logic performed by the scheduler.