The EventLog seems to provide all the building blocks, but we need some higher level special matchers (and maybe we also want to hide some of the basic EventLog matchers). A soulution might be to wrap the EventMatcher and delegate all follow-up builder calls. This seems adequate, since the EventLog-Matcher is basically used as black box, building up more elaborate matchers from the provided basic matchers... Spent some time again to understand how EventLog matching works. My feelings towards this piece of code are always the same: it is somewhat too "tricky", but I am not aware of any other technique to get this degree of elaborate chained matching on structured records, short of building a dedicated matching engine from scratch. The other alternative would be to use a flat textual log (instead of the structured log records from EventLog), but then we'd have to generate quite intricate regular expressions from the builder, and I'm really doubtful it would be easier and clearer....
159 lines
4.4 KiB
C++
159 lines
4.4 KiB
C++
/*
|
|
ActivityDetector(Test) - verify diagnostic setup to watch scheduler activities
|
|
|
|
Copyright (C) Lumiera.org
|
|
2023, Hermann Vosseler <Ichthyostega@web.de>
|
|
|
|
This program is free software; you can redistribute it and/or
|
|
modify it under the terms of the GNU General Public License as
|
|
published by the Free Software Foundation; either version 2 of
|
|
the License, or (at your option) any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
* *****************************************************/
|
|
|
|
/** @file activity-detector-test.cpp
|
|
** unit test \ref ActivityDetector_test
|
|
*/
|
|
|
|
|
|
#include "lib/test/run.hpp"
|
|
#include "activity-detector.hpp"
|
|
#include "lib/test/test-helper.hpp"
|
|
#include "lib/time/timevalue.hpp"
|
|
//#include "lib/format-cout.hpp"
|
|
//#include "lib/util.hpp"
|
|
|
|
//#include <utility>
|
|
|
|
//using test::Test;
|
|
//using lib::time::Time;
|
|
//using lib::time::FSecs;
|
|
//using std::move;
|
|
//using util::isSameObject;
|
|
|
|
|
|
namespace vault{
|
|
namespace gear {
|
|
namespace test {
|
|
|
|
// using lib::time::FrameRate;
|
|
// using lib::time::Offset;
|
|
using lib::time::Time;
|
|
using lib::time::FSecs;
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************//**
|
|
* @test verify instrumentation setup to watch scheduler Activities.
|
|
* @see SchedulerActivity_test
|
|
* @see SchedulerUsage_test
|
|
*/
|
|
class ActivityDetector_test : public Test
|
|
{
|
|
|
|
virtual void
|
|
run (Arg)
|
|
{
|
|
simpleUsage();
|
|
|
|
verifyMockInvocation();
|
|
verifyDummyJobFunctor();
|
|
detect_activation();
|
|
detect_gate();
|
|
}
|
|
|
|
|
|
/** @test TODO demonstrate a simple usage scenario
|
|
* @todo WIP 7/23 🔁 define 🔁 implement
|
|
*/
|
|
void
|
|
simpleUsage()
|
|
{
|
|
ActivityDetector detector("spectre");
|
|
|
|
auto trap = detector.buildDiagnosticFun<int(double,Time)>("trap")
|
|
.returning(55);
|
|
|
|
CHECK (55 == trap (1.23, Time{FSecs{3,2}}));
|
|
|
|
CHECK (detector == "Rec(EventLogHeader| this = ActivityDetector(spectre) ), "
|
|
"Rec(call| fun = trap, this = ActivityDetector(spectre) |{1.23, 0:00:01.500})"_expect);
|
|
}
|
|
|
|
|
|
|
|
/** @test verify the setup and detection of instrumented invocations
|
|
* @todo WIP 7/23 ✔ define 🔁 implement
|
|
*/
|
|
void
|
|
verifyMockInvocation()
|
|
{
|
|
ActivityDetector detector;
|
|
auto fun = detector.buildDiagnosticFun<void(uint)>("funny");
|
|
uint rnd = rand() % 10000;
|
|
|
|
++detector;
|
|
CHECK (1 == detector.currSeq());
|
|
CHECK (not detector.verifyInvocation ("funny"));
|
|
|
|
detector.markSequence();
|
|
fun(rnd);
|
|
CHECK (detector.verifyCall ("funny"));
|
|
CHECK (detector.verifyCall ("funny").arg(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
|
|
verifyDummyJobFunctor()
|
|
{
|
|
}
|
|
|
|
|
|
|
|
/** @test TODO diagnostic setup to detect Activity activation and propagation
|
|
* @todo WIP 7/23 ⟶ define ⟶ implement
|
|
*/
|
|
void
|
|
detect_activation()
|
|
{
|
|
}
|
|
|
|
|
|
|
|
/** @test TODO diagnostic setup to watch Activity::GATE activation
|
|
* @todo WIP 7/23 ⟶ define ⟶ implement
|
|
*/
|
|
void
|
|
detect_gate()
|
|
{
|
|
}
|
|
};
|
|
|
|
|
|
/** Register this test class... */
|
|
LAUNCHER (ActivityDetector_test, "unit engine");
|
|
|
|
|
|
|
|
}}} // namespace vault::gear::test
|