From nobody Mon Oct 6 14:39:56 2025 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; 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=fail(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1601364498; cv=none; d=zohomail.com; s=zohoarc; b=idZVhCOsez7mgmYbFsdUxhWg3RL7+dLEmxI4Dlap/xazTYQnGeTTduxtX1dzrv/3YatQUVmF/M2d58hoFm9f3MesVg0hwMaEP+SsEq2OEaiUwHQTO6WBzZHqX1G8OWrWw5n/Hkqu30ldTQJeKY2rDDsdasZn/G+bKZgftJwPvl4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1601364498; h=Content-Type:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=gyuuZ4Sz8ayGeGEwQkqastteCZWQE5SL9GYanhN/cu8=; b=LiDRKIfmxKMM8XSFhVKkagva5Or9zRk01ugzdATU7RzZe2KkwZYkpMFLgHjLV0cdaJ1BdIjp90oAQNaBo4b278gttqBMLd8nlQVCuPGaCxDh1QGtcwpTX+LNgJ9eQhJsnG6IrzqFB72jT6xYmpxVXmlLx4wwwcEynN4R+ZUAtkE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; 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=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 160136449859154.21095400544573; Tue, 29 Sep 2020 00:28:18 -0700 (PDT) Received: from localhost ([::1]:58148 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kNA3d-0002rX-5c for importer@patchew.org; Tue, 29 Sep 2020 03:28:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57172) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kN9wv-0002bS-2s for qemu-devel@nongnu.org; Tue, 29 Sep 2020 03:21:21 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:47656) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.90_1) (envelope-from ) id 1kN9ws-0001a9-NN for qemu-devel@nongnu.org; Tue, 29 Sep 2020 03:21:20 -0400 Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-363-BwrSHReHNG2Y1z-NCgezrQ-1; Tue, 29 Sep 2020 03:21:16 -0400 Received: by mail-wm1-f70.google.com with SMTP id m25so1465979wmi.0 for ; Tue, 29 Sep 2020 00:21:15 -0700 (PDT) Received: from redhat.com (bzq-79-179-71-128.red.bezeqint.net. [79.179.71.128]) by smtp.gmail.com with ESMTPSA id n66sm4256882wmb.35.2020.09.29.00.21.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2020 00:21:13 -0700 (PDT) Dkim-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1601364078; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=gyuuZ4Sz8ayGeGEwQkqastteCZWQE5SL9GYanhN/cu8=; b=UOPTdWj39V7lKyHGUi/oOOlNbUZtmukHKF2kAPPVLsgcG9K4UjcLPiBn12o3pFVuj8l/4J QAj4iIAlZgwcdMu8WbddyaQrPUe/g5a20So3Kn8h3hFNk1fYBALX2Lk0DYklWWb4BN6Taj WR6iIe0Qu2M66ZIRwSbHhORu93+E+CQ= X-MC-Unique: BwrSHReHNG2Y1z-NCgezrQ-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=gyuuZ4Sz8ayGeGEwQkqastteCZWQE5SL9GYanhN/cu8=; b=oG7Pw3j4BYeE1DVLOG0kcYun4lft+xJPc1QGMZzHOcBeTeLowJemNWvfBzueKKo9gM DY8T02qXmneMT2/rKDiZ/Ti0S73apEflu00chASqL26iM4TgXEs10zj6sixgyHsXztpc /uqkAB2cycNS7n6eBSVSxJAzFFA8UA/PdxARStDl1lc/5G/EIOqp6/PHW77UjCMbOX3G IpnMxq4l1aE+nRpUOH3P7Xma4IJdV0lZ/FyFl9Mqx795hY7+FIZdojCJZ8berXYxqHH0 fw47SDlBcQPwB86HZLF1yEzo/wUyWKF45ldSXNk9+M77e8uiF9ACFI6ZUp4NhN+Frnr8 2GcA== X-Gm-Message-State: AOAM532ZrZrhdYUM0wMZeyoNE2eRYQ9AdyW0STKo/WmWkrYIERpbL3jT LSB/tcwR9MPvKY3tDGQnXOQ1oOu1trOJe0PQQ6fDhOcihMML+/51jnnhxMVh35uJrkNblN5Rzr7 hf1B3GLQ7EVMqYZg= X-Received: by 2002:adf:ef45:: with SMTP id c5mr2455240wrp.37.1601364074445; Tue, 29 Sep 2020 00:21:14 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz0lB3Fph7wYWe/9WysN5u7iZB4AXo508F3GgngSuTPzno01+yk4S5zrLb5Y2jQv4RlnxnaiA== X-Received: by 2002:adf:ef45:: with SMTP id c5mr2455213wrp.37.1601364074231; Tue, 29 Sep 2020 00:21:14 -0700 (PDT) Date: Tue, 29 Sep 2020 03:21:11 -0400 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Subject: [PULL v4 08/48] tests/qtest/vhost-user-test: prepare the tests for adding new dev class Message-ID: <20200929071948.281157-9-mst@redhat.com> References: <20200929071948.281157-1-mst@redhat.com> MIME-Version: 1.0 In-Reply-To: <20200929071948.281157-1-mst@redhat.com> X-Mailer: git-send-email 2.27.0.106.g8ac3dc51b1 X-Mutt-Fcc: =sent Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=mst@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline 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=216.205.24.124; envelope-from=mst@redhat.com; helo=us-smtp-delivery-124.mimecast.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/29 02:22:44 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIMWL_WL_HIGH=-0.687, 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=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=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.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Laurent Vivier , Peter Maydell , Thomas Huth , Raphael Norwitz , Paolo Bonzini , Dima Stepanov Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: Dima Stepanov For now only vhost-user-net device is supported by the test. Other vhost-user devices are not tested. As a first step make source code refactoring so new devices can reuse the same test routines. To make this provide a new vhost_user_ops structure with the methods to initialize device, its command line or make a proper vhost-user responses. Signed-off-by: Dima Stepanov Reviewed-by: Raphael Norwitz Message-Id: Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- tests/qtest/vhost-user-test.c | 105 ++++++++++++++++++++++++---------- 1 file changed, 76 insertions(+), 29 deletions(-) diff --git a/tests/qtest/vhost-user-test.c b/tests/qtest/vhost-user-test.c index 9ee0f1e4fd..3df5322614 100644 --- a/tests/qtest/vhost-user-test.c +++ b/tests/qtest/vhost-user-test.c @@ -135,6 +135,10 @@ enum { TEST_FLAGS_END, }; =20 +enum { + VHOST_USER_NET, +}; + typedef struct TestServer { gchar *socket_path; gchar *mig_path; @@ -154,10 +158,25 @@ typedef struct TestServer { bool test_fail; int test_flags; int queues; + struct vhost_user_ops *vu_ops; } TestServer; =20 +struct vhost_user_ops { + /* Device types. */ + int type; + void (*append_opts)(TestServer *s, GString *cmd_line, + const char *chr_opts); + + /* VHOST-USER commands. */ + void (*set_features)(TestServer *s, CharBackend *chr, + VhostUserMsg *msg); + void (*get_protocol_features)(TestServer *s, + CharBackend *chr, VhostUserMsg *msg); +}; + static const char *init_hugepagefs(void); -static TestServer *test_server_new(const gchar *name); +static TestServer *test_server_new(const gchar *name, + struct vhost_user_ops *ops); static void test_server_free(TestServer *server); static void test_server_listen(TestServer *server); =20 @@ -167,7 +186,7 @@ enum test_memfd { TEST_MEMFD_NO, }; =20 -static void append_vhost_opts(TestServer *s, GString *cmd_line, +static void append_vhost_net_opts(TestServer *s, GString *cmd_line, const char *chr_opts) { g_string_append_printf(cmd_line, QEMU_CMD_CHR QEMU_CMD_NETDEV, @@ -332,25 +351,15 @@ static void chr_read(void *opaque, const uint8_t *buf= , int size) break; =20 case VHOST_USER_SET_FEATURES: - g_assert_cmpint(msg.payload.u64 & (0x1ULL << VHOST_USER_F_PROTOCOL= _FEATURES), - !=3D, 0ULL); - if (s->test_flags =3D=3D TEST_FLAGS_DISCONNECT) { - qemu_chr_fe_disconnect(chr); - s->test_flags =3D TEST_FLAGS_BAD; + if (s->vu_ops->set_features) { + s->vu_ops->set_features(s, chr, &msg); } break; =20 case VHOST_USER_GET_PROTOCOL_FEATURES: - /* send back features to qemu */ - msg.flags |=3D VHOST_USER_REPLY_MASK; - msg.size =3D sizeof(m.payload.u64); - msg.payload.u64 =3D 1 << VHOST_USER_PROTOCOL_F_LOG_SHMFD; - msg.payload.u64 |=3D 1 << VHOST_USER_PROTOCOL_F_CROSS_ENDIAN; - if (s->queues > 1) { - msg.payload.u64 |=3D 1 << VHOST_USER_PROTOCOL_F_MQ; + if (s->vu_ops->get_protocol_features) { + s->vu_ops->get_protocol_features(s, chr, &msg); } - p =3D (uint8_t *) &msg; - qemu_chr_fe_write_all(chr, p, VHOST_USER_HDR_SIZE + msg.size); break; =20 case VHOST_USER_GET_VRING_BASE: @@ -467,7 +476,8 @@ static const char *init_hugepagefs(void) #endif } =20 -static TestServer *test_server_new(const gchar *name) +static TestServer *test_server_new(const gchar *name, + struct vhost_user_ops *ops) { TestServer *server =3D g_new0(TestServer, 1); char template[] =3D "/tmp/vhost-test-XXXXXX"; @@ -495,6 +505,7 @@ static TestServer *test_server_new(const gchar *name) =20 server->log_fd =3D -1; server->queues =3D 1; + server->vu_ops =3D ops; =20 return server; } @@ -669,11 +680,11 @@ static void vhost_user_test_cleanup(void *s) =20 static void *vhost_user_test_setup(GString *cmd_line, void *arg) { - TestServer *server =3D test_server_new("vhost-user-test"); + TestServer *server =3D test_server_new("vhost-user-test", arg); test_server_listen(server); =20 append_mem_opts(server, cmd_line, 256, TEST_MEMFD_AUTO); - append_vhost_opts(server, cmd_line, ""); + server->vu_ops->append_opts(server, cmd_line, ""); =20 g_test_queue_destroy(vhost_user_test_cleanup, server); =20 @@ -682,11 +693,11 @@ static void *vhost_user_test_setup(GString *cmd_line,= void *arg) =20 static void *vhost_user_test_setup_memfd(GString *cmd_line, void *arg) { - TestServer *server =3D test_server_new("vhost-user-test"); + TestServer *server =3D test_server_new("vhost-user-test", arg); test_server_listen(server); =20 append_mem_opts(server, cmd_line, 256, TEST_MEMFD_YES); - append_vhost_opts(server, cmd_line, ""); + server->vu_ops->append_opts(server, cmd_line, ""); =20 g_test_queue_destroy(vhost_user_test_cleanup, server); =20 @@ -720,7 +731,7 @@ static void test_migrate(void *obj, void *arg, QGuestAl= locator *alloc) return; } =20 - dest =3D test_server_new("dest"); + dest =3D test_server_new("dest", s->vu_ops); dest_cmdline =3D g_string_new(qos_get_current_command_line()); uri =3D g_strdup_printf("%s%s", "unix:", dest->mig_path); =20 @@ -730,7 +741,7 @@ static void test_migrate(void *obj, void *arg, QGuestAl= locator *alloc) test_server_listen(dest); g_string_append_printf(dest_cmdline, " -incoming %s", uri); append_mem_opts(dest, dest_cmdline, 256, TEST_MEMFD_AUTO); - append_vhost_opts(dest, dest_cmdline, ""); + dest->vu_ops->append_opts(dest, dest_cmdline, ""); to =3D qtest_init(dest_cmdline->str); =20 /* This would be where you call qos_allocate_objects(to, NULL), if you= want @@ -831,11 +842,11 @@ connect_thread(gpointer data) =20 static void *vhost_user_test_setup_reconnect(GString *cmd_line, void *arg) { - TestServer *s =3D test_server_new("reconnect"); + TestServer *s =3D test_server_new("reconnect", arg); =20 g_thread_new("connect", connect_thread, s); append_mem_opts(s, cmd_line, 256, TEST_MEMFD_AUTO); - append_vhost_opts(s, cmd_line, ",server"); + s->vu_ops->append_opts(s, cmd_line, ",server"); =20 g_test_queue_destroy(vhost_user_test_cleanup, s); =20 @@ -866,13 +877,13 @@ static void test_reconnect(void *obj, void *arg, QGue= stAllocator *alloc) =20 static void *vhost_user_test_setup_connect_fail(GString *cmd_line, void *a= rg) { - TestServer *s =3D test_server_new("connect-fail"); + TestServer *s =3D test_server_new("connect-fail", arg); =20 s->test_fail =3D true; =20 g_thread_new("connect", connect_thread, s); append_mem_opts(s, cmd_line, 256, TEST_MEMFD_AUTO); - append_vhost_opts(s, cmd_line, ",server"); + s->vu_ops->append_opts(s, cmd_line, ",server"); =20 g_test_queue_destroy(vhost_user_test_cleanup, s); =20 @@ -881,13 +892,13 @@ static void *vhost_user_test_setup_connect_fail(GStri= ng *cmd_line, void *arg) =20 static void *vhost_user_test_setup_flags_mismatch(GString *cmd_line, void = *arg) { - TestServer *s =3D test_server_new("flags-mismatch"); + TestServer *s =3D test_server_new("flags-mismatch", arg); =20 s->test_flags =3D TEST_FLAGS_DISCONNECT; =20 g_thread_new("connect", connect_thread, s); append_mem_opts(s, cmd_line, 256, TEST_MEMFD_AUTO); - append_vhost_opts(s, cmd_line, ",server"); + s->vu_ops->append_opts(s, cmd_line, ",server"); =20 g_test_queue_destroy(vhost_user_test_cleanup, s); =20 @@ -924,11 +935,47 @@ static void test_multiqueue(void *obj, void *arg, QGu= estAllocator *alloc) wait_for_rings_started(s, s->queues * 2); } =20 +static void vu_net_set_features(TestServer *s, CharBackend *chr, + VhostUserMsg *msg) +{ + g_assert_cmpint(msg->payload.u64 & + (0x1ULL << VHOST_USER_F_PROTOCOL_FEATURES), !=3D, 0ULL); + if (s->test_flags =3D=3D TEST_FLAGS_DISCONNECT) { + qemu_chr_fe_disconnect(chr); + s->test_flags =3D TEST_FLAGS_BAD; + } +} + +static void vu_net_get_protocol_features(TestServer *s, CharBackend *chr, + VhostUserMsg *msg) +{ + /* send back features to qemu */ + msg->flags |=3D VHOST_USER_REPLY_MASK; + msg->size =3D sizeof(m.payload.u64); + msg->payload.u64 =3D 1 << VHOST_USER_PROTOCOL_F_LOG_SHMFD; + msg->payload.u64 |=3D 1 << VHOST_USER_PROTOCOL_F_CROSS_ENDIAN; + if (s->queues > 1) { + msg->payload.u64 |=3D 1 << VHOST_USER_PROTOCOL_F_MQ; + } + qemu_chr_fe_write_all(chr, (uint8_t *)msg, VHOST_USER_HDR_SIZE + msg->= size); +} + +/* Each VHOST-USER device should have its ops structure defined. */ +static struct vhost_user_ops g_vu_net_ops =3D { + .type =3D VHOST_USER_NET, + + .append_opts =3D append_vhost_net_opts, + + .set_features =3D vu_net_set_features, + .get_protocol_features =3D vu_net_get_protocol_features, +}; + static void register_vhost_user_test(void) { QOSGraphTestOptions opts =3D { .before =3D vhost_user_test_setup, .subprocess =3D true, + .arg =3D &g_vu_net_ops, }; =20 qemu_add_opts(&qemu_chardev_opts); --=20 MST