From 3784bd725292fd0b3848ea61bebf7fd15ec841fc Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Fri, 18 Aug 2023 19:37:44 +0200 Subject: [PATCH] Activity-Lang: build activation detector ...using a HOOK-Activity as prepended adaptor, optionally forwarding the activation to the inferior --- src/vault/gear/activity.hpp | 11 ++++ tests/vault/gear/activity-detector-test.cpp | 12 +++- tests/vault/gear/activity-detector.hpp | 64 +++++++++++++++++++++ wiki/thinkPad.ichthyo.mm | 35 ++++++++++- 4 files changed, 118 insertions(+), 4 deletions(-) diff --git a/src/vault/gear/activity.hpp b/src/vault/gear/activity.hpp index 6f00984cf..34a301128 100644 --- a/src/vault/gear/activity.hpp +++ b/src/vault/gear/activity.hpp @@ -136,6 +136,17 @@ namespace gear { virtual Proc activation ( Activity& thisHook , Time now , void* executionCtx) =0; + + virtual std::string + diagnostic() const + { + return "Activity::Hook"; + } + + operator std::string() const + { + return diagnostic(); + } }; diff --git a/tests/vault/gear/activity-detector-test.cpp b/tests/vault/gear/activity-detector-test.cpp index b6d7029b3..bef69f0b9 100644 --- a/tests/vault/gear/activity-detector-test.cpp +++ b/tests/vault/gear/activity-detector-test.cpp @@ -29,7 +29,7 @@ #include "activity-detector.hpp" #include "lib/test/test-helper.hpp" #include "lib/time/timevalue.hpp" -#include "lib/format-cout.hpp" +#include "lib/format-cout.hpp" /////////////////////////////TODO //#include "lib/util.hpp" //#include @@ -39,6 +39,8 @@ //using lib::time::FSecs; //using std::move; //using util::isSameObject; +using lib::test::randStr; +using lib::test::randTime; namespace vault{ @@ -193,7 +195,7 @@ namespace test { // an otherwise opaque object fulfilling the "Concept" activity::_verify_usable_as_ExecutionContext(); - Time t = lib::test::randTime(); + Time t = randTime(); size_t x = rand(); Activity a; @@ -229,11 +231,15 @@ namespace test { /** @test TODO diagnostic setup to detect Activity activation and propagation - * @todo WIP 8/23 🔁 define ⟶ implement + * @todo WIP 8/23 🔁 define 🔁 implement */ void detect_activation() { + auto someID = "trap-" + randStr(4); + ActivityDetector detector; + Activity& probe = detector.buildActivationProbe (someID); + cout << probe << endl; } diff --git a/tests/vault/gear/activity-detector.hpp b/tests/vault/gear/activity-detector.hpp index a2282e970..9d74d50e8 100644 --- a/tests/vault/gear/activity-detector.hpp +++ b/tests/vault/gear/activity-detector.hpp @@ -285,6 +285,8 @@ namespace test { return std::move (*this); } + // default copyable + /** mock function call operator: logs all invocations */ RET operator() (ARGS ...args) @@ -293,6 +295,11 @@ namespace test { .addAttrib (MARK_SEQ, util::toString(*seqNr_)); return *retVal_; } + + operator string() const + { + return log_->getID()+"."+id_; + } }; /** @internal type rebinding helper */ @@ -307,6 +314,8 @@ namespace test { using Type = typename RebindVariadic::Type; }; + using Logger = _DiagnosticFun::Type; + /** * A Mocked job operation to detect any actual invocation @@ -334,9 +343,59 @@ namespace test { }; + /** + * A rigged CALLBACK-Activity to watch passing of activations. + */ + class ActivityProbe + : public Activity + , activity::Hook + { + Logger log_; + + activity::Proc + activation ( Activity& thisHook + , Time now + , void* executionCtx) override + { + REQUIRE (Activity::HOOK == thisHook.verb_); + if (data_.callback.arg == 0) + {// no adapted target; just record this activation + log_(util::toString(now) + " ⧐ "); + return activity::PASS; + } + else + {// forward activation to the adapted target Activity + Activity& target = *reinterpret_cast (data_.callback.arg); + auto ctx = *static_cast (executionCtx); + log_(util::toString(now) + " ⧐ " + util::toString (target)); + return target.activate (now, ctx); + } + } + + std::string + diagnostic() const override + { + return "Probe("+string{log_}+")"; + } + + public: + explicit + ActivityProbe (string id, EventLog& masterLog, uint const& invocationSeqNr) + : Activity{*this, 0} + , log_{id, masterLog, invocationSeqNr} + { } + + operator string() const + { + return diagnostic(); + } + }; + + /* ===== Maintain throw-away mock instances ===== */ std::deque mockOps_{}; + std::deque mockActs_{}; public: @@ -405,6 +464,11 @@ namespace test { buildDiagnosticFun (id)); } + Activity& + buildActivationProbe (string id) + { + return mockActs_.emplace_back (id, eventLog_, invocationSeq_); + } struct FakeExecutionCtx; diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index a8960876e..abb0fea26 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -82173,8 +82173,41 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +