aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorswapnili <swapnil.ingle@nutanix.com>2020-12-08 16:01:35 +0100
committerGitHub <noreply@github.com>2020-12-08 16:01:35 +0100
commit2015453378f9d00fe271faf0f4cfa39f5f53536a (patch)
treee655a6837f76e0188cc048c28b4188813ba7ddee /test
parent486cb8a724e3259220d1da2ad673118eecb5c360 (diff)
downloadlibvfio-user-2015453378f9d00fe271faf0f4cfa39f5f53536a.zip
libvfio-user-2015453378f9d00fe271faf0f4cfa39f5f53536a.tar.gz
libvfio-user-2015453378f9d00fe271faf0f4cfa39f5f53536a.tar.bz2
Misc fixes for vfu_ctx_try_attach() and vfu_realize_ctx() (#175)
Misc changes for vfu_ctx_try_attach() * Rename to vfu_attach_ctx() * Removed call to vfu_realize_ctx(), should be called separately * Now vfu_attach_ctx() must also be called for blocking ctx. Misc changes for vfu_realize_ctx() * Made calling vfu_realize_ctx() mandatory * vfu_ctx_drive() and vfu_poll_ctx() returns EINVAL if the device is not realized. * Renamed vfu_ctx->ready to vfu_ctx->realized Added unit test for vfu_attach_ctx() and vfu_realize_ctx() Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'test')
-rw-r--r--test/unit-tests.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/unit-tests.c b/test/unit-tests.c
index a20f4fe..5d3703a 100644
--- a/test/unit-tests.c
+++ b/test/unit-tests.c
@@ -325,6 +325,37 @@ test_process_command_free_passed_fds(void **state __attribute__((unused)))
assert_int_equal(0, process_request(&vfu_ctx));
}
+static void
+test_realize_ctx(void **state __attribute__((unused)))
+{
+ vfu_reg_info_t *cfg_reg;
+ vfu_reg_info_t reg_info[VFU_PCI_DEV_NUM_REGIONS + 1] = { 0 };
+ vfu_ctx_t vfu_ctx = {
+ .reg_info = reg_info,
+ .nr_regions = VFU_PCI_DEV_NUM_REGIONS + 1
+ };
+
+ assert_int_equal(0, vfu_realize_ctx(&vfu_ctx));
+ assert_true(vfu_ctx.realized);
+ cfg_reg = &vfu_ctx.reg_info[VFU_PCI_DEV_CFG_REGION_IDX];
+ assert_int_equal(VFU_REGION_FLAG_RW, cfg_reg->flags);
+ assert_int_equal(PCI_CFG_SPACE_SIZE, cfg_reg->size);
+ assert_non_null(vfu_ctx.pci.config_space);
+ assert_non_null(vfu_ctx.irqs);
+ assert_null(vfu_ctx.pci.caps);
+}
+
+static void
+test_attach_ctx(void **state __attribute__((unused)))
+{
+ vfu_ctx_t vfu_ctx = {
+ .trans = &sock_transport_ops,
+ .fd = 111
+ };
+
+ assert_int_equal(-1, vfu_attach_ctx(&vfu_ctx));
+}
+
/*
* FIXME we shouldn't have to specify a setup function explicitly for each unit
* test, cmocka should provide that. E.g. cmocka_run_group_tests enables us to
@@ -348,6 +379,8 @@ int main(void)
cmocka_unit_test_setup(test_dma_controller_add_region_no_fd, setup),
cmocka_unit_test_setup(test_dma_controller_remove_region_no_fd, setup),
cmocka_unit_test_setup(test_process_command_free_passed_fds, setup),
+ cmocka_unit_test_setup(test_realize_ctx, setup),
+ cmocka_unit_test_setup(test_attach_ctx, setup),
};
return cmocka_run_group_tests(tests, NULL, NULL);