blob: 720a3fa12bbb2c830b87fa54906ce308d1996c2c [file] [log] [blame]
John Levon702a4ca2021-05-10 15:01:50 +01001#
2# Copyright (c) 2021 Nutanix Inc. All rights reserved.
3#
4# Authors: John Levon <john.levon@nutanix.com>
5#
6# Redistribution and use in source and binary forms, with or without
7# modification, are permitted provided that the following conditions are met:
8# * Redistributions of source code must retain the above copyright
9# notice, this list of conditions and the following disclaimer.
10# * Redistributions in binary form must reproduce the above copyright
11# notice, this list of conditions and the following disclaimer in the
12# documentation and/or other materials provided with the distribution.
13# * Neither the name of Nutanix nor the names of its contributors may be
14# used to endorse or promote products derived from this software without
15# specific prior written permission.
16#
17# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20# ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
21# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
27# DAMAGE.
28#
29
30from libvfio_user import *
31import ctypes as c
32import errno
33
John Levon7fd786f2021-10-22 13:56:38 +010034
John Levon702a4ca2021-05-10 15:01:50 +010035def test_vfu_create_ctx_bad_trans():
John Levon3779fca2022-04-21 13:43:44 +010036 ctx = vfu_create_ctx(trans=VFU_TRANS_MAX)
John Levon7fd786f2021-10-22 13:56:38 +010037 assert ctx is None
John Levon702a4ca2021-05-10 15:01:50 +010038 assert c.get_errno() == errno.ENOTSUP
39
John Levon7fd786f2021-10-22 13:56:38 +010040
John Levon702a4ca2021-05-10 15:01:50 +010041def test_vfu_create_ctx_bad_flags():
42 ctx = vfu_create_ctx(flags=999)
John Levon7fd786f2021-10-22 13:56:38 +010043 assert ctx is None
John Levon702a4ca2021-05-10 15:01:50 +010044 assert c.get_errno() == errno.EINVAL
45
John Levon7fd786f2021-10-22 13:56:38 +010046
John Levon702a4ca2021-05-10 15:01:50 +010047def test_vfu_create_ctx_bad_dev_type():
48 ctx = vfu_create_ctx(dev_type=VFU_DEV_TYPE_PCI + 4)
John Levon7fd786f2021-10-22 13:56:38 +010049 assert ctx is None
John Levon702a4ca2021-05-10 15:01:50 +010050 assert c.get_errno() == errno.ENOTSUP
51
John Levon7fd786f2021-10-22 13:56:38 +010052
John Levon702a4ca2021-05-10 15:01:50 +010053def test_vfu_create_ctx_default():
54 ctx = vfu_create_ctx()
John Levon7fd786f2021-10-22 13:56:38 +010055 assert ctx is not None
John Levon702a4ca2021-05-10 15:01:50 +010056
57 ret = vfu_realize_ctx(ctx)
58 assert ret == 0
59
60 vfu_destroy_ctx(ctx)