aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorJohn Levon <john.levon@nutanix.com>2021-04-15 10:42:07 +0100
committerGitHub <noreply@github.com>2021-04-15 10:42:07 +0100
commitf7e9ff4496cc53caf8217b6210e29628ec60561d (patch)
treec3f652ca18b02bde8bfae80c62f386f70ed880bf /test
parent2e50c5667ce8724b0b7963255d3016efbb1f568a (diff)
downloadlibvfio-user-f7e9ff4496cc53caf8217b6210e29628ec60561d.zip
libvfio-user-f7e9ff4496cc53caf8217b6210e29628ec60561d.tar.gz
libvfio-user-f7e9ff4496cc53caf8217b6210e29628ec60561d.tar.bz2
vfu_ctx_create(): validate flags argument (#442)
In addition, return ENOTSUP for unknown device types, and add some unit tests. Signed-off-by: John Levon <john.levon@nutanix.com> Reviewed-by: Thanos Makatos <thanos.makatos@nutanix.com>
Diffstat (limited to 'test')
-rw-r--r--test/unit-tests.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/test/unit-tests.c b/test/unit-tests.c
index 5ee3358..7f03fb7 100644
--- a/test/unit-tests.c
+++ b/test/unit-tests.c
@@ -699,9 +699,6 @@ test_get_region_info(UNUSED void **state)
/* FIXME add check for multiple sparse areas */
}
-/*
- * FIXME expand and validate
- */
static void
test_vfu_ctx_create(void **state UNUSED)
{
@@ -711,6 +708,18 @@ test_vfu_ctx_create(void **state UNUSED)
pm.hdr.id = PCI_CAP_ID_PM;
pm.pmcs.nsfrst = 0x1;
+ vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK + 1, "", 0, NULL, VFU_DEV_TYPE_PCI);
+ assert_null(vfu_ctx);
+ assert_int_equal(ENOTSUP, errno);
+
+ vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, "", 0, NULL, VFU_DEV_TYPE_PCI + 4);
+ assert_null(vfu_ctx);
+ assert_int_equal(ENOTSUP, errno);
+
+ vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, "", 999, NULL, VFU_DEV_TYPE_PCI);
+ assert_null(vfu_ctx);
+ assert_int_equal(EINVAL, errno);
+
vfu_ctx = vfu_create_ctx(VFU_TRANS_SOCK, "", LIBVFIO_USER_FLAG_ATTACH_NB,
NULL, VFU_DEV_TYPE_PCI);
assert_non_null(vfu_ctx);