chromium/base/threading/thread_unittest.cc

// Copyright 2012 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/threading/thread.h"

#include <stddef.h>
#include <stdint.h>

#include <utility>
#include <vector>

#include "base/dcheck_is_on.h"
#include "base/debug/leak_annotations.h"
#include "base/functional/bind.h"
#include "base/logging.h"
#include "base/memory/ptr_util.h"
#include "base/memory/raw_ptr.h"
#include "base/run_loop.h"
#include "base/synchronization/waitable_event.h"
#include "base/task/current_thread.h"
#include "base/task/sequence_manager/sequence_manager_impl.h"
#include "base/task/single_thread_task_runner.h"
#include "base/test/bind.h"
#include "base/test/gtest_util.h"
#include "base/threading/platform_thread.h"
#include "base/time/time.h"
#include "build/build_config.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "testing/platform_test.h"
#include "third_party/abseil-cpp/absl/base/dynamic_annotations.h"

#if DCHECK_IS_ON()
#include "base/threading/thread_restrictions.h"
#endif

NotNull;

ThreadTest;

namespace base {
namespace {

void ToggleValue(bool* value) {}

class SleepInsideInitThread : public Thread {};

enum ThreadEvent {};

EventList;

class CaptureToEventList : public Thread {};

// Observer that writes a value into |event_list| when a message loop has been
// destroyed.
class CapturingDestructionObserver : public CurrentThread::DestructionObserver {};

// Task that adds a destruction observer to the current message loop.
void RegisterDestructionObserver(CurrentThread::DestructionObserver* observer) {}

// Task that calls GetThreadId() of |thread|, stores the result into |id|, then
// signal |event|.
void ReturnThreadId(Thread* thread,
                    PlatformThreadId* id,
                    WaitableEvent* event) {}

}  // namespace

TEST_F(ThreadTest, StartWithOptions_StackSize) {}

// Intentional test-only race for otherwise untestable code, won't fix.
// https://crbug.com/634383
#if !defined(THREAD_SANITIZER)
TEST_F(ThreadTest, StartWithOptions_NonJoinable) {}
#endif

TEST_F(ThreadTest, TwoTasksOnJoinableThread) {}

TEST_F(ThreadTest, DestroyWhileRunningIsSafe) {}

// TODO(gab): Enable this test when destroying a non-joinable Thread instance
// is supported (proposal @ https://crbug.com/629139#c14).
TEST_F(ThreadTest, DISABLED_DestroyWhileRunningNonJoinableIsSafe) {}

TEST_F(ThreadTest, StopSoon) {}

TEST_F(ThreadTest, StopTwiceNop) {}

// TODO(gab): Enable this test in conjunction with re-enabling the sequence
// check in Thread::Stop() as part of http://crbug.com/629139.
TEST_F(ThreadTest, DISABLED_StopOnNonOwningThreadIsDeath) {}

TEST_F(ThreadTest, TransferOwnershipAndStop) {}

TEST_F(ThreadTest, StartTwice) {}

// Intentional test-only race for otherwise untestable code, won't fix.
// https://crbug.com/634383
#if !defined(THREAD_SANITIZER)
TEST_F(ThreadTest, StartTwiceNonJoinableNotAllowed) {}
#endif

TEST_F(ThreadTest, ThreadName) {}

TEST_F(ThreadTest, ThreadId) {}

TEST_F(ThreadTest, ThreadIdWithRestart) {}

// Make sure Init() is called after Start() and before
// WaitUntilThreadInitialized() returns.
TEST_F(ThreadTest, SleepInsideInit) {}

// Make sure that the destruction sequence is:
//
//  (1) Thread::CleanUp()
//  (2) MessageLoop::~MessageLoop()
//      CurrentThread::DestructionObservers called.
TEST_F(ThreadTest, CleanUp) {}

TEST_F(ThreadTest, ThreadNotStarted) {}

TEST_F(ThreadTest, MultipleWaitUntilThreadStarted) {}

TEST_F(ThreadTest, FlushForTesting) {}

namespace {

TaskQueue;

class SequenceManagerThreadDelegate : public Thread::Delegate {};

}  // namespace

TEST_F(ThreadTest, ProvidedThreadDelegate) {}

}  // namespace base