aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorSwapnil Ingle <swapnil.ingle@nutanix.com>2021-05-14 12:05:55 +0200
committerGitHub <noreply@github.com>2021-05-14 12:05:55 +0200
commitc174ca8539a47ea3b87b1d4015a0b9f21c738dad (patch)
treecc0160741f05c8e9795def8ac84deb3aa0863c35 /test
parent4929d0a29187d4c71e9034da692b5335c57cc91d (diff)
downloadlibvfio-user-c174ca8539a47ea3b87b1d4015a0b9f21c738dad.zip
libvfio-user-c174ca8539a47ea3b87b1d4015a0b9f21c738dad.tar.gz
libvfio-user-c174ca8539a47ea3b87b1d4015a0b9f21c738dad.tar.bz2
dma: Use correct len type (#479)
* dma: Use correct len type vfio_iommu_type1_dirty_bitmap_get.size is of type __u64 dma_controller_dirty_page_get() receives it as int, instead it should be u64 Also added UT to test overflow of length passed to dma_controller_dirty_page_get Fixes: #477 Signed-off-by: Swapnil Ingle <swapnil.ingle@nutanix.com> Reviewed-by: John Levon <john.levon@nutanix.com>
Diffstat (limited to 'test')
-rw-r--r--test/unit-tests.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/test/unit-tests.c b/test/unit-tests.c
index 7fbb055..df51b08 100644
--- a/test/unit-tests.c
+++ b/test/unit-tests.c
@@ -486,7 +486,7 @@ test_dma_map_sg(void **state UNUSED)
sg.length = 0xcafebabe;
assert_int_equal(0, dma_map_sg(vfu_ctx.dma, &sg, &iovec, 1));
assert_int_equal(0xdeadbeef, iovec.iov_base);
- assert_int_equal((int)0x00000000cafebabe, iovec.iov_len);
+ assert_int_equal(0x00000000cafebabe, iovec.iov_len);
}
static void
@@ -1816,6 +1816,24 @@ test_process_request_free_passed_fds(void **state UNUSED)
assert_int_equal(0, process_request(&vfu_ctx));
}
+static void
+test_dma_controller_dirty_page_get(void **state UNUSED)
+{
+ dma_memory_region_t *r;
+ uint64_t len = UINT32_MAX + (uint64_t)10;
+ char bp[131073];
+
+ vfu_ctx.dma->nregions = 1;
+ r = &vfu_ctx.dma->regions[0];
+ r->info.iova.iov_base = (void *)0;
+ r->info.iova.iov_len = len;
+ r->info.vaddr = (void *)0xdeadbeef;
+ vfu_ctx.dma->dirty_pgsize = 4096;
+
+ assert_int_equal(0, dma_controller_dirty_page_get(vfu_ctx.dma, (void *)0,
+ len, 4096, 131073, (char **)&bp));
+}
+
int
main(void)
{
@@ -1869,6 +1887,7 @@ main(void)
cmocka_unit_test_setup(test_cmd_allowed_when_stopped_and_copying, setup),
cmocka_unit_test_setup(test_should_exec_command, setup),
cmocka_unit_test_setup(test_process_request_free_passed_fds, setup),
+ cmocka_unit_test_setup(test_dma_controller_dirty_page_get, setup),
};
return cmocka_run_group_tests(tests, NULL, NULL);