Add missing "strlen" parameter for Device InjectError command.
This CL adds a StringMessageMatcher to the wire unittests harness to validate that messages are not degenerate. Bug: chromium:1004368 Change-Id: I121a259e67938b06ccc5e9829abfa3e25fffc003 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/11740 Commit-Queue: Corentin Wallez <cwallez@chromium.org> Reviewed-by: Kai Ninomiya <kainino@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
parent
4379e8f34f
commit
867f72058a
|
@ -543,7 +543,7 @@
|
|||
"name": "inject error",
|
||||
"args": [
|
||||
{"name": "type", "type": "error type"},
|
||||
{"name": "message", "type": "char", "annotation": "const*"}
|
||||
{"name": "message", "type": "char", "annotation": "const*", "length": "strlen"}
|
||||
],
|
||||
"TODO": "enga@: Make this a Dawn extension"
|
||||
},
|
||||
|
|
|
@ -193,7 +193,7 @@ TEST_F(WireErrorCallbackTests, PopErrorScopeDeviceDestroyed) {
|
|||
FlushClient();
|
||||
|
||||
// Incomplete callback called in Device destructor.
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(DAWN_ERROR_TYPE_UNKNOWN, _, this)).Times(1);
|
||||
EXPECT_CALL(*mockDevicePopErrorScopeCallback, Call(DAWN_ERROR_TYPE_UNKNOWN, ValidStringMessage(), this)).Times(1);
|
||||
}
|
||||
|
||||
// Test that PopErrorScope returns false if there are no error scopes.
|
||||
|
|
|
@ -107,18 +107,18 @@ TEST_F(WireFenceTests, QueueSignalSuccess) {
|
|||
// than or equal to the current signaled value
|
||||
TEST_F(WireFenceTests, QueueSignalValidationError) {
|
||||
dawnQueueSignal(queue, fence, 0u); // Error
|
||||
EXPECT_CALL(api, DeviceInjectError(apiDevice, DAWN_ERROR_TYPE_VALIDATION, _)).Times(1);
|
||||
EXPECT_CALL(api, DeviceInjectError(apiDevice, DAWN_ERROR_TYPE_VALIDATION, ValidStringMessage())).Times(1);
|
||||
FlushClient();
|
||||
|
||||
dawnQueueSignal(queue, fence, 1u); // Error
|
||||
EXPECT_CALL(api, DeviceInjectError(apiDevice, DAWN_ERROR_TYPE_VALIDATION, _)).Times(1);
|
||||
EXPECT_CALL(api, DeviceInjectError(apiDevice, DAWN_ERROR_TYPE_VALIDATION, ValidStringMessage())).Times(1);
|
||||
FlushClient();
|
||||
|
||||
DoQueueSignal(4u); // Success
|
||||
FlushClient();
|
||||
|
||||
dawnQueueSignal(queue, fence, 3u); // Error
|
||||
EXPECT_CALL(api, DeviceInjectError(apiDevice, DAWN_ERROR_TYPE_VALIDATION, _)).Times(1);
|
||||
EXPECT_CALL(api, DeviceInjectError(apiDevice, DAWN_ERROR_TYPE_VALIDATION, ValidStringMessage())).Times(1);
|
||||
FlushClient();
|
||||
}
|
||||
|
||||
|
@ -194,7 +194,7 @@ TEST_F(WireFenceTests, OnCompletionValidationError) {
|
|||
|
||||
dawnFenceOnCompletion(fence, 2u, ToMockFenceOnCompletionCallback, this + 0);
|
||||
|
||||
EXPECT_CALL(api, DeviceInjectError(apiDevice, DAWN_ERROR_TYPE_VALIDATION, _)).Times(1);
|
||||
EXPECT_CALL(api, DeviceInjectError(apiDevice, DAWN_ERROR_TYPE_VALIDATION, ValidStringMessage())).Times(1);
|
||||
FlushClient();
|
||||
}
|
||||
|
||||
|
@ -235,7 +235,7 @@ TEST_F(WireFenceTests, SignalWrongQueue) {
|
|||
FlushClient();
|
||||
|
||||
dawnQueueSignal(queue2, fence, 2u); // error
|
||||
EXPECT_CALL(api, DeviceInjectError(apiDevice, DAWN_ERROR_TYPE_VALIDATION, _)).Times(1);
|
||||
EXPECT_CALL(api, DeviceInjectError(apiDevice, DAWN_ERROR_TYPE_VALIDATION, ValidStringMessage())).Times(1);
|
||||
FlushClient();
|
||||
}
|
||||
|
||||
|
@ -247,7 +247,7 @@ TEST_F(WireFenceTests, SignalWrongQueueDoesNotUpdateValue) {
|
|||
FlushClient();
|
||||
|
||||
dawnQueueSignal(queue2, fence, 2u); // error
|
||||
EXPECT_CALL(api, DeviceInjectError(apiDevice, DAWN_ERROR_TYPE_VALIDATION, _)).Times(1);
|
||||
EXPECT_CALL(api, DeviceInjectError(apiDevice, DAWN_ERROR_TYPE_VALIDATION, ValidStringMessage())).Times(1);
|
||||
FlushClient();
|
||||
|
||||
// Fence value should be unchanged.
|
||||
|
|
|
@ -66,6 +66,35 @@ inline testing::Matcher<MatcherLambdaArgument<Lambda>> MatchesLambda(Lambda lamb
|
|||
return MakeMatcher(new LambdaMatcherImpl<Lambda, MatcherLambdaArgument<Lambda>>(lambda));
|
||||
}
|
||||
|
||||
class StringMessageMatcher : public testing::MatcherInterface<const char*> {
|
||||
public:
|
||||
explicit StringMessageMatcher() {}
|
||||
|
||||
bool MatchAndExplain(const char* message, testing::MatchResultListener* listener) const override {
|
||||
if (message == nullptr) {
|
||||
*listener << "missing error message";
|
||||
return false;
|
||||
}
|
||||
if (std::strlen(message) <= 1) {
|
||||
*listener << "message is truncated";
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void DescribeTo(std::ostream* os) const override {
|
||||
*os << "valid error message";
|
||||
}
|
||||
|
||||
void DescribeNegationTo(std::ostream* os) const override {
|
||||
*os << "invalid error message";
|
||||
}
|
||||
};
|
||||
|
||||
inline testing::Matcher<const char*> ValidStringMessage() {
|
||||
return MakeMatcher(new StringMessageMatcher());
|
||||
}
|
||||
|
||||
namespace dawn_wire {
|
||||
class WireClient;
|
||||
class WireServer;
|
||||
|
|
Loading…
Reference in New Issue