From nobody Sun May 19 05:50:53 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=1673942940; cv=none; d=zohomail.com; s=zohoarc; b=JXPaCKerZPEQFOE3p8itdHwy1KEnstBypc2Nm/zX0sY2w7eZ7FhupIv8r1iQx05a+pOCEL0ErS3qYhMmE4pdTFTZVEnHt7axgoCQx4fWqS44DfqoIg0HYWKgUYCI4gyE7UONjivM+yHVzl8KWuP67v5oA9QeZVnXf2fNUyAQaJI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673942940; h=Content-Type: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=s2CxFTHityeNV5UFpIKrh+T9Z/RsPZNuWUHcYXPHaQg=; b=S30HdGE9o4JiwJ/qN9J78rlnef+RS+l8U5QTOryMWsNsbPD+X+qJWD1oIiGMHojh8ySFUVZxsupNJZd4jfu4S2yuZoVshKM9CHNa4WvZp+wObNP5/GHjGl1zZUpopWaqTraq7tLGotJUSMoVGTZ3pS2ipfEfA1y5gGYDiX7RWag= 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 1673942940607583.6654056308314; Tue, 17 Jan 2023 00:09:00 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHh1H-0002tw-S0; Tue, 17 Jan 2023 03:08:35 -0500 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 1pHh0g-0002nx-SQ for qemu-devel@nongnu.org; Tue, 17 Jan 2023 03:07:58 -0500 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 1pHh0c-0000Rg-5u for qemu-devel@nongnu.org; Tue, 17 Jan 2023 03:07:58 -0500 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-267-QRgN9NKwMKCPDz_lja8Gwg-1; Tue, 17 Jan 2023 03:07:52 -0500 Received: by mail-ed1-f70.google.com with SMTP id m7-20020a056402510700b00488d1fcdaebso20458786edd.9 for ; Tue, 17 Jan 2023 00:07:51 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id x25-20020a170906b09900b0080345493023sm12606424ejy.167.2023.01.17.00.07.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 00:07:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673942873; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=s2CxFTHityeNV5UFpIKrh+T9Z/RsPZNuWUHcYXPHaQg=; b=LJHMUwb51Gc4U4Im/zk31kheheRhJMqyVQJ7P0inyByAYBAVT9xCXoQQCXF5hegE/C2k6Q e+2MnRUDyrqem1BsE6VsSY3+YMghLJY4K/7CqGxplnqGJG8FcDJWfqLKgIDnXcJC3G7IMY 4aXbRB5PEWm8fYU08SIcKKZGduiwoEg= X-MC-Unique: QRgN9NKwMKCPDz_lja8Gwg-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=s2CxFTHityeNV5UFpIKrh+T9Z/RsPZNuWUHcYXPHaQg=; b=0cWRgVmN3zPxSsuyS96rcBdvRJOnGQAUO4w4foz4/Z7PtH/bsOvqnSd5Vpqlk+5bsp WQ3ciB4PY70utwAsxfnRLRRLjYTiJtL2dLy6Rf5RQxOyXYmSueAxzHfFXpYylZLF4N9z lZA+1grYnBuv1wgFiyHBtg4pdAr2XYjSCWuCgyGEMqABgAlsWAejyVbvKlcjqtfXf0QB birZ1HFgdPrjuzJR62zP/UVcYDk+yOGYb2dOcyWkBbNCgF5mmqhQXMdaKmCuGixAkVy+ PS8NNMQyKoyn2FyjpHHfHWXMaN/lOm2a8SbVkQ1GXZvLuaL5o+CkFMk4AJDgMTwCpKxd ntmg== X-Gm-Message-State: AFqh2kohMiHbaHb0IIATxcQkmb2X8gPVKhhI+6icSlGSsdZH1hNh8Z/B 3cpCUV3Ky98kkje7Cn3OP2Ag37RMS85Ay9+vF9X9ywVgxJllw5vUjCiINL3ofFCWofG22IY/tKf j0W4zDlSE6hBdtvURAV31DWPbA0sE198sH4aIstiDLx8FJvuDndmwljxfnbg7cI371Gw= X-Received: by 2002:a17:907:1747:b0:86e:7300:1fa8 with SMTP id lf7-20020a170907174700b0086e73001fa8mr2056968ejc.35.1673942870426; Tue, 17 Jan 2023 00:07:50 -0800 (PST) X-Google-Smtp-Source: AMrXdXsYmlYMPt5PiigqaBkFJIRJY8WwSSKmYNoSq8q7fMmJJT4spbbMoZ9SvFr9t08eQVWHTpZQPw== X-Received: by 2002:a17:907:1747:b0:86e:7300:1fa8 with SMTP id lf7-20020a170907174700b0086e73001fa8mr2056953ejc.35.1673942870224; Tue, 17 Jan 2023 00:07:50 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: thuth@redhat.com Subject: [PATCH 1/4] vl: catch [accel] entry without accelerator Date: Tue, 17 Jan 2023 09:07:42 +0100 Message-Id: <20230117080745.43247-2-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230117080745.43247-1-pbonzini@redhat.com> References: <20230117080745.43247-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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: 1673942942282100001 Content-Type: text/plain; charset="utf-8" While QEMU catches invalid -accel command line options: $ qemu-system-x86_64 -accel foo=3Dbar Accelerators supported in QEMU binary: tcg xen kvm the same is not true of configuration files, which instead crash. Avoid a SIGSEGV and return an error instead. Reported-by: Thomas Huth Resolves: https://gitlab.com/qemu-project/qemu/-/issues/1439 Signed-off-by: Paolo Bonzini --- softmmu/vl.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/softmmu/vl.c b/softmmu/vl.c index 9bd0e52d016a..b6deaee52da4 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2204,14 +2204,18 @@ static int do_configure_accelerator(void *opaque, Q= emuOpts *opts, Error **errp) int ret; bool qtest_with_kvm; =20 + if (!acc) { + error_setg(&error_fatal, QERR_MISSING_PARAMETER, "accel"); + goto bad; + } + qtest_with_kvm =3D g_str_equal(acc, "kvm") && qtest_chrdev !=3D NULL; =20 if (!ac) { - *p_init_failed =3D true; if (!qtest_with_kvm) { error_report("invalid accelerator %s", acc); } - return 0; + goto bad; } accel =3D ACCEL(object_new_with_class(OBJECT_CLASS(ac))); object_apply_compat_props(OBJECT(accel)); @@ -2221,14 +2225,17 @@ static int do_configure_accelerator(void *opaque, Q= emuOpts *opts, Error **errp) =20 ret =3D accel_init_machine(accel, current_machine); if (ret < 0) { - *p_init_failed =3D true; if (!qtest_with_kvm || ret !=3D -ENOENT) { error_report("failed to initialize %s: %s", acc, strerror(-ret= )); } - return 0; + goto bad; } =20 return 1; + +bad: + *p_init_failed =3D true; + return 0; } =20 static void configure_accelerators(const char *progname) --=20 2.38.1 From nobody Sun May 19 05:50:53 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=1673942921; cv=none; d=zohomail.com; s=zohoarc; b=kBvg7de8Glj8xlQR4yVmfPLPpWTmSoNgjSyv6Qf6eFAsNRubXfBmNALvfUlzFSUgCequXP41ut55ZpRBZwXbJD/jvejofNOjReG1Rmi+OcN3gBOccNtOwtktnXQPeMm0Tsek0e8K+I4KcIzCTBlD8Q/Zr49MU4uwX+lic6C3Sjo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673942921; h=Content-Type: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=4Nf/qoa+K7HjuYdhLWL8wXyrH53Imqw+8MLAETNKXus=; b=QjXeSF4hNDN2+Swe7q/JmenZwokvkHblS7sJxM6BVOer+ePFDeR+DjXYd9/aQWlU3pxrSzPCsaNhb5La4lK8/Mk8uptT9D56IQVLISdhKFruIpF9wDNNg6fiQMbe3KIwBfEqlSP8hrB9p6pDAlJQVZ3izzos4/z08PCK+QHRriY= 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 1673942921687394.2691824311231; Tue, 17 Jan 2023 00:08:41 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHh17-0002pS-Sv; Tue, 17 Jan 2023 03:08:28 -0500 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 1pHh0g-0002nw-Ir for qemu-devel@nongnu.org; Tue, 17 Jan 2023 03:07:58 -0500 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 1pHh0e-0000Rt-Dq for qemu-devel@nongnu.org; Tue, 17 Jan 2023 03:07:58 -0500 Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-489-UylCSCe7NxSnwAOpNjEp8g-1; Tue, 17 Jan 2023 03:07:54 -0500 Received: by mail-ed1-f72.google.com with SMTP id w18-20020a05640234d200b0048cc3aa4993so20557824edc.7 for ; Tue, 17 Jan 2023 00:07:54 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id p5-20020a17090653c500b007ae32daf4b9sm12834223ejo.106.2023.01.17.00.07.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 00:07:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673942875; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=4Nf/qoa+K7HjuYdhLWL8wXyrH53Imqw+8MLAETNKXus=; b=IVxZAatXCiy9b19fH5pwgfVyLHpJQeY4vjuggmZsXGlBoJdhshS4K61Dru/GBHLNCp27Yq gXv1uI5TJgRuqJSBhdnMZ0eNEHuf7ytncwvu0Bxcxj4hwi9d6BDPZ7zTw2dRBAbf4sV64d oT7MCLuZW0RuruVvD8sl5FdIgArnnI4= X-MC-Unique: UylCSCe7NxSnwAOpNjEp8g-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=4Nf/qoa+K7HjuYdhLWL8wXyrH53Imqw+8MLAETNKXus=; b=5Kfja4N44xe2scRuDEH24VA4bjP+Hrly2BHV5f0aP6Dmwu2iiOpK2U9nfaMXeRYWW7 S3vsfS9sWDhKhLj7QlK7QHwcTk/uSxJZMx1dYJDnqcN3+ZrCdxH9XYoz+TIHySNjHWEz jtL9pELNihjV7BhjJ7FlDqgfGy1ApThbwB2CORdJ2wDj1ynTn7DMh6Wljd0gNCOQMyU+ XpZ50HIN0+mrwJf8gF/auFIjlvfA3Qi8Nb0J8gziTlI82Q6InKuhlqbyzbJVA/1UJ5aE Y21OyBEj0p9zFbi4u270uh/Kw1QqpYCh4u05jQXaP6ti3csQ+0IDeI79OFuvDe+l3mFY +9dQ== X-Gm-Message-State: AFqh2ko2DIypg0Rxa7J02qCzPAFCc+hoy0aTRZpHTbNL23ZAE2QvIFk6 unYbgbMQVn7HzeBgKmOZJ3ptuR19UaZUZ4pB4RK7CBGucMAJhr6WgEesxJTpaPe/Jes2EMEx08B pWC+pT6AWBMorGyUZwubT2GnoJtatqBj6OqMESF+CvG+aooembK5BK7yFVnjHNR26bUU= X-Received: by 2002:a17:906:57da:b0:872:5222:9024 with SMTP id u26-20020a17090657da00b0087252229024mr1758248ejr.67.1673942873073; Tue, 17 Jan 2023 00:07:53 -0800 (PST) X-Google-Smtp-Source: AMrXdXsiViovqGnWGXtQdPJq3BZ5P3rhpuU0XXf53cjHSRMh0qG+Vt/PiBMxV+NAnYx4QgyqX1Vv7w== X-Received: by 2002:a17:906:57da:b0:872:5222:9024 with SMTP id u26-20020a17090657da00b0087252229024mr1758229ejr.67.1673942872734; Tue, 17 Jan 2023 00:07:52 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: thuth@redhat.com Subject: [PATCH 2/4] libqtest: split qtest_spawn_qemu function Date: Tue, 17 Jan 2023 09:07:43 +0100 Message-Id: <20230117080745.43247-3-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230117080745.43247-1-pbonzini@redhat.com> References: <20230117080745.43247-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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: 1673942922668100001 Content-Type: text/plain; charset="utf-8" In order to create a function that allows testing of invalid command lines, extract the parts of qtest_init_without_qmp_handshake that do not require any successful set up of sockets. Signed-off-by: Paolo Bonzini Reviewed-by: Philippe Mathieu-Daud=C3=A9 --- tests/qtest/libqtest.c | 103 ++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 48 deletions(-) diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index 5cb38f90da19..4d9cf919b2f7 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -342,60 +342,25 @@ static pid_t qtest_create_process(char *cmd) } #endif /* _WIN32 */ =20 -QTestState *qtest_init_without_qmp_handshake(const char *extra_args) +static QTestState *G_GNUC_PRINTF(1, 0) qtest_spawn_qemu(const char *fmt, .= ..) { - QTestState *s; - int sock, qmpsock, i; - gchar *socket_path; - gchar *qmp_socket_path; - gchar *command; - const char *qemu_binary =3D qtest_qemu_binary(); + va_list ap; + QTestState *s =3D g_new0(QTestState, 1); const char *trace =3D g_getenv("QTEST_TRACE"); g_autofree char *tracearg =3D trace ? g_strdup_printf("-trace %s ", trace) : g_strdup(""); + g_autoptr(GString) command =3D g_string_new(""); =20 - s =3D g_new(QTestState, 1); - - socket_path =3D g_strdup_printf("%s/qtest-%d.sock", - g_get_tmp_dir(), getpid()); - qmp_socket_path =3D g_strdup_printf("%s/qtest-%d.qmp", - g_get_tmp_dir(), getpid()); - - /* It's possible that if an earlier test run crashed it might - * have left a stale unix socket lying around. Delete any - * stale old socket to avoid spurious test failures with - * tests/libqtest.c:70:init_socket: assertion failed (ret !=3D -1): (-= 1 !=3D -1) - */ - unlink(socket_path); - unlink(qmp_socket_path); - - socket_init(); - sock =3D init_socket(socket_path); - qmpsock =3D init_socket(qmp_socket_path); - - qtest_client_set_rx_handler(s, qtest_client_socket_recv_line); - qtest_client_set_tx_handler(s, qtest_client_socket_send); + va_start(ap, fmt); + g_string_append_printf(command, CMD_EXEC "%s %s", + qtest_qemu_binary(), tracearg); + g_string_append_vprintf(command, fmt, ap); + va_end(ap); =20 qtest_add_abrt_handler(kill_qemu_hook_func, s); =20 - command =3D g_strdup_printf(CMD_EXEC "%s %s" - "-qtest unix:%s " - "-qtest-log %s " - "-chardev socket,path=3D%s,id=3Dchar0 " - "-mon chardev=3Dchar0,mode=3Dcontrol " - "-display none " - "%s" - " -accel qtest", - qemu_binary, tracearg, socket_path, - getenv("QTEST_LOG") ? DEV_STDERR : DEV_NULL, - qmp_socket_path, - extra_args ?: ""); + g_test_message("starting QEMU: %s", command->str); =20 - g_test_message("starting QEMU: %s", command); - - s->pending_events =3D NULL; - s->wstatus =3D 0; - s->expected_status =3D 0; #ifndef _WIN32 s->qemu_pid =3D fork(); if (s->qemu_pid =3D=3D 0) { @@ -416,14 +381,56 @@ QTestState *qtest_init_without_qmp_handshake(const ch= ar *extra_args) if (!g_setenv("QEMU_AUDIO_DRV", "none", true)) { exit(1); } - execlp("/bin/sh", "sh", "-c", command, NULL); + execlp("/bin/sh", "sh", "-c", command->str, NULL); exit(1); } #else - s->qemu_pid =3D qtest_create_process(command); + s->qemu_pid =3D qtest_create_process(command->str); #endif /* _WIN32 */ =20 - g_free(command); + return s; +} + +QTestState *qtest_init_without_qmp_handshake(const char *extra_args) +{ + QTestState *s; + int sock, qmpsock, i; + gchar *socket_path; + gchar *qmp_socket_path; + + socket_path =3D g_strdup_printf("%s/qtest-%d.sock", + g_get_tmp_dir(), getpid()); + qmp_socket_path =3D g_strdup_printf("%s/qtest-%d.qmp", + g_get_tmp_dir(), getpid()); + + /* + * It's possible that if an earlier test run crashed it might + * have left a stale unix socket lying around. Delete any + * stale old socket to avoid spurious test failures with + * tests/libqtest.c:70:init_socket: assertion failed (ret !=3D -1): (-= 1 !=3D -1) + */ + unlink(socket_path); + unlink(qmp_socket_path); + + socket_init(); + sock =3D init_socket(socket_path); + qmpsock =3D init_socket(qmp_socket_path); + + s =3D qtest_spawn_qemu("-qtest unix:%s " + "-qtest-log %s " + "-chardev socket,path=3D%s,id=3Dchar0 " + "-mon chardev=3Dchar0,mode=3Dcontrol " + "-display none " + "%s" + " -accel qtest", + socket_path, + getenv("QTEST_LOG") ? DEV_STDERR : DEV_NULL, + qmp_socket_path, + extra_args ?: ""); + + qtest_client_set_rx_handler(s, qtest_client_socket_recv_line); + qtest_client_set_tx_handler(s, qtest_client_socket_send); + s->fd =3D socket_accept(sock); if (s->fd >=3D 0) { s->qmp_fd =3D socket_accept(qmpsock); --=20 2.38.1 From nobody Sun May 19 05:50:53 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=1673942963; cv=none; d=zohomail.com; s=zohoarc; b=YLMaXEdfMhckcywfewCOnO6ckRADF1KBY/U92rjKqJLudKEohQXq9oFzFEcmAX3n6sGijnblXowIlPLswGt/ord575Fcc6Pig9IgeqkmmsNtyXkFUVHoiTgfcTzfwTDykjeg/9VKf0sjIJp3YUST9SDmpvgI8gzDlc3KWeHNvpM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673942963; h=Content-Type: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=3xZlc7eqrE8EfA+fTVdxTZ+8cHR3tlPNZKDZmmLOI0U=; b=VZomDZm85DzH0YhF/EQPcGODLq50mbUNnXP6nvS/j6OXsRycxu8FyRdjPAS+Ctq0rJstrC2Ckn5+mV6axMiLferJPF4N4WEd7fNNlUl47t/EOvVMANzc/MfFFVth6OGA8ErQ8qTm2sYCW/7HVRSp4qQX40Q7tXFdoQtA3TcFeVw= 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 167394296384480.77105393191198; Tue, 17 Jan 2023 00:09:23 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHh1I-0002uV-3J; Tue, 17 Jan 2023 03:08:36 -0500 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 1pHh0j-0002pb-HZ for qemu-devel@nongnu.org; Tue, 17 Jan 2023 03:08:19 -0500 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 1pHh0h-0000SK-VU for qemu-devel@nongnu.org; Tue, 17 Jan 2023 03:08:01 -0500 Received: from mail-ed1-f72.google.com (mail-ed1-f72.google.com [209.85.208.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-626-bOtHT4xlONC5q5uLW0Nkog-1; Tue, 17 Jan 2023 03:07:57 -0500 Received: by mail-ed1-f72.google.com with SMTP id z8-20020a056402274800b0048a31c1746aso20398416edd.0 for ; Tue, 17 Jan 2023 00:07:57 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id b26-20020aa7dc1a000000b00499c3ca6a0dsm8289196edu.10.2023.01.17.00.07.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 00:07:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673942878; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=3xZlc7eqrE8EfA+fTVdxTZ+8cHR3tlPNZKDZmmLOI0U=; b=VCIqY3UFnXFT7dtV+sFXE8rDw7jcdWIpAdwCXtXNw7A22I0tnwGo8JvyQHbhL7vhgOpbnO k0ZqESp6hJBmcRSgp4q4qJj1vxQAXO2kbXTLE8TNFG+RCSUn7wcvEKhiLAz+uB8jv9L5xD F7drPN8gwt+P9cYen1rKy8CYv5sjzrU= X-MC-Unique: bOtHT4xlONC5q5uLW0Nkog-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3xZlc7eqrE8EfA+fTVdxTZ+8cHR3tlPNZKDZmmLOI0U=; b=1ducI6K/6G1z9MFlUDBYsBSK9M5xaSVE1jprl1ro/Qn2Ap1rUYlFZaAgyBvmZ6QzPX rLgVQtbLrK9KQus9nArtEc24Yu00Scyvwz+JLUhY83ncjGh2Yh3rdVDLE+YPv9AuNBvg jZHsqHF3Fk93+26bd9IsdEz9NwtooAZYwCrfXnrOgBDvX3G3tNmOT9PCWLNC7GHrKw7q 4wWkrOkFd9vOI3rscMMYN5U7BRtoGK1TwxxfO3vtFlAOLk7iXDalDuyfYJYO5SOGFEd5 XWH2TPcbMBUz5Nz6OonjKjRPjNsa3ElDqhKPszFmVU47KO4cj4/WVpzsfwYDa26jp96x sXaw== X-Gm-Message-State: AFqh2kq+FvXkoGJqnFwx0PCIUkzrY2DqltyNvUiEyiDWtjB8XkF9Tega oPN+b/4d7Ao9bdeSV/nJpdX6iWQoLZ87S9Y1Bg/APAg7SfHqoZLF1wsPRJP7DbyQgwlo/+2JzS6 dxqbxuLacgaM9miBZNx70HPvTZJCiKOMFF4zBOGxo6gV1MpyH74Vw3h+zQqjlTS51zqM= X-Received: by 2002:a05:6402:28ca:b0:499:c294:77af with SMTP id ef10-20020a05640228ca00b00499c29477afmr2061901edb.12.1673942876084; Tue, 17 Jan 2023 00:07:56 -0800 (PST) X-Google-Smtp-Source: AMrXdXuHDT3STKyPLlcpE6iNKOTf5dLg/9aPbdt4FFgwuJh8U4CjABN4ueo5QGWsuX6akQ+2IyZffg== X-Received: by 2002:a05:6402:28ca:b0:499:c294:77af with SMTP id ef10-20020a05640228ca00b00499c29477afmr2061886edb.12.1673942875734; Tue, 17 Jan 2023 00:07:55 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: thuth@redhat.com Subject: [PATCH 3/4] libqtest: ensure waitpid() is only called once Date: Tue, 17 Jan 2023 09:07:44 +0100 Message-Id: <20230117080745.43247-4-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230117080745.43247-1-pbonzini@redhat.com> References: <20230117080745.43247-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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: 1673942964315100005 Content-Type: text/plain; charset="utf-8" If a test aborts after qtest_wait_qemu() is called, the SIGABRT hooks are still in place and waitpid() is called again. The second time it is called, the process does not exist anymore and the system call fails. Move the s->qemu_pid =3D -1 assignment to qtest_wait_qemu() to make it idempotent, and anyway remove the SIGABRT hook as well to avoid that qtest_check_status() is called twice. Because of the extra call, qtest_remove_abrt_handler() now has to be made idempotent as well. Signed-off-by: Paolo Bonzini Reviewed-by: Thomas Huth --- tests/qtest/libqtest.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index 4d9cf919b2f7..64ba98bc5853 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -156,6 +156,7 @@ bool qtest_probe_child(QTestState *s) CloseHandle((HANDLE)pid); #endif s->qemu_pid =3D -1; + qtest_remove_abrt_handler(s); } return false; } @@ -167,6 +168,8 @@ void qtest_set_expected_status(QTestState *s, int statu= s) =20 static void qtest_check_status(QTestState *s) { + assert (s->qemu_pid =3D=3D -1); + /* * Check whether qemu exited with expected exit status; anything else = is * fishy and should be logged with as much detail as possible. @@ -200,20 +203,24 @@ static void qtest_check_status(QTestState *s) =20 void qtest_wait_qemu(QTestState *s) { + if (s->qemu_pid !=3D -1) { #ifndef _WIN32 - pid_t pid; + pid_t pid; =20 - pid =3D RETRY_ON_EINTR(waitpid(s->qemu_pid, &s->wstatus, 0)); - assert(pid =3D=3D s->qemu_pid); + pid =3D RETRY_ON_EINTR(waitpid(s->qemu_pid, &s->wstatus, 0)); + g_assert_cmpint(pid, =3D=3D, s->qemu_pid); #else - DWORD ret; + DWORD ret; =20 - ret =3D WaitForSingleObject((HANDLE)s->qemu_pid, INFINITE); - assert(ret =3D=3D WAIT_OBJECT_0); - GetExitCodeProcess((HANDLE)s->qemu_pid, &s->exit_code); - CloseHandle((HANDLE)s->qemu_pid); + ret =3D WaitForSingleObject((HANDLE)s->qemu_pid, INFINITE); + assert(ret =3D=3D WAIT_OBJECT_0); + GetExitCodeProcess((HANDLE)s->qemu_pid, &s->exit_code); + CloseHandle((HANDLE)s->qemu_pid); #endif =20 + s->qemu_pid =3D -1; + qtest_remove_abrt_handler(s); + } qtest_check_status(s); } =20 @@ -227,7 +234,6 @@ void qtest_kill_qemu(QTestState *s) TerminateProcess((HANDLE)s->qemu_pid, s->expected_status); #endif qtest_wait_qemu(s); - s->qemu_pid =3D -1; return; } =20 @@ -289,6 +295,11 @@ void qtest_add_abrt_handler(GHookFunc fn, const void *= data) void qtest_remove_abrt_handler(void *data) { GHook *hook =3D g_hook_find_data(&abrt_hooks, TRUE, data); + + if (!hook) { + return; + } + g_hook_destroy_link(&abrt_hooks, hook); =20 /* Uninstall SIGABRT handler on last instance */ --=20 2.38.1 From nobody Sun May 19 05:50:53 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=1673942960; cv=none; d=zohomail.com; s=zohoarc; b=axNPWgwC+MCcFvoL62ZINWpQFd4WRepX5F/uCUv3pZk3JP6Qqhnfn79kTM1f+p8TBGTCcvhHOsdqoUXsa5PWaUdScsRy3hQXnTseHE9cMxbnXkVP82ixAwMcrMfUzJ1MjWux/HK/jhWOcKnYjMiIrzJDv/DU5+g4gLLuIcOMnqE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1673942960; h=Content-Type: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=Qpw/5/aIJktG9Q0OND3WGSL83i6tZBDG69a8KADEOQs=; b=kS2kex+LdChcEP8BLQ2sz6EWzDBoDfPzBCYi0bdNBP8vLMKOHzgiGOlkuoTcLcOwqa5xU7Yr+B2D5mydZsmN/Rmp2kbFvMzYAT8pQuTac6Uxn9Im4JF65FoKEslIgZ0/lwK19ig1Tu3WUGEvVlU1Ettiwx1xMvzw+Le2c0a6wEM= 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 1673942960287639.0337732595045; Tue, 17 Jan 2023 00:09:20 -0800 (PST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pHh1K-0002vq-D5; Tue, 17 Jan 2023 03:08:38 -0500 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 1pHh0s-0002q8-1U for qemu-devel@nongnu.org; Tue, 17 Jan 2023 03:08:25 -0500 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 1pHh0p-0000Sf-Ih for qemu-devel@nongnu.org; Tue, 17 Jan 2023 03:08:09 -0500 Received: from mail-ed1-f70.google.com (mail-ed1-f70.google.com [209.85.208.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-468-sDwVsEc8N8CkeGmJ39EhKw-1; Tue, 17 Jan 2023 03:08:01 -0500 Received: by mail-ed1-f70.google.com with SMTP id t17-20020a056402525100b0049e0d2dd9b1so3828604edd.11 for ; Tue, 17 Jan 2023 00:08:00 -0800 (PST) Received: from avogadro.local ([2001:b07:6468:f312:5e2c:eb9a:a8b6:fd3e]) by smtp.gmail.com with ESMTPSA id q24-20020a056402249800b0046ac460da13sm12490778eda.53.2023.01.17.00.07.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Jan 2023 00:07:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1673942882; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Qpw/5/aIJktG9Q0OND3WGSL83i6tZBDG69a8KADEOQs=; b=UBOwW5mnaLX8/eAKuKZMH9k0HVJ7YS1yp/wfQinqfs0+c/XB5jzYZ7goG50e9aLsjzv+ld jyk8zCFPyEo2Zyy4oEfZkEoZC16uIHpWoUOVC62R2qtm4f04j5z6Io1mE9RybhDFIj1uJ8 rKvjdzW5UdQ19JkmpdZi8Kj7qPLIYtY= X-MC-Unique: sDwVsEc8N8CkeGmJ39EhKw-1 X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Qpw/5/aIJktG9Q0OND3WGSL83i6tZBDG69a8KADEOQs=; b=MlvQQNfa0/Q8l2OrRQ5IvJaPClZqETXzxSPi0cgWB43GWbxngBsXNWIcyTllkYf4eg /lQPImZrHFUPB6MnZ+AMcPSXzDbzzXa/ZJRLlW++lSvuKLiTtlyaHGZAevZyGnLEiTAR mAEkT/tg9PtzPY+ec6GskSVRHT2UbViBb39DJx7DM3GXKfc7J0/BTgNIJBlIxB9kWdvx QS/pSD2Gz4IP7eSWnFYHQ0AvmAZkekNNvpQuD1LvGk4/nDRumhkCgKcLyIvgsuqoqcpO aPZraqCGNGF+5rMbUjDZUSa4N6UfIG5DFIZhBtD+9OPOPLOigMm931mOX+OemiPejJoj EV6Q== X-Gm-Message-State: AFqh2koy4TQQnIoq8t+YfUrgCsPPakgFnLkv98VvtbZzXeCatpuIQwrF 81D4NjRdU1vfBybFulggAho/dcvIUXnGvJ7HAbYqXSK6XIaifsXxmYjpC4QvhU4VpAtfIlKIo6C T0WzzXaoYCIBt5DWPkBVPOUTHnuOwj0V9zT1xlUN1DLwzkbORmU51SfdxwmIQCMXrT7g= X-Received: by 2002:a05:6402:454:b0:492:8c77:7dad with SMTP id p20-20020a056402045400b004928c777dadmr2139061edw.8.1673942879537; Tue, 17 Jan 2023 00:07:59 -0800 (PST) X-Google-Smtp-Source: AMrXdXtHwpdgH84/wUjqURt7U9cfPll7ZyiV1S9NVAwLJaq3qojLcTdTUk+HAjI0FKzyHucPPjYEnQ== X-Received: by 2002:a05:6402:454:b0:492:8c77:7dad with SMTP id p20-20020a056402045400b004928c777dadmr2139047edw.8.1673942879180; Tue, 17 Jan 2023 00:07:59 -0800 (PST) From: Paolo Bonzini To: qemu-devel@nongnu.org Cc: thuth@redhat.com Subject: [PATCH 4/4] readconfig-test: add test for accelerator configuration Date: Tue, 17 Jan 2023 09:07:45 +0100 Message-Id: <20230117080745.43247-5-pbonzini@redhat.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20230117080745.43247-1-pbonzini@redhat.com> References: <20230117080745.43247-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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=pbonzini@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_H2=-0.001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.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: 1673942962336100003 Content-Type: text/plain; charset="utf-8" Test that invalid configurations do not cause a SIGSEGV, and cover a valid configuration as well. Signed-off-by: Paolo Bonzini --- tests/qtest/libqtest.c | 28 +++++++++++++++++----- tests/qtest/libqtest.h | 12 ++++++++++ tests/qtest/readconfig-test.c | 45 ++++++++++++++++++++++++++++------- 3 files changed, 70 insertions(+), 15 deletions(-) diff --git a/tests/qtest/libqtest.c b/tests/qtest/libqtest.c index 64ba98bc5853..53d766fe3fa5 100644 --- a/tests/qtest/libqtest.c +++ b/tests/qtest/libqtest.c @@ -402,6 +402,26 @@ static QTestState *G_GNUC_PRINTF(1, 0) qtest_spawn_qem= u(const char *fmt, ...) return s; } =20 +QTestState *G_GNUC_PRINTF(1, 0) qtest_init_bare(const char *args) +{ + QTestState *s =3D qtest_spawn_qemu("%s", args); + + /* + * Stopping QEMU for debugging is not supported on Windows. + * + * Using DebugActiveProcess() API can suspend the QEMU process, + * but gdb cannot attach to the process. Using the undocumented + * NtSuspendProcess() can suspend the QEMU process and gdb can + * attach to the process, but gdb cannot resume it. + */ +#ifndef _WIN32 + if (getenv("QTEST_STOP")) { + kill(s->qemu_pid, SIGSTOP); + } +#endif + return s; +} + QTestState *qtest_init_without_qmp_handshake(const char *extra_args) { QTestState *s; @@ -459,12 +479,8 @@ QTestState *qtest_init_without_qmp_handshake(const cha= r *extra_args) } =20 /* - * Stopping QEMU for debugging is not supported on Windows. - * - * Using DebugActiveProcess() API can suspend the QEMU process, - * but gdb cannot attach to the process. Using the undocumented - * NtSuspendProcess() can suspend the QEMU process and gdb can - * attach to the process, but gdb cannot resume it. + * Stopping QEMU for debugging is not supported on Windows; + * see qtest_init_bare for more information. */ #ifndef _WIN32 if (getenv("QTEST_STOP")) { diff --git a/tests/qtest/libqtest.h b/tests/qtest/libqtest.h index fcf1c3c3b36f..7ca7df26a2c0 100644 --- a/tests/qtest/libqtest.h +++ b/tests/qtest/libqtest.h @@ -23,6 +23,18 @@ =20 typedef struct QTestState QTestState; =20 +/** + * qtest_init_bare: + * @extra_args: other arguments to pass to QEMU. CAUTION: these + * arguments are subject to word splitting and shell evaluation. + * + * Return a QTestState instance without automatically creating any + * sockets for QMP and qtest communication. + * + * Returns: #QTestState instance. + */ +QTestState *qtest_init_bare(const char *args); + /** * qtest_initf: * @fmt: Format for creating other arguments to pass to QEMU, formatted diff --git a/tests/qtest/readconfig-test.c b/tests/qtest/readconfig-test.c index 9ef870643dcd..4c11883e36eb 100644 --- a/tests/qtest/readconfig-test.c +++ b/tests/qtest/readconfig-test.c @@ -19,13 +19,11 @@ #include "qapi/qmp/qstring.h" #include "qemu/units.h" =20 -static QTestState *qtest_init_with_config(const char *cfgdata) +static char *qtest_write_config(const char *cfgdata) { GError *error =3D NULL; - g_autofree char *args =3D NULL; int cfgfd =3D -1; - g_autofree char *cfgpath =3D NULL; - QTestState *qts; + char *cfgpath; ssize_t ret; =20 cfgfd =3D g_file_open_tmp("readconfig-test-XXXXXX", &cfgpath, &error); @@ -38,13 +36,14 @@ static QTestState *qtest_init_with_config(const char *c= fgdata) unlink(cfgpath); } g_assert_cmpint(ret, =3D=3D, strlen(cfgdata)); + return cfgpath; +} =20 - args =3D g_strdup_printf("-nodefaults -machine none -readconfig %s", c= fgpath); - - qts =3D qtest_init(args); - +static QTestState *qtest_init_with_config(const char *cfgdata) +{ + g_autofree char *cfgpath =3D qtest_write_config(cfgdata); + QTestState *qts =3D qtest_initf("-nodefaults -machine none -readconfig= %s", cfgpath); unlink(cfgpath); - return qts; } =20 @@ -176,6 +175,32 @@ static void test_object_rng(void) qtest_quit(qts); } =20 +static void test_invalid_accel(void) +{ + const char *cfgdata =3D + "[accel]\n" + "foo =3D \"bar\"\n"; + + g_autofree char *cfgpath =3D qtest_write_config(cfgdata); + g_autofree char *args =3D g_strdup_printf("-nodefaults -machine none -= readconfig %s", cfgpath); + QTestState *qts =3D qtest_init_bare(args); + + qtest_set_expected_status(qts, 1); + qtest_wait_qemu(qts); + g_free(qts); + unlink(cfgpath); +} + +static void test_valid_accel(void) +{ + const char *cfgdata =3D + "[accel]\n" + "accel =3D \"qtest\"\n"; + + QTestState *qts =3D qtest_init_with_config(cfgdata); + qtest_quit(qts); +} + int main(int argc, char *argv[]) { const char *arch; @@ -192,6 +217,8 @@ int main(int argc, char *argv[]) #endif =20 qtest_add_func("readconfig/object-rng", test_object_rng); + qtest_add_func("readconfig/invalid-accel", test_invalid_accel); + qtest_add_func("readconfig/valid-accel", test_valid_accel); =20 return g_test_run(); } --=20 2.38.1