From nobody Mon May 13 10:21:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1688455089; cv=none; d=zohomail.com; s=zohoarc; b=C8Cew9bmVkp3RndRoMrsaaAp5hoUEh6pKcDLrt9kCuVRIHoqzM7u/u0GyOMX9vtOd/dShFFKV2Te3Rm0906MaBGPXllP67knfCCQwEW9mv5t/UoL9lJ3t8eRVVZ++sb8pgoSXF7ryxeXH5GSU9qmM9bPk7ts0Rp0TfXWDZ0t3j8= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688455089; h=Content-Transfer-Encoding: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=ucULyzajFx/Or06D5biHO/o9m7YQg/WZ+w5FZAhPc9Q=; b=a8gjLJIXAD8z8zo4f0yrjG5ku70Va6iybRUYEYo94XHFHoyBYw5N9B+EtuaqxlMzmdiUdqJDICLU4GQlw1X55pHMMsQsge8rzlSyjcZwk4jrfmOqEKmw9124DZNU1JnZMTx+X2ljQ/Nq+IBHpY9RfSPfuj9iy+NNS6H5b9B1aTo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1688455089701331.61675838611416; Tue, 4 Jul 2023 00:18:09 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qGaHi-0000Qu-31; Tue, 04 Jul 2023 03:17:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGaHZ-0000PD-VQ for qemu-devel@nongnu.org; Tue, 04 Jul 2023 03:17:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGaHY-0006hQ-7H for qemu-devel@nongnu.org; Tue, 04 Jul 2023 03:17:05 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-657-UC0zqqVGNnmo9wyohL9vvg-1; Tue, 04 Jul 2023 03:17:00 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 93AE9104458D for ; Tue, 4 Jul 2023 07:17:00 +0000 (UTC) Received: from thuth.com (unknown [10.39.192.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 562B62014E17; Tue, 4 Jul 2023 07:16:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688455023; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ucULyzajFx/Or06D5biHO/o9m7YQg/WZ+w5FZAhPc9Q=; b=fO7oS01JUgbrX7Rm25c2Jw3EL0nbZ/6PBKWVkPGPSc7yH6RzVtJHIzE8rIh/hnBUIkPB3+ kVkDyiog0wsqnCrt6fo9oBi13WRW2m5maDeBqDQ6k1iHDKm3tzBdtRlCODDlG8VGd/rNyM W+JzUsVtXZw4JAlxAS+EhYk9RJE5M1U= X-MC-Unique: UC0zqqVGNnmo9wyohL9vvg-1 From: Thomas Huth To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Laurent Vivier , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Subject: [PATCH 1/3] tests/qtest/readconfig-test: Allow testing for arbitrary memory sizes Date: Tue, 4 Jul 2023 09:16:53 +0200 Message-Id: <20230704071655.75381-2-thuth@redhat.com> In-Reply-To: <20230704071655.75381-1-thuth@redhat.com> References: <20230704071655.75381-1-thuth@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1688455090117100001 Content-Type: text/plain; charset="utf-8" Make test_x86_memdev_resp() more flexible by allowing arbitrary memory sizes as parameter here. Signed-off-by: Thomas Huth --- tests/qtest/readconfig-test.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/qtest/readconfig-test.c b/tests/qtest/readconfig-test.c index ac7242451b..74526f3af2 100644 --- a/tests/qtest/readconfig-test.c +++ b/tests/qtest/readconfig-test.c @@ -48,7 +48,7 @@ static QTestState *qtest_init_with_config(const char *cfg= data) return qts; } =20 -static void test_x86_memdev_resp(QObject *res) +static void test_x86_memdev_resp(QObject *res, const char *mem_id, int siz= e) { Visitor *v; g_autoptr(MemdevList) memdevs =3D NULL; @@ -63,8 +63,8 @@ static void test_x86_memdev_resp(QObject *res) g_assert(!memdevs->next); =20 memdev =3D memdevs->value; - g_assert_cmpstr(memdev->id, =3D=3D, "ram"); - g_assert_cmpint(memdev->size, =3D=3D, 200 * MiB); + g_assert_cmpstr(memdev->id, =3D=3D, mem_id); + g_assert_cmpint(memdev->size, =3D=3D, size * MiB); =20 visit_free(v); } @@ -80,7 +80,7 @@ static void test_x86_memdev(void) qts =3D qtest_init_with_config(cfgdata); /* Test valid command */ resp =3D qtest_qmp(qts, "{ 'execute': 'query-memdev' }"); - test_x86_memdev_resp(qdict_get(resp, "return")); + test_x86_memdev_resp(qdict_get(resp, "return"), "ram", 200); qobject_unref(resp); =20 qtest_quit(qts); --=20 2.39.3 From nobody Mon May 13 10:21:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1688455111; cv=none; d=zohomail.com; s=zohoarc; b=Y1P3s2sTZ9I5eX8xs7l8rXkLfiCduosXGVtQ2uBk24/l1nAxfDYput5DlXN1lo47VhtUFle4cXHttg7RgUCDFQG074VwVtEMFdvXYKZoxQFie2URJuDmbbBHTOSlZGhrrY5spF7JkYTZHDotFMadoEsHOAHYhxfa4iZ8s27IWIo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688455111; h=Content-Transfer-Encoding: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=RysB1AS1/QaguR1e1QrNkMenhrfrDs5Ggmy1o/mZjPY=; b=h/aH+aEuMEekvdxandRJLNR9/O6CmhiCexENiK5jdJ21/uMczO2GdQ1R4LBaZujGTomoazOFODKlC1wVt1m1Rap+vXtd4gpjtX6w8RRxHQ+5oD0c5S7naNwfi4jhw6gxWuX/QRmb0U4lKP0IxOgs3iKtCX8dlwDrqIDMRojTUp4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1688455111412981.4678741685502; Tue, 4 Jul 2023 00:18:31 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qGaHl-0000S1-AO; Tue, 04 Jul 2023 03:17:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGaHb-0000PJ-7k for qemu-devel@nongnu.org; Tue, 04 Jul 2023 03:17:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.129.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGaHY-0006hR-HV for qemu-devel@nongnu.org; Tue, 04 Jul 2023 03:17:06 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-343-LsgbqaJ4O2ibza8mRMPtCA-1; Tue, 04 Jul 2023 03:17:02 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id E26AB858EED for ; Tue, 4 Jul 2023 07:17:01 +0000 (UTC) Received: from thuth.com (unknown [10.39.192.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id F37F52023439; Tue, 4 Jul 2023 07:17:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688455023; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=RysB1AS1/QaguR1e1QrNkMenhrfrDs5Ggmy1o/mZjPY=; b=drN9WpHqjzWngnUBc5Glz5p48mEAI3l9zyHocR9tbw/X9MZxKngaK0m3VtoabZaz8hnXUp S6jcPlFqyMD6Z94Q3BscF9Y9ZWZM+90OZHaDMsdvl31cYsWICZ0jDR1wtgBaLKoqdUxnnX L3c6HTz89/3sh0vi0/rmxoGxMgyhjW4= X-MC-Unique: LsgbqaJ4O2ibza8mRMPtCA-1 From: Thomas Huth To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Laurent Vivier , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Subject: [PATCH 2/3] tests/qtest: Move mkimg() and have_qemu_img() from libqos to libqtest Date: Tue, 4 Jul 2023 09:16:54 +0200 Message-Id: <20230704071655.75381-3-thuth@redhat.com> In-Reply-To: <20230704071655.75381-1-thuth@redhat.com> References: <20230704071655.75381-1-thuth@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.129.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1688455113307100001 Content-Type: text/plain; charset="utf-8" These two functions can be useful for other qtests beside the qos-test, too, so move them to libqtest instead. Signed-off-by: Thomas Huth --- tests/qtest/libqos/libqos.h | 2 -- tests/qtest/libqtest.h | 20 ++++++++++++++ tests/qtest/libqos/libqos.c | 49 +--------------------------------- tests/qtest/libqtest.c | 52 +++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 50 deletions(-) diff --git a/tests/qtest/libqos/libqos.h b/tests/qtest/libqos/libqos.h index 12d05b2365..c04950e2b1 100644 --- a/tests/qtest/libqos/libqos.h +++ b/tests/qtest/libqos/libqos.h @@ -27,8 +27,6 @@ QOSState *qtest_boot(QOSOps *ops, const char *cmdline_fmt= , ...) G_GNUC_PRINTF(2, 3); void qtest_common_shutdown(QOSState *qs); void qtest_shutdown(QOSState *qs); -bool have_qemu_img(void); -void mkimg(const char *file, const char *fmt, unsigned size_mb); void mkqcow2(const char *file, unsigned size_mb); void migrate(QOSState *from, QOSState *to, const char *uri); void prepare_blkdebug_script(const char *debug_fn, const char *event); diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h index 913acc3d5c..3a71bc45fc 100644 --- a/tests/qtest/libqtest.h +++ b/tests/qtest/libqtest.h @@ -994,4 +994,24 @@ bool qtest_qom_get_bool(QTestState *s, const char *pat= h, const char *property); */ pid_t qtest_pid(QTestState *s); =20 +/** + * have_qemu_img: + * + * Returns: true if "qemu-img" is available. + */ +bool have_qemu_img(void); + +/** + * mkimg: + * @file: File name of the image that should be created + * @fmt: Format, e.g. "qcow2" or "raw" + * @size_mb: Size of the image in megabytes + * + * Create a disk image with qemu-img. Note that the QTEST_QEMU_IMG + * environment variable must point to the qemu-img file. + * + * Returns: true if the image has been created successfully. + */ +bool mkimg(const char *file, const char *fmt, unsigned size_mb); + #endif diff --git a/tests/qtest/libqos/libqos.c b/tests/qtest/libqos/libqos.c index 5ffda080ec..5c0fa1f7c5 100644 --- a/tests/qtest/libqos/libqos.c +++ b/tests/qtest/libqos/libqos.c @@ -137,56 +137,9 @@ void migrate(QOSState *from, QOSState *to, const char = *uri) migrate_allocator(&from->alloc, &to->alloc); } =20 -bool have_qemu_img(void) -{ - char *rpath; - const char *path =3D getenv("QTEST_QEMU_IMG"); - if (!path) { - return false; - } - - rpath =3D realpath(path, NULL); - if (!rpath) { - return false; - } else { - free(rpath); - return true; - } -} - -void mkimg(const char *file, const char *fmt, unsigned size_mb) -{ - gchar *cli; - bool ret; - int rc; - GError *err =3D NULL; - char *qemu_img_path; - gchar *out, *out2; - char *qemu_img_abs_path; - - qemu_img_path =3D getenv("QTEST_QEMU_IMG"); - g_assert(qemu_img_path); - qemu_img_abs_path =3D realpath(qemu_img_path, NULL); - g_assert(qemu_img_abs_path); - - cli =3D g_strdup_printf("%s create -f %s %s %uM", qemu_img_abs_path, - fmt, file, size_mb); - ret =3D g_spawn_command_line_sync(cli, &out, &out2, &rc, &err); - if (err || !g_spawn_check_exit_status(rc, &err)) { - fprintf(stderr, "%s\n", err->message); - g_error_free(err); - } - g_assert(ret && !err); - - g_free(out); - g_free(out2); - g_free(cli); - free(qemu_img_abs_path); -} - void mkqcow2(const char *file, unsigned size_mb) { - return mkimg(file, "qcow2", size_mb); + g_assert_true(mkimg(file, "qcow2", size_mb)); } =20 void prepare_blkdebug_script(const char *debug_fn, const char *event) diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index 79152f0ec3..c22dfc30d3 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -1742,3 +1742,55 @@ bool qtest_qom_get_bool(QTestState *s, const char *p= ath, const char *property) =20 return b; } + +bool have_qemu_img(void) +{ + char *rpath; + const char *path =3D getenv("QTEST_QEMU_IMG"); + if (!path) { + return false; + } + + rpath =3D realpath(path, NULL); + if (!rpath) { + return false; + } else { + free(rpath); + return true; + } +} + +bool mkimg(const char *file, const char *fmt, unsigned size_mb) +{ + gchar *cli; + bool ret; + int rc; + GError *err =3D NULL; + char *qemu_img_path; + gchar *out, *out2; + char *qemu_img_abs_path; + + qemu_img_path =3D getenv("QTEST_QEMU_IMG"); + if (!qemu_img_path) { + return false; + } + qemu_img_abs_path =3D realpath(qemu_img_path, NULL); + if (!qemu_img_abs_path) { + return false; + } + + cli =3D g_strdup_printf("%s create -f %s %s %uM", qemu_img_abs_path, + fmt, file, size_mb); + ret =3D g_spawn_command_line_sync(cli, &out, &out2, &rc, &err); + if (err || !g_spawn_check_exit_status(rc, &err)) { + fprintf(stderr, "%s\n", err->message); + g_error_free(err); + } + + g_free(out); + g_free(out2); + g_free(cli); + free(qemu_img_abs_path); + + return ret && !err; +} --=20 2.39.3 From nobody Mon May 13 10:21:37 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1688455090; cv=none; d=zohomail.com; s=zohoarc; b=Yum99s53w55SMyPiaSUhDsewWQTBxAfIXBEkjDfxvr2YW3bZfr3FKWZ7i9osopjyxcRw3B3TAaENtpk6ps4O9bWRSoDDmXWEj0Nwkemto5dcHRbr3pyDM97mInImguNcNWsKSRl4bDZXfH9sMSYp34N1MPG9I04edzn4SDlrtZs= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1688455090; h=Content-Transfer-Encoding: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=Oysj6trjbqoas0ThT8XqdbBjkAsC2RjOZlgy4EWOkus=; b=UL3sq7u8WvStcC4BF/ggogdHvrmWcvjkH8gyHP8Z9W66QvHtAbo/8ze6kpWwpa5vAuBlYV0MopWcl7FyK/+UysR+mJWwOh263OMHJ+UDG0YSJ0TNj0NPRuWsILHJjFU8GRNRuZTcvKpEmnG5Rmn2Vbq/q4/VOj3OjUDbcf9MTCA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 16884550900341.400102707836254; Tue, 4 Jul 2023 00:18:10 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qGaHk-0000Rs-IT; Tue, 04 Jul 2023 03:17:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGaHb-0000PK-HA for qemu-devel@nongnu.org; Tue, 04 Jul 2023 03:17:09 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qGaHZ-0006hY-Jc for qemu-devel@nongnu.org; Tue, 04 Jul 2023 03:17:07 -0400 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-606-Ni-alB_GPsKtxoQLYstnPw-1; Tue, 04 Jul 2023 03:17:03 -0400 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 5AA01830EFC for ; Tue, 4 Jul 2023 07:17:03 +0000 (UTC) Received: from thuth.com (unknown [10.39.192.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 43AAA2014E17; Tue, 4 Jul 2023 07:17:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1688455024; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Oysj6trjbqoas0ThT8XqdbBjkAsC2RjOZlgy4EWOkus=; b=jPfRSi8Jfv0Qn6sxQSj1tZ3Odj3xZp53iaBCBBirZL4iFH7TPQKj84uv7R53qhhklXR958 AcHUwlAi1q93vgJ9i1ZIhvnGgjbOHcWKCQXGge3IpX0Mff7HR4S/tBEAWr/c3acH6L/GnT ygjbIkZokb+tWVTFJ5wdfMbA+zLElmc= X-MC-Unique: Ni-alB_GPsKtxoQLYstnPw-1 From: Thomas Huth To: qemu-devel@nongnu.org Cc: Paolo Bonzini , Laurent Vivier , =?UTF-8?q?Daniel=20P=20=2E=20Berrang=C3=A9?= Subject: [PATCH 3/3] tests/qtest/readconfig: Test the docs/config/q35-*.cfg files Date: Tue, 4 Jul 2023 09:16:55 +0200 Message-Id: <20230704071655.75381-4-thuth@redhat.com> In-Reply-To: <20230704071655.75381-1-thuth@redhat.com> References: <20230704071655.75381-1-thuth@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=170.10.133.124; envelope-from=thuth@redhat.com; helo=us-smtp-delivery-124.mimecast.com 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, DKIMWL_WL_HIGH=-0.001, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_MSPIKE_H4=0.001, RCVD_IN_MSPIKE_WL=0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1688455091263100005 Content-Type: text/plain; charset="utf-8" Test that we can successfully parse the docs/config/q35-emulated.cfg, docs/config/q35-virtio-graphical.cfg and docs/config/q35-virtio-serial.cfg config files (the "...-serial.cfg" file is a subset of the graphical config file, so we skip that in quick mode). These config files use two hard-coded image names which we have to replace with unique temporary files to avoid race conditions in case the tests are run in parallel. So after creating the temporary image files, we also have to create a copy of the config file where we replaced the hard-coded image names. If KVM is not available, we also have to disable the "accel" lines. Once everything is in place, we can start QEMU with the modified config file and check that everything is available in QEMU. Signed-off-by: Thomas Huth --- tests/qtest/readconfig-test.c | 196 ++++++++++++++++++++++++++++++++++ 1 file changed, 196 insertions(+) diff --git a/tests/qtest/readconfig-test.c b/tests/qtest/readconfig-test.c index 74526f3af2..760f974e63 100644 --- a/tests/qtest/readconfig-test.c +++ b/tests/qtest/readconfig-test.c @@ -197,6 +197,189 @@ static void test_docs_config_ich9(void) qtest_quit(qts); } =20 +#if defined(CONFIG_POSIX) && defined(CONFIG_SLIRP) + +static char *make_temp_img(const char *template, const char *format, int s= ize) +{ + GError *error =3D NULL; + char *temp_name; + int fd; + + /* Create a temporary image names */ + fd =3D g_file_open_tmp(template, &temp_name, &error); + if (fd =3D=3D -1) { + fprintf(stderr, "unable to create file: %s\n", error->message); + g_error_free(error); + return NULL; + } + close(fd); + + if (!mkimg(temp_name, format, size)) { + fprintf(stderr, "qemu-img failed to create %s\n", temp_name); + g_free(temp_name); + return NULL; + } + + return temp_name; +} + +struct device { + const char *name; + const char *type; +}; + +static void test_docs_q35(const char *input_file, struct device *devices) +{ + QTestState *qts; + QDict *resp; + QObject *qobj; + int ret, i; + g_autofree char *cfg_file =3D NULL, *sedcmd =3D NULL; + g_autofree char *hd_file =3D NULL, *cd_file =3D NULL; + + /* Check that all the devices are available in the QEMU binary */ + for (i =3D 0; devices[i].name; i++) { + if (!qtest_has_device(devices[i].type)) { + g_test_skip("one of the required devices is not available"); + return; + } + } + + hd_file =3D make_temp_img("qtest_disk_XXXXXX.qcow2", "qcow2", 1); + cd_file =3D make_temp_img("qtest_cdrom_XXXXXX.iso", "raw", 1); + if (!hd_file || !cd_file) { + g_test_skip("could not create disk images"); + goto cleanup; + } + + /* Create a temporary config file where we replace the disk image name= s */ + ret =3D g_file_open_tmp("q35-emulated-XXXXXX.cfg", &cfg_file, NULL); + if (ret =3D=3D -1) { + g_test_skip("could not create temporary config file"); + goto cleanup; + } + close(ret); + + sedcmd =3D g_strdup_printf("sed -e 's,guest.qcow2,%s,' -e 's,install.i= so,%s,'" + " %s %s > '%s'", + hd_file, cd_file, + !qtest_has_accel("kvm") ? "-e '/accel/d'" : "= ", + input_file, cfg_file); + ret =3D system(sedcmd); + if (ret) { + g_test_skip("could not modify temporary config file"); + goto cleanup; + } + + qts =3D qtest_initf("-machine none -nodefaults -readconfig %s", cfg_fi= le); + + /* Check memory size */ + resp =3D qtest_qmp(qts, "{ 'execute': 'query-memdev' }"); + test_x86_memdev_resp(qdict_get(resp, "return"), "pc.ram", 1024); + qobject_unref(resp); + + resp =3D qtest_qmp(qts, "{ 'execute': 'qom-list'," + " 'arguments': {'path': '/machine/peripheral' }= }"); + qobj =3D qdict_get(resp, "return"); + + /* Check that all the devices have been created */ + for (i =3D 0; devices[i].name; i++) { + test_object_available(qobj, devices[i].name, devices[i].type); + } + + qobject_unref(resp); + + qtest_quit(qts); + +cleanup: + if (hd_file) { + unlink(hd_file); + } + if (cd_file) { + unlink(cd_file); + } + if (cfg_file) { + unlink(cfg_file); + } +} + +static void test_docs_q35_emulated(void) +{ + struct device devices[] =3D { + { "ich9-pcie-port-1", "ioh3420" }, + { "ich9-pcie-port-2", "ioh3420" }, + { "ich9-pcie-port-3", "ioh3420" }, + { "ich9-pcie-port-4", "ioh3420" }, + { "ich9-pci-bridge", "i82801b11-bridge" }, + { "ich9-ehci-1", "ich9-usb-ehci1" }, + { "ich9-ehci-2", "ich9-usb-ehci2" }, + { "ich9-uhci-1", "ich9-usb-uhci1" }, + { "ich9-uhci-2", "ich9-usb-uhci2" }, + { "ich9-uhci-3", "ich9-usb-uhci3" }, + { "ich9-uhci-4", "ich9-usb-uhci4" }, + { "ich9-uhci-5", "ich9-usb-uhci5" }, + { "ich9-uhci-6", "ich9-usb-uhci6" }, + { "sata-disk", "ide-hd" }, + { "sata-optical-disk", "ide-cd" }, + { "net", "e1000" }, + { "video", "VGA" }, + { "ich9-hda-audio", "ich9-intel-hda" }, + { "ich9-hda-duplex", "hda-duplex" }, + { NULL, NULL } + }; + + test_docs_q35("docs/config/q35-emulated.cfg", devices); +} + +static void test_docs_q35_virtio_graphical(void) +{ + struct device devices[] =3D { + { "pcie.1", "pcie-root-port" }, + { "pcie.2", "pcie-root-port" }, + { "pcie.3", "pcie-root-port" }, + { "pcie.4", "pcie-root-port" }, + { "pcie.5", "pcie-root-port" }, + { "pcie.6", "pcie-root-port" }, + { "pcie.7", "pcie-root-port" }, + { "pcie.8", "pcie-root-port" }, + { "scsi", "virtio-scsi-pci" }, + { "scsi-disk", "scsi-hd" }, + { "scsi-optical-disk", "scsi-cd" }, + { "net", "virtio-net-pci" }, + { "usb", "nec-usb-xhci" }, + { "tablet", "usb-tablet" }, + { "video", "qxl-vga" }, + { "sound", "ich9-intel-hda" }, + { "duplex", "hda-duplex" }, + { NULL, NULL } + }; + + test_docs_q35("docs/config/q35-virtio-graphical.cfg", devices); +} + +static void test_docs_q35_virtio_serial(void) +{ + struct device devices[] =3D { + { "pcie.1", "pcie-root-port" }, + { "pcie.2", "pcie-root-port" }, + { "pcie.3", "pcie-root-port" }, + { "pcie.4", "pcie-root-port" }, + { "pcie.5", "pcie-root-port" }, + { "pcie.6", "pcie-root-port" }, + { "pcie.7", "pcie-root-port" }, + { "pcie.8", "pcie-root-port" }, + { "scsi", "virtio-scsi-pci" }, + { "scsi-disk", "scsi-hd" }, + { "scsi-optical-disk", "scsi-cd" }, + { "net", "virtio-net-pci" }, + { NULL, NULL } + }; + + test_docs_q35("docs/config/q35-virtio-serial.cfg", devices); +} + +#endif /* CONFIG_LINUX */ + int main(int argc, char *argv[]) { const char *arch; @@ -211,6 +394,19 @@ int main(int argc, char *argv[]) qtest_has_device("ich9-usb-uhci1")) { qtest_add_func("readconfig/x86/ich9-ehci-uhci", test_docs_conf= ig_ich9); } +#if defined(CONFIG_POSIX) && defined(CONFIG_SLIRP) + qtest_add_func("readconfig/x86/q35-emulated", test_docs_q35_emulat= ed); + qtest_add_func("readconfig/x86/q35-virtio-graphical", + test_docs_q35_virtio_graphical); + if (g_test_slow()) { + /* + * q35-virtio-serial.cfg is a subset of q35-virtio-graphical.c= fg, + * so we can skip the test in quick mode + */ + qtest_add_func("readconfig/x86/q35-virtio-serial", + test_docs_q35_virtio_serial); + } +#endif } #if defined(CONFIG_SPICE) && !defined(__FreeBSD__) qtest_add_func("readconfig/spice", test_spice); --=20 2.39.3