mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-07-09 14:45:58 +00:00
Add output string streams to NXT test expectation helpers
This commit is contained in:
parent
59dc03f101
commit
4234c39a09
@ -150,7 +150,7 @@ void NXTTest::TearDown() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void NXTTest::AddBufferExpectation(const char* file, int line, const nxt::Buffer& buffer, uint32_t offset, uint32_t size, detail::Expectation* expectation) {
|
std::ostringstream& NXTTest::AddBufferExpectation(const char* file, int line, const nxt::Buffer& buffer, uint32_t offset, uint32_t size, detail::Expectation* expectation) {
|
||||||
nxt::Buffer source = buffer.Clone();
|
nxt::Buffer source = buffer.Clone();
|
||||||
|
|
||||||
auto readback = ReserveReadback(size);
|
auto readback = ReserveReadback(size);
|
||||||
@ -175,10 +175,12 @@ void NXTTest::AddBufferExpectation(const char* file, int line, const nxt::Buffer
|
|||||||
deferred.rowPitch = size;
|
deferred.rowPitch = size;
|
||||||
deferred.expectation = expectation;
|
deferred.expectation = expectation;
|
||||||
|
|
||||||
deferredExpectations.push_back(deferred);
|
deferredExpectations.push_back(std::move(deferred));
|
||||||
|
deferredExpectations.back().message = std::make_unique<std::ostringstream>();
|
||||||
|
return *(deferredExpectations.back().message.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
void NXTTest::AddTextureExpectation(const char* file, int line, const nxt::Texture& texture, uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint32_t pixelSize, detail::Expectation* expectation) {
|
std::ostringstream& NXTTest::AddTextureExpectation(const char* file, int line, const nxt::Texture& texture, uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint32_t pixelSize, detail::Expectation* expectation) {
|
||||||
nxt::Texture source = texture.Clone();
|
nxt::Texture source = texture.Clone();
|
||||||
uint32_t rowPitch = Align(width * pixelSize, kTextureRowPitchAlignment);
|
uint32_t rowPitch = Align(width * pixelSize, kTextureRowPitchAlignment);
|
||||||
uint32_t size = rowPitch * (height - 1) + width * pixelSize;
|
uint32_t size = rowPitch * (height - 1) + width * pixelSize;
|
||||||
@ -205,7 +207,9 @@ void NXTTest::AddTextureExpectation(const char* file, int line, const nxt::Textu
|
|||||||
deferred.rowPitch = rowPitch;
|
deferred.rowPitch = rowPitch;
|
||||||
deferred.expectation = expectation;
|
deferred.expectation = expectation;
|
||||||
|
|
||||||
deferredExpectations.push_back(deferred);
|
deferredExpectations.push_back(std::move(deferred));
|
||||||
|
deferredExpectations.back().message = std::make_unique<std::ostringstream>();
|
||||||
|
return *(deferredExpectations.back().message.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
void NXTTest::WaitABit() {
|
void NXTTest::WaitABit() {
|
||||||
@ -296,7 +300,8 @@ void NXTTest::ResolveExpectations() {
|
|||||||
// Get the result for the expectation and add context to failures
|
// Get the result for the expectation and add context to failures
|
||||||
testing::AssertionResult result = expectation.expectation->Check(data, size);
|
testing::AssertionResult result = expectation.expectation->Check(data, size);
|
||||||
if (!result) {
|
if (!result) {
|
||||||
result << " Expectation created at " << expectation.file << ":" << expectation.line;
|
result << " Expectation created at " << expectation.file << ":" << expectation.line << std::endl;
|
||||||
|
result << expectation.message->str();
|
||||||
}
|
}
|
||||||
|
|
||||||
EXPECT_TRUE(result);
|
EXPECT_TRUE(result);
|
||||||
|
@ -15,19 +15,20 @@
|
|||||||
#include "nxt/nxtcpp.h"
|
#include "nxt/nxtcpp.h"
|
||||||
|
|
||||||
#include <gtest/gtest.h>
|
#include <gtest/gtest.h>
|
||||||
|
#include <memory>
|
||||||
|
|
||||||
// Getting data back from NXT is done in an async manners so all expectations are "deferred"
|
// Getting data back from NXT is done in an async manners so all expectations are "deferred"
|
||||||
// until the end of the test. Also expectations use a copy to a MapRead buffer to get the data
|
// until the end of the test. Also expectations use a copy to a MapRead buffer to get the data
|
||||||
// so resources should have the TransferSrc allowed usage bit if you want to add expectations on them.
|
// so resources should have the TransferSrc allowed usage bit if you want to add expectations on them.
|
||||||
#define EXPECT_BUFFER_U32_EQ(expected, buffer, offset) \
|
#define EXPECT_BUFFER_U32_EQ(expected, buffer, offset) \
|
||||||
AddBufferExpectation(__FILE__, __LINE__, buffer, offset, sizeof(uint32_t), new detail::ExpectEq<uint32_t>(expected));
|
AddBufferExpectation(__FILE__, __LINE__, buffer, offset, sizeof(uint32_t), new detail::ExpectEq<uint32_t>(expected))
|
||||||
|
|
||||||
#define EXPECT_BUFFER_U32_RANGE_EQ(expected, buffer, offset, count) \
|
#define EXPECT_BUFFER_U32_RANGE_EQ(expected, buffer, offset, count) \
|
||||||
AddBufferExpectation(__FILE__, __LINE__, buffer, offset, sizeof(uint32_t) * count, new detail::ExpectEq<uint32_t>(expected, count));
|
AddBufferExpectation(__FILE__, __LINE__, buffer, offset, sizeof(uint32_t) * count, new detail::ExpectEq<uint32_t>(expected, count))
|
||||||
|
|
||||||
// Test a pixel of the mip level 0 of a 2D texture.
|
// Test a pixel of the mip level 0 of a 2D texture.
|
||||||
#define EXPECT_PIXEL_RGBA8_EQ(expected, texture, x, y) \
|
#define EXPECT_PIXEL_RGBA8_EQ(expected, texture, x, y) \
|
||||||
AddTextureExpectation(__FILE__, __LINE__, texture, x, y, 1, 1, sizeof(RGBA8), new detail::ExpectEq<RGBA8>(expected));
|
AddTextureExpectation(__FILE__, __LINE__, texture, x, y, 1, 1, sizeof(RGBA8), new detail::ExpectEq<RGBA8>(expected))
|
||||||
|
|
||||||
struct RGBA8 {
|
struct RGBA8 {
|
||||||
constexpr RGBA8(uint8_t r, uint8_t g, uint8_t b, uint8_t a): r(r), g(g), b(b), a(a) {
|
constexpr RGBA8(uint8_t r, uint8_t g, uint8_t b, uint8_t a): r(r), g(g), b(b), a(a) {
|
||||||
@ -74,8 +75,8 @@ class NXTTest : public ::testing::TestWithParam<BackendType> {
|
|||||||
nxt::Queue queue;
|
nxt::Queue queue;
|
||||||
|
|
||||||
// Helper methods to implement the EXPECT_ macros
|
// Helper methods to implement the EXPECT_ macros
|
||||||
void AddBufferExpectation(const char* file, int line, const nxt::Buffer& buffer, uint32_t offset, uint32_t size, detail::Expectation* expectation);
|
std::ostringstream& AddBufferExpectation(const char* file, int line, const nxt::Buffer& buffer, uint32_t offset, uint32_t size, detail::Expectation* expectation);
|
||||||
void AddTextureExpectation(const char* file, int line, const nxt::Texture& texture, uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint32_t pixelSize, detail::Expectation* expectation);
|
std::ostringstream& AddTextureExpectation(const char* file, int line, const nxt::Texture& texture, uint32_t x, uint32_t y, uint32_t width, uint32_t height, uint32_t pixelSize, detail::Expectation* expectation);
|
||||||
|
|
||||||
void WaitABit();
|
void WaitABit();
|
||||||
void SwapBuffers();
|
void SwapBuffers();
|
||||||
@ -111,6 +112,9 @@ class NXTTest : public ::testing::TestWithParam<BackendType> {
|
|||||||
uint32_t rowBytes;
|
uint32_t rowBytes;
|
||||||
uint32_t rowPitch;
|
uint32_t rowPitch;
|
||||||
detail::Expectation* expectation;
|
detail::Expectation* expectation;
|
||||||
|
// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=54316
|
||||||
|
// Use unique_ptr because of missing move/copy constructors on std::basic_ostringstream
|
||||||
|
std::unique_ptr<std::ostringstream> message;
|
||||||
};
|
};
|
||||||
std::vector<DeferredExpectation> deferredExpectations;
|
std::vector<DeferredExpectation> deferredExpectations;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user