Add wire tests for passing arguments around
- Add test for passing value arguments as well as aarrays of them - Add test for passing C string - Rework Object array argument test to pass multiple objects
This commit is contained in:
parent
1b7c5e3f70
commit
c85b5c0640
|
@ -144,6 +144,79 @@ TEST_F(WireTests, ReleaseCalledOnRefCount0) {
|
||||||
FlushClient();
|
FlushClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Test that the wire is able to send numerical values
|
||||||
|
TEST_F(WireTests, ValueArgument) {
|
||||||
|
nxtSamplerBuilder builder = nxtDeviceCreateSamplerBuilder(device);
|
||||||
|
nxtSamplerBuilderSetFilterMode(builder, NXT_FILTER_MODE_LINEAR, NXT_FILTER_MODE_LINEAR, NXT_FILTER_MODE_NEAREST);
|
||||||
|
|
||||||
|
nxtSamplerBuilder apiBuilder = api.GetNewSamplerBuilder();
|
||||||
|
EXPECT_CALL(api, DeviceCreateSamplerBuilder(apiDevice))
|
||||||
|
.WillOnce(Return(apiBuilder));
|
||||||
|
|
||||||
|
EXPECT_CALL(api, SamplerBuilderSetFilterMode(apiBuilder, NXT_FILTER_MODE_LINEAR, NXT_FILTER_MODE_LINEAR, NXT_FILTER_MODE_NEAREST))
|
||||||
|
.Times(1);
|
||||||
|
|
||||||
|
FlushClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test that the wire is able to send arrays of numerical values
|
||||||
|
static constexpr uint32_t testPushConstantValues[4] = {
|
||||||
|
0,
|
||||||
|
42,
|
||||||
|
0xDEADBEEFu,
|
||||||
|
0xFFFFFFFFu
|
||||||
|
};
|
||||||
|
|
||||||
|
bool CheckPushConstantValues(const uint32_t* values) {
|
||||||
|
for (int i = 0; i < 4; ++i) {
|
||||||
|
if (values[i] != testPushConstantValues[i]) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(WireTests, ValueArrayArgument) {
|
||||||
|
nxtCommandBufferBuilder builder = nxtDeviceCreateCommandBufferBuilder(device);
|
||||||
|
nxtCommandBufferBuilderSetPushConstants(builder, NXT_SHADER_STAGE_BIT_VERTEX, 0, 4, testPushConstantValues);
|
||||||
|
|
||||||
|
nxtCommandBufferBuilder apiBuilder = api.GetNewCommandBufferBuilder();
|
||||||
|
EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
|
||||||
|
.WillOnce(Return(apiBuilder));
|
||||||
|
|
||||||
|
EXPECT_CALL(api, CommandBufferBuilderSetPushConstants(apiBuilder, NXT_SHADER_STAGE_BIT_VERTEX, 0, 4, ResultOf(CheckPushConstantValues, Eq(true))));
|
||||||
|
|
||||||
|
FlushClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test that the wire is able to send C strings
|
||||||
|
TEST_F(WireTests, CStringArgument) {
|
||||||
|
// Create shader module
|
||||||
|
nxtShaderModuleBuilder shaderModuleBuilder = nxtDeviceCreateShaderModuleBuilder(device);
|
||||||
|
nxtShaderModule shaderModule = nxtShaderModuleBuilderGetResult(shaderModuleBuilder);
|
||||||
|
|
||||||
|
nxtShaderModuleBuilder apiShaderModuleBuilder = api.GetNewShaderModuleBuilder();
|
||||||
|
EXPECT_CALL(api, DeviceCreateShaderModuleBuilder(apiDevice))
|
||||||
|
.WillOnce(Return(apiShaderModuleBuilder));
|
||||||
|
|
||||||
|
nxtShaderModule apiShaderModule = api.GetNewShaderModule();
|
||||||
|
EXPECT_CALL(api, ShaderModuleBuilderGetResult(apiShaderModuleBuilder))
|
||||||
|
.WillOnce(Return(apiShaderModule));
|
||||||
|
|
||||||
|
// Create pipeline
|
||||||
|
nxtPipelineBuilder pipelineBuilder = nxtDeviceCreatePipelineBuilder(device);
|
||||||
|
nxtPipelineBuilderSetStage(pipelineBuilder, NXT_SHADER_STAGE_FRAGMENT, shaderModule, "my entry point");
|
||||||
|
|
||||||
|
nxtPipelineBuilder apiPipelineBuilder = api.GetNewPipelineBuilder();
|
||||||
|
EXPECT_CALL(api, DeviceCreatePipelineBuilder(apiDevice))
|
||||||
|
.WillOnce(Return(apiPipelineBuilder));
|
||||||
|
|
||||||
|
EXPECT_CALL(api, PipelineBuilderSetStage(apiPipelineBuilder, NXT_SHADER_STAGE_FRAGMENT, apiShaderModule, StrEq("my entry point")));
|
||||||
|
|
||||||
|
FlushClient();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test that the wire is able to send objects as value arguments
|
||||||
TEST_F(WireTests, ObjectAsValueArgument) {
|
TEST_F(WireTests, ObjectAsValueArgument) {
|
||||||
// Create pipeline
|
// Create pipeline
|
||||||
nxtPipelineBuilder pipelineBuilder = nxtDeviceCreatePipelineBuilder(device);
|
nxtPipelineBuilder pipelineBuilder = nxtDeviceCreatePipelineBuilder(device);
|
||||||
|
@ -170,18 +243,37 @@ TEST_F(WireTests, ObjectAsValueArgument) {
|
||||||
FlushClient();
|
FlushClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(WireTests, OneObjectAsPointerArgument) {
|
// GMock doesn't support lambdas in ResultOf, so we make a functor instead.
|
||||||
// Create command buffer
|
struct AreAPICmdBufs {
|
||||||
|
using result_type = bool;
|
||||||
|
using argument_type = const nxtCommandBuffer*;
|
||||||
|
bool operator() (const nxtCommandBuffer* cmdBufs) const {
|
||||||
|
return cmdBufs[0] == apiCmdBufs[0] && cmdBufs[1] == apiCmdBufs[1];
|
||||||
|
}
|
||||||
|
nxtCommandBuffer apiCmdBufs[2];
|
||||||
|
};
|
||||||
|
|
||||||
|
// Test that the wire is able to send array of objects
|
||||||
|
TEST_F(WireTests, ObjectsAsPointerArgument) {
|
||||||
|
nxtCommandBuffer cmdBufs[2];
|
||||||
|
nxtCommandBuffer apiCmdBufs[2];
|
||||||
|
|
||||||
|
// Create two command buffers we need to use a GMock sequence otherwise the order of the
|
||||||
|
// CreateCommandBufferBuilder might be swapped since they are equivalent in term of matchers
|
||||||
|
Sequence s;
|
||||||
|
for (int i = 0; i < 2; ++i) {
|
||||||
nxtCommandBufferBuilder cmdBufBuilder = nxtDeviceCreateCommandBufferBuilder(device);
|
nxtCommandBufferBuilder cmdBufBuilder = nxtDeviceCreateCommandBufferBuilder(device);
|
||||||
nxtCommandBuffer cmdBuf = nxtCommandBufferBuilderGetResult(cmdBufBuilder);
|
cmdBufs[i] = nxtCommandBufferBuilderGetResult(cmdBufBuilder);
|
||||||
|
|
||||||
nxtCommandBufferBuilder apiCmdBufBuilder = api.GetNewCommandBufferBuilder();
|
nxtCommandBufferBuilder apiCmdBufBuilder = api.GetNewCommandBufferBuilder();
|
||||||
EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
|
EXPECT_CALL(api, DeviceCreateCommandBufferBuilder(apiDevice))
|
||||||
|
.InSequence(s)
|
||||||
.WillOnce(Return(apiCmdBufBuilder));
|
.WillOnce(Return(apiCmdBufBuilder));
|
||||||
|
|
||||||
nxtCommandBuffer apiCmdBuf = api.GetNewCommandBuffer();
|
apiCmdBufs[i] = api.GetNewCommandBuffer();
|
||||||
EXPECT_CALL(api, CommandBufferBuilderGetResult(apiCmdBufBuilder))
|
EXPECT_CALL(api, CommandBufferBuilderGetResult(apiCmdBufBuilder))
|
||||||
.WillOnce(Return(apiCmdBuf));
|
.WillOnce(Return(apiCmdBufs[i]));
|
||||||
|
}
|
||||||
|
|
||||||
// Create queue
|
// Create queue
|
||||||
nxtQueueBuilder queueBuilder = nxtDeviceCreateQueueBuilder(device);
|
nxtQueueBuilder queueBuilder = nxtDeviceCreateQueueBuilder(device);
|
||||||
|
@ -195,17 +287,19 @@ TEST_F(WireTests, OneObjectAsPointerArgument) {
|
||||||
EXPECT_CALL(api, QueueBuilderGetResult(apiQueueBuilder))
|
EXPECT_CALL(api, QueueBuilderGetResult(apiQueueBuilder))
|
||||||
.WillOnce(Return(apiQueue));
|
.WillOnce(Return(apiQueue));
|
||||||
|
|
||||||
// Submit command buffer
|
// Submit command buffer and check we got a call with both API-side command buffers
|
||||||
nxtQueueSubmit(queue, 1, &cmdBuf);
|
nxtQueueSubmit(queue, 2, cmdBufs);
|
||||||
|
|
||||||
EXPECT_CALL(api, QueueSubmit(apiQueue, 1, Pointee(apiCmdBuf)));
|
AreAPICmdBufs predicate;
|
||||||
|
predicate.apiCmdBufs[0] = apiCmdBufs[0];
|
||||||
|
predicate.apiCmdBufs[1] = apiCmdBufs[1];
|
||||||
|
|
||||||
|
EXPECT_CALL(api, QueueSubmit(apiQueue, 2, ResultOf(predicate, Eq(true))));
|
||||||
|
|
||||||
FlushClient();
|
FlushClient();
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO
|
// TODO
|
||||||
// - Test values work
|
|
||||||
// - Test multiple objects as value work
|
|
||||||
// - Object creation, then calls do nothing after error on builder
|
// - Object creation, then calls do nothing after error on builder
|
||||||
// - Object creation then error then create object, then should do nothing.
|
// - Object creation then error then create object, then should do nothing.
|
||||||
// - Device error gets forwarded properly
|
// - Device error gets forwarded properly
|
||||||
|
|
Loading…
Reference in New Issue