From patchwork Sun Sep 27 10:38:28 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 11802057 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9EEE86CB for ; Sun, 27 Sep 2020 12:17:11 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4DD3723718 for ; Sun, 27 Sep 2020 12:17:11 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=crudebyte.com header.i=@crudebyte.com header.b="oxcvDeqN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4DD3723718 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=crudebyte.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:50116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kMVc6-0000qK-AZ for patchwork-qemu-devel@patchwork.kernel.org; Sun, 27 Sep 2020 08:17:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52638) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <1fb057f08700e9264634c90b960f2c93f36cfb44@lizzy.crudebyte.com>) id 1kMVbI-000883-Ce for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:16:20 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:36287) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <1fb057f08700e9264634c90b960f2c93f36cfb44@lizzy.crudebyte.com>) id 1kMVbG-0006SG-N4 for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:16:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=vzTZmwRo6gxL8ZvAfTv4lGN1iSk8y/hJoFzIf3N9sQc=; b=oxcvD eqNfbpl1ZGjoSkbxF0W3Y0/nVsMUNrRKobGxBdW3m7/tWFVQ80Cm8+30GH0CGmJ0ErZpYyiZbYmqp pl8UATKl7AadaAtmz6Z0AsRRnAUA9tKtFKg8cNUI82GJC3EugcskDh4sdChaQql9TQnXz4YZoc1CC URGNseDQdCvXqFi3H+r1Id07yXCDSIoVvlI7jh4adsfGAfRzWOvSn89JEl8volG1j7sp6gfHXViXq WDEtrdm6IFGCsXlEkW6rP5mOV7ay5Nvao0xboZL4EEKjowqSArk8Wk9eSDg7kQ5q0EgVadYu5RvAH HTy8wOEQXChrFw2UL8AjuHj3NC2Ow==; Message-Id: <1fb057f08700e9264634c90b960f2c93f36cfb44.1601203436.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Sun, 27 Sep 2020 12:38:28 +0200 Subject: [PATCH 01/12] tests/qtest/qgraph: add qemu_name to QOSGraphNode To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Paolo Bonzini , Emanuele Giuseppe Esposito , Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=1fb057f08700e9264634c90b960f2c93f36cfb44@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/27 07:42:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Add new member variable 'qemu_name' to struct QOSGraphNode. This new member may be optionally set in case a different name for the node (which must always be unique) vs. its actually associated QEMU (QMP) device name is required. Signed-off-by: Christian Schoenebeck --- tests/qtest/libqos/qgraph.c | 1 + tests/qtest/libqos/qgraph_internal.h | 1 + 2 files changed, 2 insertions(+) diff --git a/tests/qtest/libqos/qgraph.c b/tests/qtest/libqos/qgraph.c index fc49cfa879..e42f3eaafa 100644 --- a/tests/qtest/libqos/qgraph.c +++ b/tests/qtest/libqos/qgraph.c @@ -153,6 +153,7 @@ static QOSGraphNode *create_node(const char *name, QOSNodeType type) static void destroy_node(void *val) { QOSGraphNode *node = val; + g_free(node->qemu_name); g_free(node->command_line); g_free(node); } diff --git a/tests/qtest/libqos/qgraph_internal.h b/tests/qtest/libqos/qgraph_internal.h index 968fa69450..974985dce9 100644 --- a/tests/qtest/libqos/qgraph_internal.h +++ b/tests/qtest/libqos/qgraph_internal.h @@ -56,6 +56,7 @@ struct QOSGraphNode { bool available; /* set by QEMU via QMP, used during graph walk */ bool visited; /* used during graph walk */ char *name; /* used to identify the node */ + char *qemu_name; /* optional: see qos_node_create_driver_named() */ char *command_line; /* used to start QEMU at test execution */ union { struct { From patchwork Sun Sep 27 10:39:00 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 11802055 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 53CA76CB for ; Sun, 27 Sep 2020 12:16:21 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 187E02389F for ; Sun, 27 Sep 2020 12:16:21 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=crudebyte.com header.i=@crudebyte.com header.b="PmZjNk0L" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 187E02389F Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=crudebyte.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:47276 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kMVbI-00086R-6l for patchwork-qemu-devel@patchwork.kernel.org; Sun, 27 Sep 2020 08:16:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52454) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kMVaF-0006wg-W8 for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:15:16 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:45003) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kMVaD-0006Mz-Kz for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:15:15 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=u38o6Urrjnc7Jg5615IWWJbb5xaiKnTL1nkmnv3/K9c=; b=PmZjN k0LK2vP+JqanH5bn77zJ89uC9JByY/m9klei9Wo1k0ESGnMDYxVUctplxoreyqi3dX40wJQ1i2MYk HyfI45UKukZrzNOqv61aBVuWDD9oql58zJPufC6/F5HssyUWSm/jleb51osIX3fGG1sT935SzGp40 y7km85xP4luGxL7wZIbCEgwiP9bMxoyMA8u09bgTiqcrL7tIe4ewrYQefYWUJwjrHmpT44tHHfiTU VRnVmqEXnuqjZGulTwlMsomss4rP91MHkZELCIu/gE4g4bW+E8R1GGelfLrhNfNRN88nLiqD3egAE EvnTeBRQTHA3AMYafSDNHQG92t5sg==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Sun, 27 Sep 2020 12:39:00 +0200 Subject: [PATCH 02/12] tests/qtest/qgraph: add qos_node_create_driver_named() To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Paolo Bonzini , Emanuele Giuseppe Esposito , Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=e19ada89f61345a2260f2b6ebd07fda9ed6458ce@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/27 07:42:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" So far the qos subsystem of the qtest framework had the limitation that only one instance of the same official QEMU (QMP) driver name could be created for qtests. That's because a) the created qos node names must always be unique, b) the node name must match the official QEMU driver name being instantiated and c) all nodes are in a global space shared by all tests. This patch removes this limitation by introducing a new function qos_node_create_driver_named() which allows test case authors to specify a node name being different from the actual associated QEMU driver name. It fills the new 'qemu_name' field of QOSGraphNode for that purpose. build_driver_cmd_line() and qos_graph_node_set_availability() had to be adjusted to correctly deal with either accessing node name vs. node's qemu_name correctly. Signed-off-by: Christian Schoenebeck --- tests/qtest/libqos/qgraph.c | 53 ++++++++++++++++++++++++++++++++++--- tests/qtest/libqos/qgraph.h | 16 +++++++++++ 2 files changed, 66 insertions(+), 3 deletions(-) diff --git a/tests/qtest/libqos/qgraph.c b/tests/qtest/libqos/qgraph.c index e42f3eaafa..61faf6b27d 100644 --- a/tests/qtest/libqos/qgraph.c +++ b/tests/qtest/libqos/qgraph.c @@ -287,7 +287,8 @@ static void build_machine_cmd_line(QOSGraphNode *node, const char *args) */ static void build_driver_cmd_line(QOSGraphNode *node) { - node->command_line = g_strconcat(" -device ", node->name, NULL); + const char *name = node->qemu_name ?: node->name; + node->command_line = g_strconcat(" -device ", name, NULL); } /* qos_print_cb(): callback prints all path found by the DFS algorithm. */ @@ -632,6 +633,15 @@ void qos_node_create_driver(const char *name, QOSCreateDriverFunc function) node->u.driver.constructor = function; } +void qos_node_create_driver_named(const char *name, const char *qemu_name, + QOSCreateDriverFunc function) +{ + QOSGraphNode *node = create_node(name, QNODE_DRIVER); + node->qemu_name = g_strdup(qemu_name); + build_driver_cmd_line(node); + node->u.driver.constructor = function; +} + void qos_node_contains(const char *container, const char *contained, QOSGraphEdgeOptions *opts, ...) { @@ -664,7 +674,7 @@ void qos_node_consumes(const char *consumer, const char *interface, add_edge(interface, consumer, QEDGE_CONSUMED_BY, opts); } -void qos_graph_node_set_availability(const char *node, bool av) +static void qos_graph_node_set_availability_explicit(const char *node, bool av) { QOSGraphEdgeList *elist; QOSGraphNode *n = search_node(node); @@ -679,9 +689,46 @@ void qos_graph_node_set_availability(const char *node, bool av) } QSLIST_FOREACH_SAFE(e, elist, edge_list, next) { if (e->type == QEDGE_CONTAINS || e->type == QEDGE_PRODUCES) { - qos_graph_node_set_availability(e->dest, av); + qos_graph_node_set_availability_explicit(e->dest, av); + } + } +} + +/* + * Behaves as qos_graph_node_set_availability_explicit(), except that the + * former always matches by node name only, whereas this function matches both + * by node name and node's optional 'qemu_name' field. + */ +void qos_graph_node_set_availability(const char *node, bool av) +{ + GList *l; + QOSGraphEdgeList *elist; + QOSGraphEdge *e, *next; + QOSGraphNode *n; + GList *keys = g_hash_table_get_keys(node_table); + + for (l = keys; l != NULL; l = l->next) { + const gchar *key = l->data; + n = g_hash_table_lookup(node_table, key); + /* + * node's 'qemu_name' is set if there is more than one device with + * the same QEMU (QMP) device name + */ + const char *node_name = n->qemu_name ?: n->name; + if (g_strcmp0(node_name, node) == 0) { + n->available = av; + elist = get_edgelist(n->name); + if (elist) { + QSLIST_FOREACH_SAFE(e, elist, edge_list, next) { + if (e->type == QEDGE_CONTAINS || e->type == QEDGE_PRODUCES) + { + qos_graph_node_set_availability_explicit(e->dest, av); + } + } + } } } + g_list_free(keys); } void qos_graph_foreach_test_path(QOSTestCallback fn) diff --git a/tests/qtest/libqos/qgraph.h b/tests/qtest/libqos/qgraph.h index 5f63d352ca..f472949f68 100644 --- a/tests/qtest/libqos/qgraph.h +++ b/tests/qtest/libqos/qgraph.h @@ -452,6 +452,22 @@ void qos_node_create_machine_args(const char *name, */ void qos_node_create_driver(const char *name, QOSCreateDriverFunc function); +/** + * Behaves as qos_node_create_driver() with the extension of allowing to + * specify a different node name vs. associated QEMU device name. + * + * Use this function instead of qos_node_create_driver() if you need to create + * several instances of the same QEMU device. You are free to choose a custom + * node name, however the chosen node name must always be unique. + * + * @param name: custom, unique name of the node to be created + * @param qemu_name: actual (official) QEMU driver name the node shall be + * associated with + * @param function: driver constructor + */ +void qos_node_create_driver_named(const char *name, const char *qemu_name, + QOSCreateDriverFunc function); + /** * qos_node_contains(): creates one or more edges of type QEDGE_CONTAINS * and adds them to the edge list mapped to @container in the From patchwork Sun Sep 27 10:39:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 11802061 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CE46A6CB for ; Sun, 27 Sep 2020 12:19:49 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6A2B623718 for ; Sun, 27 Sep 2020 12:19:49 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=crudebyte.com header.i=@crudebyte.com header.b="Rjjgy3n8" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6A2B623718 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=crudebyte.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:57598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kMVee-0003vF-Ez for patchwork-qemu-devel@patchwork.kernel.org; Sun, 27 Sep 2020 08:19:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53024) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kMVdK-0002c0-ES for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:18:26 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:52907) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kMVdI-0006jf-PH for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:18:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=RpchxIRjTMmMwFMZr0cf7veocelrms95TEq16l9UbCI=; b=Rjjgy 3n8LaAjKpQam7Z0TBI/9EcjqbYlPQmWY9dOfl3gxKaDIC7g/1mH+lcO9+Dn0TO8lzft2tXVZKWVXB oW6QYp1US/T7rdTwQd7uGO9KpLzcLE6OPk5z1OLyZVd6sLKt36G8y69l/tlFl1PMGC4UJUu/Y/16O G9yOVAnZv02POuRfBA70/FnJ2ya5duQgWDKdMzYJ5RlzXmcLV4sPvZ3PKajNJ5tmTdqoKDNgLVGZy 3TzZoVnjoqs7QXqUQh1Ur3VrYNMxKrZ6bWZ3kkIXp+Gd6lo9OYpdOgjiR5VcHJUCo0r5xOhRU0/gk CUkeVlMY9e22kJBIG2+bXbdx/XaNA==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Sun, 27 Sep 2020 12:39:17 +0200 Subject: [PATCH 03/12] tests/qtest/qos: add qos_dump_graph() To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Paolo Bonzini , Emanuele Giuseppe Esposito , Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=b40b46794184fc18bbd39d8aa7f01ca3ee1fbb2f@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/27 07:42:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This new function is purely for debugging purposes. It prints the current qos graph to stdout and allows to identify problems in the created qos graph e.g. when writing new qos tests. Signed-off-by: Christian Schoenebeck --- tests/qtest/libqos/qgraph.c | 54 +++++++++++++++++++++++++++++++++++++ tests/qtest/libqos/qgraph.h | 20 ++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/tests/qtest/libqos/qgraph.c b/tests/qtest/libqos/qgraph.c index 61faf6b27d..e70635750e 100644 --- a/tests/qtest/libqos/qgraph.c +++ b/tests/qtest/libqos/qgraph.c @@ -805,3 +805,57 @@ void qos_delete_cmd_line(const char *name) node->command_line = NULL; } } + +#define RED(txt) ( \ + "\033[0;91m" txt \ + "\033[0m" \ +) + +#define GREEN(txt) ( \ + "\033[0;92m" txt \ + "\033[0m" \ +) + +void qos_dump_graph(void) +{ + GList *keys; + GList *l; + QOSGraphEdgeList *list; + QOSGraphEdge *e, *next; + QOSGraphNode *dest_node, *node; + + printf("ALL QGRAPH EDGES: {\n"); + keys = g_hash_table_get_keys(edge_table); + for (l = keys; l != NULL; l = l->next) { + const gchar *key = l->data; + printf("\t src='%s'\n", key); + list = get_edgelist(key); + QSLIST_FOREACH_SAFE(e, list, edge_list, next) { + dest_node = g_hash_table_lookup(node_table, e->dest); + printf("\t\t|-> dest='%s' type=%d (node=%p)", + e->dest, e->type, dest_node); + if (!dest_node) { + printf(RED(" <------- ERROR !")); + } + printf("\n"); + } + } + g_list_free(keys); + printf("}\n"); + + printf("ALL QGRAPH NODES: {\n"); + keys = g_hash_table_get_keys(node_table); + for (l = keys; l != NULL; l = l->next) { + const gchar *key = l->data; + node = g_hash_table_lookup(node_table, key); + printf("\t name='%s' ", key); + if (node->qemu_name) { + printf("qemu_name='%s' ", node->qemu_name); + } + printf("type=%d cmd_line='%s' [%s]\n", + node->type, node->command_line, + node->available ? GREEN("available") : RED("UNAVAILBLE")); + } + g_list_free(keys); + printf("}\n"); +} diff --git a/tests/qtest/libqos/qgraph.h b/tests/qtest/libqos/qgraph.h index f472949f68..07a32535f1 100644 --- a/tests/qtest/libqos/qgraph.h +++ b/tests/qtest/libqos/qgraph.h @@ -586,5 +586,25 @@ QOSGraphObject *qos_machine_new(QOSGraphNode *node, QTestState *qts); QOSGraphObject *qos_driver_new(QOSGraphNode *node, QOSGraphObject *parent, QGuestAllocator *alloc, void *arg); +/** + * Just for debugging purpose: prints all currently existing nodes and + * edges to stdout. + * + * All qtests add themselves to the overall qos graph by calling qgraph + * functions that add device nodes and edges between the individual graph + * nodes for tests. As the actual graph is assmbled at runtime by the qos + * subsystem, it is sometimes not obvious how the overall graph looks like. + * E.g. when writing new tests it may happen that those new tests are simply + * ignored by the qtest framework. + * + * This function allows to identify problems in the created qgraph. Keep in + * mind: only tests with a path down from the actual test case node (leaf) up + * to the graph's root node are actually executed by the qtest framework. And + * the qtest framework uses QMP to automatically check which QEMU drivers are + * actually currently available, and accordingly qos marks certain pathes as + * 'unavailable' in such cases (e.g. when QEMU was compiled without support for + * a certain feature). + */ +void qos_dump_graph(void); #endif From patchwork Sun Sep 27 10:39:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 11802053 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CB169618 for ; Sun, 27 Sep 2020 12:14:51 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5F4C523718 for ; Sun, 27 Sep 2020 12:14:51 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=crudebyte.com header.i=@crudebyte.com header.b="GvNOpfH5" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5F4C523718 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=crudebyte.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:43814 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kMVZq-0006a6-HP for patchwork-qemu-devel@patchwork.kernel.org; Sun, 27 Sep 2020 08:14:50 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52272) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <0101be73855284d25a44e7d3051d515456db94b9@lizzy.crudebyte.com>) id 1kMVZD-00064a-Ca for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:14:11 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:51153) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <0101be73855284d25a44e7d3051d515456db94b9@lizzy.crudebyte.com>) id 1kMVZC-0006Ib-2J for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:14:11 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=GtJHuwyoegajjaKgnQ0LAhrlyUdI4zEzua7f4qjZ8wI=; b=GvNOp fH5t8mNUTu4srnb/TGDuOdPQLcfvpYVKtYDRrLVFOwX1+MI7tBNlu8ir1BXiBJARfUom7tFKA34Cs ZNV0WsWappRzgciEil/eGpLxdf0vziSeNtffSVyJA9nkPR5oNMrTXMBAA2q5GyfCUcpYtELG3F/jJ 5PBZDJRGGBprk9zanVU37QmJErOzrBQbA4LNrj6l8lTq76EmmeWx62N9SZFRYcvudZvCd1jBki1nj fhBr3CA+i171hcRhgwNRkrvwycEZPP91TjOYslz9lhjJ2wcL1espUVwG19wd4bKsXNN8/x++t60ec vZr+EZl3Je7rOymIMy3gRQtAEw5kA==; Message-Id: <0101be73855284d25a44e7d3051d515456db94b9.1601203436.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Sun, 27 Sep 2020 12:39:34 +0200 Subject: [PATCH 04/12] tests/qtest/qos-test: new QTEST_DUMP_GRAPH environment variable To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Paolo Bonzini , Emanuele Giuseppe Esposito , Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=0101be73855284d25a44e7d3051d515456db94b9@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/27 07:42:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Setting this new QTEST_DUMP_GRAPH environment variable causes qos-test to dump the created qos graph (all nodes and edges, along with their current individual availability status) to stdout. See API doc comment on function qos_dump_graph() for details. Signed-off-by: Christian Schoenebeck --- tests/qtest/qos-test.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/qtest/qos-test.c b/tests/qtest/qos-test.c index 8fdf87b183..db667e16da 100644 --- a/tests/qtest/qos-test.c +++ b/tests/qtest/qos-test.c @@ -322,6 +322,9 @@ int main(int argc, char **argv) qos_set_machines_devices_available(); qos_graph_foreach_test_path(walk_path); + if (getenv("QTEST_DUMP_GRAPH") != NULL) { + qos_dump_graph(); + } g_test_run(); qtest_end(); qos_graph_destroy(); From patchwork Sun Sep 27 10:39:54 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 11802045 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B279F6CB for ; Sun, 27 Sep 2020 12:08:01 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E66422389F for ; Sun, 27 Sep 2020 12:08:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=crudebyte.com header.i=@crudebyte.com header.b="mH6i+gLe" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E66422389F Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=crudebyte.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:34744 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kMVTD-0002cU-IN for patchwork-qemu-devel@patchwork.kernel.org; Sun, 27 Sep 2020 08:07:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51292) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kMVSb-0002CX-Tf for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:07:21 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:53175) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kMVSa-0005Zb-3t for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:07:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=801Pvm947DyXbU4TP1t/rbST7LiYXx1aSU7SF7Jmwnw=; b=mH6i+ gLeUEpTWIpbDriWXjmN8BDTgtZNEsICYwcck03PeHh0i8mJyTIe7pgdqk+fnLPxOIaZhghp/2aVzv PQqouvxTljX4mAStDXQweZXXw6USammrenfZqwWNFvQvRV/ifZCb1GPzsExgxW+mOak8epgABwv9l GcZydITUkc8L0hvlkFIRjcW/roR+3w/tt/QAoyFTeVdjy27nqitZn1yJ5fv5Y0X/as4llQ2R00l26 oBe48E/CISV1q9AUcGmpVaxIROBUqmwXE+pG8+db7t6zFwQ5gqPy5VNGdZJ4cWZ79b6EWj8N2dMGQ BrGZKehyQY9M3zNpt9wBOOWnf0QJQ==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Sun, 27 Sep 2020 12:39:54 +0200 Subject: [PATCH 05/12] tests/qtest/qos-test: add QTEST_DUMP_ENV environment variable To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Paolo Bonzini , Emanuele Giuseppe Esposito , Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=fcbcd16ad20daa20680665dd38942f01b3a310aa@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/27 07:42:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" If this new QTEST_DUMP_ENV is set, it will cause all environment variables to be dumped to stdout. Signed-off-by: Christian Schoenebeck --- tests/qtest/qos-test.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/tests/qtest/qos-test.c b/tests/qtest/qos-test.c index db667e16da..4b1a1922fc 100644 --- a/tests/qtest/qos-test.c +++ b/tests/qtest/qos-test.c @@ -313,8 +313,15 @@ static void walk_path(QOSGraphNode *orig_path, int len) * machine/drivers/test objects * - Cleans up everything */ -int main(int argc, char **argv) +int main(int argc, char **argv, char** envp) { + if (getenv("QTEST_DUMP_ENV") != NULL) { + printf("ENVIRONMENT VARIABLES: {\n"); + for (char **env = envp; *env != 0; env++) { + printf("\t%s\n", *env); + } + printf("}\n"); + } g_test_init(&argc, &argv, NULL); qos_graph_init(); module_call_init(MODULE_INIT_QOM); From patchwork Sun Sep 27 10:40:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 11802049 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 148EC6CB for ; Sun, 27 Sep 2020 12:11:26 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 99BEC23718 for ; Sun, 27 Sep 2020 12:11:25 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=crudebyte.com header.i=@crudebyte.com header.b="S72lexkg" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 99BEC23718 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=crudebyte.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:39586 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kMVWW-0004lN-M3 for patchwork-qemu-devel@patchwork.kernel.org; Sun, 27 Sep 2020 08:11:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51848) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kMVVv-0004Kl-Tn for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:10:47 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:50987) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kMVVu-0005my-Fw for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:10:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=pY75VwLoxKQv1SwLMelW/wR9FrH1mMMB6Kt18BguEts=; b=S72le xkgu6wO/TsIAJF+t+qD5n7mqxgQT9v8faJPW5K6kfMLCUIkP+qYlug6q7bNJDmC8VsoGaStYNSFS9 XZjWkvnyFar914F0t17K4PpWwkxa7cc3V8iExH5ZsLjkgdhkyv4X3Z3SvdUpGMFJet3PD0b2EKIyO FbaUZW2cf3Awoh6XsVLODM4UoryoKQA/9SYALRi+2nYt8Z9Jbe13EIDHtAgdKknjCSf2BPSAshItE gmHMzP29uDr9SIukPHVR/QOieD/8oLneLYcGpuHcuidXoGjTeolqgpe1uXFYnmPuxYoNHpa6aW50j wIjz+cC/S4SHwOx/wAG4r0yqSgAPw==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Sun, 27 Sep 2020 12:40:07 +0200 Subject: [PATCH 06/12] tests/qtest/qos-test: add environment variable QTEST_DEBUG To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Paolo Bonzini , Emanuele Giuseppe Esposito , Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=cc6109fcc03d47a68d01ceac5ade71fe8467a3f7@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/27 07:42:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" For now this new environment variable QTEST_DEBUG will cause the assembled qemu command line to be printed before running each test. Signed-off-by: Christian Schoenebeck --- tests/qtest/qos-test.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/qtest/qos-test.c b/tests/qtest/qos-test.c index 4b1a1922fc..571d1e140a 100644 --- a/tests/qtest/qos-test.c +++ b/tests/qtest/qos-test.c @@ -89,6 +89,9 @@ static void qos_set_machines_devices_available(void) static void restart_qemu_or_continue(char *path) { + if (getenv("QTEST_DEBUG") != NULL) { + printf("run QEMU with: '%s'\n", path); + } /* compares the current command line with the * one previously executed: if they are the same, * don't restart QEMU, if they differ, stop previous From patchwork Sun Sep 27 10:40:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 11802051 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A77E36CB for ; Sun, 27 Sep 2020 12:13:41 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3338E23718 for ; Sun, 27 Sep 2020 12:13:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=crudebyte.com header.i=@crudebyte.com header.b="jWSbJUqY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3338E23718 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=crudebyte.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:41714 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kMVYi-0005hh-6a for patchwork-qemu-devel@patchwork.kernel.org; Sun, 27 Sep 2020 08:13:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52162) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kMVYC-0005IT-VY for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:13:09 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:47425) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kMVYA-00066K-AU for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:13:08 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=cdYoMuk7yWJGGnSW3M/mg3s/OyEZ1H38EURPSLuhe2s=; b=jWSbJ UqYR0fso4+D8rbuSmOzADgIyvZziIdKgnyzdsXWQk59JKAGmELbAElMncpJ9aSrbnaiQKe8rxX6OF 9mPaF0+Ma8KaDBFuM9+DsgMW3Nqf3G3aH3V/mEPITngDa5MlNm3qvv7TyeBjaytkuQ61Cxzly8qlW y4xO93FlSUqwcz4X+rqq0G0bG63545K2KqZvfoyk2g1NkPC+awUuyr9N4kXyWE4sasboU1fzbmXs6 sw8L7kXDQM3g8mzUaW6RzCQTebgJ9r/rufqouxg79c4wm8BeXaK7qauzrSm0YE7204Imr/pgLbw/t oR/mNkqalXfccnh0p7Vxtj3WzO5/g==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Sun, 27 Sep 2020 12:40:21 +0200 Subject: [PATCH 07/12] test/9pfs: change export tag name to qtest-synth To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Paolo Bonzini , Emanuele Giuseppe Esposito , Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=e6142a0af2050fa1355b8bc6de6162c4cd675812@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/27 07:42:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" All existing 9pfs test cases are using the 'synth' fs driver so far, which means they are not accessing real files, but a purely simulated (in RAM only) file system. Let's start to make this clear with this and the following patch to pave the way for upcoming new tests going to use the 9pfs 'local' driver instead. This patch starts by changing the 9p tag name (which identifies one particular 9p exported file tree) from 'qtest' to 'qtest-synth' and also change the preprocessor macro used for this from TAG_NAME to TAG_NAME_SYNTH. Signed-off-by: Christian Schoenebeck --- tests/qtest/libqos/virtio-9p.c | 4 ++-- tests/qtest/libqos/virtio-9p.h | 2 +- tests/qtest/virtio-9p-test.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c index 2e300063e3..9f099737f9 100644 --- a/tests/qtest/libqos/virtio-9p.c +++ b/tests/qtest/libqos/virtio-9p.c @@ -148,8 +148,8 @@ static void *virtio_9p_pci_create(void *pci_bus, QGuestAllocator *t_alloc, static void virtio_9p_register_nodes(void) { - const char *str_simple = "fsdev=fsdev0,mount_tag=" MOUNT_TAG; - const char *str_addr = "fsdev=fsdev0,addr=04.0,mount_tag=" MOUNT_TAG; + const char *str_simple = "fsdev=fsdev0,mount_tag=" MOUNT_TAG_SYNTH; + const char *str_addr = "fsdev=fsdev0,addr=04.0,mount_tag=" MOUNT_TAG_SYNTH; QPCIAddress addr = { .devfn = QPCI_DEVFN(4, 0), diff --git a/tests/qtest/libqos/virtio-9p.h b/tests/qtest/libqos/virtio-9p.h index b1e6badc4a..d9a815083f 100644 --- a/tests/qtest/libqos/virtio-9p.h +++ b/tests/qtest/libqos/virtio-9p.h @@ -27,7 +27,7 @@ typedef struct QVirtio9P QVirtio9P; typedef struct QVirtio9PPCI QVirtio9PPCI; typedef struct QVirtio9PDevice QVirtio9PDevice; -#define MOUNT_TAG "qtest" +#define MOUNT_TAG_SYNTH "qtest-synth" struct QVirtio9P { QVirtioDevice *vdev; diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c index de30b717b6..f7505396f3 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -26,13 +26,13 @@ static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc) char *tag; int i; - g_assert_cmpint(tag_len, ==, strlen(MOUNT_TAG)); + g_assert_cmpint(tag_len, ==, strlen(MOUNT_TAG_SYNTH)); tag = g_malloc(tag_len); for (i = 0; i < tag_len; i++) { tag[i] = qvirtio_config_readb(v9p->vdev, i + 2); } - g_assert_cmpmem(tag, tag_len, MOUNT_TAG, tag_len); + g_assert_cmpmem(tag, tag_len, MOUNT_TAG_SYNTH, tag_len); g_free(tag); } From patchwork Sun Sep 27 10:40:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 11802063 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 20784139A for ; Sun, 27 Sep 2020 12:21:30 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9A6CA23718 for ; Sun, 27 Sep 2020 12:21:29 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=crudebyte.com header.i=@crudebyte.com header.b="TqvZ2ijj" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9A6CA23718 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=crudebyte.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:60650 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kMVgG-0005HL-Oj for patchwork-qemu-devel@patchwork.kernel.org; Sun, 27 Sep 2020 08:21:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53208) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <265f5d9a0fb10ce5e782455839d1baf678dbac48@lizzy.crudebyte.com>) id 1kMVeL-0003bd-5z for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:19:29 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:44541) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <265f5d9a0fb10ce5e782455839d1baf678dbac48@lizzy.crudebyte.com>) id 1kMVeJ-0006o8-Dn for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:19:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=JWoDBnO+yolHB04O/0j0yUtvrSSuKrhkfcd+BHmO3/0=; b=TqvZ2 ijjVaAt1vRlgfAVeuwU2FXL/fHor/PiL3MtR5iDZBvbtnkxmWKXm6F071mNhfOxvWoBl4GfkK/7qs PRgU/0YnnCqw+3KgLbn0dQQhDaVqbTdUePB34qYgq0EXwXnXs4htFapSrPd2dqrXjZNxHXYCsQAB/ v8meCysIxYEu+fjbKn4EpLkQ1GPVTqjKOlVbnFfEq0eWlAJujJHR9ET0pcUjrC+JvqvoZrbky3yGk nqIC9o5P9GHABYCFkugBDqZwaJS2DIEfJH233oGR2bqSog8LvR3v/912AYmNriW+nHm+E7gv9OkDu 6dvnnFClSjI9RIa/RzMIVlelKkOoA==; Message-Id: <265f5d9a0fb10ce5e782455839d1baf678dbac48.1601203436.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Sun, 27 Sep 2020 12:40:34 +0200 Subject: [PATCH 08/12] tests/9pfs: refactor test names and test devices To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Paolo Bonzini , Emanuele Giuseppe Esposito , Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=265f5d9a0fb10ce5e782455839d1baf678dbac48@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/27 07:42:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Rename all 9pfs tests and devices they create for running their tests from 'virtio*' -> 'virtio*-synth'. In order for the tests still to work after this renaming, use the newly added function qos_node_create_driver_named() instead of qos_node_create_driver(). That new function allows to assign a name to a device that differs from the actual QEMU driver it's using. Signed-off-by: Christian Schoenebeck --- tests/qtest/libqos/virtio-9p.c | 29 ++++++++++++++------------- tests/qtest/virtio-9p-test.c | 36 +++++++++++++++++----------------- 2 files changed, 33 insertions(+), 32 deletions(-) diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c index 9f099737f9..1bda5403ff 100644 --- a/tests/qtest/libqos/virtio-9p.c +++ b/tests/qtest/libqos/virtio-9p.c @@ -62,10 +62,10 @@ static void virtio_9p_device_start_hw(QOSGraphObject *obj) static void *virtio_9p_get_driver(QVirtio9P *v_9p, const char *interface) { - if (!g_strcmp0(interface, "virtio-9p")) { + if (!g_strcmp0(interface, "virtio-9p-synth")) { return v_9p; } - if (!g_strcmp0(interface, "virtio")) { + if (!g_strcmp0(interface, "virtio-synth")) { return v_9p->vdev; } @@ -159,22 +159,23 @@ static void virtio_9p_register_nodes(void) .before_cmd_line = "-fsdev synth,id=fsdev0", }; - /* virtio-9p-device */ + /* virtio-9p-device-synth */ opts.extra_device_opts = str_simple, - qos_node_create_driver("virtio-9p-device", virtio_9p_device_create); - qos_node_consumes("virtio-9p-device", "virtio-bus", &opts); - qos_node_produces("virtio-9p-device", "virtio"); - qos_node_produces("virtio-9p-device", "virtio-9p"); + qos_node_create_driver_named("virtio-9p-device-synth", "virtio-9p-device", + virtio_9p_device_create); + qos_node_consumes("virtio-9p-device-synth", "virtio-bus", &opts); + qos_node_produces("virtio-9p-device-synth", "virtio-synth"); + qos_node_produces("virtio-9p-device-synth", "virtio-9p-synth"); - /* virtio-9p-pci */ + /* virtio-9p-pci-synth */ opts.extra_device_opts = str_addr; add_qpci_address(&opts, &addr); - qos_node_create_driver("virtio-9p-pci", virtio_9p_pci_create); - qos_node_consumes("virtio-9p-pci", "pci-bus", &opts); - qos_node_produces("virtio-9p-pci", "pci-device"); - qos_node_produces("virtio-9p-pci", "virtio"); - qos_node_produces("virtio-9p-pci", "virtio-9p"); - + qos_node_create_driver_named("virtio-9p-pci-synth", "virtio-9p-pci", + virtio_9p_pci_create); + qos_node_consumes("virtio-9p-pci-synth", "pci-bus", &opts); + qos_node_produces("virtio-9p-pci-synth", "pci-device"); + qos_node_produces("virtio-9p-pci-synth", "virtio-synth"); + qos_node_produces("virtio-9p-pci-synth", "virtio-9p-synth"); } libqos_init(virtio_9p_register_nodes); diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c index f7505396f3..d46d675309 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -897,27 +897,27 @@ static void fs_readdir_split_512(void *obj, void *data, static void register_virtio_9p_test(void) { - qos_add_test("config", "virtio-9p", pci_config, NULL); - qos_add_test("fs/version/basic", "virtio-9p", fs_version, NULL); - qos_add_test("fs/attach/basic", "virtio-9p", fs_attach, NULL); - qos_add_test("fs/walk/basic", "virtio-9p", fs_walk, NULL); - qos_add_test("fs/walk/no_slash", "virtio-9p", fs_walk_no_slash, + /* selects the 9pfs 'synth' filesystem driver for the respective test */ + const char *synth_driver = "virtio-9p-synth"; + + qos_add_test("config", synth_driver, pci_config, NULL); + qos_add_test("fs/version/basic", synth_driver, fs_version, NULL); + qos_add_test("fs/attach/basic", synth_driver, fs_attach, NULL); + qos_add_test("fs/walk/basic", synth_driver, fs_walk, NULL); + qos_add_test("fs/walk/no_slash", synth_driver, fs_walk_no_slash, NULL); + qos_add_test("fs/walk/dotdot_from_root", synth_driver, fs_walk_dotdot, NULL); - qos_add_test("fs/walk/dotdot_from_root", "virtio-9p", - fs_walk_dotdot, NULL); - qos_add_test("fs/lopen/basic", "virtio-9p", fs_lopen, NULL); - qos_add_test("fs/write/basic", "virtio-9p", fs_write, NULL); - qos_add_test("fs/flush/success", "virtio-9p", fs_flush_success, + qos_add_test("fs/lopen/basic", synth_driver, fs_lopen, NULL); + qos_add_test("fs/write/basic", synth_driver, fs_write, NULL); + qos_add_test("fs/flush/success", synth_driver, fs_flush_success, NULL); + qos_add_test("fs/flush/ignored", synth_driver, fs_flush_ignored, NULL); + qos_add_test("fs/readdir/basic", synth_driver, fs_readdir, NULL); + qos_add_test("fs/readdir/split_512", synth_driver, fs_readdir_split_512, NULL); - qos_add_test("fs/flush/ignored", "virtio-9p", fs_flush_ignored, + qos_add_test("fs/readdir/split_256", synth_driver, fs_readdir_split_256, + NULL); + qos_add_test("fs/readdir/split_128", synth_driver, fs_readdir_split_128, NULL); - qos_add_test("fs/readdir/basic", "virtio-9p", fs_readdir, NULL); - qos_add_test("fs/readdir/split_512", "virtio-9p", - fs_readdir_split_512, NULL); - qos_add_test("fs/readdir/split_256", "virtio-9p", - fs_readdir_split_256, NULL); - qos_add_test("fs/readdir/split_128", "virtio-9p", - fs_readdir_split_128, NULL); } libqos_init(register_virtio_9p_test); From patchwork Sun Sep 27 10:40:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 11802059 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 643616CB for ; Sun, 27 Sep 2020 12:18:18 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 27AB623718 for ; Sun, 27 Sep 2020 12:18:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=crudebyte.com header.i=@crudebyte.com header.b="AE/L+fKH" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 27AB623718 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=crudebyte.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:53654 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kMVdB-0002JU-7q for patchwork-qemu-devel@patchwork.kernel.org; Sun, 27 Sep 2020 08:18:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52852) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <44025a54367bc69073295b48b9b8b21bb419ca50@lizzy.crudebyte.com>) id 1kMVcJ-00016A-Hc for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:17:23 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:42049) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <44025a54367bc69073295b48b9b8b21bb419ca50@lizzy.crudebyte.com>) id 1kMVcH-0006fs-KM for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:17:23 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=snCJV9LSnmMnp5dULhDa2f2+dgymsNHca6AQx2Ncx10=; b=AE/L+ fKHoIWqWN8Mvl6tVZW08HTy/AQbzHNQXLG2XJQdBd4i2v1Hka82W1GhYblVyVw14CEiOe+BSdwI1b sRNZdY+lJTi7o5wCcih3mSEXHkfXfBnqnAOQAH8AELv7lE5/YRnWHvigWQ8hOTZ8sLptkR8XNKoY1 yAXFRGQeeLafI4SQqpKZwNTg7f1IuC7tBj5Wikq28quf3kzf55WJzogC83C0C9VlYRYyuZ7QZJXR9 039e0PpfKR1aik8GgIxvp+LGTa884PIPIIVZ76Yl97SNqhgI6ypDbaEt796yN6ruGSJ2YyggQdJyn fTvlz2EVMDJYaJDKPetwNNa8gQXdQ==; Message-Id: <44025a54367bc69073295b48b9b8b21bb419ca50.1601203436.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Sun, 27 Sep 2020 12:40:47 +0200 Subject: [PATCH 09/12] tests/9pfs: introduce local tests To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Paolo Bonzini , Emanuele Giuseppe Esposito , Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=44025a54367bc69073295b48b9b8b21bb419ca50@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/27 07:42:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This patch introduces 9pfs test cases using the 9pfs 'local' filesystem driver which reads/writes/creates/deletes real files and directories. In this initial version, there are only 2 local tests which actually only check if the 9pfs 'local' device was created successfully. Before the 9pfs 'local' tests are run, a test directory 'qtest-9p-local' is created (with world rwx permissions) under the current working directory. At this point that test directory is not auto deleted yet. A different PCI address, fsdev id and mount tag is used for the 'local' 9pfs device. This is not really necessary right now, but might be useful to avoid potential colissions in future. Signed-off-by: Christian Schoenebeck --- tests/qtest/libqos/virtio-9p.c | 101 ++++++++++++++++++++++++++++++++- tests/qtest/libqos/virtio-9p.h | 1 + tests/qtest/virtio-9p-test.c | 12 +++- 3 files changed, 110 insertions(+), 4 deletions(-) diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c index 1bda5403ff..400f4b0113 100644 --- a/tests/qtest/libqos/virtio-9p.c +++ b/tests/qtest/libqos/virtio-9p.c @@ -24,6 +24,61 @@ #include "qgraph.h" static QGuestAllocator *alloc; +static char *local_test_path; + +/* Concatenates the passed 2 pathes. Returned result must be freed. */ +static char *concat_path(const char* a, const char* b) +{ + const int len = strlen(a) + strlen("/") + strlen(b); + char *path = g_malloc0(len + 1); + snprintf(path, len + 1, "%s/%s", a, b); + g_assert(strlen(path) == len); + return path; +} + +/* + * Lazy sprintf() implementation which auto allocates buffer. Returned result + * must be freed. + */ +static char *strpr(const char* format, ...) +{ + va_list argp; + + va_start(argp, format); + const int sz = vsnprintf(NULL, 0, format, argp) + 1; + va_end(argp); + + g_assert(sz > 0); + char *s = g_malloc0(sz); + + va_start(argp, format); + const int len = vsnprintf(s, sz, format, argp); + va_end(argp); + + g_assert(len + 1 == sz); + return s; +} + +static void init_local_test_path(void) +{ + char *pwd = get_current_dir_name(); + local_test_path = concat_path(pwd, "qtest-9p-local"); + free(pwd); +} + +/* Creates the directory for the 9pfs 'local' filesystem driver to access. */ +static void create_local_test_dir(void) +{ + struct stat st; + + g_assert(local_test_path != NULL); + mkdir(local_test_path, 0777); + + /* ensure test directory exists now ... */ + g_assert(stat(local_test_path, &st) == 0); + /* ... and is actually a directory */ + g_assert((st.st_mode & S_IFMT) == S_IFDIR); +} static void virtio_9p_cleanup(QVirtio9P *interface) { @@ -62,10 +117,14 @@ static void virtio_9p_device_start_hw(QOSGraphObject *obj) static void *virtio_9p_get_driver(QVirtio9P *v_9p, const char *interface) { - if (!g_strcmp0(interface, "virtio-9p-synth")) { + if (!g_strcmp0(interface, "virtio-9p-synth") || + !g_strcmp0(interface, "virtio-9p-local")) + { return v_9p; } - if (!g_strcmp0(interface, "virtio-synth")) { + if (!g_strcmp0(interface, "virtio-synth") || + !g_strcmp0(interface, "virtio-local")) + { return v_9p->vdev; } @@ -148,6 +207,12 @@ static void *virtio_9p_pci_create(void *pci_bus, QGuestAllocator *t_alloc, static void virtio_9p_register_nodes(void) { + /* make sure test dir for the 'local' tests exists and is clean */ + init_local_test_path(); + create_local_test_dir(); + + /* 9pfs device using the 'synth' fs driver */ + const char *str_simple = "fsdev=fsdev0,mount_tag=" MOUNT_TAG_SYNTH; const char *str_addr = "fsdev=fsdev0,addr=04.0,mount_tag=" MOUNT_TAG_SYNTH; @@ -176,6 +241,38 @@ static void virtio_9p_register_nodes(void) qos_node_produces("virtio-9p-pci-synth", "pci-device"); qos_node_produces("virtio-9p-pci-synth", "virtio-synth"); qos_node_produces("virtio-9p-pci-synth", "virtio-9p-synth"); + + + /* 9pfs device using the 'local' fs driver */ + + const char *local_str_simple = "fsdev=fsdev1,mount_tag=" MOUNT_TAG_LOCAL; + const char *local_str_addr = "fsdev=fsdev1,addr=04.1,mount_tag=" + MOUNT_TAG_LOCAL; + + addr.devfn = QPCI_DEVFN(4, 1), + + opts.before_cmd_line = strpr( + "-fsdev local,id=fsdev1,path='%s',security_model=mapped-xattr", + local_test_path + ); + + /* virtio-9p-device-local */ + opts.extra_device_opts = local_str_simple, + qos_node_create_driver_named("virtio-9p-device-local", "virtio-9p-device", + virtio_9p_device_create); + qos_node_consumes("virtio-9p-device-local", "virtio-bus", &opts); + qos_node_produces("virtio-9p-device-local", "virtio-local"); + qos_node_produces("virtio-9p-device-local", "virtio-9p-local"); + + /* virtio-9p-pci-local */ + opts.extra_device_opts = local_str_addr; + add_qpci_address(&opts, &addr); + qos_node_create_driver_named("virtio-9p-pci-local", "virtio-9p-pci", + virtio_9p_pci_create); + qos_node_consumes("virtio-9p-pci-local", "pci-bus", &opts); + qos_node_produces("virtio-9p-pci-local", "pci-device"); + qos_node_produces("virtio-9p-pci-local", "virtio-local"); + qos_node_produces("virtio-9p-pci-local", "virtio-9p-local"); } libqos_init(virtio_9p_register_nodes); diff --git a/tests/qtest/libqos/virtio-9p.h b/tests/qtest/libqos/virtio-9p.h index d9a815083f..20d1fc6270 100644 --- a/tests/qtest/libqos/virtio-9p.h +++ b/tests/qtest/libqos/virtio-9p.h @@ -28,6 +28,7 @@ typedef struct QVirtio9PPCI QVirtio9PPCI; typedef struct QVirtio9PDevice QVirtio9PDevice; #define MOUNT_TAG_SYNTH "qtest-synth" +#define MOUNT_TAG_LOCAL "qtest-local" struct QVirtio9P { QVirtioDevice *vdev; diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c index d46d675309..88451f255f 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -26,13 +26,15 @@ static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc) char *tag; int i; - g_assert_cmpint(tag_len, ==, strlen(MOUNT_TAG_SYNTH)); + g_assert(tag_len == strlen(MOUNT_TAG_SYNTH) || + tag_len == strlen(MOUNT_TAG_LOCAL)); tag = g_malloc(tag_len); for (i = 0; i < tag_len; i++) { tag[i] = qvirtio_config_readb(v9p->vdev, i + 2); } - g_assert_cmpmem(tag, tag_len, MOUNT_TAG_SYNTH, tag_len); + g_assert(strncmp(tag, MOUNT_TAG_SYNTH, tag_len) == 0 || + strncmp(tag, MOUNT_TAG_LOCAL, tag_len) == 0); g_free(tag); } @@ -918,6 +920,12 @@ static void register_virtio_9p_test(void) NULL); qos_add_test("fs/readdir/split_128", synth_driver, fs_readdir_split_128, NULL); + + + /* selects the 9pfs 'local' filesystem driver for the respective test */ + const char *local_driver = "virtio-9p-local"; + + qos_add_test("config", local_driver, pci_config, NULL); } libqos_init(register_virtio_9p_test); From patchwork Sun Sep 27 10:41:01 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 11802083 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BF244618 for ; Sun, 27 Sep 2020 12:38:43 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2B23423718 for ; Sun, 27 Sep 2020 12:38:42 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=crudebyte.com header.i=@crudebyte.com header.b="V7Kzku44" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2B23423718 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=crudebyte.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:38188 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kMVwv-0000Kc-UO for patchwork-qemu-devel@patchwork.kernel.org; Sun, 27 Sep 2020 08:38:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3a589c709cf1e617156d374508533388cd946c9c@lizzy.crudebyte.com>) id 1kMVve-00086Z-Ng for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:37:22 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:33387) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from <3a589c709cf1e617156d374508533388cd946c9c@lizzy.crudebyte.com>) id 1kMVva-0000Ai-4Q for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:37:22 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=9IsaP5ZXjznl8OjHwQO/SJaqdndqR4ZYG5hpsBM/PFA=; b=V7Kzk u444RAxVCgyBFESngIRDYvh1Ko6p2i5KdyG/zPdOK2sIlL+AX+0LsJ3WZd3RMUfN+Dkxb7BhJERTB b56z7rYxCfULUIvkYqa0J8Vc1MovLNptMiylF9mx1Kj5QwPJ+DD4ZSnv8v1WSUszhXoUMPasvTD+Q rysQknQ8NEN+1aHwSwIW3zPbYDUDm5rZi8QvjcnxgK/F9J0MQw3KGHa7VIoXIDpecp92N4H+Lf5PG 2qBxKlngPVda/weHuwFNPPzfW3Ubxi+JS8XHeGY97RLGR1bAhk6DZKs5ZfeUU2yJUIppXR0eNL1xw 7noV7EIfc3mdmq8QvAK7zf4WiGBpg==; Message-Id: <3a589c709cf1e617156d374508533388cd946c9c.1601203436.git.qemu_oss@crudebyte.com> In-Reply-To: References: From: Christian Schoenebeck Date: Sun, 27 Sep 2020 12:41:01 +0200 Subject: [PATCH 10/12] tests/9pfs: wipe local 9pfs test directory To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Paolo Bonzini , Emanuele Giuseppe Esposito , Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=3a589c709cf1e617156d374508533388cd946c9c@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/27 07:42:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" Before running the first 9pfs test case, make sure the test directory for running the 9pfs 'local' tests on is entirely empty. For that reason simply delete the test directory (if any) before (re)creating it on test suite startup. Signed-off-by: Christian Schoenebeck --- tests/qtest/libqos/virtio-9p.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c index 400f4b0113..b44fc4ad63 100644 --- a/tests/qtest/libqos/virtio-9p.c +++ b/tests/qtest/libqos/virtio-9p.c @@ -80,6 +80,18 @@ static void create_local_test_dir(void) g_assert((st.st_mode & S_IFMT) == S_IFDIR); } +/* Deletes directory previously created by create_local_test_dir(). */ +static void remove_local_test_dir(void) +{ + g_assert(local_test_path != NULL); + char *cmd = strpr("rm -r '%s'\n", local_test_path); + int res = system(cmd); + if (res < 0) { + /* ignore error, dummy check to prevent compiler error */ + } + g_free(cmd); +} + static void virtio_9p_cleanup(QVirtio9P *interface) { qvirtqueue_cleanup(interface->vdev->bus, interface->vq, alloc); @@ -209,6 +221,7 @@ static void virtio_9p_register_nodes(void) { /* make sure test dir for the 'local' tests exists and is clean */ init_local_test_path(); + remove_local_test_dir(); create_local_test_dir(); /* 9pfs device using the 'synth' fs driver */ From patchwork Sun Sep 27 10:41:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 11802085 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E8CCB6CA for ; Sun, 27 Sep 2020 12:39:20 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 97F5C23718 for ; Sun, 27 Sep 2020 12:39:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=crudebyte.com header.i=@crudebyte.com header.b="pTUXGOOt" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 97F5C23718 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=crudebyte.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:40162 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kMVxX-0001AI-OL for patchwork-qemu-devel@patchwork.kernel.org; Sun, 27 Sep 2020 08:39:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:56282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kMVwk-0000HD-4Z for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:38:30 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:36839) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kMVwg-0000FT-Gh for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:38:28 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=z8Q8TmVLfHNYUvSNhYvsSyw1bjj67qrXdlwp0bqoAd4=; b=pTUXG OOtTxP0DVqE7TdzaGbfKGVqprdIFX6xwDmkVdRqfHpOZlO1zYZzVcFr1Erd/pLjRShaK2DzH1ODbb MI381OtUkSqFfRw6rEgQaWRISuyiwNtL7s3uJaJuSA7JvTyvoLySY/oVUvbY9ApDSCgTmiqWSCpcX 8hwvm4RSc4oYVHygxy1bJJOQZYNIUNsu39ZO9FjGLbd3Iahgumk+5dPQfLSx/21QP0Ak5yagM45je lh+eF0QzEF95SD07oJvaTUirPdzJRAt8MZGCpAqvQDu9bEw4Mf5XvINtdN16szLEeySPNm4pStEhk xgaFAVCB7U3TxErHiEnasG9wwDk5w==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Sun, 27 Sep 2020 12:41:13 +0200 Subject: [PATCH 11/12] tests/9pfs: add virtio_9p_test_path() To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Paolo Bonzini , Emanuele Giuseppe Esposito , Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=b1a9c16b687b8d0fe8f13986a50ba413a13be36e@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/27 07:42:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This new public function virtio_9p_test_path() allows 9pfs 'local' tests to translate a path from guest scope to host scope. For instance by passing an empty string it would return the root path on host of the exported 9pfs tree. Signed-off-by: Christian Schoenebeck --- tests/qtest/libqos/virtio-9p.c | 6 ++++++ tests/qtest/libqos/virtio-9p.h | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/tests/qtest/libqos/virtio-9p.c b/tests/qtest/libqos/virtio-9p.c index b44fc4ad63..599b73a9d7 100644 --- a/tests/qtest/libqos/virtio-9p.c +++ b/tests/qtest/libqos/virtio-9p.c @@ -92,6 +92,12 @@ static void remove_local_test_dir(void) g_free(cmd); } +char *virtio_9p_test_path(const char *path) +{ + g_assert(local_test_path); + return concat_path(local_test_path, path); +} + static void virtio_9p_cleanup(QVirtio9P *interface) { qvirtqueue_cleanup(interface->vdev->bus, interface->vq, alloc); diff --git a/tests/qtest/libqos/virtio-9p.h b/tests/qtest/libqos/virtio-9p.h index 20d1fc6270..052882ef7c 100644 --- a/tests/qtest/libqos/virtio-9p.h +++ b/tests/qtest/libqos/virtio-9p.h @@ -45,4 +45,9 @@ struct QVirtio9PDevice { QVirtio9P v9p; }; +/** + * Returns path on host to the passed guest path. Result must be freed. + */ +char *virtio_9p_test_path(const char *path); + #endif From patchwork Sun Sep 27 10:41:25 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Schoenebeck X-Patchwork-Id: 11802047 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7BA0E618 for ; Sun, 27 Sep 2020 12:08:54 +0000 (UTC) Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E0A5523976 for ; Sun, 27 Sep 2020 12:08:53 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=crudebyte.com header.i=@crudebyte.com header.b="HNVyNnXD" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E0A5523976 Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=crudebyte.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Received: from localhost ([::1]:36872 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kMVU4-0003Us-SP for patchwork-qemu-devel@patchwork.kernel.org; Sun, 27 Sep 2020 08:08:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:51482) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kMVTe-00035Y-FY for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:08:26 -0400 Received: from lizzy.crudebyte.com ([91.194.90.13]:53175) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kMVTc-0005Zb-Lt for qemu-devel@nongnu.org; Sun, 27 Sep 2020 08:08:26 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=crudebyte.com; s=lizzy; h=Cc:To:Subject:Date:From:References:In-Reply-To: Message-Id:Content-Type:Content-Transfer-Encoding:MIME-Version:Content-ID: Content-Description; bh=F3pTxsN/2pAQD7vMAhPM2ora7rGRDB/qg/kX4EypVAo=; b=HNVyN nXD99AjkminRvPRGcDznViSReIoTG8I0FAvZv9VSKMEvmOiiU2N8b/l2QRxvYmrFjd82Dsac74Gx/ Bi7qEI15AHmbuX+Iog1U1SFeykgjVtgBBgS7j3EjuMJz4G04Z6JZCU6PK4CLT72FBWpA/zAeUyhgx bvhviC2GUI8rM6DrONoa+SNjjYjkKZ5RYglbXJCLHuUHG0LmSXS00smC9Pvi44zFvfykYI392eklk IUHZ1EFrpQvNE3Ax8l/jE6ofeBItm0KNgIBMRuXB4KZKp2hWdlaFGwhHErhP2C74ccBnFZAApTsZ6 +FsgerHjT2zB7b/PlPq2XFUIbCBQw==; Message-Id: In-Reply-To: References: From: Christian Schoenebeck Date: Sun, 27 Sep 2020 12:41:25 +0200 Subject: [PATCH 12/12] tests/9pfs: add local Tmkdir test To: qemu-devel@nongnu.org Cc: Thomas Huth , Laurent Vivier , Paolo Bonzini , Emanuele Giuseppe Esposito , Greg Kurz Received-SPF: none client-ip=91.194.90.13; envelope-from=e45214e28a9aacf59bc0d0793bedfb18d7520c1f@lizzy.crudebyte.com; helo=lizzy.crudebyte.com X-detected-operating-system: by eggs.gnu.org: First seen = 2020/09/27 07:42:27 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] [fuzzy] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_NONE=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: , Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" This test case uses the 9pfs 'local' driver to create a directory and then checks if the expected directory was actually created on host side. Signed-off-by: Christian Schoenebeck --- tests/qtest/virtio-9p-test.c | 140 +++++++++++++++++++++++++++++++++++ 1 file changed, 140 insertions(+) diff --git a/tests/qtest/virtio-9p-test.c b/tests/qtest/virtio-9p-test.c index 88451f255f..c45c706d4f 100644 --- a/tests/qtest/virtio-9p-test.c +++ b/tests/qtest/virtio-9p-test.c @@ -18,6 +18,62 @@ #define QVIRTIO_9P_TIMEOUT_US (10 * 1000 * 1000) static QGuestAllocator *alloc; +/* + * Used to auto generate new fids. Start with arbitrary high value to avoid + * collision with hard coded fids in basic test code. + */ +static uint32_t fid_generator = 1000; + +static uint32_t genfid(void) +{ + return fid_generator++; +} + +/** + * Splits the @a in string by @a delim into individual (non empty) strings + * and outputs them to @a out. The output array @a out is NULL terminated. + * + * Output array @a out must be freed by calling split_free(). + * + * @returns number of individual elements in output array @a out (without the + * final NULL terminating element) + */ +static int split(const char *in, const char *delim, char ***out) +{ + int n = 0, i = 0; + char *tmp, *p; + + tmp = g_strdup(in); + for (p = strtok(tmp, delim); p != NULL; p = strtok(NULL, delim)) { + if (strlen(p) > 0) { + ++n; + } + } + g_free(tmp); + + *out = g_malloc0(n * sizeof(char *) + 1); /* last element NULL delimiter */ + + tmp = g_strdup(in); + for (p = strtok(tmp, delim); p != NULL; p = strtok(NULL, delim)) { + if (strlen(p) > 0) { + (*out)[i++] = g_strdup(p); + } + } + g_free(tmp); + + return n; +} + +static void split_free(char ***out) +{ + int i; + for (i = 0; (*out)[i]; ++i) { + g_free((*out)[i]); + } + g_free(*out); + *out = NULL; +} + static void pci_config(void *obj, void *data, QGuestAllocator *t_alloc) { QVirtio9P *v9p = obj; @@ -203,6 +259,7 @@ static const char *rmessage_name(uint8_t id) id == P9_RWALK ? "RWALK" : id == P9_RLOPEN ? "RLOPEN" : id == P9_RWRITE ? "RWRITE" : + id == P9_RMKDIR ? "RMKDIR" : id == P9_RFLUSH ? "RFLUSH" : id == P9_RREADDIR ? "READDIR" : ""; @@ -580,6 +637,39 @@ static bool fs_dirents_contain_name(struct V9fsDirent *e, const char* name) return false; } +/* size[4] Tmkdir tag[2] dfid[4] name[s] mode[4] gid[4] */ +static P9Req *v9fs_tmkdir(QVirtio9P *v9p, uint32_t dfid, const char *name, + uint32_t mode, uint32_t gid, uint16_t tag) +{ + P9Req *req; + + uint32_t body_size = 4 + 4 + 4; + uint16_t string_size = v9fs_string_size(name); + + g_assert_cmpint(body_size, <=, UINT32_MAX - string_size); + body_size += string_size; + + req = v9fs_req_init(v9p, body_size, P9_TMKDIR, tag); + v9fs_uint32_write(req, dfid); + v9fs_string_write(req, name); + v9fs_uint32_write(req, mode); + v9fs_uint32_write(req, gid); + v9fs_req_send(req); + return req; +} + +/* size[4] Rmkdir tag[2] qid[13] */ +static void v9fs_rmkdir(P9Req *req, v9fs_qid *qid) +{ + v9fs_req_recv(req, P9_RMKDIR); + if (qid) { + v9fs_memread(req, qid, 13); + } else { + v9fs_memskip(req, 13); + } + v9fs_req_free(req); +} + /* basic readdir test where reply fits into a single response message */ static void fs_readdir(void *obj, void *data, QGuestAllocator *t_alloc) { @@ -879,6 +969,30 @@ static void fs_flush_ignored(void *obj, void *data, QGuestAllocator *t_alloc) g_free(wnames[0]); } +static void fs_mkdir(void *obj, void *data, QGuestAllocator *t_alloc, + const char *path, const char *cname) +{ + QVirtio9P *v9p = obj; + alloc = t_alloc; + char **wnames; + char *const name = g_strdup(cname); + P9Req *req; + const uint32_t fid = genfid(); + + int nwnames = split(path, "/", &wnames); + + req = v9fs_twalk(v9p, 0, fid, nwnames, wnames, 0); + v9fs_req_wait_for_reply(req, NULL); + v9fs_rwalk(req, NULL, NULL); + + req = v9fs_tmkdir(v9p, fid, name, 0750, 0, 0); + v9fs_req_wait_for_reply(req, NULL); + v9fs_rmkdir(req, NULL); + + g_free(name); + split_free(&wnames); +} + static void fs_readdir_split_128(void *obj, void *data, QGuestAllocator *t_alloc) { @@ -897,6 +1011,31 @@ static void fs_readdir_split_512(void *obj, void *data, fs_readdir_split(obj, data, t_alloc, 512); } + +/* tests using the 9pfs 'local' fs driver */ + +static void fs_create_dir(void *obj, void *data, QGuestAllocator *t_alloc) +{ + QVirtio9P *v9p = obj; + struct stat st; + char *root_path = virtio_9p_test_path(""); + char *new_dir = virtio_9p_test_path("01"); + + g_assert(root_path != NULL); + + fs_attach(v9p, NULL, t_alloc); + fs_mkdir(v9p, data, t_alloc, "/", "01"); + + /* check if created directory really exists now ... */ + g_assert(stat(new_dir, &st) == 0); + /* ... and is actually a directory */ + g_assert((st.st_mode & S_IFMT) == S_IFDIR); + + g_free(new_dir); + g_free(root_path); +} + + static void register_virtio_9p_test(void) { /* selects the 9pfs 'synth' filesystem driver for the respective test */ @@ -926,6 +1065,7 @@ static void register_virtio_9p_test(void) const char *local_driver = "virtio-9p-local"; qos_add_test("config", local_driver, pci_config, NULL); + qos_add_test("fs/create_dir", local_driver, fs_create_dir, NULL); } libqos_init(register_virtio_9p_test);