chromium/third_party/abseil-cpp/absl/base/spinlock_test_common.cc

// Copyright 2017 The Abseil Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

// A bunch of threads repeatedly hash an array of ints protected by a
// spinlock.  If the spinlock is working properly, all elements of the
// array should be equal at the end of the test.

#include <cstdint>
#include <limits>
#include <random>
#include <thread>  // NOLINT(build/c++11)
#include <type_traits>
#include <vector>

#include "gtest/gtest.h"
#include "absl/base/attributes.h"
#include "absl/base/config.h"
#include "absl/base/internal/low_level_scheduling.h"
#include "absl/base/internal/scheduling_mode.h"
#include "absl/base/internal/spinlock.h"
#include "absl/base/internal/sysinfo.h"
#include "absl/base/macros.h"
#include "absl/synchronization/blocking_counter.h"
#include "absl/synchronization/notification.h"

constexpr uint32_t kNumThreads =;
constexpr int32_t kIters =;

namespace absl {
ABSL_NAMESPACE_BEGIN
namespace base_internal {

// This is defined outside of anonymous namespace so that it can be
// a friend of SpinLock to access protected methods for testing.
struct SpinLockTest {};

namespace {

static constexpr size_t kArrayLength =;
static uint32_t values[kArrayLength];

ABSL_CONST_INIT static SpinLock static_cooperative_spinlock(
    absl::kConstInit, base_internal::SCHEDULE_COOPERATIVE_AND_KERNEL);
ABSL_CONST_INIT static SpinLock static_noncooperative_spinlock(
    absl::kConstInit, base_internal::SCHEDULE_KERNEL_ONLY);

// Simple integer hash function based on the public domain lookup2 hash.
// http://burtleburtle.net/bob/c/lookup2.c
static uint32_t Hash32(uint32_t a, uint32_t c) {}

static void TestFunction(uint32_t thread_salt, SpinLock* spinlock) {}

static void ThreadedTest(SpinLock* spinlock) {}

#ifndef ABSL_HAVE_THREAD_SANITIZER
static_assert;
#endif

TEST(SpinLock, StackNonCooperativeDisablesScheduling) {}

TEST(SpinLock, StaticNonCooperativeDisablesScheduling) {}

TEST(SpinLock, WaitCyclesEncoding) {}

TEST(SpinLockWithThreads, StackSpinLock) {}

TEST(SpinLockWithThreads, StackCooperativeSpinLock) {}

TEST(SpinLockWithThreads, StackNonCooperativeSpinLock) {}

TEST(SpinLockWithThreads, StaticCooperativeSpinLock) {}

TEST(SpinLockWithThreads, StaticNonCooperativeSpinLock) {}

TEST(SpinLockWithThreads, DoesNotDeadlock) {}

TEST(SpinLockTest, IsCooperative) {}

}  // namespace
}  // namespace base_internal
ABSL_NAMESPACE_END
}  // namespace absl