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

View File

@ -94,12 +94,12 @@ class NXTTest : public ::testing::TestWithParam<BackendType> {
uint32_t bufferSize;
const void* mappedData = nullptr;
};
std::vector<ReadbackSlot> readbackSlots;
std::vector<ReadbackSlot> mReadbackSlots;
// Maps all the buffers and fill ReadbackSlot::mappedData
void MapSlotsSynchronously();
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
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
std::unique_ptr<std::ostringstream> message;
};
std::vector<DeferredExpectation> deferredExpectations;
std::vector<DeferredExpectation> mDeferredExpectations;
// Assuming the data is mapped, checks all expectations
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:
@ -162,7 +162,7 @@ namespace detail {
testing::AssertionResult Check(const void* data, size_t size) override;
private:
std::vector<T> expected;
std::vector<T> mExpected;
};
extern template class ExpectEq<uint32_t>;
extern template class ExpectEq<RGBA8>;

View File

@ -55,7 +55,7 @@ static void ToMockBufferMapReadCallback(nxtBufferMapReadStatus status, const voi
class WireTestsBase : public Test {
protected:
WireTestsBase(bool ignoreSetCallbackCalls)
: ignoreSetCallbackCalls(ignoreSetCallbackCalls) {
: mIgnoreSetCallbackCalls(ignoreSetCallbackCalls) {
}
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
EXPECT_CALL(api, OnDeviceSetErrorCallback(_, _, _)).Times(Exactly(1));
if (ignoreSetCallbackCalls) {
if (mIgnoreSetCallbackCalls) {
EXPECT_CALL(api, OnBuilderSetErrorCallback(_, _, _, _)).Times(AnyNumber());
}
EXPECT_CALL(api, DeviceTick(_)).Times(AnyNumber());
s2cBuf = new TerribleCommandBuffer();
c2sBuf = new TerribleCommandBuffer(wireServer);
mS2cBuf = new TerribleCommandBuffer();
mC2sBuf = new TerribleCommandBuffer(mWireServer);
wireServer = NewServerCommandHandler(mockDevice, mockProcs, s2cBuf);
c2sBuf->SetHandler(wireServer);
mWireServer = NewServerCommandHandler(mockDevice, mockProcs, mS2cBuf);
mC2sBuf->SetHandler(mWireServer);
nxtProcTable clientProcs;
wireClient = NewClientDevice(&clientProcs, &device, c2sBuf);
mWireClient = NewClientDevice(&clientProcs, &device, mC2sBuf);
nxtSetProcs(&clientProcs);
s2cBuf->SetHandler(wireClient);
mS2cBuf->SetHandler(mWireClient);
apiDevice = mockDevice;
}
void TearDown() override {
nxtSetProcs(nullptr);
delete wireServer;
delete wireClient;
delete c2sBuf;
delete s2cBuf;
delete mWireServer;
delete mWireClient;
delete mC2sBuf;
delete mS2cBuf;
delete mockDeviceErrorCallback;
delete mockBuilderErrorCallback;
delete mockBufferMapReadCallback;
}
void FlushClient() {
c2sBuf->Flush();
mC2sBuf->Flush();
}
void FlushServer() {
s2cBuf->Flush();
mS2cBuf->Flush();
}
MockProcTable api;
@ -112,12 +112,12 @@ class WireTestsBase : public Test {
nxtDevice device;
private:
bool ignoreSetCallbackCalls = false;
bool mIgnoreSetCallbackCalls = false;
CommandHandler* wireServer = nullptr;
CommandHandler* wireClient = nullptr;
TerribleCommandBuffer* s2cBuf = nullptr;
TerribleCommandBuffer* c2sBuf = nullptr;
CommandHandler* mWireServer = nullptr;
CommandHandler* mWireClient = nullptr;
TerribleCommandBuffer* mS2cBuf = nullptr;
TerribleCommandBuffer* mC2sBuf = nullptr;
};
class WireTests : public WireTestsBase {

View File

@ -41,9 +41,9 @@ ValidationTest::~ValidationTest() {
}
void ValidationTest::TearDown() {
ASSERT_FALSE(expectError);
ASSERT_FALSE(mExpectError);
for (auto& expectation : expectations) {
for (auto& expectation : mExpectations) {
std::string name = expectation.debugName;
if (name.empty()) {
name = "<no debug name set>";
@ -61,12 +61,12 @@ void ValidationTest::TearDown() {
}
void ValidationTest::StartExpectDeviceError() {
expectError = true;
error = false;
mExpectError = true;
mError = false;
}
bool ValidationTest::EndExpectDeviceError() {
expectError = false;
return error;
mExpectError = false;
return mError;
}
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));
ASSERT_TRUE(self->expectError) << "Got unexpected device error: " << message;
ASSERT_FALSE(self->error) << "Got two errors in expect block";
self->error = true;
ASSERT_TRUE(self->mExpectError) << "Got unexpected device error: " << message;
ASSERT_FALSE(self->mError) << "Got two errors in expect block";
self->mError = true;
}
void ValidationTest::OnBuilderErrorStatus(nxtBuilderErrorStatus status, const char* message, nxt::CallbackUserdata userdata1, nxt::CallbackUserdata userdata2) {
auto* self = reinterpret_cast<ValidationTest*>(static_cast<uintptr_t>(userdata1));
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);
expectation.gotStatus = true;
expectation.status = status;

View File

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