From nobody Sat Nov 15 07:41:38 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=quarantine dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1755511564; cv=none; d=zohomail.com; s=zohoarc; b=FxyhIvBBqL4UsiKV6jiCVyyUsY7aE9tnt2F+Hvn6H3zYNUAwRs7vCgJRm1oFnFmtdRRsvWUwzPFWgw8KmjupRaErwysTgw3y49iU9CH7iaDLwUqyT4K+/72dfAckObS0rWRbxkZqTnBC9dJdYsxOI88OEyAmLItH7puX6lB1/+I= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1755511564; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=VcgyWEw0UZlhydwF41sGf+kzWAR2qTmet/4n/K4pS3U=; b=jBsv3Jia+q5eiAVm4u08m+bUYl/kGKyGHRQTLcOBIdEhp5opxKQ/OK7uBwEI4doEf0QA9iuI6lF7BJ+hWoXkHdOQmDPlFEDW1FgHYnxeJ+J+mqi05xJynQnvsO7RSUd95T2XuPcf60MNectJ2qveG3ji/e0YUCIt4MZ8RiEvrb4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1755511564719728.8677472871557; Mon, 18 Aug 2025 03:06:04 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1unwjP-0004BP-1A; Mon, 18 Aug 2025 06:04:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1unwjN-0004Ax-8i for qemu-devel@nongnu.org; Mon, 18 Aug 2025 06:04:45 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1unwjL-0002sI-Ez for qemu-devel@nongnu.org; Mon, 18 Aug 2025 06:04:45 -0400 Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-526-U4RiXNvvOGKFyRsKb3ZIvQ-1; Mon, 18 Aug 2025 06:04:41 -0400 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5A8B61956086; Mon, 18 Aug 2025 10:04:40 +0000 (UTC) Received: from fedora.redhat.com (unknown [10.45.225.45]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id ADDAC180047F; Mon, 18 Aug 2025 10:04:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1755511482; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=VcgyWEw0UZlhydwF41sGf+kzWAR2qTmet/4n/K4pS3U=; b=VNaobZXR23TvSRZ1b1GyTVr1P8qmO8Uh4QLTztfh0cr1HKcMO3N026dPr1gIHo6mutD9TI +V+FbDXzAG4TRbqMdcehdEg0pKBy6jk4k+cqoXbt+lQJXH3XE2aJIjrIAqniwrO9k5MY5z R3sD2PHhaCewlYhMgAE5/BnDfF+CHyc= X-MC-Unique: U4RiXNvvOGKFyRsKb3ZIvQ-1 X-Mimecast-MFC-AGG-ID: U4RiXNvvOGKFyRsKb3ZIvQ_1755511480 From: Albert Esteve To: qemu-devel@nongnu.org Cc: david@redhat.com, "Michael S. Tsirkin" , hi@alyssa.is, jasowang@redhat.com, Laurent Vivier , dbassey@redhat.com, Stefano Garzarella , Paolo Bonzini , stefanha@redhat.com, stevensd@chromium.org, Fabiano Rosas , =?UTF-8?q?Alex=20Benn=C3=A9e?= , slp@redhat.com, Albert Esteve Subject: [PATCH v7 6/8] tests/qtest: Add GET_SHMEM validation test Date: Mon, 18 Aug 2025 12:03:51 +0200 Message-ID: <20250818100353.1560655-7-aesteve@redhat.com> In-Reply-To: <20250818100353.1560655-1-aesteve@redhat.com> References: <20250818100353.1560655-1-aesteve@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=aesteve@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-Spam_score_int: -30 X-Spam_score: -3.1 X-Spam_bar: --- X-Spam_report: (-3.1 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H5=-1, RCVD_IN_MSPIKE_WL=-0.01, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001, RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1755511566075124100 Content-Type: text/plain; charset="utf-8" Improve vhost-user-test to properly validate VHOST_USER_GET_SHMEM_CONFIG message handling by directly simulating the message exchange. The test manually triggers the VHOST_USER_GET_SHMEM_CONFIG message by calling chr_read() with a crafted VhostUserMsg, allowing direct validation of the shmem configuration response handler. Added TestServerShmem structure to track shmem configuration state, including nregions_sent and sizes_sent arrays for comprehensive validation. The test verifies that the response contains the expected number of shared memory regions and their corresponding sizes. Signed-off-by: Albert Esteve --- tests/qtest/vhost-user-test.c | 91 +++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c index 75cb3e44b2..44a5e90b2e 100644 --- a/tests/qtest/vhost-user-test.c +++ b/tests/qtest/vhost-user-test.c @@ -88,6 +88,7 @@ typedef enum VhostUserRequest { VHOST_USER_SET_VRING_ENABLE =3D 18, VHOST_USER_GET_CONFIG =3D 24, VHOST_USER_SET_CONFIG =3D 25, + VHOST_USER_GET_SHMEM_CONFIG =3D 44, VHOST_USER_MAX } VhostUserRequest; =20 @@ -109,6 +110,20 @@ typedef struct VhostUserLog { uint64_t mmap_offset; } VhostUserLog; =20 +#define VIRTIO_MAX_SHMEM_REGIONS 256 + +typedef struct VhostUserShMemConfig { + uint32_t nregions; + uint32_t padding; + uint64_t memory_sizes[VIRTIO_MAX_SHMEM_REGIONS]; +} VhostUserShMemConfig; + +typedef struct TestServerShmem { + bool test_enabled; + uint32_t nregions_sent; + uint64_t sizes_sent[VIRTIO_MAX_SHMEM_REGIONS]; +} TestServerShmem; + typedef struct VhostUserMsg { VhostUserRequest request; =20 @@ -124,6 +139,7 @@ typedef struct VhostUserMsg { struct vhost_vring_addr addr; VhostUserMemory memory; VhostUserLog log; + VhostUserShMemConfig shmem; } payload; } QEMU_PACKED VhostUserMsg; =20 @@ -170,6 +186,7 @@ typedef struct TestServer { bool test_fail; int test_flags; int queues; + TestServerShmem shmem; struct vhost_user_ops *vu_ops; } TestServer; =20 @@ -513,6 +530,31 @@ static void chr_read(void *opaque, const uint8_t *buf,= int size) qos_printf("set_vring(%d)=3D%s\n", msg.payload.state.index, msg.payload.state.num ? "enabled" : "disabled"); break; + =20 + case VHOST_USER_GET_SHMEM_CONFIG: + if (!s->shmem.test_enabled) { + /* Reply with error if shmem feature not enabled */ + msg.flags |=3D VHOST_USER_REPLY_MASK; + msg.size =3D sizeof(uint64_t); + msg.payload.u64 =3D -1; /* Error */ + qemu_chr_fe_write_all(chr, (uint8_t *) &msg, VHOST_USER_HDR_SI= ZE + msg.size); + } else { + /* Reply with test shmem configuration */ + msg.flags |=3D VHOST_USER_REPLY_MASK; + msg.size =3D sizeof(VhostUserShMemConfig); + msg.payload.shmem.nregions =3D 2; /* Test with 2 regions */ + msg.payload.shmem.padding =3D 0; + msg.payload.shmem.memory_sizes[0] =3D 0x100000; /* 1MB */ + msg.payload.shmem.memory_sizes[1] =3D 0x200000; /* 2MB */ + =20 + /* Record what we're sending for test validation */ + s->shmem.nregions_sent =3D msg.payload.shmem.nregions; + s->shmem.sizes_sent[0] =3D msg.payload.shmem.memory_sizes[0]; + s->shmem.sizes_sent[1] =3D msg.payload.shmem.memory_sizes[1]; + =20 + qemu_chr_fe_write_all(chr, (uint8_t *) &msg, VHOST_USER_HDR_SI= ZE + msg.size); + } + break; =20 default: qos_printf("vhost-user: un-handled message: %d\n", msg.request); @@ -809,6 +851,22 @@ static void *vhost_user_test_setup_shm(GString *cmd_li= ne, void *arg) return server; } =20 +static void *vhost_user_test_setup_shmem_config(GString *cmd_line, void *a= rg) +{ + TestServer *server =3D test_server_new("vhost-user-test", arg); + test_server_listen(server); + + /* Enable shmem testing for this server */ + server->shmem.test_enabled =3D true; + + append_mem_opts(server, cmd_line, 256, TEST_MEMFD_SHM); + server->vu_ops->append_opts(server, cmd_line, ""); + + g_test_queue_destroy(vhost_user_test_cleanup, server); + + return server; +} + static void test_read_guest_mem(void *obj, void *arg, QGuestAllocator *all= oc) { TestServer *server =3D arg; @@ -1089,6 +1147,33 @@ static struct vhost_user_ops g_vu_net_ops =3D { .get_protocol_features =3D vu_net_get_protocol_features, }; =20 +/* Test function for VHOST_USER_GET_SHMEM_CONFIG message */ +static void test_shmem_config(void *obj, void *arg, QGuestAllocator *alloc) +{ + TestServer *s =3D arg; + =20 + g_assert_true(s->shmem.test_enabled); + =20 + g_mutex_lock(&s->data_mutex); + s->shmem.nregions_sent =3D 0; + s->shmem.sizes_sent[0] =3D 0; + s->shmem.sizes_sent[1] =3D 0; + g_mutex_unlock(&s->data_mutex); + =20 + VhostUserMsg msg =3D { + .request =3D VHOST_USER_GET_SHMEM_CONFIG, + .flags =3D VHOST_USER_VERSION, + .size =3D 0, + }; + chr_read(s, (uint8_t *) &msg, VHOST_USER_HDR_SIZE); + + g_mutex_lock(&s->data_mutex); + g_assert_cmpint(s->shmem.nregions_sent, =3D=3D, 2); + g_assert_cmpint(s->shmem.sizes_sent[0], =3D=3D, 0x100000); /* 1MB */ + g_assert_cmpint(s->shmem.sizes_sent[1], =3D=3D, 0x200000); /* 2MB */ + g_mutex_unlock(&s->data_mutex); +} + static void register_vhost_user_test(void) { QOSGraphTestOptions opts =3D { @@ -1136,6 +1221,12 @@ static void register_vhost_user_test(void) qos_add_test("vhost-user/multiqueue", "virtio-net", test_multiqueue, &opts); + =20 + opts.before =3D vhost_user_test_setup_shmem_config; + opts.edge.extra_device_opts =3D ""; + qos_add_test("vhost-user/shmem-config", + "virtio-net", + test_shmem_config, &opts); } libqos_init(register_vhost_user_test); =20 --=20 2.49.0