diff options
author | swapnili <swapnil.ingle@nutanix.com> | 2021-01-08 15:30:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-08 15:30:50 +0100 |
commit | d211f2cf4920e7f082bb5e707c672cecb6f52a6c (patch) | |
tree | b9fb13e4fe3e6cec4d44095109d666c431a9878a /test | |
parent | 6ec31642f6253f5c19187c1ffb396d5921138b67 (diff) | |
download | libvfio-user-d211f2cf4920e7f082bb5e707c672cecb6f52a6c.zip libvfio-user-d211f2cf4920e7f082bb5e707c672cecb6f52a6c.tar.gz libvfio-user-d211f2cf4920e7f082bb5e707c672cecb6f52a6c.tar.bz2 |
Use prot flags sent by client to map dma regions (#227)
* Use prot flags sent by client to map dma regions
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/mocks.c | 7 | ||||
-rw-r--r-- | test/unit-tests.c | 28 |
2 files changed, 26 insertions, 9 deletions
diff --git a/test/mocks.c b/test/mocks.c index faa8ed4..7f7fc02 100644 --- a/test/mocks.c +++ b/test/mocks.c @@ -47,10 +47,12 @@ struct function int __wrap_dma_controller_add_region(dma_controller_t *dma, dma_addr_t dma_addr, - size_t size, int fd, off_t offset) + size_t size, int fd, off_t offset, + uint32_t prot) { if (!is_patched(dma_controller_add_region)) { - return __real_dma_controller_add_region(dma, dma_addr, size, fd, offset); + return __real_dma_controller_add_region(dma, dma_addr, size, fd, offset, + prot); } check_expected_ptr(dma); @@ -58,6 +60,7 @@ __wrap_dma_controller_add_region(dma_controller_t *dma, dma_addr_t dma_addr, check_expected(size); check_expected(fd); check_expected(offset); + check_expected(prot); return mock(); } diff --git a/test/unit-tests.c b/test/unit-tests.c index 30cc71c..135eabe 100644 --- a/test/unit-tests.c +++ b/test/unit-tests.c @@ -85,7 +85,8 @@ test_dma_map_without_fd(void **state __attribute__((unused))) struct vfio_user_dma_region r = { .addr = 0xdeadbeef, .size = 0xcafebabe, - .offset = 0x8badf00d + .offset = 0x8badf00d, + .prot = PROT_NONE }; int fd; @@ -96,6 +97,7 @@ test_dma_map_without_fd(void **state __attribute__((unused))) 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); + expect_value(__wrap_dma_controller_add_region, prot, r.prot); assert_int_equal(0, handle_dma_map_or_unmap(&vfu_ctx, size, true, &fd, 0, &r)); } @@ -113,13 +115,15 @@ test_dma_add_regions_mixed(void **state __attribute__((unused))) [0] = { .addr = 0xdeadbeef, .size = 0x1000, - .offset = 0 + .offset = 0, + .prot = PROT_NONE }, [1] = { .addr = 0xcafebabe, .size = 0x1000, .offset = 0x1000, - .flags = VFIO_USER_F_DMA_REGION_MAPPABLE + .flags = VFIO_USER_F_DMA_REGION_MAPPABLE, + .prot = PROT_READ|PROT_WRITE } }; int fd = 0x0badf00d; @@ -132,11 +136,13 @@ test_dma_add_regions_mixed(void **state __attribute__((unused))) expect_value(__wrap_dma_controller_add_region, size, r[0].size); expect_value(__wrap_dma_controller_add_region, fd, -1); expect_value(__wrap_dma_controller_add_region, offset, r[0].offset); + expect_value(__wrap_dma_controller_add_region, prot, r[0].prot); expect_value(__wrap_dma_controller_add_region, dma, vfu_ctx.dma); expect_value(__wrap_dma_controller_add_region, dma_addr, r[1].addr); expect_value(__wrap_dma_controller_add_region, size, r[1].size); expect_value(__wrap_dma_controller_add_region, fd, fd); expect_value(__wrap_dma_controller_add_region, offset, r[1].offset); + expect_value(__wrap_dma_controller_add_region, prot, r[1].prot); assert_int_equal(0, handle_dma_map_or_unmap(&vfu_ctx, sizeof r, true, &fd, 1, r)); } @@ -161,13 +167,15 @@ test_dma_add_regions_mixed_partial_failure(void **state __attribute__((unused))) .addr = 0xcafebabe, .size = 0x1000, .offset = 0x1000, - .flags = VFIO_USER_F_DMA_REGION_MAPPABLE + .flags = VFIO_USER_F_DMA_REGION_MAPPABLE, + .prot = PROT_READ }, [2] = { .addr = 0xbabecafe, .size = 0x1000, .offset = 0x2000, - .flags = VFIO_USER_F_DMA_REGION_MAPPABLE + .flags = VFIO_USER_F_DMA_REGION_MAPPABLE, + .prot = PROT_READ|PROT_WRITE } }; int fds[] = {0xa, 0xb}; @@ -180,6 +188,7 @@ test_dma_add_regions_mixed_partial_failure(void **state __attribute__((unused))) expect_value(__wrap_dma_controller_add_region, size, r[0].size); expect_value(__wrap_dma_controller_add_region, fd, -1); expect_value(__wrap_dma_controller_add_region, offset, r[0].offset); + expect_value(__wrap_dma_controller_add_region, prot, r[0].prot); will_return(__wrap_dma_controller_add_region, 0); /* 2nd region */ @@ -188,6 +197,7 @@ test_dma_add_regions_mixed_partial_failure(void **state __attribute__((unused))) expect_value(__wrap_dma_controller_add_region, size, r[1].size); expect_value(__wrap_dma_controller_add_region, fd, fds[0]); expect_value(__wrap_dma_controller_add_region, offset, r[1].offset); + expect_value(__wrap_dma_controller_add_region, prot, r[1].prot); will_return(__wrap_dma_controller_add_region, 0); /* 3rd region */ @@ -196,6 +206,7 @@ test_dma_add_regions_mixed_partial_failure(void **state __attribute__((unused))) expect_value(__wrap_dma_controller_add_region, size, r[2].size); expect_value(__wrap_dma_controller_add_region, fd, fds[1]); expect_value(__wrap_dma_controller_add_region, offset, r[2].offset); + expect_value(__wrap_dma_controller_add_region, prot, r[2].prot); will_return(__wrap_dma_controller_add_region, -0x1234); patch(close); @@ -227,8 +238,9 @@ test_dma_map_return_value(void **state __attribute__((unused))) 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); + expect_value(__wrap_dma_controller_add_region, prot, r.prot); 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)); @@ -245,7 +257,8 @@ test_dma_controller_add_region_no_fd(void **state __attribute__((unused))) off_t offset = 0; dma_memory_region_t *r; - assert_int_equal(0, dma_controller_add_region(&dma, dma_addr, size, fd, offset)); + assert_int_equal(0, dma_controller_add_region(&dma, dma_addr, size, fd, + offset, PROT_NONE)); assert_int_equal(1, dma.nregions); r = &dma.regions[0]; assert_ptr_equal(NULL, r->virt_addr); @@ -255,6 +268,7 @@ test_dma_controller_add_region_no_fd(void **state __attribute__((unused))) assert_int_equal(offset, r->offset); assert_int_equal(fd, r->fd); assert_int_equal(0, r->refcnt); + assert_int_equal(PROT_NONE, r->prot); } static void |