#include "partition_alloc/partition_lock.h"
#include "partition_alloc/build_config.h"
#include "partition_alloc/buildflags.h"
#include "partition_alloc/partition_alloc_base/thread_annotations.h"
#include "partition_alloc/partition_alloc_base/threading/platform_thread_for_testing.h"
#include "partition_alloc/partition_alloc_base/time/time.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace partition_alloc::internal {
TEST(PartitionAllocLockTest, Simple) { … }
namespace {
Lock g_lock;
}
TEST(PartitionAllocLockTest, StaticLockStartsUnlocked) { … }
namespace {
class ThreadDelegateForContended
: public base::PlatformThreadForTesting::Delegate { … };
}
TEST(PartitionAllocLockTest, Contended) { … }
namespace {
class ThreadDelegateForSlowThreads
: public base::PlatformThreadForTesting::Delegate { … };
}
TEST(PartitionAllocLockTest, SlowThreads) { … }
TEST(PartitionAllocLockTest, AssertAcquired) { … }
#if defined(GTEST_HAS_DEATH_TEST) && PA_BUILDFLAG(DCHECKS_ARE_ON) && \
(!defined(OFFICIAL_BUILD) || !defined(NDEBUG))
TEST(PartitionAllocLockTest, AssertAcquiredDeathTest) { … }
namespace {
class ThreadDelegateForAssertAcquiredAnotherThreadHoldsTheLock
: public base::PlatformThreadForTesting::Delegate { … };
}
TEST(PartitionAllocLockTest, AssertAcquiredAnotherThreadHoldsTheLock) { … }
#if PA_BUILDFLAG(IS_APPLE)
namespace {
class ThreadDelegateForReinitInOtherThread
: public base::PlatformThreadForTesting::Delegate {
public:
explicit ThreadDelegateForReinitInOtherThread(Lock& lock) : lock_(lock) {}
void ThreadMain() PA_NO_THREAD_SAFETY_ANALYSIS override {
lock_.Reinit();
lock_.Acquire();
lock_.Release();
}
private:
Lock& lock_;
};
}
TEST(PartitionAllocLockTest, ReinitInOtherThread) PA_NO_THREAD_SAFETY_ANALYSIS {
Lock lock;
lock.Acquire();
ThreadDelegateForReinitInOtherThread delegate(lock);
base::PlatformThreadHandle handle;
base::PlatformThreadForTesting::Create(0, &delegate, &handle);
base::PlatformThreadForTesting::Join(handle);
}
#endif
#endif
}