#include "base/task/thread_pool/thread_group_impl.h"
#include <stddef.h>
#include <algorithm>
#include <atomic>
#include <memory>
#include <optional>
#include <unordered_set>
#include <utility>
#include <vector>
#include "base/atomicops.h"
#include "base/barrier_closure.h"
#include "base/functional/bind.h"
#include "base/functional/callback.h"
#include "base/functional/callback_helpers.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/memory/ref_counted.h"
#include "base/metrics/statistics_recorder.h"
#include "base/synchronization/atomic_flag.h"
#include "base/synchronization/condition_variable.h"
#include "base/synchronization/lock.h"
#include "base/task/task_features.h"
#include "base/task/task_runner.h"
#include "base/task/thread_pool/delayed_task_manager.h"
#include "base/task/thread_pool/environment_config.h"
#include "base/task/thread_pool/pooled_task_runner_delegate.h"
#include "base/task/thread_pool/sequence.h"
#include "base/task/thread_pool/task_source_sort_key.h"
#include "base/task/thread_pool/task_tracker.h"
#include "base/task/thread_pool/test_task_factory.h"
#include "base/task/thread_pool/test_utils.h"
#include "base/task/thread_pool/worker_thread_observer.h"
#include "base/test/bind.h"
#include "base/test/gtest_util.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/test_simple_task_runner.h"
#include "base/test/test_timeouts.h"
#include "base/test/test_waitable_event.h"
#include "base/threading/platform_thread.h"
#include "base/threading/scoped_blocking_call.h"
#include "base/threading/simple_thread.h"
#include "base/threading/thread.h"
#include "base/threading/thread_checker_impl.h"
#include "base/time/time.h"
#include "base/timer/timer.h"
#include "build/build_config.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace base {
namespace internal {
namespace {
constexpr size_t kMaxTasks = …;
constexpr size_t kNumThreadsPostingTasks = …;
constexpr size_t kNumTasksPostedPerThread = …;
constexpr TimeDelta kReclaimTimeForCleanupTests = …;
constexpr size_t kLargeNumber = …;
class ThreadGroupImplImplTestBase : public ThreadGroup::Delegate { … };
class ThreadGroupImplImplTest : public ThreadGroupImplImplTestBase,
public testing::Test { … };
class ThreadGroupImplImplTestParam
: public ThreadGroupImplImplTestBase,
public testing::TestWithParam<TaskSourceExecutionMode> { … };
PostNestedTask;
class ThreadPostingTasksWaitIdle : public SimpleThread { … };
}
TEST_P(ThreadGroupImplImplTestParam, PostTasksWaitAllWorkersIdle) { … }
TEST_P(ThreadGroupImplImplTestParam, PostTasksWithOneAvailableWorker) { … }
TEST_P(ThreadGroupImplImplTestParam, Saturate) { … }
TEST_F(ThreadGroupImplImplTest, ShouldYieldFloodedUserVisible) { … }
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
namespace {
class ThreadGroupImplImplStartInBodyTest : public ThreadGroupImplImplTest { … };
void TaskPostedBeforeStart(PlatformThreadRef* platform_thread_ref,
TestWaitableEvent* task_running,
TestWaitableEvent* barrier) { … }
}
TEST_F(ThreadGroupImplImplStartInBodyTest, PostTasksBeforeStart) { … }
TEST_F(ThreadGroupImplImplStartInBodyTest, PostManyTasks) { … }
namespace {
class BackgroundThreadGroupImplTest : public ThreadGroupImplImplTest { … };
}
TEST_F(BackgroundThreadGroupImplTest, UpdatePriorityBlockingStarted) { … }
namespace {
class ThreadGroupImplStandbyPolicyTest : public ThreadGroupImplImplTestBase,
public testing::Test { … };
}
TEST_F(ThreadGroupImplStandbyPolicyTest, InitOne) { … }
namespace {
enum class OptionalBlockingType { … };
struct NestedBlockingType { … };
class NestedScopedBlockingCall { … };
}
class ThreadGroupImplBlockingTest
: public ThreadGroupImplImplTestBase,
public testing::TestWithParam<NestedBlockingType> { … };
TEST_P(ThreadGroupImplBlockingTest, ThreadBlockedUnblocked) { … }
TEST_P(ThreadGroupImplBlockingTest, ThreadBlockedUnblockedBestEffort) { … }
TEST_P(ThreadGroupImplBlockingTest, TooManyBestEffortTasks) { … }
TEST_P(ThreadGroupImplBlockingTest, PostBeforeBlocking) { … }
TEST_P(ThreadGroupImplBlockingTest, WorkersIdleWhenOverCapacity) { … }
TEST_P(ThreadGroupImplBlockingTest, ThreadBlockedUnblockedShouldYield) { … }
INSTANTIATE_TEST_SUITE_P(…);
TEST_F(ThreadGroupImplBlockingTest, ThreadBlockUnblockPremature) { … }
TEST_F(ThreadGroupImplBlockingTest, ThreadBlockUnblockPrematureBestEffort) { … }
TEST_F(ThreadGroupImplBlockingTest, MayBlockIncreaseCapacityNestedWillBlock) { … }
TEST_F(ThreadGroupImplBlockingTest, ThreadBusyShutdown) { … }
enum class ReclaimType { … };
class ThreadGroupImplOverCapacityTest
: public ThreadGroupImplImplTestBase,
public testing::TestWithParam<ReclaimType> { … };
TEST_P(ThreadGroupImplOverCapacityTest, VerifyCleanup) { … }
INSTANTIATE_TEST_SUITE_P(…);
TEST_F(ThreadGroupImplBlockingTest, MaximumWorkersTest) { … }
TEST_F(ThreadGroupImplImplStartInBodyTest, MaxBestEffortTasks) { … }
TEST_F(ThreadGroupImplImplStartInBodyTest,
FloodBestEffortTasksDoesNotCreateTooManyWorkers) { … }
TEST_F(ThreadGroupImplImplStartInBodyTest,
RepeatedWillBlockDoesNotCreateTooManyWorkers) { … }
namespace {
class ThreadGroupImplBlockingCallAndMaxBestEffortTasksTest
: public ThreadGroupImplImplTestBase,
public testing::TestWithParam<BlockingType> { … };
}
TEST_P(ThreadGroupImplBlockingCallAndMaxBestEffortTasksTest,
BlockingCallAndMaxBestEffortTasksTest) { … }
INSTANTIATE_TEST_SUITE_P(…);
INSTANTIATE_TEST_SUITE_P(…);
TEST_F(ThreadGroupImplImplStartInBodyTest, RacyCleanup) { … }
}
}