1 #include <c10/util/DeadlockDetection.h> 2 3 #include <gtest/gtest.h> 4 5 #include <cstdlib> 6 7 using namespace ::testing; 8 using namespace c10::impl; 9 10 struct DummyPythonGILHooks : public PythonGILHooks { check_python_gilDummyPythonGILHooks11 bool check_python_gil() const override { 12 return true; 13 } 14 }; 15 TEST(DeadlockDetection,basic)16TEST(DeadlockDetection, basic) { 17 ASSERT_FALSE(check_python_gil()); 18 DummyPythonGILHooks hooks; 19 SetPythonGILHooks(&hooks); 20 ASSERT_TRUE(check_python_gil()); 21 SetPythonGILHooks(nullptr); 22 } 23 24 #ifndef _WIN32 TEST(DeadlockDetection,disable)25TEST(DeadlockDetection, disable) { 26 setenv("TORCH_DISABLE_DEADLOCK_DETECTION", "1", 1); 27 DummyPythonGILHooks hooks; 28 SetPythonGILHooks(&hooks); 29 SetPythonGILHooks(&hooks); 30 } 31 #endif 32