chromium/base/task/thread_pool/task_tracker_unittest.cc

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/task/thread_pool/task_tracker.h"

#include <stdint.h>

#include <memory>
#include <utility>
#include <vector>

#include "base/barrier_closure.h"
#include "base/check_op.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/histogram_base.h"
#include "base/metrics/histogram_samples.h"
#include "base/sequence_token.h"
#include "base/synchronization/atomic_flag.h"
#include "base/task/common/checked_lock.h"
#include "base/task/sequenced_task_runner.h"
#include "base/task/single_thread_task_runner.h"
#include "base/task/task_traits.h"
#include "base/task/thread_pool/task.h"
#include "base/task/thread_pool/test_utils.h"
#include "base/test/bind.h"
#include "base/test/gtest_util.h"
#include "base/test/metrics/histogram_tester.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_restrictions.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace base {
namespace internal {

namespace {

constexpr size_t kLoadTestNumIterations =;

// Invokes a closure asynchronously.
class CallbackThread : public SimpleThread {};

class ThreadPostingAndRunningTask : public SimpleThread {};

class ThreadPoolTaskTrackerTest
    : public testing::TestWithParam<TaskShutdownBehavior> {};

#define WAIT_FOR_ASYNC_SHUTDOWN_COMPLETED()

#define VERIFY_ASYNC_SHUTDOWN_IN_PROGRESS()

#define WAIT_FOR_ASYNC_FLUSHES_RETURNED()

#define VERIFY_ASYNC_FLUSHES_IN_PROGRESS()

}  // namespace

TEST_P(ThreadPoolTaskTrackerTest, WillPostAndRunBeforeShutdown) {}

TEST_P(ThreadPoolTaskTrackerTest, WillPostAndRunLongTaskBeforeShutdown) {}

// Posting a BLOCK_SHUTDOWN task after shutdown must be allowed from a
// CONTINUE_ON_SHUTDOWN. Ref. https://crbug.com/1499644#c9 - #c16.
// Note: This test can't be TEST_P as non-CONTINUE_ON_SHUTDOWN `poster` would
// hang in CompleteShutdown().
TEST_F(ThreadPoolTaskTrackerTest, PostAfterShutdownFromContinueOnShutdown) {}

// Verify that an undelayed task whose sequence wasn't queued does not block
// shutdown, regardless of its shutdown behavior.
TEST_P(ThreadPoolTaskTrackerTest, WillPostBeforeShutdownQueueDuringShutdown) {}

TEST_P(ThreadPoolTaskTrackerTest, WillPostBeforeShutdownRunDuringShutdown) {}

TEST_P(ThreadPoolTaskTrackerTest, WillPostBeforeShutdownRunAfterShutdown) {}

TEST_P(ThreadPoolTaskTrackerTest, WillPostAndRunDuringShutdown) {}

TEST_P(ThreadPoolTaskTrackerTest, WillPostAfterShutdown) {}

// Verify that BLOCK_SHUTDOWN and SKIP_ON_SHUTDOWN tasks can
// AssertSingletonAllowed() but CONTINUE_ON_SHUTDOWN tasks can't.
TEST_P(ThreadPoolTaskTrackerTest, SingletonAllowed) {}

// Verify that AssertIOAllowed() succeeds only for a MayBlock() task.
TEST_P(ThreadPoolTaskTrackerTest, IOAllowed) {}

static void RunTaskRunnerCurrentDefaultHandleVerificationTask(
    TaskTracker* tracker,
    Task verify_task,
    TaskTraits traits,
    scoped_refptr<SequencedTaskRunner> task_runner,
    TaskSourceExecutionMode execution_mode) {}

static void VerifyNoTaskRunnerCurrentDefaultHandle() {}

TEST_P(ThreadPoolTaskTrackerTest, TaskRunnerHandleIsNotSetOnParallel) {}

static void VerifySequencedTaskRunnerCurrentDefaultHandle(
    const SequencedTaskRunner* expected_task_runner) {}

TEST_P(ThreadPoolTaskTrackerTest,
       SequencedTaskRunnerHasCurrentDefaultOnSequenced) {}

static void VerifySingleThreadTaskRunnerCurrentDefaultHandle(
    const SingleThreadTaskRunner* expected_task_runner) {}

TEST_P(ThreadPoolTaskTrackerTest,
       SingleThreadTaskRunnerCurrentDefaultHandleIsSetOnSingleThreaded) {}

TEST_P(ThreadPoolTaskTrackerTest, FlushPendingDelayedTask) {}

TEST_P(ThreadPoolTaskTrackerTest, FlushAsyncForTestingPendingDelayedTask) {}

TEST_P(ThreadPoolTaskTrackerTest, FlushPendingUndelayedTask) {}

TEST_P(ThreadPoolTaskTrackerTest, MultipleFlushes) {}

TEST_P(ThreadPoolTaskTrackerTest, FlushAsyncForTestingPendingUndelayedTask) {}

TEST_P(ThreadPoolTaskTrackerTest, MultipleFlushAsyncForTesting) {}

TEST_P(ThreadPoolTaskTrackerTest, PostTaskDuringFlush) {}

TEST_P(ThreadPoolTaskTrackerTest, PostTaskDuringFlushAsyncForTesting) {}

TEST_P(ThreadPoolTaskTrackerTest, RunDelayedTaskDuringFlush) {}

TEST_P(ThreadPoolTaskTrackerTest, RunDelayedTaskDuringFlushAsyncForTesting) {}

TEST_P(ThreadPoolTaskTrackerTest, FlushAfterShutdown) {}

TEST_P(ThreadPoolTaskTrackerTest, FlushAfterShutdownAsync) {}

TEST_P(ThreadPoolTaskTrackerTest, ShutdownDuringFlush) {}

TEST_P(ThreadPoolTaskTrackerTest, ShutdownDuringFlushAsyncForTesting) {}

TEST_P(ThreadPoolTaskTrackerTest, PostTasksDoNotBlockShutdown) {}

// Verify that a delayed task does not block shutdown once it's run, regardless
// of its shutdown behavior.
TEST_P(ThreadPoolTaskTrackerTest, DelayedRunTasks) {}

INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();
INSTANTIATE_TEST_SUITE_P();

namespace {

void ExpectSequenceToken(SequenceToken sequence_token) {}

}  // namespace

// Verify that SequenceToken::GetForCurrentThread() returns the Sequence's token
// when a Task runs.
TEST_F(ThreadPoolTaskTrackerTest, CurrentSequenceToken) {}

TEST_F(ThreadPoolTaskTrackerTest, LoadWillPostAndRunBeforeShutdown) {}

TEST_F(ThreadPoolTaskTrackerTest,
       LoadWillPostBeforeShutdownAndRunDuringShutdown) {}

TEST_F(ThreadPoolTaskTrackerTest, LoadWillPostAndRunDuringShutdown) {}

// Verify that RunAndPopNextTask() returns the sequence from which it ran a task
// when it can be rescheduled.
TEST_F(ThreadPoolTaskTrackerTest,
       RunAndPopNextTaskReturnsSequenceToReschedule) {}

namespace {

class WaitAllowedTestThread : public SimpleThread {};

}  // namespace

// Verify that AssertIOAllowed() succeeds only for a WithBaseSyncPrimitives()
// task.
TEST(ThreadPoolTaskTrackerWaitAllowedTest, WaitAllowed) {}

}  // namespace internal
}  // namespace base