diff --git a/Tests/unit/core/CMakeLists.txt b/Tests/unit/core/CMakeLists.txt index 7b1c13b5d..a7a262709 100644 --- a/Tests/unit/core/CMakeLists.txt +++ b/Tests/unit/core/CMakeLists.txt @@ -68,7 +68,7 @@ add_executable(${TEST_RUNNER_NAME} test_textfragment.cpp test_textreader.cpp test_thread.cpp - #test_threadpool.cpp + test_threadpool.cpp test_time.cpp #test_timer.cpp test_tristate.cpp diff --git a/Tests/unit/core/test_threadpool.cpp b/Tests/unit/core/test_threadpool.cpp index c82022a5b..bfc41b990 100644 --- a/Tests/unit/core/test_threadpool.cpp +++ b/Tests/unit/core/test_threadpool.cpp @@ -305,7 +305,7 @@ class ThreadPoolTester : public EventControl, public JobControl job = Core::ProxyType(Core::ProxyType>::Create(minion, TestJob::INITIATED, 500)); EXPECT_EQ(static_cast&>(*job).GetStatus(), TestJob::INITIATED); - EXPECT_EQ(minion.IsActive(), false); minion.Submit(job); - EXPECT_EQ(minion.IsActive(), false); minion.Run(); EXPECT_EQ(minion.WaitForJobEvent(job, MaxJobWaitTime * 2), Core::ERROR_NONE); minion.NotifyReady(job); minion.Shutdown(); EXPECT_EQ(static_cast&>(*job).GetStatus(), TestJob::COMPLETED); - EXPECT_EQ(minion.Runs(), 1u); + + WPEFramework::Core::ThreadPool::Metadata info; + minion.Info(info); + EXPECT_EQ(info.Runs, 1u); + job.Release(); } TEST(Core_ThreadPool, CheckMinion_ProcessJob_CheckActiveStateInBetweenDispatch) @@ -455,7 +457,11 @@ TEST(Core_ThreadPool, CheckMinion_ProcessJob_CheckActiveStateInBetweenDispatch) minion.Shutdown(); EXPECT_EQ(static_cast&>(*job).GetStatus(), TestJob::COMPLETED); - EXPECT_EQ(minion.Runs(), 1u); + + WPEFramework::Core::ThreadPool::Metadata info; + minion.Info(info); + EXPECT_EQ(info.Runs, 1u); + job.Release(); } TEST(Core_ThreadPool, CheckMinion_CancelJob_BeforeProcessing) @@ -472,7 +478,11 @@ TEST(Core_ThreadPool, CheckMinion_CancelJob_BeforeProcessing) minion.Revoke(job); EXPECT_EQ(minion.IsActive(), false); EXPECT_EQ(static_cast&>(*job).GetStatus(), TestJob::CANCELED); - EXPECT_EQ(minion.Runs(), 0u); + + WPEFramework::Core::ThreadPool::Metadata info; + minion.Info(info); + EXPECT_EQ(info.Runs, 0u); + job.Release(); } TEST(Core_ThreadPool, CheckMinion_CancelJob_WhileProcessing) @@ -497,7 +507,11 @@ TEST(Core_ThreadPool, CheckMinion_CancelJob_WhileProcessing) minion.Shutdown(); EXPECT_EQ(minion.IsActive(), false); EXPECT_EQ(static_cast&>(*job).GetStatus(), TestJob::COMPLETED); - EXPECT_EQ(minion.Runs(), 1u); + + WPEFramework::Core::ThreadPool::Metadata info; + minion.Info(info); + EXPECT_EQ(info.Runs, 1u); + job.Release(); } TEST(Core_ThreadPool, CheckMinion_CancelJob_WhileProcessing_ByAddingWaitOnTheDispatcher) @@ -516,7 +530,11 @@ TEST(Core_ThreadPool, CheckMinion_CancelJob_WhileProcessing_ByAddingWaitOnTheDis EXPECT_EQ(minion.IsActive(), true); minion.NotifyReady(job); EXPECT_EQ(static_cast&>(*job).GetStatus(), TestJob::COMPLETED); - EXPECT_EQ(minion.Runs(), 1u); + + WPEFramework::Core::ThreadPool::Metadata info; + minion.Info(info); + EXPECT_EQ(info.Runs, 1u); + minion.Shutdown(); usleep(100); EXPECT_EQ(minion.IsActive(), false); @@ -555,7 +573,9 @@ TEST(Core_ThreadPool, CheckMinion_ProcessMultipleJobs) EXPECT_EQ(static_cast&>(*job).GetStatus(), TestJob::COMPLETED); } - EXPECT_EQ(minion.Runs(), 6u); + WPEFramework::Core::ThreadPool::Metadata info; + minion.Info(info); + EXPECT_EQ(info.Runs, 6u); for (auto& job: jobs) { job.Release(); @@ -607,7 +627,9 @@ TEST(Core_ThreadPool, CheckMinion_ProcessMultipleJobs_CancelInBetween) minion.Shutdown(); - EXPECT_EQ(minion.Runs(), queueSize); + WPEFramework::Core::ThreadPool::Metadata info; + minion.Info(info); + EXPECT_EQ(info.Runs, queueSize); for (auto& job: jobs) { job.Release(); @@ -622,16 +644,13 @@ TEST(Core_ThreadPool, CheckThreadPool_ProcessJob) ThreadPoolTester threadPool(threadCount, 0, queueSize); Core::ProxyType job = Core::ProxyType(Core::ProxyType>::Create(threadPool, TestJob::INITIATED, 500)); EXPECT_EQ(static_cast&>(*job).GetStatus(), TestJob::INITIATED); - EXPECT_EQ(threadPool.Active(), false); threadPool.Submit(job, 0); EXPECT_EQ(threadPool.Pending(), queueSize); EXPECT_EQ(threadPool.QueueIsEmpty(), false); - EXPECT_EQ(threadPool.Active(), false); threadPool.Run(); while(threadPool.QueueIsEmpty() != true) { __asm__ volatile("nop"); } - EXPECT_EQ(threadPool.Active(), true); EXPECT_EQ(threadPool.WaitForJobEvent(job, MaxJobWaitTime), Core::ERROR_NONE); EXPECT_EQ(threadPool.Pending(), 0u); threadPool.Stop(); @@ -648,15 +667,12 @@ TEST(Core_ThreadPool, CheckThreadPool_RevokeJob) Core::ProxyType job = Core::ProxyType(Core::ProxyType>::Create(threadPool, TestJob::INITIATED)); EXPECT_EQ(static_cast&>(*job).GetStatus(), TestJob::INITIATED); - EXPECT_EQ(threadPool.Active(), false); threadPool.Submit(job, 0); EXPECT_EQ(threadPool.Pending(), queueSize); threadPool.Revoke(job, 0); EXPECT_EQ(threadPool.Pending(), 0u); EXPECT_EQ(threadPool.QueueIsEmpty(), true); - EXPECT_EQ(threadPool.Active(), false); threadPool.Run(); - EXPECT_EQ(threadPool.Active(), false); threadPool.Stop(); EXPECT_EQ(static_cast&>(*job).GetStatus(), TestJob::INITIATED); @@ -670,17 +686,14 @@ TEST(Core_ThreadPool, CheckThreadPool_CancelJob_WhileProcessing) Core::ProxyType job = Core::ProxyType(Core::ProxyType>::Create(threadPool, TestJob::INITIATED, 1000)); EXPECT_EQ(static_cast&>(*job).GetStatus(), TestJob::INITIATED); - EXPECT_EQ(threadPool.Active(), false); threadPool.Submit(job, 0); EXPECT_EQ(threadPool.Pending(), queueSize); EXPECT_EQ(threadPool.QueueIsEmpty(), false); - EXPECT_EQ(threadPool.Active(), false); threadPool.Run(); EXPECT_EQ(threadPool.QueueIsEmpty(), false); while(threadPool.QueueIsEmpty() != true) { __asm__ volatile("nop"); } - EXPECT_EQ(threadPool.Active(), true); threadPool.Revoke(job, 0); EXPECT_EQ(threadPool.Pending(), 0u); EXPECT_EQ(threadPool.WaitForJobEvent(job, MaxJobWaitTime * 3), Core::ERROR_NONE); @@ -721,11 +734,15 @@ void CheckThreadPool_ProcessMultipleJobs(const uint8_t threadCount, const uint8_ EXPECT_EQ(static_cast&>(*job).GetStatus(), TestJob::COMPLETED); } - uint32_t counters[threadCount] = {0}; uint8_t totalRuns = 0; - threadPool.Runs(threadCount, counters); + + WPEFramework::Core::ThreadPool::Metadata info[threadCount]; + std::vector jobsStrings; + + threadPool.Snapshot(threadCount, info, jobsStrings); + for (uint8_t i = 0; i < threadCount; ++i) { - totalRuns += counters[i]; + totalRuns += info[i].Runs; } EXPECT_EQ(totalRuns, static_cast(queueSize + additionalJobs)); @@ -800,14 +817,18 @@ TEST(Core_ThreadPool, CheckThreadPool_ProcessMultipleJobs_CancelInBetween) } } - uint32_t counters[threadCount] = {0}; - threadPool.Runs(threadCount, counters); uint8_t totalRuns = 0; + + WPEFramework::Core::ThreadPool::Metadata info[threadCount]; + std::vector jobsStrings; + + threadPool.Snapshot(threadCount, info, jobsStrings); + for (uint8_t i = 0; i < threadCount; ++i) { - totalRuns += counters[i]; + totalRuns += info[i].Runs; } - EXPECT_EQ(totalRuns, queueSize + additionalJobs - 1); + threadPool.Stop(); for (auto& job: jobs) { @@ -854,13 +875,17 @@ void CheckThreadPool_ProcessMultipleJobs_CancelInBetween_WithMultiplePool(const } uint8_t totalRuns = 0; - uint32_t counters[threadCount] = {0}; - threadPool.Runs(threadCount, counters); + + WPEFramework::Core::ThreadPool::Metadata info[threadCount]; + std::vector jobsStrings; + + threadPool.Snapshot(threadCount, info, jobsStrings); + for (uint8_t i = 0; i < threadCount; ++i) { - totalRuns += counters[i]; + totalRuns += info[i].Runs; } - EXPECT_EQ(totalRuns, queueSize + additionalJobs); + threadPool.Stop(); for (auto& job: jobs) { @@ -1002,13 +1027,17 @@ void CheckThreadPool_JobType_Submit_Using_Idle(const uint8_t threadCount, const } uint8_t totalRuns = 0; - uint32_t counters[threadCount] = {0}; - threadPool.Runs(threadCount, counters); + + WPEFramework::Core::ThreadPool::Metadata info[threadCount]; + std::vector jobsStrings; + + threadPool.Snapshot(threadCount, info, jobsStrings); + for (uint8_t i = 0; i < threadCount; ++i) { - totalRuns += counters[i]; + totalRuns += info[i].Runs; } - EXPECT_EQ(totalRuns, queueSize + additionalJobs - cancelJobsCount); + threadPool.Stop(); for (auto& job: jobs) { @@ -1114,13 +1143,17 @@ void CheckThreadPool_JobType_Submit_Using_Submit(const uint8_t threadCount, cons } uint8_t totalRuns = 0; - uint32_t counters[threadCount] = {0}; - threadPool.Runs(threadCount, counters); + + WPEFramework::Core::ThreadPool::Metadata info[threadCount]; + std::vector jobsStrings; + + threadPool.Snapshot(threadCount, info, jobsStrings); + for (uint8_t i = 0; i < threadCount; ++i) { - totalRuns += counters[i]; + totalRuns += info[i].Runs; } - EXPECT_EQ(totalRuns, queueSize + additionalJobs - cancelJobsCount); + threadPool.Stop(); for (auto& job: jobs) { @@ -1221,13 +1254,17 @@ void CheckThreadPool_JobType_Submit_Using_Reschedule(const uint8_t threadCount, } uint8_t totalRuns = 0; - uint32_t counters[threadCount] = {0}; - threadPool.Runs(threadCount, counters); + + WPEFramework::Core::ThreadPool::Metadata info[threadCount]; + std::vector jobsStrings; + + threadPool.Snapshot(threadCount, info, jobsStrings); + for (uint8_t i = 0; i < threadCount; ++i) { - totalRuns += counters[i]; + totalRuns += info[i].Runs; } - EXPECT_EQ(totalRuns, (queueSize + additionalJobs - cancelJobsCount) * 2); + threadPool.Stop(); for (auto& job: jobs) { @@ -1314,10 +1351,14 @@ TEST(Core_ThreadPool, CheckThreadPool_JobType_Reschedule_AfterSubmit) } uint8_t totalRuns = 0; - uint32_t counters[threadCount] = {0}; - threadPool.Runs(threadCount, counters); + + WPEFramework::Core::ThreadPool::Metadata info[threadCount]; + std::vector jobsStrings; + + threadPool.Snapshot(threadCount, info, jobsStrings); + for (uint8_t i = 0; i < threadCount; ++i) { - totalRuns += counters[i]; + totalRuns += info[i].Runs; } EXPECT_EQ(totalRuns, (queueSize + additionalJobs) * 2); @@ -1373,10 +1414,14 @@ TEST(Core_ThreadPool, CheckThreadPool_JobType_Reschedule_AfterIdle) } uint8_t totalRuns = 0; - uint32_t counters[threadCount] = {0}; - threadPool.Runs(threadCount, counters); + + WPEFramework::Core::ThreadPool::Metadata info[threadCount]; + std::vector jobsStrings; + + threadPool.Snapshot(threadCount, info, jobsStrings); + for (uint8_t i = 0; i < threadCount; ++i) { - totalRuns += counters[i]; + totalRuns += info[i].Runs; } EXPECT_EQ(totalRuns, (queueSize + additionalJobs) * 2);