diff options
author | Thanos Makatos <thanos.makatos@nutanix.com> | 2020-12-14 13:15:21 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-14 13:15:21 +0000 |
commit | 0e2a9fe81ace3ae06d6a931833bea367f7dda26b (patch) | |
tree | 8f4dcfd2b2bad9c812f8282f57f3ec94c60a4719 | |
parent | 6299ba17273e9bc7b020395cb85ebf77dba296cd (diff) | |
download | libvfio-user-0e2a9fe81ace3ae06d6a931833bea367f7dda26b.zip libvfio-user-0e2a9fe81ace3ae06d6a931833bea367f7dda26b.tar.gz libvfio-user-0e2a9fe81ace3ae06d6a931833bea367f7dda26b.tar.bz2 |
add unit test for device get info (#192)
Signed-off-by: Thanos Makatos <thanos.makatos@nutanix.com>
-rw-r--r-- | lib/libvfio-user.c | 2 | ||||
-rw-r--r-- | lib/private.h | 4 | ||||
-rw-r--r-- | test/unit-tests.c | 14 |
3 files changed, 19 insertions, 1 deletions
diff --git a/lib/libvfio-user.c b/lib/libvfio-user.c index 75ad41c..c3cd1e2 100644 --- a/lib/libvfio-user.c +++ b/lib/libvfio-user.c @@ -486,7 +486,7 @@ handle_device_get_region_info(vfu_ctx_t *vfu_ctx, uint32_t size, return dev_get_reginfo(vfu_ctx, reg_info_in->index, reg_info_out); } -static int +int handle_device_get_info(vfu_ctx_t *vfu_ctx, uint32_t size, struct vfio_device_info *dev_info) { diff --git a/lib/private.h b/lib/private.h index e8afd79..5321734 100644 --- a/lib/private.h +++ b/lib/private.h @@ -168,6 +168,10 @@ process_request(vfu_ctx_t *vfu_ctx); int consume_fd(int *fds, size_t nr_fds, size_t index); +int +handle_device_get_info(vfu_ctx_t *vfu_ctx, uint32_t size, + struct vfio_device_info *dev_info); + #endif /* LIB_VFIO_USER_PRIVATE_H */ /* ex: set tabstop=4 shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/test/unit-tests.c b/test/unit-tests.c index c10ce5a..d4ac1ef 100644 --- a/test/unit-tests.c +++ b/test/unit-tests.c @@ -483,6 +483,19 @@ test_pci_caps(void **state __attribute__((unused))) assert_memory_equal(&config_space.raw[off], vsc[0]->vsc.data, 5); } +static void +test_device_get_info(void **state __attribute__((unused))) +{ + vfu_ctx_t vfu_ctx = { .nr_regions = 0xdeadbeef}; + struct vfio_device_info d = { 0 }; + + assert_int_equal(0, handle_device_get_info(&vfu_ctx, sizeof d, &d)); + assert_int_equal(sizeof d, d.argsz); + assert_int_equal(VFIO_DEVICE_FLAGS_PCI | VFIO_DEVICE_FLAGS_RESET, d.flags); + assert_int_equal(vfu_ctx.nr_regions, d.num_regions); + assert_int_equal(VFU_DEV_NUM_IRQS, d.num_irqs); +} + /* * 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 @@ -511,6 +524,7 @@ int main(void) cmocka_unit_test_setup(test_run_ctx, setup), cmocka_unit_test_setup(test_vfu_ctx_create, setup), cmocka_unit_test_setup(test_pci_caps, setup), + cmocka_unit_test_setup(test_device_get_info, setup), }; return cmocka_run_group_tests(tests, NULL, NULL); |