From 4234c39a091986c667a532711808c54c7e8e31d4 Mon Sep 17 00:00:00 2001 From: Austin Eng Date: Mon, 17 Jul 2017 09:37:08 -0400 Subject: [PATCH] Add output string streams to NXT test expectation helpers --- src/tests/NXTTest.cpp | 15 ++++++++++----- src/tests/NXTTest.h | 14 +++++++++----- 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/tests/NXTTest.cpp b/src/tests/NXTTest.cpp index b65605b2c1..888d0551d4 100644 --- a/src/tests/NXTTest.cpp +++ b/src/tests/NXTTest.cpp @@ -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(); auto readback = ReserveReadback(size); @@ -175,10 +175,12 @@ void NXTTest::AddBufferExpectation(const char* file, int line, const nxt::Buffer deferred.rowPitch = size; deferred.expectation = expectation; - deferredExpectations.push_back(deferred); + deferredExpectations.push_back(std::move(deferred)); + deferredExpectations.back().message = std::make_unique(); + 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(); uint32_t rowPitch = Align(width * pixelSize, kTextureRowPitchAlignment); 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.expectation = expectation; - deferredExpectations.push_back(deferred); + deferredExpectations.push_back(std::move(deferred)); + deferredExpectations.back().message = std::make_unique(); + return *(deferredExpectations.back().message.get()); } void NXTTest::WaitABit() { @@ -296,7 +300,8 @@ void NXTTest::ResolveExpectations() { // Get the result for the expectation and add context to failures testing::AssertionResult result = expectation.expectation->Check(data, size); 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); diff --git a/src/tests/NXTTest.h b/src/tests/NXTTest.h index b3fc0241ca..57c21efba2 100644 --- a/src/tests/NXTTest.h +++ b/src/tests/NXTTest.h @@ -15,19 +15,20 @@ #include "nxt/nxtcpp.h" #include +#include // 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 // 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) \ - AddBufferExpectation(__FILE__, __LINE__, buffer, offset, sizeof(uint32_t), new detail::ExpectEq(expected)); + AddBufferExpectation(__FILE__, __LINE__, buffer, offset, sizeof(uint32_t), new detail::ExpectEq(expected)) #define EXPECT_BUFFER_U32_RANGE_EQ(expected, buffer, offset, count) \ - AddBufferExpectation(__FILE__, __LINE__, buffer, offset, sizeof(uint32_t) * count, new detail::ExpectEq(expected, count)); + AddBufferExpectation(__FILE__, __LINE__, buffer, offset, sizeof(uint32_t) * count, new detail::ExpectEq(expected, count)) // Test a pixel of the mip level 0 of a 2D texture. #define EXPECT_PIXEL_RGBA8_EQ(expected, texture, x, y) \ - AddTextureExpectation(__FILE__, __LINE__, texture, x, y, 1, 1, sizeof(RGBA8), new detail::ExpectEq(expected)); + AddTextureExpectation(__FILE__, __LINE__, texture, x, y, 1, 1, sizeof(RGBA8), new detail::ExpectEq(expected)) struct RGBA8 { 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 { nxt::Queue queue; // 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); - 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& AddBufferExpectation(const char* file, int line, const nxt::Buffer& buffer, uint32_t offset, uint32_t size, 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 SwapBuffers(); @@ -111,6 +112,9 @@ class NXTTest : public ::testing::TestWithParam { uint32_t rowBytes; uint32_t rowPitch; 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 message; }; std::vector deferredExpectations;