From a71bcaae4368a08d9f323f6841176e56ebd818b3 Mon Sep 17 00:00:00 2001 From: Ichthyostega Date: Wed, 25 Oct 2023 23:43:19 +0200 Subject: [PATCH] Scheduler: shorthand notation for work-Function test To cover the visible behaviour of the work-Function, we have to check an amalgam of timing delays and time differences. This kind of test tends to be problematic, since timings are always random and also machine dependent, and thus we need to produce pronounced effects --- src/lib/test/microbenchmark.hpp | 2 +- src/vault/gear/scheduler.hpp | 6 +++ tests/vault/gear/scheduler-service-test.cpp | 54 ++++++++++++++++----- wiki/thinkPad.ichthyo.mm | 23 +++++++++ 4 files changed, 72 insertions(+), 13 deletions(-) diff --git a/src/lib/test/microbenchmark.hpp b/src/lib/test/microbenchmark.hpp index 28b904fec..d733f93d7 100644 --- a/src/lib/test/microbenchmark.hpp +++ b/src/lib/test/microbenchmark.hpp @@ -88,7 +88,7 @@ namespace test{ auto start = system_clock::now(); invokeTestLoop(); Dur duration = system_clock::now () - start; - return duration.count()/(repeatCnt); + return duration.count() / repeatCnt; }; diff --git a/src/vault/gear/scheduler.hpp b/src/vault/gear/scheduler.hpp index 10acbf42e..a861578fa 100644 --- a/src/vault/gear/scheduler.hpp +++ b/src/vault/gear/scheduler.hpp @@ -123,6 +123,12 @@ namespace gear { { } + bool + empty() const + { + return layer1_.empty(); + } + /** * */ diff --git a/tests/vault/gear/scheduler-service-test.cpp b/tests/vault/gear/scheduler-service-test.cpp index 43e3a484b..b2b89ca41 100644 --- a/tests/vault/gear/scheduler-service-test.cpp +++ b/tests/vault/gear/scheduler-service-test.cpp @@ -30,6 +30,7 @@ #include "vault/gear/scheduler.hpp" #include "lib/time/timevalue.hpp" #include "lib/format-cout.hpp" +#include "lib/test/microbenchmark.hpp" #include "lib/test/diagnostic-output.hpp"///////////////TODO //#include "lib/util.hpp" @@ -99,22 +100,51 @@ namespace test { // this test class is declared friend to get a backdoor to Scheduler internals... auto& schedCtx = Scheduler::ExecutionCtx::from(scheduler); - Time now = schedCtx.getSchedTime(); - schedCtx.post (now, &probe, schedCtx); - CHECK (activity::WAIT == scheduler.getWork()); - cout << detector.showLog()<= start + and wasClose (invoked, start); + }; + + TimeVar start = RealClock::now(); + schedCtx.post (start, &probe, schedCtx); +SHOW_EXPR(_raw(start)) +SHOW_EXPR(_raw(detector.invokeTime(probe))) + + CHECK (wasInvoked(start)); + CHECK (scheduler.empty()); + + activity::Proc res; + double delay_us; + int64_t slip_us; + + + auto pullWork = [&] { + uint REPETITIONS = 1; + delay_us = lib::test::benchmarkTime([&]{ res = scheduler.getWork(); }, REPETITIONS); + slip_us = _raw(detector.invokeTime(probe)) - _raw(start); + }; + +// start = RealClock::now(); + pullWork(); + +SHOW_EXPR(_raw(start)) +SHOW_EXPR(_raw(detector.invokeTime(probe))) +SHOW_EXPR(res); +SHOW_EXPR(delay_us) +SHOW_EXPR(slip_us) +SHOW_EXPR(wasInvoked(start)) + CHECK (activity::WAIT == res); + + cout << detector.showLog()< + + + + + + @@ -88208,6 +88214,19 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + + + + + + + + + + + @@ -88220,6 +88239,10 @@ Date:   Thu Apr 20 18:53:17 2023 +0200
+ + + +