61 #ifndef VAULT_GEAR_TEST_ACTIVITY_DETECTOR_H 62 #define VAULT_GEAR_TEST_ACTIVITY_DETECTOR_H 105 const string MARK_INC{
"IncSeq"};
106 const string MARK_SEQ{
"Seq"};
108 using SIG_JobDiagnostic = void(
Time, int32_t);
109 const size_t JOB_ARG_POS_TIME = 0;
111 const string CTX_POST{
"CTX-post"};
112 const string CTX_WORK{
"CTX-work"};
113 const string CTX_DONE{
"CTX-done"};
114 const string CTX_TICK{
"CTX-tick"};
146 operator bool()
const {
return _Parent::operator bool(); }
150 ActivityMatch& beforeInvocation (
string match) {
return delegate (&EventMatch::beforeCall, move(match)); }
154 ActivityMatch& afterInvocation (
string match) {
return delegate (&EventMatch::afterCall, move(match)); }
159 template<
typename...ARGS>
163 return delegate (&EventMatch::arg<ARGS...>, args...);
182 afterSeqIncrement (uint seqNr)
184 _Parent::afterEvent(MARK_INC, util::toString(seqNr));
192 return delegate (&EventMatch::argPos<Time const&>,
size_t(JOB_ARG_POS_TIME), time);
202 template<
typename...ARGS>
207 (this->*fun) (forward<ARGS> (args)...));
231 template<
typename RET,
typename...ARGS>
235 using ImplFun = std::function<RET(ARGS...)>;
247 , seqNr_{&invocationSeqNr}
255 template<
typename VAL>
259 retVal_ = std::forward<VAL> (riggedResponse);
260 return std::move (*
this);
268 implFun_ = std::forward<FUN> (customImpl);
269 return std::move (*
this);
276 operator() (ARGS ...args)
const 279 .
addAttrib (MARK_SEQ, util::toString(*seqNr_));
280 return implFun_? implFun_(std::forward<ARGS>(args)...)
284 operator string()
const 286 return log_->
getID()+
"."+id_;
291 template<
typename SIG>
299 using Type =
typename RebindVariadic<DiagnosticFun, SigTypes>::Type;
313 MockOp mockOperation_;
321 mockOperation_(
Time{
TimeValue{param.nominalTime}}, param.invoKey.part.a);
324 string diagnostic()
const override 326 return "JobFun-"+
string{mockOperation_};
337 : mockOperation_{move (mockedJobOperation)}
355 return reinterpret_cast<Activity*
> (data_.callback.arg);
361 return unConst(
this)->target();
367 ,
void* executionCtx)
override 373 log_(util::toString(now) +
" ⧐ ");
374 return activity::PASS;
379 log_(util::toString(now) +
" ⧐ " + util::toString (*target()));
380 return target()->activate (now, ctx);
387 ,
void* executionCtx)
override 393 log_(util::toString(now) +
" --notify-↯• ");
394 return activity::PASS;
399 log_(util::toString(now) +
" --notify-↯> " + util::toString (*target()));
400 return target()->dispatch (now, ctx);
405 getDeadline()
const override 408 return target()->data_.condition.getDeadline();
414 diagnostic()
const override 416 return "Probe("+
string{log_}+
")";
422 , log_{
id, masterLog, invocationSeqNr}
426 :
Activity{*
this,
reinterpret_cast<size_t> (&subject)}
427 , log_{
id, masterLog, invocationSeqNr}
432 operator string()
const 441 if (act and act->verb_ == HOOK)
445 return probe->invoked_;
454 std::deque<MockJobFunctor> mockOps_{};
455 std::deque<ActivityProbe> mockActs_{};
460 : eventLog_{
"ActivityDetector" + (isnil (
id)?
string{}:
"("+
id+
")")}
464 operator string()
const 466 return util::join (eventLog_);
472 return "\n____Event-Log___________________________\n" 473 + util::join (eventLog_,
"\n")
474 +
"\n────╼━━━━━━━━╾──────────────────────────" 484 eventLog_.
clear (newID);
492 eventLog_.
event (MARK_INC, util::toString(invocationSeq_));
493 return invocationSeq_;
499 return invocationSeq_;
509 template<
typename SIG>
513 using Functor =
typename _DiagnosticFun<SIG>::Type;
514 return Functor{
id, eventLog_, invocationSeq_};
518 buildMockJobFunctor (
string id)
520 return mockOps_.emplace_back (
521 buildDiagnosticFun<SIG_JobDiagnostic> (
id));
525 buildMockJob (
string id =
"" 526 ,
Time nominal = lib::test::randTime()
527 ,
size_t extra =
rani())
530 invoKey.part.a = extra;
531 invoKey.part.t = _raw(nominal);
532 return Job{buildMockJobFunctor (isnil(
id)?
"mockJob-"+util::toString(nominal) :
id)
541 return mockActs_.emplace_back (
id, eventLog_, invocationSeq_);
548 return mockActs_.emplace_back (subject
549 ,isnil(
id)?
"tap-"+subject.showVerb()+util::showAdr(subject)
559 wiring = wiring? & buildActivationTap (*wiring,
id)
560 : & buildActivationProbe (isnil(
id)?
"tail-"+util::showAdr(&wiring) :
id);
565 buildGateWatcher (
Activity& gate,
string id =
"")
567 insertActivationTap (gate.
next,
"after-" + (isnil(
id)? gate.showVerb()+util::showAdr(gate) :
id));
568 return buildActivationTap (gate,
id);
572 watchGate (
Activity*& wiring,
string id =
"")
574 wiring = wiring? & buildGateWatcher (*wiring,
id)
575 : & buildActivationProbe (isnil(
id)?
"tail-"+util::showAdr(&wiring) :
id);
580 Time invokeTime (
Activity const* hook) {
return ActivityProbe::lastInvoked (hook); }
581 bool wasInvoked (
Activity const* hook) {
return invokeTime(hook).isRegular(); }
582 Time invokeTime (
Activity const& hook) {
return invokeTime (&hook); }
583 bool wasInvoked (
Activity const& hook) {
return wasInvoked (&hook); }
588 using SIG_work = void(
Time,
size_t);
589 using SIG_done = void(
Time,
size_t);
615 operator string()
const {
return "≺test::CTX≻"; }
623 verifyInvocation (
string fun)
629 ensureNoInvocation (
string fun)
635 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.
int rani(uint bound=_iBOUND())
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)
Generating (pseudo) random numbers with controlled seed.
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.