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