Skip to content

Commit

Permalink
Merge branch 'master' into twin_socket_spec
Browse files Browse the repository at this point in the history
  • Loading branch information
tmakatos authored Aug 31, 2023
2 parents a761260 + f63ef82 commit 1b90d13
Show file tree
Hide file tree
Showing 22 changed files with 370 additions and 356 deletions.
10 changes: 5 additions & 5 deletions docs/spdk.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ GPIO.
Build QEMU
----------

Use Oracle's QEMU d377d483f9 from https://github.com/oracle/qemu:
Use Oracle's QEMU vfio-user-p3.1 from https://github.com/oracle/qemu:

git clone https://github.com/oracle/qemu qemu-orcl
git clone https://github.com/oracle/qemu qemu-orcl --branch vfio-user-p3.1
cd qemu-orcl
git submodule update --init --recursive
./configure --enable-multiprocess
Expand All @@ -20,9 +20,9 @@ Use Oracle's QEMU d377d483f9 from https://github.com/oracle/qemu:
Build SPDK
----------

Use SPDK 72a5fa139:
Use SPDK v23.05:

git clone https://github.com/spdk/spdk
git clone https://github.com/spdk/spdk --branch v23.05
cd spdk
git submodule update --init --recursive
./configure --with-vfio-user
Expand All @@ -47,7 +47,7 @@ Start the Guest

Start the guest with e.g. 4 GB of RAM:

qemu-orcl/build/qemu-system-x86_64 ... \
qemu-orcl/build/qemu-system-x86_64 \
-m 4G -object memory-backend-file,id=mem0,size=4G,mem-path=/dev/hugepages,share=on,prealloc=yes -numa node,memdev=mem0 \
-device vfio-user-pci,socket=/var/run/cntrl

Expand Down
51 changes: 32 additions & 19 deletions test/py/libvfio_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -688,25 +688,38 @@ def connect_sock():
return sock


def connect_client(ctx):
sock = connect_sock()

json = b'{ "capabilities": { "max_msg_fds": 8 } }'
# struct vfio_user_version
payload = struct.pack("HH%dsc" % len(json), LIBVFIO_USER_MAJOR,
LIBVFIO_USER_MINOR, json, b'\0')
hdr = vfio_user_header(VFIO_USER_VERSION, size=len(payload))
sock.send(hdr + payload)
vfu_attach_ctx(ctx, expect=0)
payload = get_reply(sock, expect=0)
return sock


def disconnect_client(ctx, sock):
sock.close()

# notice client closed connection
vfu_run_ctx(ctx, errno.ENOTCONN)
class Client:
"""Models a VFIO-user client connected to the server under test."""

def __init__(self, sock=None):
self.sock = sock
self.client_cmd_socket = None

def connect(self, ctx):
self.sock = connect_sock()

json = b'{ "capabilities": { "max_msg_fds": 8 } }'
# struct vfio_user_version
payload = struct.pack("HH%dsc" % len(json), LIBVFIO_USER_MAJOR,
LIBVFIO_USER_MINOR, json, b'\0')
hdr = vfio_user_header(VFIO_USER_VERSION, size=len(payload))
self.sock.send(hdr + payload)
vfu_attach_ctx(ctx, expect=0)
payload = get_reply(self.sock, expect=0)
return self.sock

def disconnect(self, ctx):
self.sock.close()
self.sock = None

# notice client closed connection
vfu_run_ctx(ctx, errno.ENOTCONN)


def connect_client(*args, **kwargs):
client = Client()
client.connect(*args, **kwargs)
return client


def get_reply(sock, expect=0):
Expand Down
4 changes: 2 additions & 2 deletions test/py/test_destroy.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@


def setup_function(function):
global ctx, sock
global ctx, client
ctx = prepare_ctx_for_dma()
assert ctx is not None
sock = connect_client(ctx)
client = connect_client(ctx)


def teardown_function(function):
Expand Down
10 changes: 5 additions & 5 deletions test/py/test_device_get_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,27 @@ def test_device_get_info():

# test short write

sock = connect_client(ctx)
client = connect_client(ctx)

payload = struct.pack("II", 0, 0)

