aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThanos Makatos <thanos.makatos@nutanix.com>2020-12-16 11:00:13 +0000
committerGitHub <noreply@github.com>2020-12-16 11:00:13 +0000
commitd1eda3154fc9ea8ff45bfab5d5ec1a712584d468 (patch)
tree0c198d0b7df3e448aaa5592c7e2faa574684d09e
parent8694149b351e3e125aa8f1740f8d5925e7ec112c (diff)
downloadlibvfio-user-d1eda3154fc9ea8ff45bfab5d5ec1a712584d468.zip
libvfio-user-d1eda3154fc9ea8ff45bfab5d5ec1a712584d468.tar.gz
libvfio-user-d1eda3154fc9ea8ff45bfab5d5ec1a712584d468.tar.bz2
don't treat non-zero return value of dma_controller_add_region as failure (#206)
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
-rw-r--r--lib/libvfio-user.c1
-rw-r--r--test/unit-tests.c29
2 files changed, 29 insertions, 1 deletions
diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c
index 846a70f..c5cd3c3 100644
--- a/lib/libvfio-user.c
+++ b/lib/libvfio-user.c
@@ -612,6 +612,7 @@ handle_dma_map_or_unmap(vfu_ctx_t *vfu_ctx, uint32_t size, bool map,
strerror(-ret));
break;
}
+ ret = 0;
vfu_log(vfu_ctx, LOG_DEBUG,
"added DMA region %#lx-%#lx offset=%#lx fd=%d",
dma_regions[i].addr,
diff --git a/test/unit-tests.c b/test/unit-tests.c
index 4d28db7..c3de8e9 100644
--- a/test/unit-tests.c
+++ b/test/unit-tests.c
@@ -208,6 +208,32 @@ test_dma_add_regions_mixed_partial_failure(void **state __attribute__((unused)))
true, fds, 2, r));
}
+/*
+ * Checks that handle_dma_map_or_unmap returns 0 when dma_controller_add_region
+ * succeeds.
+ */
+static void
+test_dma_map_return_value(void **state __attribute__((unused)))
+{
+ dma_controller_t dma = { 0 };
+ vfu_ctx_t vfu_ctx = { .dma = &dma };
+ dma.vfu_ctx = &vfu_ctx;
+ struct vfio_user_dma_region r = { 0 };
+ int fd = 0;
+
+ patch(dma_controller_add_region);
+ expect_value(__wrap_dma_controller_add_region, dma, vfu_ctx.dma);
+ expect_value(__wrap_dma_controller_add_region, dma_addr, r.addr);
+ expect_value(__wrap_dma_controller_add_region, size, r.size);
+ expect_value(__wrap_dma_controller_add_region, fd, -1);
+ expect_value(__wrap_dma_controller_add_region, offset, r.offset);
+ will_return(__wrap_dma_controller_add_region, 2);
+
+ assert_int_equal(0,
+ handle_dma_map_or_unmap(&vfu_ctx, sizeof(struct vfio_user_dma_region),
+ true, &fd, 0, &r));
+}
+
static void
test_dma_controller_add_region_no_fd(void **state __attribute__((unused)))
{
@@ -648,7 +674,8 @@ int main(void)
cmocka_unit_test_setup(test_pci_caps, setup),
cmocka_unit_test_setup(test_device_get_info, setup),
cmocka_unit_test_setup(test_get_region_info, setup),
- cmocka_unit_test_setup(test_setup_sparse_region, setup)
+ cmocka_unit_test_setup(test_setup_sparse_region, setup),
+ cmocka_unit_test_setup(test_dma_map_return_value, setup)
};
return cmocka_run_group_tests(tests, NULL, NULL);