From 6ffd938f98781b6bd2ddec0af4a514abc6d2cab7 Mon Sep 17 00:00:00 2001 From: Dentomologist Date: Thu, 19 May 2022 12:17:46 -0700 Subject: [PATCH] UnitTests: Skip PageFaultTest if exception handlers are not supported Page faults should only occur on architectures that support exception handlers, so skip the test on other architectures to avoid spurious test failures. --- Source/Core/Core/MemTools.cpp | 22 ++++++++++++++++++++++ Source/Core/Core/MemTools.h | 1 + Source/UnitTests/Core/PageFaultTest.cpp | 5 +++++ 3 files changed, 28 insertions(+) diff --git a/Source/Core/Core/MemTools.cpp b/Source/Core/Core/MemTools.cpp index c427c8ba7e..c9109bfd1f 100644 --- a/Source/Core/Core/MemTools.cpp +++ b/Source/Core/Core/MemTools.cpp @@ -113,6 +113,11 @@ void UninstallExceptionHandler() s_veh_handle = nullptr; } +bool IsExceptionHandlerSupported() +{ + return true; +} + #elif defined(__APPLE__) && !defined(USE_SIGACTION_ON_APPLE) static void CheckKR(const char* name, kern_return_t kr) @@ -245,6 +250,11 @@ void UninstallExceptionHandler() { } +bool IsExceptionHandlerSupported() +{ + return true; +} + #elif defined(_POSIX_VERSION) && !defined(_M_GENERIC) static struct sigaction old_sa_segv; @@ -353,15 +363,27 @@ void UninstallExceptionHandler() sigaction(SIGBUS, &old_sa_bus, nullptr); #endif } + +bool IsExceptionHandlerSupported() +{ + return true; +} + #else // _M_GENERIC or unsupported platform void InstallExceptionHandler() { } + void UninstallExceptionHandler() { } +bool IsExceptionHandlerSupported() +{ + return false; +} + #endif } // namespace EMM diff --git a/Source/Core/Core/MemTools.h b/Source/Core/Core/MemTools.h index 65c06e7023..e71f2bb2f9 100644 --- a/Source/Core/Core/MemTools.h +++ b/Source/Core/Core/MemTools.h @@ -7,4 +7,5 @@ namespace EMM { void InstallExceptionHandler(); void UninstallExceptionHandler(); +bool IsExceptionHandlerSupported(); } // namespace EMM diff --git a/Source/UnitTests/Core/PageFaultTest.cpp b/Source/UnitTests/Core/PageFaultTest.cpp index 841ba54609..e340ca7646 100644 --- a/Source/UnitTests/Core/PageFaultTest.cpp +++ b/Source/UnitTests/Core/PageFaultTest.cpp @@ -61,6 +61,11 @@ static void ASAN_DISABLE perform_invalid_access(void* data) TEST(PageFault, PageFault) { + if (!EMM::IsExceptionHandlerSupported()) + { + // TODO: Use GTEST_SKIP() instead when GTest is updated to 1.10+ + return; + } EMM::InstallExceptionHandler(); void* data = Common::AllocateMemoryPages(PAGE_GRAN); EXPECT_NE(data, nullptr);