msg(ctx, sock, VFIO_USER_DEVICE_GET_INFO, payload,
msg(ctx, client.sock, VFIO_USER_DEVICE_GET_INFO, payload,
expect=errno.EINVAL)

# bad argsz

payload = vfio_user_device_info(argsz=8, flags=0,
num_regions=0, num_irqs=0)

msg(ctx, sock, VFIO_USER_DEVICE_GET_INFO, payload,
msg(ctx, client.sock, VFIO_USER_DEVICE_GET_INFO, payload,
expect=errno.EINVAL)

# valid with larger argsz

payload = vfio_user_device_info(argsz=32, flags=0,
num_regions=0, num_irqs=0)

result = msg(ctx, sock, VFIO_USER_DEVICE_GET_INFO, payload)
result = msg(ctx, client.sock, VFIO_USER_DEVICE_GET_INFO, payload)

(argsz, flags, num_regions, num_irqs) = struct.unpack("IIII", result)

Expand All @@ -78,7 +78,7 @@ def test_device_get_info():
assert num_regions == VFU_PCI_DEV_NUM_REGIONS
assert num_irqs == VFU_DEV_NUM_IRQS

disconnect_client(ctx, sock)
client.disconnect(ctx)

vfu_destroy_ctx(ctx)

Expand Down
22 changes: 11 additions & 11 deletions test/py/test_device_get_irq_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@
import errno

ctx = None
sock = None
client = None

argsz = len(vfio_irq_info())


def test_device_get_irq_info_setup():
global ctx, sock
global ctx, client

ctx = vfu_create_ctx(flags=LIBVFIO_USER_FLAG_ATTACH_NB)
assert ctx is not None
Expand All @@ -55,27 +55,27 @@ def test_device_get_irq_info_setup():
ret = vfu_realize_ctx(ctx)
assert ret == 0

sock = connect_client(ctx)
client = connect_client(ctx)


def test_device_get_irq_info_bad_in():
payload = struct.pack("II", 0, 0)

msg(ctx, sock, VFIO_USER_DEVICE_GET_IRQ_INFO, payload,
msg(ctx, client.sock, VFIO_USER_DEVICE_GET_IRQ_INFO, payload,
expect=errno.EINVAL)

# bad argsz
payload = vfio_irq_info(argsz=8, flags=0, index=VFU_DEV_REQ_IRQ,
count=0)

msg(ctx, sock, VFIO_USER_DEVICE_GET_IRQ_INFO, payload,
msg(ctx, client.sock, VFIO_USER_DEVICE_GET_IRQ_INFO, payload,
expect=errno.EINVAL)

# bad index
payload = vfio_irq_info(argsz=argsz, flags=0, index=VFU_DEV_NUM_IRQS,
count=0)

msg(ctx, sock, VFIO_USER_DEVICE_GET_IRQ_INFO, payload,
msg(ctx, client.sock, VFIO_USER_DEVICE_GET_IRQ_INFO, payload,
expect=errno.EINVAL)


Expand All @@ -86,12 +86,12 @@ def test_device_get_irq_info():
payload = vfio_irq_info(argsz=argsz + 16, flags=0, index=VFU_DEV_REQ_IRQ,
count=0)

msg(ctx, sock, VFIO_USER_DEVICE_GET_IRQ_INFO, payload)
msg(ctx, client.sock, VFIO_USER_DEVICE_GET_IRQ_INFO, payload)

payload = vfio_irq_info(argsz=argsz, flags=0, index=VFU_DEV_REQ_IRQ,
count=0)

result = msg(ctx, sock, VFIO_USER_DEVICE_GET_IRQ_INFO, payload)
result = msg(ctx, client.sock, VFIO_USER_DEVICE_GET_IRQ_INFO, payload)

info, _ = vfio_irq_info.pop_from_buffer(result)

Expand All @@ -103,7 +103,7 @@ def test_device_get_irq_info():
payload = vfio_irq_info(argsz=argsz, flags=0, index=VFU_DEV_ERR_IRQ,
count=0)

result = msg(ctx, sock, VFIO_USER_DEVICE_GET_IRQ_INFO, payload)
result = msg(ctx, client.sock, VFIO_USER_DEVICE_GET_IRQ_INFO, payload)

info, _ = vfio_irq_info.pop_from_buffer(result)

Expand All @@ -115,7 +115,7 @@ def test_device_get_irq_info():
payload = vfio_irq_info(argsz=argsz, flags=0, index=VFU_DEV_MSIX_IRQ,
count=0)

result = msg(ctx, sock, VFIO_USER_DEVICE_GET_IRQ_INFO, payload)
result = msg(ctx, client.sock, VFIO_USER_DEVICE_GET_IRQ_INFO, payload)

info, _ = vfio_irq_info.pop_from_buffer(result)

Expand All @@ -126,7 +126,7 @@ def test_device_get_irq_info():


def test_device_get_irq_info_cleanup():
disconnect_client(ctx, sock)
client.disconnect(ctx)

vfu_destroy_ctx(ctx)

Expand Down
Loading

0 comments on commit 1b90d13

Please sign in to comment.