From 2e81814184b19f89b8c64acd163c519fb32e849d Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Sun, 7 Aug 2022 11:59:19 +0000 Subject: [PATCH] Suppress a failure with new (std::nothrow) on Mac ARM64. This happens when trying to allocate the backing storage for an error buffer when the allocation would cause an OOM. new (std::nothrow) doesn't work on Mac ARM64. The code in libc++ that's compiled into dawn_unittests seems correct, but macOS's libunwind returns "end of stack" when trying to unwind. Bug: dawn:1506 Change-Id: Ibc5d7251ea7a411b0e3cc91646a059270d965a90 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/98122 Reviewed-by: Loko Kung Kokoro: Kokoro Reviewed-by: Austin Eng Commit-Queue: Corentin Wallez --- .../validation/BufferValidationTests.cpp | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/dawn/tests/unittests/validation/BufferValidationTests.cpp b/src/dawn/tests/unittests/validation/BufferValidationTests.cpp index 11b42be275..af95b82816 100644 --- a/src/dawn/tests/unittests/validation/BufferValidationTests.cpp +++ b/src/dawn/tests/unittests/validation/BufferValidationTests.cpp @@ -15,6 +15,7 @@ #include #include +#include "dawn/common/Platform.h" #include "dawn/tests/unittests/validation/ValidationTest.h" #include "gmock/gmock.h" @@ -802,12 +803,6 @@ TEST_F(BufferValidationTest, GetMappedRange_ValidBufferStateCases) { // Test valid cases to call GetMappedRange on an error buffer. TEST_F(BufferValidationTest, GetMappedRange_OnErrorBuffer) { - wgpu::BufferDescriptor desc; - desc.size = 4; - desc.usage = wgpu::BufferUsage::Storage | wgpu::BufferUsage::MapRead; - - uint64_t kStupidLarge = uint64_t(1) << uint64_t(63); - // GetMappedRange after mappedAtCreation a zero-sized buffer returns a non-nullptr. // This is to check we don't do a malloc(0). { @@ -828,17 +823,23 @@ TEST_F(BufferValidationTest, GetMappedRange_OnErrorBuffer) { ASSERT_NE(buffer.GetConstMappedRange(), nullptr); ASSERT_EQ(buffer.GetConstMappedRange(), buffer.GetMappedRange()); } +} + +// Test valid cases to call GetMappedRange on an error buffer that's also OOM. +TEST_F(BufferValidationTest, GetMappedRange_OnErrorBuffer_OOM) { + // TODO(crbug.com/dawn/1506): new (std::nothrow) crashes on OOM on Mac ARM64 because libunwind + // doesn't see the previous catchall try-catch. + DAWN_SKIP_TEST_IF(DAWN_PLATFORM_IS(MACOS) && DAWN_PLATFORM_IS(ARM64)); + + uint64_t kStupidLarge = uint64_t(1) << uint64_t(63); + + wgpu::Buffer buffer; + ASSERT_DEVICE_ERROR(buffer = BufferMappedAtCreation( + kStupidLarge, wgpu::BufferUsage::Storage | wgpu::BufferUsage::MapRead)); // GetMappedRange after mappedAtCreation OOM case returns nullptr. - { - wgpu::Buffer buffer; - ASSERT_DEVICE_ERROR( - buffer = BufferMappedAtCreation( - kStupidLarge, wgpu::BufferUsage::Storage | wgpu::BufferUsage::MapRead)); - - ASSERT_EQ(buffer.GetConstMappedRange(), nullptr); - ASSERT_EQ(buffer.GetConstMappedRange(), buffer.GetMappedRange()); - } + ASSERT_EQ(buffer.GetConstMappedRange(), nullptr); + ASSERT_EQ(buffer.GetConstMappedRange(), buffer.GetMappedRange()); } // Test validation of the GetMappedRange parameters