mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-18 17:35:30 +00:00
fuzzing: Add error injection macros to the Vulkan backend
This will enable fuzzing the Vulkan backend with randomly injected errors to help ensure the backend properly handles all errors. It also redefines VkResult in the dawn_native::vulkan namespace such that a VkResult cannot be used unless it is explicitly wrapped. Bug: dawn:295 Change-Id: I3ab2f98702a67a61afe06315658a9ab76ed4ccc3 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/14520 Commit-Queue: Austin Eng <enga@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org>
This commit is contained in:
committed by
Commit Bot service account
parent
2c8a17ecc7
commit
6ea362cae0
123
src/tests/white_box/VulkanErrorInjectorTests.cpp
Normal file
123
src/tests/white_box/VulkanErrorInjectorTests.cpp
Normal file
@@ -0,0 +1,123 @@
|
||||
// Copyright 2019 The Dawn Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
#include "tests/DawnTest.h"
|
||||
|
||||
#include "common/Math.h"
|
||||
#include "common/vulkan_platform.h"
|
||||
#include "dawn_native/ErrorData.h"
|
||||
#include "dawn_native/VulkanBackend.h"
|
||||
#include "dawn_native/vulkan/DeviceVk.h"
|
||||
#include "dawn_native/vulkan/VulkanError.h"
|
||||
|
||||
namespace {
|
||||
|
||||
class VulkanErrorInjectorTests : public DawnTest {
|
||||
public:
|
||||
void TestSetUp() override {
|
||||
DAWN_SKIP_TEST_IF(UsesWire());
|
||||
|
||||
mDeviceVk = reinterpret_cast<dawn_native::vulkan::Device*>(device.Get());
|
||||
}
|
||||
|
||||
protected:
|
||||
dawn_native::vulkan::Device* mDeviceVk;
|
||||
};
|
||||
|
||||
} // anonymous namespace
|
||||
|
||||
TEST_P(VulkanErrorInjectorTests, InjectErrorOnCreateBuffer) {
|
||||
VkBufferCreateInfo createInfo = {};
|
||||
createInfo.sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO;
|
||||
createInfo.pNext = nullptr;
|
||||
createInfo.size = 16;
|
||||
createInfo.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT;
|
||||
|
||||
// Check that making a buffer works.
|
||||
{
|
||||
VkBuffer buffer = VK_NULL_HANDLE;
|
||||
EXPECT_EQ(
|
||||
mDeviceVk->fn.CreateBuffer(mDeviceVk->GetVkDevice(), &createInfo, nullptr, &buffer),
|
||||
VK_SUCCESS);
|
||||
mDeviceVk->fn.DestroyBuffer(mDeviceVk->GetVkDevice(), buffer, nullptr);
|
||||
}
|
||||
|
||||
auto CreateTestBuffer = [&]() -> bool {
|
||||
VkBuffer buffer = VK_NULL_HANDLE;
|
||||
dawn_native::MaybeError err = CheckVkSuccess(
|
||||
mDeviceVk->fn.CreateBuffer(mDeviceVk->GetVkDevice(), &createInfo, nullptr, &buffer),
|
||||
"vkCreateBuffer");
|
||||
if (err.IsError()) {
|
||||
// The handle should never be written to, even for mock failures.
|
||||
EXPECT_EQ(buffer, VK_NULL_HANDLE);
|
||||
delete err.AcquireError();
|
||||
return false;
|
||||
}
|
||||
EXPECT_NE(buffer, VK_NULL_HANDLE);
|
||||
|
||||
// We never use the buffer, only test mocking errors on creation. Cleanup now.
|
||||
mDeviceVk->fn.DestroyBuffer(mDeviceVk->GetVkDevice(), buffer, nullptr);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
// Check that making a buffer inside CheckVkSuccess works.
|
||||
{
|
||||
EXPECT_TRUE(CreateTestBuffer());
|
||||
|
||||
// The error injector call count should be empty
|
||||
EXPECT_EQ(dawn_native::AcquireErrorInjectorCallCount(), 0u);
|
||||
}
|
||||
|
||||
// Test error injection works.
|
||||
dawn_native::EnableErrorInjector();
|
||||
{
|
||||
EXPECT_TRUE(CreateTestBuffer());
|
||||
EXPECT_TRUE(CreateTestBuffer());
|
||||
|
||||
// The error injector call count should be two.
|
||||
EXPECT_EQ(dawn_native::AcquireErrorInjectorCallCount(), 2u);
|
||||
|
||||
// Inject an error at index 0. The first should fail, the second succeed.
|
||||
{
|
||||
dawn_native::InjectErrorAt(0u);
|
||||
EXPECT_FALSE(CreateTestBuffer());
|
||||
EXPECT_TRUE(CreateTestBuffer());
|
||||
|
||||
dawn_native::ClearErrorInjector();
|
||||
}
|
||||
|
||||
// Inject an error at index 1. The second should fail, the first succeed.
|
||||
{
|
||||
dawn_native::InjectErrorAt(1u);
|
||||
EXPECT_TRUE(CreateTestBuffer());
|
||||
EXPECT_FALSE(CreateTestBuffer());
|
||||
|
||||
dawn_native::ClearErrorInjector();
|
||||
}
|
||||
|
||||
// Inject an error and then clear the injector. Calls should be successful.
|
||||
{
|
||||
dawn_native::InjectErrorAt(0u);
|
||||
dawn_native::DisableErrorInjector();
|
||||
|
||||
EXPECT_TRUE(CreateTestBuffer());
|
||||
EXPECT_TRUE(CreateTestBuffer());
|
||||
|
||||
dawn_native::ClearErrorInjector();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DAWN_INSTANTIATE_TEST(VulkanErrorInjectorTests, VulkanBackend);
|
||||
Reference in New Issue
Block a user