John Levon | 702a4ca | 2021-05-10 15:01:50 +0100 | [diff] [blame] | 1 | # |
| 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 | |
| 30 | from libvfio_user import * |
| 31 | import ctypes as c |
| 32 | import errno |
| 33 | |
John Levon | 7fd786f | 2021-10-22 13:56:38 +0100 | [diff] [blame] | 34 | |
John Levon | 702a4ca | 2021-05-10 15:01:50 +0100 | [diff] [blame] | 35 | def test_vfu_create_ctx_bad_trans(): |
John Levon | 3779fca | 2022-04-21 13:43:44 +0100 | [diff] [blame] | 36 | ctx = vfu_create_ctx(trans=VFU_TRANS_MAX) |
John Levon | 7fd786f | 2021-10-22 13:56:38 +0100 | [diff] [blame] | 37 | assert ctx is None |
John Levon | 702a4ca | 2021-05-10 15:01:50 +0100 | [diff] [blame] | 38 | assert c.get_errno() == errno.ENOTSUP |
| 39 | |
John Levon | 7fd786f | 2021-10-22 13:56:38 +0100 | [diff] [blame] | 40 | |
John Levon | 702a4ca | 2021-05-10 15:01:50 +0100 | [diff] [blame] | 41 | def test_vfu_create_ctx_bad_flags(): |
| 42 | ctx = vfu_create_ctx(flags=999) |
John Levon | 7fd786f | 2021-10-22 13:56:38 +0100 | [diff] [blame] | 43 | assert ctx is None |
John Levon | 702a4ca | 2021-05-10 15:01:50 +0100 | [diff] [blame] | 44 | assert c.get_errno() == errno.EINVAL |
| 45 | |
John Levon | 7fd786f | 2021-10-22 13:56:38 +0100 | [diff] [blame] | 46 | |
John Levon | 702a4ca | 2021-05-10 15:01:50 +0100 | [diff] [blame] | 47 | def test_vfu_create_ctx_bad_dev_type(): |
| 48 | ctx = vfu_create_ctx(dev_type=VFU_DEV_TYPE_PCI + 4) |
John Levon | 7fd786f | 2021-10-22 13:56:38 +0100 | [diff] [blame] | 49 | assert ctx is None |
John Levon | 702a4ca | 2021-05-10 15:01:50 +0100 | [diff] [blame] | 50 | assert c.get_errno() == errno.ENOTSUP |
| 51 | |
John Levon | 7fd786f | 2021-10-22 13:56:38 +0100 | [diff] [blame] | 52 | |
John Levon | 702a4ca | 2021-05-10 15:01:50 +0100 | [diff] [blame] | 53 | def test_vfu_create_ctx_default(): |
| 54 | ctx = vfu_create_ctx() |
John Levon | 7fd786f | 2021-10-22 13:56:38 +0100 | [diff] [blame] | 55 | assert ctx is not None |
John Levon | 702a4ca | 2021-05-10 15:01:50 +0100 | [diff] [blame] | 56 | |
| 57 | ret = vfu_realize_ctx(ctx) |
| 58 | assert ret == 0 |
| 59 | |
| 60 | vfu_destroy_ctx(ctx) |