@@ -33,27 +33,38 @@ struct TaskWithMetaData {
3333// / UB.
3434template <typename T>
3535concept StrategyTaskVerifier = requires (T a) {
36- // --- New API for workload policies (Reserve rules etc.) ---
37- { a.OnRoundStart (size_t ()) } -> std::same_as<void >;
36+ { a.Verify (std::declval<const std::string&>(), size_t ()) } -> std::same_as<bool >;
37+ { a.OnFinished (std::declval<Task&>(), size_t ()) } -> std::same_as<void >;
38+ { a.ReleaseTask (size_t ()) } -> std::same_as<std::optional<std::string>>;
39+ };
3840
39- {
40- a.OnTaskStarted (std::declval<const std::string&>(), size_t (), int ())
41- } -> std::same_as<void >;
41+ namespace ltest ::verifier_hooks {
4242
43- {
44- a.VerifyStart (std::declval<const std::string&>(), size_t (),
45- std::declval<const ltest::StartContext&>())
46- } -> std::same_as<bool >;
43+ template <class V >
44+ void OnRoundStart (V& v, std::size_t threads) {
45+ if constexpr (requires { v.OnRoundStart (threads); }) {
46+ v.OnRoundStart (threads);
47+ }
48+ }
4749
48- // --- Existing API (protocol constraints / UB-prevention) ---
49- {
50- a.Verify (std::declval<const std::string&>(), size_t ())
51- } -> std::same_as<bool >;
50+ template <class V >
51+ void OnTaskStarted (V& v, const std::string& method, std::size_t thread_id, int task_id) {
52+ if constexpr (requires { v.OnTaskStarted (method, thread_id, task_id); }) {
53+ v.OnTaskStarted (method, thread_id, task_id);
54+ }
55+ }
5256
53- { a.OnFinished (std::declval<Task&>(), size_t ()) } -> std::same_as<void >;
57+ template <class V >
58+ bool VerifyStart (V& v, const std::string& method, std::size_t thread_id,
59+ const ltest::StartContext& ctx) {
60+ if constexpr (requires { v.VerifyStart (method, thread_id, ctx); }) {
61+ return v.VerifyStart (method, thread_id, ctx);
62+ } else {
63+ return v.Verify (method, thread_id);
64+ }
65+ }
5466
55- { a.ReleaseTask (size_t ()) } -> std::same_as<std::optional<std::string>>;
56- };
67+ } // namespace ltest::verifier_hooks
5768
5869// Strategy is the general strategy interface which decides which task
5970// will be the next one it can be implemented by different strategies, such as:
@@ -147,7 +158,7 @@ struct BaseStrategyWithThreads : public Strategy {
147158 std::random_device dev;
148159 rng = std::mt19937 (dev ());
149160
150- sched_checker. OnRoundStart (threads_count);
161+ ltest::verifier_hooks:: OnRoundStart (sched_checker, threads_count);
151162 }
152163
153164 std::optional<std::tuple<Task&, int >> GetTask (int task_id) override {
@@ -258,7 +269,7 @@ struct BaseStrategyWithThreads : public Strategy {
258269 for (size_t i = 0 ; i < this ->constructors .size (); ++i) {
259270 const TaskBuilder& constructor = this ->constructors .at (i);
260271
261- if (this -> sched_checker . VerifyStart (constructor.GetName (), thread_index,
272+ if (ltest::verifier_hooks:: VerifyStart (sched_checker, constructor.GetName (), thread_index,
262273 ctx) &&
263274 this ->sched_checker .Verify (constructor.GetName (), thread_index)) {
264275 verified_constructor = i;
@@ -275,7 +286,7 @@ struct BaseStrategyWithThreads : public Strategy {
275286
276287 Task task =
277288 chosen.Build (this ->state .get (), thread_index, this ->new_task_id ++);
278- this -> sched_checker . OnTaskStarted (method_name, thread_index,
289+ ltest::verifier_hooks:: OnTaskStarted (sched_checker, method_name, thread_index,
279290 task->GetId ());
280291
281292 threads[thread_index].emplace_back (std::move (task));
0 commit comments