Member rename: src/tests

This commit is contained in:
Corentin Wallez 2017-11-23 11:51:16 -08:00 committed by Corentin Wallez
parent ad6470466c
commit d5d77af5b6
5 changed files with 80 additions and 80 deletions

View File

@ -95,13 +95,13 @@ namespace {
NXTTest::~NXTTest() { NXTTest::~NXTTest() {
// We need to destroy child objects before the Device // We need to destroy child objects before the Device
readbackSlots.clear(); mReadbackSlots.clear();
queue = nxt::Queue(); queue = nxt::Queue();
device = nxt::Device(); device = nxt::Device();
swapchain = nxt::SwapChain(); swapchain = nxt::SwapChain();
delete binding; delete mBinding;
binding = nullptr; mBinding = nullptr;
nxtSetProcs(nullptr); nxtSetProcs(nullptr);
} }
@ -123,26 +123,26 @@ bool NXTTest::IsVulkan() const {
} }
void NXTTest::SetUp() { void NXTTest::SetUp() {
binding = utils::CreateBinding(ParamToBackendType(GetParam())); mBinding = utils::CreateBinding(ParamToBackendType(GetParam()));
NXT_ASSERT(binding != nullptr); NXT_ASSERT(mBinding != nullptr);
GLFWwindow* testWindow = GetWindowForBackend(binding, GetParam()); GLFWwindow* testWindow = GetWindowForBackend(mBinding, GetParam());
NXT_ASSERT(testWindow != nullptr); NXT_ASSERT(testWindow != nullptr);
binding->SetWindow(testWindow); mBinding->SetWindow(testWindow);
nxtDevice backendDevice; nxtDevice backendDevice;
nxtProcTable backendProcs; nxtProcTable backendProcs;
binding->GetProcAndDevice(&backendProcs, &backendDevice); mBinding->GetProcAndDevice(&backendProcs, &backendDevice);
nxtSetProcs(&backendProcs); nxtSetProcs(&backendProcs);
device = nxt::Device::Acquire(backendDevice); device = nxt::Device::Acquire(backendDevice);
queue = device.CreateQueueBuilder().GetResult(); queue = device.CreateQueueBuilder().GetResult();
swapchain = device.CreateSwapChainBuilder() swapchain = device.CreateSwapChainBuilder()
.SetImplementation(binding->GetSwapChainImplementation()) .SetImplementation(mBinding->GetSwapChainImplementation())
.GetResult(); .GetResult();
swapchain.Configure(static_cast<nxt::TextureFormat>(binding->GetPreferredSwapChainTextureFormat()), swapchain.Configure(static_cast<nxt::TextureFormat>(mBinding->GetPreferredSwapChainTextureFormat()),
nxt::TextureUsageBit::OutputAttachment, 400, 400); nxt::TextureUsageBit::OutputAttachment, 400, 400);
device.SetErrorCallback(DeviceErrorCauseTestFailure, 0); device.SetErrorCallback(DeviceErrorCauseTestFailure, 0);
@ -152,11 +152,11 @@ void NXTTest::TearDown() {
MapSlotsSynchronously(); MapSlotsSynchronously();
ResolveExpectations(); ResolveExpectations();
for (size_t i = 0; i < readbackSlots.size(); ++i) { for (size_t i = 0; i < mReadbackSlots.size(); ++i) {
readbackSlots[i].buffer.Unmap(); mReadbackSlots[i].buffer.Unmap();
} }
for (auto& expectation : deferredExpectations) { for (auto& expectation : mDeferredExpectations) {
delete expectation.expectation; delete expectation.expectation;
expectation.expectation = nullptr; expectation.expectation = nullptr;
} }
@ -187,9 +187,9 @@ std::ostringstream& NXTTest::AddBufferExpectation(const char* file, int line, co
deferred.rowPitch = size; deferred.rowPitch = size;
deferred.expectation = expectation; deferred.expectation = expectation;
deferredExpectations.push_back(std::move(deferred)); mDeferredExpectations.push_back(std::move(deferred));
deferredExpectations.back().message = std::make_unique<std::ostringstream>(); mDeferredExpectations.back().message = std::make_unique<std::ostringstream>();
return *(deferredExpectations.back().message.get()); return *(mDeferredExpectations.back().message.get());
} }
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 level, 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 level, uint32_t pixelSize, detail::Expectation* expectation) {
@ -219,9 +219,9 @@ std::ostringstream& NXTTest::AddTextureExpectation(const char* file, int line, c
deferred.rowPitch = rowPitch; deferred.rowPitch = rowPitch;
deferred.expectation = expectation; deferred.expectation = expectation;
deferredExpectations.push_back(std::move(deferred)); mDeferredExpectations.push_back(std::move(deferred));
deferredExpectations.back().message = std::make_unique<std::ostringstream>(); mDeferredExpectations.back().message = std::make_unique<std::ostringstream>();
return *(deferredExpectations.back().message.get()); return *(mDeferredExpectations.back().message.get());
} }
void NXTTest::WaitABit() { void NXTTest::WaitABit() {
@ -249,28 +249,28 @@ NXTTest::ReadbackReservation NXTTest::ReserveReadback(uint32_t readbackSize) {
ReadbackReservation reservation; ReadbackReservation reservation;
reservation.buffer = slot.buffer.Clone(); reservation.buffer = slot.buffer.Clone();
reservation.slot = readbackSlots.size(); reservation.slot = mReadbackSlots.size();
reservation.offset = 0; reservation.offset = 0;
readbackSlots.push_back(std::move(slot)); mReadbackSlots.push_back(std::move(slot));
return reservation; return reservation;
} }
void NXTTest::MapSlotsSynchronously() { void NXTTest::MapSlotsSynchronously() {
// Initialize numPendingMapOperations before mapping, just in case the callback is called immediately. // Initialize numPendingMapOperations before mapping, just in case the callback is called immediately.
numPendingMapOperations = readbackSlots.size(); mNumPendingMapOperations = mReadbackSlots.size();
// Map all readback slots // Map all readback slots
for (size_t i = 0; i < readbackSlots.size(); ++i) { for (size_t i = 0; i < mReadbackSlots.size(); ++i) {
auto userdata = new MapReadUserdata{this, i}; auto userdata = new MapReadUserdata{this, i};
auto& slot = readbackSlots[i]; auto& slot = mReadbackSlots[i];
slot.buffer.TransitionUsage(nxt::BufferUsageBit::MapRead); slot.buffer.TransitionUsage(nxt::BufferUsageBit::MapRead);
slot.buffer.MapReadAsync(0, slot.bufferSize, SlotMapReadCallback, static_cast<nxt::CallbackUserdata>(reinterpret_cast<uintptr_t>(userdata))); slot.buffer.MapReadAsync(0, slot.bufferSize, SlotMapReadCallback, static_cast<nxt::CallbackUserdata>(reinterpret_cast<uintptr_t>(userdata)));
} }
// Busy wait until all map operations are done. // Busy wait until all map operations are done.
while (numPendingMapOperations != 0) { while (mNumPendingMapOperations != 0) {
WaitABit(); WaitABit();
} }
} }
@ -280,18 +280,18 @@ void NXTTest::SlotMapReadCallback(nxtBufferMapReadStatus status, const void* dat
NXT_ASSERT(status == NXT_BUFFER_MAP_READ_STATUS_SUCCESS); NXT_ASSERT(status == NXT_BUFFER_MAP_READ_STATUS_SUCCESS);
auto userdata = reinterpret_cast<MapReadUserdata*>(static_cast<uintptr_t>(userdata_)); auto userdata = reinterpret_cast<MapReadUserdata*>(static_cast<uintptr_t>(userdata_));
userdata->test->readbackSlots[userdata->slot].mappedData = data; userdata->test->mReadbackSlots[userdata->slot].mappedData = data;
userdata->test->numPendingMapOperations --; userdata->test->mNumPendingMapOperations --;
delete userdata; delete userdata;
} }
void NXTTest::ResolveExpectations() { void NXTTest::ResolveExpectations() {
for (const auto& expectation : deferredExpectations) { for (const auto& expectation : mDeferredExpectations) {
NXT_ASSERT(readbackSlots[expectation.readbackSlot].mappedData != nullptr); NXT_ASSERT(mReadbackSlots[expectation.readbackSlot].mappedData != nullptr);
// Get a pointer to the mapped copy of the data for the expectation. // Get a pointer to the mapped copy of the data for the expectation.
const char* data = reinterpret_cast<const char*>(readbackSlots[expectation.readbackSlot].mappedData); const char* data = reinterpret_cast<const char*>(mReadbackSlots[expectation.readbackSlot].mappedData);
data += expectation.readbackOffset; data += expectation.readbackOffset;
uint32_t size; uint32_t size;
@ -380,29 +380,29 @@ namespace detail {
template<typename T> template<typename T>
ExpectEq<T>::ExpectEq(T singleValue) { ExpectEq<T>::ExpectEq(T singleValue) {
expected.push_back(singleValue); mExpected.push_back(singleValue);
} }
template<typename T> template<typename T>
ExpectEq<T>::ExpectEq(const T* values, const unsigned int count) { ExpectEq<T>::ExpectEq(const T* values, const unsigned int count) {
expected.assign(values, values + count); mExpected.assign(values, values + count);
} }
template<typename T> template<typename T>
testing::AssertionResult ExpectEq<T>::Check(const void* data, size_t size) { testing::AssertionResult ExpectEq<T>::Check(const void* data, size_t size) {
NXT_ASSERT(size == sizeof(T) * expected.size()); NXT_ASSERT(size == sizeof(T) * mExpected.size());
const T* actual = reinterpret_cast<const T*>(data); const T* actual = reinterpret_cast<const T*>(data);
testing::AssertionResult failure = testing::AssertionFailure(); testing::AssertionResult failure = testing::AssertionFailure();
for (size_t i = 0; i < expected.size(); ++i) { for (size_t i = 0; i < mExpected.size(); ++i) {
if (actual[i] != expected[i]) { if (actual[i] != mExpected[i]) {
testing::AssertionResult result = testing::AssertionFailure() << "Expected data[" << i << "] to be " << expected[i] << ", actual " << actual[i] << std::endl; testing::AssertionResult result = testing::AssertionFailure() << "Expected data[" << i << "] to be " << mExpected[i] << ", actual " << actual[i] << std::endl;
auto printBuffer = [&](const T* buffer) { auto printBuffer = [&](const T* buffer) {
static constexpr unsigned int kBytes = sizeof(T); static constexpr unsigned int kBytes = sizeof(T);
for (size_t index = 0; index < expected.size(); ++index) { for (size_t index = 0; index < mExpected.size(); ++index) {
auto byteView = reinterpret_cast<const uint8_t*>(buffer + index); auto byteView = reinterpret_cast<const uint8_t*>(buffer + index);
for (unsigned int b = 0; b < kBytes; ++b) { for (unsigned int b = 0; b < kBytes; ++b) {
char buf[4]; char buf[4];
@ -413,9 +413,9 @@ namespace detail {
result << std::endl; result << std::endl;
}; };
if (expected.size() <= 1024) { if (mExpected.size() <= 1024) {
result << "Expected:" << std::endl; result << "Expected:" << std::endl;
printBuffer(expected.data()); printBuffer(mExpected.data());
result << "Actual:" << std::endl; result << "Actual:" << std::endl;
printBuffer(actual); printBuffer(actual);

View File

@ -94,12 +94,12 @@ class NXTTest : public ::testing::TestWithParam<BackendType> {
uint32_t bufferSize; uint32_t bufferSize;
const void* mappedData = nullptr; const void* mappedData = nullptr;
}; };
std::vector<ReadbackSlot> readbackSlots; std::vector<ReadbackSlot> mReadbackSlots;
// Maps all the buffers and fill ReadbackSlot::mappedData // Maps all the buffers and fill ReadbackSlot::mappedData
void MapSlotsSynchronously(); void MapSlotsSynchronously();
static void SlotMapReadCallback(nxtBufferMapReadStatus status, const void* data, nxtCallbackUserdata userdata); static void SlotMapReadCallback(nxtBufferMapReadStatus status, const void* data, nxtCallbackUserdata userdata);
size_t numPendingMapOperations = 0; size_t mNumPendingMapOperations = 0;
// Reserve space where the data for an expectation can be copied // Reserve space where the data for an expectation can be copied
struct ReadbackReservation { struct ReadbackReservation {
@ -122,12 +122,12 @@ class NXTTest : public ::testing::TestWithParam<BackendType> {
// Use unique_ptr because of missing move/copy constructors on std::basic_ostringstream // Use unique_ptr because of missing move/copy constructors on std::basic_ostringstream
std::unique_ptr<std::ostringstream> message; std::unique_ptr<std::ostringstream> message;
}; };
std::vector<DeferredExpectation> deferredExpectations; std::vector<DeferredExpectation> mDeferredExpectations;
// Assuming the data is mapped, checks all expectations // Assuming the data is mapped, checks all expectations
void ResolveExpectations(); void ResolveExpectations();
utils::BackendBinding* binding = nullptr; utils::BackendBinding* mBinding = nullptr;
}; };
// Instantiate the test once for each backend provided after the first argument. Use it like this: // Instantiate the test once for each backend provided after the first argument. Use it like this:
@ -162,7 +162,7 @@ namespace detail {
testing::AssertionResult Check(const void* data, size_t size) override; testing::AssertionResult Check(const void* data, size_t size) override;
private: private:
std::vector<T> expected; std::vector<T> mExpected;
}; };
extern template class ExpectEq<uint32_t>; extern template class ExpectEq<uint32_t>;
extern template class ExpectEq<RGBA8>; extern template class ExpectEq<RGBA8>;

View File

@ -55,7 +55,7 @@ static void ToMockBufferMapReadCallback(nxtBufferMapReadStatus status, const voi
class WireTestsBase : public Test { class WireTestsBase : public Test {
protected: protected:
WireTestsBase(bool ignoreSetCallbackCalls) WireTestsBase(bool ignoreSetCallbackCalls)
: ignoreSetCallbackCalls(ignoreSetCallbackCalls) { : mIgnoreSetCallbackCalls(ignoreSetCallbackCalls) {
} }
void SetUp() override { void SetUp() override {
@ -69,42 +69,42 @@ class WireTestsBase : public Test {
// This SetCallback call cannot be ignored because it is done as soon as we start the server // This SetCallback call cannot be ignored because it is done as soon as we start the server
EXPECT_CALL(api, OnDeviceSetErrorCallback(_, _, _)).Times(Exactly(1)); EXPECT_CALL(api, OnDeviceSetErrorCallback(_, _, _)).Times(Exactly(1));
if (ignoreSetCallbackCalls) { if (mIgnoreSetCallbackCalls) {
EXPECT_CALL(api, OnBuilderSetErrorCallback(_, _, _, _)).Times(AnyNumber()); EXPECT_CALL(api, OnBuilderSetErrorCallback(_, _, _, _)).Times(AnyNumber());
} }
EXPECT_CALL(api, DeviceTick(_)).Times(AnyNumber()); EXPECT_CALL(api, DeviceTick(_)).Times(AnyNumber());
s2cBuf = new TerribleCommandBuffer(); mS2cBuf = new TerribleCommandBuffer();
c2sBuf = new TerribleCommandBuffer(wireServer); mC2sBuf = new TerribleCommandBuffer(mWireServer);
wireServer = NewServerCommandHandler(mockDevice, mockProcs, s2cBuf); mWireServer = NewServerCommandHandler(mockDevice, mockProcs, mS2cBuf);
c2sBuf->SetHandler(wireServer); mC2sBuf->SetHandler(mWireServer);
nxtProcTable clientProcs; nxtProcTable clientProcs;
wireClient = NewClientDevice(&clientProcs, &device, c2sBuf); mWireClient = NewClientDevice(&clientProcs, &device, mC2sBuf);
nxtSetProcs(&clientProcs); nxtSetProcs(&clientProcs);
s2cBuf->SetHandler(wireClient); mS2cBuf->SetHandler(mWireClient);
apiDevice = mockDevice; apiDevice = mockDevice;
} }
void TearDown() override { void TearDown() override {
nxtSetProcs(nullptr); nxtSetProcs(nullptr);
delete wireServer; delete mWireServer;
delete wireClient; delete mWireClient;
delete c2sBuf; delete mC2sBuf;
delete s2cBuf; delete mS2cBuf;
delete mockDeviceErrorCallback; delete mockDeviceErrorCallback;
delete mockBuilderErrorCallback; delete mockBuilderErrorCallback;
delete mockBufferMapReadCallback; delete mockBufferMapReadCallback;
} }
void FlushClient() { void FlushClient() {
c2sBuf->Flush(); mC2sBuf->Flush();
} }
void FlushServer() { void FlushServer() {
s2cBuf->Flush(); mS2cBuf->Flush();
} }
MockProcTable api; MockProcTable api;
@ -112,12 +112,12 @@ class WireTestsBase : public Test {
nxtDevice device; nxtDevice device;
private: private:
bool ignoreSetCallbackCalls = false; bool mIgnoreSetCallbackCalls = false;
CommandHandler* wireServer = nullptr; CommandHandler* mWireServer = nullptr;
CommandHandler* wireClient = nullptr; CommandHandler* mWireClient = nullptr;
TerribleCommandBuffer* s2cBuf = nullptr; TerribleCommandBuffer* mS2cBuf = nullptr;
TerribleCommandBuffer* c2sBuf = nullptr; TerribleCommandBuffer* mC2sBuf = nullptr;
}; };
class WireTests : public WireTestsBase { class WireTests : public WireTestsBase {

View File

@ -41,9 +41,9 @@ ValidationTest::~ValidationTest() {
} }
void ValidationTest::TearDown() { void ValidationTest::TearDown() {
ASSERT_FALSE(expectError); ASSERT_FALSE(mExpectError);
for (auto& expectation : expectations) { for (auto& expectation : mExpectations) {
std::string name = expectation.debugName; std::string name = expectation.debugName;
if (name.empty()) { if (name.empty()) {
name = "<no debug name set>"; name = "<no debug name set>";
@ -61,12 +61,12 @@ void ValidationTest::TearDown() {
} }
void ValidationTest::StartExpectDeviceError() { void ValidationTest::StartExpectDeviceError() {
expectError = true; mExpectError = true;
error = false; mError = false;
} }
bool ValidationTest::EndExpectDeviceError() { bool ValidationTest::EndExpectDeviceError() {
expectError = false; mExpectError = false;
return error; return mError;
} }
void ValidationTest::CreateSimpleRenderPassAndFramebuffer(const nxt::Device& device, nxt::RenderPass* renderpass, nxt::Framebuffer* framebuffer) { void ValidationTest::CreateSimpleRenderPassAndFramebuffer(const nxt::Device& device, nxt::RenderPass* renderpass, nxt::Framebuffer* framebuffer) {
@ -104,18 +104,18 @@ void ValidationTest::OnDeviceError(const char* message, nxtCallbackUserdata user
} }
auto self = reinterpret_cast<ValidationTest*>(static_cast<uintptr_t>(userdata)); auto self = reinterpret_cast<ValidationTest*>(static_cast<uintptr_t>(userdata));
ASSERT_TRUE(self->expectError) << "Got unexpected device error: " << message; ASSERT_TRUE(self->mExpectError) << "Got unexpected device error: " << message;
ASSERT_FALSE(self->error) << "Got two errors in expect block"; ASSERT_FALSE(self->mError) << "Got two errors in expect block";
self->error = true; self->mError = true;
} }
void ValidationTest::OnBuilderErrorStatus(nxtBuilderErrorStatus status, const char* message, nxt::CallbackUserdata userdata1, nxt::CallbackUserdata userdata2) { void ValidationTest::OnBuilderErrorStatus(nxtBuilderErrorStatus status, const char* message, nxt::CallbackUserdata userdata1, nxt::CallbackUserdata userdata2) {
auto* self = reinterpret_cast<ValidationTest*>(static_cast<uintptr_t>(userdata1)); auto* self = reinterpret_cast<ValidationTest*>(static_cast<uintptr_t>(userdata1));
size_t index = static_cast<size_t>(userdata2); size_t index = static_cast<size_t>(userdata2);
ASSERT_LT(index, self->expectations.size()); ASSERT_LT(index, self->mExpectations.size());
auto& expectation = self->expectations[index]; auto& expectation = self->mExpectations[index];
ASSERT_FALSE(expectation.gotStatus); ASSERT_FALSE(expectation.gotStatus);
expectation.gotStatus = true; expectation.gotStatus = true;
expectation.status = status; expectation.status = status;

View File

@ -67,8 +67,8 @@ class ValidationTest : public testing::Test {
private: private:
static void OnDeviceError(const char* message, nxtCallbackUserdata userdata); static void OnDeviceError(const char* message, nxtCallbackUserdata userdata);
bool expectError = false; bool mExpectError = false;
bool error = false; bool mError = false;
struct BuilderStatusExpectations { struct BuilderStatusExpectations {
bool expectSuccess; bool expectSuccess;
@ -78,7 +78,7 @@ class ValidationTest : public testing::Test {
std::string statusMessage; std::string statusMessage;
nxtBuilderErrorStatus status; nxtBuilderErrorStatus status;
}; };
std::vector<BuilderStatusExpectations> expectations; std::vector<BuilderStatusExpectations> mExpectations;
template<typename Builder> template<typename Builder>
Builder AddExpectation(Builder& builder, std::string debugName, bool expectSuccess); Builder AddExpectation(Builder& builder, std::string debugName, bool expectSuccess);
@ -101,11 +101,11 @@ Builder ValidationTest::AssertWillBeError(Builder builder, std::string debugName
template<typename Builder> template<typename Builder>
Builder ValidationTest::AddExpectation(Builder& builder, std::string debugName, bool expectSuccess) { Builder ValidationTest::AddExpectation(Builder& builder, std::string debugName, bool expectSuccess) {
uint64_t userdata1 = reinterpret_cast<uintptr_t>(this); uint64_t userdata1 = reinterpret_cast<uintptr_t>(this);
uint64_t userdata2 = expectations.size(); uint64_t userdata2 = mExpectations.size();
builder.SetErrorCallback(OnBuilderErrorStatus, userdata1, userdata2); builder.SetErrorCallback(OnBuilderErrorStatus, userdata1, userdata2);
expectations.emplace_back(); mExpectations.emplace_back();
auto& expectation = expectations.back(); auto& expectation = mExpectations.back();
expectation.expectSuccess = expectSuccess; expectation.expectSuccess = expectSuccess;
expectation.debugName = debugName; expectation.debugName = debugName;