Adds testing infrastructure in DawnTest for error testing.
Bug: dawn:628 Change-Id: I80ef132a3ff0998d30a25cc5024e86905d859fb0 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/71240 Commit-Queue: Loko Kung <lokokung@google.com> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
e1e51e6c75
commit
25e41622c8
|
@ -1012,12 +1012,15 @@ void DawnTestBase::TearDown() {
|
||||||
ExpectDeviceDestruction();
|
ExpectDeviceDestruction();
|
||||||
}
|
}
|
||||||
|
|
||||||
void DawnTestBase::StartExpectDeviceError() {
|
void DawnTestBase::StartExpectDeviceError(testing::Matcher<std::string> errorMatcher) {
|
||||||
mExpectError = true;
|
mExpectError = true;
|
||||||
mError = false;
|
mError = false;
|
||||||
|
mErrorMatcher = errorMatcher;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool DawnTestBase::EndExpectDeviceError() {
|
bool DawnTestBase::EndExpectDeviceError() {
|
||||||
mExpectError = false;
|
mExpectError = false;
|
||||||
|
mErrorMatcher = testing::_;
|
||||||
return mError;
|
return mError;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1032,6 +1035,9 @@ void DawnTestBase::OnDeviceError(WGPUErrorType type, const char* message, void*
|
||||||
|
|
||||||
ASSERT_TRUE(self->mExpectError) << "Got unexpected device error: " << message;
|
ASSERT_TRUE(self->mExpectError) << "Got unexpected device error: " << message;
|
||||||
ASSERT_FALSE(self->mError) << "Got two errors in expect block";
|
ASSERT_FALSE(self->mError) << "Got two errors in expect block";
|
||||||
|
if (self->mExpectError) {
|
||||||
|
ASSERT_THAT(message, self->mErrorMatcher);
|
||||||
|
}
|
||||||
self->mError = true;
|
self->mError = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#include "utils/ScopedAutoreleasePool.h"
|
#include "utils/ScopedAutoreleasePool.h"
|
||||||
|
|
||||||
#include <dawn_platform/DawnPlatform.h>
|
#include <dawn_platform/DawnPlatform.h>
|
||||||
|
#include <gmock/gmock.h>
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
@ -94,10 +95,8 @@
|
||||||
|
|
||||||
#define EXPECT_TEXTURE_EQ(...) AddTextureExpectation(__FILE__, __LINE__, __VA_ARGS__)
|
#define EXPECT_TEXTURE_EQ(...) AddTextureExpectation(__FILE__, __LINE__, __VA_ARGS__)
|
||||||
|
|
||||||
// Should only be used to test validation of function that can't be tested by regular validation
|
#define ASSERT_DEVICE_ERROR_MSG(statement, matcher) \
|
||||||
// tests;
|
StartExpectDeviceError(matcher); \
|
||||||
#define ASSERT_DEVICE_ERROR(statement) \
|
|
||||||
StartExpectDeviceError(); \
|
|
||||||
statement; \
|
statement; \
|
||||||
FlushWire(); \
|
FlushWire(); \
|
||||||
if (!EndExpectDeviceError()) { \
|
if (!EndExpectDeviceError()) { \
|
||||||
|
@ -106,6 +105,8 @@
|
||||||
do { \
|
do { \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
#define ASSERT_DEVICE_ERROR(statement) ASSERT_DEVICE_ERROR_MSG(statement, testing::_)
|
||||||
|
|
||||||
struct RGBA8 {
|
struct RGBA8 {
|
||||||
constexpr RGBA8() : RGBA8(0, 0, 0, 0) {
|
constexpr RGBA8() : RGBA8(0, 0, 0, 0) {
|
||||||
}
|
}
|
||||||
|
@ -305,7 +306,7 @@ class DawnTestBase {
|
||||||
|
|
||||||
bool HasToggleEnabled(const char* workaround) const;
|
bool HasToggleEnabled(const char* workaround) const;
|
||||||
|
|
||||||
void StartExpectDeviceError();
|
void StartExpectDeviceError(testing::Matcher<std::string> errorMatcher = testing::_);
|
||||||
bool EndExpectDeviceError();
|
bool EndExpectDeviceError();
|
||||||
|
|
||||||
void ExpectDeviceDestruction();
|
void ExpectDeviceDestruction();
|
||||||
|
@ -507,6 +508,7 @@ class DawnTestBase {
|
||||||
static void OnDeviceLost(WGPUDeviceLostReason reason, const char* message, void* userdata);
|
static void OnDeviceLost(WGPUDeviceLostReason reason, const char* message, void* userdata);
|
||||||
bool mExpectError = false;
|
bool mExpectError = false;
|
||||||
bool mError = false;
|
bool mError = false;
|
||||||
|
testing::Matcher<std::string> mErrorMatcher;
|
||||||
bool mExpectDestruction = false;
|
bool mExpectDestruction = false;
|
||||||
|
|
||||||
std::ostringstream& AddTextureExpectationImpl(const char* file,
|
std::ostringstream& AddTextureExpectationImpl(const char* file,
|
||||||
|
|
|
@ -17,6 +17,8 @@
|
||||||
#include "utils/ComboRenderPipelineDescriptor.h"
|
#include "utils/ComboRenderPipelineDescriptor.h"
|
||||||
#include "utils/WGPUHelpers.h"
|
#include "utils/WGPUHelpers.h"
|
||||||
|
|
||||||
|
using ::testing::HasSubstr;
|
||||||
|
|
||||||
constexpr uint32_t kRTSize = 4;
|
constexpr uint32_t kRTSize = 4;
|
||||||
|
|
||||||
class DestroyTest : public DawnTest {
|
class DestroyTest : public DawnTest {
|
||||||
|
@ -174,7 +176,7 @@ TEST_P(DestroyTest, DestroyDeviceBeforeSubmit) {
|
||||||
// actually do, so we need to override the default device lost callback.
|
// actually do, so we need to override the default device lost callback.
|
||||||
ExpectDeviceDestruction();
|
ExpectDeviceDestruction();
|
||||||
device.Destroy();
|
device.Destroy();
|
||||||
ASSERT_DEVICE_ERROR(queue.Submit(1, &commands));
|
ASSERT_DEVICE_ERROR_MSG(queue.Submit(1, &commands), HasSubstr("[Device] is lost."));
|
||||||
}
|
}
|
||||||
|
|
||||||
DAWN_INSTANTIATE_TEST(DestroyTest,
|
DAWN_INSTANTIATE_TEST(DestroyTest,
|
||||||
|
|
Loading…
Reference in New Issue