this repo has no description
at trunk 40 lines 1.1 kB view raw
1// Copyright (c) Facebook, Inc. and its affiliates. (http://www.facebook.com) 2#include "Python.h" 3#include "gtest/gtest.h" 4 5#include "capi-fixture.h" 6#include "capi-testing.h" 7#include "pythread.h" 8 9namespace py { 10namespace testing { 11 12using ThreadExtensionApiTest = ExtensionApi; 13 14TEST_F(ThreadExtensionApiTest, GetThreadIdentReturnsSameValue) { 15 EXPECT_EQ(PyThread_get_thread_ident(), PyThread_get_thread_ident()); 16} 17 18TEST_F(ThreadExtensionApiTest, TryLockWithBusyLockReturnsFailure) { 19 PyThread_type_lock lock = PyThread_allocate_lock(); 20 ASSERT_NE(lock, nullptr); 21 ASSERT_EQ(PyThread_acquire_lock(lock, 0), 1); 22 EXPECT_EQ(PyThread_acquire_lock(lock, 0), 0); 23 24 PyThread_release_lock(lock); 25 PyThread_free_lock(lock); 26} 27 28TEST_F(ThreadExtensionApiTest, ReleaseWithBusyLockAllowsItToBeAcquiredAgain) { 29 PyThread_type_lock lock = PyThread_allocate_lock(); 30 ASSERT_NE(lock, nullptr); 31 ASSERT_EQ(PyThread_acquire_lock(lock, 0), 1); 32 PyThread_release_lock(lock); 33 EXPECT_EQ(PyThread_acquire_lock(lock, 0), 1); 34 35 PyThread_release_lock(lock); 36 PyThread_free_lock(lock); 37} 38 39} // namespace testing 40} // namespace py