Adds validation tests for new device.Tick behavior based on internal and API calls.
Bug: dawn:628 Change-Id: I4de0a32fd18dc620637777754304df4634bbac66 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/77720 Reviewed-by: Kai Ninomiya <kainino@chromium.org> Commit-Queue: Loko Kung <lokokung@google.com>
This commit is contained in:
parent
03373965e3
commit
a52dc04ee3
|
@ -236,6 +236,7 @@ test("dawn_unittests") {
|
|||
"unittests/validation/CopyCommandsValidationTests.cpp",
|
||||
"unittests/validation/CopyTextureForBrowserTests.cpp",
|
||||
"unittests/validation/DebugMarkerValidationTests.cpp",
|
||||
"unittests/validation/DeviceValidationTests.cpp",
|
||||
"unittests/validation/DrawIndirectValidationTests.cpp",
|
||||
"unittests/validation/DrawVertexAndIndexBufferOOBValidationTests.cpp",
|
||||
"unittests/validation/DynamicStateCommandValidationTests.cpp",
|
||||
|
@ -257,7 +258,6 @@ test("dawn_unittests") {
|
|||
"unittests/validation/RenderBundleValidationTests.cpp",
|
||||
"unittests/validation/RenderPassDescriptorValidationTests.cpp",
|
||||
"unittests/validation/RenderPipelineValidationTests.cpp",
|
||||
"unittests/validation/RequestDeviceValidationTests.cpp",
|
||||
"unittests/validation/ResourceUsageTrackingTests.cpp",
|
||||
"unittests/validation/SamplerValidationTests.cpp",
|
||||
"unittests/validation/ShaderModuleValidationTests.cpp",
|
||||
|
|
|
@ -14,6 +14,11 @@
|
|||
|
||||
#include "tests/unittests/validation/ValidationTest.h"
|
||||
|
||||
#include "dawn_native/Device.h"
|
||||
#include "dawn_native/dawn_platform.h"
|
||||
|
||||
using ::testing::HasSubstr;
|
||||
|
||||
class RequestDeviceValidationTest : public ValidationTest {
|
||||
protected:
|
||||
void SetUp() {
|
||||
|
@ -203,3 +208,23 @@ TEST_F(RequestDeviceValidationTest, InvalidChainedStruct) {
|
|||
descriptor.requiredLimits = &limits;
|
||||
adapter.RequestDevice(&descriptor, ExpectRequestDeviceError, nullptr);
|
||||
}
|
||||
|
||||
class DeviceTickValidationTest : public ValidationTest {};
|
||||
|
||||
// Device destroy before API-level Tick should always result in no-op and false.
|
||||
TEST_F(DeviceTickValidationTest, DestroyDeviceBeforeAPITick) {
|
||||
ExpectDeviceDestruction();
|
||||
device.Destroy();
|
||||
device.Tick();
|
||||
}
|
||||
|
||||
// Device destroy before an internal Tick should return an error.
|
||||
TEST_F(DeviceTickValidationTest, DestroyDeviceBeforeInternalTick) {
|
||||
DAWN_SKIP_TEST_IF(UsesWire());
|
||||
|
||||
ExpectDeviceDestruction();
|
||||
device.Destroy();
|
||||
dawn::native::DeviceBase* nativeDevice = dawn::native::FromAPI(device.Get());
|
||||
ASSERT_DEVICE_ERROR(nativeDevice->ConsumedError(nativeDevice->Tick()),
|
||||
HasSubstr("[Device] is lost."));
|
||||
}
|
|
@ -197,12 +197,13 @@ TEST_F(ErrorScopeValidationTest, DeviceDestroyedBeforeCallback) {
|
|||
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(WGPUErrorType_Unknown, _, this))
|
||||
.Times(1);
|
||||
ExpectDeviceDestruction();
|
||||
device = nullptr;
|
||||
} else {
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(WGPUErrorType_NoError, _, this))
|
||||
.Times(1);
|
||||
device.PopErrorScope(ToMockDevicePopErrorScopeCallback, this);
|
||||
|
||||
ExpectDeviceDestruction();
|
||||
device = nullptr;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -105,6 +105,7 @@ void ValidationTest::SetUp() {
|
|||
|
||||
std::tie(device, backendDevice) = mWireHelper->RegisterDevice(CreateTestDevice());
|
||||
device.SetUncapturedErrorCallback(ValidationTest::OnDeviceError, this);
|
||||
device.SetDeviceLostCallback(ValidationTest::OnDeviceLost, this);
|
||||
|
||||
std::string traceName =
|
||||
std::string(::testing::UnitTest::GetInstance()->current_test_info()->test_suite_name()) +
|
||||
|
@ -127,6 +128,9 @@ void ValidationTest::TearDown() {
|
|||
EXPECT_EQ(mLastWarningCount,
|
||||
dawn::native::GetDeprecationWarningCountForTesting(backendDevice));
|
||||
}
|
||||
|
||||
// The device will be destroyed soon after, so we want to set the expectation.
|
||||
ExpectDeviceDestruction();
|
||||
}
|
||||
|
||||
void ValidationTest::StartExpectDeviceError(testing::Matcher<std::string> errorMatcher) {
|
||||
|
@ -148,6 +152,10 @@ std::string ValidationTest::GetLastDeviceErrorMessage() const {
|
|||
return mDeviceErrorMessage;
|
||||
}
|
||||
|
||||
void ValidationTest::ExpectDeviceDestruction() {
|
||||
mExpectDestruction = true;
|
||||
}
|
||||
|
||||
wgpu::Device ValidationTest::RegisterDevice(WGPUDevice backendDevice) {
|
||||
return mWireHelper->RegisterDevice(backendDevice).first;
|
||||
}
|
||||
|
@ -232,6 +240,18 @@ void ValidationTest::OnDeviceError(WGPUErrorType type, const char* message, void
|
|||
self->mError = true;
|
||||
}
|
||||
|
||||
void ValidationTest::OnDeviceLost(WGPUDeviceLostReason reason,
|
||||
const char* message,
|
||||
void* userdata) {
|
||||
auto self = static_cast<ValidationTest*>(userdata);
|
||||
if (self->mExpectDestruction) {
|
||||
EXPECT_EQ(reason, WGPUDeviceLostReason_Destroyed);
|
||||
return;
|
||||
}
|
||||
ADD_FAILURE() << "Device lost during test: " << message;
|
||||
ASSERT(false);
|
||||
}
|
||||
|
||||
ValidationTest::DummyRenderPass::DummyRenderPass(const wgpu::Device& device)
|
||||
: attachmentFormat(wgpu::TextureFormat::RGBA8Unorm), width(400), height(400) {
|
||||
wgpu::TextureDescriptor descriptor;
|
||||
|
|
|
@ -104,6 +104,8 @@ class ValidationTest : public testing::Test {
|
|||
bool EndExpectDeviceError();
|
||||
std::string GetLastDeviceErrorMessage() const;
|
||||
|
||||
void ExpectDeviceDestruction();
|
||||
|
||||
wgpu::Device RegisterDevice(WGPUDevice backendDevice);
|
||||
|
||||
bool UsesWire() const;
|
||||
|
@ -146,10 +148,12 @@ class ValidationTest : public testing::Test {
|
|||
std::unique_ptr<utils::WireHelper> mWireHelper;
|
||||
|
||||
static void OnDeviceError(WGPUErrorType type, const char* message, void* userdata);
|
||||
static void OnDeviceLost(WGPUDeviceLostReason reason, const char* message, void* userdata);
|
||||
std::string mDeviceErrorMessage;
|
||||
bool mExpectError = false;
|
||||
bool mError = false;
|
||||
testing::Matcher<std::string> mErrorMatcher;
|
||||
bool mExpectDestruction = false;
|
||||
};
|
||||
|
||||
#endif // TESTS_UNITTESTS_VALIDATIONTEST_H_
|
||||
|
|
Loading…
Reference in New Issue