From 3bdaba42877a1523cc6beda4f6a9de56fcc53d1c Mon Sep 17 00:00:00 2001 From: FritzFlorian Date: Wed, 5 Jun 2019 11:44:34 +0200 Subject: [PATCH] Adapt tests to new fork-join model. --- lib/pls/include/pls/internal/scheduling/task.h | 6 +++--- test/CMakeLists.txt | 3 ++- test/scheduling_tests.cpp | 14 ++++++-------- 3 files changed, 11 insertions(+), 12 deletions(-) diff --git a/lib/pls/include/pls/internal/scheduling/task.h b/lib/pls/include/pls/internal/scheduling/task.h index b11ec5f..d2bada3 100644 --- a/lib/pls/include/pls/internal/scheduling/task.h +++ b/lib/pls/include/pls/internal/scheduling/task.h @@ -34,7 +34,7 @@ class task { virtual void execute_internal() = 0; template - void spawn_child(T &sub_task); + void spawn_child(T &&sub_task); void wait_for_all(); private: @@ -42,9 +42,9 @@ class task { }; template -void task::spawn_child(T &sub_task) { +void task::spawn_child(T &&sub_task) { PROFILE_FORK_JOIN_STEALING("spawn_child") - static_assert(std::is_base_of::value, "Only pass task subclasses!"); + static_assert(std::is_base_of::type>::value, "Only pass task subclasses!"); // Keep our refcount up to date ref_count_++; diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 7f224a1..416b530 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,4 +1,5 @@ add_executable(tests main.cpp - data_structures_test.cpp) + data_structures_test.cpp + scheduling_tests.cpp) target_link_libraries(tests catch2 pls) diff --git a/test/scheduling_tests.cpp b/test/scheduling_tests.cpp index a442abd..d99be04 100644 --- a/test/scheduling_tests.cpp +++ b/test/scheduling_tests.cpp @@ -4,7 +4,7 @@ using namespace pls; -class once_sub_task : public fork_join_sub_task { +class once_sub_task : public task { std::atomic *counter_; int children_; @@ -18,12 +18,12 @@ class once_sub_task : public fork_join_sub_task { public: explicit once_sub_task(std::atomic *counter, int children) : - fork_join_sub_task(), + task{}, counter_{counter}, children_{children} {} }; -class force_steal_sub_task : public fork_join_sub_task { +class force_steal_sub_task : public task { std::atomic *parent_counter_; std::atomic *overall_counter_; @@ -41,7 +41,7 @@ class force_steal_sub_task : public fork_join_sub_task { public: explicit force_steal_sub_task(std::atomic *parent_counter, std::atomic *overall_counter) : - fork_join_sub_task(), + task{}, parent_counter_{parent_counter}, overall_counter_{overall_counter} {} }; @@ -57,8 +57,7 @@ TEST_CASE("tbb task are scheduled correctly", "[internal/scheduling/fork_join_ta my_scheduler.perform_work([&]() { once_sub_task sub_task{&counter, start_counter}; - fork_join_task task{&sub_task, unique_id::create(42)}; - scheduler::execute_task(task); + scheduler::spawn_child(sub_task); }); REQUIRE(counter.load() == total_tasks); @@ -70,8 +69,7 @@ TEST_CASE("tbb task are scheduled correctly", "[internal/scheduling/fork_join_ta my_scheduler.perform_work([&]() { std::atomic dummy_parent{1}, overall_counter{8}; force_steal_sub_task sub_task{&dummy_parent, &overall_counter}; - fork_join_task task{&sub_task, unique_id::create(42)}; - scheduler::execute_task(task); + scheduler::spawn_child(sub_task); }); my_scheduler.terminate(true); } -- libgit2 0.26.0