diff --git a/src/lib/format-util.hpp b/src/lib/format-util.hpp index 3d84cf024..77940543d 100644 --- a/src/lib/format-util.hpp +++ b/src/lib/format-util.hpp @@ -215,5 +215,14 @@ namespace util { } + /** shortcut: List in parentheses, separated by comma, using temporary vector */ + template + inline string + joinArgList (ARGS const& ...args) + { + return "("+join (stringify> (args...))+")"; + } + + } // namespace util #endif /*LIB_FORMAT_UTIL_H*/ diff --git a/tests/vault/gear/activity-detector-test.cpp b/tests/vault/gear/activity-detector-test.cpp index b0e48063c..2e27279b3 100644 --- a/tests/vault/gear/activity-detector-test.cpp +++ b/tests/vault/gear/activity-detector-test.cpp @@ -67,7 +67,8 @@ namespace test { { simpleUsage(); - verifyDummyFuncttor(); + verifyMockInvocation(); + verifyDummyJobFunctor(); detect_activation(); detect_gate(); } @@ -92,11 +93,40 @@ namespace test { + /** @test verify the setup and detection of instrumented invocations + * @todo WIP 7/23 ⟶ define ⟶ implement + */ + void + verifyMockInvocation() + { + ActivityDetector detector; + auto fun = detector.buildDiagnosticFun("funny"); + uint rnd = rand() % 10000; + + ++detector; + CHECK (1 == detector.currSeq()); + CHECK (not detector.verifyInvocation ("funny")); + + detector.markSequence(); + fun(rnd); + detector.markSequence(); + CHECK (detector.verifyInvocation ("funny")); + CHECK (detector.verifyInvocation ("funny", rnd)); + CHECK (detector.verifyInvocation ("funny", Seq(1))); + CHECK (detector.verifyInvocation ("funny", Seq(1), rnd)); + CHECK (not detector.verifyInvocation ("bunny")); + CHECK (not detector.verifyInvocation ("funny", -rnd)); + CHECK (not detector.verifyInvocation ("funny", Seq(5))); + CHECK (not detector.verifyInvocation ("funny", rnd, Seq(1))); + } + + + /** @test TODO diagnostic setup to detect a JobFunctor activation * @todo WIP 7/23 ⟶ define ⟶ implement */ void - verifyDummyFuncttor() + verifyDummyJobFunctor() { } diff --git a/tests/vault/gear/activity-detector.hpp b/tests/vault/gear/activity-detector.hpp index 73a41be24..d2833df13 100644 --- a/tests/vault/gear/activity-detector.hpp +++ b/tests/vault/gear/activity-detector.hpp @@ -62,6 +62,7 @@ //#include "lib/linked-elements.hpp" #include "lib/meta/variadic-helper.hpp" #include "lib/wrapper.hpp" +#include "lib/format-cout.hpp" #include "lib/format-util.hpp" //#include "lib/itertools.hpp" //#include "lib/depend.hpp" @@ -94,6 +95,45 @@ namespace test { // using vault::gear::JobClosure; + /** Marker for invocation sequence */ + class Seq + { + uint step_; + + public: + Seq (uint start =0) + : step_{start} + { } + + operator uint() const + { + return step_; + } + operator string() const + { + return util::toString (step_); + } + + uint + operator++() + { + ++step_; + return step_; + } + + bool + operator== (Seq const& o) + { + return step_ == o.step_; + } + }; + + + namespace {// Event markers + const string MARK_INC{"Inc"}; + const string MARK_SEQ{"Seq"}; + } + /** * Diagnostic context to record and evaluate activations within the Scheduler. @@ -105,6 +145,7 @@ namespace test { using EventLog = lib::test::EventLog; EventLog eventLog_; + Seq invocationSeq_; /** * A Mock functor, logging all invocations into the EventLog @@ -126,10 +167,11 @@ namespace test { { } /** prepare a response value to return from the mock invocation */ + template DiagnosticFun&& - returning (RET&& riggedResponse) + returning (VAL&& riggedResponse) { - retVal_ = std::forward (riggedResponse); + retVal_ = std::forward (riggedResponse); return std::move (*this); } @@ -144,8 +186,9 @@ namespace test { public: - ActivityDetector(string id) + ActivityDetector(string id ="") : eventLog_{"ActivityDetector" + (isnil (id)? string{}: "("+id+")")} + , invocationSeq_{0} { } operator string() const @@ -162,6 +205,28 @@ namespace test { eventLog_.clear (newID); } + uint + operator++() + { + ++invocationSeq_; + eventLog_.event (MARK_INC, invocationSeq_); + return invocationSeq_; + } + + uint + currSeq() const + { + return invocationSeq_; + } + + uint + markSequence() + { + eventLog_.event (MARK_SEQ, invocationSeq_); + return operator++(); + } + + /** * Generic testing helper: build a λ-mock, logging all invocations * @tparam SIG signature of the functor to be generated @@ -181,6 +246,36 @@ namespace test { return Functor{id, eventLog_}; } + template + bool + verifyInvocation (string fun, Seq const& seq, ARGS const& ...args) + { + bool valid = eventLog_.verifyEvent(seq).id(MARK_INC) + .beforeCall(fun).arg(args...) + .beforeEvent(seq).id(MARK_SEQ); + if (not valid) + { + cerr << "FAIL___Function_invocation___________" + << "\nfunction:"< + bool + verifyInvocation (string fun, ARGS const& ...args) + { + Seq currentEventSeq = invocationSeq_; + markSequence(); // NOTE: incrementing here + return verifyInvocation (fun, currentEventSeq, args...); + } + + private: }; diff --git a/wiki/thinkPad.ichthyo.mm b/wiki/thinkPad.ichthyo.mm index 808ec20c1..ce8a21eb1 100644 --- a/wiki/thinkPad.ichthyo.mm +++ b/wiki/thinkPad.ichthyo.mm @@ -81700,7 +81700,7 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
- + @@ -81713,9 +81713,49 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + +

+ geht leider nicht anders, weil ich mich für eine generische (concept-artige) Form des Execution-context entschieden habe; eine virtuelle Methode kann selber kein Template sein, und andererseits möchte ich den Activity-Record selber template-frei halten +

+ +
+ +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + +