chromium/base/synchronization/lock_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/synchronization/lock.h"

#include <stdlib.h>

#include <cstdint>

#include "base/compiler_specific.h"
#include "base/dcheck_is_on.h"
#include "base/memory/raw_ptr.h"
#include "base/synchronization/lock_subtle.h"
#include "base/test/gtest_util.h"
#include "base/threading/platform_thread.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

UnorderedElementsAre;
UnorderedElementsAreArray;

namespace base {

// Basic test to make sure that Acquire()/Release()/Try() don't crash ----------

class BasicLockTestThread : public PlatformThread::Delegate {};

TEST(LockTest, Basic) {}

// Test that Try() works as expected -------------------------------------------

class TryLockTestThread : public PlatformThread::Delegate {};

TEST(LockTest, TryLock) {}

// Tests that locks actually exclude -------------------------------------------

class MutexLockTestThread : public PlatformThread::Delegate {};

TEST(LockTest, MutexTwoThreads) {}

TEST(LockTest, MutexFourThreads) {}

TEST(LockTest, AutoLockMaybe) {}

TEST(LockTest, AutoLockMaybeNull) {}

TEST(LockTest, ReleasableAutoLockExplicitRelease) {}

TEST(LockTest, ReleasableAutoLockImplicitRelease) {}

class TryLockTest : public testing::Test {};

// Verifies thread safety annotations do not prevent correct `AutoTryLock` usage
// from compiling. A dual of this test exists in lock_nocompile.nc. For more
// context, see <https://crbug.com/340196356>.
TEST_F(TryLockTest, CorrectlyCheckIsAcquired) {}

#if DCHECK_IS_ON()

TEST(LockTest, GetTrackedLocksHeldByCurrentThread) {}

TEST(LockTest, GetTrackedLocksHeldByCurrentThread_AutoLock) {}

TEST(LockTest, GetTrackedLocksHeldByCurrentThread_MovableAutoLock) {}

TEST(LockTest, GetTrackedLocksHeldByCurrentThread_AutoTryLock) {}

TEST(LockTest, GetTrackedLocksHeldByCurrentThread_AutoLockMaybe) {}

TEST(LockTest, GetTrackedLocksHeldByCurrentThreadOverCapacity)
// Thread-safety analysis doesn't handle the array of locks properly.
NO_THREAD_SAFETY_ANALYSIS {}

TEST(LockTest, TrackingDisabled) {}

#endif  // DCHECK_IS_ON()

}  // namespace base