diff options
author | John Levon <john.levon@nutanix.com> | 2021-03-25 16:54:53 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-25 16:54:53 +0000 |
commit | 710a0081aa206b319161fac9bbafce14f5045ee8 (patch) | |
tree | fbf91231220be75cd05279c0492f90cf1d5ab669 /lib/dma.h | |
parent | 4f4c378978f0e22ec5b803496e2971adca6a3f8f (diff) | |
download | libvfio-user-710a0081aa206b319161fac9bbafce14f5045ee8.zip libvfio-user-710a0081aa206b319161fac9bbafce14f5045ee8.tar.gz libvfio-user-710a0081aa206b319161fac9bbafce14f5045ee8.tar.bz2 |
re-work unit test mocking (#400)
Instead of trying to use the linker's --wrap, which just led to more problems
when we want to call the real function, we'll add two defines, MOCK_DEFINE() and
MOCK_DECLARE(), that behave differently when building the unit tests, such that
all wrapped functions are picked up from test/mocks.c instead, regardless of
compilation unit.
Signed-off-by: John Levon <john.levon@nutanix.com>
Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'lib/dma.h')
-rw-r--r-- | lib/dma.h | 19 |
1 files changed, 10 insertions, 9 deletions
@@ -116,15 +116,16 @@ dma_controller_destroy(dma_controller_t *dma); * where this region would have been mapped to if the call could succeed * (e.g. due to conflict with existing region). */ -MOCKED(int, dma_controller_add_region, dma_controller_t *dma, - dma_addr_t dma_addr, size_t size, int fd, off_t offset, uint32_t prot); +MOCK_DECLARE(int, dma_controller_add_region, dma_controller_t *dma, + dma_addr_t dma_addr, size_t size, int fd, off_t offset, + uint32_t prot); -MOCKED(void, _dma_controller_do_remove_region, dma_controller_t *dma, - dma_memory_region_t *region); +MOCK_DECLARE(void, _dma_controller_do_remove_region, dma_controller_t *dma, + dma_memory_region_t *region); -MOCKED(int, dma_controller_remove_region, dma_controller_t *dma, - dma_addr_t dma_addr, size_t size, vfu_unmap_dma_cb_t *unmap_dma, - void *data); +MOCK_DECLARE(int, dma_controller_remove_region, dma_controller_t *dma, + dma_addr_t dma_addr, size_t size, vfu_unmap_dma_cb_t *unmap_dma, + void *data); // Helper for dma_addr_to_sg() slow path. int @@ -250,8 +251,8 @@ dma_addr_to_sg(const dma_controller_t *dma, return cnt; } -MOCKED(void *, dma_map_region, dma_memory_region_t *region, int prot, - size_t offset, size_t len); +MOCK_DECLARE(void *, dma_map_region, dma_memory_region_t *region, int prot, + size_t offset, size_t len); int dma_unmap_region(dma_memory_region_t *region, void *virt_addr, size_t len); |